"content": {"application/json": {"schema": {"$ref": "#/components/schemas/Job"}}},
"required": true
},
+ "description": "The job will be enabled when a producer is available",
"operationId": "putIndividualInfoJob",
"responses": {
"200": {
"content": {"application/json": {"schema": {"$ref": "#/components/schemas/ProblemDetails"}}}
}
},
- "parameters": [{
- "schema": {"type": "string"},
- "in": "path",
- "name": "infoJobId",
- "required": true
- }],
+ "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
+ }
+ ],
"tags": ["Data consumer"]
}
},
path = "/info-jobs/{infoJobId}", //
produces = MediaType.APPLICATION_JSON_VALUE, //
consumes = MediaType.APPLICATION_JSON_VALUE)
- @Operation(summary = ConsumerConsts.INDIVIDUAL_JOB)
+ @Operation(summary = ConsumerConsts.INDIVIDUAL_JOB, description = ConsumerConsts.PUT_INDIVIDUAL_JOB_DESCRIPTION)
@ApiResponses(
value = { //
@ApiResponse(
})
public Mono<ResponseEntity<Object>> putIndividualInfoJob( //
@PathVariable("infoJobId") 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.jobs.get(jobId) == null;
- return validatePutInfoJob(jobId, informationJobObject) //
+ return validatePutInfoJob(jobId, informationJobObject, performTypeCheck) //
.flatMap(this::startInfoSubscriptionJob) //
.doOnNext(newEiJob -> this.jobs.put(newEiJob)) //
.flatMap(newEiJob -> Mono.just(new ResponseEntity<>(isNewJob ? HttpStatus.CREATED : HttpStatus.OK)))
.flatMap(noOfAcceptingProducers -> Mono.just(newInfoJob));
}
- private Mono<EiJob> validatePutInfoJob(String jobId, ConsumerJobInfo jobInfo) {
+ private Mono<EiJob> validatePutInfoJob(String jobId, ConsumerJobInfo jobInfo, boolean performTypeCheck) {
try {
- EiType infoType = this.infoTypes.getType(jobInfo.infoTypeId);
- validateJsonObjectAgainstSchema(infoType.getJobDataSchema(), jobInfo.jobDefinition);
+ if (performTypeCheck) {
+ EiType infoType = this.infoTypes.getType(jobInfo.infoTypeId);
+ validateJsonObjectAgainstSchema(infoType.getJobDataSchema(), jobInfo.jobDefinition);
+ }
EiJob existingEiJob = this.jobs.get(jobId);
if (existingEiJob != null && !existingEiJob.getTypeId().equals(jobInfo.infoTypeId)) {
throw new ServiceException("Not allowed to change type for existing job", HttpStatus.CONFLICT);
}
- return Mono.just(toEiJob(jobInfo, jobId, infoType));
+ return Mono.just(toEiJob(jobInfo, jobId, jobInfo.infoTypeId));
} catch (Exception e) {
return Mono.error(e);
}
}
}
- private EiJob toEiJob(ConsumerJobInfo info, String id, EiType type) {
+ private EiJob toEiJob(ConsumerJobInfo info, String id, String typeId) {
return EiJob.builder() //
.id(id) //
- .typeId(type.getId()) //
+ .typeId(typeId) //
.owner(info.owner) //
.jobData(info.jobDefinition) //
.targetUrl(info.jobResultUri) //
.build();
}
+ private EiJob toEiJob(ConsumerJobInfo info, String id, EiType type) {
+ return toEiJob(info, id, type.getId());
+ }
+
private ConsumerInfoTypeInfo toInfoTypeInfo(EiType type) {
return new ConsumerInfoTypeInfo(type.getJobDataSchema());
}
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.eiJobs.size()).isEqualTo(1);
+ assertThat(resp.getStatusCode()).isEqualTo(HttpStatus.CREATED);
+ verifyJobStatus(EI_JOB_ID, "DISABLED");
+
+ putEiProducerWithOneType(PRODUCER_ID, TYPE_ID);
+
+ verifyJobStatus(EI_JOB_ID, "ENABLED");
+
+ }
+
@Test
void a1ePutEiJob_jsonSchemavalidationError() throws Exception {
putEiProducerWithOneType(PRODUCER_ID, TYPE_ID);
void consumerPutJob_jsonSchemavalidationError() throws Exception {
putEiProducerWithOneType(PRODUCER_ID, TYPE_ID);
- String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId";
+ String url = ConsumerConsts.API_ROOT + "/info-jobs/jobId?typeCheck=true";
// The element with name "property1" is mandatory in the schema
ConsumerJobInfo jobInfo = new ConsumerJobInfo("typeId", jsonObject("{ \"XXstring\" : \"value\" }"), "owner",
"targetUri", "jobStatusUrl");