Exemplo n.º 1
0
  protected boolean _setDevice(Device device, String ipAddress, int clientPort) {

    /* valid device? */
    if (device == null) {
      return false;
    }

    /* validate ID address */
    DataTransport dataXPort = device.getDataTransport();
    if ((ipAddress != null) && !dataXPort.isValidIPAddress(ipAddress)) {
      Print.logError(
          "Invalid IPAddr: "
              + device.getAccountID()
              + "/"
              + device.getDeviceID()
              + " Found="
              + ipAddress
              + " Expect="
              + dataXPort.getIpAddressValid());
      return false;
    }

    /* update device */
    this.device = device;
    this.dataXPort = dataXPort;
    this.dataXPort.setIpAddressCurrent(ipAddress); // FLD_ipAddressCurrent
    this.dataXPort.setRemotePortCurrent(clientPort); // FLD_remotePortCurrent
    this.dataXPort.setDeviceCode(this.getDeviceCode()); // FLD_deviceCode
    this.device.setLastTotalConnectTime(DateTime.getCurrentTimeSec()); // FLD_lastTotalConnectTime

    /* ok */
    return true;
  }
Exemplo n.º 2
0
 protected String getSmsPhoneNumber(Device device) {
   if (device == null) {
     return null;
   }
   String smsPhone = device.getSimPhoneNumber();
   return smsPhone;
 }
Exemplo n.º 3
0
 protected String getSmsEmailAddress(Device device) {
   if (device == null) {
     return null;
   }
   String toEmail = device.getSmsEmail();
   return toEmail;
 }
Exemplo n.º 4
0
  /* return icon name */
  public static String getIconName(Device device, int statusCode, BasicPrivateLabel pl) {

    /* device code */
    if (device != null) {
      StatusCode code = device.getStatusCode(statusCode);
      if (code != null) {
        return code.getIconName();
      }
    }

    /* default */
    return StatusCodes.GetIconName(statusCode, pl);
  }
Exemplo n.º 5
0
 protected String getStringProperty(Device device, String key, String dft) {
   DCServerConfig dcs =
       (device != null) ? DCServerFactory.getServerConfig(device.getDeviceCode()) : null;
   String prop = null;
   if (dcs != null) {
     prop = dcs.getStringProperty(key, dft);
     Print.logInfo("DCServerConfig property '" + key + "' ==> " + prop);
     if (StringTools.isBlank(prop) && RTConfig.hasProperty(key)) {
       Print.logInfo("(RTConfig property '" + key + "' ==> " + RTConfig.getString(key, "") + ")");
     }
   } else {
     prop = RTConfig.getString(key, dft);
     Print.logInfo("RTConfig property '" + key + "' ==> " + prop);
   }
   return prop;
 }
Exemplo n.º 6
0
 public static DBFactory<StatusCode> getFactory() {
   if (factory == null) {
     factory =
         DBFactory.createDBFactory(
             StatusCode.TABLE_NAME(),
             StatusCode.FieldInfo,
             DBFactory.KeyType.PRIMARY,
             StatusCode.class,
             StatusCode.Key.class,
             true /*editable*/,
             true /*viewable*/);
     factory.addParentTable(Account.TABLE_NAME());
     factory.addParentTable(Device.TABLE_NAME());
     factory.setFieldDefaultValue(FLD_deviceID, ALL_DEVICES);
   }
   return factory;
 }
Exemplo n.º 7
0
  /* Return status code description */
  public static String getDescription(
      Device device, int statusCode, BasicPrivateLabel bpl, String dftDesc) {

    /* device code */
    if (device != null) {
      StatusCode code = device.getStatusCode(statusCode);
      if (code != null) {
        return code.getDescription();
      }
    }

    /* default */
    if (!StringTools.isBlank(dftDesc)) {
      return dftDesc;
    } else {
      return StatusCodes.GetDescription(statusCode, bpl);
    }
  }
Exemplo n.º 8
0
 protected String getFromEmailAddress(Device device) {
   if (device == null) {
     return null;
   }
   return CommandPacketHandler.getFromEmailCommand(device.getAccount());
 }
Exemplo n.º 9
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();
    }
  }