Search in sources :

Example 61 with DefaultValue

use of javax.ws.rs.DefaultValue in project oxTrust by GluuFederation.

the class UserWebService method searchUsers.

@GET
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Search users", notes = "Returns a list of users (https://tools.ietf.org/html/rfc7644#section-3.4.2.2)", response = ListResponse.class)
public Response searchUsers(@QueryParam(QUERY_PARAM_FILTER) String filter, @QueryParam(QUERY_PARAM_START_INDEX) Integer startIndex, @QueryParam(QUERY_PARAM_COUNT) Integer count, @QueryParam(QUERY_PARAM_SORT_BY) String sortBy, @QueryParam(QUERY_PARAM_SORT_ORDER) String sortOrder, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. searchUsers");
        sortBy = translateSortByAttribute(UserResource.class, sortBy);
        ListViewResponse<BaseScimResource> resources = scim2UserService.searchUsers(filter, sortBy, SortOrder.getByValue(sortOrder), startIndex, count, endpointUrl, getMaxCount());
        String json = getListResponseSerialized(resources.getTotalResults(), startIndex, resources.getResult(), attrsList, excludedAttrsList, count == 0);
        response = Response.ok(json).location(new URI(endpointUrl)).build();
    } catch (SCIMException e) {
        log.error(e.getMessage(), e);
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at searchUsers method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) BaseScimResource(org.gluu.oxtrust.model.scim2.BaseScimResource) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 62 with DefaultValue

use of javax.ws.rs.DefaultValue in project oxTrust by GluuFederation.

the class UserWebService method searchUsersPost.

@Path(SEARCH_SUFFIX)
@POST
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Search users POST /.search", notes = "Returns a list of users (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchUsersPost(@ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) {
    log.debug("Executing web service method. searchUsersPost");
    // Calling searchUsers here does not provoke that method's interceptor/decorator being called (only this one's)
    URI uri = null;
    Response response = searchUsers(searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesStr(), searchRequest.getExcludedAttributesStr());
    try {
        uri = new URI(endpointUrl + "/" + SEARCH_SUFFIX);
    } catch (Exception e) {
        log.error(e.getMessage(), e);
    }
    return Response.fromResponse(response).location(uri).build();
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) URI(java.net.URI) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) POST(javax.ws.rs.POST) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi)

Example 63 with DefaultValue

use of javax.ws.rs.DefaultValue in project oxTrust by GluuFederation.

the class UserWebService method updateUser.

/**
 * This implementation differs from spec in the following aspects:
 * - Passing a null value for an attribute, does not modify the attribute in the destination, however passing an
 * empty array for a multivalued attribute does clear the attribute. Thus, to clear single-valued attribute, PATCH
 * operation should be used
 */
@Path("{id}")
@PUT
@Consumes({ MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@Produces({ MEDIA_TYPE_SCIM_JSON + UTF8_CHARSET_FRAGMENT, MediaType.APPLICATION_JSON + UTF8_CHARSET_FRAGMENT })
@HeaderParam("Accept")
@DefaultValue(MEDIA_TYPE_SCIM_JSON)
@ProtectedApi
@RefAdjusted
@ApiOperation(value = "Update user", notes = "Update user (https://tools.ietf.org/html/rfc7644#section-3.5.1)", response = UserResource.class)
public Response updateUser(@ApiParam(value = "User", required = true) UserResource user, @PathParam("id") String id, @QueryParam(QUERY_PARAM_ATTRIBUTES) String attrsList, @QueryParam(QUERY_PARAM_EXCLUDED_ATTRS) String excludedAttrsList) {
    Response response;
    try {
        log.debug("Executing web service method. updateUser");
        UserResource updatedResource = scim2UserService.updateUser(id, user, endpointUrl);
        String json = resourceSerializer.serialize(updatedResource, attrsList, excludedAttrsList);
        response = Response.ok(new URI(updatedResource.getMeta().getLocation())).entity(json).build();
    } catch (InvalidAttributeValueException e) {
        log.error(e.getMessage());
        response = getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.MUTABILITY, e.getMessage());
    } catch (Exception e) {
        log.error("Failure at updateUser method", e);
        response = getErrorResponse(Response.Status.INTERNAL_SERVER_ERROR, "Unexpected error: " + e.getMessage());
    }
    return response;
}
Also used : ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) ListViewResponse(org.gluu.persist.model.ListViewResponse) UserResource(org.gluu.oxtrust.model.scim2.user.UserResource) URI(java.net.URI) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) SCIMException(org.gluu.oxtrust.model.exception.SCIMException) InvalidAttributeValueException(javax.management.InvalidAttributeValueException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) RefAdjusted(org.gluu.oxtrust.service.scim2.interceptor.RefAdjusted) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) PUT(javax.ws.rs.PUT)

Example 64 with DefaultValue

use of javax.ws.rs.DefaultValue 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 65 with DefaultValue

use of javax.ws.rs.DefaultValue 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)

Aggregations

DefaultValue (javax.ws.rs.DefaultValue)83 Produces (javax.ws.rs.Produces)67 Response (javax.ws.rs.core.Response)63 Path (javax.ws.rs.Path)56 HeaderParam (javax.ws.rs.HeaderParam)49 GET (javax.ws.rs.GET)46 URI (java.net.URI)42 ListResponse (org.gluu.oxtrust.model.scim2.ListResponse)36 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)35 QueryParam (javax.ws.rs.QueryParam)34 Consumes (javax.ws.rs.Consumes)32 POST (javax.ws.rs.POST)30 PathParam (javax.ws.rs.PathParam)29 List (java.util.List)24 ArrayList (java.util.ArrayList)23 Inject (javax.inject.Inject)20 PUT (javax.ws.rs.PUT)20 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)20 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)19 MediaType (javax.ws.rs.core.MediaType)19