Search in sources :

Example 1 with DefaultValue

use of javax.ws.rs.DefaultValue in project che by eclipse.

the class FactoryService method getFactoryByAttribute.

@GET
@Path("/find")
@Produces(APPLICATION_JSON)
@ApiOperation(value = "Get factory by attribute, " + "the attribute must match one of the Factory model fields with type 'String', " + "e.g. (factory.name, factory.creator.name)", notes = "If specify more than one value for a single query parameter then will be taken the first one")
@ApiResponses({ @ApiResponse(code = 200, message = "Response contains list requested factories"), @ApiResponse(code = 400, message = "When query does not contain at least one attribute to search for"), @ApiResponse(code = 500, message = "Internal server error") })
public List<FactoryDto> getFactoryByAttribute(@DefaultValue("0") @QueryParam("skipCount") Integer skipCount, @DefaultValue("30") @QueryParam("maxItems") Integer maxItems, @Context UriInfo uriInfo) throws BadRequestException, ServerException {
    final Set<String> skip = ImmutableSet.of("token", "skipCount", "maxItems");
    final List<Pair<String, String>> query = URLEncodedUtils.parse(uriInfo.getRequestUri()).entrySet().stream().filter(param -> !skip.contains(param.getKey()) && !param.getValue().isEmpty()).map(entry -> Pair.of(entry.getKey(), entry.getValue().iterator().next())).collect(toList());
    checkArgument(!query.isEmpty(), "Query must contain at least one attribute");
    final List<FactoryDto> factories = new ArrayList<>();
    for (Factory factory : factoryManager.getByAttribute(maxItems, skipCount, query)) {
        factories.add(injectLinks(asDto(factory), null));
    }
    return factories;
}
Also used : URLEncodedUtils(org.eclipse.che.commons.lang.URLEncodedUtils) Produces(javax.ws.rs.Produces) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) FactoryBuilder(org.eclipse.che.api.factory.server.builder.FactoryBuilder) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) ApiOperation(io.swagger.annotations.ApiOperation) QueryParam(javax.ws.rs.QueryParam) Service(org.eclipse.che.api.core.rest.Service) PreferenceManager(org.eclipse.che.api.user.server.PreferenceManager) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) APPLICATION_JSON(javax.ws.rs.core.MediaType.APPLICATION_JSON) NameGenerator(org.eclipse.che.commons.lang.NameGenerator) DELETE(javax.ws.rs.DELETE) WorkspaceManager(org.eclipse.che.api.workspace.server.WorkspaceManager) ImmutableSet(com.google.common.collect.ImmutableSet) Context(javax.ws.rs.core.Context) Predicate(java.util.function.Predicate) Set(java.util.Set) Pair(org.eclipse.che.commons.lang.Pair) AuthorDto(org.eclipse.che.api.factory.shared.dto.AuthorDto) List(java.util.List) BadRequestException(org.eclipse.che.api.core.BadRequestException) Response(javax.ws.rs.core.Response) ProjectConfig(org.eclipse.che.api.core.model.project.ProjectConfig) UriInfo(javax.ws.rs.core.UriInfo) WorkspaceImpl(org.eclipse.che.api.workspace.server.model.impl.WorkspaceImpl) TEXT_PLAIN(javax.ws.rs.core.MediaType.TEXT_PLAIN) FactoryLinksHelper.createLinks(org.eclipse.che.api.factory.server.FactoryLinksHelper.createLinks) PathParam(javax.ws.rs.PathParam) ByteArrayOutputStream(java.io.ByteArrayOutputStream) GET(javax.ws.rs.GET) Strings.isNullOrEmpty(com.google.common.base.Strings.isNullOrEmpty) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) Inject(javax.inject.Inject) HashSet(java.util.HashSet) EnvironmentContext(org.eclipse.che.commons.env.EnvironmentContext) ApiException(org.eclipse.che.api.core.ApiException) User(org.eclipse.che.api.core.model.user.User) ConflictException(org.eclipse.che.api.core.ConflictException) MULTIPART_FORM_DATA(javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA) Api(io.swagger.annotations.Api) DtoFactory(org.eclipse.che.dto.server.DtoFactory) CONTENT_DISPOSITION(javax.ws.rs.core.HttpHeaders.CONTENT_DISPOSITION) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) Iterator(java.util.Iterator) JsonSyntaxException(com.google.gson.JsonSyntaxException) FileItem(org.apache.commons.fileupload.FileItem) IOException(java.io.IOException) NotFoundException(org.eclipse.che.api.core.NotFoundException) Factory(org.eclipse.che.api.core.model.factory.Factory) Collectors.toList(java.util.stream.Collectors.toList) Boolean.parseBoolean(java.lang.Boolean.parseBoolean) ServerException(org.eclipse.che.api.core.ServerException) ApiResponse(io.swagger.annotations.ApiResponse) ForbiddenException(org.eclipse.che.api.core.ForbiddenException) ProjectConfigImpl(org.eclipse.che.api.workspace.server.model.impl.ProjectConfigImpl) PUT(javax.ws.rs.PUT) UserManager(org.eclipse.che.api.user.server.UserManager) Collections(java.util.Collections) InputStream(java.io.InputStream) FactoryDto(org.eclipse.che.api.factory.shared.dto.FactoryDto) ArrayList(java.util.ArrayList) LoggerFactory(org.slf4j.LoggerFactory) DtoFactory(org.eclipse.che.dto.server.DtoFactory) Factory(org.eclipse.che.api.core.model.factory.Factory) Pair(org.eclipse.che.commons.lang.Pair) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 2 with DefaultValue

use of javax.ws.rs.DefaultValue in project che by eclipse.

the class Service method generateLinkForMethod.

private Link generateLinkForMethod(UriInfo uriInfo, String linkRel, Method method, Object... pathParameters) {
    String httpMethod = null;
    final HttpMethod httpMethodAnnotation = getMetaAnnotation(method, HttpMethod.class);
    if (httpMethodAnnotation != null) {
        httpMethod = httpMethodAnnotation.value();
    }
    if (httpMethod == null) {
        throw new IllegalArgumentException(format("Method '%s' has not any HTTP method annotation and may not be used to produce link.", method.getName()));
    }
    final Consumes consumes = getAnnotation(method, Consumes.class);
    final Produces produces = getAnnotation(method, Produces.class);
    final UriBuilder baseUriBuilder = uriInfo.getBaseUriBuilder();
    final LinkedList<String> matchedURIs = new LinkedList<>(uriInfo.getMatchedURIs());
    // Get path to the root resource.
    if (uriInfo.getMatchedResources().size() < matchedURIs.size()) {
        matchedURIs.remove();
    }
    while (!matchedURIs.isEmpty()) {
        baseUriBuilder.path(matchedURIs.pollLast());
    }
    final Path path = method.getAnnotation(Path.class);
    if (path != null) {
        baseUriBuilder.path(path.value());
    }
    final Link link = DtoFactory.getInstance().createDto(Link.class).withRel(linkRel).withHref(baseUriBuilder.build(pathParameters).toString()).withMethod(httpMethod);
    if (consumes != null) {
        link.setConsumes(consumes.value()[0]);
    }
    if (produces != null) {
        link.setProduces(produces.value()[0]);
    }
    Class<?>[] parameterClasses = method.getParameterTypes();
    if (parameterClasses.length > 0) {
        Annotation[][] annotations = method.getParameterAnnotations();
        for (int i = 0; i < parameterClasses.length; i++) {
            if (annotations[i].length > 0) {
                boolean isBodyParameter = false;
                QueryParam queryParam = null;
                Description description = null;
                Required required = null;
                Valid valid = null;
                DefaultValue defaultValue = null;
                for (int j = 0; j < annotations[i].length; j++) {
                    Annotation annotation = annotations[i][j];
                    isBodyParameter |= !JAX_RS_ANNOTATIONS.contains(annotation.annotationType().getName());
                    Class<?> annotationType = annotation.annotationType();
                    if (annotationType == QueryParam.class) {
                        queryParam = (QueryParam) annotation;
                    } else if (annotationType == Description.class) {
                        description = (Description) annotation;
                    } else if (annotationType == Required.class) {
                        required = (Required) annotation;
                    } else if (annotationType == Valid.class) {
                        valid = (Valid) annotation;
                    } else if (annotationType == DefaultValue.class) {
                        defaultValue = (DefaultValue) annotation;
                    }
                }
                if (queryParam != null) {
                    LinkParameter parameter = DtoFactory.getInstance().createDto(LinkParameter.class).withName(queryParam.value()).withRequired(required != null).withType(getParameterType(parameterClasses[i]));
                    if (defaultValue != null) {
                        parameter.setDefaultValue(defaultValue.value());
                    }
                    if (description != null) {
                        parameter.setDescription(description.value());
                    }
                    if (valid != null) {
                        parameter.setValid(Arrays.asList(valid.value()));
                    }
                    link.getParameters().add(parameter);
                } else if (isBodyParameter) {
                    if (description != null) {
                        link.setRequestBody(DtoFactory.getInstance().createDto(RequestBodyDescriptor.class).withDescription(description.value()));
                    }
                }
            }
        }
    }
    return link;
}
Also used : Path(javax.ws.rs.Path) RequestBodyDescriptor(org.eclipse.che.api.core.rest.shared.dto.RequestBodyDescriptor) Description(org.eclipse.che.api.core.rest.annotations.Description) LinkParameter(org.eclipse.che.api.core.rest.shared.dto.LinkParameter) LinkedList(java.util.LinkedList) Annotation(java.lang.annotation.Annotation) DefaultValue(javax.ws.rs.DefaultValue) Required(org.eclipse.che.api.core.rest.annotations.Required) Consumes(javax.ws.rs.Consumes) Produces(javax.ws.rs.Produces) QueryParam(javax.ws.rs.QueryParam) Valid(org.eclipse.che.api.core.rest.annotations.Valid) UriBuilder(javax.ws.rs.core.UriBuilder) HttpMethod(javax.ws.rs.HttpMethod) Link(org.eclipse.che.api.core.rest.shared.dto.Link) GenerateLink(org.eclipse.che.api.core.rest.annotations.GenerateLink)

Example 3 with DefaultValue

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

the class GroupWebService method searchGroupsPost.

@Path("/.search")
@POST
@Produces({ Constants.MEDIA_TYPE_SCIM_JSON, MediaType.APPLICATION_JSON })
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
@ApiOperation(value = "Search group POST /.search", notes = "Returns a list of groups (https://tools.ietf.org/html/rfc7644#section-3.4.3)", response = ListResponse.class)
public Response searchGroupsPost(@HeaderParam("Authorization") String authorization, @QueryParam(OxTrustConstants.QUERY_PARAMETER_TEST_MODE_OAUTH2_TOKEN) final String token, @ApiParam(value = "SearchRequest", required = true) SearchRequest searchRequest) throws Exception {
    try {
        log.info("IN GroupWebService.searchGroupsPost()...");
        // Authorization check is done in searchGroups()
        Response response = searchGroups(authorization, token, searchRequest.getFilter(), searchRequest.getStartIndex(), searchRequest.getCount(), searchRequest.getSortBy(), searchRequest.getSortOrder(), searchRequest.getAttributesArray());
        URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/Groups/.search");
        log.info("LEAVING GroupWebService.searchGroupsPost()...");
        return Response.fromResponse(response).location(location).build();
    } catch (EntryPersistenceException ex) {
        log.error("Error in searchGroupsPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.NOT_FOUND, ErrorScimType.INVALID_VALUE, "Resource not found");
    } catch (Exception ex) {
        log.error("Error in searchGroupsPost", ex);
        ex.printStackTrace();
        return getErrorResponse(Response.Status.BAD_REQUEST, ErrorScimType.INVALID_FILTER, INTERNAL_SERVER_ERROR_MESSAGE);
    }
}
Also used : VirtualListViewResponse(org.xdi.ldap.model.VirtualListViewResponse) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) Response(javax.ws.rs.core.Response) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) URI(java.net.URI) EntryPersistenceException(org.gluu.site.ldap.persistence.exception.EntryPersistenceException) DuplicateEntryException(org.gluu.site.ldap.exception.DuplicateEntryException) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation)

Example 4 with DefaultValue

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

the class ResourceTypeWS method getResourceTypeUser.

@Path("User")
@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response getResourceTypeUser(@HeaderParam("Authorization") String authorization) throws Exception {
    ResourceType userResourceType = new ResourceType();
    userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
    userResourceType.setEndpoint("/v2/Users");
    userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
    Meta userMeta = new Meta();
    userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    userMeta.setResourceType("ResourceType");
    userResourceType.setMeta(userMeta);
    List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
    SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
    userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
    userExtensionSchema.setRequired(false);
    schemaExtensions.add(userExtensionSchema);
    userResourceType.setSchemaExtensions(schemaExtensions);
    // ResourceType[] resourceTypes = new ResourceType[]{userResourceType};
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    // return Response.ok(resourceTypes).location(location).build();
    return Response.ok(userResourceType).location(location).build();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.schema.SchemaExtensionHolder) ArrayList(java.util.ArrayList) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) Path(javax.ws.rs.Path) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Example 5 with DefaultValue

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

the class ResourceTypeWS method listResources.

@GET
@Produces(Constants.MEDIA_TYPE_SCIM_JSON + "; charset=utf-8")
@HeaderParam("Accept")
@DefaultValue(Constants.MEDIA_TYPE_SCIM_JSON)
public Response listResources(@HeaderParam("Authorization") String authorization) throws Exception {
    ListResponse listResponse = new ListResponse();
    List<String> schemas = new ArrayList<String>();
    schemas.add(Constants.LIST_RESPONSE_SCHEMA_ID);
    listResponse.setSchemas(schemas);
    // START: User
    ResourceType userResourceType = new ResourceType();
    userResourceType.setDescription(Constants.USER_CORE_SCHEMA_DESCRIPTION);
    userResourceType.setEndpoint("/v2/Users");
    userResourceType.setName(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setId(Constants.USER_CORE_SCHEMA_NAME);
    userResourceType.setSchema(Constants.USER_CORE_SCHEMA_ID);
    Meta userMeta = new Meta();
    userMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/User");
    userMeta.setResourceType("ResourceType");
    userResourceType.setMeta(userMeta);
    List<SchemaExtensionHolder> schemaExtensions = new ArrayList<SchemaExtensionHolder>();
    SchemaExtensionHolder userExtensionSchema = new SchemaExtensionHolder();
    userExtensionSchema.setSchema(Constants.USER_EXT_SCHEMA_ID);
    userExtensionSchema.setRequired(false);
    schemaExtensions.add(userExtensionSchema);
    userResourceType.setSchemaExtensions(schemaExtensions);
    // START: Group
    ResourceType groupResourceType = new ResourceType();
    groupResourceType.setDescription(Constants.GROUP_CORE_SCHEMA_DESCRIPTION);
    groupResourceType.setEndpoint("/v2/Groups");
    groupResourceType.setName(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setId(Constants.GROUP_CORE_SCHEMA_NAME);
    groupResourceType.setSchema(Constants.GROUP_CORE_SCHEMA_ID);
    Meta groupMeta = new Meta();
    groupMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/Group");
    groupMeta.setResourceType("ResourceType");
    groupResourceType.setMeta(groupMeta);
    // START: FidoDevice
    ResourceType fidoDeviceResourceType = new ResourceType();
    fidoDeviceResourceType.setDescription(Constants.FIDO_DEVICES_CORE_SCHEMA_DESCRIPTION);
    fidoDeviceResourceType.setEndpoint("/v2/FidoDevices");
    fidoDeviceResourceType.setName(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setId(Constants.FIDO_DEVICES_CORE_SCHEMA_NAME);
    fidoDeviceResourceType.setSchema(Constants.FIDO_DEVICES_CORE_SCHEMA_ID);
    Meta fidoDeviceMeta = new Meta();
    fidoDeviceMeta.setLocation(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes/FidoDevice");
    fidoDeviceMeta.setResourceType("ResourceType");
    fidoDeviceResourceType.setMeta(fidoDeviceMeta);
    // ResourceType[] resourceTypes = new ResourceType[]{userResourceType, groupResourceType};
    List<Resource> resourceTypes = new ArrayList<Resource>();
    resourceTypes.add(userResourceType);
    resourceTypes.add(groupResourceType);
    resourceTypes.add(fidoDeviceResourceType);
    listResponse.setResources(resourceTypes);
    listResponse.setTotalResults(resourceTypes.size());
    listResponse.setItemsPerPage(10);
    listResponse.setStartIndex(1);
    URI location = new URI(appConfiguration.getBaseEndpoint() + "/scim/v2/ResourceTypes");
    // return Response.ok(resourceTypes).location(location).build();
    return Response.ok(listResponse).location(location).build();
}
Also used : Meta(org.gluu.oxtrust.model.scim2.Meta) SchemaExtensionHolder(org.gluu.oxtrust.model.scim2.schema.SchemaExtensionHolder) ListResponse(org.gluu.oxtrust.model.scim2.ListResponse) ArrayList(java.util.ArrayList) Resource(org.gluu.oxtrust.model.scim2.Resource) ResourceType(org.gluu.oxtrust.model.scim2.provider.ResourceType) URI(java.net.URI) DefaultValue(javax.ws.rs.DefaultValue) HeaderParam(javax.ws.rs.HeaderParam) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

DefaultValue (javax.ws.rs.DefaultValue)82 Produces (javax.ws.rs.Produces)66 Response (javax.ws.rs.core.Response)62 Path (javax.ws.rs.Path)55 HeaderParam (javax.ws.rs.HeaderParam)48 GET (javax.ws.rs.GET)45 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)33 Consumes (javax.ws.rs.Consumes)31 POST (javax.ws.rs.POST)29 PathParam (javax.ws.rs.PathParam)28 List (java.util.List)23 ArrayList (java.util.ArrayList)22 Inject (javax.inject.Inject)20 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)20 InvalidAttributeValueException (javax.management.InvalidAttributeValueException)19 PUT (javax.ws.rs.PUT)19 SCIMException (org.gluu.oxtrust.model.exception.SCIMException)19