예제 #1
0
  /* update title string */
  public static void updateAccountString(
      Account account, String stringID, String description, String singular, String plural)
      throws DBException {

    /* valid account? */
    if (account == null) {
      throw new DBException("Account not specified.");
    }

    /* delete? */
    // delete if both singular/plural values are empty/null
    if (((singular == null) || singular.equals("")) && ((plural == null) || plural.equals(""))) {
      String acctID = account.getAccountID();
      AccountString.Key key = new AccountString.Key(acctID, stringID);
      key.delete(true); // also delete dependencies (if any)
      return;
    }

    /* get/create AccountString */
    AccountString str = AccountString.getAccountString(account, stringID);
    if (str == null) {
      str = AccountString.getAccountString(account, stringID, true);
    }

    /* insert/update */
    str.setDescription(description);
    str.setSingularTitle(singular);
    str.setPluralTitle((plural != null) ? plural : singular);
    str.save();
  }
예제 #2
0
  public static void main(String args[]) {
    DBConfig.cmdLineInit(args, true); // main
    String acctID = RTConfig.getString(ARG_ACCOUNT, "");
    String strID = RTConfig.getString(ARG_STRING, "");

    /* account-id specified? */
    if (StringTools.isBlank(acctID)) {
      Print.logError("Account-ID not specified.");
      usage();
    }

    /* get account */
    Account acct = null;
    try {
      acct = Account.getAccount(acctID); // may throw DBException
      if (acct == null) {
        Print.logError("Account-ID does not exist: " + acctID);
        usage();
      }
    } catch (DBException dbe) {
      Print.logException("Error loading Account: " + acctID, dbe);
      // dbe.printException();
      System.exit(99);
    }

    /* string-id specified? */
    if ((strID == null) || strID.equals("")) {
      Print.logError("String-ID not specified.");
      usage();
    }

    /* string exists? */
    boolean stringExists = false;
    try {
      stringExists = AccountString.exists(acctID, strID);
    } catch (DBException dbe) {
      Print.logError("Error determining if AccountString exists: " + _fmtStrID(acctID, strID));
      System.exit(99);
    }

    /* option count */
    int opts = 0;

    /* delete */
    if (RTConfig.getBoolean(ARG_DELETE, false) && !acctID.equals("") && !strID.equals("")) {
      opts++;
      if (!stringExists) {
        Print.logWarn("AccountString does not exist: " + _fmtStrID(acctID, strID));
        Print.logWarn("Continuing with delete process ...");
      }
      try {
        AccountString.Key strKey = new AccountString.Key(acctID, strID);
        strKey.delete(true); // also delete dependencies
        Print.logInfo("AccountString deleted: " + _fmtStrID(acctID, strID));
        stringExists = false;
      } catch (DBException dbe) {
        Print.logError("Error deleting AccountString: " + _fmtStrID(acctID, strID));
        dbe.printException();
        System.exit(99);
      }
      System.exit(0);
    }

    /* create */
    if (RTConfig.getBoolean(ARG_CREATE, false)) {
      opts++;
      if (stringExists) {
        Print.logWarn("AccountString already exists: " + _fmtStrID(acctID, strID));
      } else {
        try {
          AccountString.createNewAccountString(acct, strID);
          Print.logInfo("Created AccountString: " + _fmtStrID(acctID, strID));
          stringExists = true;
        } catch (DBException dbe) {
          Print.logError("Error creating AccountString: " + _fmtStrID(acctID, strID));
          dbe.printException();
          System.exit(99);
        }
      }
    }

    /* edit */
    if (RTConfig.getBoolean(ARG_EDIT, false)) {
      opts++;
      if (!stringExists) {
        Print.logError("AccountString does not exist: " + _fmtStrID(acctID, strID));
      } else {
        try {
          AccountString str =
              AccountString.getAccountString(acct, strID, false); // may throw DBException
          DBEdit editor = new DBEdit(str);
          editor.edit(true); // may throw IOException
        } catch (IOException ioe) {
          if (ioe instanceof EOFException) {
            Print.logError("End of input");
          } else {
            Print.logError("IO Error");
          }
        } catch (DBException dbe) {
          Print.logError("Error editing AccountString: " + _fmtStrID(acctID, strID));
          dbe.printException();
        }
      }
      System.exit(0);
    }

    /* no options specified */
    if (opts == 0) {
      Print.logWarn("Missing options ...");
      usage();
    }
  }