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);
}
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();
}
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"));
}
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);
}
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());
}
Aggregations