Search in sources :

Example 1 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-kb-ebsco-java by folio-org.

the class EholdingsTitlesTest method shouldUpdateTagsWhenValidPostRequest.

@Test
public void shouldUpdateTagsWhenValidPostRequest() throws IOException, URISyntaxException {
    List<String> tagList = Arrays.asList(STUB_TAG_VALUE, STUB_TAG_VALUE_2);
    Title actual = postTitle(tagList).as(Title.class);
    List<String> tagsFromDB = TagsTestUtil.getTags(vertx);
    assertThat(actual.getData().getAttributes().getTags().getTagList(), containsInAnyOrder(tagList.toArray()));
    assertThat(tagsFromDB, containsInAnyOrder(tagList.toArray()));
}
Also used : DbTitle(org.folio.repository.titles.DbTitle) Title(org.folio.rest.jaxrs.model.Title) AssertTestUtil.assertErrorContainsTitle(org.folio.util.AssertTestUtil.assertErrorContainsTitle) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 2 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-kb-ebsco-java by folio-org.

the class EholdingsTitlesImpl method putEholdingsTitlesByTitleId.

@Override
@HandleValidationErrors
public void putEholdingsTitlesByTitleId(String titleId, String contentType, TitlePutRequest entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
    titleCommonRequestAttributesValidator.validate(entity.getData().getAttributes());
    Long parsedTitleId = parseTitleId(titleId);
    templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> context.getTitlesService().retrieveTitle(parsedTitleId).thenCompose(title -> {
        if (BooleanUtils.isNotTrue(title.getIsTitleCustom())) {
            return completedFuture(null);
        }
        CustomerResources resource = title.getCustomerResourcesList().get(0);
        ResourcePut resourcePutRequest = titlePutRequestConverter.convertToRMAPICustomResourcePutRequest(entity, resource);
        String resourceId = resource.getVendorId() + "-" + resource.getPackageId() + "-" + resource.getTitleId();
        return context.getResourcesService().updateResource(parseResourceId(resourceId), resourcePutRequest);
    }).thenCompose(o -> context.getTitlesService().retrieveTitle(parsedTitleId)).thenCompose(title -> updateTags(toTitleResult(title, false), context, entity.getData().getAttributes().getTags()))).executeWithResult(Title.class);
}
Also used : RMAPITemplateFactory(org.folio.rest.util.template.RMAPITemplateFactory) Filter(org.folio.rest.model.filter.Filter) TagRepository(org.folio.repository.tag.TagRepository) TitleCollectionResult(org.folio.rmapi.result.TitleCollectionResult) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) Autowired(org.springframework.beans.factory.annotation.Autowired) Context(io.vertx.core.Context) PackageId(org.folio.holdingsiq.model.PackageId) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors) Map(java.util.Map) TitlesPostBodyValidator(org.folio.rest.validator.TitlesPostBodyValidator) TitlePutRequest(org.folio.rest.jaxrs.model.TitlePutRequest) EholdingsTitles(org.folio.rest.jaxrs.resource.EholdingsTitles) IdParser.parseTitleId(org.folio.rest.util.IdParser.parseTitleId) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) Objects(java.util.Objects) List(java.util.List) Response(javax.ws.rs.core.Response) ErrorUtil(org.folio.rest.util.ErrorUtil) TitlePostRequest(org.folio.rest.jaxrs.model.TitlePostRequest) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) ListUtils(org.folio.common.ListUtils) RecordKey(org.folio.repository.RecordKey) FilteredEntitiesLoader(org.folio.service.loader.FilteredEntitiesLoader) RecordType(org.folio.repository.RecordType) IdParser.parsePackageId(org.folio.rest.util.IdParser.parsePackageId) IdParser.parseResourceId(org.folio.rest.util.IdParser.parseResourceId) Tags(org.folio.rest.jaxrs.model.Tags) TitlesRepository(org.folio.repository.titles.TitlesRepository) CompletableFuture(java.util.concurrent.CompletableFuture) BooleanUtils(org.apache.commons.lang3.BooleanUtils) DbTitle(org.folio.repository.titles.DbTitle) SpringContextUtil(org.folio.spring.SpringContextUtil) TitlePost(org.folio.holdingsiq.model.TitlePost) Title(org.folio.rest.jaxrs.model.Title) RelatedEntitiesLoader(org.folio.service.loader.RelatedEntitiesLoader) AsyncResult(io.vertx.core.AsyncResult) SearchProperties(org.folio.properties.common.SearchProperties) Converter(org.springframework.core.convert.converter.Converter) TitleCommonRequestAttributesValidator(org.folio.rest.validator.TitleCommonRequestAttributesValidator) IdParser(org.folio.rest.util.IdParser) Vertx(io.vertx.core.Vertx) ResourceNotFoundException(org.folio.holdingsiq.service.exception.ResourceNotFoundException) Titles(org.folio.holdingsiq.model.Titles) Validate(org.folio.rest.annotations.Validate) CustomerResources(org.folio.holdingsiq.model.CustomerResources) TitlePutRequestConverter(org.folio.rest.converter.titles.TitlePutRequestConverter) TitleResult(org.folio.rmapi.result.TitleResult) TitleCollection(org.folio.rest.jaxrs.model.TitleCollection) ResourcePut(org.folio.holdingsiq.model.ResourcePut) Handler(io.vertx.core.Handler) CustomerResources(org.folio.holdingsiq.model.CustomerResources) ResourcePut(org.folio.holdingsiq.model.ResourcePut) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors)

Example 3 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-kb-ebsco-java by folio-org.

the class ResourceResultConverter method includeTitle.

private void includeTitle(org.folio.holdingsiq.model.Title rmapiTitle, Resource resultResource) {
    Title title = requireNonNull(titlesConverter.convert(new TitleResult(rmapiTitle, false)));
    resultResource.getIncluded().add(title.getData());
    resultResource.getData().getRelationships().withTitle(new HasOneRelationship().withData(new RelationshipData().withId(title.getData().getId()).withType(TITLES_TYPE)));
}
Also used : RelationshipData(org.folio.rest.jaxrs.model.RelationshipData) TitleResult(org.folio.rmapi.result.TitleResult) Title(org.folio.rest.jaxrs.model.Title) HasOneRelationship(org.folio.rest.jaxrs.model.HasOneRelationship)

Example 4 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-kb-ebsco-java by folio-org.

the class TitleConverter method convert.

@Override
public Title convert(@NonNull TitleResult titleResult) {
    org.folio.holdingsiq.model.Title rmapiTitle = titleResult.getTitle();
    Title title = new Title().withData(new Data().withId(String.valueOf(rmapiTitle.getTitleId())).withType(TITLES_TYPE).withAttributes(new TitleAttributes().withName(rmapiTitle.getTitleName()).withPublisherName(rmapiTitle.getPublisherName()).withIsTitleCustom(rmapiTitle.getIsTitleCustom()).withPublicationType(ConverterConsts.publicationTypes.get(rmapiTitle.getPubType().toLowerCase())).withSubjects(subjectsConverter.convert(rmapiTitle.getSubjectsList())).withIdentifiers(identifiersConverter.convert(rmapiTitle.getIdentifiersList())).withContributors(contributorsConverter.convert(rmapiTitle.getContributorsList())).withAlternateTitles(alternateTitleConverter.convert(rmapiTitle.getAlternateTitleList())).withEdition(rmapiTitle.getEdition()).withDescription(rmapiTitle.getDescription()).withIsPeerReviewed(rmapiTitle.getIsPeerReviewed()).withTags(titleResult.getTags())).withRelationships(createEmptyResourcesRelationships())).withIncluded(null).withJsonapi(RestConstants.JSONAPI);
    title.getData().getAttributes().setHasSelectedResources(matchesAny(rmapiTitle.getCustomerResourcesList(), CustomerResources::getIsSelected));
    includeResourcesIfNeeded(title, titleResult);
    return title;
}
Also used : AlternateTitle(org.folio.rest.jaxrs.model.AlternateTitle) Title(org.folio.rest.jaxrs.model.Title) Data(org.folio.rest.jaxrs.model.Data) RelationshipData(org.folio.rest.jaxrs.model.RelationshipData) TitleAttributes(org.folio.rest.jaxrs.model.TitleAttributes)

Example 5 with Title

use of org.folio.rest.jaxrs.model.Title in project mod-orders by folio-org.

the class OpenCompositeOrderPieceServiceTest method testShouldUpdateInventoryPositiveCaseIfLineIsPackageAndPieceContainsHoldingId.

@Test
void testShouldUpdateInventoryPositiveCaseIfLineIsPackageAndPieceContainsHoldingId() throws ExecutionException, InterruptedException {
    // given
    CompositePoLine line = getMockAsJson(COMPOSITE_LINES_PATH, LINE_ID).mapTo(CompositePoLine.class);
    String holdingId = UUID.randomUUID().toString();
    String itemId = UUID.randomUUID().toString();
    line.getLocations().get(0).withLocationId(null).withHoldingId(holdingId);
    line.setIsPackage(true);
    Title title = getMockAsJson(TILES_PATH, "title").mapTo(Title.class);
    Piece piece = createPieceWithHoldingId(line, title);
    doReturn(completedFuture(title)).when(titlesService).getTitleById(piece.getTitleId(), requestContext);
    doReturn(completedFuture(null)).when(titlesService).saveTitle(title, requestContext);
    doReturn(completedFuture(title)).when(inventoryManager).openOrderHandlePackageLineInstance(title, false, requestContext);
    doReturn(completedFuture(itemId)).when(inventoryManager).openOrderCreateItemRecord(line, holdingId, requestContext);
    // When
    openCompositeOrderPieceService.openOrderUpdateInventory(line, piece, false, requestContext).get();
    // Then
    assertEquals(holdingId, piece.getHoldingId());
    assertEquals(title.getId(), piece.getTitleId());
}
Also used : Piece(org.folio.rest.jaxrs.model.Piece) CompositePoLine(org.folio.rest.jaxrs.model.CompositePoLine) Title(org.folio.rest.jaxrs.model.Title) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

Title (org.folio.rest.jaxrs.model.Title)42 Test (org.junit.jupiter.api.Test)28 Piece (org.folio.rest.jaxrs.model.Piece)23 CompositePoLine (org.folio.rest.jaxrs.model.CompositePoLine)19 Location (org.folio.rest.jaxrs.model.Location)19 JsonObject (io.vertx.core.json.JsonObject)17 ArrayList (java.util.ArrayList)10 List (java.util.List)9 CompletableFuture (java.util.concurrent.CompletableFuture)8 Cost (org.folio.rest.jaxrs.model.Cost)8 PoLine (org.folio.rest.jaxrs.model.PoLine)8 PurchaseOrder (org.folio.rest.jaxrs.model.PurchaseOrder)8 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)7 Collectors (java.util.stream.Collectors)7 Eresource (org.folio.rest.jaxrs.model.Eresource)7 Context (io.vertx.core.Context)6 Map (java.util.Map)6 PieceUpdateHolder (org.folio.models.pieces.PieceUpdateHolder)6 Optional (java.util.Optional)5 LogManager (org.apache.logging.log4j.LogManager)5