Removed type check parameter 38/8138/2
authorPatrikBuhr <patrik.buhr@est.tech>
Wed, 4 May 2022 06:19:46 +0000 (08:19 +0200)
committerPatrikBuhr <patrik.buhr@est.tech>
Wed, 4 May 2022 06:23:42 +0000 (08:23 +0200)
A type schema is now always needed and a validation towards that schema is always done.

Signed-off-by: PatrikBuhr <patrik.buhr@est.tech>
Issue-ID: NONRTRIC-743
Change-Id: I09ba9dea1e26fd3b4bbabc9e3049c616365a8e8e

api/ics-api.json
api/ics-api.yaml
config/application.yaml
src/main/java/org/oransc/ics/controllers/a1e/A1eController.java
src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerConsts.java
src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java
src/test/java/org/oransc/ics/ApplicationTest.java

index 56bbcb5..8e5c982 100644 (file)
                         "content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
                     }
                 },
-                "parameters": [
-                    {
-                        "schema": {"type": "string"},
-                        "in": "path",
-                        "name": "infoJobId",
-                        "required": true
-                    },
-                    {
-                        "schema": {
-                            "default": false,
-                            "type": "boolean"
-                        },
-                        "in": "query",
-                        "name": "typeCheck",
-                        "description": "when true, a validation of that the type exists and that the job matches the type schema.",
-                        "required": false
-                    }
-                ],
+                "parameters": [{
+                    "schema": {"type": "string"},
+                    "in": "path",
+                    "name": "infoJobId",
+                    "required": true
+                }],
                 "tags": ["Data consumer"]
             }
         },
index be8fc94..9548822 100644 (file)
@@ -996,16 +996,6 @@ paths:
         explode: false
         schema:
           type: string
-      - name: typeCheck
-        in: query
-        description: when true, a validation of that the type exists and that the
-          job matches the type schema.
-        required: false
-        style: form
-        explode: true
-        schema:
-          type: boolean
-          default: false
       requestBody:
         content:
           application/json:
index 372b61c..e61bfea 100644 (file)
@@ -48,5 +48,5 @@ app:
     http.proxy-host:
     http.proxy-port: 0
   vardata-directory: /var/information-coordinator-service
-  # If the file name is empty, no authorzation token is sent
-  auth-token-file:
\ No newline at end of file
+  # If the file name is empty, no authorization token is used
+  auth-token-file:
index 699308d..0c2aca6 100644 (file)
@@ -336,20 +336,18 @@ public class A1eController {
     }
 
     private void validateJsonObjectAgainstSchema(Object schemaObj, Object object) throws ServiceException {
-        if (schemaObj != null) { // schema is optional for now
-            try {
-                ObjectMapper mapper = new ObjectMapper();
-
-                String schemaAsString = mapper.writeValueAsString(schemaObj);
-                JSONObject schemaJSON = new JSONObject(schemaAsString);
-                var schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON);
-
-                String objectAsString = mapper.writeValueAsString(object);
-                JSONObject json = new JSONObject(objectAsString);
-                schema.validate(json);
-            } catch (Exception e) {
-                throw new ServiceException("Json validation failure " + e.toString(), HttpStatus.BAD_REQUEST);
-            }
+        try {
+            ObjectMapper mapper = new ObjectMapper();
+
+            String schemaAsString = mapper.writeValueAsString(schemaObj);
+            JSONObject schemaJSON = new JSONObject(schemaAsString);
+            var schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON);
+
+            String objectAsString = mapper.writeValueAsString(object);
+            JSONObject json = new JSONObject(objectAsString);
+            schema.validate(json);
+        } catch (Exception e) {
+            throw new ServiceException("Json validation failure " + e.toString(), HttpStatus.BAD_REQUEST);
         }
     }
 
index 7005a23..00ab0f2 100644 (file)
@@ -44,10 +44,6 @@ public class ConsumerConsts {
 
     public static final String SUBSCRIPTION_ID_PATH = "subscriptionId";
 
-    public static final String PERFORM_TYPE_CHECK_PARAM = "typeCheck";
-    public static final String PERFORM_TYPE_CHECK_PARAM_DESCRIPTION =
-        "when true, a validation of that the type exists and that the job matches the type schema.";
-
     public static final String INDIVIDUAL_TYPE_SUBSCRIPTION =
         "Individual subscription for information types (registration/deregistration)";
 
index fa335d9..c988595 100644 (file)
@@ -293,19 +293,11 @@ public class ConsumerController {
                 content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class)))})
     public Mono<ResponseEntity<Object>> putIndividualInfoJob( //
         @PathVariable(ConsumerConsts.INFO_JOB_ID_PATH) String jobId, //
-        @Parameter(
-            name = ConsumerConsts.PERFORM_TYPE_CHECK_PARAM,
-            required = false, //
-            description = ConsumerConsts.PERFORM_TYPE_CHECK_PARAM_DESCRIPTION) //
-        @RequestParam(
-            name = ConsumerConsts.PERFORM_TYPE_CHECK_PARAM,
-            required = false,
-            defaultValue = "false") boolean performTypeCheck,
         @RequestBody ConsumerJobInfo informationJobObject) {
 
         final boolean isNewJob = this.infoJobs.get(jobId) == null;
 
-        return validatePutInfoJob(jobId, informationJobObject, performTypeCheck) //
+        return validatePutInfoJob(jobId, informationJobObject) //
             .flatMap(this::startInfoSubscriptionJob) //
             .doOnNext(this.infoJobs::put) //
             .map(newEiJob -> new ResponseEntity<>(isNewJob ? HttpStatus.CREATED : HttpStatus.OK)) //
@@ -444,12 +436,12 @@ public class ConsumerController {
             .map(noOfAcceptingProducers -> newInfoJob);
     }
 
-    private Mono<InfoJob> validatePutInfoJob(String jobId, ConsumerJobInfo jobInfo, boolean performTypeCheck) {
+    private Mono<InfoJob> validatePutInfoJob(String jobId, ConsumerJobInfo jobInfo) {
         try {
-            if (performTypeCheck) {
-                InfoType infoType = this.infoTypes.getType(jobInfo.infoTypeId);
-                validateJsonObjectAgainstSchema(infoType.getJobDataSchema(), jobInfo.jobDefinition);
-            }
+
+            InfoType infoType = this.infoTypes.getType(jobInfo.infoTypeId);
+            validateJsonObjectAgainstSchema(infoType.getJobDataSchema(), jobInfo.jobDefinition);
+
             InfoJob existingEiJob = this.infoJobs.get(jobId);
             validateUri(jobInfo.statusNotificationUri);
             validateUri(jobInfo.jobResultUri);
@@ -473,20 +465,18 @@ public class ConsumerController {
     }
 
     private void validateJsonObjectAgainstSchema(Object schemaObj, Object object) throws ServiceException {
-        if (schemaObj != null) { // schema is optional for now
-            try {
-                ObjectMapper mapper = new ObjectMapper();
-
-                String schemaAsString = mapper.writeValueAsString(schemaObj);
-                JSONObject schemaJSON = new JSONObject(schemaAsString);
-                var schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON);
-
-                String objectAsString = mapper.writeValueAsString(object);
-                JSONObject json = new JSONObject(objectAsString);
-                schema.validate(json);
-            } catch (Exception e) {
-                throw new ServiceException("Json validation failure " + e.toString(), HttpStatus.BAD_REQUEST);
-            }
+        try {
+            ObjectMapper mapper = new ObjectMapper();
+
+            String schemaAsString = mapper.writeValueAsString(schemaObj);
+            JSONObject schemaJSON = new JSONObject(schemaAsString);
+            var schema = org.everit.json.schema.loader.SchemaLoader.load(schemaJSON);
+
+            String objectAsString = mapper.writeValueAsString(object);
+            JSONObject json = new JSONObject(objectAsString);
+            schema.validate(json);
+        } catch (Exception e) {
+            throw new ServiceException("Json validation failure " + e.toString(), HttpStatus.BAD_REQUEST);
         }
     }
 
index 975bf81..f0a4fed 100644 (file)
@@ -480,20 +480,6 @@ class ApplicationTest {
         verifyJobStatus(EI_JOB_ID, "ENABLED");
     }
 
-    @Test
-    void consumerPutInformationJob_noType() throws JsonMappingException, JsonProcessingException, ServiceException {
-        String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId?typeCheck=false";
-        String body = gson.toJson(consumerJobInfo());
-        ResponseEntity<String> resp = restClient().putForEntity(url, body).block();
-        assertThat(this.infoJobs.size()).isEqualTo(1);
-        assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.CREATED);
-        verifyJobStatus(EI_JOB_ID, "DISABLED");
-
-        putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
-
-        verifyJobStatus(EI_JOB_ID, "ENABLED");
-    }
-
     @Test
     void a1ePutEiJob_jsonSchemavalidationError() throws Exception {
         putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
@@ -514,7 +500,7 @@ class ApplicationTest {
     void consumerPutJob_jsonSchemavalidationError() throws Exception {
         putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
 
-        String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId?typeCheck=true";
+        String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId";
         // The element with name "property1" is mandatory in the schema
         ConsumerJobInfo jobInfo =
             new ConsumerJobInfo("typeId", jsonObject("{ \"XXstring\" : \"value\" }"), "owner", "targetUri", null);
@@ -527,7 +513,7 @@ class ApplicationTest {
     void consumerPutJob_uriError() throws Exception {
         putInfoProducerWithOneType(PRODUCER_ID, TYPE_ID);
 
-        String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId?typeCheck=true";
+        String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId";
 
         ConsumerJobInfo jobInfo = new ConsumerJobInfo(TYPE_ID, jsonObject(), "owner", "junk", null);
         String body = gson.toJson(jobInfo);