コード例 #1
0
ファイル: StatusCode.java プロジェクト: Eltondcr/opengtsgrey
  /* return StatusCode */
  public static StatusCode findStatusCode(String accountID, String deviceID, int statusCode) {

    /* check account status codes */
    if (!StringTools.isBlank(accountID)) {

      // first, try account/device
      if (!StringTools.isBlank(deviceID)) {
        try {
          StatusCode.Key codeKey = new StatusCode.Key(accountID, deviceID, statusCode);
          if (codeKey.exists()) { // may throw DBException
            StatusCode code = codeKey.getDBRecord(true);
            if (code != null) { // should not be null
              return code;
            }
          }
        } catch (DBException dbe) {
          // ignore error
        }
      }

      // next, try just the account
      try {
        StatusCode.Key codeKey = new StatusCode.Key(accountID, statusCode);
        if (codeKey.exists()) { // may throw DBException
          StatusCode code = codeKey.getDBRecord(true);
          if (code != null) { // should not be null
            return code;
          }
        }
      } catch (DBException dbe) {
        // ignore error
      }
    }

    /* check global status codes */
    String sysAdmin = AccountRecord.getSystemAdminAccountID();
    if (!StringTools.isBlank(sysAdmin)) {
      try {
        StatusCode.Key codeKey = new StatusCode.Key(sysAdmin, statusCode);
        if (codeKey.exists()) { // may throw DBException
          StatusCode code = codeKey.getDBRecord(true);
          if (code != null) { // should not be null
            return code;
          }
        }
      } catch (DBException dbe) {
        // ignore error
      }
    }

    /* icon selector not found */
    return null;
  }
コード例 #2
0
ファイル: StatusCode.java プロジェクト: Eltondcr/opengtsgrey
 /* return true if StatusCode exists */
 public static boolean exists(String accountID, String deviceID, int code)
     throws DBException // if error occurs while testing existance
     {
   if ((accountID != null) && (deviceID != null)) {
     StatusCode.Key scKey = new StatusCode.Key(accountID, deviceID, code);
     return scKey.exists();
   }
   return false;
 }
コード例 #3
0
ファイル: StatusCode.java プロジェクト: Eltondcr/opengtsgrey
  /* Return specified StatusCode, create if specified */
  private static StatusCode _getStatusCode(
      String accountID, Account account, String deviceID, int code, boolean createOK)
      throws DBException {
    // does not return null if 'createOK' is true

    /* account-id specified? */
    if (StringTools.isBlank(accountID)) {
      if (account == null) {
        throw new DBException("Account not specified.");
      } else {
        accountID = account.getAccountID();
      }
    } else if ((account != null) && !account.getAccountID().equals(accountID)) {
      throw new DBException("Account does not match specified AccountID.");
    }

    /* device-id specified? */
    if (StringTools.isBlank(deviceID)) {
      // throw new DBException("Device-ID not specified.");
      deviceID = ALL_DEVICES;
    }

    /* get/create entity */
    StatusCode.Key scKey = new StatusCode.Key(accountID, deviceID, code);
    if (scKey.exists()) { // may throw DBException
      StatusCode sc = scKey.getDBRecord(true);
      if (account != null) {
        sc.setAccount(account);
      }
      return sc;
    } else if (createOK) {
      StatusCode sc = scKey.getDBRecord();
      if (account != null) {
        sc.setAccount(account);
      }
      sc.setCreationDefaultValues();
      return sc; // not yet saved!
    } else {
      // record doesn't exist, and caller doesn't want us to create it
      return null;
    }
  }