use of org.folio.rest.jaxrs.model.File 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.File in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method testInitJobExecutionsWithUserWithoutPersonalInformation.
@Test
public void testInitJobExecutionsWithUserWithoutPersonalInformation() {
// given
String jsonFiles;
List<File> filesList;
try {
jsonFiles = TestUtil.readFileFromPath(FILES_PATH);
filesList = new ObjectMapper().readValue(jsonFiles, new TypeReference<>() {
});
} catch (IOException e) {
throw new RuntimeException(e);
}
List<File> limitedFilesList = filesList.stream().limit(1).collect(Collectors.toList());
String stubUserId = UUID.randomUUID().toString();
WireMock.stubFor(get(GET_USER_URL + stubUserId).willReturn(okJson(userResponse.toString())));
InitJobExecutionsRqDto requestDto = new InitJobExecutionsRqDto();
requestDto.getFiles().addAll(limitedFilesList);
requestDto.setUserId(stubUserId);
requestDto.setSourceType(InitJobExecutionsRqDto.SourceType.FILES);
// when
String parentJobExecutionId = RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().post(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_CREATED).extract().path("parentJobExecutionId");
JsonObject jsonUser = userResponse.getJsonArray("users").getJsonObject(0);
RestAssured.given().spec(spec).when().get(JOB_EXECUTION_PATH + parentJobExecutionId).then().statusCode(HttpStatus.SC_OK).body("id", is(parentJobExecutionId)).body("hrId", greaterThanOrEqualTo(0)).body("runBy.firstName", is(jsonUser.getString("username"))).body("runBy.lastName", is("SYSTEM"));
}
use of org.folio.rest.jaxrs.model.File in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method testDeleteChangeManagerJobExecutionsSingleEntity.
@Test
public void testDeleteChangeManagerJobExecutionsSingleEntity() {
// given
String jsonFiles;
List<File> filesList;
try {
jsonFiles = TestUtil.readFileFromPath(FILES_PATH);
filesList = new ObjectMapper().readValue(jsonFiles, new TypeReference<>() {
});
} catch (IOException e) {
throw new RuntimeException(e);
}
List<File> limitedFilesList = filesList.stream().limit(1).collect(Collectors.toList());
String stubUserId = UUID.randomUUID().toString();
WireMock.stubFor(get(GET_USER_URL + stubUserId).willReturn(okJson(userResponse.toString())));
InitJobExecutionsRqDto requestDto = new InitJobExecutionsRqDto();
requestDto.getFiles().addAll(limitedFilesList);
requestDto.setUserId(stubUserId);
requestDto.setSourceType(InitJobExecutionsRqDto.SourceType.FILES);
// when
String parentJobExecutionId = RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().post(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_CREATED).extract().path("parentJobExecutionId");
DeleteJobExecutionsReq deleteJobExecutionsReq = new DeleteJobExecutionsReq().withIds(Arrays.asList(parentJobExecutionId));
RestAssured.given().spec(spec).body(deleteJobExecutionsReq).when().delete(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_OK).body("jobExecutionDetails.isDeleted.get(0)", is(true)).body("jobExecutionDetails.jobExecutionId.get(0)", is(parentJobExecutionId));
}
use of org.folio.rest.jaxrs.model.File in project mod-source-record-manager by folio-org.
the class AbstractRestTest method constructAndPostInitJobExecutionRqDto.
protected InitJobExecutionsRsDto constructAndPostInitJobExecutionRqDto(int filesNumber) {
InitJobExecutionsRqDto requestDto = new InitJobExecutionsRqDto();
String jsonFiles;
List<File> filesList;
try {
jsonFiles = TestUtil.readFileFromPath(FILES_PATH);
filesList = new ObjectMapper().readValue(jsonFiles, new TypeReference<>() {
});
} catch (IOException e) {
throw new RuntimeException(e);
}
List<File> limitedFilesList = filesList.stream().limit(filesNumber).collect(Collectors.toList());
requestDto.getFiles().addAll(limitedFilesList);
requestDto.setUserId(okapiUserIdHeader);
requestDto.setSourceType(InitJobExecutionsRqDto.SourceType.FILES);
return RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().post(JOB_EXECUTION_PATH).body().as(InitJobExecutionsRsDto.class);
}
use of org.folio.rest.jaxrs.model.File in project mod-source-record-manager by folio-org.
the class ChangeManagerAPITest method testDeleteChangeManagerJobExecutionsMultipleIds.
@Test
public void testDeleteChangeManagerJobExecutionsMultipleIds() {
// given
String jsonFiles;
List<File> filesList;
try {
jsonFiles = TestUtil.readFileFromPath(FILES_PATH);
filesList = new ObjectMapper().readValue(jsonFiles, new TypeReference<>() {
});
} catch (IOException e) {
throw new RuntimeException(e);
}
List<File> limitedFilesList = filesList.stream().limit(1).collect(Collectors.toList());
String stubUserId = UUID.randomUUID().toString();
WireMock.stubFor(get(GET_USER_URL + stubUserId).willReturn(okJson(userResponse.toString())));
InitJobExecutionsRqDto requestDto = new InitJobExecutionsRqDto();
requestDto.getFiles().addAll(limitedFilesList);
requestDto.setUserId(stubUserId);
requestDto.setSourceType(InitJobExecutionsRqDto.SourceType.FILES);
// when
String parentJobExecutionId = RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().post(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_CREATED).extract().path("parentJobExecutionId");
// when
String parentJobExecutionId_2 = RestAssured.given().spec(spec).body(JsonObject.mapFrom(requestDto).toString()).when().post(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_CREATED).extract().path("parentJobExecutionId");
DeleteJobExecutionsReq deleteJobExecutionsReq = new DeleteJobExecutionsReq().withIds(Arrays.asList(parentJobExecutionId, parentJobExecutionId_2));
RestAssured.given().spec(spec).body(deleteJobExecutionsReq).when().delete(JOB_EXECUTION_PATH).then().statusCode(HttpStatus.SC_OK).body("jobExecutionDetails.jobExecutionId.get(0)", is(parentJobExecutionId)).body("jobExecutionDetails.isDeleted.get(0)", is(true)).body("jobExecutionDetails.jobExecutionId.get(1)", is(parentJobExecutionId_2)).body("jobExecutionDetails.isDeleted.get(1)", is(true));
}
Aggregations