Search in sources :

Example 1 with BibliographicToBibliographicEntity

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"));
}
Also used : BibliographicToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test)

Example 2 with BibliographicToBibliographicEntity

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")));
}
Also used : Response(javax.ws.rs.core.Response) BibliographicToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity) java.sql(java.sql) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) java.util(java.util) URISyntaxException(java.net.URISyntaxException) HoldingsToBibliographicKey(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey) LoggerFactory(org.slf4j.LoggerFactory) BibliographicToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity) IndexKeysList(dk.dbc.search.solrdocstore.jpa.IndexKeysList) Assert.fail(org.junit.Assert.fail) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) Before(org.junit.Before) EMPTY_LIST(java.util.Collections.EMPTY_LIST) Logger(org.slf4j.Logger) BeanFactoryUtil(dk.dbc.search.solrdocstore.BeanFactoryUtil) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) Matchers(org.hamcrest.Matchers) Test(org.junit.Test) EntityManager(javax.persistence.EntityManager) Instant(java.time.Instant) Collectors(java.util.stream.Collectors) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) JSONBContext(dk.dbc.commons.jsonb.JSONBContext) SolrIndexKeys(dk.dbc.search.solrdocstore.SolrIndexKeys) Response(javax.ws.rs.core.Response) JSONBException(dk.dbc.commons.jsonb.JSONBException) BibliographicEntityRequest(dk.dbc.search.solrdocstore.request.BibliographicEntityRequest) Assert(org.junit.Assert) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) Test(org.junit.Test)

Example 3 with BibliographicToBibliographicEntity

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"));
    });
}
Also used : BibliographicToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity) EntityManager(javax.persistence.EntityManager) Test(org.junit.Test)

Example 4 with BibliographicToBibliographicEntity

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);
    }
}
Also used : BibliographicToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity)

Example 5 with BibliographicToBibliographicEntity

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;
}
Also used : BibliographicToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity) HashSet(java.util.HashSet)

Aggregations

BibliographicToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity)5 EntityManager (javax.persistence.EntityManager)3 Test (org.junit.Test)3 JSONBContext (dk.dbc.commons.jsonb.JSONBContext)1 JSONBException (dk.dbc.commons.jsonb.JSONBException)1 BeanFactoryUtil (dk.dbc.search.solrdocstore.BeanFactoryUtil)1 SolrIndexKeys (dk.dbc.search.solrdocstore.SolrIndexKeys)1 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)1 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)1 HoldingsToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity)1 HoldingsToBibliographicKey (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey)1 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)1 IndexKeysList (dk.dbc.search.solrdocstore.jpa.IndexKeysList)1 BibliographicEntityRequest (dk.dbc.search.solrdocstore.request.BibliographicEntityRequest)1 URISyntaxException (java.net.URISyntaxException)1 java.sql (java.sql)1 Instant (java.time.Instant)1 java.util (java.util)1 EMPTY_LIST (java.util.Collections.EMPTY_LIST)1 HashSet (java.util.HashSet)1