Search in sources :

Example 1 with HoldingsToBibliographicKey

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

the class HoldingsItemBean method queueRelatedBibliographic.

private void queueRelatedBibliographic(HoldingsItemEntity hi, EnqueueCollector enqueue, QueueType... queues) {
    HoldingsToBibliographicKey key = new HoldingsToBibliographicKey(hi.getAgencyId(), hi.getBibliographicRecordId());
    HoldingsToBibliographicEntity binding = entityManager.find(HoldingsToBibliographicEntity.class, key);
    if (binding != null) {
        queueRelatedBibliographic(binding, enqueue, queues);
    }
}
Also used : HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) HoldingsToBibliographicKey(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey)

Example 2 with HoldingsToBibliographicKey

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

the class HoldingsItemBean method setHoldingsKeys.

public void setHoldingsKeys(HoldingsItemEntity hi) throws SQLException {
    EnqueueCollector enqueue = enqueueSupplier.getEnqueueCollector();
    List<HoldingsItemEntity> his = entityManager.createQuery("SELECT h FROM HoldingsItemEntity h WHERE h.bibliographicRecordId = :bibId and h.agencyId = :agency", HoldingsItemEntity.class).setParameter("agency", hi.getAgencyId()).setParameter("bibId", hi.getBibliographicRecordId()).getResultList();
    boolean hadLiveHoldings = !his.isEmpty();
    boolean hasLiveHoldings = !hi.getIndexKeys().isEmpty();
    Set<String> oldLocations = his.isEmpty() ? EMPTY_SET : his.get(0).getLocations();
    log.info("Updating holdings for {}:{}", hi.getAgencyId(), hi.getBibliographicRecordId());
    if (!hadLiveHoldings && !hasLiveHoldings) {
        // No holdings before or now
        log.debug("No holdings before or now");
    } else if (hadLiveHoldings != hasLiveHoldings && hasLiveHoldings) {
        // holdings existence change -> exists
        entityManager.merge(hi);
        h2bBean.tryToAttachToBibliographicRecord(hi.getAgencyId(), hi.getBibliographicRecordId(), enqueue, QueueType.HOLDING, QueueType.UNIT, QueueType.WORK, QueueType.MAJORHOLDING, QueueType.UNITMAJORHOLDING, QueueType.FIRSTLASTHOLDING, QueueType.UNITFIRSTLASTHOLDING, QueueType.MAJORHOLDING, QueueType.WORKMAJORHOLDING, QueueType.FIRSTLASTHOLDING, QueueType.WORKFIRSTLASTHOLDING);
    } else if (hadLiveHoldings != hasLiveHoldings && hadLiveHoldings) {
        // holdings existence change -> none
        // Remove existing
        entityManager.remove(his.get(0));
        HoldingsToBibliographicKey key = new HoldingsToBibliographicKey(hi.getAgencyId(), hi.getBibliographicRecordId());
        HoldingsToBibliographicEntity binding = entityManager.find(HoldingsToBibliographicEntity.class, key);
        if (binding != null) {
            entityManager.remove(binding);
            queueRelatedBibliographic(binding, enqueue, QueueType.HOLDING, QueueType.UNIT, QueueType.WORK, QueueType.MAJORHOLDING, QueueType.UNITMAJORHOLDING, QueueType.FIRSTLASTHOLDING, QueueType.UNITFIRSTLASTHOLDING, QueueType.MAJORHOLDING, QueueType.WORKMAJORHOLDING, QueueType.FIRSTLASTHOLDING, QueueType.WORKFIRSTLASTHOLDING);
        }
    } else if (!oldLocations.equals(hi.getLocations())) {
        // holdings accessibility change
        entityManager.merge(hi);
        queueRelatedBibliographic(hi, enqueue, QueueType.HOLDING, QueueType.UNIT, QueueType.WORK, QueueType.MAJORHOLDING, QueueType.UNITMAJORHOLDING, QueueType.MAJORHOLDING, QueueType.WORKMAJORHOLDING);
    } else {
        entityManager.merge(hi);
        queueRelatedBibliographic(hi, enqueue, QueueType.HOLDING, QueueType.UNIT, QueueType.WORK);
    }
    enqueue.commit();
}
Also used : HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) EnqueueCollector(dk.dbc.search.solrdocstore.enqueue.EnqueueCollector) HoldingsToBibliographicKey(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey)

Example 3 with HoldingsToBibliographicKey

use of dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey 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 4 with HoldingsToBibliographicKey

use of dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey 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 5 with HoldingsToBibliographicKey

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

the class HoldingsToBibliographicEntityIT method loadEntity.

@Test
public void loadEntity() {
    executeScriptResource("/entityTestData.sql");
    EntityManager em = env().getEntityManager();
    HoldingsToBibliographicKey key = new HoldingsToBibliographicKey(600, "600");
    HoldingsToBibliographicEntity h2b = env().getPersistenceContext().run(() -> em.find(HoldingsToBibliographicEntity.class, key));
    assertThat(h2b.getHoldingsAgencyId(), is(600));
    assertThat(h2b.getBibliographicRecordId(), is("600"));
    assertThat(h2b.getBibliographicAgencyId(), is(100));
    assertThat(h2b.getIsCommonDerived(), is(false));
}
Also used : EntityManager(javax.persistence.EntityManager) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) HoldingsToBibliographicKey(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey) Test(org.junit.Test)

Aggregations

HoldingsToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity)8 HoldingsToBibliographicKey (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey)8 Test (org.junit.Test)6 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)5 EntityManager (javax.persistence.EntityManager)3 JpaTestEnvironment (dk.dbc.commons.persistence.JpaTestEnvironment)2 AgencyItemKey (dk.dbc.search.solrdocstore.jpa.AgencyItemKey)2 QueueRuleEntity (dk.dbc.search.solrdocstore.jpa.QueueRuleEntity)2 Response (javax.ws.rs.core.Response)2 SolrIndexKeys (dk.dbc.search.solrdocstore.SolrIndexKeys)1 EnqueueCollector (dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)1 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)1 BibliographicToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity)1 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)1 IndexKeysList (dk.dbc.search.solrdocstore.jpa.IndexKeysList)1 BibliographicEntityRequest (dk.dbc.search.solrdocstore.request.BibliographicEntityRequest)1