Search in sources :

Example 1 with Title

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

the class EholdingsResourcesImpl method postEholdingsResources.

@Override
@HandleValidationErrors
public void postEholdingsResources(String contentType, ResourcePostRequest entity, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
    postValidator.validate(entity);
    ResourcePostDataAttributes attributes = entity.getData().getAttributes();
    long titleId = parseTitleId(attributes.getTitleId());
    PackageId packageId = parsePackageId(attributes.getPackageId());
    templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> (CompletableFuture<?>) getObjectsForPostResource(titleId, packageId, context.getTitlesService(), context.getPackagesService()).thenCompose(result -> {
        Title title = result.getTitle();
        postValidator.validateRelatedObjects(result.getPackageData(), title, result.getTitles());
        ResourceSelectedPayload postRequest = new ResourceSelectedPayload(true, title.getTitleName(), title.getPubType(), attributes.getUrl());
        ResourceId resourceId = ResourceId.builder().providerIdPart(packageId.getProviderIdPart()).packageIdPart(packageId.getPackageIdPart()).titleIdPart(titleId).build();
        return context.getResourcesService().postResource(postRequest, resourceId);
    }).thenCompose(title -> CompletableFuture.completedFuture(new ResourceResult(title, null, null, false)))).addErrorMapper(InputValidationException.class, error422InputValidationMapper()).executeWithResult(Resource.class);
}
Also used : ResourcePostDataAttributes(org.folio.rest.jaxrs.model.ResourcePostDataAttributes) RMAPITemplateFactory(org.folio.rest.util.template.RMAPITemplateFactory) ResourcePostBulkFetchRequest(org.folio.rest.jaxrs.model.ResourcePostBulkFetchRequest) TagRepository(org.folio.repository.tag.TagRepository) ExceptionMappers.error400NotFoundMapper(org.folio.rest.util.ExceptionMappers.error400NotFoundMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) ResourcePutRequest(org.folio.rest.jaxrs.model.ResourcePutRequest) AccessTypeMappingsService(org.folio.service.accesstypes.AccessTypeMappingsService) Context(io.vertx.core.Context) PackageId(org.folio.holdingsiq.model.PackageId) AccessType(org.folio.rest.jaxrs.model.AccessType) JSONAPI(org.folio.rest.util.RestConstants.JSONAPI) RowSetUtils(org.folio.db.RowSetUtils) AccessTypesService(org.folio.service.accesstypes.AccessTypesService) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors) ResourcePostValidator(org.folio.rest.validator.ResourcePostValidator) ListUtils.parseByComma(org.folio.common.ListUtils.parseByComma) Map(java.util.Map) TitlesHoldingsIQService(org.folio.holdingsiq.service.TitlesHoldingsIQService) PackagesHoldingsIQService(org.folio.holdingsiq.service.PackagesHoldingsIQService) EholdingsResources(org.folio.rest.jaxrs.resource.EholdingsResources) OkapiData(org.folio.holdingsiq.model.OkapiData) ResourceTagsPutBodyValidator(org.folio.rest.validator.ResourceTagsPutBodyValidator) DbResource(org.folio.repository.resources.DbResource) IdParser.parseTitleId(org.folio.rest.util.IdParser.parseTitleId) UUID(java.util.UUID) Future(io.vertx.core.Future) FilterQuery(org.folio.holdingsiq.model.FilterQuery) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) CompletionStage(java.util.concurrent.CompletionStage) Response(javax.ws.rs.core.Response) ResourceBulkFetchCollection(org.folio.rest.jaxrs.model.ResourceBulkFetchCollection) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) CONTENT_TYPE(org.apache.http.protocol.HTTP.CONTENT_TYPE) SC_NOT_FOUND(org.apache.http.HttpStatus.SC_NOT_FOUND) UserKbCredentialsService(org.folio.service.kbcredentials.UserKbCredentialsService) RecordKey(org.folio.repository.RecordKey) RecordType(org.folio.repository.RecordType) IdParser.parsePackageId(org.folio.rest.util.IdParser.parsePackageId) IdParser.parseResourceId(org.folio.rest.util.IdParser.parseResourceId) ResourceTagsPutRequest(org.folio.rest.jaxrs.model.ResourceTagsPutRequest) ResourceRequestConverter(org.folio.rest.converter.resources.ResourceRequestConverter) Sort(org.folio.holdingsiq.model.Sort) CompletableFuture(java.util.concurrent.CompletableFuture) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Function(java.util.function.Function) InputValidationException(org.folio.rest.exception.InputValidationException) SpringContextUtil(org.folio.spring.SpringContextUtil) ErrorUtil.createError(org.folio.rest.util.ErrorUtil.createError) ResourceSelectedPayload(org.folio.holdingsiq.model.ResourceSelectedPayload) ResourcePostRequest(org.folio.rest.jaxrs.model.ResourcePostRequest) ResourceTags(org.folio.rest.jaxrs.model.ResourceTags) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ResourceRepository(org.folio.repository.resources.ResourceRepository) RelatedEntitiesLoader(org.folio.service.loader.RelatedEntitiesLoader) AsyncResult(io.vertx.core.AsyncResult) SearchProperties(org.folio.properties.common.SearchProperties) RMAPITemplate(org.folio.rest.util.template.RMAPITemplate) ResourceId(org.folio.holdingsiq.model.ResourceId) Title(org.folio.holdingsiq.model.Title) IdParser.resourceIdToString(org.folio.rest.util.IdParser.resourceIdToString) JSON_API_TYPE(org.folio.rest.util.RestConstants.JSON_API_TYPE) Resource(org.folio.rest.jaxrs.model.Resource) ResourceTagsItem(org.folio.rest.jaxrs.model.ResourceTagsItem) IdParser(org.folio.rest.util.IdParser) ResourcePostDataAttributes(org.folio.rest.jaxrs.model.ResourcePostDataAttributes) ExceptionMappers.error422InputValidationMapper(org.folio.rest.util.ExceptionMappers.error422InputValidationMapper) Vertx(io.vertx.core.Vertx) ResourceNotFoundException(org.folio.holdingsiq.service.exception.ResourceNotFoundException) ErrorHandler(org.folio.rest.util.ErrorHandler) ObjectsForPostResourceResult(org.folio.rmapi.result.ObjectsForPostResourceResult) CustomerResources(org.folio.holdingsiq.model.CustomerResources) IdParser.getResourceId(org.folio.rest.util.IdParser.getResourceId) TAGS_TYPE(org.folio.rest.util.RestConstants.TAGS_TYPE) ResourcePut(org.folio.holdingsiq.model.ResourcePut) Handler(io.vertx.core.Handler) ResourceTagsDataAttributes(org.folio.rest.jaxrs.model.ResourceTagsDataAttributes) ResourcePutBodyValidator(org.folio.rest.validator.ResourcePutBodyValidator) ResourceResult(org.folio.rmapi.result.ResourceResult) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) ObjectsForPostResourceResult(org.folio.rmapi.result.ObjectsForPostResourceResult) ResourceResult(org.folio.rmapi.result.ResourceResult) IdParser.parseResourceId(org.folio.rest.util.IdParser.parseResourceId) ResourceId(org.folio.holdingsiq.model.ResourceId) IdParser.getResourceId(org.folio.rest.util.IdParser.getResourceId) ResourceSelectedPayload(org.folio.holdingsiq.model.ResourceSelectedPayload) Title(org.folio.holdingsiq.model.Title) PackageId(org.folio.holdingsiq.model.PackageId) IdParser.parsePackageId(org.folio.rest.util.IdParser.parsePackageId) InputValidationException(org.folio.rest.exception.InputValidationException) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors)

Example 2 with Title

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

the class EholdingsResourcesImpl method deleteEholdingsResourcesByResourceId.

@Override
@HandleValidationErrors
public void deleteEholdingsResourcesByResourceId(String resourceId, Map<String, String> okapiHeaders, Handler<AsyncResult<Response>> asyncResultHandler, Context vertxContext) {
    ResourceId parsedResourceId = parseResourceId(resourceId);
    templateFactory.createTemplate(okapiHeaders, asyncResultHandler).requestAction(context -> context.getResourcesService().retrieveResource(parsedResourceId).thenCompose(title -> {
        if (BooleanUtils.isNotTrue(title.getCustomerResourcesList().get(0).getIsPackageCustom())) {
            throw new InputValidationException(RESOURCE_CANNOT_BE_DELETED_TITLE, RESOURCE_CANNOT_BE_DELETED_DETAIL);
        }
        return context.getResourcesService().deleteResource(parsedResourceId);
    }).thenCompose(o -> deleteAssignedResources(resourceId, context))).execute();
}
Also used : RMAPITemplateFactory(org.folio.rest.util.template.RMAPITemplateFactory) ResourcePostBulkFetchRequest(org.folio.rest.jaxrs.model.ResourcePostBulkFetchRequest) TagRepository(org.folio.repository.tag.TagRepository) ExceptionMappers.error400NotFoundMapper(org.folio.rest.util.ExceptionMappers.error400NotFoundMapper) Autowired(org.springframework.beans.factory.annotation.Autowired) ResourcePutRequest(org.folio.rest.jaxrs.model.ResourcePutRequest) AccessTypeMappingsService(org.folio.service.accesstypes.AccessTypeMappingsService) Context(io.vertx.core.Context) PackageId(org.folio.holdingsiq.model.PackageId) AccessType(org.folio.rest.jaxrs.model.AccessType) JSONAPI(org.folio.rest.util.RestConstants.JSONAPI) RowSetUtils(org.folio.db.RowSetUtils) AccessTypesService(org.folio.service.accesstypes.AccessTypesService) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors) ResourcePostValidator(org.folio.rest.validator.ResourcePostValidator) ListUtils.parseByComma(org.folio.common.ListUtils.parseByComma) Map(java.util.Map) TitlesHoldingsIQService(org.folio.holdingsiq.service.TitlesHoldingsIQService) PackagesHoldingsIQService(org.folio.holdingsiq.service.PackagesHoldingsIQService) EholdingsResources(org.folio.rest.jaxrs.resource.EholdingsResources) OkapiData(org.folio.holdingsiq.model.OkapiData) ResourceTagsPutBodyValidator(org.folio.rest.validator.ResourceTagsPutBodyValidator) DbResource(org.folio.repository.resources.DbResource) IdParser.parseTitleId(org.folio.rest.util.IdParser.parseTitleId) UUID(java.util.UUID) Future(io.vertx.core.Future) FilterQuery(org.folio.holdingsiq.model.FilterQuery) NotFoundException(javax.ws.rs.NotFoundException) Objects(java.util.Objects) List(java.util.List) CollectionUtils.isNotEmpty(org.apache.commons.collections4.CollectionUtils.isNotEmpty) CompletionStage(java.util.concurrent.CompletionStage) Response(javax.ws.rs.core.Response) ResourceBulkFetchCollection(org.folio.rest.jaxrs.model.ResourceBulkFetchCollection) RMAPITemplateContext(org.folio.rest.util.template.RMAPITemplateContext) CONTENT_TYPE(org.apache.http.protocol.HTTP.CONTENT_TYPE) SC_NOT_FOUND(org.apache.http.HttpStatus.SC_NOT_FOUND) UserKbCredentialsService(org.folio.service.kbcredentials.UserKbCredentialsService) RecordKey(org.folio.repository.RecordKey) RecordType(org.folio.repository.RecordType) IdParser.parsePackageId(org.folio.rest.util.IdParser.parsePackageId) IdParser.parseResourceId(org.folio.rest.util.IdParser.parseResourceId) ResourceTagsPutRequest(org.folio.rest.jaxrs.model.ResourceTagsPutRequest) ResourceRequestConverter(org.folio.rest.converter.resources.ResourceRequestConverter) Sort(org.folio.holdingsiq.model.Sort) CompletableFuture(java.util.concurrent.CompletableFuture) BooleanUtils(org.apache.commons.lang3.BooleanUtils) Function(java.util.function.Function) InputValidationException(org.folio.rest.exception.InputValidationException) SpringContextUtil(org.folio.spring.SpringContextUtil) ErrorUtil.createError(org.folio.rest.util.ErrorUtil.createError) ResourceSelectedPayload(org.folio.holdingsiq.model.ResourceSelectedPayload) ResourcePostRequest(org.folio.rest.jaxrs.model.ResourcePostRequest) ResourceTags(org.folio.rest.jaxrs.model.ResourceTags) Qualifier(org.springframework.beans.factory.annotation.Qualifier) ResourceRepository(org.folio.repository.resources.ResourceRepository) RelatedEntitiesLoader(org.folio.service.loader.RelatedEntitiesLoader) AsyncResult(io.vertx.core.AsyncResult) SearchProperties(org.folio.properties.common.SearchProperties) RMAPITemplate(org.folio.rest.util.template.RMAPITemplate) ResourceId(org.folio.holdingsiq.model.ResourceId) Title(org.folio.holdingsiq.model.Title) IdParser.resourceIdToString(org.folio.rest.util.IdParser.resourceIdToString) JSON_API_TYPE(org.folio.rest.util.RestConstants.JSON_API_TYPE) Resource(org.folio.rest.jaxrs.model.Resource) ResourceTagsItem(org.folio.rest.jaxrs.model.ResourceTagsItem) IdParser(org.folio.rest.util.IdParser) ResourcePostDataAttributes(org.folio.rest.jaxrs.model.ResourcePostDataAttributes) ExceptionMappers.error422InputValidationMapper(org.folio.rest.util.ExceptionMappers.error422InputValidationMapper) Vertx(io.vertx.core.Vertx) ResourceNotFoundException(org.folio.holdingsiq.service.exception.ResourceNotFoundException) ErrorHandler(org.folio.rest.util.ErrorHandler) ObjectsForPostResourceResult(org.folio.rmapi.result.ObjectsForPostResourceResult) CustomerResources(org.folio.holdingsiq.model.CustomerResources) IdParser.getResourceId(org.folio.rest.util.IdParser.getResourceId) TAGS_TYPE(org.folio.rest.util.RestConstants.TAGS_TYPE) ResourcePut(org.folio.holdingsiq.model.ResourcePut) Handler(io.vertx.core.Handler) ResourceTagsDataAttributes(org.folio.rest.jaxrs.model.ResourceTagsDataAttributes) ResourcePutBodyValidator(org.folio.rest.validator.ResourcePutBodyValidator) ResourceResult(org.folio.rmapi.result.ResourceResult) PackageByIdData(org.folio.holdingsiq.model.PackageByIdData) IdParser.parseResourceId(org.folio.rest.util.IdParser.parseResourceId) ResourceId(org.folio.holdingsiq.model.ResourceId) IdParser.getResourceId(org.folio.rest.util.IdParser.getResourceId) InputValidationException(org.folio.rest.exception.InputValidationException) HandleValidationErrors(org.folio.rest.aspect.HandleValidationErrors)

Example 3 with Title

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

the class PackageResponseConverterTest method shouldReturnCustomCoverageInDescendingOrder.

@Test
public void shouldReturnCustomCoverageInDescendingOrder() throws URISyntaxException, IOException {
    ObjectMapper mapper = new ObjectMapper();
    Title title = mapper.readValue(getFile("responses/rmapi/titles/get-custom-title-with-coverage-dates-asc.json"), Title.class);
    final ResourceResult resourceResult = new ResourceResult(title, null, null, false);
    final Resource resource = conversionService.convert(resourceResult, Resource.class);
    final List<Coverage> customCoverages = resource.getData().getAttributes().getCustomCoverages();
    assertThat(customCoverages.size(), equalTo(2));
    assertThat(customCoverages.get(0).getBeginCoverage(), equalTo("2004-03-01"));
    assertThat(customCoverages.get(0).getEndCoverage(), equalTo("2004-03-04"));
    assertThat(customCoverages.get(1).getBeginCoverage(), equalTo("2001-01-01"));
    assertThat(customCoverages.get(1).getEndCoverage(), equalTo("2004-02-01"));
}
Also used : ResourceResult(org.folio.rmapi.result.ResourceResult) Resource(org.folio.rest.jaxrs.model.Resource) Title(org.folio.holdingsiq.model.Title) Coverage(org.folio.rest.jaxrs.model.Coverage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 4 with Title

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

the class TitlesServiceImpl method updateCache.

public void updateCache(Title title) {
    var cacheKey = buildTitleCacheKey(title.getTitleId());
    Title cachedTitle = titleCache.getValue(cacheKey);
    if (!Objects.isNull(cachedTitle)) {
        mergeCustomerResources(cachedTitle, title);
    }
    titleCache.putValue(cacheKey, title);
}
Also used : Title(org.folio.holdingsiq.model.Title)

Example 5 with Title

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

the class TitleServiceImplTest method shouldUpdateCachedTitle.

@Test
public void shouldUpdateCachedTitle() {
    var titleCache = mock(VertxCache.class);
    var service = new TitlesServiceImpl(configuration, Vertx.vertx(), STUB_TENANT, titleCache);
    when(titleCache.getValue(any(TitleCacheKey.class))).thenReturn(buildTitleWithCustomerResource(1));
    Title title = buildTitleWithCustomerResource(2);
    service.updateCache(title);
    assertEquals(2, title.getCustomerResourcesList().size());
}
Also used : Title(org.folio.holdingsiq.model.Title) TitleCacheKey(org.folio.rmapi.cache.TitleCacheKey) Test(org.junit.Test)

Aggregations

Title (org.folio.holdingsiq.model.Title)9 PackageByIdData (org.folio.holdingsiq.model.PackageByIdData)4 ResourceResult (org.folio.rmapi.result.ResourceResult)4 Test (org.junit.Test)4 List (java.util.List)3 CustomerResources (org.folio.holdingsiq.model.CustomerResources)3 PackageId (org.folio.holdingsiq.model.PackageId)3 ResourceId (org.folio.holdingsiq.model.ResourceId)3 ResourcePut (org.folio.holdingsiq.model.ResourcePut)3 DbResource (org.folio.repository.resources.DbResource)3 Resource (org.folio.rest.jaxrs.model.Resource)3 AsyncResult (io.vertx.core.AsyncResult)2 Context (io.vertx.core.Context)2 Future (io.vertx.core.Future)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