use of dk.dbc.search.solrdocstore.jpa.LibraryType 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.jpa.LibraryType 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.LibraryType 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.UNITRESOURCE, 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.LibraryType in project solr-document-store by DBCDK.
the class BibliographicBean method addHoldingsToBibliographic.
private void addHoldingsToBibliographic(int agency, String recordId, int holdingsAgency, String bibliographicRecordId, EnqueueCollector enqueue, QueueType... enqueueSources) {
LibraryType libraryType = openAgency.lookup(holdingsAgency).getLibraryType();
boolean isCommonDerived = libraryType == LibraryType.FBS && h2bBean.bibliographicEntityExists(agency, bibliographicRecordId);
HoldingsToBibliographicEntity h2b = new HoldingsToBibliographicEntity(holdingsAgency, recordId, agency, bibliographicRecordId, isCommonDerived);
h2bBean.attachToAgency(h2b, enqueue, enqueueSources);
}
use of dk.dbc.search.solrdocstore.jpa.LibraryType in project solr-document-store by DBCDK.
the class HoldingsToBibliographicBean method tryToAttachToBibliographicRecord.
@Timed
public void tryToAttachToBibliographicRecord(int hAgencyId, String hBibliographicRecordId, EnqueueCollector enqueue, QueueType... enqueueSources) {
log.info("Update HoldingsToBibliographic for {} {}", hAgencyId, hBibliographicRecordId);
LibraryType libraryType = openAgency.lookup(hAgencyId).getLibraryType();
switch(libraryType) {
case NonFBS:
attachToBibliographicRecord(hAgencyId, hBibliographicRecordId, hBibliographicRecordId, false, enqueue, enqueueSources, hAgencyId);
break;
case FBS:
{
String liveBibliographicRecordId = findLiveBibliographicRecordId(hBibliographicRecordId);
boolean isCommonDerived = bibliographicEntityExists(870970, liveBibliographicRecordId);
attachToBibliographicRecord(hAgencyId, hBibliographicRecordId, liveBibliographicRecordId, isCommonDerived, enqueue, enqueueSources, hAgencyId, LibraryType.COMMON_AGENCY);
break;
}
case FBSSchool:
{
String liveBibliographicRecordId = findLiveBibliographicRecordId(hBibliographicRecordId);
attachToBibliographicRecord(hAgencyId, hBibliographicRecordId, liveBibliographicRecordId, false, enqueue, enqueueSources, hAgencyId, LibraryType.SCHOOL_COMMON_AGENCY, LibraryType.COMMON_AGENCY);
break;
}
}
}
Aggregations