use of org.springframework.web.bind.annotation.RequestParam in project goci by EBISPOT.
the class AssociationController method addSnpInteraction.
@RequestMapping(value = "/studies/{studyId}/associations/add_interaction", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String addSnpInteraction(@ModelAttribute("form") @Valid SnpAssociationInteractionForm snpAssociationInteractionForm, BindingResult bindingResult, @PathVariable Long studyId, Model model, @RequestParam(required = true) String measurementType, HttpServletRequest request) throws EnsemblMappingException {
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Binding vs Validator issue. File: messages.properties
if (bindingResult.hasErrors()) {
model.addAttribute("form", snpAssociationInteractionForm);
return "add_snp_interaction_association";
}
// Check for errors in form that would prevent saving an association
List<AssociationValidationView> colErrors = associationOperationsService.checkSnpAssociationInteractionFormErrorsForView(snpAssociationInteractionForm, measurementType);
if (!colErrors.isEmpty()) {
model.addAttribute("errors", colErrors);
model.addAttribute("form", snpAssociationInteractionForm);
model.addAttribute("criticalErrorsFound", true);
return "add_snp_interaction_association";
} else {
// Create an association object from details in returned form
Association newAssociation = snpInteractionAssociationService.createAssociation(snpAssociationInteractionForm);
// Save and validate form
String eRelease = ensemblRestTemplateService.getRelease();
Collection<AssociationValidationView> errors = associationOperationsService.saveAssociationCreatedFromForm(study, newAssociation, 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) {
model.addAttribute("errors", errors);
model.addAttribute("form", snpAssociationInteractionForm);
model.addAttribute("criticalErrorsFound", true);
return "add_snp_interaction_association";
} else {
return "redirect:/associations/" + newAssociation.getId();
}
}
}
use of org.springframework.web.bind.annotation.RequestParam in project goci by EBISPOT.
the class AssociationController method addStandardSnps.
// Add new standard association/snp information to a study
@RequestMapping(value = "/studies/{studyId}/associations/add_standard", produces = MediaType.TEXT_HTML_VALUE, method = RequestMethod.POST)
public String addStandardSnps(@ModelAttribute("form") @Valid SnpAssociationStandardMultiForm snpAssociationStandardMultiForm, BindingResult bindingResult, @PathVariable Long studyId, Model model, @RequestParam(required = true) String measurementType, HttpServletRequest request) throws EnsemblMappingException {
Study study = studyRepository.findOne(studyId);
model.addAttribute("study", study);
model.addAttribute("measurementType", measurementType);
// Binding vs Validator issue. File: messages.properties
if (bindingResult.hasErrors()) {
model.addAttribute("form", snpAssociationStandardMultiForm);
return "add_standard_snp_association";
}
// Check for errors in form that would prevent saving an association
List<AssociationValidationView> rowErrors = associationOperationsService.checkSnpAssociationFormErrors(snpAssociationStandardMultiForm, measurementType);
if (!rowErrors.isEmpty()) {
model.addAttribute("errors", rowErrors);
model.addAttribute("form", snpAssociationStandardMultiForm);
model.addAttribute("criticalErrorsFound", true);
return "add_standard_snp_association";
} else {
// Create an association object from details in returned form
Association newAssociation = singleSnpMultiSnpAssociationService.createAssociation(snpAssociationStandardMultiForm);
// Save and validate form
String eRelease = ensemblRestTemplateService.getRelease();
Collection<AssociationValidationView> errors = associationOperationsService.saveAssociationCreatedFromForm(study, newAssociation, 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) {
model.addAttribute("errors", errors);
model.addAttribute("form", snpAssociationStandardMultiForm);
model.addAttribute("criticalErrorsFound", true);
return "add_standard_snp_association";
} else {
return "redirect:/associations/" + newAssociation.getId();
}
}
}
use of org.springframework.web.bind.annotation.RequestParam in project ontrack by nemerosa.
the class APIController method describe.
@RequestMapping(value = "/describe", method = RequestMethod.GET)
public APIDescription describe(HttpServletRequest request, @RequestParam String path) throws Exception {
HandlerExecutionChain executionChain = handlerMapping.getHandler(new HttpServletRequestWrapper(request) {
@Override
public String getRequestURI() {
return path;
}
@Override
public String getServletPath() {
return path;
}
});
// Gets the handler
Object handler = executionChain.getHandler();
if (handler instanceof HandlerMethod) {
HandlerMethod handlerMethod = (HandlerMethod) handler;
String type = handlerMethod.getBeanType().getName();
String method = handlerMethod.getMethod().getName();
// Gets all the infos
List<APIInfo> apiInfos = getApiInfos();
// Looking for any GET mapping
APIMethodInfo get = apiInfos.stream().flatMap(i -> i.getMethods().stream()).filter(mi -> StringUtils.equals(type, mi.getApiInfo().getType()) && StringUtils.equals(method, mi.getMethod())).findFirst().orElseThrow(() -> new APIMethodInfoNotFoundException(path));
// Gets all methods with the same path pattern
List<APIMethodInfo> methods = apiInfos.stream().flatMap(i -> i.getMethods().stream()).filter(mi -> StringUtils.equals(get.getPath(), mi.getPath())).collect(Collectors.toList());
// OK
return new APIDescription(path, methods);
} else {
throw new APIMethodInfoNotFoundException(path);
}
}
use of org.springframework.web.bind.annotation.RequestParam in project scoold by Erudika.
the class TagsController method delete.
@PostMapping("/delete")
public String delete(@RequestParam String tag, HttpServletRequest req, HttpServletResponse res) {
Profile authUser = utils.getAuthUser(req);
if (utils.isMod(authUser)) {
Tag t = pc.read(Utils.type(Tag.class), new Tag(tag).getId());
if (t != null) {
pc.delete(t);
logger.info("User {} ({}) deleted tag '{}'.", authUser.getName(), authUser.getCreatorid(), t.getTag());
Pager pager = new Pager(1, "_docid", false, Config.MAX_ITEMS_PER_PAGE);
List<Question> questionslist;
do {
questionslist = pc.findTagged(Utils.type(Question.class), new String[] { t.getTag() }, pager);
for (Question q : questionslist) {
t.setCount(t.getCount() + 1);
q.setTags(Optional.ofNullable(q.getTags()).orElse(Collections.emptyList()).stream().filter(ts -> !ts.equals(t.getTag())).distinct().collect(Collectors.toList()));
logger.debug("Removed tag {} from {} out of {} questions.", t.getTag(), questionslist.size(), pager.getCount());
}
if (!questionslist.isEmpty()) {
pc.updateAll(questionslist);
}
} while (!questionslist.isEmpty());
}
}
if (utils.isAjaxRequest(req)) {
res.setStatus(200);
return "blank";
} else {
return "redirect:" + TAGSLINK + "?" + req.getQueryString();
}
}
use of org.springframework.web.bind.annotation.RequestParam in project scoold by Erudika.
the class TagsController method rename.
@PostMapping
public String rename(@RequestParam String tag, @RequestParam String newtag, HttpServletRequest req, HttpServletResponse res, Model model) {
Profile authUser = utils.getAuthUser(req);
int count = 0;
if (utils.isMod(authUser)) {
Tag updated;
Tag oldTag = new Tag(tag);
Tag newTag = new Tag(newtag);
Tag t = pc.read(Utils.type(Tag.class), oldTag.getId());
if (t != null && !oldTag.getTag().equals(newTag.getTag())) {
if (oldTag.getTag().equals(newTag.getTag())) {
t.setCount(pc.getCount(Utils.type(Question.class), Collections.singletonMap(Config._TAGS, oldTag.getTag())).intValue());
updated = pc.update(t);
} else {
pc.delete(t);
t.setId(newtag);
logger.info("User {} ({}) is renaming tag '{}' to '{}'.", authUser.getName(), authUser.getCreatorid(), oldTag.getTag(), t.getTag());
t.setCount(pc.getCount(Utils.type(Question.class), Collections.singletonMap(Config._TAGS, newTag.getTag())).intValue());
Pager pager = new Pager(1, "_docid", false, Config.MAX_ITEMS_PER_PAGE);
List<Question> questionslist;
do {
questionslist = pc.findTagged(Utils.type(Question.class), new String[] { oldTag.getTag() }, pager);
for (Question q : questionslist) {
t.setCount(t.getCount() + 1);
q.setTags(Optional.ofNullable(q.getTags()).orElse(Collections.emptyList()).stream().map(ts -> {
if (ts.equals(newTag.getTag())) {
t.setCount(t.getCount() - 1);
}
return ts.equals(oldTag.getTag()) ? t.getTag() : ts;
}).distinct().collect(Collectors.toList()));
logger.debug("Updated {} out of {} questions with new tag {}.", questionslist.size(), pager.getCount(), t.getTag());
}
if (!questionslist.isEmpty()) {
pc.updateAll(questionslist);
}
} while (!questionslist.isEmpty());
// overwrite new tag object
updated = pc.create(t);
}
model.addAttribute("tag", updated);
count = t.getCount();
}
}
if (utils.isAjaxRequest(req)) {
res.setStatus(200);
res.setContentType("application/json");
try {
res.getWriter().println("{\"count\":" + count + ", \"tag\":\"" + new Tag(newtag).getTag() + "\"}");
} catch (IOException ex) {
}
return "blank";
} else {
return "redirect:" + TAGSLINK + "?" + req.getQueryString();
}
}
Aggregations