Search in sources :

Example 1 with File

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;
}
Also used : JobExecution(org.folio.rest.jaxrs.model.JobExecution) JobProfileInfo(org.folio.rest.jaxrs.model.JobProfileInfo) ArrayList(java.util.ArrayList) File(org.folio.rest.jaxrs.model.File)

Example 2 with File

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"));
}
Also used : InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(org.folio.rest.jaxrs.model.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 3 with File

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));
}
Also used : DeleteJobExecutionsReq(org.folio.rest.jaxrs.model.DeleteJobExecutionsReq) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(org.folio.rest.jaxrs.model.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Example 4 with File

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);
}
Also used : InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(org.folio.rest.jaxrs.model.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Example 5 with File

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));
}
Also used : DeleteJobExecutionsReq(org.folio.rest.jaxrs.model.DeleteJobExecutionsReq) InitJobExecutionsRqDto(org.folio.rest.jaxrs.model.InitJobExecutionsRqDto) Matchers.containsString(org.hamcrest.Matchers.containsString) TypeReference(com.fasterxml.jackson.core.type.TypeReference) IOException(java.io.IOException) File(org.folio.rest.jaxrs.model.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AbstractRestTest(org.folio.rest.impl.AbstractRestTest) Test(org.junit.Test)

Aggregations

File (org.folio.rest.jaxrs.model.File)6 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)5 InitJobExecutionsRqDto (org.folio.rest.jaxrs.model.InitJobExecutionsRqDto)5 TypeReference (com.fasterxml.jackson.core.type.TypeReference)4 IOException (java.io.IOException)4 AbstractRestTest (org.folio.rest.impl.AbstractRestTest)4 Matchers.containsString (org.hamcrest.Matchers.containsString)4 Test (org.junit.Test)4 DeleteJobExecutionsReq (org.folio.rest.jaxrs.model.DeleteJobExecutionsReq)2 JsonObject (io.vertx.core.json.JsonObject)1 ArrayList (java.util.ArrayList)1 JobExecution (org.folio.rest.jaxrs.model.JobExecution)1 JobProfileInfo (org.folio.rest.jaxrs.model.JobProfileInfo)1