Search in sources :

Example 71 with DefaultValue

use of javax.ws.rs.DefaultValue in project mica2 by obiba.

the class DraftCollectedDatasetsResource method list.

/**
 * Get all {@link org.obiba.mica.dataset.domain.StudyDataset}, optionally filtered by study.
 *
 * @param studyId can be null, in which case all datasets are returned
 * @return
 */
@GET
@Path("/collected-datasets")
@Timed
public List<Mica.DatasetDto> list(@QueryParam("study") String studyId, @QueryParam("query") String query, @QueryParam("from") @DefaultValue("0") Integer from, @QueryParam("limit") Integer limit, @QueryParam("sort") @DefaultValue("id") String sort, @QueryParam("order") @DefaultValue("asc") String order, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
    long totalCount;
    EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
    List<String> filteredIds = datasetService.getIdsByStateFilter(entityStateFilter);
    Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(Lists.newArrayList("/draft/collected-dataset")).ids(filteredIds).build();
    if (limit == null)
        limit = MAX_LIMIT;
    if (limit < 0)
        throw new IllegalArgumentException("limit cannot be negative");
    DocumentService.Documents<StudyDataset> datasets = draftCollectedDatasetService.find(from, limit, sort, order, studyId, query, null, null, accessibleIdFilter);
    totalCount = datasets.getTotal();
    response.addHeader("X-Total-Count", Long.toString(totalCount));
    return datasets.getList().stream().map(dataset -> dtos.asDto(dataset, true)).collect(toList());
}
Also used : EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) Async(org.springframework.scheduling.annotation.Async) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) DraftCollectedDatasetService(org.obiba.mica.dataset.service.DraftCollectedDatasetService) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) QueryParam(javax.ws.rs.QueryParam) Lists(com.google.common.collect.Lists) Mica(org.obiba.mica.web.model.Mica) DefaultValue(javax.ws.rs.DefaultValue) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) AccessibleIdFilterBuilder(org.obiba.mica.search.AccessibleIdFilterBuilder) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Searcher(org.obiba.mica.spi.search.Searcher) HttpServletResponse(javax.servlet.http.HttpServletResponse) CollectedDatasetService(org.obiba.mica.dataset.service.CollectedDatasetService) Dataset(org.obiba.mica.dataset.domain.Dataset) ApplicationContext(org.springframework.context.ApplicationContext) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) DocumentService(org.obiba.mica.core.service.DocumentService) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) Searcher(org.obiba.mica.spi.search.Searcher) StudyDataset(org.obiba.mica.dataset.domain.StudyDataset) DocumentService(org.obiba.mica.core.service.DocumentService) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 72 with DefaultValue

use of javax.ws.rs.DefaultValue in project mica2 by obiba.

the class DraftHarmonizedDatasetsResource method list.

/**
 * Get all {@link HarmonizationDataset}, optionally filtered by study.
 *
 * @param studyId can be null, in which case all datasets are returned
 * @return
 */
@GET
@Path("/harmonized-datasets")
@Timed
public List<Mica.DatasetDto> list(@QueryParam("study") String studyId, @QueryParam("query") String query, @QueryParam("from") @DefaultValue("0") Integer from, @QueryParam("limit") Integer limit, @QueryParam("sort") @DefaultValue("id") String sort, @QueryParam("order") @DefaultValue("asc") String order, @QueryParam("filter") @DefaultValue("ALL") String filter, @Context HttpServletResponse response) {
    long totalCount;
    EntityStateFilter entityStateFilter = EntityStateFilter.valueOf(filter);
    List<String> filteredIds = datasetService.getIdsByStateFilter(entityStateFilter);
    Searcher.IdFilter accessibleIdFilter = AccessibleIdFilterBuilder.newBuilder().aclService(subjectAclService).resources(Lists.newArrayList("/draft/harmonized-dataset")).ids(filteredIds).build();
    if (limit == null)
        limit = MAX_LIMIT;
    if (limit < 0)
        throw new IllegalArgumentException("limit cannot be negative");
    DocumentService.Documents<HarmonizationDataset> datasets = draftDatasetService.find(from, limit, sort, order, studyId, query, null, null, accessibleIdFilter);
    totalCount = datasets.getTotal();
    response.addHeader("X-Total-Count", Long.toString(totalCount));
    return datasets.getList().stream().map(dataset -> dtos.asDto(dataset, true)).collect(toList());
}
Also used : EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) Async(org.springframework.scheduling.annotation.Async) PathParam(javax.ws.rs.PathParam) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) RequiresPermissions(org.apache.shiro.authz.annotation.RequiresPermissions) QueryParam(javax.ws.rs.QueryParam) Lists(com.google.common.collect.Lists) Mica(org.obiba.mica.web.model.Mica) DefaultValue(javax.ws.rs.DefaultValue) Dtos(org.obiba.mica.web.model.Dtos) Nullable(javax.annotation.Nullable) AccessibleIdFilterBuilder(org.obiba.mica.search.AccessibleIdFilterBuilder) DraftHarmonizationDatasetService(org.obiba.mica.dataset.service.DraftHarmonizationDatasetService) POST(javax.ws.rs.POST) Context(javax.ws.rs.core.Context) SubjectAclService(org.obiba.mica.security.service.SubjectAclService) Searcher(org.obiba.mica.spi.search.Searcher) HttpServletResponse(javax.servlet.http.HttpServletResponse) Dataset(org.obiba.mica.dataset.domain.Dataset) ApplicationContext(org.springframework.context.ApplicationContext) HarmonizedDatasetService(org.obiba.mica.dataset.service.HarmonizedDatasetService) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) DocumentService(org.obiba.mica.core.service.DocumentService) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) PUT(javax.ws.rs.PUT) UriInfo(javax.ws.rs.core.UriInfo) EntityStateFilter(org.obiba.mica.core.domain.EntityStateFilter) Searcher(org.obiba.mica.spi.search.Searcher) DocumentService(org.obiba.mica.core.service.DocumentService) HarmonizationDataset(org.obiba.mica.dataset.domain.HarmonizationDataset) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 73 with DefaultValue

use of javax.ws.rs.DefaultValue in project mica2 by obiba.

the class TaxonomiesSearchResource method filter.

@GET
@Path("/_filter")
@Timed
public List<Opal.TaxonomyDto> filter(@QueryParam("target") @DefaultValue("variable") String target, @QueryParam("query") String query, @QueryParam("locale") String locale) {
    TaxonomyTarget taxonomyTarget = getTaxonomyTarget(target);
    List<String> filteredVocabularies = filterVocabularies(taxonomyTarget, query, locale);
    Map<String, Map<String, List<String>>> taxoNamesMap = TaxonomyResolver.asMap(filteredVocabularies, filterTerms(taxonomyTarget, query, locale, filteredVocabularies));
    List<Opal.TaxonomyDto> results = Lists.newArrayList();
    getTaxonomies(taxonomyTarget).stream().filter(t -> taxoNamesMap.containsKey(t.getName())).forEach(taxo -> {
        Opal.TaxonomyDto.Builder tBuilder = Dtos.asDto(taxo, false).toBuilder();
        populate(tBuilder, taxo, taxoNamesMap);
        results.add(tBuilder.build());
    });
    return results;
}
Also used : Logger(org.slf4j.Logger) GET(javax.ws.rs.GET) Path(javax.ws.rs.Path) Dtos(org.obiba.opal.web.taxonomy.Dtos) LoggerFactory(org.slf4j.LoggerFactory) Opal(org.obiba.opal.web.model.Opal) Collectors(java.util.stream.Collectors) Scope(org.springframework.context.annotation.Scope) Inject(javax.inject.Inject) Timed(com.codahale.metrics.annotation.Timed) List(java.util.List) Component(org.springframework.stereotype.Component) QueryParam(javax.ws.rs.QueryParam) Lists(com.google.common.collect.Lists) Map(java.util.Map) TaxonomyResolver(org.obiba.mica.taxonomy.TaxonomyResolver) DefaultValue(javax.ws.rs.DefaultValue) TaxonomyService(org.obiba.mica.micaConfig.service.TaxonomyService) TaxonomyTarget(org.obiba.mica.spi.search.TaxonomyTarget) Nullable(javax.annotation.Nullable) TaxonomyTarget(org.obiba.mica.spi.search.TaxonomyTarget) Map(java.util.Map) Path(javax.ws.rs.Path) Timed(com.codahale.metrics.annotation.Timed) GET(javax.ws.rs.GET)

Example 74 with DefaultValue

use of javax.ws.rs.DefaultValue in project wildfly by wildfly.

the class JaxrsMethodParameterProcessor method getResouceClasses.

/**
 * Create list of objects that represents resource method parameters with a
 * DefaultValue annontation assigned to it.
 *
 * When running unitTest the classes must be indexed.  In normal deployment
 * the indexing is already done.
 *
 * @param index
 * @param classLoader
 * @return
 */
private ArrayList<ParamDetail> getResouceClasses(final CompositeIndex index, final ClassLoader classLoader, Set<String> knownResourceClasses, boolean isFromUnitTest) {
    ArrayList<ParamDetail> detailList = new ArrayList<>();
    ArrayList<String> classNameArr = new ArrayList<>();
    if (isFromUnitTest) {
        Indexer indexer = new Indexer();
        for (String className : knownResourceClasses) {
            try {
                String pathName = className.replace(".", File.separator);
                InputStream stream = classLoader.getResourceAsStream(pathName + ".class");
                ClassInfo classInfo = indexer.index(stream);
                List<AnnotationInstance> defaultValuesList = classInfo.annotations().get(DEFAULT_VALUE_DOTNAME);
                if (!defaultValuesList.isEmpty()) {
                    classNameArr.add((classInfo).name().toString());
                }
                stream.close();
            } catch (IOException e) {
                JAXRS_LOGGER.classIntrospectionFailure(e.getClass().getName(), e.getMessage());
            }
        }
    } else {
        for (String clazzName : knownResourceClasses) {
            ClassInfo classInfo = index.getClassByName(DotName.createSimple(clazzName));
            if (classInfo != null) {
                Map<DotName, List<AnnotationInstance>> annotationsMap = classInfo.annotations();
                if (annotationsMap != null && !annotationsMap.isEmpty()) {
                    List<AnnotationInstance> xInstance = annotationsMap.get(JaxrsAnnotations.PATH.getDotName());
                    List<AnnotationInstance> xdefaultValuesList = annotationsMap.get(DEFAULT_VALUE_DOTNAME);
                    if ((xInstance != null && !xInstance.isEmpty()) && (xdefaultValuesList != null && !xdefaultValuesList.isEmpty())) {
                        classNameArr.add((classInfo).name().toString());
                    }
                }
            }
        }
    }
    // find methods and method params with @DefaultValue
    for (String className : classNameArr) {
        Class<?> clazz = null;
        try {
            clazz = classLoader.loadClass(className);
            for (Method method : clazz.getMethods()) {
                if (clazz == method.getDeclaringClass()) {
                    Type[] genParamTypeArr = method.getGenericParameterTypes();
                    Annotation[][] annotationMatrix = method.getParameterAnnotations();
                    for (int j = 0; j < genParamTypeArr.length; j++) {
                        DefaultValue defaultValue = lookupDefaultValueAnn(annotationMatrix[j]);
                        if (defaultValue != null) {
                            Class paramClazz = checkParamType(genParamTypeArr[j], method, j, classLoader);
                            if (paramClazz != null) {
                                detailList.add(new ParamDetail(method, defaultValue, paramClazz, annotationMatrix[j]));
                            }
                        }
                    }
                }
            }
        } catch (ClassNotFoundException e) {
            JAXRS_LOGGER.classIntrospectionFailure(e.getClass().getName(), e.getMessage());
        }
    }
    return detailList;
}
Also used : InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Method(java.lang.reflect.Method) DotName(org.jboss.jandex.DotName) DefaultValue(javax.ws.rs.DefaultValue) ParameterizedType(java.lang.reflect.ParameterizedType) DeploymentType(org.jboss.as.ee.structure.DeploymentType) Type(java.lang.reflect.Type) Indexer(org.jboss.jandex.Indexer) ArrayList(java.util.ArrayList) List(java.util.List) AnnotationInstance(org.jboss.jandex.AnnotationInstance) ClassInfo(org.jboss.jandex.ClassInfo)

Example 75 with DefaultValue

use of javax.ws.rs.DefaultValue in project kylo by Teradata.

the class DatasourceController method generatePreviewQuery.

/**
 * Executes a query on the specified datasource.
 *
 * @param idStr the datasource id
 * @param query the SQL query
 * @return the SQL result
 */
@GET
@Path("{id}/preview/{schema}/{table}")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation("Generates a preview query appropriate for the type of datasource and returns the result.")
@ApiResponses({ @ApiResponse(code = 200, message = "Returns the result.", response = QueryResult.class), @ApiResponse(code = 403, message = "Access denied.", response = RestResponseStatus.class), @ApiResponse(code = 400, message = "A JDBC data source with that id does not exist.", response = RestResponseStatus.class), @ApiResponse(code = 500, message = "NiFi or the database are unavailable.", response = RestResponseStatus.class) })
public Response generatePreviewQuery(@PathParam("id") final String idStr, @PathParam("schema") final String schema, @PathParam("table") final String tableName, @QueryParam("limit") @DefaultValue("10") final int limit) {
    // Verify user has access to data source
    final Optional<com.thinkbiganalytics.metadata.api.datasource.Datasource.ID> id = metadata.read(() -> {
        accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.ACCESS_DATASOURCES);
        final com.thinkbiganalytics.metadata.api.datasource.Datasource datasource = datasourceProvider.getDatasource(datasourceProvider.resolve(idStr));
        return Optional.ofNullable(datasource).map(com.thinkbiganalytics.metadata.api.datasource.Datasource::getId);
    });
    // Execute query
    return metadata.read(() -> {
        final String result = id.map(datasourceProvider::getDatasource).map(ds -> datasourceTransform.toDatasource(ds, DatasourceModelTransform.Level.ADMIN)).filter(JdbcDatasource.class::isInstance).map(JdbcDatasource.class::cast).map(datasource -> dbcpConnectionPoolTableInfo.generatePreviewQueryForDatasource(datasource, schema, tableName, limit)).orElseThrow(() -> new NotFoundException("No JDBC datasource exists with the given ID: " + idStr));
        return Response.ok(result).build();
    }, MetadataAccess.SERVICE);
}
Also used : JdbcDatasource(com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource) UserDatasource(com.thinkbiganalytics.metadata.rest.model.data.UserDatasource) Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) DatabaseType(com.thinkbiganalytics.jdbc.util.DatabaseType) Arrays(java.util.Arrays) JdbcDatasourceDetails(com.thinkbiganalytics.metadata.api.datasource.JdbcDatasourceDetails) Produces(javax.ws.rs.Produces) DatabaseMetadata(com.thinkbiganalytics.discovery.schema.DatabaseMetadata) LoggerFactory(org.slf4j.LoggerFactory) Path(javax.ws.rs.Path) DatasourceModelTransform(com.thinkbiganalytics.feedmgr.service.datasource.DatasourceModelTransform) Collections2(com.google.common.collect.Collections2) DatasourceDefinition(com.thinkbiganalytics.metadata.rest.model.data.DatasourceDefinition) StringUtils(org.apache.commons.lang3.StringUtils) Model(com.thinkbiganalytics.feedmgr.rest.Model) DatasourceDefinitionProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceDefinitionProvider) ApiOperation(io.swagger.annotations.ApiOperation) MediaType(javax.ws.rs.core.MediaType) QueryParam(javax.ws.rs.QueryParam) DataSetProvider(com.thinkbiganalytics.metadata.api.catalog.DataSetProvider) Consumes(javax.ws.rs.Consumes) Map(java.util.Map) AccessController(com.thinkbiganalytics.security.AccessController) DefaultValue(javax.ws.rs.DefaultValue) NiFiRestClient(com.thinkbiganalytics.nifi.rest.client.NiFiRestClient) Formatters(com.thinkbiganalytics.Formatters) FeedServicesAccessControl(com.thinkbiganalytics.feedmgr.security.FeedServicesAccessControl) MetadataAccess(com.thinkbiganalytics.metadata.api.MetadataAccess) DELETE(javax.ws.rs.DELETE) PermissionsChange(com.thinkbiganalytics.security.rest.model.PermissionsChange) ActionGroup(com.thinkbiganalytics.security.rest.model.ActionGroup) Set(java.util.Set) Collectors(java.util.stream.Collectors) NotFoundException(javax.ws.rs.NotFoundException) List(java.util.List) Principal(java.security.Principal) Stream(java.util.stream.Stream) Response(javax.ws.rs.core.Response) AccessControlException(java.security.AccessControlException) Optional(java.util.Optional) WebApplicationException(javax.ws.rs.WebApplicationException) RoleMembershipChange(com.thinkbiganalytics.security.rest.model.RoleMembershipChange) PathParam(javax.ws.rs.PathParam) SecurityModelTransform(com.thinkbiganalytics.security.rest.controller.SecurityModelTransform) GET(javax.ws.rs.GET) DataSet(com.thinkbiganalytics.metadata.api.catalog.DataSet) HashMap(java.util.HashMap) ApiResponses(io.swagger.annotations.ApiResponses) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) Inject(javax.inject.Inject) RestResponseStatus(com.thinkbiganalytics.rest.model.RestResponseStatus) DefaultDatabaseMetadata(com.thinkbiganalytics.discovery.model.DefaultDatabaseMetadata) JdbcDatasource(com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource) UserDatasource(com.thinkbiganalytics.metadata.rest.model.data.UserDatasource) Api(io.swagger.annotations.Api) Tag(io.swagger.annotations.Tag) Nonnull(javax.annotation.Nonnull) Logger(org.slf4j.Logger) CannotGetJdbcConnectionException(org.springframework.jdbc.CannotGetJdbcConnectionException) POST(javax.ws.rs.POST) SecurityService(com.thinkbiganalytics.feedmgr.service.security.SecurityService) Datasource(com.thinkbiganalytics.metadata.rest.model.data.Datasource) AccessControlled(com.thinkbiganalytics.security.AccessControlled) DBCPConnectionPoolService(com.thinkbiganalytics.feedmgr.nifi.controllerservice.DBCPConnectionPoolService) Component(org.springframework.stereotype.Component) SwaggerDefinition(io.swagger.annotations.SwaggerDefinition) DatasourceAccessControl(com.thinkbiganalytics.metadata.api.datasource.security.DatasourceAccessControl) ApiResponse(io.swagger.annotations.ApiResponse) TableSchema(com.thinkbiganalytics.discovery.schema.TableSchema) DatasourceProvider(com.thinkbiganalytics.metadata.api.datasource.DatasourceProvider) DatasourceCriteria(com.thinkbiganalytics.metadata.rest.model.data.DatasourceCriteria) QueryResult(com.thinkbiganalytics.discovery.schema.QueryResult) JdbcDatasource(com.thinkbiganalytics.metadata.rest.model.data.JdbcDatasource) NotFoundException(javax.ws.rs.NotFoundException) 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)

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