Search in sources :

Example 1 with HoldingsToBibliographicEntity

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)));
}
Also used : Response(javax.ws.rs.core.Response) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) BibliographicToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity) HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) Test(org.junit.Test)

Example 2 with HoldingsToBibliographicEntity

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

Example 3 with HoldingsToBibliographicEntity

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();
}
Also used : HoldingsToBibliographicEntity(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) EnqueueCollector(dk.dbc.search.solrdocstore.enqueue.EnqueueCollector) HoldingsToBibliographicKey(dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey)

Example 4 with HoldingsToBibliographicEntity

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

Example 5 with HoldingsToBibliographicEntity

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

Aggregations

HoldingsToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicEntity)31 Test (org.junit.Test)22 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)8 HoldingsToBibliographicKey (dk.dbc.search.solrdocstore.jpa.HoldingsToBibliographicKey)8 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)7 Response (javax.ws.rs.core.Response)6 BibliographicToBibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicToBibliographicEntity)4 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)4 EntityManager (javax.persistence.EntityManager)4 JpaTestEnvironment (dk.dbc.commons.persistence.JpaTestEnvironment)2 SolrIndexKeys (dk.dbc.search.solrdocstore.SolrIndexKeys)2 EnqueueCollector (dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)2 AgencyItemKey (dk.dbc.search.solrdocstore.jpa.AgencyItemKey)2 IndexKeysList (dk.dbc.search.solrdocstore.jpa.IndexKeysList)2 QueueRuleEntity (dk.dbc.search.solrdocstore.jpa.QueueRuleEntity)2 LibraryType (dk.dbc.search.solrdocstore.jpa.LibraryType)1 BibliographicEntityRequest (dk.dbc.search.solrdocstore.request.BibliographicEntityRequest)1 DocumentRetrieveResponse (dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse)1 Instant (java.time.Instant)1