Search in sources :

Example 1 with AgencyItemKey

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

the class HoldingsItemBeanIT method testFirstLast.

@Test(timeout = 2_000L)
public void testFirstLast() throws Exception {
    System.out.println("testFirstLast");
    JpaTestEnvironment env = env();
    EntityManager em = env.getEntityManager();
    BibliographicBean bib = createBibliographicBean(env, null);
    HoldingsItemBean hol = holdingsItemBeanWithRules(env, new QueueRuleEntity("a", QueueType.FIRSTLASTHOLDING, 0), new QueueRuleEntity("b", QueueType.UNITFIRSTLASTHOLDING, 0), new QueueRuleEntity("c", QueueType.WORKFIRSTLASTHOLDING, 0));
    env().getPersistenceContext().run(() -> {
        bib.addBibliographicKeys(true, jsonRequestBibl("870970-25912233", Instant.now()));
    });
    queueContentAndClear();
    // From non existing to live holdings
    env().getPersistenceContext().run(() -> {
        hol.setHoldingsKeys(jsonRequestHold("710100-25912233-a"));
    });
    assertThat(queueContentAndClear(), containsInAnyOrder("a,870970-basis:25912233", "b,unit:1", "c,work:1"));
    HoldingsToBibliographicEntity htobA = env().getPersistenceContext().run(() -> {
        HoldingsToBibliographicKey key = new HoldingsToBibliographicKey(710100, "25912233");
        return em.find(HoldingsToBibliographicEntity.class, key);
    });
    assertThat(htobA, notNullValue());
    // From live holdings to live holdings
    env().getPersistenceContext().run(() -> {
        hol.setHoldingsKeys(jsonRequestHold("710100-25912233-a"));
    });
    assertThat(queueContentAndClear(), empty());
    // From live holdings to no holdings
    env().getPersistenceContext().run(() -> {
        hol.setHoldingsKeys(jsonRequestHold("710100-25912233-d"));
    });
    assertThat(queueContentAndClear(), containsInAnyOrder("a,870970-basis:25912233", "b,unit:1", "c,work:1"));
    // Check that no h2b relation exists when no live holdings are present
    HoldingsToBibliographicEntity htobD = env().getPersistenceContext().run(() -> {
        HoldingsToBibliographicKey key = new HoldingsToBibliographicKey(710100, "25912233");
        return em.find(HoldingsToBibliographicEntity.class, key);
    });
    assertThat(htobD, nullValue());
    HoldingsItemEntity hi = env().getPersistenceContext().run(() -> {
        AgencyItemKey key = new AgencyItemKey(710100, "25912233");
        return em.find(HoldingsItemEntity.class, key);
    });
    assertThat(hi, nullValue());
}
Also used : JpaTestEnvironment(dk.dbc.commons.persistence.JpaTestEnvironment) AgencyItemKey(dk.dbc.search.solrdocstore.jpa.AgencyItemKey) EntityManager(javax.persistence.EntityManager) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) QueueRuleEntity(dk.dbc.search.solrdocstore.jpa.QueueRuleEntity) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) HoldingsToBibliographicKey(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey) Test(org.junit.Test)

Example 2 with AgencyItemKey

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

the class HoldingsItemBeanIT method testFirstLastNoneToNone.

@Test(timeout = 2_000L)
public void testFirstLastNoneToNone() throws Exception {
    System.out.println("testFirstLastNoneToNone");
    JpaTestEnvironment env = env();
    EntityManager em = env.getEntityManager();
    BibliographicBean bib = createBibliographicBean(env, null);
    HoldingsItemBean hol = holdingsItemBeanWithRules(env, new QueueRuleEntity("a", QueueType.FIRSTLASTHOLDING, 0), new QueueRuleEntity("b", QueueType.UNITFIRSTLASTHOLDING, 0), new QueueRuleEntity("c", QueueType.WORKFIRSTLASTHOLDING, 0));
    env().getPersistenceContext().run(() -> {
        bib.addBibliographicKeys(true, jsonRequestBibl("870970-25912233", Instant.now()));
    });
    queueContentAndClear();
    // From non existing to no holdings
    env().getPersistenceContext().run(() -> {
        hol.setHoldingsKeys(jsonRequestHold("710100-25912233-d"));
    });
    assertThat(queueContentAndClear(), empty());
    // Check that no h2b relation exists when no live holdings are present
    HoldingsToBibliographicEntity htob = env().getPersistenceContext().run(() -> {
        HoldingsToBibliographicKey key = new HoldingsToBibliographicKey(710100, "25912233");
        return em.find(HoldingsToBibliographicEntity.class, key);
    });
    assertThat(htob, nullValue());
    // and no holdings
    HoldingsItemEntity hi = env().getPersistenceContext().run(() -> {
        AgencyItemKey key = new AgencyItemKey(710100, "25912233");
        return em.find(HoldingsItemEntity.class, key);
    });
    assertThat(hi, nullValue());
    // From no holdings to no holdings
    env().getPersistenceContext().run(() -> {
        hol.setHoldingsKeys(jsonRequestHold("710100-25912233-d"));
    });
    assertThat(queueContentAndClear(), empty());
}
Also used : JpaTestEnvironment(dk.dbc.commons.persistence.JpaTestEnvironment) AgencyItemKey(dk.dbc.search.solrdocstore.jpa.AgencyItemKey) EntityManager(javax.persistence.EntityManager) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) QueueRuleEntity(dk.dbc.search.solrdocstore.jpa.QueueRuleEntity) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) HoldingsToBibliographicKey(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey) Test(org.junit.Test)

Example 3 with AgencyItemKey

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

the class HoldingsItemEntityIT method storeEntity.

@Test
public void storeEntity() {
    EntityManager em = env().getEntityManager();
    env().getPersistenceContext().run(() -> {
        IndexKeys doc1 = new IndexKeys();
        doc1.put("titel", Collections.singletonList("unix bogen"));
        doc1.put("id", Collections.singletonList("argle"));
        IndexKeys doc2 = new IndexKeys();
        doc2.put("titel", Collections.singletonList("unix bogen"));
        doc2.put("id", Collections.singletonList("argle"));
        doc2.put("dyr", Collections.singletonList("hest"));
        em.persist(new HoldingsItemEntity(200, "1234", IndexKeysList.from(doc1, doc2), ""));
    });
    Object key = new AgencyItemKey(200, "1234");
    HoldingsItemEntity be2 = em.find(HoldingsItemEntity.class, key);
    assertThat(be2.getAgencyId(), is(200));
    assertThat(be2.getBibliographicRecordId(), is("1234"));
}
Also used : AgencyItemKey(dk.dbc.search.solrdocstore.jpa.AgencyItemKey) EntityManager(javax.persistence.EntityManager) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) Test(org.junit.Test)

Example 4 with AgencyItemKey

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

the class HoldingsItemEntityIT method loadEntity.

@Test
public void loadEntity() throws Exception {
    executeScriptResource("/entityTestData.sql");
    EntityManager em = env().getEntityManager();
    AgencyItemKey key = new AgencyItemKey(300, "4321");
    HoldingsItemEntity be = env().getPersistenceContext().run(() -> em.find(HoldingsItemEntity.class, key));
    assertThat(be.getAgencyId(), is(300));
    assertThat(be.getBibliographicRecordId(), is("4321"));
    IndexKeysList expected = new IndexKeysList();
    IndexKeys doc1 = new IndexKeys();
    doc1.put("title", Collections.singletonList("unix bogen"));
    doc1.put("id", Collections.singletonList("argle"));
    expected.add(doc1);
    IndexKeys doc2 = new IndexKeys();
    doc2.put("title", Collections.singletonList("unix bogen"));
    doc2.put("id", Collections.singletonList("argle"));
    doc2.put("dyr", Collections.singletonList("hest"));
    expected.add(doc2);
    assertThat(be.getIndexKeys(), is(expected));
    assertThat(be.getTrackingId(), is("track"));
}
Also used : AgencyItemKey(dk.dbc.search.solrdocstore.jpa.AgencyItemKey) EntityManager(javax.persistence.EntityManager) IndexKeysList(dk.dbc.search.solrdocstore.jpa.IndexKeysList) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) Test(org.junit.Test)

Example 5 with AgencyItemKey

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

the class ExistenceBean method holdingExists.

@Timed
@GET
@Path("holdingsitem/{agencyId : \\d+}:{bibliographicRecordId : .+}")
@Produces(MediaType.APPLICATION_JSON)
@Operation(summary = "Check if a agency has a 'live' holdings for a bibliographic item", description = "This operation checks for a given agency/item," + " and returns if a holding is retrievable for it.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "A holding for the given agency/item has been checked", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = ExistsResponse.NAME))) })
@Parameters({ @Parameter(name = "agencyId", description = "The agency that should own the record", required = true), @Parameter(name = "bibliographicRecordId", description = "The id of the record", required = true) })
public ExistsResponse holdingExists(@PathParam("agencyId") Integer agencyId, @PathParam("bibliographicRecordId") String bibliographicRecordId) {
    log.info("Checking existence of holdings item {}:{}", agencyId, bibliographicRecordId);
    ExistsResponse response = new ExistsResponse();
    HoldingsItemEntity entity = entityManager.find(HoldingsItemEntity.class, new AgencyItemKey(agencyId, bibliographicRecordId));
    response.exists = entity != null;
    return response;
}
Also used : AgencyItemKey(dk.dbc.search.solrdocstore.jpa.AgencyItemKey) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) ExistsResponse(dk.dbc.search.solrdocstore.response.ExistsResponse) 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)

Aggregations

AgencyItemKey (dk.dbc.search.solrdocstore.jpa.AgencyItemKey)5 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)5 EntityManager (javax.persistence.EntityManager)4 Test (org.junit.Test)4 JpaTestEnvironment (dk.dbc.commons.persistence.JpaTestEnvironment)2 HoldingsToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity)2 HoldingsToBibliographicKey (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey)2 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)2 QueueRuleEntity (dk.dbc.search.solrdocstore.jpa.QueueRuleEntity)2 IndexKeysList (dk.dbc.search.solrdocstore.jpa.IndexKeysList)1 ExistsResponse (dk.dbc.search.solrdocstore.response.ExistsResponse)1 GET (javax.ws.rs.GET)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 Timed (org.eclipse.microprofile.metrics.annotation.Timed)1 Operation (org.eclipse.microprofile.openapi.annotations.Operation)1 Parameters (org.eclipse.microprofile.openapi.annotations.parameters.Parameters)1 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)1