Search in sources :

Example 1 with AgencyItemFieldKey

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

the class ResourceBean method storeResource.

private Response storeResource(BibliographicResourceEntity resource) {
    // Verify agency exists, throws exception if not exist
    LibraryType libraryType;
    try {
        OpenAgencyEntity oaEntity = openAgency.lookup(resource.getAgencyId());
        libraryType = oaEntity.getLibraryType();
    } catch (EJBException ex) {
        return Response.ok().entity(new StatusResponse("Unknown agency")).build();
    }
    if (resource.getValue()) {
        entityManager.merge(resource);
    } else {
        BibliographicResourceEntity entity = entityManager.find(BibliographicResourceEntity.class, new AgencyItemFieldKey(resource.getAgencyId(), resource.getBibliographicRecordId(), resource.getField()));
        if (entity != null)
            entityManager.remove(entity);
    }
    // Enqueue all related bib items
    List<BibliographicEntity> bibliographicEntities;
    if (LibraryType.COMMON_AGENCY == resource.getAgencyId() || LibraryType.SCHOOL_COMMON_AGENCY == resource.getAgencyId() || libraryType == LibraryType.FBS || libraryType == LibraryType.FBSSchool) {
        bibliographicEntities = commonRelatedBibEntities(resource);
    } else {
        bibliographicEntities = nonFBSBibEntries(resource);
    }
    try {
        EnqueueCollector enqueue = enqueueSupplier.getEnqueueCollector();
        bibliographicEntities.forEach(e -> {
            if (!e.isDeleted()) {
                enqueue.add(e, QueueType.RESOURCE, QueueType.UNITRESOURCE, QueueType.WORKRESOURCE);
            }
        });
        enqueue.commit();
    } catch (SQLException ex) {
        log.error("Unable to commit queue entries: {}", ex.getMessage());
        log.debug("Unable to commit queue entries: ", ex);
        return Response.status(Response.Status.BAD_REQUEST).entity(new StatusResponse("Unable to commit queue entries")).build();
    }
    return Response.ok().entity(new StatusResponse()).build();
}
Also used : SQLException(java.sql.SQLException) LibraryType(dk.dbc.search.solrdocstore.jpa.LibraryType) AgencyItemFieldKey(dk.dbc.search.solrdocstore.jpa.AgencyItemFieldKey) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) StatusResponse(dk.dbc.search.solrdocstore.response.StatusResponse) EJBException(javax.ejb.EJBException) EnqueueCollector(dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)

Example 2 with AgencyItemFieldKey

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

the class ResourceBeanIT method testAddResource.

@Test(timeout = 2_000L)
public void testAddResource() throws Exception {
    System.out.println("testAddResource");
    BibliographicResourceEntity entity;
    Response r;
    Set<String> queue;
    queueContentAndClear();
    env().getPersistenceContext().run(() -> {
        em.merge(new BibliographicEntity(870970, "clazzifier", "25912233", "id#1", "work:update", "unit:update", false, new IndexKeys(), "track:update"));
        em.merge(new BibliographicEntity(710100, "clazzifier", "25912233", "id#1", "work:update", "unit:update", false, new IndexKeys(), "track:update"));
        em.merge(new OpenAgencyEntity(870970, LibraryType.FBS, false, false, false));
        em.merge(new OpenAgencyEntity(710100, LibraryType.FBS, true, true, true));
    });
    r = env().getPersistenceContext().run(() -> bean.addResource("{\"agencyId\":870970,\"bibliographicRecordId\":\"25912233\",\"field\":\"hasCoverUrl\",\"value\":true}"));
    assertThat(r.getStatus(), is(200));
    queue = queueContentAndClear();
    assertThat(queue, containsInAnyOrder("w,work:update", "u,unit:update", "m,710100-clazzifier:25912233", "m,870970-clazzifier:25912233"));
    entity = env().getPersistenceContext().run(() -> em.find(BibliographicResourceEntity.class, new AgencyItemFieldKey(870970, "25912233", "hasCoverUrl")));
    assertThat(entity, notNullValue());
    r = env().getPersistenceContext().run(() -> bean.addResource("{\"agencyId\":870970,\"bibliographicRecordId\":\"25912233\",\"field\":\"hasCoverUrl\",\"value\":false}"));
    assertThat(r.getStatus(), is(200));
    queue = queueContentAndClear();
    assertThat(queue, containsInAnyOrder("w,work:update", "u,unit:update", "m,710100-clazzifier:25912233", "m,870970-clazzifier:25912233"));
    entity = env().getPersistenceContext().run(() -> em.find(BibliographicResourceEntity.class, new AgencyItemFieldKey(870970, "25912233", "hasCoverUrl")));
    assertThat(entity, nullValue());
}
Also used : Response(javax.ws.rs.core.Response) AgencyItemFieldKey(dk.dbc.search.solrdocstore.jpa.AgencyItemFieldKey) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) Test(org.junit.Test)

Example 3 with AgencyItemFieldKey

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

the class ResourceBeanIT method testDeleteResource.

@Test(timeout = 2_000L)
public void testDeleteResource() throws Exception {
    System.out.println("testPutResource");
    BibliographicResourceEntity entity;
    Response r;
    Set<String> queue;
    queueContentAndClear();
    env().getPersistenceContext().run(() -> {
        em.merge(new BibliographicEntity(870970, "clazzifier", "25912233", "id#1", "work:update", "unit:update", false, new IndexKeys(), "track:update"));
        em.merge(new BibliographicEntity(710100, "clazzifier", "25912233", "id#1", "work:update", "unit:update", false, new IndexKeys(), "track:update"));
        em.merge(new OpenAgencyEntity(870970, LibraryType.FBS, false, false, false));
        em.merge(new OpenAgencyEntity(710100, LibraryType.FBS, true, true, true));
    });
    r = env().getPersistenceContext().run(() -> bean.putResource("{\"has\":true}", "hasCoverUrl", 870970, "25912233", null));
    assertThat(r.getStatus(), is(200));
    queue = queueContentAndClear();
    assertThat(queue, containsInAnyOrder("w,work:update", "u,unit:update", "m,710100-clazzifier:25912233", "m,870970-clazzifier:25912233"));
    entity = env().getPersistenceContext().run(() -> em.find(BibliographicResourceEntity.class, new AgencyItemFieldKey(870970, "25912233", "hasCoverUrl")));
    assertThat(entity, notNullValue());
    r = env().getPersistenceContext().run(() -> bean.deleteResource("hasCoverUrl", 870970, "25912233", null));
    assertThat(r.getStatus(), is(200));
    queue = queueContentAndClear();
    assertThat(queue, containsInAnyOrder("w,work:update", "u,unit:update", "m,710100-clazzifier:25912233", "m,870970-clazzifier:25912233"));
    entity = env().getPersistenceContext().run(() -> em.find(BibliographicResourceEntity.class, new AgencyItemFieldKey(870970, "25912233", "hasCoverUrl")));
    assertThat(entity, nullValue());
}
Also used : Response(javax.ws.rs.core.Response) AgencyItemFieldKey(dk.dbc.search.solrdocstore.jpa.AgencyItemFieldKey) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) Test(org.junit.Test)

Example 4 with AgencyItemFieldKey

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

the class ResourceBeanIT method testPutResource.

@Test(timeout = 2_000L)
public void testPutResource() throws Exception {
    System.out.println("testPutResource");
    BibliographicResourceEntity entity;
    Response r;
    Set<String> queue;
    queueContentAndClear();
    env().getPersistenceContext().run(() -> {
        em.merge(new BibliographicEntity(870970, "clazzifier", "25912233", "id#1", "work:update", "unit:update", false, new IndexKeys(), "track:update"));
        em.merge(new BibliographicEntity(710100, "clazzifier", "25912233", "id#1", "work:update", "unit:update", false, new IndexKeys(), "track:update"));
        em.merge(new OpenAgencyEntity(870970, LibraryType.FBS, false, false, false));
        em.merge(new OpenAgencyEntity(710100, LibraryType.FBS, true, true, true));
    });
    r = env().getPersistenceContext().run(() -> bean.putResource("{\"has\":true}", "hasCoverUrl", 870970, "25912233", null));
    assertThat(r.getStatus(), is(200));
    queue = queueContentAndClear();
    assertThat(queue, containsInAnyOrder("w,work:update", "u,unit:update", "m,710100-clazzifier:25912233", "m,870970-clazzifier:25912233"));
    entity = env().getPersistenceContext().run(() -> em.find(BibliographicResourceEntity.class, new AgencyItemFieldKey(870970, "25912233", "hasCoverUrl")));
    assertThat(entity, notNullValue());
    r = env().getPersistenceContext().run(() -> bean.putResource("{\"has\":false}", "hasCoverUrl", 870970, "25912233", null));
    assertThat(r.getStatus(), is(200));
    queue = queueContentAndClear();
    assertThat(queue, containsInAnyOrder("w,work:update", "u,unit:update", "m,710100-clazzifier:25912233", "m,870970-clazzifier:25912233"));
    entity = env().getPersistenceContext().run(() -> em.find(BibliographicResourceEntity.class, new AgencyItemFieldKey(870970, "25912233", "hasCoverUrl")));
    assertThat(entity, nullValue());
}
Also used : Response(javax.ws.rs.core.Response) AgencyItemFieldKey(dk.dbc.search.solrdocstore.jpa.AgencyItemFieldKey) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) IndexKeys(dk.dbc.search.solrdocstore.jpa.IndexKeys) OpenAgencyEntity(dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity) Test(org.junit.Test)

Aggregations

AgencyItemFieldKey (dk.dbc.search.solrdocstore.jpa.AgencyItemFieldKey)4 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)4 BibliographicResourceEntity (dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity)4 OpenAgencyEntity (dk.dbc.search.solrdocstore.jpa.OpenAgencyEntity)4 IndexKeys (dk.dbc.search.solrdocstore.jpa.IndexKeys)3 Response (javax.ws.rs.core.Response)3 Test (org.junit.Test)3 EnqueueCollector (dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)1 LibraryType (dk.dbc.search.solrdocstore.jpa.LibraryType)1 StatusResponse (dk.dbc.search.solrdocstore.response.StatusResponse)1 SQLException (java.sql.SQLException)1 EJBException (javax.ejb.EJBException)1