Search in sources :

Example 1 with TitleResult

use of org.folio.rmapi.result.TitleResult 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 2 with TitleResult

use of org.folio.rmapi.result.TitleResult in project mod-kb-ebsco-java by folio-org.

the class EholdingsTitlesImpl method updateTags.

private CompletableFuture<TitleResult> updateTags(TitleResult result, RMAPITemplateContext context, Tags tags) {
    if (Objects.isNull(tags)) {
        return completedFuture(result);
    } else {
        String tenant = context.getOkapiData().getTenant();
        UUID credentialsId = toUUID(context.getCredentialsId());
        return updateStoredTitles(createDbTitle(result, credentialsId), tags, tenant).thenCompose(o -> tagRepository.updateRecordTags(tenant, String.valueOf(result.getTitle().getTitleId()), RecordType.TITLE, tags.getTagList())).thenApply(updated -> {
            result.setTags(new Tags().withTagList(tags.getTagList()));
            return result;
        });
    }
}
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) RowSetUtils.toUUID(org.folio.db.RowSetUtils.toUUID) UUID(java.util.UUID) Tags(org.folio.rest.jaxrs.model.Tags)

Example 3 with TitleResult

use of org.folio.rmapi.result.TitleResult in project mod-kb-ebsco-java by folio-org.

the class EholdingsTitlesImpl method postEholdingsTitles.

@Override
@HandleValidationErrors
public void postEholdingsTitles(String contentType, TitlePostRequest entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
    titlesPostBodyValidator.validate(entity);
    TitlePost titlePost = titlePostRequestConverter.convert(entity);
    PackageId packageId = parsePackageId(entity.getIncluded().get(0).getAttributes().getPackageId());
    templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> context.getTitlesService().postTitle(titlePost, packageId).thenCompose(title -> completedFuture(toTitleResult(title, false))).thenCompose(titleResult -> updateTags(titleResult, 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) PackageId(org.folio.holdingsiq.model.PackageId) IdParser.parsePackageId(org.folio.rest.util.IdParser.parsePackageId) TitlePost(org.folio.holdingsiq.model.TitlePost) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors)

Example 4 with TitleResult

use of org.folio.rmapi.result.TitleResult in project mod-kb-ebsco-java by folio-org.

the class EholdingsPackagesImpl method populateResourceTags.

private void populateResourceTags(Map<String, TitleResult> resourceIdToTitle, Map<String, List<DbTag>> tagMap) {
    tagMap.forEach((id, tags) -> {
        TitleResult titleResult = resourceIdToTitle.get(id);
        titleResult.setResourceTagList(tags);
    });
}
Also used : TitleResult(org.folio.rmapi.result.TitleResult)

Example 5 with TitleResult

use of org.folio.rmapi.result.TitleResult in project mod-kb-ebsco-java by folio-org.

the class TitleConverter method includeTagsIfNeeded.

private void includeTagsIfNeeded(Title title, TitleResult titleResult) {
    if (nonNull(titleResult.getResourceTagList())) {
        for (ResourceCollectionItem resourceCollectionItem : title.getIncluded()) {
            List<DbTag> tags = titleResult.getResourceTagList().stream().filter(tag -> resourceCollectionItem.getId().equals(tag.getRecordId())).collect(Collectors.toList());
            resourceCollectionItem.getAttributes().withTags(tagsConverter.convert(tags));
        }
    }
}
Also used : DbTag(org.folio.repository.tag.DbTag) TITLES_TYPE(org.folio.rest.util.RestConstants.TITLES_TYPE) Tags(org.folio.rest.jaxrs.model.Tags) Autowired(org.springframework.beans.factory.annotation.Autowired) MetaDataIncluded(org.folio.rest.jaxrs.model.MetaDataIncluded) TitleAttributes(org.folio.rest.jaxrs.model.TitleAttributes) Resources(org.folio.rest.jaxrs.model.Resources) StringUtils(org.apache.commons.lang3.StringUtils) AlternateTitle(org.folio.rest.jaxrs.model.AlternateTitle) Title(org.folio.rest.jaxrs.model.Title) TitleConverterUtils.createEmptyResourcesRelationships(org.folio.rest.converter.titles.TitleConverterUtils.createEmptyResourcesRelationships) Relationships(org.folio.rest.jaxrs.model.Relationships) IterableUtils.matchesAny(org.apache.commons.collections4.IterableUtils.matchesAny) ListUtils.mapItems(org.folio.common.ListUtils.mapItems) Comparator.nullsLast(java.util.Comparator.nullsLast) Comparator.comparing(java.util.Comparator.comparing) TitleSubject(org.folio.rest.jaxrs.model.TitleSubject) Converter(org.springframework.core.convert.converter.Converter) RestConstants(org.folio.rest.util.RestConstants) Comparator.comparingInt(java.util.Comparator.comparingInt) Subject(org.folio.holdingsiq.model.Subject) Resource(org.folio.rest.jaxrs.model.Resource) IdParser(org.folio.rest.util.IdParser) Collectors(java.util.stream.Collectors) DbTag(org.folio.repository.tag.DbTag) Data(org.folio.rest.jaxrs.model.Data) Contributor(org.folio.holdingsiq.model.Contributor) List(java.util.List) Component(org.springframework.stereotype.Component) CustomerResources(org.folio.holdingsiq.model.CustomerResources) Identifier(org.folio.holdingsiq.model.Identifier) Contributors(org.folio.rest.jaxrs.model.Contributors) ConverterConsts(org.folio.rest.converter.common.ConverterConsts) NonNull(org.springframework.lang.NonNull) TitleResult(org.folio.rmapi.result.TitleResult) Objects.nonNull(java.util.Objects.nonNull) Comparator(java.util.Comparator) RelationshipData(org.folio.rest.jaxrs.model.RelationshipData) ResourceResult(org.folio.rmapi.result.ResourceResult) ResourceCollectionItem(org.folio.rest.jaxrs.model.ResourceCollectionItem) ResourceCollectionItem(org.folio.rest.jaxrs.model.ResourceCollectionItem)

Aggregations

TitleResult (org.folio.rmapi.result.TitleResult)5 Title (org.folio.rest.jaxrs.model.Title)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 CustomerResources (org.folio.holdingsiq.model.CustomerResources)3 Tags (org.folio.rest.jaxrs.model.Tags)3 IdParser (org.folio.rest.util.IdParser)3 Autowired (org.springframework.beans.factory.annotation.Autowired)3 Converter (org.springframework.core.convert.converter.Converter)3 AsyncResult (io.vertx.core.AsyncResult)2 Context (io.vertx.core.Context)2 Handler (io.vertx.core.Handler)2 Vertx (io.vertx.core.Vertx)2 Map (java.util.Map)2 Objects (java.util.Objects)2 UUID (java.util.UUID)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)2 Response (javax.ws.rs.core.Response)2 BooleanUtils (org.apache.commons.lang3.BooleanUtils)2