@Test public void testTimestampQueryingAndOrder() throws IOException { ServiceLocator locator = container; SearchByTimestampAndOrderByTimestampRepository analysisGridRepository = locator.resolve(SearchByTimestampAndOrderByTimestampRepository.class); String marker = UUID.randomUUID().toString(); OffsetDateTime dt1 = OffsetDateTime.now(); OffsetDateTime dt2 = dt1.plusDays(1); OffsetDateTime dt3 = dt1.plusDays(2); OffsetDateTime dt4 = dt1.plusDays(3); SearchByTimestampAndOrderByTimestamp[] arr = new SearchByTimestampAndOrderByTimestamp[] { new SearchByTimestampAndOrderByTimestamp().setOndate(dt1).setMarker(marker), new SearchByTimestampAndOrderByTimestamp().setOndate(dt2).setMarker(marker), new SearchByTimestampAndOrderByTimestamp().setOndate(dt3).setMarker(marker), new SearchByTimestampAndOrderByTimestamp().setOndate(dt4).setMarker(marker) }; analysisGridRepository.insert(arr); List<SearchByTimestampAndOrderByTimestamp> queryResults = analysisGridRepository .query(it -> it.getMarker().equals(marker) && it.getOndate().isAfter(dt2)) .sortedDescendingBy(SearchByTimestampAndOrderByTimestamp::getOndate) .list(); Assert.assertEquals(queryResults.size(), arr.length - 2); Assert.assertTrue(queryResults.get(0).getOndate().isEqual(dt4)); }
@PreUpdate public void beforeUpdate(Object entity) { if (entity instanceof AbstractAuditableEntity) { AbstractAuditableEntity o = (AbstractAuditableEntity) entity; o.setUpdatedAt(OffsetDateTime.now()); if (o.getUpdatedBy() == null) { o.setUpdatedBy(currentUser()); } } }
/** * Get a single world by it's ID * * @param id the ID * @return the world */ @RequestMapping("/{id}") @ResponseBody public WorldModel get(@PathVariable("id") final String id) { WorldModel worldModel = new WorldModel(); worldModel.setId(id); worldModel.setName("Middle Earth"); worldModel.setDescription("The world of The Hobbit and The Lord of the Rings"); worldModel.setCreationDate(OffsetDateTime.now()); worldModel.setOwner(new UserLink()); worldModel.getOwner().setId(UUID.randomUUID().toString()); worldModel.getOwner().setName("Tolkien"); return worldModel; }
private void updateMetadata(ZdoModel model) throws IOException { Response.StatusType statusInfo = ClientBuilder.newClient() .target(fitTransactionToUrl(model.getUrl())) .request() .put(Entity.entity(model, RDF_SERIALIZATION)) .getStatusInfo(); if (statusInfo.getFamily() != Response.Status.Family.SUCCESSFUL) { logError(fitTransactionToUrl(model.getUrl()), statusInfo); throw new IOException("Failed to update resource " + fitTransactionToUrl(model.getUrl())); } model.removeAllValuesOfProperty(ZdoTerms.fedoraLastModified); if (ZdoType.isAbovePageCategory(model.get(ZdoTerms.zdoType))) { model.add( model.getSubject(), ZdoTerms.fedoraLastModified, OffsetDateTime.now().toString(), XSDDatatype.XSDdateTime); if (model.get(ZdoTerms.fedoraCreated) == null) { model.add( model.getSubject(), ZdoTerms.fedoraCreated, OffsetDateTime.now().toString(), XSDDatatype.XSDdateTime); } } else { model.removeAllValuesOfProperty(ZdoTerms.fedoraCreated); } // Also update triplestore model.stripPossibleBadUrlEnding(); // strip fcr:metadata if (transactionPath == null) { sparqlOnDemandIndexer.update(model); } else { // If in transaction, triplestore operations are delayed till its end toUpdate.add(model); } }
// @Inject // @AuthenticatedUser // User user; // @PersistenceContext // EntityManager em; @PrePersist public void beforePersist(Object entity) { if (entity instanceof AbstractAuditableEntity) { AbstractAuditableEntity o = (AbstractAuditableEntity) entity; final OffsetDateTime now = OffsetDateTime.now(); o.setCreatedAt(now); o.setUpdatedAt(now); if (o.getCreatedBy() == null) { o.setCreatedBy(currentUser()); } } }
@Test public void shouldReturnJobIfJobExists() throws Exception { // given ZoneId cet = ZoneId.of("CET"); OffsetDateTime now = OffsetDateTime.now(cet); JobInfo expectedJob = newJobInfo("42", "TEST", fixed(now.toInstant(), cet), "localhost"); when(jobService.findJob("42")).thenReturn(Optional.of(expectedJob)); String nowAsString = ISO_OFFSET_DATE_TIME.format(now); mockMvc .perform( MockMvcRequestBuilders.get("/some-microservice/internal/jobs/42") .servletPath("/internal/jobs/42")) .andExpect(MockMvcResultMatchers.status().is(200)) .andExpect(MockMvcResultMatchers.jsonPath("$.status").value("OK")) .andExpect(MockMvcResultMatchers.jsonPath("$.messages").isArray()) .andExpect(MockMvcResultMatchers.jsonPath("$.jobType").value("TEST")) .andExpect(MockMvcResultMatchers.jsonPath("$.hostname").value("localhost")) .andExpect(MockMvcResultMatchers.jsonPath("$.started").value(nowAsString)) .andExpect(MockMvcResultMatchers.jsonPath("$.stopped").value("")) .andExpect(MockMvcResultMatchers.jsonPath("$.lastUpdated").value(nowAsString)) .andExpect( MockMvcResultMatchers.jsonPath("$.jobUri") .value("http://localhost/some-microservice/internal/jobs/42")) .andExpect(MockMvcResultMatchers.jsonPath("$.links").isArray()) .andExpect( MockMvcResultMatchers.jsonPath("$.links[0].href") .value("http://localhost/some-microservice/internal/jobs/42")) .andExpect( MockMvcResultMatchers.jsonPath("$.links[1].href") .value("http://localhost/some-microservice/internal/jobdefinitions/TEST")) .andExpect( MockMvcResultMatchers.jsonPath("$.links[2].href") .value("http://localhost/some-microservice/internal/jobs")) .andExpect( MockMvcResultMatchers.jsonPath("$.links[3].href") .value("http://localhost/some-microservice/internal/jobs?type=TEST")) .andExpect(MockMvcResultMatchers.jsonPath("$.runtime").value("")) .andExpect(MockMvcResultMatchers.jsonPath("$.state").value("Running")); verify(jobService).findJob("42"); }
public void calculateNextScheduledRun(Long immediateFrequency) { if (lastScheduledRun == null) { lastScheduledRun = OffsetDateTime.now(); } switch (getFrequency().getFrequency()) { case IMMEDIATE: setNextScheduledRun(lastScheduledRun.plusMinutes(immediateFrequency)); break; case DAILY: setNextScheduledRun(lastScheduledRun.plusDays(1)); break; case WEEKLY: setNextScheduledRun(lastScheduledRun.plusWeeks(1)); break; case MONTHLY: setNextScheduledRun(lastScheduledRun.plusMonths(1)); break; default: setNextScheduledRun(null); } }
@Before public void before() { actual = OffsetDateTime.now(); }
protected ResponseEntity<ShimDataResponse> getData( OAuth2RestOperations restTemplate, ShimDataRequest shimDataRequest) throws ShimException { final JawboneDataTypes jawboneDataType; try { jawboneDataType = JawboneDataTypes.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."); } // FIXME this needs to get changed or documented long numToReturn = 100; if (shimDataRequest.getNumToReturn() != null) { numToReturn = shimDataRequest.getNumToReturn(); } OffsetDateTime today = OffsetDateTime.now(); OffsetDateTime startDateTime = shimDataRequest.getStartDateTime() == null ? today.minusDays(1) : shimDataRequest.getStartDateTime(); long startTimeInEpochSecond = startDateTime.toEpochSecond(); OffsetDateTime endDateTime = shimDataRequest.getEndDateTime() == null ? today.plusDays(1) : shimDataRequest.getEndDateTime(); long endTimeInEpochSecond = endDateTime.toEpochSecond(); UriComponentsBuilder uriComponentsBuilder = UriComponentsBuilder.fromUriString(DATA_URL) .path(jawboneDataType.getEndPoint()) .queryParam("start_time", startTimeInEpochSecond) .queryParam("end_time", endTimeInEpochSecond) .queryParam("limit", numToReturn); ResponseEntity<JsonNode> responseEntity; try { responseEntity = restTemplate.getForEntity(uriComponentsBuilder.build().encode().toUri(), JsonNode.class); } catch (HttpClientErrorException | HttpServerErrorException e) { // FIXME figure out how to handle this logger.error("A request for Jawbone data failed.", e); throw e; } if (shimDataRequest.getNormalize()) { JawboneDataPointMapper mapper; switch (jawboneDataType) { case WEIGHT: mapper = new JawboneBodyWeightDataPointMapper(); break; case STEPS: mapper = new JawboneStepCountDataPointMapper(); break; case BODY_MASS_INDEX: mapper = new JawboneBodyMassIndexDataPointMapper(); break; case ACTIVITY: mapper = new JawbonePhysicalActivityDataPointMapper(); break; case SLEEP: mapper = new JawboneSleepDurationDataPointMapper(); break; case HEART_RATE: mapper = new JawboneHeartRateDataPointMapper(); break; default: throw new UnsupportedOperationException(); } return ResponseEntity.ok() .body( ShimDataResponse.result( JawboneShim.SHIM_KEY, mapper.asDataPoints(singletonList(responseEntity.getBody())))); } else { return ResponseEntity.ok() .body(ShimDataResponse.result(JawboneShim.SHIM_KEY, responseEntity.getBody())); } }