Example usage for org.springframework.http ResponseEntity ResponseEntity

List of usage examples for org.springframework.http ResponseEntity ResponseEntity

Introduction

In this page you can find the example usage for org.springframework.http ResponseEntity ResponseEntity.

Prototype

public ResponseEntity(MultiValueMap<String, String> headers, HttpStatus status) 

Source Link

Document

Create a new HttpEntity with the given headers and status code, and no body.

Usage

From source file:com.ar.dev.tierra.api.controller.DetalleTransferenciaController.java

@RequestMapping(value = "/trans", method = RequestMethod.GET)
public ResponseEntity<?> getByTransferencia(@RequestParam("idTransferencia") int idTransferencia) {
    List<DetalleTransferencia> list = facadeService.getDetalleTransferenciaDAO()
            .getByTransferencia(idTransferencia);
    if (!list.isEmpty()) {
        return new ResponseEntity<>(list, HttpStatus.OK);
    } else {//from ww w  .  j  av  a 2s.  co  m
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:monkeys.web.MonkeysController.java

@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
public ResponseEntity<Void> deleteMonkey(@PathVariable Long id) {
    monkeyRepository.delete(id);/*www.  jav a  2s.c o m*/
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(headers, HttpStatus.OK);
}

From source file:reconf.server.services.property.ReadAllRestrictedPropertiesService.java

@RequestMapping(value = "/product/{prod}/component/{comp}/property/{prop}/rule", method = RequestMethod.GET)
@Transactional(readOnly = true)/* w  ww. ja va  2  s  .c o  m*/
public ResponseEntity<AllRestrictedPropertiesResult> restricted(@PathVariable("prod") String product,
        @PathVariable("comp") String component, @PathVariable("prop") String property,
        HttpServletRequest request, Authentication auth) {

    PropertyKey key = new PropertyKey(product, component, property);

    if (!products.exists(key.getProduct())) {
        return new ResponseEntity<AllRestrictedPropertiesResult>(
                new AllRestrictedPropertiesResult(key, Product.NOT_FOUND), HttpStatus.NOT_FOUND);
    }
    if (!components.exists(new ComponentKey(key.getProduct(), key.getComponent()))) {
        return new ResponseEntity<AllRestrictedPropertiesResult>(
                new AllRestrictedPropertiesResult(key, Component.NOT_FOUND), HttpStatus.NOT_FOUND);
    }
    List<Property> dbProperties = properties
            .findByKeyProductAndKeyComponentAndKeyNameOrderByRulePriorityDescKeyRuleNameAsc(key.getProduct(),
                    key.getComponent(), key.getName());
    if (CollectionUtils.isEmpty(dbProperties)) {
        return new ResponseEntity<AllRestrictedPropertiesResult>(
                new AllRestrictedPropertiesResult(key, Property.NOT_FOUND), HttpStatus.NOT_FOUND);
    }
    List<Rule> rules = new ArrayList<>();
    for (int i = 0; i < dbProperties.size() - 1; i++) {
        rules.add(new Rule(dbProperties.get(i)));
    }

    return new ResponseEntity<AllRestrictedPropertiesResult>(
            new AllRestrictedPropertiesResult(key, rules, CrudServiceUtils.getBaseUrl(request)), HttpStatus.OK);
}

From source file:reconf.server.services.component.UpsertComponentService.java

@RequestMapping(value = "/product/{prod}/component/{comp}", method = RequestMethod.PUT)
@Transactional//from  w  w w.  j a  v a 2 s  .  c  o  m
public ResponseEntity<ComponentResult> doIt(@PathVariable("prod") String productId,
        @PathVariable("comp") String componentId,
        @RequestParam(value = "desc", required = false) String description, HttpServletRequest request,
        Authentication auth) {

    ComponentKey key = new ComponentKey(productId, componentId);
    Component reqComponent = new Component(key, description);

    List<String> errors = DomainValidator.checkForErrors(key);
    if (!errors.isEmpty()) {
        return new ResponseEntity<ComponentResult>(new ComponentResult(reqComponent, errors),
                HttpStatus.BAD_REQUEST);
    }

    Product product = products.findOne(key.getProduct());
    if (product == null) {
        return new ResponseEntity<ComponentResult>(new ComponentResult(reqComponent, Product.NOT_FOUND),
                HttpStatus.NOT_FOUND);
    }
    HttpStatus status = null;
    Component dbComponent = components.findOne(key);
    if (dbComponent == null) {
        dbComponent = new Component(key, description);
        components.save(dbComponent);
        status = HttpStatus.CREATED;

    } else {
        dbComponent.setDescription(description);
        status = HttpStatus.OK;
    }
    return new ResponseEntity<ComponentResult>(
            new ComponentResult(dbComponent, CrudServiceUtils.getBaseUrl(request)), status);
}

From source file:com.rx4dr.service.controller.RestExceptionHandler.java

@ExceptionHandler({ UnknownResourceException.class })
public ResponseEntity<Map<String, String>> handleUnknownResourceException(UnknownResourceException e) {
    logger.debug("Enyeting handleUnknownResourceException");
    Map<String, String> map = new HashMap<String, String>();
    map.put(status, HttpStatus.NOT_FOUND.toString());
    map.put(error, e.getClass().getSimpleName());
    map.put(description, e.getMessage());
    return new ResponseEntity<Map<String, String>>(map, HttpStatus.OK);

}

From source file:com.sentinel.web.controllers.LoginController.java

@RequestMapping(method = RequestMethod.GET, value = "/all/invalid_session")
public @ResponseBody ResponseEntity<String> handleInvalidSession(HttpServletRequest request,
        HttpServletResponse response) {//from  w w  w  .j a v  a  2  s .c  o m
    return new ResponseEntity<>("Logged in from a different device", HttpStatus.REQUEST_TIMEOUT);
}

From source file:gt.dakaik.rest.impl.DocumentTypeImpl.java

@Override
public ResponseEntity<DocumentType> doCreate(DocumentType documentType, int idUsuario, String token)
        throws EntidadDuplicadaException {
    return new ResponseEntity(repoDocumentType.save(documentType), HttpStatus.OK);
}

From source file:reconf.server.services.security.DeleteUserService.java

@RequestMapping(value = "/user/{user}", method = RequestMethod.DELETE)
@Transactional//w ww.ja v  a 2  s  .c  o  m
public ResponseEntity<Client> doIt(@PathVariable("user") String user, Authentication authentication) {

    if (ApplicationSecurity.isRoot(user)) {
        return new ResponseEntity<Client>(new Client(user, cannotDeleteRoot), HttpStatus.BAD_REQUEST);
    }

    if (!userDetailsManager.userExists(user)) {
        return new ResponseEntity<Client>(new Client(user, userNotFound), HttpStatus.NOT_FOUND);
    }

    userProducts.deleteByKeyUsername(user);
    userDetailsManager.deleteUser(user);
    return new ResponseEntity<Client>(HttpStatus.OK);
}

From source file:com.ar.dev.tierra.api.controller.TransferenciaController.java

@RequestMapping(value = "/all", method = RequestMethod.GET)
public ResponseEntity<?> getAll() {
    List<Transferencia> list = facadeService.getTransferenciaDAO().getAll();
    if (!list.isEmpty()) {
        return new ResponseEntity<>(list, HttpStatus.OK);
    } else {//ww  w . ja va 2s . c o m
        return new ResponseEntity<>(HttpStatus.NOT_FOUND);
    }
}

From source file:monkeys.web.BananasController.java

@RequestMapping(method = RequestMethod.DELETE, value = "/{id}")
public ResponseEntity<Void> deleteBanana(@PathVariable Long id) {
    bananaRepository.delete(id);/* w w w  .  jav  a 2  s.  c  o  m*/
    HttpHeaders headers = new HttpHeaders();
    return new ResponseEntity<>(headers, HttpStatus.OK);
}