Search in sources :

Example 1 with LibraryType

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;
}
Also used : DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) HoldingsInfo(dk.dbc.search.solrdocstore.response.HoldingsInfo) QueryParam(javax.ws.rs.QueryParam) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) Timed(org.eclipse.microprofile.metrics.annotation.Timed) UnitRetrieveResponse(dk.dbc.search.solrdocstore.response.UnitRetrieveResponse) LogWith.track(dk.dbc.log.LogWith.track) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) LogWith(dk.dbc.log.LogWith) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Collectors(java.util.stream.Collectors) AgencyClassifierItemKey(dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey) List(java.util.List) Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) Collections(java.util.Collections) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) WorkRetrieveResponse(dk.dbc.search.solrdocstore.response.WorkRetrieveResponse) HoldingsInfo(dk.dbc.search.solrdocstore.response.HoldingsInfo) LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) ArrayList(java.util.ArrayList) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with LibraryType

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;
}
Also used : DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) HoldingsInfo(dk.dbc.search.solrdocstore.response.HoldingsInfo) QueryParam(javax.ws.rs.QueryParam) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) Timed(org.eclipse.microprofile.metrics.annotation.Timed) UnitRetrieveResponse(dk.dbc.search.solrdocstore.response.UnitRetrieveResponse) LogWith.track(dk.dbc.log.LogWith.track) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) LogWith(dk.dbc.log.LogWith) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) Context(javax.ws.rs.core.Context) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Collectors(java.util.stream.Collectors) AgencyClassifierItemKey(dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey) List(java.util.List) Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) Collections(java.util.Collections) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) WorkRetrieveResponse(dk.dbc.search.solrdocstore.response.WorkRetrieveResponse) HoldingsInfo(dk.dbc.search.solrdocstore.response.HoldingsInfo) LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) ArrayList(java.util.ArrayList) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) HashMap(java.util.HashMap) Map(java.util.Map)

Example 3 with LibraryType

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();
}
Also used : SQLException(java.sql.SQLException) LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) AgencyItemFieldKey(dk.dbc.search.solrdocstore.jpa.AgencyItemFieldKey) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) StatusResponse(dk.dbc.search.solrdocstore.response.StatusResponse) EJBException(javax.ejb.EJBException) EnqueueCollector(dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)

Example 4 with LibraryType

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);
}
Also used : LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity)

Example 5 with LibraryType

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;
            }
    }
}
Also used : LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) Timed(org.eclipse.microprofile.metrics.annotation.Timed)

Aggregations

LibraryType (dk.dbc.search.solrdocstore.jpa.LibraryType)6 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)4 BibliographicResourceEntity (dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity)4 OpenAgencyEntity (dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity)4 AgencyClassifierItemKey (dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey)3 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)3 DocumentRetrieveResponse (dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Timed (org.eclipse.microprofile.metrics.annotation.Timed)3 LogWith (dk.dbc.log.LogWith)2 LogWith.track (dk.dbc.log.LogWith.track)2 HoldingsInfo (dk.dbc.search.solrdocstore.response.HoldingsInfo)2 UnitRetrieveResponse (dk.dbc.search.solrdocstore.response.UnitRetrieveResponse)2 WorkRetrieveResponse (dk.dbc.search.solrdocstore.response.WorkRetrieveResponse)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Stateless (javax.ejb.Stateless)2