Example #1
0
 /** Return the keeps the user is allowed to access */
 @RequestMapping(method = RequestMethod.GET)
 public ResponseEntity<ArrayNode> findAll() {
   List<Keep> keeps = new ArrayList<Keep>();
   Iterator<Keep> keepsIt = keepDAO.findAll().iterator();
   keepsIt.forEachRemaining(keeps::add);
   ArrayNode keepsJ = KeepMapper.toJson(keeps);
   return new ResponseEntity<ArrayNode>(keepsJ, HttpStatus.OK);
 }
Example #2
0
  /**
   * Return a keep by id
   *
   * <p>Return: FORBIDDEN when not found or donĀ“t have permission
   */
  @RequestMapping(value = "/{id}", method = RequestMethod.GET)
  public ResponseEntity<ObjectNode> findById(@PathVariable long id) {
    Keep keep = keepDAO.findOne(id);

    if (keep == null) {
      return new ResponseEntity<ObjectNode>(HttpStatus.FORBIDDEN);
    }

    ObjectNode keepJ = KeepMapper.toJsonWithSecrets(keep);
    return new ResponseEntity<ObjectNode>(keepJ, HttpStatus.OK);
  }
Example #3
0
  /**
   * Create an empty keep
   *
   * <p>The creator becomes the keep owner
   */
  @RequestMapping(method = RequestMethod.POST)
  public ResponseEntity<Void> create(@RequestBody ObjectNode keepJ, Principal principal) {
    if (keepJ == null || !keepJ.has("name") || !keepJ.has("description")) {
      return new ResponseEntity<Void>(HttpStatus.BAD_REQUEST);
    }

    String name = keepJ.get("name").textValue();
    String description = keepJ.get("description").textValue();

    Keep keep = new Keep(name, description);
    keepDAO.save(keep);

    return new ResponseEntity<Void>(HttpStatus.CREATED);
  }