From: PatrikBuhr Date: Wed, 4 May 2022 06:19:46 +0000 (+0200) Subject: Removed type check parameter X-Git-Tag: 1.3.0~2 X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=e5e39ef18571a6d9e55a9489eacd6c9f96aeef82;p=nonrtric%2Fplt%2Finformationcoordinatorservice.git Removed type check parameter A type schema is now always needed and a validation towards that schema is always done. Signed-off-by: PatrikBuhr Issue-ID: NONRTRIC-743 Change-Id: I09ba9dea1e26fd3b4bbabc9e3049c616365a8e8e --- diff --git a/api/ics-api.json b/api/ics-api.json index 56bbcb5..8e5c982 100644 --- a/api/ics-api.json +++ b/api/ics-api.json @@ -1099,24 +1099,12 @@ "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"] } }, diff --git a/api/ics-api.yaml b/api/ics-api.yaml index be8fc94..9548822 100644 --- a/api/ics-api.yaml +++ b/api/ics-api.yaml @@ -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: diff --git a/config/application.yaml b/config/application.yaml index 372b61c..e61bfea 100644 --- a/config/application.yaml +++ b/config/application.yaml @@ -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: diff --git a/src/main/java/org/oransc/ics/controllers/a1e/A1eController.java b/src/main/java/org/oransc/ics/controllers/a1e/A1eController.java index 699308d..0c2aca6 100644 --- a/src/main/java/org/oransc/ics/controllers/a1e/A1eController.java +++ b/src/main/java/org/oransc/ics/controllers/a1e/A1eController.java @@ -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); } } diff --git a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerConsts.java b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerConsts.java index 7005a23..00ab0f2 100644 --- a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerConsts.java +++ b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerConsts.java @@ -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)"; diff --git a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java index fa335d9..c988595 100644 --- a/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java +++ b/src/main/java/org/oransc/ics/controllers/r1consumer/ConsumerController.java @@ -293,19 +293,11 @@ public class ConsumerController { content = @Content(schema = @Schema(implementation = ErrorResponse.ErrorInfo.class)))}) public Mono> 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 validatePutInfoJob(String jobId, ConsumerJobInfo jobInfo, boolean performTypeCheck) { + private Mono 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); } } diff --git a/src/test/java/org/oransc/ics/ApplicationTest.java b/src/test/java/org/oransc/ics/ApplicationTest.java index 975bf81..f0a4fed 100644 --- a/src/test/java/org/oransc/ics/ApplicationTest.java +++ b/src/test/java/org/oransc/ics/ApplicationTest.java @@ -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 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);