Search in sources :

Example 1 with Timed

use of dk.dbc.search.solrdocstore.monitor.Timed in project solr-document-store by DBCDK.

the class BiliographicRecordAPIBean 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) {
    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<BibliographicFrontendEntity> bibliographicFrontendEntityList = resultList.stream().map((record) -> {
        BibliographicEntity b = (BibliographicEntity) record[0];
        return new BibliographicFrontendEntity(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 : Stateless(javax.ejb.Stateless) PathParam(javax.ws.rs.PathParam) Logger(org.slf4j.Logger) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Collectors(java.util.stream.Collectors) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Timed(dk.dbc.search.solrdocstore.monitor.Timed) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Inject(javax.inject.Inject) Query(javax.persistence.Query) MediaType(javax.ws.rs.core.MediaType) List(java.util.List) QueryParam(javax.ws.rs.QueryParam) Response(javax.ws.rs.core.Response) DefaultValue(javax.ws.rs.DefaultValue) Query(javax.persistence.Query) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(dk.dbc.search.solrdocstore.monitor.Timed) GET(javax.ws.rs.GET)

Example 2 with Timed

use of dk.dbc.search.solrdocstore.monitor.Timed in project solr-document-store by DBCDK.

the class BiliographicRecordAPIBean 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 {
    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<BibliographicFrontendEntity> res = ((List<Object[]>) frontendQuery.getResultList()).stream().map((record) -> {
        BibliographicEntity b = (BibliographicEntity) record[0];
        return new BibliographicFrontendEntity(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 : Stateless(javax.ejb.Stateless) PathParam(javax.ws.rs.PathParam) Logger(org.slf4j.Logger) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) EntityManager(javax.persistence.EntityManager) PersistenceContext(javax.persistence.PersistenceContext) Collectors(java.util.stream.Collectors) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Timed(dk.dbc.search.solrdocstore.monitor.Timed) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Inject(javax.inject.Inject) Query(javax.persistence.Query) MediaType(javax.ws.rs.core.MediaType) List(java.util.List) QueryParam(javax.ws.rs.QueryParam) Response(javax.ws.rs.core.Response) DefaultValue(javax.ws.rs.DefaultValue) Query(javax.persistence.Query) List(java.util.List) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(dk.dbc.search.solrdocstore.monitor.Timed) GET(javax.ws.rs.GET)

Example 3 with Timed

use of dk.dbc.search.solrdocstore.monitor.Timed in project solr-document-store by DBCDK.

the class BiliographicRecordAPIBean method getBibliographicRecord.

@GET
@Path("bibliographic-record/{bibliographicRecordId}/{bibliographicAgencyId}")
@Produces({ MediaType.APPLICATION_JSON })
@Timed
public Response getBibliographicRecord(@PathParam("bibliographicRecordId") String bibliographicRecordId, @PathParam("bibliographicAgencyId") int bibliographicAgencyId) {
    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 BibliographicFrontendEntity((BibliographicEntity) record[0], (String) record[1])).build();
}
Also used : Query(javax.persistence.Query) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(dk.dbc.search.solrdocstore.monitor.Timed) GET(javax.ws.rs.GET)

Aggregations

Timed (dk.dbc.search.solrdocstore.monitor.Timed)3 Query (javax.persistence.Query)3 GET (javax.ws.rs.GET)3 Path (javax.ws.rs.Path)3 Produces (javax.ws.rs.Produces)3 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Stateless (javax.ejb.Stateless)2 Inject (javax.inject.Inject)2 EntityManager (javax.persistence.EntityManager)2 PersistenceContext (javax.persistence.PersistenceContext)2 DefaultValue (javax.ws.rs.DefaultValue)2 PathParam (javax.ws.rs.PathParam)2 QueryParam (javax.ws.rs.QueryParam)2 MediaType (javax.ws.rs.core.MediaType)2 Response (javax.ws.rs.core.Response)2