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