/**
   * 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 = "/new",
      produces = "application/json",
      consumes = "application/json")
  @ApiOperation(value = "Add a Refset) ")
  @PreAuthorize("hasRole('ROLE_USER')")
  public ResponseEntity<Result<Map<String, Object>>> addRefset(@RequestBody Refset r)
      throws Exception {

    logger.debug("Adding 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>> result = getResult();

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

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

      member.setCreatedBy(getUserDetails().getUsername());
      member.setModifiedBy(getUserDetails().getUsername());
    }
    aService.addRefset(r);

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

    result.setData(data);

    result.getMeta().setMessage(SUCCESS);
    result.getMeta().setStatus(HttpStatus.CREATED);

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