use of dk.dbc.log.LogWith in project solr-document-store by DBCDK.
the class QueueBean method queueUnit.
@GET
@Produces({ MediaType.APPLICATION_JSON })
@Path("unit/{ unitId : unit:\\d+ }")
@Timed
@Operation(summary = "Queue a manifestation", description = "This operation puts a unit and its manifestations on queue.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "The unit 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 unit", content = @Content(mediaType = MediaType.APPLICATION_JSON, schema = @Schema(ref = StatusResponse.NAME))) })
@Parameters({ @Parameter(name = "unitId", description = "The (corepo-)id of the unit", required = true), @Parameter(name = "trackingId", description = "For tracking the request", required = false) })
public Response queueUnit(@PathParam("unitId") String unitId, @QueryParam("trackingId") String trackingId) {
if (trackingId == null || trackingId.isEmpty())
trackingId = UUID.randomUUID().toString();
try (LogWith logWith = LogWith.track(trackingId).pid(unitId)) {
List<BibliographicEntity> biblEntitys = BibliographicEntity.fetchByUnit(entityManager, unitId);
if (biblEntitys.isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).entity(new StatusResponse("No such unit")).build();
}
EnqueueCollector enqueueCollector = enqueueSupplier.getEnqueueCollector();
biblEntitys.forEach(biblEntity -> enqueueCollector.add(biblEntity, QueueType.ENDPOINT, QueueType.UNITENDPOINT));
enqueueCollector.commit();
return Response.ok(new StatusResponse()).build();
} catch (SQLException ex) {
log.error("Error queueing: {}: {}", unitId, ex.getMessage());
log.debug("Error queueing: {}: ", unitId, 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 ResourceBean method deleteResource.
@DELETE
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("{fieldName}/{agencyId}:{bibliographicRecordId}")
@Operation(operationId = "delete-resource", summary = "Removes a resource to an item", description = "This operation removed the resource and queues old connected" + " manifestations item, if any.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response deleteResource(@PathParam("fieldName") String fieldName, @PathParam("agencyId") Integer agencyId, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("trackingId") String trackingId) throws JSONBException {
if (trackingId == null || trackingId.isEmpty())
trackingId = UUID.randomUUID().toString();
try (LogWith logWith = track(trackingId)) {
BibliographicResourceEntity resource = new BibliographicResourceEntity(agencyId, bibliographicRecordId, fieldName, false);
log.debug("DELETE resource: {}", resource);
return storeResource(resource);
}
}
use of dk.dbc.log.LogWith in project solr-document-store by DBCDK.
the class ResourceBean method putResource.
@PUT
@Consumes({ MediaType.APPLICATION_JSON })
@Produces({ MediaType.APPLICATION_JSON })
@Path("{fieldName}/{agencyId}:{bibliographicRecordId}")
@Operation(operationId = "add/update-resource", summary = "Adds/updates/removes a resource to/from an item", description = "This operation sets/removes the resource and connected" + " manifestations item, are queued.")
@APIResponses({ @APIResponse(name = "Success", responseCode = "200", description = "Resource has been added", ref = StatusResponse.NAME) })
@RequestBody(ref = BibliographicResourceSchemaAnnotated.NAME)
public Response putResource(String jsonContent, @PathParam("fieldName") String fieldName, @PathParam("agencyId") Integer agencyId, @PathParam("bibliographicRecordId") String bibliographicRecordId, @QueryParam("trackingId") String trackingId) throws JSONBException {
if (trackingId == null || trackingId.isEmpty())
trackingId = UUID.randomUUID().toString();
try (LogWith logWith = track(trackingId)) {
ResourceRestRequest request = jsonbContext.unmarshall(jsonContent, ResourceRestRequest.class);
BibliographicResourceEntity resource = new BibliographicResourceEntity(agencyId, bibliographicRecordId, fieldName, request.getHas());
log.debug("PUT resource: {}", resource);
return storeResource(resource);
}
}
use of dk.dbc.log.LogWith in project solr-document-store by DBCDK.
the class BibliographicRecordAPIBean method getBibliographicKeysByRepositoryIdWithSupersedeId.
@GET
@Path("bibliographic-records/repository-id/{repositoryId}")
@Produces({ MediaType.APPLICATION_JSON })
@Timed
public Response getBibliographicKeysByRepositoryIdWithSupersedeId(@PathParam("repositoryId") String repositoryID, @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) throws JsonProcessingException {
try (LogWith logWith = track(null)) {
log.info("Requesting bibliographic record with repository id: {}", repositoryID);
log.info("Query parameters - page: {}, page_size: {}, order_by: {}", page, pageSize, orderBy);
// Checking for valid query parameters
if (!BibliographicEntity.sortableColumns.contains(orderBy)) {
return Response.status(400).entity("{\"error\":\"order_by parameter not acceptable\"}").build();
}
String direction = desc ? "DESC" : "ASC";
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.repositoryId = ? ORDER BY b." + orderBy + " " + direction, "BibliographicEntityWithSupersedeId").setParameter(1, repositoryID).setParameter(2, orderBy).setFirstResult((page - 1) * pageSize).setMaxResults(pageSize);
List<BibliographicFrontendResponse> res = ((List<Object[]>) frontendQuery.getResultList()).stream().map((record) -> {
BibliographicEntity b = (BibliographicEntity) record[0];
return new BibliographicFrontendResponse(b, (String) record[1]);
}).collect(Collectors.toList());
Query queryTotal = entityManager.createNativeQuery("SELECT COUNT(b.bibliographicRecordId) FROM bibliographicsolrkeys b WHERE b.repositoryId = ?").setParameter(1, repositoryID);
long count = (long) queryTotal.getSingleResult();
return Response.ok(new FrontendReturnListType<>(res, pageCount(count, pageSize)), MediaType.APPLICATION_JSON).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