Search in sources :

Example 1 with DocumentRetrieveResponse

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"));
}
Also used : DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) Arrays(java.util.Arrays) EnqueueCollector(dk.dbc.search.solrdocstore.enqueue.EnqueueCollector) OpenAgencyUtil.makeOpenAgencyEntity(dk.dbc.search.solrdocstore.OpenAgencyUtil.makeOpenAgencyEntity) Matchers.not(org.hamcrest.Matchers.not) BeanFactoryUtil.createDocumentRetrieveBean(dk.dbc.search.solrdocstore.BeanFactoryUtil.createDocumentRetrieveBean) JpaTestEnvironment(dk.dbc.commons.persistence.JpaTestEnvironment) SQLException(java.sql.SQLException) BeanFactoryUtil.createHoldingsItemBean(dk.dbc.search.solrdocstore.BeanFactoryUtil.createHoldingsItemBean) IndexKeysList(dk.dbc.search.solrdocstore.jpa.IndexKeysList) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) TypeReference(com.fasterxml.jackson.core.type.TypeReference) DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) Before(org.junit.Before) COMMON_AGENCY(dk.dbc.search.solrdocstore.OpenAgencyUtil.COMMON_AGENCY) Matchers.empty(org.hamcrest.Matchers.empty) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) Matchers(org.hamcrest.Matchers) Set(java.util.Set) Test(org.junit.Test) IOException(java.io.IOException) EntityManager(javax.persistence.EntityManager) BeanFactoryUtil.createHoldingsToBibliographicBean(dk.dbc.search.solrdocstore.BeanFactoryUtil.createHoldingsToBibliographicBean) Collectors(java.util.stream.Collectors) BeanFactoryUtil.createBibliographicBean(dk.dbc.search.solrdocstore.BeanFactoryUtil.createBibliographicBean) List(java.util.List) QueueType(dk.dbc.search.solrdocstore.jpa.QueueType) Matchers.is(org.hamcrest.Matchers.is) Collections(java.util.Collections) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) Test(org.junit.Test)

Example 2 with DocumentRetrieveResponse

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();
    }
}
Also used : DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) LogWith(dk.dbc.log.LogWith) UnitRetrieveResponse(dk.dbc.search.solrdocstore.response.UnitRetrieveResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(org.eclipse.microprofile.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 3 with DocumentRetrieveResponse

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;
}
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 4 with DocumentRetrieveResponse

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;
}
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 5 with DocumentRetrieveResponse

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));
}
Also used : DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) IndexKeysList(dk.dbc.search.solrdocstore.jpa.IndexKeysList) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) Test(org.junit.Test)

Aggregations

DocumentRetrieveResponse (dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse)10 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)8 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)7 List (java.util.List)6 Collectors (java.util.stream.Collectors)6 Collections (java.util.Collections)5 EntityManager (javax.persistence.EntityManager)5 LogWith (dk.dbc.log.LogWith)4 Test (org.junit.Test)4 TypeReference (com.fasterxml.jackson.core.type.TypeReference)3 JpaTestEnvironment (dk.dbc.commons.persistence.JpaTestEnvironment)3 BeanFactoryUtil.createBibliographicBean (dk.dbc.search.solrdocstore.BeanFactoryUtil.createBibliographicBean)3 BeanFactoryUtil.createDocumentRetrieveBean (dk.dbc.search.solrdocstore.BeanFactoryUtil.createDocumentRetrieveBean)3 BeanFactoryUtil.createHoldingsItemBean (dk.dbc.search.solrdocstore.BeanFactoryUtil.createHoldingsItemBean)3 AgencyClassifierItemKey (dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey)3 BibliographicResourceEntity (dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity)3 HoldingsToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity)3 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)3 IndexKeysList (dk.dbc.search.solrdocstore.jpa.IndexKeysList)3 LibraryType (dk.dbc.search.solrdocstore.jpa.LibraryType)3