Search in sources :

Example 41 with PathParam

use of javax.ws.rs.PathParam in project graylog2-server by Graylog2.

the class IndicesResource method indexSetReopened.

@GET
@Timed
@Path("/{indexSetId}/reopened")
@ApiOperation(value = "Get a list of reopened indices, which will not be cleaned by retention cleaning")
@Produces(MediaType.APPLICATION_JSON)
public ClosedIndices indexSetReopened(@ApiParam(name = "indexSetId") @PathParam("indexSetId") String indexSetId) {
    final IndexSet indexSet = getIndexSet(indexSetRegistry, indexSetId);
    final Set<String> reopenedIndices = indices.getReopenedIndices(indexSet).stream().filter(index -> isPermitted(RestPermissions.INDICES_READ, index)).collect(Collectors.toSet());
    return ClosedIndices.create(reopenedIndices, reopenedIndices.size());
}
Also used : IndicesReadRequest(org.graylog2.rest.models.system.indexer.requests.IndicesReadRequest) PathParam(javax.ws.rs.PathParam) AllIndices(org.graylog2.rest.models.system.indexer.responses.AllIndices) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) ClosedIndices(org.graylog2.rest.models.system.indexer.responses.ClosedIndices) Inject(javax.inject.Inject) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) ShardRouting(org.graylog2.rest.models.system.indexer.responses.ShardRouting) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) MediaType(javax.ws.rs.core.MediaType) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) Api(io.swagger.annotations.Api) IndexSet(org.graylog2.indexer.IndexSet) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) DELETE(javax.ws.rs.DELETE) NoAuditEvent(org.graylog2.audit.jersey.NoAuditEvent) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) ForbiddenException(javax.ws.rs.ForbiddenException) ImmutableMap(com.google.common.collect.ImmutableMap) Collection(java.util.Collection) IndexInfo(org.graylog2.rest.models.system.indexer.responses.IndexInfo) Set(java.util.Set) RestResource(org.graylog2.shared.rest.resources.RestResource) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) ApiResponse(io.swagger.annotations.ApiResponse) AuditEventTypes(org.graylog2.audit.AuditEventTypes) OpenIndicesInfo(org.graylog2.rest.models.system.indexer.responses.OpenIndicesInfo) RestPermissions(org.graylog2.shared.security.RestPermissions) NodeInfoCache(org.graylog2.indexer.NodeInfoCache) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) TooManyAliasesException(org.graylog2.indexer.indices.TooManyAliasesException) IndexSet(org.graylog2.indexer.IndexSet) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation)

Example 42 with PathParam

use of javax.ws.rs.PathParam in project graylog2-server by Graylog2.

the class IndexSetsResource method get.

@GET
@Path("{id}")
@Timed
@ApiOperation(value = "Get index set")
@ApiResponses(value = { @ApiResponse(code = 403, message = "Unauthorized"), @ApiResponse(code = 404, message = "Index set not found") })
public IndexSetSummary get(@ApiParam(name = "id", required = true) @PathParam("id") String id) {
    checkPermission(RestPermissions.INDEXSETS_READ, id);
    final IndexSetConfig defaultIndexSet = indexSetService.getDefault();
    return indexSetService.get(id).map(config -> IndexSetSummary.fromIndexSetConfig(config, config.equals(defaultIndexSet))).orElseThrow(() -> new NotFoundException("Couldn't load index set with ID <" + id + ">"));
}
Also used : IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) Produces(javax.ws.rs.Produces) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) ApiParam(io.swagger.annotations.ApiParam) ClientErrorException(javax.ws.rs.ClientErrorException) Valid(javax.validation.Valid) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) ClusterConfigService(org.graylog2.plugin.cluster.ClusterConfigService) Consumes(javax.ws.rs.Consumes) Indices(org.graylog2.indexer.indices.Indices) Map(java.util.Map) DefaultValue(javax.ws.rs.DefaultValue) BadRequestException(javax.ws.rs.BadRequestException) IndexSet(org.graylog2.indexer.IndexSet) IndexSetStats(org.graylog2.rest.resources.system.indexer.responses.IndexSetStats) DELETE(javax.ws.rs.DELETE) IndexSetStatsCreator(org.graylog2.indexer.IndexSetStatsCreator) Set(java.util.Set) NotNull(javax.validation.constraints.NotNull) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) SystemJobManager(org.graylog2.system.jobs.SystemJobManager) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) IndexSetService(org.graylog2.indexer.indexset.IndexSetService) Response(javax.ws.rs.core.Response) AuditEventTypes(org.graylog2.audit.AuditEventTypes) Optional(java.util.Optional) RequiresAuthentication(org.apache.shiro.authz.annotation.RequiresAuthentication) DuplicateKeyException(com.mongodb.DuplicateKeyException) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) IndexSetCleanupJob(org.graylog2.indexer.indices.jobs.IndexSetCleanupJob) ApiResponses(io.swagger.annotations.ApiResponses) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) IndexSetValidator(org.graylog2.indexer.IndexSetValidator) SystemJobConcurrencyException(org.graylog2.system.jobs.SystemJobConcurrencyException) Objects.requireNonNull(java.util.Objects.requireNonNull) AuditEvent(org.graylog2.audit.jersey.AuditEvent) IndexSetUpdateRequest(org.graylog2.rest.resources.system.indexer.requests.IndexSetUpdateRequest) IndexStatistics(org.graylog2.indexer.indices.stats.IndexStatistics) IndexSetResponse(org.graylog2.rest.resources.system.indexer.responses.IndexSetResponse) Api(io.swagger.annotations.Api) IndexSetRegistry(org.graylog2.indexer.IndexSetRegistry) Logger(org.slf4j.Logger) POST(javax.ws.rs.POST) RestResource(org.graylog2.shared.rest.resources.RestResource) IndexSetSummary(org.graylog2.rest.resources.system.indexer.responses.IndexSetSummary) ApiResponse(io.swagger.annotations.ApiResponse) RestPermissions(org.graylog2.shared.security.RestPermissions) PUT(javax.ws.rs.PUT) Collections(java.util.Collections) IndexSetConfig(org.graylog2.indexer.indexset.IndexSetConfig) DefaultIndexSetConfig(org.graylog2.indexer.indexset.DefaultIndexSetConfig) NotFoundException(javax.ws.rs.NotFoundException) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Example 43 with PathParam

use of javax.ws.rs.PathParam in project graylog2-server by Graylog2.

the class Generator method determineParameters.

private List<Parameter> determineParameters(Method method) {
    final List<Parameter> params = Lists.newArrayList();
    int i = 0;
    for (Annotation[] annotations : method.getParameterAnnotations()) {
        final Parameter param = new Parameter();
        Parameter.Kind paramKind = Parameter.Kind.BODY;
        for (Annotation annotation : annotations) {
            if (annotation instanceof ApiParam) {
                final ApiParam apiParam = (ApiParam) annotation;
                final String name = Strings.isNullOrEmpty(apiParam.name()) ? Strings.isNullOrEmpty(apiParam.value()) ? "arg" + i : apiParam.value() : apiParam.name();
                param.setName(name);
                param.setDescription(apiParam.value());
                param.setIsRequired(apiParam.required());
                final TypeSchema parameterSchema = typeSchema(method.getGenericParameterTypes()[i]);
                param.setTypeSchema(parameterSchema);
                if (!isNullOrEmpty(apiParam.defaultValue())) {
                    param.setDefaultValue(apiParam.defaultValue());
                }
            }
            if (annotation instanceof DefaultValue) {
                final DefaultValue defaultValueAnnotation = (DefaultValue) annotation;
                // Only set if empty to make sure ApiParam's defaultValue has precedence!
                if (isNullOrEmpty(param.getDefaultValue()) && !isNullOrEmpty(defaultValueAnnotation.value())) {
                    param.setDefaultValue(defaultValueAnnotation.value());
                }
            }
            if (annotation instanceof QueryParam) {
                paramKind = Parameter.Kind.QUERY;
            } else if (annotation instanceof PathParam) {
                paramKind = Parameter.Kind.PATH;
            } else if (annotation instanceof HeaderParam) {
                paramKind = Parameter.Kind.HEADER;
            } else if (annotation instanceof FormParam) {
                paramKind = Parameter.Kind.FORM;
            }
        }
        param.setKind(paramKind);
        if (param.getTypeSchema() != null) {
            params.add(param);
        }
        i++;
    }
    return params;
}
Also used : HeaderParam(javax.ws.rs.HeaderParam) Annotation(java.lang.annotation.Annotation) DefaultValue(javax.ws.rs.DefaultValue) QueryParam(javax.ws.rs.QueryParam) ApiParam(io.swagger.annotations.ApiParam) PathParam(javax.ws.rs.PathParam) FormParam(javax.ws.rs.FormParam)

Example 44 with PathParam

use of javax.ws.rs.PathParam in project swagger-core by swagger-api.

the class DefaultParameterExtension method extractParameters.

@Override
public ResolvedParameter extractParameters(List<Annotation> annotations, Type type, Set<Type> typesToSkip, Components components, javax.ws.rs.Consumes classConsumes, javax.ws.rs.Consumes methodConsumes, boolean includeRequestBody, JsonView jsonViewAnnotation, Iterator<OpenAPIExtension> chain) {
    if (shouldIgnoreType(type, typesToSkip)) {
        return new ResolvedParameter();
    }
    Parameter parameter = null;
    for (Annotation annotation : annotations) {
        if (annotation instanceof QueryParam) {
            QueryParam param = (QueryParam) annotation;
            Parameter qp = new Parameter();
            qp.setIn(QUERY_PARAM);
            qp.setName(param.value());
            parameter = qp;
        } else if (annotation instanceof PathParam) {
            PathParam param = (PathParam) annotation;
            Parameter pp = new Parameter();
            pp.setIn(PATH_PARAM);
            pp.setName(param.value());
            parameter = pp;
        } else if (annotation instanceof MatrixParam) {
            MatrixParam param = (MatrixParam) annotation;
            Parameter pp = new Parameter();
            pp.setIn(PATH_PARAM);
            pp.setStyle(Parameter.StyleEnum.MATRIX);
            pp.setName(param.value());
            parameter = pp;
        } else if (annotation instanceof HeaderParam) {
            HeaderParam param = (HeaderParam) annotation;
            Parameter pp = new Parameter();
            pp.setIn(HEADER_PARAM);
            pp.setName(param.value());
            parameter = pp;
        } else if (annotation instanceof CookieParam) {
            CookieParam param = (CookieParam) annotation;
            Parameter pp = new Parameter();
            pp.setIn(COOKIE_PARAM);
            pp.setName(param.value());
            parameter = pp;
        } else if (annotation instanceof io.swagger.v3.oas.annotations.Parameter) {
            if (((io.swagger.v3.oas.annotations.Parameter) annotation).hidden()) {
                return new ResolvedParameter();
            }
            if (parameter == null) {
                parameter = new Parameter();
            }
            if (StringUtils.isNotBlank(((io.swagger.v3.oas.annotations.Parameter) annotation).ref())) {
                parameter.$ref(((io.swagger.v3.oas.annotations.Parameter) annotation).ref());
            }
        } else {
            List<Parameter> formParameters = new ArrayList<>();
            List<Parameter> parameters = new ArrayList<>();
            if (handleAdditionalAnnotation(parameters, formParameters, annotation, type, typesToSkip, classConsumes, methodConsumes, components, includeRequestBody, jsonViewAnnotation)) {
                ResolvedParameter extractParametersResult = new ResolvedParameter();
                extractParametersResult.parameters.addAll(parameters);
                extractParametersResult.formParameters.addAll(formParameters);
                return extractParametersResult;
            }
        }
    }
    List<Parameter> parameters = new ArrayList<>();
    ResolvedParameter extractParametersResult = new ResolvedParameter();
    if (parameter != null && (StringUtils.isNotBlank(parameter.getIn()) || StringUtils.isNotBlank(parameter.get$ref()))) {
        parameters.add(parameter);
    } else if (includeRequestBody) {
        Parameter unknownParameter = ParameterProcessor.applyAnnotations(null, type, annotations, components, classConsumes == null ? new String[0] : classConsumes.value(), methodConsumes == null ? new String[0] : methodConsumes.value(), jsonViewAnnotation);
        if (unknownParameter != null) {
            if (StringUtils.isNotBlank(unknownParameter.getIn()) && !"form".equals(unknownParameter.getIn())) {
                extractParametersResult.parameters.add(unknownParameter);
            } else if ("form".equals(unknownParameter.getIn())) {
                unknownParameter.setIn(null);
                extractParametersResult.formParameters.add(unknownParameter);
            } else {
                // return as request body
                extractParametersResult.requestBody = unknownParameter;
            }
        }
    }
    for (Parameter p : parameters) {
        Parameter processedParameter = ParameterProcessor.applyAnnotations(p, type, annotations, components, classConsumes == null ? new String[0] : classConsumes.value(), methodConsumes == null ? new String[0] : methodConsumes.value(), jsonViewAnnotation);
        if (processedParameter != null) {
            extractParametersResult.parameters.add(processedParameter);
        }
    }
    return extractParametersResult;
}
Also used : MatrixParam(javax.ws.rs.MatrixParam) HeaderParam(javax.ws.rs.HeaderParam) ArrayList(java.util.ArrayList) Annotation(java.lang.annotation.Annotation) CookieParam(javax.ws.rs.CookieParam) QueryParam(javax.ws.rs.QueryParam) Parameter(io.swagger.v3.oas.models.parameters.Parameter) ArrayList(java.util.ArrayList) List(java.util.List) PathParam(javax.ws.rs.PathParam)

Example 45 with PathParam

use of javax.ws.rs.PathParam in project mycore by MyCoRe-Org.

the class MCRClassificationEditorResource method filter.

@GET
@Path("filter/{text}")
@Produces(MediaType.APPLICATION_JSON)
public Response filter(@PathParam("text") String text) {
    SolrClient solrClient = MCRSolrClassificationUtil.getCore().getClient();
    ModifiableSolrParams p = new ModifiableSolrParams();
    p.set("q", "*" + text + "*");
    p.set("fl", "id,ancestors");
    JsonArray docList = new JsonArray();
    MCRSolrSearchUtils.stream(solrClient, p).flatMap(document -> {
        List<String> ids = new ArrayList<>();
        ids.add(document.getFirstValue("id").toString());
        Collection<Object> fieldValues = document.getFieldValues("ancestors");
        if (fieldValues != null) {
            for (Object anc : fieldValues) {
                ids.add(anc.toString());
            }
        }
        return ids.stream();
    }).distinct().map(JsonPrimitive::new).forEach(docList::add);
    return Response.ok().entity(docList.toString()).build();
}
Also used : JsonArray(com.google.gson.JsonArray) JsonObject(com.google.gson.JsonObject) MCRRestrictedAccess(org.mycore.frontend.jersey.filter.access.MCRRestrictedAccess) Produces(javax.ws.rs.Produces) SolrDocumentList(org.apache.solr.common.SolrDocumentList) Path(javax.ws.rs.Path) SolrServerException(org.apache.solr.client.solrj.SolrServerException) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) MCRCategLinkServiceFactory(org.mycore.datamodel.classifications2.MCRCategLinkServiceFactory) Consumes(javax.ws.rs.Consumes) Gson(com.google.gson.Gson) Map(java.util.Map) MCRCategoryDAO(org.mycore.datamodel.classifications2.MCRCategoryDAO) DELETE(javax.ws.rs.DELETE) Context(javax.ws.rs.core.Context) MCRCategoryListWrapper(org.mycore.frontend.classeditor.wrapper.MCRCategoryListWrapper) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Collection(java.util.Collection) MCRCategoryID(org.mycore.datamodel.classifications2.MCRCategoryID) MCRCategory(org.mycore.datamodel.classifications2.MCRCategory) MCRClassificationWritePermission(org.mycore.frontend.classeditor.access.MCRClassificationWritePermission) UUID(java.util.UUID) List(java.util.List) FormDataParam(org.glassfish.jersey.media.multipart.FormDataParam) JsonArray(com.google.gson.JsonArray) MCRCategLinkService(org.mycore.datamodel.classifications2.MCRCategLinkService) Response(javax.ws.rs.core.Response) MCRNewClassificationPermission(org.mycore.frontend.classeditor.access.MCRNewClassificationPermission) MCRCategoryDAOFactory(org.mycore.datamodel.classifications2.MCRCategoryDAOFactory) WebApplicationException(javax.ws.rs.WebApplicationException) UriInfo(javax.ws.rs.core.UriInfo) MCRJSONManager(org.mycore.common.MCRJSONManager) PathParam(javax.ws.rs.PathParam) PERMISSION_WRITE(org.mycore.access.MCRAccessManager.PERMISSION_WRITE) GET(javax.ws.rs.GET) MCRConfiguration(org.mycore.common.config.MCRConfiguration) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) MCRAccessManager(org.mycore.access.MCRAccessManager) JsonElement(com.google.gson.JsonElement) MCRSolrClassificationUtil(org.mycore.solr.classification.MCRSolrClassificationUtil) JsonPrimitive(com.google.gson.JsonPrimitive) LinkedList(java.util.LinkedList) MCRAccessException(org.mycore.access.MCRAccessException) PERMISSION_DELETE(org.mycore.access.MCRAccessManager.PERMISSION_DELETE) Status(javax.ws.rs.core.Response.Status) MCRClassificationUtils(org.mycore.datamodel.classifications2.utils.MCRClassificationUtils) MCRJSONCategoryPropName(org.mycore.frontend.classeditor.json.MCRJSONCategoryPropName) POST(javax.ws.rs.POST) QueryResponse(org.apache.solr.client.solrj.response.QueryResponse) IOException(java.io.IOException) SolrClient(org.apache.solr.client.solrj.SolrClient) MCRJSONCategory(org.mycore.frontend.classeditor.json.MCRJSONCategory) SolrDocument(org.apache.solr.common.SolrDocument) MCRSolrSearchUtils(org.mycore.solr.search.MCRSolrSearchUtils) MCRSolrClientFactory(org.mycore.solr.MCRSolrClientFactory) Comparator(java.util.Comparator) JsonStreamParser(com.google.gson.JsonStreamParser) InputStream(java.io.InputStream) SolrClient(org.apache.solr.client.solrj.SolrClient) Collection(java.util.Collection) SolrDocumentList(org.apache.solr.common.SolrDocumentList) List(java.util.List) ArrayList(java.util.ArrayList) LinkedList(java.util.LinkedList) JsonObject(com.google.gson.JsonObject) ModifiableSolrParams(org.apache.solr.common.params.ModifiableSolrParams) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

PathParam (javax.ws.rs.PathParam)127 Path (javax.ws.rs.Path)105 GET (javax.ws.rs.GET)96 Produces (javax.ws.rs.Produces)96 Response (javax.ws.rs.core.Response)93 QueryParam (javax.ws.rs.QueryParam)82 List (java.util.List)72 MediaType (javax.ws.rs.core.MediaType)72 POST (javax.ws.rs.POST)71 DELETE (javax.ws.rs.DELETE)70 Consumes (javax.ws.rs.Consumes)66 Inject (javax.inject.Inject)62 Api (io.swagger.annotations.Api)60 ApiOperation (io.swagger.annotations.ApiOperation)59 Map (java.util.Map)59 ApiResponse (io.swagger.annotations.ApiResponse)58 ApiResponses (io.swagger.annotations.ApiResponses)57 Collectors (java.util.stream.Collectors)57 Logger (org.slf4j.Logger)52 LoggerFactory (org.slf4j.LoggerFactory)52