Search in sources :

Example 1 with LogWith

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);
    }
}
Also used : LogWith(dk.dbc.log.LogWith) BibliographicResourceEntity(dk.dbc.search.solrdocstore.jpa.BibliographicResourceEntity) AddResourceRequest(dk.dbc.search.solrdocstore.request.AddResourceRequest) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) 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 2 with LogWith

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();
    }
}
Also used : LogWith(dk.dbc.log.LogWith) Query(javax.persistence.Query) 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 3 with LogWith

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();
    }
}
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 4 with LogWith

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();
    }
}
Also used : DocumentRetrieveResponse(dk.dbc.search.solrdocstore.response.DocumentRetrieveResponse) LogWith(dk.dbc.log.LogWith) WorkRetrieveResponse(dk.dbc.search.solrdocstore.response.WorkRetrieveResponse) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(org.eclipse.microprofile.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 5 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)10 Path (javax.ws.rs.Path)10 Produces (javax.ws.rs.Produces)10 GET (javax.ws.rs.GET)7 Timed (org.eclipse.microprofile.metrics.annotation.Timed)7 Operation (org.eclipse.microprofile.openapi.annotations.Operation)5 APIResponses (org.eclipse.microprofile.openapi.annotations.responses.APIResponses)5 BibliographicEntity (dk.dbc.search.solrdocstore.jpa.BibliographicEntity)4 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 Query (javax.persistence.Query)3 Consumes (javax.ws.rs.Consumes)3 RequestBody (org.eclipse.microprofile.openapi.annotations.parameters.RequestBody)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 LogWith.track (dk.dbc.log.LogWith.track)2 EnqueueCollector (dk.dbc.search.solrdocstore.enqueue.EnqueueCollector)2 StatusResponse (dk.dbc.search.solrdocstore.response.StatusResponse)2 SQLException (java.sql.SQLException)2