use of dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity in project solr-document-store by DBCDK.
the class BibliographicBeanIT method updateExistingBibliographicPost.
@Test
public void updateExistingBibliographicPost() throws JSONBException {
BibliographicEntity b = new BibliographicEntity(600100, "clazzifier", "properUpdate", "id#1", "work:update", "unit:update", false, makeIndexKeys(), "track:update");
String updatedB = jsonbContext.marshall(b);
Response r = env().getPersistenceContext().run(() -> bean.addBibliographicKeys(false, updatedB));
assertThat(r.getStatus(), is(200));
// Ensure update came through
BibliographicEntity updatedBibEntity = em.find(BibliographicEntity.class, b.asAgencyClassifierItemKey());
assertThat(updatedBibEntity, equalTo(b));
// assertThat(true,equalTo(true));
// Ensure related holdings are unchanged
List<HoldingsToBibliographicEntity> l = em.createQuery("SELECT h FROM HoldingsToBibliographicEntity h WHERE h.bibliographicRecordId='properUpdate'", HoldingsToBibliographicEntity.class).getResultList();
assertThat(l, containsInAnyOrder(new HoldingsToBibliographicEntity(610510, "properUpdate", 600100, false)));
}
use of dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity 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.HoldingsToBibliographicEntity 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.HoldingsToBibliographicEntity in project solr-document-store by DBCDK.
the class HoldingsToBibliographicBean method attachIfExists.
private boolean attachIfExists(int bibliographicAgencyId, String bibliographicRecordId, int holdingAgencyId, String holdingBibliographicRecordId, boolean isCommonDerived, EnqueueCollector enqueue, QueueType[] enqueueSources) {
if (bibliographicEntityExists(bibliographicAgencyId, bibliographicRecordId)) {
HoldingsToBibliographicEntity expectedState = new HoldingsToBibliographicEntity(holdingAgencyId, holdingBibliographicRecordId, bibliographicAgencyId, bibliographicRecordId, isCommonDerived);
attachToAgency(expectedState, enqueue, enqueueSources);
return true;
}
return false;
}
use of dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity in project solr-document-store by DBCDK.
the class HoldingsToBibliographicBean method attachToAgency.
public void attachToAgency(HoldingsToBibliographicEntity expectedState, EnqueueCollector enqueue, QueueType[] enqueueSources) {
HoldingsToBibliographicEntity foundEntity = entityManager.find(HoldingsToBibliographicEntity.class, expectedState.asKey());
if (foundEntity != null && !foundEntity.equals(expectedState)) {
List<BibliographicEntity> entitiesAffected = brBean.getBibliographicEntities(foundEntity.getBibliographicAgencyId(), foundEntity.getBibliographicRecordId());
entitiesAffected.forEach(e -> enqueue.add(e, enqueueSources));
}
List<BibliographicEntity> entitiesAffected = brBean.getBibliographicEntities(expectedState.getBibliographicAgencyId(), expectedState.getBibliographicRecordId());
entitiesAffected.forEach(e -> enqueue.add(e, enqueueSources));
entityManager.merge(expectedState);
}
Aggregations