Search in sources :

Example 1 with BibliographicResourceEntity

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;
}
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) 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) LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) 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) WorkRetrieveResponse(dk.dbc.search.solrdocstore.response.WorkRetrieveResponse) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) 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 BibliographicResourceEntity

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);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) AddResourceRequest(dk.dbc.search.solrdocstore.request.AddResourceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Example 3 with BibliographicResourceEntity

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();
}
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 BibliographicResourceEntity

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)));
}
Also used : Response(javax.ws.rs.core.Response) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) List(java.util.List) Test(org.junit.Test)

Example 5 with BibliographicResourceEntity

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)));
}
Also used : BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) Test(org.junit.Test)

Aggregations

BibliographicResourceEntity (dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity)15 OpenAgencyEntity (dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity)9 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)8 Test (org.junit.Test)7 Response (javax.ws.rs.core.Response)5 LogWith (dk.dbc.log.LogWith)4 AgencyItemFieldKey (dk.dbc.search.solrdocstore.jpa.AgencyItemFieldKey)4 Path (javax.ws.rs.Path)4 Produces (javax.ws.rs.Produces)4 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)3 LibraryType (dk.dbc.search.solrdocstore.jpa.LibraryType)3 AddResourceRequest (dk.dbc.search.solrdocstore.request.AddResourceRequest)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 Consumes (javax.ws.rs.Consumes)3 AgencyClassifierItemKey (dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey)2 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)2 DocumentRetrieveResponse (dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse)2 List (java.util.List)2 Operation (org.eclipse.microprofile.openapi.annotations.Operation)2