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();
}
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());
}
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());
}
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());
}
Aggregations