List of usage examples for org.joda.time.format ISODateTimeFormat dateTime
public static DateTimeFormatter dateTime()
From source file:org.trakhound.www.trakhound.device_details.DeviceStatus.java
License:Open Source License
public static DeviceStatus get(UserConfiguration userConfig, String uniqueId) { if (userConfig != null) { DateTime now = DateTime.now();/*from w ww . java 2 s .co m*/ DateTime from = new DateTime(now.year().get(), now.monthOfYear().get(), now.dayOfMonth().get(), 0, 0, 0); DateTime to = from.plusDays(1); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); String fromStr = fmt.print(from); String toStr = fmt.print(to); String urlSuffix = "data/get/?" + "token=" + userConfig.sessionToken + "&sender_id=" + UserManagement.getSenderId() + "&devices=[{\"unique_id\":\"" + uniqueId + "\"}]" + "&from=" + fromStr + "&to=" + toStr + "&command=" + "01111"; // Get Status, Controller, Oee, and Timers tables String url = Uri.withAppendedPath(ApiConfiguration.apiHost, urlSuffix).toString(); String response = Requests.get(url); if (response != null && response.length() > 0) { try { JSONArray a = new JSONArray(response); if (a.length() > 0) { JSONObject obj = a.getJSONObject(0); DeviceStatus deviceStatus = new DeviceStatus(); deviceStatus.uniqueId = obj.getString("unique_id"); deviceStatus.statusInfo = StatusInfo.parse(obj.getJSONObject("status")); deviceStatus.controllerInfo = ControllerInfo.parse(obj.getJSONObject("controller")); deviceStatus.oeeInfo = OeeInfo.parse(obj.getJSONObject("oee")); deviceStatus.timersInfo = TimersInfo.parse(obj.getJSONObject("timers")); return deviceStatus; } } catch (JSONException ex) { Log.d("Exception", ex.getMessage()); } } } return null; }
From source file:org.trakhound.www.trakhound.device_list.DeviceStatus.java
License:Open Source License
public static DeviceStatus[] get(UserConfiguration userConfig) { if (userConfig != null) { try {//from www. ja va 2s . co m DateTime now = DateTime.now(); DateTime from = new DateTime(now.year().get(), now.monthOfYear().get(), now.dayOfMonth().get(), 0, 0, 0); DateTime to = from.plusDays(1); DateTimeFormatter fmt = ISODateTimeFormat.dateTime(); String fromStr = fmt.print(from); String toStr = fmt.print(to); String urlSuffix = "data/get/?" + "token=" + URLEncoder.encode(userConfig.sessionToken, "UTF-8") + "&sender_id=" + URLEncoder.encode(UserManagement.getSenderId(), "UTF-8") + "&from=" + fromStr + "&to=" + toStr + "&command=0101"; // Get Status and Oee tables String url = Uri.withAppendedPath(ApiConfiguration.apiHost, urlSuffix).toString(); String response = Requests.get(url); if (response != null && response.length() > 0) { ArrayList<DeviceStatus> devicesStatuses = new ArrayList<>(); try { JSONArray a = new JSONArray(response); for (int i = 0; i < a.length(); i++) { JSONObject obj = a.getJSONObject(i); DeviceStatus deviceStatus = new DeviceStatus(); deviceStatus.uniqueId = obj.getString("unique_id"); deviceStatus.statusInfo = StatusInfo.parse(obj.getJSONObject("status")); deviceStatus.oeeInfo = OeeInfo.parse(obj.getJSONObject("oee")); devicesStatuses.add(deviceStatus); } } catch (JSONException ex) { Log.d("Exception", ex.getMessage()); } DeviceStatus[] deviceStatusArray = new DeviceStatus[devicesStatuses.size()]; return devicesStatuses.toArray(deviceStatusArray); } } catch (UnsupportedEncodingException ex) { Log.d("Exception", ex.getMessage()); } } return null; }
From source file:org.ttn.android.sdk.api.converter.GatewayConverter.java
License:Apache License
@Override public Object fromJson(JSONObject jsonObj) throws JSONException { Gateway.Builder builder = new Gateway.Builder(); if (jsonObj.has(JSON_KEY_EUI)) { builder.setNodeEui(jsonObj.getString(JSON_KEY_EUI)); }// w w w . j a v a2s . c om if (jsonObj.has(JSON_KEY_LATITUDE)) { builder.setLatitude(jsonObj.getDouble(JSON_KEY_LATITUDE)); } if (jsonObj.has(JSON_KEY_LONGITUDE)) { builder.setLongitude(jsonObj.getDouble(JSON_KEY_LONGITUDE)); } if (jsonObj.has(JSON_KEY_ALTITUDE)) { builder.setAltitude(jsonObj.getDouble(JSON_KEY_ALTITUDE)); } if (jsonObj.has(JSON_KEY_TIME)) { String dateStr = jsonObj.getString(JSON_KEY_TIME); DateTime time = ISODateTimeFormat.dateTime().parseDateTime(dateStr); builder.setLastSeen(time); } if (jsonObj.has(JSON_KEY_STATUS_PACKET_COUNT)) { builder.setStatusPacketcount(jsonObj.getInt(JSON_KEY_STATUS_PACKET_COUNT)); } return builder.build(); }
From source file:org.ttn.android.sdk.api.converter.GatewayStatusConverter.java
License:Apache License
@Override public Object fromJson(JSONObject jsonObj) throws JSONException { GatewayStatus.Builder builder = new GatewayStatus.Builder(); if (jsonObj.has(JSON_KEY_ACK_RATIO)) { builder.setAckRatio(jsonObj.getDouble(JSON_KEY_ACK_RATIO)); }// ww w . jav a 2 s . co m if (jsonObj.has(JSON_KEY_RX_FORWARDED)) { builder.setRxForwarded(jsonObj.getInt(JSON_KEY_RX_FORWARDED)); } if (jsonObj.has(JSON_KEY_DATAGRAMS_SENT)) { builder.setDatagramSent(jsonObj.getInt(JSON_KEY_DATAGRAMS_SENT)); } if (jsonObj.has(JSON_KEY_DATAGRAMS_RECEIVED)) { builder.setDatagramReceived(jsonObj.getInt(JSON_KEY_DATAGRAMS_RECEIVED)); } if (jsonObj.has(JSON_KEY_RX_COUNT)) { builder.setRxCount(jsonObj.getInt(JSON_KEY_RX_COUNT)); } if (jsonObj.has(JSON_KEY_RX_OK)) { builder.setRxOk(jsonObj.getInt(JSON_KEY_RX_OK)); } if (jsonObj.has(JSON_KEY_EUI)) { builder.setNodeEui(jsonObj.getString(JSON_KEY_EUI)); } if (jsonObj.has(JSON_KEY_LATITUDE)) { builder.setLatitude(jsonObj.getDouble(JSON_KEY_LATITUDE)); } if (jsonObj.has(JSON_KEY_LONGITUDE)) { builder.setLongitude(jsonObj.getDouble(JSON_KEY_LONGITUDE)); } if (jsonObj.has(JSON_KEY_ALTITUDE)) { builder.setAltitude(jsonObj.getDouble(JSON_KEY_ALTITUDE)); } if (jsonObj.has(JSON_KEY_TIME)) { String dateStr = jsonObj.getString(JSON_KEY_TIME); DateTime time = ISODateTimeFormat.dateTime().parseDateTime(dateStr); builder.setLastSeen(time); } return builder.build(); }
From source file:org.ttn.android.sdk.api.converter.MqttPacketConverter.java
License:Apache License
@Override public Object fromJson(JSONObject jsonObj) throws JSONException { Packet.Builder builder = new Packet.Builder(); if (jsonObj.has(JSON_KEY_DATA)) { builder.setData(jsonObj.getString(JSON_KEY_DATA)); }/*from w w w . j ava 2 s. c om*/ if (jsonObj.has(JSON_KEY_DATA_RAW)) { builder.setDataRaw(JSON_KEY_DATA_RAW); } if (jsonObj.has(JSON_KEY_DATA_RATE)) { builder.setDataRate(jsonObj.getString(JSON_KEY_DATA_RATE)); } if (jsonObj.has(JSON_KEY_FREQUENCY)) { builder.setFrequency(jsonObj.getDouble(JSON_KEY_FREQUENCY)); } if (jsonObj.has(JSON_KEY_RSSI)) { builder.setRSSI(jsonObj.getInt(JSON_KEY_RSSI)); } if (jsonObj.has(JSON_KEY_SNR)) { builder.setSNR(jsonObj.getDouble(JSON_KEY_SNR)); } if (jsonObj.has(JSON_KEY_GATEWAY_EUI)) { builder.setGatewayEui(jsonObj.getString(JSON_KEY_GATEWAY_EUI)); } if (jsonObj.has(JSON_KEY_NODE_EUI)) { builder.setNodeEui(jsonObj.getString(JSON_KEY_NODE_EUI)); } if (jsonObj.has(JSON_KEY_TIME)) { String dateStr = jsonObj.getString(JSON_KEY_TIME); DateTime time = null; try { time = ISODateTimeFormat.dateTime().parseDateTime(dateStr); } catch (IllegalArgumentException e1) { // maybe we need to add a Z at the end? Someone might be sending wrong dates try { time = ISODateTimeFormat.dateTime().parseDateTime(dateStr + "Z"); } catch (IllegalArgumentException e2) { // pity, nothing to do } } if (time != null) { builder.setTime(time); } } return builder.build(); }
From source file:org.ttn.android.sdk.api.converter.NodeConverter.java
License:Apache License
@Override public Object fromJson(JSONObject jsonObj) throws JSONException { Node.Builder builder = new Node.Builder(); if (jsonObj.has(JSON_KEY_LAST_GATEWAY_EUI)) { builder.setLastGatewayEui(jsonObj.getString(JSON_KEY_LAST_GATEWAY_EUI)); }//ww w.j ava2s . com if (jsonObj.has(JSON_KEY_NODE_EUI)) { builder.setNodeEui(jsonObj.getString(JSON_KEY_NODE_EUI)); } if (jsonObj.has(JSON_KEY_LAST_SEEN)) { String dateStr = jsonObj.getString(JSON_KEY_LAST_SEEN); DateTime time = null; try { time = ISODateTimeFormat.dateTime().parseDateTime(dateStr); } catch (IllegalArgumentException e1) { // maybe we need to add a Z at the end? Someone might be sending wrong dates try { time = ISODateTimeFormat.dateTime().parseDateTime(dateStr + "Z"); } catch (IllegalArgumentException e2) { // pity, nothing to do } } if (time != null) { builder.setLastSeen(time); } } if (jsonObj.has(JSON_KEY_PACKETS_COUNT)) { builder.setPacketsCount(jsonObj.getInt(JSON_KEY_PACKETS_COUNT)); } return builder.build(); }
From source file:org.ttn.android.sdk.api.converter.RestPacketConverter.java
License:Apache License
@Override public Object fromJson(JSONObject jsonObj) throws JSONException { Packet.Builder builder = new Packet.Builder(); if (jsonObj.has(JSON_KEY_DATA)) { builder.setData(jsonObj.getString(JSON_KEY_DATA)); }//from w w w .j a va2s . c o m if (jsonObj.has(JSON_KEY_DATA_RATE)) { builder.setDataRate(jsonObj.getString(JSON_KEY_DATA_RATE)); } if (jsonObj.has(JSON_KEY_FREQUENCY)) { builder.setFrequency(jsonObj.getDouble(JSON_KEY_FREQUENCY)); } if (jsonObj.has(JSON_KEY_RSSI)) { builder.setRSSI(jsonObj.getInt(JSON_KEY_RSSI)); } if (jsonObj.has(JSON_KEY_DATA_JSON)) { builder.setDataJson(jsonObj.getString(JSON_KEY_DATA_JSON)); } if (jsonObj.has(JSON_KEY_DATA_PLAIN)) { builder.setDataPlain(jsonObj.getString(JSON_KEY_DATA_PLAIN)); } if (jsonObj.has(JSON_KEY_DATA_RAW)) { builder.setDataRaw(JSON_KEY_DATA_RAW); } if (jsonObj.has(JSON_KEY_GATEWAY_EUI)) { builder.setGatewayEui(jsonObj.getString(JSON_KEY_GATEWAY_EUI)); } if (jsonObj.has(JSON_KEY_NODE_EUI)) { builder.setNodeEui(jsonObj.getString(JSON_KEY_NODE_EUI)); } if (jsonObj.has(JSON_KEY_TIME)) { String dateStr = jsonObj.getString(JSON_KEY_TIME); DateTime time = null; try { time = ISODateTimeFormat.dateTime().parseDateTime(dateStr); } catch (IllegalArgumentException e1) { // maybe we need to add a Z at the end? Someone might be sending wrong dates try { time = ISODateTimeFormat.dateTime().parseDateTime(dateStr + "Z"); } catch (IllegalArgumentException e2) { // pity, nothing to do } } if (time != null) { builder.setTime(time); } } return builder.build(); }
From source file:org.ttn.android.sdk.v1.api.DateTimeConverter.java
License:Apache License
@Override public DateTime deserialize(JsonElement json, Type type, JsonDeserializationContext context) throws JsonParseException { String dateStr = json.getAsString(); DateTime time = null;//from w w w . j av a2s .co m try { time = ISODateTimeFormat.dateTime().parseDateTime(dateStr); } catch (IllegalArgumentException e1) { // maybe we need to add a Z at the end? Someone might be sending wrong dates try { time = ISODateTimeFormat.dateTime().parseDateTime(dateStr + "Z"); } catch (IllegalArgumentException e2) { // pity, nothing to do } } return time; }
From source file:org.wso2.bps.integration.tests.bpmn.BPMNUserSubstitutionTestCase.java
License:Open Source License
/** * Add substitute request. pass null for unwanted parameters. * {//from w ww. ja v a 2 s .c o m * "substitute" : "vinod", * "startTime" : "2010-01-01T12:00:00Z", * "endTime" : "2017-01-01T12:00:00Z", * "taskList" : ["1","2"] * } * @param substitute * @param assignee * @param start * @param end * @param taskList */ private HttpResponse addSubstituteUser(String substitute, String assignee, DateTime start, DateTime end, List<String> taskList, String user, String password) throws JSONException, IOException { JSONObject payload = new JSONObject(); if (assignee != null) { payload.put("assignee", assignee); } if (substitute != null) { payload.put("substitute", substitute); } DateTimeFormatter isoFormat = ISODateTimeFormat.dateTime(); if (start != null) { payload.put("startTime", isoFormat.print(start)); } if (end != null) { payload.put("endTime", isoFormat.print(end)); } if (taskList != null && !taskList.isEmpty()) { JSONArray taskArray = new JSONArray(); for (String id : taskList) { taskArray.put(id); } payload.put("taskList", taskArray); } HttpResponse response = BPMNTestUtils.doPost(backEndUrl + SUBSTITUTE_URL, payload, user, password); return response; }
From source file:org.wso2.bps.integration.tests.bpmn.BPMNUserSubstitutionTestCase.java
License:Open Source License
private int updateSubstitute(String substitute, String assignee, DateTime start, DateTime end) throws JSONException, IOException { JSONObject payload = new JSONObject(); if (substitute != null) { payload.put("substitute", substitute); }/*from w w w . j av a 2 s .c o m*/ DateTimeFormatter isoFormat = ISODateTimeFormat.dateTime(); if (start != null) { payload.put("startTime", isoFormat.print(start)); } if (end != null) { payload.put("endTime", isoFormat.print(end)); } HttpResponse response = BPMNTestUtils.putRequest(backEndUrl + SUBSTITUTE_URL + "/" + assignee, payload); return response.getStatusLine().getStatusCode(); }