use of dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse in project solr-document-store by DBCDK.
the class DocumentRetrieveBeanIT method getUnitWithHoldings.
@Test
public void getUnitWithHoldings() throws Exception {
System.out.println("getUnitWithHoldings");
List<DocumentRetrieveResponse> resp = env().getPersistenceContext().run(() -> {
build(300055).holdings(ON_SHELF);
build(800055).holdings(ON_SHELF);
build(710001, "CBA").holdings(ON_SHELF);
return bean.getDocumentsForUnit("unit:0", true);
});
assertThat(resp, is(not(empty())));
DocumentRetrieveResponse r = resp.get(0);
Set<String> holdings = r.holdingsItemRecords.stream().map(h -> h.getAgencyId() + "-" + h.getBibliographicRecordId()).collect(Collectors.toSet());
assertThat(holdings, Matchers.containsInAnyOrder("300055-ABC", "710001-CBA"));
}
use of dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse in project solr-document-store by DBCDK.
the class DocumentRetrieveBean method getUnitDocumentsWithHoldingsItems.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("unit/{ unitid }")
@Timed
public Response getUnitDocumentsWithHoldingsItems(@Context UriInfo uriInfo, @PathParam("unitid") String unitId, @DefaultValue("false") @QueryParam("includeHoldingsItemsIndexKeys") boolean includeHoldingsItemsIndexKeys) throws Exception {
log.debug("Fetching manifestations for unit {}, includeHIIK: {}", unitId, includeHoldingsItemsIndexKeys);
try (LogWith logWith = track(null)) {
List<DocumentRetrieveResponse> responses = getDocumentsForUnit(unitId, includeHoldingsItemsIndexKeys);
if (responses == null || responses.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).header("X-DBC-Status", "200").entity("Unit not found").build();
}
final UnitRetrieveResponse res = new UnitRetrieveResponse(unitId, responses);
return Response.ok(res).build();
} catch (Exception ex) {
log.error("Error retrieving documents for unit {}: {}", unitId, ex.getMessage());
log.debug("Error retrieving documents for unit {}: {}", unitId, ex);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error retrieving documents for unit").build();
}
}
use of dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse in project solr-document-store by DBCDK.
the class DocumentRetrieveBean method getDocumentsForUnit.
public List<DocumentRetrieveResponse> getDocumentsForUnit(String unitId, boolean includeHoldingsItemsIndexKeys) throws Exception {
List<DocumentRetrieveResponse> res = new ArrayList<>();
List<BibliographicEntity> bibliographicEntities = BibliographicEntity.fetchByUnit(entityManager, unitId);
List<HoldingsInfo> holdingsObjs = entityManager.createQuery(SELECT_HOLDINGS_ITEMS_FOR_UNIT_JPA, HoldingsInfo.class).setParameter("unitId", unitId).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.response.DocumentRetrieveResponse 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.response.DocumentRetrieveResponse in project solr-document-store by DBCDK.
the class DocumentRetrieveBeanIT method newCommonRecordWithExistingHoldings.
@Test
public void newCommonRecordWithExistingHoldings() throws Exception {
em.merge(new BibliographicEntity(300000, "clazzifier", "12345678", "id#1", "work:0", "unit:0", false, new IndexKeys(), "T1"));
em.merge(new HoldingsItemEntity(300101, "12345678", new IndexKeysList(), "T2"));
em.merge(new HoldingsItemEntity(300102, "12345678", new IndexKeysList(), "T3"));
em.merge(new HoldingsToBibliographicEntity(300101, "12345678", 300000, false));
em.merge(new HoldingsToBibliographicEntity(300102, "12345678", 300000, false));
DocumentRetrieveResponse doc = env().getPersistenceContext().run(() -> bean.getDocumentWithHoldingsitems(300000, "clazzifier", "12345678"));
assertThat(doc.bibliographicRecord.getAgencyId(), is(300000));
assertThat(doc.bibliographicRecord.getBibliographicRecordId(), is("12345678"));
assertThat(doc.holdingsItemRecords.size(), is(2));
}
Aggregations