use of dk.dbc.search.solrdocstore.response.StatusResponse 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.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.response.StatusResponse in project solr-document-store by DBCDK.
the class QueueBean method queueWork.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("work/{ workId : work:\\d+ }")
@Timed
@Operation(summary = "Queue a manifestation", description = "This operation puts a work and its manifestations on queue.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "The work 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 work", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = StatusResponse.NAME))) })
@Parameters({ @Parameter(name = "workId", description = "The (corepo-)id of the work", required = true), @Parameter(name = "trackingId", description = "For tracking the request", required = false) })
public Response queueWork(@PathParam("workId") String workId, @QueryParam("trackingId") String trackingId) {
if (trackingId == null || trackingId.isEmpty())
trackingId = UUID.randomUUID().toString();
try (LogWith logWith = LogWith.track(trackingId).pid(workId)) {
List<BibliographicEntity> biblEntitys = BibliographicEntity.fetchByWork(entityManager, workId);
if (biblEntitys.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).entity(new StatusResponse("No such work")).build();
}
EnqueueCollector enqueueCollector = enqueueSupplier.getEnqueueCollector();
biblEntitys.forEach(biblEntity -> enqueueCollector.add(biblEntity, QueueType.ENDPOINT, QueueType.WORKENDPOINT));
enqueueCollector.commit();
return Response.ok(new StatusResponse()).build();
} catch (SQLException ex) {
log.error("Error queueing: {}: {}", workId, ex.getMessage());
log.debug("Error queueing: {}: ", workId, ex);
return Response.serverError().entity(new StatusResponse(ex.getMessage())).build();
}
}
use of dk.dbc.search.solrdocstore.response.StatusResponse 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.response.StatusResponse in project solr-document-store by DBCDK.
the class StatusBean method getStatus.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Timed
@SuppressFBWarnings("RCN_REDUNDANT_NULLCHECK_WOULD_HAVE_BEEN_A_NPE")
public Response getStatus() {
log.trace("getStatus called ");
try (Connection connection = getConnection();
Statement stmt = connection.createStatement();
ResultSet resultSet = stmt.executeQuery("SELECT NOW()")) {
if (resultSet.next()) {
resultSet.getTimestamp(1);
log.trace("status - ok");
return Response.ok().entity(new StatusResponse()).build();
}
return Response.serverError().entity(new StatusResponse("No rows when communicating with database")).build();
} catch (SQLException ex) {
log.error("Error getting connection for status: {}", ex.getMessage());
log.debug("Error getting connection for status: ", ex);
return Response.serverError().entity(new StatusResponse("SQL Exception: " + ex.getMessage())).build();
}
}
Aggregations