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
"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"]
}
},
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:
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:
}
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);
}
}
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)";
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)) //
.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);
}
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);
}
}
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);
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);
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);