Search in sources :

Example 1 with IndexKeysList

use of dk.dbc.search.solrdocstore.jpa.IndexKeysList in project solr-document-store by DBCDK.

the class BibliographicBeanIT method newRecordWhereSupersedesIsAlreadySet.

@Test
public void newRecordWhereSupersedesIsAlreadySet() throws Exception {
    Response r;
    String a870970 = makeBibliographicRequestJson(870970, e -> {
        e.setBibliographicRecordId("a");
    });
    r = env().getPersistenceContext().run(() -> bean.addBibliographicKeys(false, a870970));
    assertThat(r.getStatus(), is(200));
    // Setup holding pointint to 870970:a
    env().getPersistenceContext().run(() -> {
        em.persist(new HoldingsItemEntity(700000, "a", new IndexKeysList(), "T#1"));
    });
    env().getPersistenceContext().run(() -> {
        em.persist(new HoldingsToBibliographicEntity(700000, "a", 870970, true));
    });
    String b870970 = makeBibliographicRequestJson(870970, e -> {
        e.setBibliographicRecordId("b");
        e.setSupersedes(Arrays.asList("a"));
    });
    r = env().getPersistenceContext().run(() -> bean.addBibliographicKeys(false, b870970));
    assertThat(r.getStatus(), is(200));
    // Not really nessecary
    String a870970d = makeBibliographicRequestJson(870970, e -> {
        e.setDeleted(true);
        e.setBibliographicRecordId("a");
    });
    r = env().getPersistenceContext().run(() -> bean.addBibliographicKeys(false, a870970d));
    assertThat(r.getStatus(), is(200));
    HoldingsToBibliographicEntity h2bBefore = env().getPersistenceContext().run(() -> {
        return em.find(HoldingsToBibliographicEntity.class, new HoldingsToBibliographicKey(700000, "a"));
    });
    Assert.assertEquals(new HoldingsToBibliographicEntity(700000, "a", 870970, "b", true), h2bBefore);
    String b70000 = makeBibliographicRequestJson(700000, e -> {
        e.setBibliographicRecordId("b");
    });
    r = env().getPersistenceContext().run(() -> bean.addBibliographicKeys(false, b70000));
    assertThat(r.getStatus(), is(200));
    HoldingsToBibliographicEntity h2bAfter = env().getPersistenceContext().run(() -> {
        return em.find(HoldingsToBibliographicEntity.class, new HoldingsToBibliographicKey(700000, "a"));
    });
    Assert.assertEquals(new HoldingsToBibliographicEntity(700000, "a", 700000, "b", true), h2bAfter);
}
Also used : Response(javax.ws.rs.core.Response) IndexKeysList(dk.dbc.search.solrdocstore.jpa.IndexKeysList) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) HoldingsToBibliographicKey(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey) Test(org.junit.Test)

Example 2 with IndexKeysList

use of dk.dbc.search.solrdocstore.jpa.IndexKeysList in project solr-document-store by DBCDK.

the class DocumentRetrieveBeanIT method newCommonRecordWithExistingHoldings.

@Test
public void newCommonRecordWithExistingHoldings() throws Exception {
    em.merge(new BibliographicEntity(300000, "clazzifier", "12345678", "id#1", "work:0", "unit:0", false, new IndexKeys(), "T1"));
    em.merge(new HoldingsItemEntity(300101, "12345678", new IndexKeysList(), "T2"));
    em.merge(new HoldingsItemEntity(300102, "12345678", new IndexKeysList(), "T3"));
    em.merge(new HoldingsToBibliographicEntity(300101, "12345678", 300000, false));
    em.merge(new HoldingsToBibliographicEntity(300102, "12345678", 300000, false));
    DocumentRetrieveResponse doc = env().getPersistenceContext().run(() -> bean.getDocumentWithHoldingsitems(300000, "clazzifier", "12345678"));
    assertThat(doc.bibliographicRecord.getAgencyId(), is(300000));
    assertThat(doc.bibliographicRecord.getBibliographicRecordId(), is("12345678"));
    assertThat(doc.holdingsItemRecords.size(), is(2));
}
Also used : DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) IndexKeysList(dk.dbc.search.solrdocstore.jpa.IndexKeysList) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) Test(org.junit.Test)

Example 3 with IndexKeysList

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

Aggregations

HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)3 IndexKeysList (dk.dbc.search.solrdocstore.jpa.IndexKeysList)3 Test (org.junit.Test)3 HoldingsToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity)2 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)2 AgencyItemKey (dk.dbc.search.solrdocstore.jpa.AgencyItemKey)1 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)1 HoldingsToBibliographicKey (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey)1 DocumentRetrieveResponse (dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse)1 EntityManager (javax.persistence.EntityManager)1 Response (javax.ws.rs.core.Response)1