use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class JobExecutionServiceImpl method prepareJobExecutionList.
/**
* Creates and returns list of JobExecution entities depending on received files.
* In a case if only one file passed, method returns list with one JobExecution entity
* signed by SINGLE_PARENT status.
* In a case if N files passed (N > 1), method returns list with JobExecution entities
* with one JobExecution entity signed by PARENT_MULTIPLE and N JobExecution entities signed by CHILD status.
*
* @param parentJobExecutionId id of the parent JobExecution entity
* @param files Representations of the Files user uploads
* @param userInfo The user creating JobExecution
* @param dto {@link InitJobExecutionsRqDto}
* @return list of JobExecution entities
*/
private List<JobExecution> prepareJobExecutionList(String parentJobExecutionId, List<File> files, UserInfo userInfo, InitJobExecutionsRqDto dto) {
String userId = dto.getUserId();
if (dto.getSourceType().equals(InitJobExecutionsRqDto.SourceType.ONLINE)) {
JobProfileInfo jobProfileInfo = dto.getJobProfileInfo();
if (jobProfileInfo != null && jobProfileInfo.getId().equals(DEFAULT_JOB_PROFILE_ID)) {
jobProfileInfo.withName(DEFAULT_JOB_PROFILE);
}
return Collections.singletonList(buildNewJobExecution(true, true, parentJobExecutionId, null, userId).withJobProfileInfo(jobProfileInfo).withRunBy(buildRunByFromUserInfo(userInfo)));
}
List<JobExecution> result = new ArrayList<>();
if (files.size() > 1) {
for (File file : files) {
result.add(buildNewJobExecution(false, false, parentJobExecutionId, file.getName(), userId));
}
result.add(buildNewJobExecution(true, false, parentJobExecutionId, null, userId));
} else {
File file = files.get(0);
result.add(buildNewJobExecution(true, true, parentJobExecutionId, file.getName(), userId));
}
result.forEach(job -> job.setRunBy(buildRunByFromUserInfo(userInfo)));
return result;
}
use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method shouldReturn204OkEventIfRemoveJobExecutionWithCommittedStatus.
@Test
public void shouldReturn204OkEventIfRemoveJobExecutionWithCommittedStatus(TestContext testContext) {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
WireMock.stubFor(post(RECORDS_SERVICE_URL).willReturn(created().withTransformers(RequestToResponseTransformer.NAME)));
WireMock.stubFor(WireMock.delete(new UrlPathPattern(new RegexPattern(SNAPSHOT_SERVICE_URL + "/.*"), true)).willReturn(WireMock.noContent()));
Async async = testContext.async();
RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(DEFAULT_JOB_PROFILE_ID).withDataType(JobProfileInfo.DataType.MARC)).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).body(rawRecordsDto.withId(UUID.randomUUID().toString())).when().post(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();
StatusDto status = new StatusDto().withStatus(COMMITTED);
RestAssured.given().spec(spec).body(JsonObject.mapFrom(status).toString()).when().put(JOB_EXECUTION_PATH + jobExec.getId() + STATUS_PATH).then().statusCode(HttpStatus.SC_OK);
async = testContext.async();
RestAssured.given().spec(spec).when().delete(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
async.complete();
async = testContext.async();
RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(COMMITTED.value()));
async.complete();
}
use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method fillInRecordOrderIfAtLeastOneRecordHasNoOrder.
private void fillInRecordOrderIfAtLeastOneRecordHasNoOrder(String rawRecord) throws InterruptedException {
RawRecordsDto rawRecordsDto = new RawRecordsDto().withId(UUID.randomUUID().toString()).withRecordsMetadata(new RecordsMetadata().withLast(true).withCounter(7).withContentType(RecordsMetadata.ContentType.MARC_RAW)).withInitialRecords(asList(new InitialRecord().withRecord(CORRECT_RAW_RECORD_1), new InitialRecord().withRecord(CORRECT_RAW_RECORD_2).withOrder(5), new InitialRecord().withRecord(rawRecord).withOrder(6)));
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
RestAssured.given().spec(spec).body(new JobProfileInfo().withName("MARC records").withId(DEFAULT_JOB_PROFILE_ID).withDataType(DataType.MARC)).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK);
RestAssured.given().spec(spec).body(rawRecordsDto).when().post(JOB_EXECUTION_PATH + jobExec.getId() + RECORDS_PATH).then().statusCode(HttpStatus.SC_NO_CONTENT);
String topicToObserve = formatToKafkaTopicName(DI_RAW_RECORDS_CHUNK_PARSED.value());
List<String> observedValues = kafkaCluster.observeValues(ObserveKeyValues.on(topicToObserve, 1).observeFor(30, TimeUnit.SECONDS).build());
Event obtainedEvent = Json.decodeValue(observedValues.get(0), Event.class);
assertEquals(DI_RAW_RECORDS_CHUNK_PARSED.value(), obtainedEvent.getEventType());
RecordCollection processedRecords = Json.decodeValue(obtainedEvent.getEventPayload(), RecordCollection.class);
assertEquals(3, processedRecords.getRecords().size());
assertEquals(4, processedRecords.getRecords().get(0).getOrder().intValue());
assertEquals(5, processedRecords.getRecords().get(1).getOrder().intValue());
assertEquals(6, processedRecords.getRecords().get(2).getOrder().intValue());
}
use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method shouldMarkJobExecutionAsErrorOnSetJobProfileInfoWhenCreationProfileWrapperFailed.
@Test
public void shouldMarkJobExecutionAsErrorOnSetJobProfileInfoWhenCreationProfileWrapperFailed() {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
WireMock.stubFor(post(new UrlPathPattern(new RegexPattern(PROFILE_SNAPSHOT_URL + "/.*"), true)).willReturn(serverError()));
JobProfileInfo jobProfile = new JobProfileInfo().withId(DEFAULT_JOB_PROFILE_ID).withName("marc");
RestAssured.given().spec(spec).body(JsonObject.mapFrom(jobProfile).toString()).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).body("status", is(JobExecution.Status.ERROR.value())).body("errorStatus", is(JobExecution.ErrorStatus.PROFILE_SNAPSHOT_CREATING_ERROR.value()));
}
use of org.folio.rest.jaxrs.model.JobProfileInfo in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method shouldSetJobProfileInfoForJobExecution.
@Test
public void shouldSetJobProfileInfoForJobExecution() {
InitJobExecutionsRsDto response = constructAndPostInitJobExecutionRqDto(1);
List<JobExecution> createdJobExecutions = response.getJobExecutions();
assertThat(createdJobExecutions.size(), is(1));
JobExecution jobExec = createdJobExecutions.get(0);
JobProfileInfo jobProfile = new JobProfileInfo().withId(DEFAULT_JOB_PROFILE_ID).withName("Default job profile");
RestAssured.given().spec(spec).body(JsonObject.mapFrom(jobProfile).toString()).when().put(JOB_EXECUTION_PATH + jobExec.getId() + JOB_PROFILE_PATH).then().statusCode(HttpStatus.SC_OK).body("jobProfileInfo.id", is(jobProfile.getId())).body("jobProfileInfo.name", is(jobProfile.getName())).body("jobProfileSnapshotWrapper", notNullValue());
RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + jobExec.getId()).then().statusCode(HttpStatus.SC_OK).body("jobProfileInfo.id", is(jobProfile.getId())).body("jobProfileInfo.name", is(jobProfile.getName())).body("jobProfileSnapshotWrapper", notNullValue());
}
Aggregations