Beispiel #1
0
 public static void main(String argv[]) {
   RTConfig.setCommandLineArgs(argv);
   InitJ1587DescriptionProvider();
   RTProperties cmdLineProps = RTConfig.getCommandLineProperties();
   long fault = EncodeFault(cmdLineProps);
   Print.sysPrintln("Fault : " + fault + " [0x" + StringTools.toHexString(fault) + "]");
   Print.sysPrintln("String: " + GetPropertyString(fault));
   Print.sysPrintln("Desc  : " + GetFaultDescription(fault, null));
 }
Beispiel #2
0
 public final User getUser() {
   if (this.user == null) {
     String userID = this.getUserID();
     Print.logDebug("[Optimize] Retrieving User record: " + userID);
     try {
       this.user = User.getUser(this.getAccount(), userID);
       // 'this.asset' may still be null if the asset was not found
     } catch (DBException dbe) {
       // may be caused by "java.net.ConnectException: Connection refused: connect"
       Print.logError("User not found: " + this.getAccountID() + "/" + userID);
       this.user = null;
     }
   }
   return this.user;
 }
Beispiel #3
0
 private static void usage() {
   Print.logInfo("Usage:");
   Print.logInfo("  java ... " + StatusCode.class.getName() + " {options}");
   Print.logInfo("Options:");
   Print.logInfo("  -account=<id>   Account ID owning StatusCode");
   Print.logInfo("  -device=<id>    Device ID owning StatusCode (use '/' for ALL)");
   Print.logInfo("  -code=<id>      StatusCode to create/delete/edit");
   Print.logInfo("  -create         Create a new StatusCode");
   Print.logInfo("  -edit           To edit an existing StatusCode");
   Print.logInfo("  -delete         Delete specified StatusCode");
   System.exit(1);
 }
Beispiel #4
0
 private static void usage() {
   Print.logInfo("Usage:");
   Print.logInfo("  java ... " + URIArg.class.getName() + " {options}");
   Print.logInfo("Options:");
   Print.logInfo("  -encode=<ASCII>    Encode ASCII string to URL argument string");
   Print.logInfo("  -decode=<args>     Decode URL argument string to ASCII");
   Print.logInfo("  -rtpEnc=<url>      RTP Encode URL [key = 'rtp']");
   Print.logInfo("  -rtpDec=<url>      RTP Decode URL [key = 'rtp']");
   System.exit(1);
 }
Beispiel #5
0
 /** ** Descrambles String */
 public static String _des64(String e) {
   if (!StringTools.isBlank(e)) {
     try {
       byte b[] = Base64.decode(e, getBase64Alphabet(), Base64Pad);
       return StringTools.toStringValue(b, ' ');
     } catch (Base64.Base64DecodeException bde) {
       Print.logError("Invalid Base64 characters", bde);
       return "";
     }
   } else {
     return "";
   }
 }
Beispiel #6
0
  /**
   * ** Traverses the DBFactory dependency tree, creating a DBFactoryTree ** @param level The
   * current tree level ** @param dbFact The current DBFactory to add ** @param parentNode The
   * parent node to which a new DBFactoryNode child will be added ** @param addedTables A set of
   * table names added to the current DBFactoryTree *
   */
  private static void _traverseDBFactoryTree(
      int level,
      DBFactory<? extends DBRecord> dbFact,
      DBFactoryTree parentNode,
      Set<String> addedTables) {

    /* no DBFactory? */
    if (dbFact == null) {
      Print.logError("Null DBFactory!");
      return;
    }
    String utableName = dbFact.getUntranslatedTableName();

    /* already added? */
    if (addedTables.contains(utableName)) {
      return;
    }
    addedTables.add(utableName);

    /* add this node */
    // Print.logInfo(StringTools.replicateString("  ",level) + dbFact.getUntranslatedTableName());
    DBFactoryTree dbFactNode = new DBFactoryTree(level, parentNode, dbFact);
    parentNode.addChild(dbFactNode);

    /* find dependent children */
    DBFactory<? extends DBRecord> childFact[] = dbFact.getChildFactories();
    for (int i = 0; i < childFact.length; i++) {
      int index = childFact[i].getParentTables().indexOf(utableName);
      if (level == index) {
        DBFactoryTree._traverseDBFactoryTree(level + 1, childFact[i], dbFactNode, addedTables);
      } else if (!addedTables.contains(childFact[i].getUntranslatedTableName())) {
        Print.logWarn(
            "Skipping table in heiarchy: "
                + utableName
                + " ==> "
                + childFact[i].getUntranslatedTableName());
      }
    }
  }
Beispiel #7
0
  /** ** Main entry point for testing/debugging ** @param argv Comand-line arguments */
  public static void main(String argv[]) {
    RTConfig.setCommandLineArgs(argv);

    /* decode URI argument strings */
    if (RTConfig.hasProperty(ARG_DECODE)) {
      String a = RTConfig.getString(ARG_DECODE, "");
      String s = URIArg.decodeArg(new StringBuffer(), a).toString();
      Print.sysPrintln("ASCII: " + s);
      System.exit(0);
    }

    /* encode Base64 strings */
    if (RTConfig.hasProperty(ARG_ENCODE)) {
      String s = RTConfig.getString(ARG_ENCODE, "");
      String a = URIArg.encodeArg(new StringBuffer(), s).toString();
      Print.sysPrintln("Args: " + a);
      System.exit(0);
    }

    /* RTP decode */
    if (RTConfig.hasProperty(ARG_RTPDEC)) {
      URIArg rtpUrl = new URIArg(RTConfig.getString(ARG_RTPDEC, ""));
      URIArg decUrl = rtpUrl.rtpDecode("rtp");
      Print.sysPrintln("URL: " + decUrl.toString());
      System.exit(0);
    }

    /* RTP encode */
    if (RTConfig.hasProperty(ARG_RTPENC)) {
      URIArg decUrl = new URIArg(RTConfig.getString(ARG_RTPENC, ""));
      URIArg rtpUrl = decUrl.rtpEncode("rtp");
      Print.sysPrintln("URL: " + rtpUrl.toString());
      System.exit(0);
    }

    /* no options */
    usage();
  }
Beispiel #8
0
  /**
   * ** Sets the DBRecord for this node ** @param record The DBRecord to set ** @return True if the
   * DBRecord was successfully set, false otherwise
   */
  public boolean setDBRecord(DBRecord<?> record) {

    /* pre-checks */
    this.dbRecord = null;
    if (record == null) {
      return false;
    } else if (!this.hasDBFactory()) {
      // TODO: we probably could just retrieve the DBFactory from the DBRecord
      Print.logError("DBFactory is not defined!");
      return false;
    }

    /* check DBFactory */
    DBFactory<?> rcdFact = DBRecord.getFactory(record);
    if (!this.getDBFactory().equals(rcdFact)) {
      Print.logError("Invalid DBFactory for specified DBRecord!");
      return false;
    }

    /* set DBRecord */
    this.dbRecord = record;
    return true;
  }
Beispiel #9
0
 public static boolean InitJ1587DescriptionProvider() {
   if (!j1587DidInit) {
     j1587DidInit = true;
     try {
       j1587GetDescription =
           new MethodAction(
               PACKAGE_EXTRA_DBTOOLS_ + "J1587", "GetJ1587Description", Properties.class);
       j1587DescProvider =
           new DTOBDFault.J1587DescriptionProvider() {
             public Properties getJ1587Descriptions(long fault) {
               if (DTOBDFault.IsJ1708(fault)) {
                 int mid = DTOBDFault.DecodeSystem(fault); // MID
                 boolean isSid = DTOBDFault.IsJ1708_SID(fault);
                 int pidSid = DTOBDFault.DecodePidSid(fault); // PID|SID "128/[s]123/1"
                 int fmi = DTOBDFault.DecodeFMI(fault); // FMI
                 Properties p = new Properties();
                 p.setProperty("MID", String.valueOf(mid));
                 p.setProperty((isSid ? "SID" : "PID"), String.valueOf(pidSid));
                 p.setProperty("FMI", String.valueOf(fmi));
                 try {
                   return (Properties) j1587GetDescription.invoke(p);
                 } catch (Throwable th) {
                   return null;
                 }
               } else {
                 return null;
               }
             }
           };
       Print.logDebug("J1587 Description Provider installed ...");
     } catch (Throwable th) {
       // Print.logException("J1587 Description Provider NOT installed!", th);
     }
   }
   return (j1587DescProvider != null);
 }
Beispiel #10
0
  public static void main(String argv[]) {
    DBConfig.cmdLineInit(argv, true); // main
    String accountID = RTConfig.getString(ARG_ACCOUNT, "");
    String deviceID = RTConfig.getString(ARG_DEVICE, "");
    int statusCode = RTConfig.getInt(ARG_CODE, 0);
    boolean anyCode = true; // RTConfig.hasProperty(ARG_ECODE);

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

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

    /* device-id specified? */
    if (StringTools.isBlank(deviceID) || deviceID.startsWith("/")) {
      deviceID = ALL_DEVICES;
    }

    /* check device existance */
    if (!deviceID.equals(ALL_DEVICES)) {
      try {
        Device device = Device.getDevice(account, deviceID); // may throw DBException
        if (device == null) {
          Print.logError("Device-ID does not exist: " + accountID + " / " + deviceID);
          usage();
        }
      } catch (DBException dbe) {
        Print.logException("Error loading Device: " + accountID + " / " + deviceID, dbe);
        System.exit(99);
      }
    }

    /* status-code specified? */
    if ((statusCode > 0)
        && !anyCode
        && !StatusCodes.IsValid(statusCode, account.getPrivateLabel())) {
      Print.logError("Invalid Status Code specified.");
      usage();
    }

    /* statusCode specified? */
    if (statusCode <= 0) {
      Print.logError("StatusCode not specified.");
      usage();
    }

    /* statusCode exists? */
    boolean statusCodeExists = false;
    try {
      statusCodeExists = StatusCode.exists(accountID, deviceID, statusCode);
    } catch (DBException dbe) {
      Print.logError(
          "Error determining if StatusCode exists: "
              + accountID
              + "/"
              + deviceID
              + "/"
              + statusCode);
      System.exit(99);
    }

    /* option count */
    int opts = 0;

    /* delete */
    if (RTConfig.getBoolean(ARG_DELETE, false)) {
      opts++;
      if (!statusCodeExists) {
        Print.logWarn(
            "StatusCode does not exist: " + accountID + "/" + deviceID + "/" + statusCode);
        Print.logWarn("Continuing with delete process ...");
      }
      try {
        StatusCode.Key scKey = new StatusCode.Key(accountID, deviceID, statusCode);
        scKey.delete(true); // also delete dependencies (if any)
        Print.logInfo("StatusCode deleted: " + accountID + "/" + deviceID + "/" + statusCode);
        statusCodeExists = false;
      } catch (DBException dbe) {
        Print.logError(
            "Error deleting StatusCode: " + accountID + "/" + deviceID + "/" + statusCode);
        dbe.printException();
        System.exit(99);
      }
      System.exit(0);
    }

    /* create */
    if (RTConfig.getBoolean(ARG_CREATE, false)) {
      opts++;
      if (statusCodeExists) {
        Print.logWarn(
            "StatusCode already exists: " + accountID + "/" + deviceID + "/" + statusCode);
      } else {
        try {
          StatusCode.createNewStatusCode(account, deviceID, statusCode);
          Print.logInfo("Created StatusCode: " + accountID + "/" + deviceID + "/" + statusCode);
          statusCodeExists = true;
        } catch (DBException dbe) {
          Print.logError(
              "Error creating StatusCode: " + accountID + "/" + deviceID + "/" + statusCode);
          dbe.printException();
          System.exit(99);
        }
      }
    }

    /* edit */
    if (RTConfig.getBoolean(ARG_EDIT, false)) {
      opts++;
      if (!statusCodeExists) {
        Print.logError(
            "StatusCode does not exist: " + accountID + "/" + deviceID + "/" + statusCode);
      } else {
        try {
          StatusCode sc =
              StatusCode.getStatusCode(account, deviceID, statusCode); // may throw DBException
          DBEdit editor = new DBEdit(sc);
          editor.edit(); // 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 StatusCode: " + accountID + "/" + deviceID + "/" + statusCode);
          dbe.printException();
        }
      }
      System.exit(0);
    }

    /* list */
    if (RTConfig.hasProperty(ARG_LIST)) {
      opts++;
      String listType = RTConfig.getString(ARG_LIST, null);
      // TODO: complete ...
    }

    /* no options specified */
    if (opts == 0) {
      Print.logWarn("Missing options ...");
      usage();
    }
  }
Beispiel #11
0
  public static void main(String args[]) {
    DBConfig.cmdLineInit(args, true); // main
    String acctID = RTConfig.getString(ARG_ACCOUNT, "");
    String roleID = RTConfig.getString(ARG_ROLE, "");
    String aclID = RTConfig.getString(ARG_ACL, "");

    /* account-id specified? */
    if ((acctID == null) || acctID.equals("")) {
      Print.logError("Account-ID not specified.");
      usage();
    }

    /* get account */
    Account acct = null;
    try {
      acct = Account.getAccount(acctID); // may return 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);
    }

    /* role-id specified? */
    if ((roleID == null) || roleID.equals("")) {
      Print.logError("Role-ID not specified.");
      usage();
    }

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

    /* RoleAcl exists? */
    boolean aclExists = false;
    if ((aclID != null) && !aclID.equals("")) {
      try {
        aclExists = RoleAcl.exists(acctID, roleID, aclID);
      } catch (DBException dbe) {
        Print.logError(
            "Error determining if RoleAcl exists: " + acctID + "/" + roleID + "/" + aclID);
        System.exit(99);
      }
    }

    /* option count */
    int opts = 0;

    /* list */
    if (RTConfig.getBoolean(ARG_LIST, false)) {
      opts++;
      try {
        String aclList[] = role.getAclsForRole();
        for (int i = 0; i < aclList.length; i++) {
          AccessLevel level = RoleAcl.getAccessLevel(role, aclList[i], AccessLevel.NONE);
          Print.sysPrintln("  " + aclList[i] + " ==> " + level);
        }
      } catch (DBException dbe) {
        Print.logError("Error getting Acl list: " + dbe);
        System.exit(99);
      }
      System.exit(0);
    }

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

    /* create */
    if (RTConfig.getBoolean(ARG_CREATE, false)) {
      opts++;
      if (aclExists) {
        Print.logWarn("RoleAcl already exists: " + acctID + "/" + roleID + "/" + aclID);
      } else {
        try {
          RoleAcl.createNewRoleAcl(role, aclID);
          Print.logInfo("Created RoleAcl: " + acctID + "/" + roleID + "/" + aclID);
          aclExists = true;
        } catch (DBException dbe) {
          Print.logError("Error creating RoleAcl: " + acctID + "/" + roleID + "/" + aclID);
          dbe.printException();
          System.exit(99);
        }
      }
    }

    /* set */
    if (RTConfig.hasProperty(ARG_SET)) {
      opts++;
      AccessLevel aclLevel = EnumTools.getValueOf(AccessLevel.class, RTConfig.getInt(ARG_SET, -1));
      try {
        RoleAcl.setAccessLevel(role, aclID, aclLevel);
        Print.logInfo(
            "Set RoleAcl '" + acctID + "/" + roleID + "/" + aclID + "' to level " + aclLevel);
      } catch (DBException dbe) {
        Print.logError("Error setting RoleAcl: " + acctID + "/" + roleID + "/" + aclID);
        dbe.printException();
        System.exit(99);
      }
      System.exit(0);
    }

    /* edit */
    if (RTConfig.getBoolean(ARG_EDIT, false)) {
      opts++;
      if (!aclExists) {
        Print.logError("RoleAcl does not exist: " + acctID + "/" + roleID + "/" + aclID);
      } else {
        try {
          RoleAcl roleAcl = RoleAcl.getRoleAcl(role, aclID, false); // may throw DBException
          DBEdit editor = new DBEdit(roleAcl);
          editor.edit(); // 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 RoleAcl: " + acctID + "/" + roleID + "/" + aclID);
          dbe.printException();
        }
      }
      System.exit(0);
    }

    /* no options specified */
    if (opts == 0) {
      Print.logWarn("Missing options ...");
      usage();
    }
  }
Beispiel #12
0
 private static void usage() {
   Print.logInfo("Usage:");
   Print.logInfo("  java ... " + RoleAcl.class.getName() + " {options}");
   Print.logInfo("Common Options:");
   Print.logInfo("  -account=<id>   Acount ID which owns Role");
   Print.logInfo("  -role=<id>      Role ID which owns RoleAcl");
   Print.logInfo("  -list           List Acls for Role");
   Print.logInfo("  -acl=<id>       Role ID to create/edit");
   Print.logInfo("  -set=<val>      RoleAcl value (create if necessary)");
   Print.logInfo("  -create         Create a new RoleAcl");
   Print.logInfo("  -edit           Edit an existing (or newly created) RoleAcl");
   Print.logInfo("  -delete         Delete specified RoleAcl");
   System.exit(1);
 }