use of dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity in project solr-document-store by DBCDK.
the class DocumentRetrieveBean method getDocumentsForWork.
public List<DocumentRetrieveResponse> getDocumentsForWork(String workId, boolean includeHoldingsItemsIndexKeys) throws Exception {
List<DocumentRetrieveResponse> res = new ArrayList<>();
List<BibliographicEntity> bibliographicEntities = BibliographicEntity.fetchByWork(entityManager, workId);
List<HoldingsInfo> holdingsObjs = entityManager.createQuery(SELECT_HOLDINGS_ITEMS_FOR_WORK_JPA, HoldingsInfo.class).setParameter("workId", workId).getResultList();
for (BibliographicEntity b : bibliographicEntities) {
List<HoldingsItemEntity> holdingsItemEntityList = holdingsObjs.stream().filter(ho -> ho.holdingsToBibliographicEntity.getBibliographicAgencyId() == b.getAgencyId() && ho.holdingsToBibliographicEntity.getBibliographicRecordId().equals(b.getBibliographicRecordId())).map(h -> h.holdingsItemEntity).map(h -> includeHoldingsItemsIndexKeys ? h : h.copyForLightweightPresentation()).collect(Collectors.toList());
List<Integer> partOfDanbib = b.getAgencyId() == LibraryType.COMMON_AGENCY ? getPartOfDanbibCommon(b.getBibliographicRecordId()) : Collections.EMPTY_LIST;
LibraryType lt = oaBean.lookup(b.getAgencyId()).getLibraryType();
List<BibliographicResourceEntity> resources = agencyLibTypeCommon(b.getAgencyId(), lt) ? brrBean.getResourcesForCommon(b.getBibliographicRecordId()) : brrBean.getResourcesFor(b.getAgencyId(), b.getBibliographicRecordId());
Map<String, Map<Integer, Boolean>> attachedResources = mapResources(resources);
DocumentRetrieveResponse r = new DocumentRetrieveResponse(b, holdingsItemEntityList, partOfDanbib, attachedResources);
res.add(r);
}
return res;
}
use of dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity in project solr-document-store by DBCDK.
the class ResourceBean method addResource.
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("add")
@Operation(operationId = "add-resource", summary = "Adds a resource to an item", description = "This operation sets the resource and connect" + " it to a number of manifestations item, if possible.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response addResource(String jsonContent) throws JSONBException {
try (LogWith logWith = track(UUID.randomUUID().toString())) {
AddResourceRequest request = jsonbContext.unmarshall(jsonContent, AddResourceRequest.class);
// Add resource
BibliographicResourceEntity resource = request.asBibliographicResource();
log.debug("POST resource: {}", resource);
return storeResource(resource);
}
}
use of dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity in project solr-document-store by DBCDK.
the class ResourceBean method storeResource.
private Response storeResource(BibliographicResourceEntity resource) {
// Verify agency exists, throws exception if not exist
LibraryType libraryType;
try {
OpenAgencyEntity oaEntity = openAgency.lookup(resource.getAgencyId());
libraryType = oaEntity.getLibraryType();
} catch (EJBException ex) {
return Response.ok().entity(new StatusResponse("Unknown agency")).build();
}
if (resource.getValue()) {
entityManager.merge(resource);
} else {
BibliographicResourceEntity entity = entityManager.find(BibliographicResourceEntity.class, new AgencyItemFieldKey(resource.getAgencyId(), resource.getBibliographicRecordId(), resource.getField()));
if (entity != null)
entityManager.remove(entity);
}
// Enqueue all related bib items
List<BibliographicEntity> bibliographicEntities;
if (LibraryType.COMMON_AGENCY == resource.getAgencyId() || LibraryType.SCHOOL_COMMON_AGENCY == resource.getAgencyId() || libraryType == LibraryType.FBS || libraryType == LibraryType.FBSSchool) {
bibliographicEntities = commonRelatedBibEntities(resource);
} else {
bibliographicEntities = nonFBSBibEntries(resource);
}
try {
EnqueueCollector enqueue = enqueueSupplier.getEnqueueCollector();
bibliographicEntities.forEach(e -> {
if (!e.isDeleted()) {
enqueue.add(e, QueueType.RESOURCE, QueueType.WORKRESOURCE);
}
});
enqueue.commit();
} catch (SQLException ex) {
log.error("Unable to commit queue entries: {}", ex.getMessage());
log.debug("Unable to commit queue entries: ", ex);
return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponse("Unable to commit queue entries")).build();
}
return Response.ok().entity(new StatusResponse()).build();
}
use of dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity in project solr-document-store by DBCDK.
the class BibliographicResourceIT method testGetResourcesByBibItem.
@Test
public void testGetResourcesByBibItem() {
System.out.println("testGetResourcesByBibItem");
Response response = bean.getResourcesByBibItem(870970, "11111111");
List<BibliographicResourceEntity> result = (List<BibliographicResourceEntity>) response.getEntity();
assertThat(result, containsInAnyOrder(new BibliographicResourceEntity(870970, "11111111", "hasCoverUrl", true), new BibliographicResourceEntity(870970, "11111111", "hasBackCoverUrl", false), new BibliographicResourceEntity(870970, "11111111", "includesCD", true)));
}
use of dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity in project solr-document-store by DBCDK.
the class BibliographicResourceRetrieveBeanIT method testCase.
@Test(timeout = 2_000L)
public void testCase() throws Exception {
System.out.println("testCase");
jpa(em -> {
em.merge(new OpenAgencyEntity(888888, LibraryType.NonFBS, true, true, true));
em.merge(new OpenAgencyEntity(710100, LibraryType.FBS, true, true, true));
em.merge(new OpenAgencyEntity(310100, LibraryType.FBSSchool, true, true, true));
em.merge(new BibliographicResourceEntity(888888, "a", "foo", true));
em.merge(new BibliographicResourceEntity(710100, "a", "foo", true));
em.merge(new BibliographicResourceEntity(710100, "a", "bar", false));
em.merge(new BibliographicResourceEntity(710100, "no", "bar", false));
em.merge(new BibliographicResourceEntity(310100, "a", "foo", false));
});
List<BibliographicResourceEntity> resourcesFor = bean.getResourcesFor(710100, "a");
System.out.println("resourcesFor = " + resourcesFor);
assertThat(resourcesFor, containsInAnyOrder(new BibliographicResourceEntity(710100, "a", "foo", true), new BibliographicResourceEntity(710100, "a", "bar", false)));
List<BibliographicResourceEntity> resourcesForCommon = bean.getResourcesForCommon("a");
System.out.println("resourcesForCommon = " + resourcesForCommon);
assertThat(resourcesForCommon, containsInAnyOrder(new BibliographicResourceEntity(710100, "a", "foo", true), new BibliographicResourceEntity(710100, "a", "bar", false), new BibliographicResourceEntity(310100, "a", "foo", false)));
}
Aggregations