private static OrderedMap<Long, Double[]> _MergeDataSets(boolean F, TemperatureSet TSList[]) { /* merge temperature data sets */ OrderedMap<Long, Double[]> rowMap = new OrderedMap<Long, Double[]>(); if (!ListTools.isEmpty(TSList)) { for (int d = 0; d < TSList.length; d++) { TemperatureSet TS = TSList[d]; if (TS != null) { Collection<Temperature> TList = TS.getTemperatures(); for (Temperature T : TList) { Long ts = new Long(T.getTimestamp()); Double tmp = new Double(T.getTemperature(F)); Double row[] = rowMap.get(ts); if (row == null) { row = new Double[TSList.length]; rowMap.put(ts, row); } row[d] = tmp; } } } } /* sort by timestamp */ rowMap.sortKeys(new ListTools.NumberComparator<Long>()); /* return */ return rowMap; }
private static String CreateGoogleDataTableJSON(boolean F, TemperatureSet... TSList) { /* merge temperature data sets */ OrderedMap<Long, Double[]> rowMap = _MergeDataSets(F, TSList); /* create JSON "cols" Object */ JSON._Array dataTable_cols = new JSON._Array(); // -- DateTime JSON._Object col_dateTime = (new JSON._Object()).setFormatIndent(false); col_dateTime.addKeyValue("id", "date"); col_dateTime.addKeyValue("label", "Date/Time"); col_dateTime.addKeyValue("type", "datetime"); dataTable_cols.addValue(col_dateTime); // -- data set titles if (!ListTools.isEmpty(TSList)) { for (int d = 0; d < TSList.length; d++) { TemperatureSet TS = TSList[d]; JSON._Object col_temp = (new JSON._Object()).setFormatIndent(false); col_temp.addKeyValue("id", "temp" + (d + 1)); col_temp.addKeyValue("label", "Temp-" + (d + 1)); col_temp.addKeyValue("type", "number"); dataTable_cols.addValue(col_temp); } } /* create JSON "rows" Object */ JSON._Array dataTable_rows = new JSON._Array(); for (Long ts : rowMap.keySet()) { JSON._Object col = new JSON._Object(); // TODO } /* return */ return null; // TODO: }
/** ** Constructor */ public TemperatureSet(String title, Collection<Temperature> TList) { this.title = StringTools.trim(title); if (!ListTools.isEmpty(TList)) { for (Temperature T : TList) { this.addTemperature(T); } } }
/** * ** A String reperesentation of this URI (with arguments) ** @param includeBlankValues True to * include keys for blank values. ** @return A String representation of this URI */ public String toString(boolean includeBlankValues) { StringBuffer sb = new StringBuffer(this.getURI()); if (!ListTools.isEmpty(this.getKeyValList())) { sb.append("?"); this.getArgString(sb, includeBlankValues); } return sb.toString(); }
/** * ** A String reperesentation of this URI (with arguments) ** @return A String representation of * this URI */ public String toString() { StringBuffer sb = new StringBuffer(this.getURI()); if (!ListTools.isEmpty(this.getKeyValList())) { sb.append("?"); this.getArgString(sb); } return sb.toString(); }
/* private constructor */ private TrackServer(int tcpPorts[], int udpPorts[], int commandPort) throws Throwable { int listeners = 0; // Start TCP listeners if (!ListTools.isEmpty(tcpPorts)) { for (int i = 0; i < tcpPorts.length; i++) { int port = tcpPorts[i]; if (ServerSocketThread.isValidPort(port)) { try { this._startTCP(port); listeners++; } catch (java.net.BindException be) { Print.logError("TCP: Error binding to port: %d", port); } } else { throw new Exception("TCP: Invalid port number: " + port); } } } // Start UDP listeners if (!ListTools.isEmpty(udpPorts)) { for (int i = 0; i < udpPorts.length; i++) { int port = udpPorts[i]; if (ServerSocketThread.isValidPort(port)) { try { ServerSocketThread sst = this._startUDP(port); if (this.udpSocket == null) { this.udpSocket = sst.getDatagramSocket(); } listeners++; } catch (java.net.BindException be) { Print.logError("UDP: Error binding to port: %d", port); } } else { throw new Exception("UDP: Invalid port number: " + port); } } } /* do we have any active listeners? */ if (listeners <= 0) { Print.logWarn("No active device communication listeners!"); } }
/** * ** Returns true if the specified key is not to be included in the 'defined propertes' section * ** @param key The property key to test ** @return true to omit the specified property from the * 'defined properties' section */ protected boolean _skipPropKey(Object key) { String ks = key.toString(); for (int i = 0; i < SKIP_PROPS.length; i++) { String propKey[] = (String[]) SKIP_PROPS[i]; if (ListTools.contains(propKey, ks)) { return true; } } return false; }
@SuppressWarnings("unchecked") public void _addRandomSampleData(int setCount, int tempCount) throws Exception { long sts = this.minDateTS; long ets = this.maxDateTS; Random ran = new Random(sts); /* init datasets */ if (setCount <= 0) { setCount = 1; } java.util.List<Data> dataSet[] = new java.util.List[setCount]; for (int d = 0; d < dataSet.length; d++) { dataSet[d] = new Vector<Data>(); } /* populate random temperature data */ double rangeC = this.maxTempC - this.minTempC; long deltaSize = (ets - sts) / (long) tempCount; long deltaRangeTS = DateTime.HourSeconds(3); long ts = sts + (deltaSize / 2L); double Cs = (ran.nextDouble() * rangeC * 0.10) + (rangeC * 0.05); for (int t = 0; t < tempCount; t++) { double C[] = new double[dataSet.length]; for (int d = 0; d < dataSet.length; d++) { C[d] = (ran.nextDouble() * 7.0) + ((d == 0) ? Cs : C[d - 1]) - 2.5; if (C[d] < this.minTempC) { C[d] = this.minTempC; } if (C[d] > this.maxTempC) { C[d] = this.maxTempC; } dataSet[d].add(new Data(ts, C[d])); } ts = sts + ((long) (t + 1) * deltaSize) + (long) ran.nextInt((int) deltaRangeTS) + (deltaRangeTS / 2L); if (ts > ets) { ts = ets - 1L; } // ts = sts + ((t==0)?DateTime.HourSeconds(1):(long)ran.nextInt((int)(ets - sts))); Cs = C[0]; } /* add datasets */ for (int d = 0; d < dataSet.length; d++) { ListTools.sort(dataSet[d], null); Color color = TEMP_COLOR[d % TEMP_COLOR.length]; this.addDataSet(color, "Temp " + (d + 1), dataSet[d].toArray(new Data[dataSet[d].size()])); } }
public static String GetPropertyString_OBDII(long dtcFault[]) { if (ListTools.isEmpty(dtcFault)) { return GetPropertyString_OBDII(""); } else { java.util.List<String> dtc = new Vector<String>(); for (int i = 0; i < dtcFault.length; i++) { if (dtcFault[i] != 0L) { dtc.add(GetFaultString(dtcFault[i])); } } return GetPropertyString_OBDII(dtc); } }
/** * ** Returns a new URIArg with this URIArg's arguments encoded into a ** single RTProperties * added with a specified key [CHECK] ** @param rtpKey The key to add the encoded args at * ** @param exclKeys keys to exclude from encoding ** @return A new URIArg with non excluded * arguments encoded */ public URIArg rtpEncode(String rtpKey, String... exclKeys) { URIArg rtpUrl = new URIArg(this.getURI()); RTProperties rtp = new RTProperties(); for (KeyVal kv : this.getKeyValList()) { String kn = kv.getKey(); if (ListTools.contains(exclKeys, kn)) { rtpUrl.addArg(kv); } else { rtp.setString(kn, kv.getValue()); } } rtpUrl.addArg(rtpKey, rtp); return rtpUrl; }
/** * ** Sets the specified argument key to the specified String value. ** @param key The key of the * agrument ** @param value The value to set ** @param obfuscate True if the value should be * obfuscated ** @return True if the argument existed, else false */ public boolean setArgValue(String key[], String value, boolean obfuscate) { if (ListTools.size(key) >= 1) { boolean hadArg = this.hasArg(key); // remove all but the first key for (int i = 1; i < key.length; i++) { this.removeArg(key[i]); } // set the first key this.setArgValue(key[0], value, obfuscate); return hadArg; } else { return false; } }
/** * ** Returns true if this key fully defines all key fields ** @return True if this key fully * defines all key fields */ public boolean isFullKey() { DBField kfld[] = this.getKeyFields(); if (ListTools.isEmpty(kfld)) { return false; } else { DBFieldValues fldVals = this.getFieldValues(); // hasPartialKey for (int i = 0; i < kfld.length; i++) { String fldName = kfld[i].getName(); if (!fldVals.hasFieldValue(fldName)) { return false; } } return true; } }
public static String GetPropertyString_OBDII(java.util.List<String> dtc) { String dtcStr = !ListTools.isEmpty(dtc) ? StringTools.join(dtc, ",") : ""; return GetPropertyString_OBDII(dtcStr); }
/** ** Get size of TemperatureSet */ public int getSize() { return ListTools.size(this.tempList); }
/** * ** Returns true if any tagged field names have been defined ** @return True if any tagged field * names have been defined */ public boolean hasTaggedFields() { return !ListTools.isEmpty(this.taggedFields); }
/* write mapping support JS to stream */ protected void writeJSVariables(PrintWriter out, RequestProperties reqState) throws IOException { // This var initilizations must not use any functions defined in 'jsmap.js' PrivateLabel privLabel = reqState.getPrivateLabel(); I18N i18n = privLabel.getI18N(JSMap.class); Locale locale = reqState.getLocale(); GeoPoint dftCenter = this.getDefaultCenter(null); boolean isFleet = reqState.isFleet(); Account account = reqState.getCurrentAccount(); long maxPushpins = this.getMaxPushpins(reqState); out.write("// --- Map support Javascript [" + this.getName() + "]\n"); JavaScriptTools.writeJSVar(out, "MAP_PROVIDER_NAME", this.getName()); /* properties */ boolean wrotePropHeader = false; RTProperties rtp = this.getProperties(); for (Iterator<?> i = rtp.keyIterator(); i.hasNext(); ) { Object key = i.next(); if (!this._skipPropKey(key)) { if (!wrotePropHeader) { // out.write("\n"); out.write("// Defined properties\n"); wrotePropHeader = true; } String val[] = StringTools.parseStringArray(rtp.getProperty(key, "").toString(), '\n'); String propVar = "PROP_" + key.toString().replace('.', '_').replace('-', '_'); if (val.length == 1) { if (StringTools.isDouble(val[0], true) || StringTools.isLong(val[0], true) || StringTools.isBoolean(val[0], true)) { JavaScriptTools.writeJSVar(out, propVar, val[0], false); } else { JavaScriptTools.writeJSVar(out, propVar, val[0]); } } else if (val.length > 1) { JavaScriptTools.writeJSVar(out, propVar, StringTools.join(val, "\\n")); } } } /* speed units */ Account.SpeedUnits speedUnits = reqState.getSpeedUnits(); boolean speedIsKph = speedUnits.equals(Account.SpeedUnits.KPH); double altUnitsMult = speedIsKph ? 1.0 : GeoPoint.FEET_PER_METER; String altUnitsName = speedIsKph ? i18n.getString("JSMap.altitude.meters", "Meters") : i18n.getString("JSMap.altitude.feet", "Feet"); /* constants (these do not change during the user session) */ out.write("// Element IDs\n"); JavaScriptTools.writeJSVar(out, "MAP_ID", this.getMapID()); JavaScriptTools.writeJSVar(out, "ID_DETAIL_TABLE", ID_DETAIL_TABLE); JavaScriptTools.writeJSVar(out, "ID_DETAIL_CONTROL", ID_DETAIL_CONTROL); JavaScriptTools.writeJSVar(out, "ID_LAT_LON_DISPLAY", ID_LAT_LON_DISPLAY); JavaScriptTools.writeJSVar(out, "ID_DISTANCE_DISPLAY", ID_DISTANCE_DISPLAY); JavaScriptTools.writeJSVar(out, "ID_LATEST_EVENT_DATE", ID_LATEST_EVENT_DATE); JavaScriptTools.writeJSVar(out, "ID_LATEST_EVENT_TIME", ID_LATEST_EVENT_TIME); JavaScriptTools.writeJSVar(out, "ID_LATEST_EVENT_TMZ", ID_LATEST_EVENT_TMZ); JavaScriptTools.writeJSVar(out, "ID_LATEST_BATTERY", ID_LATEST_BATTERY); JavaScriptTools.writeJSVar(out, "ID_MESSAGE_TEXT", ID_MESSAGE_TEXT); out.write("// Geozone IDs\n"); JavaScriptTools.writeJSVar(out, "ID_ZONE_LATITUDE_", ID_ZONE_LATITUDE_); JavaScriptTools.writeJSVar(out, "ID_ZONE_LONGITUDE_", ID_ZONE_LONGITUDE_); JavaScriptTools.writeJSVar(out, "ID_ZONE_RADIUS_M", ID_ZONE_RADIUS_M); out.write("// Session constants\n"); JavaScriptTools.writeJSVar(out, "PUSHPINS_SHOW", rtp.getBoolean(PROP_map_pushpins, true)); JavaScriptTools.writeJSVar(out, "MAX_PUSH_PINS", maxPushpins); JavaScriptTools.writeJSVar(out, "MAX_CREATION_AGE_SEC", rtp.getInt(PROP_map_maxCreationAge, 0)); JavaScriptTools.writeJSVar(out, "MAP_WIDTH", this.getDimension().getWidth()); JavaScriptTools.writeJSVar(out, "MAP_HEIGHT", this.getDimension().getHeight()); JavaScriptTools.writeJSVar(out, "IS_FLEET", isFleet); JavaScriptTools.writeJSVar( out, "SHOW_SAT_COUNT", rtp.getBoolean(PROP_detail_showSatCount, false)); JavaScriptTools.writeJSVar(out, "SHOW_SPEED", rtp.getBoolean(PROP_info_showSpeed, true)); JavaScriptTools.writeJSVar( out, "COMBINE_SPEED_HEAD", rtp.getBoolean(PROP_combineSpeedHeading, true)); JavaScriptTools.writeJSVar(out, "SHOW_ALTITUDE", rtp.getBoolean(PROP_info_showAltitude, false)); JavaScriptTools.writeJSVar(out, "SHOW_ADDR", reqState.getShowAddress()); JavaScriptTools.writeJSVar( out, "INCL_BLANK_ADDR", rtp.getBoolean(PROP_info_inclBlankAddress, true)); JavaScriptTools.writeJSVar( out, "SHOW_OPT_FIELDS", rtp.getBoolean(PROP_info_showOptionalFields, true)); JavaScriptTools.writeJSVar( out, "INCL_BLANK_OPT_FIELDS", rtp.getBoolean(PROP_info_inclBlankOptFields, true)); JavaScriptTools.writeJSVar( out, "LATLON_FORMAT", Account.getLatLonFormat(account).getIntValue()); JavaScriptTools.writeJSVar( out, "DISTANCE_KM_MULT", reqState.getDistanceUnits().getMultiplier()); JavaScriptTools.writeJSVar(out, "SPEED_KPH_MULT", speedUnits.getMultiplier()); JavaScriptTools.writeJSVar(out, "SPEED_UNITS", speedUnits.toString(locale)); JavaScriptTools.writeJSVar(out, "ALTITUDE_METERS_MULT", altUnitsMult); JavaScriptTools.writeJSVar(out, "ALTITUDE_UNITS", altUnitsName); JavaScriptTools.writeJSVar(out, "TIME_ZONE", reqState.getTimeZoneString(null)); // long JavaScriptTools.writeJSVar( out, "DEFAULT_CENTER", "{ lat:" + dftCenter.getLatitude() + ", lon:" + dftCenter.getLongitude() + " }", false); JavaScriptTools.writeJSVar(out, "DEFAULT_ZOOM", this.getDefaultZoom(JSMap.DEFAULT_ZOOM, false)); JavaScriptTools.writeJSVar(out, "PUSHPIN_ZOOM", this.getDefaultZoom(JSMap.PUSHPIN_ZOOM, true)); JavaScriptTools.writeJSVar(out, "MAP_AUTHORIZATION", this.getAuthorization()); JavaScriptTools.writeJSVar( out, "SCROLL_WHEEL_ZOOM", rtp.getBoolean(PROP_scrollWheelZoom, false)); JavaScriptTools.writeJSVar(out, "DEFAULT_VIEW", rtp.getString(PROP_map_view, "").toLowerCase()); JavaScriptTools.writeJSVar(out, "ROUTE_LINE_SHOW", rtp.getBoolean(PROP_map_routeLine, true)); JavaScriptTools.writeJSVar( out, "ROUTE_LINE_COLOR", rtp.getString(PROP_map_routeLine_color, "#FF2222")); JavaScriptTools.writeJSVar( out, "ROUTE_LINE_ARROWS", rtp.getBoolean(PROP_map_routeLine_arrows, false)); JavaScriptTools.writeJSVar( out, "ROUTE_SNAP_TO_ROAD", rtp.getBoolean(PROP_map_routeLine_snapToRoad, false)); // Google V2 only JavaScriptTools.writeJSVar(out, "REPLAY_INTERVAL", this.getReplayInterval()); JavaScriptTools.writeJSVar(out, "REPLAY_SINGLE", this.getReplaySinglePushpin()); /* address title */ String adrTitles[] = reqState.getAddressTitles(); String adrTitle = ListTools.itemAt(adrTitles, 0, null); /* device title */ String devTitles[] = reqState.getDeviceTitles(); String devTitle = ListTools.itemAt(devTitles, 0, null); /* labels */ out.write("// Localized Text/Labels\n"); JavaScriptTools.writeJSVar( out, "HEADING", "new Array(" + "\"" + GeoPoint.CompassHeading.N.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.NE.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.E.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.SE.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.S.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.SW.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.W.toString(locale) + "\"," + "\"" + GeoPoint.CompassHeading.NW.toString(locale) + "\")", false); JavaScriptTools.writeJSVar(out, "TEXT_INFO_DATE", i18n.getString("JSMap.info.date", "Date")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_GPS", i18n.getString("JSMap.info.gps", "GPS")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_SATS", i18n.getString("JSMap.info.sats", "#Sats")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_SPEED", i18n.getString("JSMap.info.speed", "Speed")); JavaScriptTools.writeJSVar(out, "TEXT_INFO_HEADING", GeoPoint.GetHeadingTitle(locale)); JavaScriptTools.writeJSVar( out, "TEXT_INFO_ALTITUDE", i18n.getString("JSMap.info.altitude", "Altitude")); JavaScriptTools.writeJSVar( out, "TEXT_INFO_STOP_TIME", i18n.getString("JSMap.info.stopTime", "Stop Time")); JavaScriptTools.writeJSVar( out, "TEXT_INFO_ADDR", !StringTools.isBlank(adrTitle) ? adrTitle : i18n.getString("JSMap.info.address", "Address")); JavaScriptTools.writeJSVar( out, "TEXT_DEVICE", !StringTools.isBlank(devTitle) ? devTitle : i18n.getString("JSMap.device", "Device")); JavaScriptTools.writeJSVar(out, "TEXT_DATE", i18n.getString("JSMap.dateTime", "Date/Time")); JavaScriptTools.writeJSVar(out, "TEXT_CODE", i18n.getString("JSMap.code", "Status")); JavaScriptTools.writeJSVar(out, "TEXT_LATLON", i18n.getString("JSMap.latLon", "Lat/Lon")); JavaScriptTools.writeJSVar(out, "TEXT_SATCOUNT", i18n.getString("JSMap.satCount", "#Sats")); JavaScriptTools.writeJSVar( out, "TEXT_ADDR", !StringTools.isBlank(adrTitle) ? adrTitle : i18n.getString("JSMap.address", "Address")); JavaScriptTools.writeJSVar(out, "TEXT_SPEED", reqState.getSpeedUnits().toString(locale)); JavaScriptTools.writeJSVar(out, "TEXT_HEADING", i18n.getString("JSMap.heading", "Heading")); JavaScriptTools.writeJSVar(out, "TEXT_DISTANCE", reqState.getDistanceUnits().toString(locale)); JavaScriptTools.writeJSVar( out, "TEXT_TIMEOUT", i18n.getString("JSMap.sessionTimeout", "Your session has timed-out.\nPlease login ...")); JavaScriptTools.writeJSVar( out, "TEXT_PING_OK", i18n.getString( "JSMap.pingDevice.ok", "A command request has been sent.\nThe {0} should respond shortly ...", devTitles)); JavaScriptTools.writeJSVar( out, "TEXT_PING_ERROR", i18n.getString( "JSMap.pingDevice.err", "The command request failed.\nThe {0} may not support this feature ...", devTitles)); JavaScriptTools.writeJSVar( out, "TEXT_MAXPUSHPINS_ALERT", i18n.getString( "JSMap.maxPushpins.err", "The maximum number of allowed pushpins has been exceeded.\n" + " [max={0}] Not all pushpins may be displayed on this map.\n" + "Adjust the 'From' time to see remaining pushpins", String.valueOf(maxPushpins))); JavaScriptTools.writeJSVar( out, "TEXT_MAXPUSHPINS_MSG", i18n.getString( "JSMap.maxPushpins.msg", "Only partial data displayed. The maximum allowed pushpins has been reached.<BR>" + "Adjust the Date/Time range accordingly to view the remaining pushpins.")); JavaScriptTools.writeJSVar( out, "TEXT_UNAVAILABLE", i18n.getString("JSMap.unavailable", "unavailable")); JavaScriptTools.writeJSVar( out, "TEXT_showLocationDetails", i18n.getString("JSMap.showLocationDetails", "Show Location Details")); JavaScriptTools.writeJSVar( out, "TEXT_hideLocationDetails", i18n.getString("JSMap.hideLocationDetails", "Hide Location Details")); /* map "Loading ..." */ JavaScriptTools.writeJSVar( out, "TEXT_LOADING_MAP_POINTS", (rtp.getBoolean(PROP_MAP_LOADING, false) ? i18n.getString("JSMap.loadingMapPoints", "Loading Map Points ...") : null)); JavaScriptTools.writeJSVar( out, "MAP_LOADING_IMAGE_URI", rtp.getString(PROP_MAP_LOADING_IMAGE, null)); /* icons/shadows */ JSMap.writePushpinArray(out, reqState); /* constants (these do not change during the user session) */ out.write("// Geozone support constants\n"); JavaScriptTools.writeJSVar(out, "jsvGeozoneMode", false); JavaScriptTools.writeJSVar(out, "MAX_ZONE_RADIUS_M", Geozone.MAX_RADIUS_METERS); JavaScriptTools.writeJSVar(out, "MIN_ZONE_RADIUS_M", Geozone.MIN_RADIUS_METERS); JavaScriptTools.writeJSVar( out, "DETAIL_REPORT", this.isFeatureSupported(FEATURE_DETAIL_REPORT)); JavaScriptTools.writeJSVar( out, "DETAIL_INFO_BOX", this.isFeatureSupported(FEATURE_DETAIL_INFO_BOX)); JavaScriptTools.writeJSVar(out, "TEXT_METERS", GeoPoint.DistanceUnits.METERS.toString(locale)); /* variables */ out.write("// TrackMap Vars\n"); JavaScriptTools.writeJSVar(out, "jsvPoiPins", null); JavaScriptTools.writeJSVar(out, "jsvDataSets", null); JavaScriptTools.writeJSVar(out, "jsvDetailPoints", null); JavaScriptTools.writeJSVar(out, "jsvDetailVisible", false); JavaScriptTools.writeJSVar( out, "jsvDetailAscending", privLabel.getBooleanProperty(PrivateLabel.PROP_TrackMap_detailAscending, true)); JavaScriptTools.writeJSVar( out, "jsvDetailCenterPushpin", privLabel.getBooleanProperty(PrivateLabel.PROP_TrackMap_detailCenterPushpin, false)); /* last update time */ TimeZone tmz = reqState.getTimeZone(); String dateFmt = (account != null) ? account.getDateFormat() : BasicPrivateLabel.getDefaultDateFormat(); String timeFmt = (account != null) ? account.getTimeFormat() : BasicPrivateLabel.getDefaultTimeFormat(); DateTime today = new DateTime(tmz); JavaScriptTools.writeJSVar(out, "jsvTodayEpoch", today.getTimeSec()); JavaScriptTools.writeJSVar( out, "jsvTodayYMD", "{ YYYY:" + today.getYear(tmz) + ", MM:" + today.getMonth1(tmz) + ", DD:" + today.getDayOfMonth(tmz) + " }", false); JavaScriptTools.writeJSVar(out, "jsvTodayDateFmt", today.format(dateFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvTodayTimeFmt", today.format(timeFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvTodayTmzFmt", today.format("z", tmz)); /* last event time */ out.write("// Last event time\n"); DateTime lastEventTime = reqState.getLastEventTime(); if (lastEventTime != null) { JavaScriptTools.writeJSVar(out, "jsvLastEventEpoch", lastEventTime.getTimeSec()); JavaScriptTools.writeJSVar( out, "jsvLastEventYMD", "{ YYYY:" + lastEventTime.getYear(tmz) + ", MM:" + lastEventTime.getMonth1(tmz) + ", DD:" + lastEventTime.getDayOfMonth(tmz) + " }", false); JavaScriptTools.writeJSVar(out, "jsvLastEventDateFmt", lastEventTime.format(dateFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvLastEventTimeFmt", lastEventTime.format(timeFmt, tmz)); JavaScriptTools.writeJSVar(out, "jsvLastEventTmzFmt", lastEventTime.format("z", tmz)); JavaScriptTools.writeJSVar(out, "jsvLastBatteryLevel", 0L); JavaScriptTools.writeJSVar(out, "jsvLastSignalStrength", 0L); } else { JavaScriptTools.writeJSVar(out, "jsvLastEventEpoch", 0L); JavaScriptTools.writeJSVar(out, "jsvLastEventYMD", null); JavaScriptTools.writeJSVar(out, "jsvLastEventDateFmt", null); JavaScriptTools.writeJSVar(out, "jsvLastEventTimeFmt", null); JavaScriptTools.writeJSVar(out, "jsvLastEventTmzFmt", null); JavaScriptTools.writeJSVar(out, "jsvLastBatteryLevel", 0.0); JavaScriptTools.writeJSVar(out, "jsvLastSignalStrength", 0.0); } /* map pointers */ out.write("// Map vars\n"); JavaScriptTools.writeJSVar(out, "jsmapElem", null); JavaScriptTools.writeJSVar(out, "jsmap", null); }
public static String GetPropertyString_OBDII(String dtc[]) { String dtcStr = !ListTools.isEmpty(dtc) ? StringTools.join(dtc, ",") : ""; return GetPropertyString_OBDII(dtcStr); }
/** * ** Return the 'WHERE' clause for this key [CHECK] ** @param altIndexName The alternate index * name. If null or blank, uses ** primary keys instead ** @param whereKeyType The where key type. * One of the constants from DBWhere ** @return The 'WHERE' clause for this key */ protected String _getWhereClause( String altIndexName, int whereKeyType) // boolean fullKeyRequired) throws DBException { /* key fields */ boolean usePrimaryKey = StringTools.isBlank(altIndexName); DBField keyFlds[] = usePrimaryKey ? this.getKeyFields() : this.getAltKeyFields(altIndexName); if (ListTools.isEmpty(keyFlds)) { throw new DBException("No keys found!"); } /* WHERE */ DBWhere dwh = new DBWhere(this.getFactory()); DBFieldValues fldVals = this.getFieldValues(); int keyCnt = 0; boolean hasPartialKey = false; for (int i = 0; i < keyFlds.length; i++) { String fldName = keyFlds[i].getName(); if (fldVals.hasFieldValue(fldName)) { if (!hasPartialKey || (whereKeyType == DBWhere.KEY_PARTIAL_ALL)) { String fev = dwh.EQ(fldName, fldVals.getFieldValueAsString(fldName)); if (keyCnt > 0) { dwh.append(dwh.AND_(fev)); } else { dwh.append(fev); } keyCnt++; } else { // whereKeyType == DBWhere.KEY_PARTIAL_FIRST, and we found a subsequent key String m = "Additional partial key in 'WHERE' clause! [" + this.getTableName() + "." + fldName + "]"; // throw new DBException(m); // TODO: Print.logWarn("******************************************************************"); Print.logWarn(m); // Print.logWarn(StringTools.join(keyFlds,",")); // Print.logStackTrace(m); Print.logWarn("******************************************************************"); } } else if ((i == 0) && (whereKeyType != DBWhere.KEY_PARTIAL_ALL_EMPTY)) { // // missing first key if (keyFlds[i].isAutoIncrement()) { // first key is an "auto_increment" and it is not present // assume that we are expecting the DB server to create this value for us, thus the key // dow not exist // However, there is nothing we can do about this here. String m = "First key field for 'WHERE' clause is 'auto_increment' and field is not present [" + this.getTableName() + "." + fldName + "]"; throw new DBException(m); } else { String m = "Missing first key field for 'WHERE' clause! [" + this.getTableName() + "." + fldName + "]"; throw new DBException(m); } } else if (whereKeyType == DBWhere.KEY_FULL) { // missing a key when all keys are required String m = "Missing key for 'WHERE' clause! [" + this.getTableName() + "." + fldName + "]"; throw new DBException(m); } else { // only a portion of the key has been specified. // This is a common occurance deleting an Account/Device with sub-dependencies // Print.logWarn("Key field not specified: " + this.getTableName() + "." + fldName); hasPartialKey = true; } } return (keyCnt > 1) ? dwh.WHERE(dwh.toString()) : dwh.WHERE_(dwh.toString()); }
/** * ** Returns true if the specified key attribute exists in the table ** @param altIndexName The * alternate index name, or null to use the primary index ** @param whereKeyType The partial key * match type ** @return True if the specified key attribute exists in the table, false otherwise */ protected boolean _exists(String altIndexName, int whereKeyType) throws SQLException, DBException { /* key fields */ boolean usePrimaryKey = StringTools.isBlank(altIndexName); DBField kfld[] = usePrimaryKey ? this.getKeyFields() : this.getAltKeyFields(altIndexName); if (ListTools.isEmpty(kfld)) { throw new DBException("No keys found!"); } /* check last key for "auto_increment" */ if (whereKeyType == DBWhere.KEY_FULL) { DBField lastField = kfld[kfld.length - 1]; if (lastField.isAutoIncrement() && !this.getFieldValues().hasFieldValue(lastField.getName())) { // full key requested and last key is auto_increment, which is missing return false; } } // DBSelect: SELECT <Keys> FROM <TableName> <KeyWhere> String firstKey = kfld[0].getName(); DBSelect<gDBR> dsel = new DBSelect<gDBR>(this.getFactory()); dsel.setSelectedFields(firstKey); dsel.setWhere(this._getWhereClause(altIndexName, whereKeyType)); /* get keyed record */ DBConnection dbc = null; Statement stmt = null; ResultSet rs = null; boolean exists = false; try { dbc = DBConnection.getDefaultConnection(); stmt = dbc.execute(dsel.toString()); // may throw DBException rs = stmt.getResultSet(); exists = rs.next(); } catch (SQLException sqe) { if (sqe.getErrorCode() == DBFactory.SQLERR_TABLE_NOTLOCKED) { // MySQL: This case has been seen on rare occasions. Not sure what causes it. Print.logError("SQL Lock Error: " + sqe); Print.logError("Hackery! Forcing lock on table: " + this.getTableName()); if (DBProvider.lockTableForRead(this.getTableName(), true)) { // may throw DBException stmt = dbc.execute(dsel.toString()); // may throw SQLException, DBException rs = stmt.getResultSet(); // SQLException exists = rs.next(); // SQLException DBProvider.unlockTables(); // DBException } } else { throw sqe; } } finally { if (rs != null) { try { rs.close(); } catch (Throwable t) { } } if (stmt != null) { try { stmt.close(); } catch (Throwable t) { } } DBConnection.release(dbc); } return exists; }