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());
}
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());
}
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;
}
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;
}
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);
}
Aggregations