use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.
the class BibliographicEntityIT method LoadEntity.
@Test
public void LoadEntity() {
executeScriptResource("/entityTestData.sql");
EntityManager em = env().getEntityManager();
AgencyClassifierItemKey key = new AgencyClassifierItemKey(300, "clazzifier", "4321");
BibliographicEntity be = env().getPersistenceContext().run(() -> em.find(BibliographicEntity.class, key));
assertThat(be.getAgencyId(), is(300));
assertThat(be.getClassifier(), is("clazzifier"));
assertThat(be.getBibliographicRecordId(), is("4321"));
assertThat(be.getWork(), is("work:3"));
assertThat(be.getUnit(), is("unit:3"));
assertThat(be.isDeleted(), is(true));
IndexKeys expected = new IndexKeys();
expected.put("ti", Arrays.asList("isdnBogen", "title2"));
expected.put("001", Collections.singletonList("argle"));
assertThat(be.getIndexKeys(), is(expected));
assertThat(be.getTrackingId(), is("track"));
}
use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.
the class BibliographicEntityIT method StoreEntity.
@Test
public void StoreEntity() {
EntityManager em = env().getEntityManager();
env().getPersistenceContext().run(() -> {
IndexKeys indexKeys = new IndexKeys();
indexKeys.put("titel", Collections.singletonList("unix bogen"));
indexKeys.put("id", Collections.singletonList("argle"));
BibliographicEntity be = new BibliographicEntity(200, "clazzifier", "1234", "id#1", "work:1", "unit:2", false, indexKeys, "");
em.persist(be);
});
AgencyClassifierItemKey key = new AgencyClassifierItemKey(200, "clazzifier", "1234");
BibliographicEntity be2 = env().getPersistenceContext().run(() -> em.find(BibliographicEntity.class, key));
assertThat(be2.getAgencyId(), is(200));
assertThat(be2.getClassifier(), is("clazzifier"));
assertThat(be2.getBibliographicRecordId(), is("1234"));
}
use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.
the class QueueBean method queueManifestation.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("manifestation/{ agencyId : \\d+}-{ classifier : \\w+ }:{ bibliographicRecordId : .+}")
@Operation(summary = "Queue a manifestation", description = "This operation puts a manifestation," + " and optionally (if it isn't deleted) its work on queue.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "The manifestation was found, and put onto the queue", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = StatusResponse.NAME))), @APIResponse(name = "Not Found", responseCode = "404", description = "There's no such manifestation", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = StatusResponse.NAME))) })
@Parameters({ @Parameter(name = "agencyId", description = "The agency that owns the record", required = true), @Parameter(name = "classifier", description = "The classifier of the records (usually basis or katalog)", required = true), @Parameter(name = "bibliographicRecordId", description = "The id of the record", required = true), @Parameter(name = "trackingId", description = "For tracking the request", required = false) })
@Timed
public Response queueManifestation(@PathParam("agencyId") Integer agencyId, @PathParam("classifier") String classifier, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("trackingId") String trackingId) {
if (trackingId == null || trackingId.isEmpty())
trackingId = UUID.randomUUID().toString();
String pid = agencyId + "-" + classifier + ":" + bibliographicRecordId;
try (LogWith logWith = LogWith.track(trackingId).pid(pid)) {
AgencyClassifierItemKey bibliographicKey = new AgencyClassifierItemKey(agencyId, classifier, bibliographicRecordId);
BibliographicEntity biblEntity = entityManager.find(BibliographicEntity.class, bibliographicKey);
if (biblEntity == null) {
return Response.status(Response.Status.NOT_FOUND).entity(new StatusResponse("No such manifestation")).build();
}
EnqueueCollector enqueueCollector = enqueueSupplier.getEnqueueCollector();
if (biblEntity.isDeleted()) {
enqueueCollector.add(biblEntity, QueueType.ENDPOINT);
} else {
enqueueCollector.add(biblEntity, QueueType.ENDPOINT, QueueType.WORKENDPOINT);
}
enqueueCollector.commit();
return Response.ok(new StatusResponse()).build();
} catch (SQLException ex) {
log.error("Error queueing: {}: {}", pid, ex.getMessage());
log.debug("Error queueing: {}: ", pid, ex);
return Response.serverError().entity(new StatusResponse(ex.getMessage())).build();
}
}
use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.
the class HoldingsToBibliographicBeanIT method deleteBibRecord.
private void deleteBibRecord(int agencyId, String bibliographicRecordId) {
BibliographicEntity e = em.find(BibliographicEntity.class, new AgencyClassifierItemKey(agencyId, "clazzifier", bibliographicRecordId));
e.setDeleted(true);
em.merge(e);
}
use of dk.dbc.search.solrdocstore.jpa.AgencyClassifierItemKey in project solr-document-store by DBCDK.
the class DocumentRetrieveBean method getDocumentWithHoldingsitems.
public DocumentRetrieveResponse getDocumentWithHoldingsitems(int agencyId, String classifier, String bibliographicRecordId) throws Exception {
BibliographicEntity biblEntity = entityManager.find(BibliographicEntity.class, new AgencyClassifierItemKey(agencyId, classifier, bibliographicRecordId));
if (biblEntity == null) {
return null;
}
List<HoldingsItemEntity> holdingsItemRecords = Collections.EMPTY_LIST;
List<Integer> partOfDanbib = Collections.EMPTY_LIST;
Map<String, Map<Integer, Boolean>> attachedResources = Collections.EMPTY_MAP;
if (!biblEntity.isDeleted()) {
holdingsItemRecords = entityManager.createQuery(SELECT_HOLDINGS_ITEMS_JPA, HoldingsItemEntity.class).setParameter("bibliographicRecordId", bibliographicRecordId).setParameter("agencyId", agencyId).getResultList();
if (LibraryType.COMMON_AGENCY == agencyId) {
partOfDanbib = getPartOfDanbibCommon(bibliographicRecordId);
}
OpenAgencyEntity oaEntity = oaBean.lookup(agencyId);
LibraryType libraryType = oaEntity.getLibraryType();
List<BibliographicResourceEntity> resources = agencyLibTypeCommon(agencyId, libraryType) ? brrBean.getResourcesForCommon(bibliographicRecordId) : brrBean.getResourcesFor(agencyId, bibliographicRecordId);
attachedResources = mapResources(resources);
}
DocumentRetrieveResponse response = new DocumentRetrieveResponse(biblEntity, holdingsItemRecords, partOfDanbib, attachedResources);
return response;
}
Aggregations