Skip to content

Commit

Permalink
Merge pull request #273 from pranavrd/chore/remove-context
Browse files Browse the repository at this point in the history
chore: update item schemas to not have @context
  • Loading branch information
pranavrd authored Sep 20, 2023
2 parents a3045b6 + de0831f commit 951f1ca
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 67 deletions.
3 changes: 2 additions & 1 deletion configs/config-example.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@
"databasePort": 1234,
"databasePassword": "",
"databaseUser": "",
"docIndex": ""
"docIndex": "",
"@context": ""
},
{
"id": "iudx.catalogue.server.apiserver.ApiServerVerticle",
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/iudx/catalogue/server/validator/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class Constants {
public static final String ITEM_STATUS = "itemStatus";
public static final String ACTIVE = "ACTIVE";
public static final String ITEM_CREATED_AT = "itemCreatedAt";
public static final String CONTEXT = "@context";

/** Error messages. */
public static final String NON_EXISTING_LINK_MSG = "No such cat item exists: ";
public static final String VALIDATION_FAILURE_MSG = "Validation failed";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,21 @@ public class ValidatorServiceImpl implements ValidatorService {
private Validator mlayerDatasetValidator;
private String docIndex;
private boolean isUacInstance;
private String vocContext;

/**
* Constructs a new ValidatorServiceImpl object with the specified ElasticClient and docIndex.
*
* @param client the ElasticClient object to use for interacting with the Elasticsearch instance
* @param docIndex the index name to use for storing documents in Elasticsearch
*/
public ValidatorServiceImpl(ElasticClient client, String docIndex, boolean isUacInstance) {
public ValidatorServiceImpl(
ElasticClient client, String docIndex, boolean isUacInstance, String vocContext) {

this.client = client;
this.docIndex = docIndex;
this.isUacInstance = isUacInstance;
this.vocContext = vocContext;
try {
resourceValidator = new Validator("/resourceItemSchema.json");
resourceGroupValidator = new Validator("/resourceGroupItemSchema.json");
Expand Down Expand Up @@ -158,6 +161,8 @@ public ValidatorService validateSchema(
public ValidatorService validateItem(
JsonObject request, Handler<AsyncResult<JsonObject>> handler) {

request.put(CONTEXT, vocContext);

String itemType = getItemType(request, handler);
LOGGER.debug("Info: itemType: " + itemType);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import static iudx.catalogue.server.apiserver.util.Constants.UAC_DEPLOYMENT;
import static iudx.catalogue.server.util.Constants.*;
import static iudx.catalogue.server.validator.Constants.CONTEXT;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.eventbus.MessageConsumer;
Expand Down Expand Up @@ -35,6 +36,7 @@ public class ValidatorVerticle extends AbstractVerticle {
private ServiceBinder binder;
private MessageConsumer<JsonObject> consumer;
private boolean isUacInstance;
private String vocContext;

/**
* This method is used to start the Verticle. It deploys a verticle in a cluster, registers the
Expand All @@ -50,6 +52,7 @@ public void start() throws Exception {
databasePassword = config().getString(DATABASE_PASSWD);
docIndex = config().getString(DOC_INDEX);
isUacInstance = config().getBoolean(UAC_DEPLOYMENT);
vocContext = config().getString(CONTEXT);
/* Create a reference to HazelcastClusterManager. */

client = new ElasticClient(databaseIp, databasePort, docIndex, databaseUser, databasePassword);
Expand All @@ -58,7 +61,7 @@ public void start() throws Exception {

/* Publish the Validator service with the Event Bus against an address. */

validator = new ValidatorServiceImpl(client, docIndex, isUacInstance);
validator = new ValidatorServiceImpl(client, docIndex, isUacInstance, vocContext);
consumer =
binder.setAddress(VALIDATION_SERVICE_ADDRESS)
.register(ValidatorService.class, validator);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"description": "The root schema comprises the entire JSON document",
"examples": [
{
"@context": "https://voc.iudx.org.in/",
"type": [
"iudx:COS"
],
Expand All @@ -18,7 +17,6 @@
}
],
"required": [
"@context",
"type",
"name",
"description",
Expand All @@ -27,16 +25,6 @@
"cosUI"
],
"properties": {
"@context": {
"$id": "#/properties/%40context",
"type": "string",
"title": "The @context schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"https://voc.iudx.org.in/"
]
},
"type": {
"$id": "#/properties/type",
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"default": {},
"examples": [
{
"@context": "https://voc.iudx.org.in/",
"type": [
"iudx:Owner"
],
Expand All @@ -17,22 +16,11 @@
}
],
"required": [
"@context",
"type",
"name",
"description"
],
"properties": {
"@context": {
"$id": "#/properties/%40context",
"type": "string",
"title": "The @context schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"https://voc.iudx.org.in/"
]
},
"type": {
"$id": "#/properties/type",
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"default": {},
"examples": [
{
"@context": "https://voc.iudx.org.in/",
"type": [
"iudx:Provider"
],
Expand Down Expand Up @@ -36,7 +35,6 @@
}
],
"required": [
"@context",
"type",
"name",
"description",
Expand All @@ -45,16 +43,6 @@
"resourceServer"
],
"properties": {
"@context": {
"$id": "#/properties/%40context",
"type": "string",
"title": "The @context schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"https://voc.iudx.org.in/"
]
},
"type": {
"$id": "#/properties/type",
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"default": {},
"examples": [
{
"@context": "https://voc.iudx.org.in/",
"type": [
"iudx:ResourceGroup"
],
Expand All @@ -27,24 +26,13 @@
}
],
"required": [
"@context",
"type",
"description",
"name",
"tags",
"provider"
],
"properties": {
"@context": {
"$id": "#/properties/%40context",
"type": "string",
"title": "The @context schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"https://voc.iudx.org.in/"
]
},
"type": {
"$id": "#/properties/type",
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
"default": {},
"examples": [
{
"@context": "https://voc.iudx.org.in/",
"type": [
"iudx:ResourceServer"
],
Expand Down Expand Up @@ -79,7 +78,6 @@
}
],
"required": [
"@context",
"type",
"cos",
"owner",
Expand All @@ -91,16 +89,6 @@
"resourceAccessModalities"
],
"properties": {
"@context": {
"$id": "#/properties/%40context",
"type": "string",
"title": "The @context schema",
"description": "An explanation about the purpose of this instance.",
"default": "",
"examples": [
"https://voc.iudx.org.in/"
]
},
"type": {
"$id": "#/properties/type",
"type": "array",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class ConstraintsValidationTest {
private static String databasePassword;
private static FileSystem fileSystem;
private static boolean isUACinstance;
private static String vocContext;

@BeforeAll
@DisplayName("Deploying Verticle")
Expand All @@ -55,10 +56,11 @@ static void startVertx(Vertx vertx, VertxTestContext testContext) {
databaseUser = validationconfig.getString(DATABASE_UNAME);
databasePassword = validationconfig.getString(DATABASE_PASSWD);
docIndex = validationconfig.getString(DOC_INDEX);
vocContext = "xyz";

fileSystem = vertx.fileSystem();
client = new ElasticClient(databaseIP, databasePort, docIndex, databaseUser, databasePassword);
validator = new ValidatorServiceImpl(client,docIndex,isUACinstance);
validator = new ValidatorServiceImpl(client,docIndex,isUACinstance, vocContext);

testContext.completed();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public class ValidatorServiceImplTest {
private static JsonObject jsonMock;
private static JsonArray jsonArrayMock;
private static Stream<Object> streamMock;
private static String vocContext;
@Mock Handler<AsyncResult<JsonObject>> handler;

@BeforeAll
Expand All @@ -67,11 +68,12 @@ static void startVertx(Vertx vertx, VertxTestContext testContext) {
databasePassword = validatorConfig.getString(DATABASE_PASSWD);
docIndex = validatorConfig.getString(DOC_INDEX);
isUacInstance = false;
vocContext = "xyz";

// client = new ElasticClient(databaseIP, databasePort, docIndex, databaseUser,
// databasePassword);
client = mock(ElasticClient.class);
validatorService = new ValidatorServiceImpl(client, docIndex, isUacInstance);
validatorService = new ValidatorServiceImpl(client, docIndex, isUacInstance, vocContext);

asyncResult = mock(AsyncResult.class);
doAnswer(
Expand Down Expand Up @@ -120,7 +122,7 @@ private static Stream<Arguments> validateItemTypes() {
@MethodSource("itemTypes")
@Description("testing the method validateSchema when itemType equals ITEM_TYPE_RESOURCE_SERVER")
public void testValidateSchema(String itemType, VertxTestContext vertxTestContext) {
validatorService = new ValidatorServiceImpl(client, docIndex, isUacInstance);
validatorService = new ValidatorServiceImpl(client, docIndex, isUacInstance, vocContext);
JsonObject request = new JsonObject();
JsonArray jsonArray = new JsonArray();
jsonArray.add(itemType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class ValidatorServiceTest {
private static String databasePassword;
private static FileSystem fileSystem;
private static boolean isUacInstance;
private static String vocContext;

@BeforeAll
@DisplayName("Deploying Verticle")
Expand All @@ -45,10 +46,11 @@ static void startVertx(Vertx vertx, VertxTestContext testContext) {
databaseUser = validatorConfig.getString(DATABASE_UNAME);
databasePassword = validatorConfig.getString(DATABASE_PASSWD);
docIndex = validatorConfig.getString(DOC_INDEX);
vocContext = "xyz";

// TODO : Need to enable TLS using xpack security
client = new ElasticClient(databaseIP, databasePort, docIndex, databaseUser, databasePassword);
validator = new ValidatorServiceImpl(client, docIndex,isUacInstance);
validator = new ValidatorServiceImpl(client, docIndex,isUacInstance, vocContext);
testContext.completeNow();
}

Expand Down

0 comments on commit 951f1ca

Please sign in to comment.