diff --git a/configs/config-example.json b/configs/config-example.json index 4ae720d5..927d0544 100644 --- a/configs/config-example.json +++ b/configs/config-example.json @@ -45,7 +45,8 @@ "databasePort": 1234, "databasePassword": "", "databaseUser": "", - "docIndex": "" + "docIndex": "", + "@context": "" }, { "id": "iudx.catalogue.server.apiserver.ApiServerVerticle", diff --git a/src/main/java/iudx/catalogue/server/validator/Constants.java b/src/main/java/iudx/catalogue/server/validator/Constants.java index bb3f7219..a2d20494 100644 --- a/src/main/java/iudx/catalogue/server/validator/Constants.java +++ b/src/main/java/iudx/catalogue/server/validator/Constants.java @@ -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"; diff --git a/src/main/java/iudx/catalogue/server/validator/ValidatorServiceImpl.java b/src/main/java/iudx/catalogue/server/validator/ValidatorServiceImpl.java index 941a9bcf..c478b98a 100644 --- a/src/main/java/iudx/catalogue/server/validator/ValidatorServiceImpl.java +++ b/src/main/java/iudx/catalogue/server/validator/ValidatorServiceImpl.java @@ -49,6 +49,7 @@ 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. @@ -56,11 +57,13 @@ public class ValidatorServiceImpl implements ValidatorService { * @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"); @@ -158,6 +161,8 @@ public ValidatorService validateSchema( public ValidatorService validateItem( JsonObject request, Handler> handler) { + request.put(CONTEXT, vocContext); + String itemType = getItemType(request, handler); LOGGER.debug("Info: itemType: " + itemType); diff --git a/src/main/java/iudx/catalogue/server/validator/ValidatorVerticle.java b/src/main/java/iudx/catalogue/server/validator/ValidatorVerticle.java index ad25e535..5006e024 100644 --- a/src/main/java/iudx/catalogue/server/validator/ValidatorVerticle.java +++ b/src/main/java/iudx/catalogue/server/validator/ValidatorVerticle.java @@ -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; @@ -35,6 +36,7 @@ public class ValidatorVerticle extends AbstractVerticle { private ServiceBinder binder; private MessageConsumer consumer; private boolean isUacInstance; + private String vocContext; /** * This method is used to start the Verticle. It deploys a verticle in a cluster, registers the @@ -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); @@ -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); diff --git a/src/main/resources/iudx/catalogue/server/validator/cosItemSchema.json b/src/main/resources/iudx/catalogue/server/validator/cosItemSchema.json index cd54f8b3..b9dcf804 100644 --- a/src/main/resources/iudx/catalogue/server/validator/cosItemSchema.json +++ b/src/main/resources/iudx/catalogue/server/validator/cosItemSchema.json @@ -6,7 +6,6 @@ "description": "The root schema comprises the entire JSON document", "examples": [ { - "@context": "https://voc.iudx.org.in/", "type": [ "iudx:COS" ], @@ -18,7 +17,6 @@ } ], "required": [ - "@context", "type", "name", "description", @@ -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", diff --git a/src/main/resources/iudx/catalogue/server/validator/ownerItemSchema.json b/src/main/resources/iudx/catalogue/server/validator/ownerItemSchema.json index 2bc4a0f9..8aa3ff98 100644 --- a/src/main/resources/iudx/catalogue/server/validator/ownerItemSchema.json +++ b/src/main/resources/iudx/catalogue/server/validator/ownerItemSchema.json @@ -7,7 +7,6 @@ "default": {}, "examples": [ { - "@context": "https://voc.iudx.org.in/", "type": [ "iudx:Owner" ], @@ -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", diff --git a/src/main/resources/iudx/catalogue/server/validator/providerItemSchema.json b/src/main/resources/iudx/catalogue/server/validator/providerItemSchema.json index 62f3a1fa..bb0d74ac 100644 --- a/src/main/resources/iudx/catalogue/server/validator/providerItemSchema.json +++ b/src/main/resources/iudx/catalogue/server/validator/providerItemSchema.json @@ -7,7 +7,6 @@ "default": {}, "examples": [ { - "@context": "https://voc.iudx.org.in/", "type": [ "iudx:Provider" ], @@ -36,7 +35,6 @@ } ], "required": [ - "@context", "type", "name", "description", @@ -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", diff --git a/src/main/resources/iudx/catalogue/server/validator/resourceGroupItemSchema.json b/src/main/resources/iudx/catalogue/server/validator/resourceGroupItemSchema.json index 41e3f199..ab1fa360 100644 --- a/src/main/resources/iudx/catalogue/server/validator/resourceGroupItemSchema.json +++ b/src/main/resources/iudx/catalogue/server/validator/resourceGroupItemSchema.json @@ -7,7 +7,6 @@ "default": {}, "examples": [ { - "@context": "https://voc.iudx.org.in/", "type": [ "iudx:ResourceGroup" ], @@ -27,7 +26,6 @@ } ], "required": [ - "@context", "type", "description", "name", @@ -35,16 +33,6 @@ "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", diff --git a/src/main/resources/iudx/catalogue/server/validator/resourceServerItemSchema.json b/src/main/resources/iudx/catalogue/server/validator/resourceServerItemSchema.json index 027ccf79..8069e0df 100644 --- a/src/main/resources/iudx/catalogue/server/validator/resourceServerItemSchema.json +++ b/src/main/resources/iudx/catalogue/server/validator/resourceServerItemSchema.json @@ -7,7 +7,6 @@ "default": {}, "examples": [ { - "@context": "https://voc.iudx.org.in/", "type": [ "iudx:ResourceServer" ], @@ -79,7 +78,6 @@ } ], "required": [ - "@context", "type", "cos", "owner", @@ -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", diff --git a/src/test/java/iudx/catalogue/server/apiserver/ConstraintsValidationTest.java b/src/test/java/iudx/catalogue/server/apiserver/ConstraintsValidationTest.java index 138e1d00..57d3ad15 100755 --- a/src/test/java/iudx/catalogue/server/apiserver/ConstraintsValidationTest.java +++ b/src/test/java/iudx/catalogue/server/apiserver/ConstraintsValidationTest.java @@ -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") @@ -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(); } diff --git a/src/test/java/iudx/catalogue/server/validator/ValidatorServiceImplTest.java b/src/test/java/iudx/catalogue/server/validator/ValidatorServiceImplTest.java index 6ecbd11a..e965b469 100644 --- a/src/test/java/iudx/catalogue/server/validator/ValidatorServiceImplTest.java +++ b/src/test/java/iudx/catalogue/server/validator/ValidatorServiceImplTest.java @@ -51,6 +51,7 @@ public class ValidatorServiceImplTest { private static JsonObject jsonMock; private static JsonArray jsonArrayMock; private static Stream streamMock; + private static String vocContext; @Mock Handler> handler; @BeforeAll @@ -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( @@ -120,7 +122,7 @@ private static Stream 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); diff --git a/src/test/java/iudx/catalogue/server/validator/ValidatorServiceTest.java b/src/test/java/iudx/catalogue/server/validator/ValidatorServiceTest.java index b1bfdafe..9a0bcd62 100644 --- a/src/test/java/iudx/catalogue/server/validator/ValidatorServiceTest.java +++ b/src/test/java/iudx/catalogue/server/validator/ValidatorServiceTest.java @@ -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") @@ -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(); }