List of usage examples for java.time OffsetDateTime now
public static OffsetDateTime now()
From source file:org.openmhealth.shim.misfit.MisfitShim.java
@Override protected ResponseEntity<ShimDataResponse> getData(OAuth2RestOperations restTemplate, ShimDataRequest shimDataRequest) throws ShimException { final MisfitDataTypes misfitDataType; try {//ww w. j a v a2 s. com misfitDataType = MisfitDataTypes.valueOf(shimDataRequest.getDataTypeKey().trim().toUpperCase()); } catch (NullPointerException | IllegalArgumentException e) { throw new ShimException("Null or Invalid data type parameter: " + shimDataRequest.getDataTypeKey() + " in shimDataRequest, cannot retrieve data."); } // TODO don't truncate dates OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime startDateTime = shimDataRequest.getStartDateTime() == null ? now.minusDays(1) : shimDataRequest.getStartDateTime(); OffsetDateTime endDateTime = shimDataRequest.getEndDateTime() == null ? now.plusDays(1) : shimDataRequest.getEndDateTime(); if (Duration.between(startDateTime, endDateTime).toDays() > MAX_DURATION_IN_DAYS) { endDateTime = startDateTime.plusDays(MAX_DURATION_IN_DAYS - 1); // TODO when refactoring, break apart queries } UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(DATA_URL); for (String pathSegment : Splitter.on("/").split(misfitDataType.getEndPoint())) { uriBuilder.pathSegment(pathSegment); } uriBuilder.queryParam("start_date", startDateTime.toLocalDate()) // TODO convert ODT to LocalDate properly .queryParam("end_date", endDateTime.toLocalDate()).queryParam("detail", true); // added to all endpoints to support summaries ResponseEntity<JsonNode> responseEntity; try { responseEntity = restTemplate.getForEntity(uriBuilder.build().encode().toUri(), JsonNode.class); } catch (HttpClientErrorException | HttpServerErrorException e) { // FIXME figure out how to handle this logger.error("A request for Misfit data failed.", e); throw e; } if (shimDataRequest.getNormalize()) { MisfitDataPointMapper<?> dataPointMapper; switch (misfitDataType) { case ACTIVITIES: dataPointMapper = physicalActivityMapper; break; case SLEEP: dataPointMapper = sleepDurationMapper; break; case STEPS: dataPointMapper = stepCountMapper; break; default: throw new UnsupportedOperationException(); } return ok().body(ShimDataResponse.result(SHIM_KEY, dataPointMapper.asDataPoints(singletonList(responseEntity.getBody())))); } else { return ok().body(ShimDataResponse.result(SHIM_KEY, responseEntity.getBody())); } }
From source file:org.apache.james.sieve.jpa.model.JPASieveScript.java
public void activate() { this.isActive = true; this.activationDateTime = OffsetDateTime.now(); }
From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java
@Override public void executeStartResourceJob(boolean isAppliedForClusters) { OffsetDateTime currentDateTime = OffsetDateTime.now(); List<SchedulerJobData> jobsToStart = getSchedulerJobsForAction(UserInstanceStatus.RUNNING, currentDateTime, isAppliedForClusters);//from w w w . j ava 2s . co m if (!jobsToStart.isEmpty()) { log.debug(isAppliedForClusters ? "Scheduler computational resource start job is executing..." : "Scheduler exploratory start job is executing..."); log.info(CURRENT_DATETIME_INFO, LocalTime.of(currentDateTime.toLocalTime().getHour(), currentDateTime.toLocalTime().getMinute()), currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek()); log.info(isAppliedForClusters ? "Quantity of clusters for starting: {}" : "Quantity of exploratories for starting: {}", jobsToStart.size()); jobsToStart .forEach(job -> changeResourceStatusTo(UserInstanceStatus.RUNNING, job, isAppliedForClusters)); } }
From source file:org.openmhealth.shim.runkeeper.RunkeeperShim.java
protected ResponseEntity<ShimDataResponse> getData(OAuth2RestOperations restTemplate, ShimDataRequest shimDataRequest) throws ShimException { String dataTypeKey = shimDataRequest.getDataTypeKey().trim().toUpperCase(); RunkeeperDataType runkeeperDataType; try {//from w ww . j av a2s.co m runkeeperDataType = RunkeeperDataType.valueOf(dataTypeKey); } catch (NullPointerException | IllegalArgumentException e) { throw new ShimException("Null or Invalid data type parameter: " + dataTypeKey + " in shimDataRequest, cannot retrieve data."); } /*** * Setup default date parameters */ OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime startDateTime = shimDataRequest.getStartDateTime() == null ? now.minusDays(1) : shimDataRequest.getStartDateTime(); OffsetDateTime endDateTime = shimDataRequest.getEndDateTime() == null ? now.plusDays(1) : shimDataRequest.getEndDateTime(); /* Runkeeper defaults to returning a maximum of 25 entries per request (pageSize = 25 by default), so we override the default by specifying an arbitrarily large number as the pageSize. */ long numToReturn = 100_000; UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(DATA_URL) .pathSegment(runkeeperDataType.getEndPointUrl()) .queryParam("noEarlierThan", startDateTime.toLocalDate()) .queryParam("noLaterThan", endDateTime.toLocalDate()).queryParam("pageSize", numToReturn) .queryParam("detail", true); // added to all endpoints to support summaries HttpHeaders headers = new HttpHeaders(); headers.set("Accept", runkeeperDataType.getDataTypeHeader()); ResponseEntity<JsonNode> responseEntity; try { responseEntity = restTemplate.exchange(uriBuilder.build().encode().toUri(), GET, new HttpEntity<JsonNode>(headers), JsonNode.class); } catch (HttpClientErrorException | HttpServerErrorException e) { // FIXME figure out how to handle this logger.error("A request for RunKeeper data failed.", e); throw e; } if (shimDataRequest.getNormalize()) { RunkeeperDataPointMapper<?> dataPointMapper; switch (runkeeperDataType) { case ACTIVITY: dataPointMapper = new RunkeeperPhysicalActivityDataPointMapper(); break; case CALORIES: dataPointMapper = new RunkeeperCaloriesBurnedDataPointMapper(); break; default: throw new UnsupportedOperationException(); } return ok().body(ShimDataResponse.result(SHIM_KEY, dataPointMapper.asDataPoints(singletonList(responseEntity.getBody())))); } else { return ok().body(ShimDataResponse.result(SHIM_KEY, responseEntity.getBody())); } }
From source file:org.kie.workbench.common.forms.integration.tests.valueprocessing.FormValuesProcessorTest.java
@Test public void testLocalDateFieldTaskFormValuesProcessing() { setupFormValuesProcessor(Collections.singletonList(localDateFieldValueProcessor)); final String LOCAL_DATE_BINDING = "_localDate_", LOCAL_DATE_TIME_BINDING = "_localDateTime_", LOCAL_TIME_BINDING = "_localTime_", OFFSET_DATE_TIME_BINDING = "_offsetDateTime_"; final LocalDate localDate1 = LocalDate.of(1989, 6, 6); final LocalDateTime localDateTime1 = LocalDateTime.of(2000, 5, 2, 3, 4); final LocalTime localTime1 = LocalTime.of(23, 15); //form engine does not support setting custom offset final ZoneOffset zoneOffset1 = OffsetDateTime.now().getOffset(); final OffsetDateTime offsetDateTime1 = OffsetDateTime.of(localDate1, localTime1, zoneOffset1); final Map<String, Object> originalRawValues = new HashMap<String, Object>() { {//from w w w. jav a 2s. c o m put(LOCAL_DATE_BINDING, localDate1); put(LOCAL_DATE_TIME_BINDING, localDateTime1); put(LOCAL_TIME_BINDING, localTime1); put(OFFSET_DATE_TIME_BINDING, offsetDateTime1); } }; localDateFieldValueProcessor.init(); final Map<String, Object> readFlatValues = formValuesProcessor.readFormValues(localDateTaskForm, originalRawValues, context); final Map<String, Object> writtenRawValues = testWritingFormValues(localDateTaskForm, originalRawValues, readFlatValues, originalRawValues); testReadingFormValues(localDateTaskForm, writtenRawValues, readFlatValues); }
From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java
@Override public void executeStopResourceJob(boolean isAppliedForClusters) { OffsetDateTime currentDateTime = OffsetDateTime.now(); List<SchedulerJobData> jobsToStop = getSchedulerJobsForAction(STOPPED, currentDateTime, isAppliedForClusters);// ww w . jav a 2 s. c om if (!jobsToStop.isEmpty()) { log.debug(isAppliedForClusters ? "Scheduler computational resource stop job is executing..." : "Scheduler exploratory stop job is executing..."); log.info(CURRENT_DATETIME_INFO, LocalTime.of(currentDateTime.toLocalTime().getHour(), currentDateTime.toLocalTime().getMinute()), currentDateTime.toLocalDate(), currentDateTime.getDayOfWeek()); log.info(isAppliedForClusters ? "Quantity of clusters for stopping: {}" : "Quantity of exploratories for stopping: {}", jobsToStop.size()); jobsToStop.forEach(job -> changeResourceStatusTo(STOPPED, job, isAppliedForClusters)); } }
From source file:org.silverpeas.components.gallery.notification.user.AlbumMediaNotificationManagerTest.java
@Test void putCreationWithDelay() throws Exception { final OffsetDateTime now = OffsetDateTime.now(); gallerySettings.put("subscription.notification.delay", "10"); testedManager.putCreationOf(albumMediaA, senderX); assertThat(getContextCache().size(), is(1)); final String expectedKey = "1@gallery38@26"; assertThat(getContextCache(), hasKey(expectedKey)); final NotificationAlbumJob notificationAlbumJob = getContextCache().get(expectedKey); assertNotificationAlbumJob(notificationAlbumJob, 1, albumDetail1, senderX); verify(scheduler, times(1)).unscheduleJob(anyString()); final ArgumentCaptor<JobTrigger> captor = forClass(JobTrigger.class); verify(scheduler, times(1)).scheduleJob(any(NotificationAlbumJob.class), captor.capture()); final JobTrigger jobTrigger = captor.getValue(); assertJobScheduled(jobTrigger, now, 0); }
From source file:org.openmhealth.shim.ihealth.IHealthShim.java
@Override protected ResponseEntity<ShimDataResponse> getData(OAuth2RestOperations restTemplate, ShimDataRequest shimDataRequest) throws ShimException { final IHealthDataTypes dataType; try {/*from w w w .jav a 2s. c om*/ dataType = valueOf(shimDataRequest.getDataTypeKey().trim().toUpperCase()); } catch (NullPointerException | IllegalArgumentException e) { throw new ShimException("Null or Invalid data type parameter: " + shimDataRequest.getDataTypeKey() + " in shimDataRequest, cannot retrieve data."); } OffsetDateTime now = OffsetDateTime.now(); OffsetDateTime startDate = shimDataRequest.getStartDateTime() == null ? now.minusDays(1) : shimDataRequest.getStartDateTime(); OffsetDateTime endDate = shimDataRequest.getEndDateTime() == null ? now.plusDays(1) : shimDataRequest.getEndDateTime(); /* The physical activity point handles start and end datetimes differently than the other endpoints. It requires use to include the range until the beginning of the next day. */ if (dataType == PHYSICAL_ACTIVITY) { endDate = endDate.plusDays(1); } // SC and SV values are client-based keys that are unique to each endpoint within a project String scValue = getScValue(); List<String> svValues = getSvValues(dataType); List<JsonNode> responseEntities = newArrayList(); int i = 0; // We iterate because one of the measures (Heart rate) comes from multiple endpoints, so we submit // requests to each of these endpoints, map the responses separately and then combine them for (String endPoint : dataType.getEndPoint()) { UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(API_URL); // Need to use a dummy userId if we haven't authenticated yet. This is the case where we are using // getData to trigger Spring to conduct the OAuth exchange String userId = "uk"; if (shimDataRequest.getAccessParameters() != null) { OAuth2AccessToken token = SerializationUtils .deserialize(shimDataRequest.getAccessParameters().getSerializedToken()); userId = Preconditions.checkNotNull((String) token.getAdditionalInformation().get("UserID")); uriBuilder.queryParam("access_token", token.getValue()); } uriBuilder.path("/user/").path(userId + "/").path(endPoint) .queryParam("client_id", restTemplate.getResource().getClientId()) .queryParam("client_secret", restTemplate.getResource().getClientSecret()) .queryParam("start_time", startDate.toEpochSecond()) .queryParam("end_time", endDate.toEpochSecond()).queryParam("locale", "default") .queryParam("sc", scValue).queryParam("sv", svValues.get(i)); ResponseEntity<JsonNode> responseEntity; try { URI url = uriBuilder.build().encode().toUri(); responseEntity = restTemplate.getForEntity(url, JsonNode.class); } catch (HttpClientErrorException | HttpServerErrorException e) { // FIXME figure out how to handle this logger.error("A request for iHealth data failed.", e); throw e; } if (shimDataRequest.getNormalize()) { IHealthDataPointMapper mapper; switch (dataType) { case PHYSICAL_ACTIVITY: mapper = new IHealthPhysicalActivityDataPointMapper(); break; case BLOOD_GLUCOSE: mapper = new IHealthBloodGlucoseDataPointMapper(); break; case BLOOD_PRESSURE: mapper = new IHealthBloodPressureDataPointMapper(); break; case BODY_WEIGHT: mapper = new IHealthBodyWeightDataPointMapper(); break; case BODY_MASS_INDEX: mapper = new IHealthBodyMassIndexDataPointMapper(); break; case STEP_COUNT: mapper = new IHealthStepCountDataPointMapper(); break; case SLEEP_DURATION: mapper = new IHealthSleepDurationDataPointMapper(); break; case HEART_RATE: // there are two different mappers for heart rate because the data can come from two endpoints if (endPoint == "bp.json") { mapper = new IHealthBloodPressureEndpointHeartRateDataPointMapper(); break; } else if (endPoint == "spo2.json") { mapper = new IHealthBloodOxygenEndpointHeartRateDataPointMapper(); break; } case OXYGEN_SATURATION: mapper = new IHealthOxygenSaturationDataPointMapper(); break; default: throw new UnsupportedOperationException(); } responseEntities.addAll(mapper.asDataPoints(singletonList(responseEntity.getBody()))); } else { responseEntities.add(responseEntity.getBody()); } i++; } return ResponseEntity.ok().body(ShimDataResponse.result(SHIM_KEY, responseEntities)); }