Search in sources :

Example 1 with AgencyClassifierItemKey

use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.

the class BibliographicEntityIT method LoadEntity.

@Test
public void LoadEntity() {
    executeScriptResource("/entityTestData.sql");
    EntityManager em = env().getEntityManager();
    AgencyClassifierItemKey key = new AgencyClassifierItemKey(300, "clazzifier", "4321");
    BibliographicEntity be = env().getPersistenceContext().run(() -> em.find(BibliographicEntity.class, key));
    assertThat(be.getAgencyId(), is(300));
    assertThat(be.getClassifier(), is("clazzifier"));
    assertThat(be.getBibliographicRecordId(), is("4321"));
    assertThat(be.getWork(), is("work:3"));
    assertThat(be.getUnit(), is("unit:3"));
    assertThat(be.isDeleted(), is(true));
    IndexKeys expected = new IndexKeys();
    expected.put("ti", Arrays.asList("isdnBogen", "title2"));
    expected.put("001", Collections.singletonList("argle"));
    assertThat(be.getIndexKeys(), is(expected));
    assertThat(be.getTrackingId(), is("track"));
}
Also used : EntityManager(javax.persistence.EntityManager) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) AgencyClassifierItemKey(dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) Test(org.junit.Test)

Example 2 with AgencyClassifierItemKey

use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.

the class BibliographicEntityIT method StoreEntity.

@Test
public void StoreEntity() {
    EntityManager em = env().getEntityManager();
    env().getPersistenceContext().run(() -> {
        IndexKeys indexKeys = new IndexKeys();
        indexKeys.put("titel", Collections.singletonList("unix bogen"));
        indexKeys.put("id", Collections.singletonList("argle"));
        BibliographicEntity be = new BibliographicEntity(200, "clazzifier", "1234", "id#1", "work:1", "unit:2", false, indexKeys, "");
        em.persist(be);
    });
    AgencyClassifierItemKey key = new AgencyClassifierItemKey(200, "clazzifier", "1234");
    BibliographicEntity be2 = env().getPersistenceContext().run(() -> em.find(BibliographicEntity.class, key));
    assertThat(be2.getAgencyId(), is(200));
    assertThat(be2.getClassifier(), is("clazzifier"));
    assertThat(be2.getBibliographicRecordId(), is("1234"));
}
Also used : EntityManager(javax.persistence.EntityManager) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) AgencyClassifierItemKey(dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey) Test(org.junit.Test)

Example 3 with AgencyClassifierItemKey

use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.

the class QueueBean method queueManifestation.

@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("manifestation/{ agencyId : \\d+}-{ classifier : \\w+ }:{ bibliographicRecordId : .+}")
@Operation(summary = "Queue a manifestation", description = "This operation puts a manifestation," + " and optionally (if it isn't deleted) its work on queue.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "The manifestation was found, and put onto the queue", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = StatusResponse.NAME))), @APIResponse(name = "Not Found", responseCode = "404", description = "There's no such manifestation", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = StatusResponse.NAME))) })
@Parameters({ @Parameter(name = "agencyId", description = "The agency that owns the record", required = true), @Parameter(name = "classifier", description = "The classifier of the records (usually basis or katalog)", required = true), @Parameter(name = "bibliographicRecordId", description = "The id of the record", required = true), @Parameter(name = "trackingId", description = "For tracking the request", required = false) })
@Timed
public Response queueManifestation(@PathParam("agencyId") Integer agencyId, @PathParam("classifier") String classifier, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("trackingId") String trackingId) {
    if (trackingId == null || trackingId.isEmpty())
        trackingId = UUID.randomUUID().toString();
    String pid = agencyId + "-" + classifier + ":" + bibliographicRecordId;
    try (LogWith logWith = LogWith.track(trackingId).pid(pid)) {
        AgencyClassifierItemKey bibliographicKey = new AgencyClassifierItemKey(agencyId, classifier, bibliographicRecordId);
        BibliographicEntity biblEntity = entityManager.find(BibliographicEntity.class, bibliographicKey);
        if (biblEntity == null) {
            return Response.status(Response.Status.NOT_FOUND).entity(new StatusResponse("No such manifestation")).build();
        }
        EnqueueCollector enqueueCollector = enqueueSupplier.getEnqueueCollector();
        if (biblEntity.isDeleted()) {
            enqueueCollector.add(biblEntity, QueueType.ENDPOINT);
        } else {
            enqueueCollector.add(biblEntity, QueueType.ENDPOINT, QueueType.WORKENDPOINT);
        }
        enqueueCollector.commit();
        return Response.ok(new StatusResponse()).build();
    } catch (SQLException ex) {
        log.error("Error queueing: {}: {}", pid, ex.getMessage());
        log.debug("Error queueing: {}: ", pid, ex);
        return Response.serverError().entity(new StatusResponse(ex.getMessage())).build();
    }
}
Also used : LogWith(dk.dbc.log.LogWith) SQLException(java.sql.SQLException) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) AgencyClassifierItemKey(dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey) StatusResponse(dk.dbc.search.solrdocstore.response.StatusResponse) EnqueueCollector(dk.dbc.search.solrdocstore.enqueue.EnqueueCollector) Path(javax.ws.rs.Path) Parameters(org.eclipse.microprofile.openapi.annotations.parameters.Parameters) Produces(javax.ws.rs.Produces) Timed(org.eclipse.microprofile.metrics.annotation.Timed) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 4 with AgencyClassifierItemKey

use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.

the class HoldingsToBibliographicBeanIT method deleteBibRecord.

private void deleteBibRecord(int agencyId, String bibliographicRecordId) {
    BibliographicEntity e = em.find(BibliographicEntity.class, new AgencyClassifierItemKey(agencyId, "clazzifier", bibliographicRecordId));
    e.setDeleted(true);
    em.merge(e);
}
Also used : BibliographicToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) AgencyClassifierItemKey(dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey)

Example 5 with AgencyClassifierItemKey

use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.

the class DocumentRetrieveBean method getDocumentWithHoldingsitems.

public DocumentRetrieveResponse getDocumentWithHoldingsitems(int agencyId, String classifier, String bibliographicRecordId) throws Exception {
    BibliographicEntity biblEntity = entityManager.find(BibliographicEntity.class, new AgencyClassifierItemKey(agencyId, classifier, bibliographicRecordId));
    if (biblEntity == null) {
        return null;
    }
    List<HoldingsItemEntity> holdingsItemRecords = Collections.EMPTY_LIST;
    List<Integer> partOfDanbib = Collections.EMPTY_LIST;
    Map<String, Map<Integer, Boolean>> attachedResources = Collections.EMPTY_MAP;
    if (!biblEntity.isDeleted()) {
        holdingsItemRecords = entityManager.createQuery(SELECT_HOLDINGS_ITEMS_JPA, HoldingsItemEntity.class).setParameter("bibliographicRecordId", bibliographicRecordId).setParameter("agencyId", agencyId).getResultList();
        if (LibraryType.COMMON_AGENCY == agencyId) {
            partOfDanbib = getPartOfDanbibCommon(bibliographicRecordId);
        }
        OpenAgencyEntity oaEntity = oaBean.lookup(agencyId);
        LibraryType libraryType = oaEntity.getLibraryType();
        List<BibliographicResourceEntity> resources = agencyLibTypeCommon(agencyId, libraryType) ? brrBean.getResourcesForCommon(bibliographicRecordId) : brrBean.getResourcesFor(agencyId, bibliographicRecordId);
        attachedResources = mapResources(resources);
    }
    DocumentRetrieveResponse response = new DocumentRetrieveResponse(biblEntity, holdingsItemRecords, partOfDanbib, attachedResources);
    return response;
}
Also used : DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) AgencyClassifierItemKey(dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

AgencyClassifierItemKey (dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey)6 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)6 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)2 EntityManager (javax.persistence.EntityManager)2 GET (javax.ws.rs.GET)2 Path (javax.ws.rs.Path)2 Produces (javax.ws.rs.Produces)2 Timed (org.eclipse.microprofile.metrics.annotation.Timed)2 Operation (org.eclipse.microprofile.openapi.annotations.Operation)2 Parameters (org.eclipse.microprofile.openapi.annotations.parameters.Parameters)2 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)2 Test (org.junit.Test)2 LogWith (dk.dbc.log.LogWith)1 EnqueueCollector (dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)1 BibliographicResourceEntity (dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity)1 BibliographicToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity)1 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)1 HoldingsToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity)1 LibraryType (dk.dbc.search.solrdocstore.jpa.LibraryType)1 OpenAgencyEntity (dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity)1