use of dk.dbc.log.LogWith in project solr-document-store by DBCDK.
the class ResourceBean method addResource.
@POST
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("add")
@Operation(operationId = "add-resource", summary = "Adds a resource to an item", description = "This operation sets the resource and connect" + " it to a number of manifestations item, if possible.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response addResource(String jsonContent) throws JSONBException {
try (LogWith logWith = track(UUID.randomUUID().toString())) {
AddResourceRequest request = jsonbContext.unmarshall(jsonContent, AddResourceRequest.class);
// Add resource
BibliographicResourceEntity resource = request.asBibliographicResource();
log.debug("POST resource: {}", resource);
return storeResource(resource);
}
}
use of dk.dbc.log.LogWith in project solr-document-store by DBCDK.
the class BibliographicRecordAPIBean method getBibliographicRecord.
@GET
@Path("bibliographic-record/{bibliographicRecordId}/{bibliographicAgencyId}")
@Produces({ MediaType.APPLICATION_JSON })
@Timed
public Response getBibliographicRecord(@PathParam("bibliographicRecordId") String bibliographicRecordId, @PathParam("bibliographicAgencyId") int bibliographicAgencyId) {
try (LogWith logWith = track(null)) {
Query frontendQuery = entityManager.createNativeQuery("SELECT b.*,b2b.livebibliographicrecordid as supersede_id " + "FROM bibliographicsolrkeys b " + "LEFT OUTER JOIN bibliographictobibliographic b2b ON b.bibliographicrecordid=b2b.deadbibliographicrecordid " + "WHERE (b.bibliographicrecordid=?1 AND b.agencyid=?2)", "BibliographicEntityWithSupersedeId").setParameter(1, bibliographicRecordId).setParameter(2, bibliographicAgencyId);
Object[] record = (Object[]) frontendQuery.getSingleResult();
return Response.ok(new BibliographicFrontendResponse((BibliographicEntity) record[0], (String) record[1])).build();
}
}
use of dk.dbc.log.LogWith 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.log.LogWith in project solr-document-store by DBCDK.
the class DocumentRetrieveBean method getWorkDocumentsWithHoldingsItems.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("work/{ workid }")
@Timed
public Response getWorkDocumentsWithHoldingsItems(@Context UriInfo uriInfo, @PathParam("workid") String workId, @DefaultValue("false") @QueryParam("includeHoldingsItemsIndexKeys") boolean includeHoldingsItemsIndexKeys) throws Exception {
log.debug("Fetching manifestations for work {}, includeHIIK: {}", workId, includeHoldingsItemsIndexKeys);
try (LogWith logWith = track(null)) {
List<DocumentRetrieveResponse> responses = getDocumentsForWork(workId, includeHoldingsItemsIndexKeys);
if (responses == null || responses.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).header("X-DBC-Status", "200").entity("Work not found").build();
}
final WorkRetrieveResponse res = new WorkRetrieveResponse(workId, responses);
return Response.ok(res).build();
} catch (Exception ex) {
log.error("Error retrieving documents for work {}: {}", workId, ex.getMessage());
log.debug("Error retrieving documents for work {}: {}", workId, ex);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity("Error retrieving documents for work").build();
}
}
use of dk.dbc.log.LogWith in project solr-document-store by DBCDK.
the class BibliographicRecordAPIBean method getBibliographicKeysWithSupersedeId.
/*
* Returns a json object with a result field, which is a list of json BibliographicEntity that matches
* holdingsBibliographicRecordId with the argument. Also includes the supersede id, if it exists.
*/
@GET
@Path("bibliographic-records/bibliographic-record-id/{bibliographicRecordId}")
@Produces({ MediaType.APPLICATION_JSON })
@Timed
public Response getBibliographicKeysWithSupersedeId(@PathParam("bibliographicRecordId") String bibliographicRecordId, @DefaultValue("1") @QueryParam("page") int page, @DefaultValue("10") @QueryParam("page_size") int pageSize, @DefaultValue("agencyId") @QueryParam("order_by") String orderBy, @DefaultValue("false") @QueryParam("desc") boolean desc) {
try (LogWith logWith = track(null)) {
log.info("Requesting bibliographic record id: {}", bibliographicRecordId);
log.info("Query parameters - page: {}, page_size: {}, order_by: {}, desc: {}", page, pageSize, orderBy, desc);
// Checking for valid query parameters
if (!BibliographicEntity.sortableColumns.contains(orderBy)) {
return Response.status(400).entity("{\"error\":\"order_by parameter not acceptable\"}").build();
}
Query frontendQuery = brBean.getBibliographicEntitiesWithIndexKeys(bibliographicRecordId, orderBy, desc);
List<Object[]> resultList = frontendQuery.setFirstResult((page - 1) * pageSize).setMaxResults(pageSize).getResultList();
List<BibliographicFrontendResponse> bibliographicFrontendEntityList = resultList.stream().map((record) -> {
BibliographicEntity b = (BibliographicEntity) record[0];
return new BibliographicFrontendResponse(b, (String) record[1]);
}).collect(Collectors.toList());
long countResult = brBean.getBibliographicEntityCountById(bibliographicRecordId);
return Response.ok(new FrontendReturnListType<>(bibliographicFrontendEntityList, pageCount(countResult, pageSize)), MediaType.APPLICATION_JSON).build();
}
}
Aggregations