use of org.springframework.web.bind.annotation.RequestParam in project goci by EBISPOT.
the class AssociationController method editAssociation.
// Edit existing association
// We tried to remap if the snp or genes changed.
// TODO : implement something for SNP:SNP iteration. Actually we remap.
@RequestMapping(value = "/associations/{associationId}", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public // TODO COULD REFACTOR TO JUST USE SUPERCLASS AS METHOD PARAMETER
String editAssociation(@ModelAttribute SnpAssociationStandardMultiForm snpAssociationStandardMultiForm, @ModelAttribute SnpAssociationInteractionForm snpAssociationInteractionForm, @PathVariable Long associationId, @RequestParam(value = "associationtype", required = true) String associationType, Model model, HttpServletRequest request, RedirectAttributes redirectAttributes) throws EnsemblMappingException {
// Establish study and association we are editing
Collection<String> previousAuthorReportedGenes = new HashSet<>();
Collection<String> authorReportedGenes = new HashSet<>();
Collection<String> previousSnps = new HashSet<>();
Collection<String> snps = new HashSet<>();
String isToRemapping = "yes";
Association associationToEdit = associationRepository.findOne(associationId);
Long studyId = associationToEdit.getStudy().getId();
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
AssociationReport oldAssociationReport = associationToEdit.getAssociationReport();
previousAuthorReportedGenes = associationOperationsService.getGenesIds(associationToEdit.getLoci());
previousSnps = associationOperationsService.getSpnsName(associationToEdit.getSnps());
// Determine if association is an OR or BETA type
String measurementType = associationOperationsService.determineIfAssociationIsOrType(associationToEdit);
model.addAttribute("measurementType", measurementType);
// Validate returned form depending on association type
List<AssociationValidationView> criticalErrors = new ArrayList<>();
if (associationType.equalsIgnoreCase("interaction")) {
criticalErrors = associationOperationsService.checkSnpAssociationInteractionFormErrorsForView(snpAssociationInteractionForm, measurementType);
} else {
criticalErrors = associationOperationsService.checkSnpAssociationFormErrors(snpAssociationStandardMultiForm, measurementType);
}
// If errors found then return the edit form with all information entered by curator preserved
if (!criticalErrors.isEmpty()) {
// Get mapping details
model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToEdit));
// Return any association errors
model.addAttribute("errors", criticalErrors);
model.addAttribute("criticalErrorsFound", true);
if (associationType.equalsIgnoreCase("interaction")) {
model.addAttribute("form", snpAssociationInteractionForm);
return "edit_snp_interaction_association";
} else {
model.addAttribute("form", snpAssociationStandardMultiForm);
// Determine view
if (associationToEdit.getMultiSnpHaplotype()) {
return "edit_multi_snp_association";
} else {
return "edit_standard_snp_association";
}
}
} else {
// Create association
Association editedAssociation;
// Request parameter determines how to process form and also which form to process
if (associationType.equalsIgnoreCase("interaction")) {
editedAssociation = snpInteractionAssociationService.createAssociation(snpAssociationInteractionForm);
} else {
editedAssociation = singleSnpMultiSnpAssociationService.createAssociation(snpAssociationStandardMultiForm);
// New snps to compare with the previousSnps.
Collection<SnpFormRow> newSnpsList = snpAssociationStandardMultiForm.getSnpFormRows();
if (newSnpsList != null && !newSnpsList.isEmpty()) {
for (SnpFormRow snp : newSnpsList) {
snps.add(snp.getSnp());
}
}
}
authorReportedGenes = associationOperationsService.getGenesIds(editedAssociation.getLoci());
if (oldAssociationReport != null) {
if ((previousAuthorReportedGenes.size() == authorReportedGenes.size()) && (snps.size() == snps.size())) {
// check the values
if ((authorReportedGenes.equals(previousAuthorReportedGenes)) && (snps.equals(previousSnps))) {
editedAssociation.setLastMappingDate(associationToEdit.getLastMappingDate());
editedAssociation.setLastMappingPerformedBy(associationToEdit.getLastMappingPerformedBy());
editedAssociation.setAssociationReport(oldAssociationReport);
isToRemapping = "no";
}
}
}
if ((oldAssociationReport != null) && (isToRemapping.compareTo("yes") == 0)) {
associationOperationsService.deleteAssocationReport(associationToEdit.getAssociationReport().getId());
}
// Save and validate form
String eRelease = ensemblRestTemplateService.getRelease();
Collection<AssociationValidationView> errors = associationOperationsService.saveEditedAssociationFromForm(study, editedAssociation, associationId, currentUserDetailsService.getUserFromRequest(request), eRelease);
// Determine if we have any errors rather than warnings
long errorCount = errors.stream().filter(validationError -> !validationError.getWarning()).count();
if (errorCount > 0) {
// Get mapping details for association we're editing
model.addAttribute("mappingDetails", associationOperationsService.createMappingDetails(associationToEdit));
model.addAttribute("errors", errors);
model.addAttribute("criticalErrorsFound", true);
if (associationType.equalsIgnoreCase("interaction")) {
model.addAttribute("form", snpAssociationInteractionForm);
return "edit_snp_interaction_association";
} else {
model.addAttribute("form", snpAssociationStandardMultiForm);
// Determine view
if (associationToEdit.getMultiSnpHaplotype()) {
return "edit_multi_snp_association";
} else {
return "edit_standard_snp_association";
}
}
} else {
redirectAttributes.addFlashAttribute("isToRemapping", isToRemapping);
return "redirect:/associations/" + associationId;
}
}
}
use of org.springframework.web.bind.annotation.RequestParam in project dhis2-core by dhis2.
the class EnrollmentController method postEnrollmentJson.
// -------------------------------------------------------------------------
// CREATE
// -------------------------------------------------------------------------
@PostMapping(value = "", consumes = APPLICATION_JSON_VALUE, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public WebMessage postEnrollmentJson(@RequestParam(defaultValue = "CREATE_AND_UPDATE") ImportStrategy strategy, ImportOptions importOptions, HttpServletRequest request) throws IOException {
importOptions.setStrategy(strategy);
InputStream inputStream = StreamUtils.wrapAndCheckCompressionFormat(request.getInputStream());
if (!importOptions.isAsync()) {
ImportSummaries importSummaries = enrollmentService.addEnrollmentsJson(inputStream, importOptions);
importSummaries.setImportOptions(importOptions);
importSummaries.getImportSummaries().stream().filter(importSummary -> !importOptions.isDryRun() && !importSummary.getStatus().equals(ImportStatus.ERROR) && !importOptions.getImportStrategy().isDelete() && (!importOptions.getImportStrategy().isSync() || importSummary.getImportCount().getDeleted() == 0)).forEach(importSummary -> importSummary.setHref(ContextUtils.getRootPath(request) + RESOURCE_PATH + "/" + importSummary.getReference()));
if (importSummaries.getImportSummaries().size() == 1) {
ImportSummary importSummary = importSummaries.getImportSummaries().get(0);
importSummary.setImportOptions(importOptions);
if (!importSummary.getStatus().equals(ImportStatus.ERROR)) {
importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED).setLocation("/api/" + "enrollments" + "/" + importSummary.getReference());
}
}
return importSummaries(importSummaries).setHttpStatus(HttpStatus.CREATED);
}
return startAsyncImport(importOptions, enrollmentService.getEnrollmentsJson(inputStream));
}
use of org.springframework.web.bind.annotation.RequestParam in project cas by apereo.
the class SingleSignOnSessionsEndpoint method destroySsoSessions.
/**
* Destroy sso sessions map.
*
* @param type the type
* @param username the username
* @param from the from
* @param count the count
* @param request the request
* @param response the response
* @return the map
*/
@Operation(summary = "Remove single sign-on session for type and user")
@DeleteMapping(produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, Object> destroySsoSessions(@Nullable @RequestParam(name = "type", required = false) final String type, @Nullable @RequestParam(name = "username", required = false) final String username, @RequestParam(name = "from", required = false, defaultValue = "0") final long from, @RequestParam(name = "count", required = false, defaultValue = "1000") final long count, final HttpServletRequest request, final HttpServletResponse response) {
if (StringUtils.isBlank(username) && StringUtils.isBlank(type)) {
return Map.of(STATUS, HttpServletResponse.SC_BAD_REQUEST);
}
if (StringUtils.isNotBlank(username)) {
val sessionsMap = new HashMap<String, Object>(1);
val tickets = centralAuthenticationService.getObject().getTickets(ticket -> ticket instanceof TicketGrantingTicket && ((TicketGrantingTicket) ticket).getAuthentication().getPrincipal().getId().equalsIgnoreCase(username));
tickets.forEach(ticket -> sessionsMap.put(ticket.getId(), destroySsoSession(ticket.getId(), request, response)));
return sessionsMap;
}
val sessionsMap = new HashMap<String, Object>();
val option = SsoSessionReportOptions.valueOf(type);
val collection = getActiveSsoSessions(option, username, from, count);
collection.stream().map(sso -> sso.get(SsoSessionAttributeKeys.TICKET_GRANTING_TICKET.getAttributeKey()).toString()).forEach(ticketGrantingTicket -> destroySsoSession(ticketGrantingTicket, request, response));
sessionsMap.put(STATUS, HttpServletResponse.SC_OK);
return sessionsMap;
}
use of org.springframework.web.bind.annotation.RequestParam in project cas by apereo.
the class DuoSecurityAdminApiEndpoint method getUser.
/**
* Fetch duo user account from admin api.
*
* @param username the username
* @param providerId the provider id
* @return the map
*/
@GetMapping(path = "/{username}", produces = MediaType.APPLICATION_JSON_VALUE)
@Operation(summary = "Fetch Duo Security user account from Duo Admin API", parameters = { @Parameter(name = "username", required = true, in = ParameterIn.PATH), @Parameter(name = "providerId") })
public Map<String, DuoSecurityUserAccount> getUser(@PathVariable("username") final String username, @RequestParam(required = false) final String providerId) {
val results = new LinkedHashMap<String, DuoSecurityUserAccount>();
val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).filter(provider -> provider.getDuoAuthenticationService().getAdminApiService().isPresent()).forEach(Unchecked.consumer(p -> {
val duoService = p.getDuoAuthenticationService().getAdminApiService().get();
duoService.getDuoSecurityUserAccount(username).ifPresent(user -> results.put(p.getId(), user));
}));
return results;
}
use of org.springframework.web.bind.annotation.RequestParam in project cas by apereo.
the class DuoSecurityAdminApiEndpoint method createBypassCodes.
/**
* Create bypass codes.
*
* @param username the username
* @param providerId the provider id
* @param userId the user id
* @return the map
*/
@Operation(summary = "Create bypass codes using Duo Admin API", parameters = { @Parameter(name = "username", required = true), @Parameter(name = "providerId"), @Parameter(name = "userId") })
@PostMapping(path = "/bypassCodes", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Map<String, List<Long>> createBypassCodes(@RequestParam(value = "username", required = false) final String username, @RequestParam(value = "providerId", required = false) final String providerId, @RequestParam(value = "userId", required = false) final String userId) {
val results = new LinkedHashMap<String, List<Long>>();
val providers = applicationContext.getBeansOfType(DuoSecurityMultifactorAuthenticationProvider.class).values();
providers.stream().filter(Objects::nonNull).map(DuoSecurityMultifactorAuthenticationProvider.class::cast).filter(provider -> StringUtils.isBlank(providerId) || provider.matches(providerId)).filter(provider -> provider.getDuoAuthenticationService().getAdminApiService().isPresent()).forEach(Unchecked.consumer(p -> {
val duoService = p.getDuoAuthenticationService().getAdminApiService().get();
val uid = StringUtils.isBlank(userId) ? duoService.getDuoSecurityUserAccount(username).map(DuoSecurityUserAccount::getUserId).orElse(StringUtils.EMPTY) : userId;
if (StringUtils.isNotBlank(uid)) {
val codes = duoService.createDuoSecurityBypassCodesFor(uid);
results.put(p.getId(), codes);
}
}));
return results;
}
Aggregations