List of usage examples for java.time ZonedDateTime plusSeconds
public ZonedDateTime plusSeconds(long seconds)
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void updateTimeLastActivity_default_noGoalConflictMessagesCreated() { ZonedDateTime t1 = now(); ZonedDateTime t2 = t1.plusSeconds(1); ZonedDateTime t3 = t2.plusSeconds(1); DayActivity existingDayActivity = mockExistingActivity(gamblingGoal, t2); ActivityDto lastRegisteredActivity = ActivityDto.createInstance(existingDayActivity.getActivities().get(0)); service.updateTimeLastActivity(createPayload(t1, t3), GoalDto.createInstance(gamblingGoal), lastRegisteredActivity);//from w ww . j a v a 2 s . c o m verifyNoGoalConflictMessagesCreated(); }
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void updateTimeExistingActivity_startTimeEarlier_activityStartTimeUpdated() { ZonedDateTime t1 = now(); ZonedDateTime t2 = t1.plusSeconds(1); ZonedDateTime t3 = t2.plusSeconds(1); DayActivity existingDayActivityEntity = mockExistingActivity(gamblingGoal, t2, t3, "Lotto"); Activity existingActivityEntity = existingDayActivityEntity.getLastActivity(deviceAnonId); service.updateTimeExistingActivity(createPayload(t1, t2), existingActivityEntity); assertThat("Expect start time updated", existingActivityEntity.getStartTimeAsZonedDateTime(), equalTo(t1)); assertThat("Expect end time same", existingActivityEntity.getEndTimeAsZonedDateTime(), equalTo(t3)); }
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void updateTimeExistingActivity_endTimeLater_activityEndTimeUpdated() { ZonedDateTime t1 = now(); ZonedDateTime t2 = t1.plusSeconds(1); ZonedDateTime t3 = t2.plusSeconds(1); DayActivity existingDayActivityEntity = mockExistingActivity(gamblingGoal, t1, t2, "Lotto"); Activity existingActivityEntity = existingDayActivityEntity.getLastActivity(deviceAnonId); service.updateTimeExistingActivity(createPayload(t2, t3), existingActivityEntity); assertThat("Expect start time same", existingActivityEntity.getStartTimeAsZonedDateTime(), equalTo(t1)); assertThat("Expect end time updated", existingActivityEntity.getEndTimeAsZonedDateTime(), equalTo(t3)); }
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void updateTimeLastActivity_default_cacheUpdated() { ZonedDateTime t1 = now(); ZonedDateTime t2 = t1.plusSeconds(1); DayActivity existingDayActivityEntity = mockExistingActivity(gamblingGoal, t2, t2, "Lotto"); Activity existingActivityEntity = existingDayActivityEntity.getLastActivity(deviceAnonId); ActivityDto lastRegisteredActivity = ActivityDto.createInstance(existingActivityEntity); service.updateTimeLastActivity(createPayload(t1, t2), GoalDto.createInstance(gamblingGoal), lastRegisteredActivity);/*from ww w . ja v a 2s . c o m*/ verify(mockAnalysisEngineCacheService).updateLastActivityForUser(eq(userAnonId), eq(deviceAnonId), eq(gamblingGoal.getId()), any()); }
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void updateTimeLastActivity_startTimeEarlier_activityStartTimeUpdated() { ZonedDateTime t1 = now(); ZonedDateTime t2 = t1.plusSeconds(1); ZonedDateTime t3 = t2.plusSeconds(1); DayActivity existingDayActivityEntity = mockExistingActivity(gamblingGoal, t2, t3, "Lotto"); Activity existingActivityEntity = existingDayActivityEntity.getLastActivity(deviceAnonId); ActivityDto lastRegisteredActivity = ActivityDto.createInstance(existingActivityEntity); service.updateTimeLastActivity(createPayload(t1, t2), GoalDto.createInstance(gamblingGoal), lastRegisteredActivity);/* w w w . j a v a2 s .com*/ assertThat("Expect start time updated", existingActivityEntity.getStartTimeAsZonedDateTime(), equalTo(t1)); assertThat("Expect end time same", existingActivityEntity.getEndTimeAsZonedDateTime(), equalTo(t3)); }
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void updateTimeLastActivity_endTimeLater_activityEndTimeUpdated() { ZonedDateTime t1 = now(); ZonedDateTime t2 = t1.plusSeconds(1); ZonedDateTime t3 = t2.plusSeconds(1); DayActivity existingDayActivityEntity = mockExistingActivity(gamblingGoal, t1, t2, "Lotto"); Activity existingActivityEntity = existingDayActivityEntity.getLastActivity(deviceAnonId); ActivityDto lastRegisteredActivity = ActivityDto.createInstance(existingActivityEntity); service.updateTimeLastActivity(createPayload(t2, t3), GoalDto.createInstance(gamblingGoal), lastRegisteredActivity);//from w w w .j av a2s . c o m assertThat("Expect start time same", existingActivityEntity.getStartTimeAsZonedDateTime(), equalTo(t1)); assertThat("Expect end time updated", existingActivityEntity.getEndTimeAsZonedDateTime(), equalTo(t3)); }
From source file:nu.yona.server.analysis.service.ActivityUpdateServiceTest.java
@Test public void addActivity_durationLessThanOneMinute_minimumDurationOneMinute() { ZonedDateTime t1 = now(); ZonedDateTime t2 = t1.plusSeconds(59); service.addActivity(userAnonEntity, createPayload(t1, t2), GoalDto.createInstance(gamblingGoal), Optional.empty());//w w w. j a v a 2 s. c o m List<WeekActivity> weekActivities = gamblingGoal.getWeekActivities(); assertThat("One week activity present or created", weekActivities.size(), equalTo(1)); List<DayActivity> dayActivities = weekActivities.get(0).getDayActivities(); assertThat("One day activity present or created", dayActivities.size(), equalTo(1)); List<Activity> activities = dayActivities.get(0).getActivities(); assertThat("One activity present or created", activities.size(), equalTo(1)); Activity activity = activities.get(0); assertThat("Expect right goal set to activity", activity.getActivityCategory(), equalTo(gamblingGoal.getActivityCategory())); assertThat(activity.getStartTimeAsZonedDateTime(), equalTo(t1)); assertThat(activity.getEndTimeAsZonedDateTime(), equalTo(t1.plusMinutes(1))); }
From source file:com.example.geomesa.cassandra.CassandraQuickStart.java
static FeatureCollection createNewFeatures(SimpleFeatureType simpleFeatureType, int numNewFeatures) { DefaultFeatureCollection featureCollection = new DefaultFeatureCollection(); String id;// ww w. j av a 2 s. c om Object[] NO_VALUES = {}; String[] PEOPLE_NAMES = { "Addams", "Bierce", "Clemens" }; Long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L; Random random = new Random(5771); ZonedDateTime MIN_DATE = ZonedDateTime.of(2014, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); Double MIN_X = -78.0; Double MIN_Y = -39.0; Double DX = 2.0; Double DY = 2.0; for (int i = 0; i < numNewFeatures; i++) { // create the new (unique) identifier and empty feature shell id = "Observation." + Integer.toString(i); SimpleFeature simpleFeature = SimpleFeatureBuilder.build(simpleFeatureType, NO_VALUES, id); // be sure to tell GeoTools explicitly that you want to use the ID you provided simpleFeature.getUserData().put(Hints.USE_PROVIDED_FID, java.lang.Boolean.TRUE); // populate the new feature's attributes // string value simpleFeature.setAttribute("Who", PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // long value simpleFeature.setAttribute("What", i); // location: construct a random point within a 2-degree-per-side square double x = MIN_X + random.nextDouble() * DX; double y = MIN_Y + random.nextDouble() * DY; Geometry geometry = WKTUtils.read("POINT(" + x + " " + y + ")"); // date-time: construct a random instant within a year simpleFeature.setAttribute("Where", geometry); ZonedDateTime dateTime = MIN_DATE.plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)); simpleFeature.setAttribute("When", Date.from(dateTime.toInstant())); // another string value // "Why"; left empty, showing that not all attributes need values // accumulate this new feature in the collection featureCollection.add(simpleFeature); } return featureCollection; }
From source file:com.example.geomesa.lambda.LambdaQuickStart.java
@Override public void run() { try {// w w w .j a v a 2 s.co m // create the schema final String sftName = "lambda-quick-start"; final String sftSchema = "name:String,age:Int,dtg:Date,*geom:Point:srid=4326"; SimpleFeatureType sft = SimpleFeatureTypes.createType(sftName, sftSchema); if (ds.getSchema(sftName) != null) { out.println("'" + sftName + "' feature type already exists - quick start will not work correctly"); out.println("Please delete it and re-run"); return; } out.println("Creating feature type '" + sftName + "'"); ds.createSchema(sft); out.println("Feature type created - register the layer '" + sftName + "' in geoserver then hit <enter> to continue"); in.read(); SimpleFeatureWriter writer = ds.getFeatureWriterAppend(sftName, Transaction.AUTO_COMMIT); out.println("Writing features to Kafka... refresh GeoServer layer preview to see changes"); // creates and adds SimpleFeatures to the producer every 1/5th of a second final int COUNT = 1000; final int MIN_X = -180; final int MAX_X = 180; final int MIN_Y = -90; final int MAX_Y = 90; final int DX = 2; final String[] PEOPLE_NAMES = { "James", "John", "Peter", "Hannah", "Claire", "Gabriel" }; final long SECONDS_PER_YEAR = 365L * 24L * 60L * 60L; ZonedDateTime MIN_DATE = ZonedDateTime.of(2015, 1, 1, 0, 0, 0, 0, ZoneOffset.UTC); final Random random = new Random(); int numUpdates = (MAX_X - MIN_X) / DX; for (int j = 0; j < numUpdates; j++) { for (int i = 0; i < COUNT; i++) { SimpleFeature feature = writer.next(); feature.setAttribute(0, PEOPLE_NAMES[i % PEOPLE_NAMES.length]); // name feature.setAttribute(1, (int) Math.round(random.nextDouble() * 110)); // age feature.setAttribute(2, Date.from(MIN_DATE .plusSeconds((int) Math.round(random.nextDouble() * SECONDS_PER_YEAR)).toInstant())); // dtg feature.setAttribute(3, "POINT(" + (MIN_X + (DX * j)) + " " + (MIN_Y + ((MAX_Y - MIN_Y) / ((double) COUNT)) * i) + ")"); // geom feature.getUserData().put(Hints.PROVIDED_FID, String.format("%04d", i)); writer.write(); } Thread.sleep(200); } writer.close(); out.println("Waiting for expiry and persistence..."); long total = 0, persisted = 0; do { long newTotal = (long) ds.stats().getCount(sft, Filter.INCLUDE, true).get(); long newPersisted = (long) ((AccumuloDataStore) ds.persistence()).stats() .getCount(sft, Filter.INCLUDE, true).get(); if (newTotal != total || newPersisted != persisted) { total = newTotal; persisted = newPersisted; out.println("Total features: " + total + ", features persisted to Accumulo: " + persisted); } Thread.sleep(100); } while (persisted < COUNT || total > COUNT); } catch (Exception e) { throw new RuntimeException(e); } finally { ds.dispose(); } }
From source file:org.thingsboard.server.service.security.model.token.JwtTokenFactory.java
public JwtToken createRefreshToken(SecurityUser securityUser) { if (StringUtils.isBlank(securityUser.getEmail())) { throw new IllegalArgumentException("Cannot create JWT Token without username/email"); }/* w ww . ja va2s . c o m*/ ZonedDateTime currentTime = ZonedDateTime.now(); UserPrincipal principal = securityUser.getUserPrincipal(); Claims claims = Jwts.claims().setSubject(principal.getValue()); claims.put(SCOPES, Collections.singletonList(Authority.REFRESH_TOKEN.name())); claims.put(USER_ID, securityUser.getId().getId().toString()); claims.put(IS_PUBLIC, principal.getType() == UserPrincipal.Type.PUBLIC_ID); String token = Jwts.builder().setClaims(claims).setIssuer(settings.getTokenIssuer()) .setId(UUID.randomUUID().toString()).setIssuedAt(Date.from(currentTime.toInstant())) .setExpiration(Date.from(currentTime.plusSeconds(settings.getRefreshTokenExpTime()).toInstant())) .signWith(SignatureAlgorithm.HS512, settings.getTokenSigningKey()).compact(); return new AccessJwtToken(token, claims); }