use of org.springframework.web.bind.annotation.ResponseBody in project goci by EBISPOT.
the class PussycatGOCIController method getRelatedTraits.
/**
* This method returns all the children of the provided URI in order to allow filtering based on URIs
*
* @param traitName the name of the trait to lookup
* @param session the http session in which to perform this request
* @return a list of URIs, appropriately "shortformed", that describe the classes that are relevant for this trait
* name
* @throws PussycatSessionNotReadyException
*/
@RequestMapping(value = "/filter/{traitName}")
@ResponseBody
public Set<String> getRelatedTraits(@PathVariable String traitName, HttpSession session) throws PussycatSessionNotReadyException {
Set<URI> uris = getPussycatSession(session).getRelatedTraits(traitName);
Set<String> results = new HashSet<String>();
for (URI uri : uris) {
// process URI to just keep term name
String typeStr = uri.toString();
typeStr = typeStr.substring(typeStr.lastIndexOf("/") + 1, typeStr.length());
typeStr = typeStr.contains("#") ? typeStr.substring(typeStr.lastIndexOf("#") + 1, typeStr.length()) : typeStr;
results.add(typeStr);
}
return results;
}
use of org.springframework.web.bind.annotation.ResponseBody in project SI2016_TIM6 by SoftverInzenjeringETFSA.
the class PrijavaController method odjaviIspit.
@PreAuthorize("hasAnyRole('ROLE_STUDENT')")
@RequestMapping(path = "/odjavi", method = RequestMethod.POST)
@ResponseBody
public void odjaviIspit(@ModelAttribute("odjava") Prijava p, Principal principal) throws Exception {
Student s = studentService.findByUsername(principal.getName());
prijavaService.DeletePrijava(p, s);
}
use of org.springframework.web.bind.annotation.ResponseBody in project rhino by PLOS.
the class ArticleCrudController method flagArticleCategory.
@Transactional(rollbackFor = { Throwable.class })
@RequestMapping(value = "/articles/{doi}/categories", params = { "flag" }, method = RequestMethod.POST)
@ResponseBody
public Map<String, String> flagArticleCategory(@PathVariable("doi") String articleDoi, @RequestParam(value = "categoryTerm", required = true) String categoryTerm, @RequestParam(value = "userId", required = false) String userId, @RequestParam(value = "flag", required = true) String action) throws IOException {
ArticleIdentifier articleId = ArticleIdentifier.create(DoiEscaping.unescape(articleDoi));
Article article = articleCrudService.readArticle(articleId);
Optional<Long> userIdObj = Optional.ofNullable(userId).map(Long::parseLong);
Collection<Category> categories = taxonomyService.getArticleCategoriesWithTerm(article, categoryTerm);
switch(action) {
case "add":
for (Category category : categories) {
taxonomyService.flagArticleCategory(article, category, userIdObj);
}
break;
case "remove":
for (Category category : categories) {
taxonomyService.deflagArticleCategory(article, category, userIdObj);
}
break;
default:
throw new RestClientException("action must be 'add' or 'remove'", HttpStatus.BAD_REQUEST);
}
// ajax call expects returned data so provide an empty map for the body
return ImmutableMap.of();
}
use of org.springframework.web.bind.annotation.ResponseBody in project chassis by Kixeye.
the class HttpExceptionHandler method defaultErrorHandler.
@ExceptionHandler(Exception.class)
@ResponseBody
public ServiceError defaultErrorHandler(HttpServletRequest request, HttpServletResponse response, Exception ex) throws Exception {
ServiceError error = ExceptionServiceErrorMapper.mapException(ex);
switch(error.code) {
case ExceptionServiceErrorMapper.UNKNOWN_ERROR_CODE:
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
logger.error("Unexpected error", ex);
break;
case ExceptionServiceErrorMapper.VALIDATION_ERROR_CODE:
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
if (logger.isDebugEnabled()) {
logger.debug("Validation exception", ex);
}
break;
case ExceptionServiceErrorMapper.SECURITY_ERROR_CODE:
response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
if (logger.isDebugEnabled()) {
logger.debug("Security exception", ex);
}
break;
default:
if (ex instanceof HttpServiceException) {
HttpServiceException httpEx = (HttpServiceException) ex;
response.setStatus(httpEx.httpResponseCode);
}
logger.warn("Service exception", ex);
break;
}
return error;
}
use of org.springframework.web.bind.annotation.ResponseBody in project RESTdoclet by IG-Group.
the class SampleController method getSampleByReference.
/**
* Find sample by unique lookup reference
*
* @param reference the sample reference, a 5 digit text field
* @return the sample object corresponding to the lookup reference
*/
@RequestMapping(value = "/samples/{reference}", method = { RequestMethod.GET })
@ResponseBody
public Sample getSampleByReference(/*
* @Valid @Pattern(regexp=
* "[0-9][0-9][0-9][0-9][0-9]")
*/
@PathVariable String reference) {
LOGGER.info("getSampleByReference " + reference);
// since @Valid doesn't work properly until Spring 3.1
// Note: could use SampleReference as a RequestParam but then the
// interface is a little clunky
validate(new SampleReference(reference));
return service.getSampleByReference(reference);
}
Aggregations