@Before
 public void before() throws DatastoreException, NotFoundException {
   assertNotNull(entityController);
   toDelete = new ArrayList<String>();
   // Map test objects to their urls
   // Make sure we have a valid user.
   testUser = userManager.getUserInfo(userName);
   UserInfo.validateUserInfo(testUser);
 }
  /* (non-Javadoc)
   * @see org.sagebionetworks.repo.web.service.S3TokenService#createEntityS3Token(java.lang.String, java.lang.String, org.sagebionetworks.repo.model.S3Token, javax.servlet.http.HttpServletRequest)
   */
  @Override
  public S3Token createEntityS3Token(
      String userId, String id, S3Token s3Token, HttpServletRequest request)
      throws DatastoreException, NotFoundException, UnauthorizedException, InvalidModelException {

    // Infer one more parameter
    UserInfo userInfo = userManager.getUserInfo(userId);
    EntityType entityType = entityManager.getEntityType(userInfo, id);
    return s3TokenManager.createS3Token(userId, id, s3Token, entityType);
  }
 @ResponseStatus(HttpStatus.CREATED)
 @RequestMapping(value = UrlHelpers.ACCESS_REQUIREMENT, method = RequestMethod.POST)
 public @ResponseBody AccessRequirement createAccessRequirement(
     @RequestParam(value = AuthorizationConstants.USER_ID_PARAM, required = false) String userId,
     @RequestHeader HttpHeaders header,
     HttpServletRequest request)
     throws Exception {
   UserInfo userInfo = userManager.getUserInfo(userId);
   AccessRequirement accessRequirement = deserialize(request, header);
   return accessRequirementManager.createAccessRequirement(userInfo, accessRequirement);
 }
  @ResponseStatus(HttpStatus.OK)
  @RequestMapping(
      value = UrlHelpers.ACCESS_REQUIREMENT_WITH_REQUIREMENT_ID,
      method = RequestMethod.DELETE)
  public void deleteAccessRequirements(
      @RequestParam(value = AuthorizationConstants.USER_ID_PARAM, required = false) String userId,
      @PathVariable String requirementId)
      throws DatastoreException, UnauthorizedException, NotFoundException, ForbiddenException {
    UserInfo userInfo = userManager.getUserInfo(userId);

    accessRequirementManager.deleteAccessRequirement(userInfo, requirementId);
  }
  /**
   * Create a security token for use for a particular with a particular locationable entity to be
   * stored in AWS S3
   *
   * @param userId
   * @param id
   * @param etag
   * @param s3Token
   * @param request
   * @return a filled-in S3Token
   * @throws NotFoundException
   * @throws DatastoreException
   * @throws UnauthorizedException
   * @throws InvalidModelException
   */
  @Transactional(readOnly = false)
  @ResponseStatus(HttpStatus.CREATED)
  @RequestMapping(
      value = {UrlHelpers.ENTITY_S3TOKEN},
      method = RequestMethod.POST)
  public @ResponseBody S3Token createEntityS3Token(
      @RequestParam(value = AuthorizationConstants.USER_ID_PARAM, required = false) String userId,
      @PathVariable String id,
      @RequestBody S3Token s3Token,
      HttpServletRequest request)
      throws DatastoreException, NotFoundException, UnauthorizedException, InvalidModelException {

    // Infer one more parameter
    UserInfo userInfo = userManager.getUserInfo(userId);
    EntityType entityType = entityManager.getEntityType(userInfo, id);
    return s3TokenManager.createS3Token(userId, id, s3Token, entityType);
  }
  @ResponseStatus(HttpStatus.OK)
  @RequestMapping(value = UrlHelpers.ACCESS_REQUIREMENT_WITH_ENTITY_ID, method = RequestMethod.GET)
  public @ResponseBody PaginatedResults<AccessRequirement> getAccessRequirements(
      @RequestParam(value = AuthorizationConstants.USER_ID_PARAM, required = false) String userId,
      @PathVariable String entityId,
      HttpServletRequest request)
      throws DatastoreException, UnauthorizedException, NotFoundException, ForbiddenException {
    UserInfo userInfo = userManager.getUserInfo(userId);

    QueryResults<AccessRequirement> results =
        accessRequirementManager.getAccessRequirementsForEntity(userInfo, entityId);

    return new PaginatedResults<AccessRequirement>(
        request.getServletPath() + UrlHelpers.ACCESS_REQUIREMENT,
        results.getResults(),
        (int) results.getTotalNumberOfResults(),
        1,
        (int) results.getTotalNumberOfResults(),
        "",
        false);
  }