List of usage examples for org.joda.time LocalDateTime toDateTime
public DateTime toDateTime()
From source file:at.wada811.dayscounter.view.appwidget.CounterAppWidgetProvider.java
License:Apache License
@TargetApi(Build.VERSION_CODES.KITKAT) public static void setDateChangeAlarm(Context context) { Intent intent = new Intent(DateTimeChangeReceiver.ACTION_DATE_CHANGED); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE); LocalDateTime today = new LocalDateTime(); LocalDateTime tomorrow = today.plusDays(1); alarmManager.cancel(pendingIntent);/*from w w w. jav a2s . c o m*/ if (AndroidUtils.isLessThanBuildVersion(Build.VERSION_CODES.KITKAT)) { alarmManager.set(AlarmManager.RTC, tomorrow.toDateTime().getMillis(), pendingIntent); } else { alarmManager.setExact(AlarmManager.RTC, tomorrow.toDateTime().getMillis(), pendingIntent); } }
From source file:ch.aonyx.broker.ib.api.data.historical.HistoricalDataEvent.java
License:Apache License
public long getMillis() { if (dateTime.length() == 18) { LocalDateTime l = timeFormat.parseLocalDateTime(dateTime); return l.toDateTime().getMillis(); }//from w w w .ja va 2 s. c o m if (dateTime.length() == 8) { DateTime l = dateFormat.parseDateTime(dateTime); return l.getMillis(); } return new DateTime(dateTime).getMillis(); }
From source file:ch.icclab.cyclops.resource.impl.ExternalAppResource.java
License:Open Source License
/** * Receives the JSON data sent by an external application * * Pseudo Code/*from ww w . j a v a2 s . c om*/ * 1. Receive the data * 2. Extract the JSON array * 3. Send the JSON array to saveData() for further processing * * @param entity * @return Representation A JSON response is returned */ @Post("json:json") public Representation receiveRequest(JsonRepresentation entity) { JSONArray jsonArr = null; boolean output = true; LocalDateTime currentDateTime = new LocalDateTime(); Response response = new Response(); Representation jsonResponse = new JsonRepresentation(response); ResponseUtil util = new ResponseUtil(); try { jsonArr = entity.getJsonArray(); output = saveData(jsonArr); } catch (JSONException e) { output = false; e.printStackTrace(); } response.setTimestamp(currentDateTime.toDateTime().toString()); if (output) { response.setStatus("Success"); response.setMessage("Data saved into the DB"); } else { response.setStatus("Failure"); response.setMessage("Data could not be saved into the DB"); } jsonResponse = util.toJson(response); return jsonResponse; }
From source file:ch.icclab.cyclops.resource.impl.MeterResource.java
License:Open Source License
/** * Receives the JSON data consisting of meter selection status * * Pseudo Code/*from ww w . j a va 2 s .com*/ * 1. Receive the data * 2. Extract the JSON array * 3. Send the JSON array to saveData() for persistence into the DB * * @param entity The body of the POST request * @return Representation A JSON response containing the status of the request serviced */ @Post("json:json") public Representation setMeterList(Representation entity) { boolean output = true; ObjectMapper mapper = new ObjectMapper(); String jsonData = null; JsonRepresentation request = null; JsonRepresentation responseJson = null; LocalDateTime currentDateTime = new LocalDateTime(); Response response = new Response(); // Get the JSON representation of the incoming POST request try { request = new JsonRepresentation(entity); } catch (IOException e) { e.printStackTrace(); } //Set the isMeterListReset to TRUE Flag.setMeterListReset(true); // Process the incoming request try { output = saveData(request.getJsonObject()); } catch (JSONException e) { output = false; e.printStackTrace(); } // Set the time stamp response.setTimestamp(currentDateTime.toDateTime().toString()); // Set the status and message if (output) { response.setStatus("Success"); response.setMessage("Data saved into the DB"); } else { response.setStatus("Failure"); response.setMessage("Data could not be saved into the DB"); } // Convert the Java object to a JSON string try { jsonData = mapper.writeValueAsString(response); responseJson = new JsonRepresentation(jsonData); } catch (JsonProcessingException e) { e.printStackTrace(); } return responseJson; }
From source file:ch.icclab.cyclops.resource.impl.TelemetryResource.java
License:Open Source License
/** * Evaluates the outcome of the operation to save the Cumulative & Gauge and constructs the * response object accordingly// w w w. jav a 2 s .c o m * * @param cumulativeMeterOutput A boolean which indicates the outcome of the operation to save the Cumulative Meter data * @param gaugeMeterOutput A boolean which indicates the outcome of the operation to save the Gauge Meter data * @return A response object containing the details of the operation */ private Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput) { Response responseObj = new Response(); LocalDateTime currentDateTime = new LocalDateTime(); if (cumulativeMeterOutput && gaugeMeterOutput) { responseObj.setTimestamp(currentDateTime.toDateTime().toString()); responseObj.setStatus("Success"); responseObj.setMessage("Cumulative & Gauge Meters were Successfully saved into the DB"); } else if (gaugeMeterOutput) { responseObj.setTimestamp(currentDateTime.toDateTime().toString()); responseObj.setStatus("Success"); responseObj.setMessage("Only Gauge Meter was Successfully saved into the DB"); } else { responseObj.setTimestamp(currentDateTime.toDateTime().toString()); responseObj.setStatus("Success"); responseObj.setMessage("Only Cumulative Meter was Successfully saved into the DB"); } return responseObj; }
From source file:ch.icclab.cyclops.services.iaas.openstack.resource.impl.ExternalAppResource.java
License:Open Source License
/** * Receives the JSON data sent by an external application * <p/>/*w ww .ja va 2s .co m*/ * Pseudo Code<br/> * 1. Receive the data<br/> * 2. Extract the JSON array<br/> * 3. Send the JSON array to saveData() for further processing<br/> * * @param entity * @return Representation A JSON response is returned */ @Post("json:json") public Representation receiveRequest(JsonRepresentation entity) { counter.increment(endpoint); logger.trace("BEGIN Representation receiveRequest(JsonRepresentation entity)"); JSONArray jsonArr = null; boolean output = true; LocalDateTime currentDateTime = new LocalDateTime(); Response response = new Response(); Representation jsonResponse = new JsonRepresentation(response); ResponseUtil util = new ResponseUtil(); try { jsonArr = entity.getJsonArray(); output = saveData(jsonArr); } catch (JSONException e) { logger.error("EXCEPTION JSONEXCEPTION Representation receiveRequest(JsonRepresentation entity)"); output = false; e.printStackTrace(); } response.setTimestamp(currentDateTime.toDateTime().toString()); if (output) { response.setStatus("Success"); response.setMessage("Data saved into the DB"); } else { response.setStatus("Failure"); response.setMessage("Data could not be saved into the DB"); } jsonResponse = util.toJson(response); logger.trace("END Representation receiveRequest(JsonRepresentation entity)"); return jsonResponse; }
From source file:ch.icclab.cyclops.services.iaas.openstack.resource.impl.MeterResource.java
License:Open Source License
/** * Receives the JSON data consisting of meter selection status * <p/>//from ww w . j a va 2 s . c o m * Pseudo Code<br> * 1. Receive the data<br> * 2. Extract the JSON array<br> * 3. Send the JSON array to saveData() for persistence into the DB * * @param entity The body of the POST request * @return Representation A JSON response containing the status of the request serviced */ @Post("json:json") public Representation setMeterList(Representation entity) { counter.increment(endpoint); logger.trace("BEGIN Representation setMeterList(Representation entity)"); boolean output = true; ObjectMapper mapper = new ObjectMapper(); String jsonData = null; JsonRepresentation request = null; JsonRepresentation responseJson = null; LocalDateTime currentDateTime = new LocalDateTime(); Response response = new Response(); // Get the JSON representation of the incoming POST request try { request = new JsonRepresentation(entity); } catch (IOException e) { logger.error("EXCEPTION IOEXCEPTION Representation setMeterList(Representation entity)"); e.printStackTrace(); } //Tells to UDR that need to reload the meter list in Load Flag.setMeterListReset(true); // Process the incoming request try { output = saveData(request.getJsonObject()); } catch (JSONException e) { logger.error("EXCEPTION JSONGEXCEPTION Representation setMeterList(Representation entity)"); output = false; e.printStackTrace(); } // Set the time stamp response.setTimestamp(currentDateTime.toDateTime().toString()); // Set the status and message if (output) { response.setStatus("Success"); response.setMessage("Data saved into the DB"); } else { logger.debug( "DEBUG Representation setMeterList(Representation entity): Data could not be saved into the DB"); response.setStatus("Failure"); response.setMessage("Data could not be saved into the DB"); } //TODO: jsonMapper method. reusable in all the classes. // Convert the Java object to a JSON string try { jsonData = mapper.writeValueAsString(response); responseJson = new JsonRepresentation(jsonData); } catch (JsonProcessingException e) { logger.error("EXCEPTION JSONPROCESSINGEXCEPTION Representation setMeterList(Representation entity)"); e.printStackTrace(); } logger.trace("END Representation setMeterList(Representation entity)"); return responseJson; }
From source file:ch.icclab.cyclops.services.iaas.openstack.resource.impl.TelemetryResource.java
License:Open Source License
/** * Evaluates the outcome of the operation to save the Cumulative & Gauge and constructs the * response object accordingly//from w w w . j ava2s. com * * @param cumulativeMeterOutput A boolean which indicates the outcome of the operation to save the Cumulative Meter data * @param gaugeMeterOutput A boolean which indicates the outcome of the operation to save the Gauge Meter data * @return A response object containing the details of the operation */ private Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput) { logger.trace("BEGIN Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput)"); Response responseObj = new Response(); LocalDateTime currentDateTime = new LocalDateTime(); //TODO: response for no usagedata saved. if (cumulativeMeterOutput && gaugeMeterOutput) { responseObj.setTimestamp(currentDateTime.toDateTime().toString()); responseObj.setStatus("Success"); responseObj.setMessage("Cumulative & Gauge Meters were Successfully saved into the DB"); } else if (gaugeMeterOutput) { responseObj.setTimestamp(currentDateTime.toDateTime().toString()); responseObj.setStatus("Success"); responseObj.setMessage("Only Gauge Meter was Successfully saved into the DB"); logger.debug( "DEBUG Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput) - Only Gauge Meter was Successfully saved into the DB"); } else { responseObj.setTimestamp(currentDateTime.toDateTime().toString()); responseObj.setStatus("Success"); responseObj.setMessage("Only Cumulative Meter was Successfully saved into the DB"); logger.debug( "DEBUG Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput) - Only Cumulative Meter was Successfully saved into the DB"); } logger.trace("END Response constructResponse(boolean cumulativeMeterOutput, boolean gaugeMeterOutput)"); return responseObj; }
From source file:ch.icclab.cyclops.usecases.mcn.impl.MCNResource.java
License:Open Source License
/** * This method creates the response message of the API call * * @return// ww w. j a va 2 s.c o m */ //TODO: remove method private Response constructResponse() { logger.trace("BEGIN constructResponse(TSDBData data)"); Response responseObj = new Response(); LocalDateTime currentDateTime = new LocalDateTime(); responseObj.setTimestamp(currentDateTime.toDateTime().toString()); responseObj.setStatus("Success"); responseObj.setMessage("Event Data retrieved."); logger.trace("BEGIN constructResponse(TSDBData data)"); return responseObj; }
From source file:com.axelor.apps.crm.service.EventReminderService.java
License:Open Source License
public Duration computeDuration(LocalDateTime startDateTime, LocalDateTime endDateTime) { return new Interval(startDateTime.toDateTime(), endDateTime.toDateTime()).toDuration(); }