/**
   * Adds meta details in new {@link Refset}
   *
   * @param r
   * @throws AccessDeniedException
   */
  private void addMetaDetails(Refset r) throws AccessDeniedException {

    String id = UUID.randomUUID().toString();
    r.setUuid(id);
    r.setCreated(new DateTime());
    r.setCreatedBy(getUserDetails().getUsername());
    r.setActive(r.isActive());
  }
  @RequestMapping(
      method = RequestMethod.POST,
      value = "/update",
      produces = "application/json",
      consumes = "application/json")
  @ApiOperation(value = "Update a Refset")
  @PreAuthorize("hasRole('ROLE_USER')")
  public ResponseEntity<Result<Map<String, Object>>> updateRefset(@RequestBody Refset r)
      throws Exception {

    logger.debug("Updating an existing refsets {}", r);

    validateRefset(r);
    Set<Member> ms = new HashSet<Member>();
    ms.addAll(r.getMembers());
    if (ms != null && !ms.isEmpty()) {

      validateMembers(ms);
    }
    Result<Map<String, Object>> response = new Result<Map<String, Object>>();
    Meta m = new Meta();

    response.setMeta(m);

    r.setModifiedBy(getUserDetails().getUsername());

    List<Member> members = r.getMembers();
    for (Member member : members) {

      member.setModifiedBy(getUserDetails().getUsername());
    }

    aService.updateRefset(r);

    Map<String, Object> data = new HashMap<String, Object>();
    data.put("uuid", r.getUuid());
    m.add(
        linkTo(methodOn(RefsetBrowseController.class).getRefsetDetails(r.getUuid()))
            .withRel("Refset"));

    response.setData(data);

    m.setMessage(SUCCESS);
    m.setStatus(HttpStatus.OK);

    return new ResponseEntity<Result<Map<String, Object>>>(response, HttpStatus.OK);
  }