コード例 #1
0
  /**
   * Verifies that each username in usernameList belongs to the campaign specified by the
   * campaignId.
   *
   * @param request The request to fail when a user does not belong to a campaign or an IO problem
   *     occurs.
   * @param campaignId The campaign to check each user against.
   * @param usernameList The users in question
   * @throws ServiceException If any user in usernameList does not belong to the campaign or if an
   *     IO problem occurs.
   * @throws IllegalArgumentException if the request is null; if the campaignId is empty or null; or
   *     if the usernameList is null.
   */
  public static void verifyUsersExistInCampaign(
      Request request, String campaignId, List<String> usernameList) throws ServiceException {
    // check for logical errors
    if (request == null
        || StringUtils.isEmptyOrWhitespaceOnly(campaignId)
        || usernameList == null) {
      throw new IllegalArgumentException("null request, empty campaignId, or null usernameList");
    }

    // check each username in usernameList
    try {
      for (String username : usernameList) {
        if (!UserCampaignDaos.userBelongsToCampaign(username, campaignId)) {
          StringBuilder sb = new StringBuilder();
          sb.append("User in usernameList does not belong to campaign. Username: "******" Campaign ID: ");
          sb.append(campaignId);
          String msg = sb.toString();
          request.setFailed(ErrorCodes.USER_NOT_IN_CAMPAIGN, msg);
          throw new ServiceException(msg);
        }
      }
    } catch (DataAccessException e) {
      request.setFailed();
      throw new ServiceException(e);
    }
  }
コード例 #2
0
ファイル: Annotation.java プロジェクト: Priyeshmshr/server
  /**
   * Creates an Annotation using the provided values.
   *
   * @param id a UUID
   * @param text the annotation text
   * @param epochMillis the UNIX epoch millis
   * @param timezone the timezone on the annotation
   * @throws DomainException if any of the input is missing or malformed
   */
  public Annotation(String id, String text, Long epochMillis, String timezone)
      throws DomainException {
    UUID tUuid = null;

    try {
      tUuid = UUID.fromString(id);
    } catch (IllegalArgumentException e) {
      throw new DomainException("The id is not a valid UUID.");
    }
    if (StringUtils.isEmptyOrWhitespaceOnly(text)) {
      throw new DomainException("Annotation text is required.");
    }
    if (epochMillis == null) {
      throw new DomainException("A epoch milliseconds value is required.");
    }
    if (StringUtils.isEmptyOrWhitespaceOnly(timezone)) {
      throw new DomainException("A timezone is required.");
    }

    this.id = tUuid;
    this.text = text;
    this.epochMillis = epochMillis;
    this.timezone = TimeZone.getTimeZone(timezone);
  }