Search in sources :

Example 36 with ResponseBody

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;
}
Also used : URI(java.net.URI) HashSet(java.util.HashSet) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 37 with ResponseBody

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);
}
Also used : Student(ba.isss.models.Student) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 38 with ResponseBody

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();
}
Also used : ArticleIdentifier(org.ambraproject.rhino.identity.ArticleIdentifier) Category(org.ambraproject.rhino.model.Category) Article(org.ambraproject.rhino.model.Article) RestClientException(org.ambraproject.rhino.rest.RestClientException) Transactional(org.springframework.transaction.annotation.Transactional) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 39 with ResponseBody

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;
}
Also used : ServiceError(com.kixeye.chassis.transport.dto.ServiceError) ExceptionHandler(org.springframework.web.bind.annotation.ExceptionHandler) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Example 40 with ResponseBody

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);
}
Also used : SampleReference(com.iggroup.oss.sample.domain.SampleReference) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

Aggregations

ResponseBody (org.springframework.web.bind.annotation.ResponseBody)491 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)454 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)84 ApiOperation (io.swagger.annotations.ApiOperation)64 ArrayList (java.util.ArrayList)55 HashMap (java.util.HashMap)50 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)47 ResponseEntity (org.springframework.http.ResponseEntity)39 CommandStringBuilder (org.apache.geode.management.internal.cli.util.CommandStringBuilder)37 ProfileEntity (org.orcid.persistence.jpa.entities.ProfileEntity)36 RootNode (org.hisp.dhis.node.types.RootNode)33 IOException (java.io.IOException)22 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)22 CollectionNode (org.hisp.dhis.node.types.CollectionNode)19 GetMapping (org.springframework.web.bind.annotation.GetMapping)19 Date (java.util.Date)18 User (org.hisp.dhis.user.User)17 Range (com.navercorp.pinpoint.web.vo.Range)15 Text (org.orcid.pojo.ajaxForm.Text)15 OrcidProfile (org.orcid.jaxb.model.message.OrcidProfile)14