Search in sources :

Example 6 with LogWith

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();
    }
}
Also used : LogWith(dk.dbc.log.LogWith) SQLException(java.sql.SQLException) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) StatusResponse(dk.dbc.search.solrdocstore.response.StatusResponse) EnqueueCollector(dk.dbc.search.solrdocstore.enqueue.EnqueueCollector) Path(javax.ws.rs.Path) Parameters(org.eclipse.microprofile.openapi.annotations.parameters.Parameters) Produces(javax.ws.rs.Produces) Timed(org.eclipse.microprofile.metrics.annotation.Timed) GET(javax.ws.rs.GET) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation)

Example 7 with LogWith

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);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Example 8 with LogWith

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);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) ResourceRestRequest(dk.dbc.search.solrdocstore.request.ResourceRestRequest) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) Path(javax.ws.rs.Path) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) APIResponses(org.eclipse.microprofile.openapi.annotations.responses.APIResponses) Operation(org.eclipse.microprofile.openapi.annotations.Operation) PUT(javax.ws.rs.PUT) RequestBody(org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)

Example 9 with LogWith

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();
    }
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) FrontendReturnListType(dk.dbc.search.solrdocstore.response.FrontendReturnListType) DefaultValue(javax.ws.rs.DefaultValue) Timed(org.eclipse.microprofile.metrics.annotation.Timed) LogWith.track(dk.dbc.log.LogWith.track) LogWith(dk.dbc.log.LogWith) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) BibliographicFrontendResponse(dk.dbc.search.solrdocstore.response.BibliographicFrontendResponse) Collectors(java.util.stream.Collectors) Query(javax.persistence.Query) List(java.util.List) Response(javax.ws.rs.core.Response) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) LogWith(dk.dbc.log.LogWith) Query(javax.persistence.Query) FrontendReturnListType(dk.dbc.search.solrdocstore.response.FrontendReturnListType) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) List(java.util.List) BibliographicFrontendResponse(dk.dbc.search.solrdocstore.response.BibliographicFrontendResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(org.eclipse.microprofile.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 10 with LogWith

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();
    }
}
Also used : PathParam(javax.ws.rs.PathParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) Inject(javax.inject.Inject) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) FrontendReturnListType(dk.dbc.search.solrdocstore.response.FrontendReturnListType) DefaultValue(javax.ws.rs.DefaultValue) Timed(org.eclipse.microprofile.metrics.annotation.Timed) LogWith.track(dk.dbc.log.LogWith.track) LogWith(dk.dbc.log.LogWith) Stateless(javax.ejb.Stateless) Logger(org.slf4j.Logger) HoldingsItemEntity(dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) BibliographicFrontendResponse(dk.dbc.search.solrdocstore.response.BibliographicFrontendResponse) Collectors(java.util.stream.Collectors) Query(javax.persistence.Query) List(java.util.List) Response(javax.ws.rs.core.Response) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) LogWith(dk.dbc.log.LogWith) Query(javax.persistence.Query) FrontendReturnListType(dk.dbc.search.solrdocstore.response.FrontendReturnListType) BibliographicEntity(dk.dbc.search.solrdocstore.jpa.BibliographicEntity) BibliographicFrontendResponse(dk.dbc.search.solrdocstore.response.BibliographicFrontendResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(org.eclipse.microprofile.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Aggregations

LogWith (dk.dbc.log.LogWith)12 Path (javax.ws.rs.Path)12 Produces (javax.ws.rs.Produces)12 GET (javax.ws.rs.GET)9 Timed (org.eclipse.microprofile.metrics.annotation.Timed)9 Operation (org.eclipse.microprofile.openapi.annotations.Operation)6 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)6 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)5 EnqueueCollector (dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)3 BibliographicResourceEntity (dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity)3 HoldingsItemEntity (dk.dbc.search.solrdocstore.jpa.HoldingsItemEntity)3 BibliographicFrontendResponse (dk.dbc.search.solrdocstore.response.BibliographicFrontendResponse)3 FrontendReturnListType (dk.dbc.search.solrdocstore.response.FrontendReturnListType)3 StatusResponse (dk.dbc.search.solrdocstore.response.StatusResponse)3 SQLException (java.sql.SQLException)3 Query (javax.persistence.Query)3 Consumes (javax.ws.rs.Consumes)3 Parameters (org.eclipse.microprofile.openapi.annotations.parameters.Parameters)3 RequestBody (org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2