use of org.springframework.beans.factory.annotation.Value in project ArachneCentralAPI by OHDSI.
the class BaseAnalysisController method list.
@ApiOperation("List analyses.")
@RequestMapping(value = "/api/v1/analysis-management/analyses", method = GET)
public JsonResult<List<D>> list(Principal principal, @RequestParam("study-id") Long studyId) throws PermissionDeniedException, NotExistException {
JsonResult<List<D>> result;
IUser user = userService.getByUsername(principal.getName());
if (user == null) {
result = new JsonResult<>(PERMISSION_DENIED);
return result;
}
Iterable<T> analyses = analysisService.list(user, studyId);
result = new JsonResult<>(NO_ERROR);
List<D> analysisDTOs = StreamSupport.stream(analyses.spliterator(), false).map(analysis -> conversionService.convert(analysis, getAnalysisDTOClass())).collect(Collectors.toList());
result.setResult(analysisDTOs);
return result;
}
use of org.springframework.beans.factory.annotation.Value in project tephra by heisedebaise.
the class StatusImpl method setVersion.
private void setVersion(Map<String, Set<String>> map) {
Set<String> set = new HashSet<>();
map.forEach((key, value) -> {
if (value.size() > 1)
set.add(key);
});
set.forEach(map::remove);
Map<String, String> versions = new HashMap<>();
map.forEach((key, value) -> versions.put(key, value.iterator().next()));
set.clear();
versions.forEach((key, value) -> versions.forEach((k, v) -> {
if (key.contains(k) && !key.equals(k) && value.equals(v))
set.add(key);
}));
set.forEach(versions::remove);
version = new JSONObject();
versions.forEach((key, value) -> version.put(key.substring(1), value));
}
use of org.springframework.beans.factory.annotation.Value in project irida by phac-nml.
the class ProjectsController method exportProjectsToFile.
/**
* Export Projects table as either an excel file or CSV
*
* @param type
* of file to export (csv or excel)
* @param isAdmin
* if the currently logged in user is an administrator
* @param response
* {@link HttpServletResponse}
* @param principal
* {@link Principal}
* @param locale
* {@link Locale}
*
* @throws IOException
* thrown if cannot open the {@link HttpServletResponse} {@link OutputStream}
*/
@RequestMapping("/projects/ajax/export")
public void exportProjectsToFile(@RequestParam(value = "dtf") String type, @RequestParam(required = false, defaultValue = "false", value = "admin") Boolean isAdmin, HttpServletResponse response, Principal principal, Locale locale) throws IOException {
// Let's make sure the export type is set properly
if (!(type.equalsIgnoreCase("xlsx") || type.equalsIgnoreCase("csv"))) {
throw new IllegalArgumentException("No file type sent for downloading all projects. Expecting parameter 'dtf=' xlsx or csv");
}
List<Project> projects;
// If viewing the admin projects page give the user all the projects.
if (isAdmin) {
projects = (List<Project>) projectService.findAll();
} else // If on the users projects page, give the user their projects.
{
User user = userService.getUserByUsername(principal.getName());
projects = projectService.getProjectsForUser(user).stream().map(Join::getSubject).collect(Collectors.toList());
}
List<DTProject> dtProjects = projects.stream().map(this::createDataTablesProject).collect(Collectors.toList());
List<String> headers = ImmutableList.of("id", "name", "organism", "samples", "created", "modified").stream().map(h -> messageSource.getMessage("projects.table." + h, new Object[] {}, locale)).collect(Collectors.toList());
// Create the filename
Date date = new Date();
DateFormat fileDateFormat = new SimpleDateFormat(messageSource.getMessage("date.iso-8601", null, locale));
String filename = "IRIDA_projects_" + fileDateFormat.format(date);
response.setHeader("Content-Disposition", "attachment; filename=\"" + filename + "." + type + "\"");
if (type.equals("xlsx")) {
writeProjectsToExcelFile(headers, dtProjects, locale, response);
} else {
writeProjectsToCsvFile(headers, dtProjects, locale, response);
}
}
use of org.springframework.beans.factory.annotation.Value in project irida by phac-nml.
the class ProjectExportController method getUploadNcbiPage.
/**
* Get the page for exporting a given {@link Project} and selected
* {@link Sample}s
*
* @param projectId
* The ID of the project to export
* @param sampleIds
* A List of sample ids to export
* @param model
* model for the view to render
* @return Name of the NCBI export page
*/
@RequestMapping(value = "/projects/{projectId}/export/ncbi", method = RequestMethod.GET)
public String getUploadNcbiPage(@PathVariable Long projectId, @RequestParam("ids[]") List<Long> sampleIds, Model model) {
Project project = projectService.read(projectId);
logger.trace("Reading " + sampleIds.size() + " samples");
Iterable<Sample> samples = sampleService.readMultiple(sampleIds);
logger.trace("Got samples");
Set<Long> checkedSingles = new HashSet<>();
Set<Long> checkedPairs = new HashSet<>();
List<Map<String, Object>> sampleList = new ArrayList<>();
for (Sample sample : samples) {
Map<String, Object> sampleMap = new HashMap<>();
sampleMap.put("name", sample.getLabel());
sampleMap.put("id", sample.getId().toString());
logger.trace("Doing sample " + sample.getId());
Map<String, List<? extends Object>> files = new HashMap<>();
Collection<SampleSequencingObjectJoin> singleEndFiles = sequencingObjectService.getSequencesForSampleOfType(sample, SingleEndSequenceFile.class);
Collection<SampleSequencingObjectJoin> pairedEndFiles = sequencingObjectService.getSequencesForSampleOfType(sample, SequenceFilePair.class);
List<SingleEndSequenceFile> singleEndFilesForSample = singleEndFiles.stream().map(j -> (SingleEndSequenceFile) j.getObject()).collect(Collectors.toList());
List<SequenceFilePair> sequenceFilePairsForSample = pairedEndFiles.stream().map(j -> (SequenceFilePair) j.getObject()).collect(Collectors.toList());
Optional<SequenceFilePair> newestPair = sequenceFilePairsForSample.stream().sorted((f1, f2) -> f2.getCreatedDate().compareTo(f1.getCreatedDate())).findFirst();
Optional<SingleEndSequenceFile> newestSingle = singleEndFilesForSample.stream().sorted((f1, f2) -> f2.getCreatedDate().compareTo(f1.getCreatedDate())).findFirst();
if (newestPair.isPresent() && newestSingle.isPresent()) {
SequenceFilePair sequenceFilePair = newestPair.get();
SingleEndSequenceFile join = newestSingle.get();
if (sequenceFilePair.getCreatedDate().after(join.getCreatedDate())) {
checkedPairs.add(newestPair.get().getId());
} else {
checkedSingles.add(newestSingle.get().getId());
}
} else {
if (newestPair.isPresent()) {
checkedPairs.add(newestPair.get().getId());
} else if (newestSingle.isPresent()) {
checkedSingles.add(newestSingle.get().getId());
}
}
files.put("paired_end", sequenceFilePairsForSample);
files.put("single_end", singleEndFilesForSample);
sampleMap.put("files", files);
sampleList.add(sampleMap);
}
sampleList.sort(new Comparator<Map<String, Object>>() {
@Override
public int compare(Map<String, Object> o1, Map<String, Object> o2) {
String s1Name = (String) o1.get("name");
String s2Name = (String) o2.get("name");
return s1Name.compareTo(s2Name);
}
});
model.addAttribute("project", project);
model.addAttribute("samples", sampleList);
model.addAttribute("newestSingles", checkedSingles);
model.addAttribute("newestPairs", checkedPairs);
model.addAttribute("instrument_model", NcbiInstrumentModel.values());
model.addAttribute("library_selection", NcbiLibrarySelection.values());
model.addAttribute("library_source", NcbiLibrarySource.values());
model.addAttribute("library_strategy", NcbiLibraryStrategy.values());
model.addAttribute("defaultNamespace", namespace);
model.addAttribute("activeNav", "export");
return NCBI_EXPORT_VIEW;
}
use of org.springframework.beans.factory.annotation.Value in project spring-security by spring-projects.
the class OAuth2ResourceServerSpecTests method getWhenUsingCustomAuthenticationManagerResolverThenUsesItAccordingly.
@Test
public void getWhenUsingCustomAuthenticationManagerResolverThenUsesItAccordingly() {
this.spring.register(CustomAuthenticationManagerResolverConfig.class).autowire();
ReactiveAuthenticationManagerResolver<ServerWebExchange> authenticationManagerResolver = this.spring.getContext().getBean(ReactiveAuthenticationManagerResolver.class);
ReactiveAuthenticationManager authenticationManager = this.spring.getContext().getBean(ReactiveAuthenticationManager.class);
given(authenticationManagerResolver.resolve(any(ServerWebExchange.class))).willReturn(Mono.just(authenticationManager));
given(authenticationManager.authenticate(any(Authentication.class))).willReturn(Mono.error(new OAuth2AuthenticationException(new OAuth2Error("mock-failure"))));
// @formatter:off
this.client.get().headers((headers) -> headers.setBearerAuth(this.messageReadToken)).exchange().expectStatus().isUnauthorized().expectHeader().value(HttpHeaders.WWW_AUTHENTICATE, startsWith("Bearer error=\"mock-failure\""));
// @formatter:on
}
Aggregations