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