use of dk.dbc.search.solrdocstore.jpa.QueueRuleEntity in project solr-document-store by DBCDK.
the class HoldingsItemBeanIT method testMajorHoldingsChange.
@Test(timeout = 2_000L)
public void testMajorHoldingsChange() throws Exception {
System.out.println("testMajorHoldingsChange");
JpaTestEnvironment env = env();
BibliographicBean bib = createBibliographicBean(env, null);
HoldingsItemBean hol = holdingsItemBeanWithRules(env, new QueueRuleEntity("fm", QueueType.FIRSTLASTHOLDING, 0), new QueueRuleEntity("fu", QueueType.UNITFIRSTLASTHOLDING, 0), new QueueRuleEntity("fw", QueueType.WORKFIRSTLASTHOLDING, 0), new QueueRuleEntity("mm", QueueType.MAJORHOLDING, 0), new QueueRuleEntity("mu", QueueType.UNITMAJORHOLDING, 0), new QueueRuleEntity("mw", QueueType.WORKMAJORHOLDING, 0));
env().getPersistenceContext().run(() -> {
bib.addBibliographicKeys(true, jsonRequestBibl("870970-25912233", Instant.now()));
});
queueContentAndClear();
// From non existing to OnShelf
env().getPersistenceContext().run(() -> {
hol.setHoldingsKeys(jsonRequestHold("710100-25912233-a"));
});
assertThat(queueContentAndClear(), containsInAnyOrder("fm,870970-basis:25912233", "fu,unit:1", "fw,work:1", "mm,870970-basis:25912233", "mu,unit:1", "mw,work:1"));
// From OnShelf to OnLoan
env().getPersistenceContext().run(() -> {
hol.setHoldingsKeys(jsonRequestHold("710100-25912233-b"));
});
assertThat(queueContentAndClear(), containsInAnyOrder("mm,870970-basis:25912233", "mu,unit:1", "mw,work:1"));
}
use of dk.dbc.search.solrdocstore.jpa.QueueRuleEntity 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.QueueRuleEntity 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.QueueRuleEntity in project solr-document-store by DBCDK.
the class QueueRuleEntityIT method storeAndLoadEntity.
@Test
public void storeAndLoadEntity() {
System.out.println("storeAndLoadEntity");
EntityManager em = env().getEntityManager();
EnumSet.allOf(QueueType.class).forEach(type -> {
System.out.println(" - testing: " + type);
env().getPersistenceContext().run(() -> {
em.persist(new QueueRuleEntity("foo", type, -456));
});
env().clearEntityManagerCache();
QueueRuleEntity qr = env().getPersistenceContext().run(() -> em.find(QueueRuleEntity.class, new QueueRuleKey("foo", type)));
assertThat(qr.getQueue(), is("foo"));
assertThat(qr.getSupplier(), is(type));
assertThat(qr.getPostpone(), is(-456));
env().getPersistenceContext().run(() -> em.remove(em.find(QueueRuleEntity.class, new QueueRuleKey("foo", type))));
});
}
use of dk.dbc.search.solrdocstore.jpa.QueueRuleEntity in project solr-document-store by DBCDK.
the class EnqueueSupplierBeanIT method testEnqueueAddsTotTables.
@Test(timeout = 2_000L)
public void testEnqueueAddsTotTables() throws Exception {
System.out.println("testEnqueueAddsTotTables");
EntityManager em = env().getEntityManager();
EnqueueSupplierBean bean = new EnqueueSupplierBean() {
@Override
protected Collection<QueueRuleEntity> getQueueRules() {
return Arrays.asList(new QueueRuleEntity("a", QueueType.MANIFESTATION, 0), new QueueRuleEntity("b", QueueType.MANIFESTATION, 5), new QueueRuleEntity("c", QueueType.HOLDING, 0), new QueueRuleEntity("d", QueueType.HOLDING, 20), new QueueRuleEntity("e", QueueType.FIRSTLASTHOLDING, 0), new QueueRuleEntity("f", QueueType.FIRSTLASTHOLDING, 20), new QueueRuleEntity("g", QueueType.WORK, 0), new QueueRuleEntity("h", QueueType.WORK, 100), new QueueRuleEntity("i", QueueType.WORKFIRSTLASTHOLDING, 0), new QueueRuleEntity("j", QueueType.WORKFIRSTLASTHOLDING, 100), new QueueRuleEntity("k", QueueType.UNIT, 0), new QueueRuleEntity("l", QueueType.UNIT, 100), new QueueRuleEntity("m", QueueType.UNITFIRSTLASTHOLDING, 0), new QueueRuleEntity("n", QueueType.UNITFIRSTLASTHOLDING, 100));
}
};
bean.entityManager = em;
env().getPersistenceContext().run(() -> {
EnqueueCollector collector = bean.getEnqueueCollector();
collector.add(entity(123456, "katalog", "87654321", "work:2", "unit:0"), QueueType.WORK);
collector.add(entity(123456, "katalog", "87654321", "work:2", "unit:0"), QueueType.UNIT);
collector.add(entity(123456, "katalog", "87654321", "work:2", "unit:0"), QueueType.MANIFESTATION);
collector.commit();
});
assertThat(queueContentAndClear(), containsInAnyOrder("a,123456-katalog:87654321", "b,123456-katalog:87654321", "g,work:2", "h,work:2", "k,unit:0", "l,unit:0"));
}
Aggregations