use of dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity in project solr-document-store by DBCDK.
the class BibliographicToBibliographicEntityIT method loadEntity.
@Test
public void loadEntity() {
executeScriptResource("/entityTestData.sql");
EntityManager em = env().getEntityManager();
BibliographicToBibliographicEntity b2b = env().getPersistenceContext().run(() -> em.find(BibliographicToBibliographicEntity.class, "399"));
assertThat(b2b.getLiveBibliographicRecordId(), is("600"));
}
use of dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity in project solr-document-store by DBCDK.
the class BibliographicBeanIT method supersedesAdd.
@Test
public void supersedesAdd() throws Exception {
String json = makeBibliographicRequestJson(870970, e -> {
e.setSupersedes(Arrays.asList("a", "b"));
});
Response r = env().getPersistenceContext().run(() -> bean.addBibliographicKeys(false, json));
assertThat(r.getStatus(), is(200));
List<BibliographicToBibliographicEntity> l = em.createQuery("SELECT b2b FROM BibliographicToBibliographicEntity as b2b WHERE b2b.liveBibliographicRecordId='new'", BibliographicToBibliographicEntity.class).getResultList();
assertThat(l.size(), is(2));
Assert.assertTrue("One superseded named 'a'", l.stream().anyMatch(b2b -> b2b.getDeadBibliographicRecordId().equals("a")));
Assert.assertTrue("One superseded named 'b'", l.stream().anyMatch(b2b -> b2b.getDeadBibliographicRecordId().equals("b")));
}
use of dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity in project solr-document-store by DBCDK.
the class BibliographicToBibliographicEntityIT method storeEntity.
@Test
public void storeEntity() {
executeScriptResource("/entityTestData.sql");
EntityManager em = env().getEntityManager();
env().getPersistenceContext().run(() -> {
em.persist(new BibliographicToBibliographicEntity("300", "4321"));
});
}
use of dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity in project solr-document-store by DBCDK.
the class BibliographicBean method deleteSuperseded.
private void deleteSuperseded(String bibliographicRecordId) {
List<BibliographicToBibliographicEntity> resultList = entityManager.createQuery("SELECT b2b FROM BibliographicToBibliographicEntity AS b2b" + " WHERE b2b.liveBibliographicRecordId = :bibliographicRecordId", BibliographicToBibliographicEntity.class).setParameter("bibliographicRecordId", bibliographicRecordId).getResultList();
for (BibliographicToBibliographicEntity b2b : resultList) {
String deadBibliographicRecordId = b2b.getDeadBibliographicRecordId();
log.info("Removing reference from dead bibliographicrecordid({}) to this", deadBibliographicRecordId);
entityManager.remove(b2b);
}
}
use of dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity in project solr-document-store by DBCDK.
the class BibliographicBean method updateSuperseded.
private Set<String> updateSuperseded(String bibliographicRecordId, List<String> supersededs) {
if (supersededs == null) {
return Collections.emptySet();
}
HashSet<String> changedBibliographicRecordIds = new HashSet<>();
for (String superseded : supersededs) {
BibliographicToBibliographicEntity b2b = entityManager.find(BibliographicToBibliographicEntity.class, superseded, LockModeType.PESSIMISTIC_WRITE);
if (b2b == null) {
b2b = new BibliographicToBibliographicEntity(superseded, bibliographicRecordId);
} else {
if (b2b.getLiveBibliographicRecordId().equals(bibliographicRecordId)) {
continue;
}
b2b.setLiveBibliographicRecordId(bibliographicRecordId);
}
entityManager.merge(b2b);
changedBibliographicRecordIds.add(superseded);
}
return changedBibliographicRecordIds;
}
Aggregations