List of usage examples for java.time LocalDateTime now
public static LocalDateTime now()
From source file:org.jgrades.security.service.UserDetailsServiceImpl.java
private boolean isCredentialsNotExpired(User user) { Set<JgRole> userRoles = userMgntService.getUserRoles(user); int expirationDaysForRole = getExpirationDays(getRoleWithHighestPriority(userRoles)); if (expirationDaysForRole != 0) { LocalDateTime lastPasswordChangeTime = passwordDataRepository.getPasswordDataWithUser(user.getLogin()) .getLastChange();//w w w.j a v a2 s. com Duration duration = Duration.between(lastPasswordChangeTime, LocalDateTime.now()); return duration.minusDays(expirationDaysForRole).isNegative(); } else { return true; } }
From source file:io.mandrel.metrics.impl.MongoMetricsRepository.java
@Override public void sync(Map<String, Long> accumulators) { LocalDateTime now = LocalDateTime.now(); LocalDateTime keytime = now.withMinute(0).withSecond(0).withNano(0); // {global.XXX=0, global.YYY=0, ...} to {global{XXX=O, YYY=0}, ...} Stream<Pair<String, Pair<String, Long>>> map = accumulators.entrySet().stream().map(e -> { Iterable<String> results = splitter.split(e.getKey()); List<String> elts = Lists.newArrayList(results); return Pair.of(elts.get(0), Pair.of(elts.get(1), e.getValue())); });/*from w w w . j a v a 2s . c om*/ Map<String, List<Pair<String, Long>>> byKey = map.collect(Collectors.groupingBy(e -> e.getLeft(), Collectors.mapping(e -> e.getRight(), Collectors.toList()))); List<? extends WriteModel<Document>> requests = byKey.entrySet().stream().map(e -> { Document updates = new Document(); e.getValue().stream().forEach(i -> { Iterable<String> results = splitter.split(i.getKey()); List<String> elts = Lists.newArrayList(results); if (elts.size() > 1) { updates.put(elts.get(0) + "." + JsonBsonCodec.toBson(elts.get(1)), i.getValue()); } else { updates.put(i.getKey(), i.getValue()); } }); return new UpdateOneModel<Document>(Filters.eq("_id", e.getKey()), new Document("$inc", updates), new UpdateOptions().upsert(true)); }).collect(Collectors.toList()); counters.bulkWrite(requests); requests = byKey.entrySet().stream().map(e -> { List<UpdateOneModel<Document>> tsUpdates = Lists.newArrayList(); e.getValue().stream().forEach(i -> { Iterable<String> results = splitter.split(i.getKey()); List<String> elts = Lists.newArrayList(results); if (elts.size() == 1 && e.getKey().equalsIgnoreCase(MetricKeys.global())) { tsUpdates.add(new UpdateOneModel<Document>( Filters.and(Filters.eq("type", e.getKey() + MetricKeys.METRIC_DELIM + i.getKey()), Filters.eq("timestamp_hour", keytime)), new Document("$inc", new Document("values." + Integer.toString(now.getMinute()), i.getValue())), new UpdateOptions().upsert(true))); } }); return tsUpdates; }).flatMap(list -> list.stream()).collect(Collectors.toList()); timeseries.bulkWrite(requests); }
From source file:org.wallride.service.PostService.java
public List<Post> publishScheduledPosts() { logger.info("Starting public posts of the scheduled"); LocalDateTime now = LocalDateTime.now(); List<Post> posts = postRepository.findAllByStatusAndDateLessThanEqual(Post.Status.SCHEDULED, now); for (Post post : posts) { post.setStatus(Post.Status.PUBLISHED); postRepository.saveAndFlush(post); }//from w ww .j ava 2s. c o m if (!CollectionUtils.isEmpty(posts)) { cacheManager.getCache(WallRideCacheConfiguration.ARTICLE_CACHE).clear(); cacheManager.getCache(WallRideCacheConfiguration.PAGE_CACHE).clear(); } return posts; }
From source file:org.jgrades.backup.creator.EncryptArchiveJob.java
private BackupEvent getNewEvent(String message) { BackupEvent event = new BackupEvent(); event.setEventType(BackupEventType.ONGOING); event.setSeverity(BackupEventSeverity.INFO); event.setOperation(BackupOperation.BACKUPING); event.setStartTime(LocalDateTime.now()); event.setBackup(backup);/*from w w w . ja v a 2 s . com*/ event.setMessage(message); backupEventRepository.save(event); return event; }
From source file:org.jgrades.backup.creator.StartBackupJob.java
private void tryToCreateBackupFolder(File backupInstanceDir, Backup backup, BackupEvent event) throws JobExecutionException { try {/* w w w . ja v a2s . com*/ FileUtils.forceMkdir(backupInstanceDir); event.setEventType(BackupEventType.FINISHED); event.setEndTime(LocalDateTime.now()); backupEventRepository.save(event); } catch (IOException e) { LOGGER.error("Cannot create directory for backup: {}", backupInstanceDir, e); setFailureDetails(backup, event); throw new JobExecutionException(e); } }
From source file:net.sf.gazpachoquest.dbpopulator.DBPopulator.java
public void populateJavaPerformanceSurvey(Set<UserDTO> respondents) { QuestionnaireDefinitionDTO questionnaireDefinition = javaPerformanceSurveyCreator.create(); asignDefaultMailTemplate(questionnaireDefinition); questionnaireDefinitionEditorFacade.confirm(questionnaireDefinition); ResearchDTO research = ResearchDTO.with().type(ResearchAccessType.BY_INVITATION) .name("Tracked survey: " + questionnaireDefinition.getLanguageSettings().getTitle() + " started") .startDate(LocalDateTime.now()).expirationDate(LocalDateTime.of(2015, 12, 31, 12, 0, 0)).build(); research.setQuestionnaireDefinition(questionnaireDefinition); research = researchFacade.save(research); Integer researchId = research.getId(); for (UserDTO respondent : respondents) { researchFacade.addRespondent(researchId, respondent); }/*w w w. jav a 2s . c o m*/ researchFacade.changeStatus(researchId, EntityStatus.CONFIRMED); research = ResearchDTO.with().type(ResearchAccessType.OPEN_ACCESS) .name("Anonymous Survey: " + questionnaireDefinition.getLanguageSettings().getTitle() + " started") .startDate(LocalDateTime.now()).expirationDate(LocalDateTime.of(2015, 12, 31, 12, 0, 0)).build(); research.setQuestionnaireDefinition(questionnaireDefinition); research = researchFacade.save(research); }
From source file:org.pentaho.platform.web.http.api.resources.RepositoryFileStreamProvider.java
public OutputStream getOutputStream() throws Exception { String tempOutputFilePath = outputFilePath; String extension = RepositoryFilenameUtils.getExtension(tempOutputFilePath); if ("*".equals(extension)) { //$NON-NLS-1$ tempOutputFilePath = tempOutputFilePath.substring(0, tempOutputFilePath.lastIndexOf('.')); if (appendDateFormat != null) { try { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern(appendDateFormat); String formattedDate = now.format(formatter); tempOutputFilePath += formattedDate; } catch (Exception e) { logger.warn("Unable to calculate current date: " + e.getMessage()); }//from w ww . j a va 2 s.c o m } if (streamingAction != null) { String mimeType = streamingAction.getMimeType(null); if (mimeType != null && MimeHelper.getExtension(mimeType) != null) { tempOutputFilePath += MimeHelper.getExtension(mimeType); } } } RepositoryFileOutputStream outputStream = new RepositoryFileOutputStream(tempOutputFilePath, autoCreateUniqueFilename, true); outputStream.addListener(this); return outputStream; }
From source file:com.fns.grivet.service.EntityServiceTest.java
@Test public void testSchemaLinkAndValidationSuccessThenUnlink() throws IOException { registerType("TestType"); Resource r = resolver.getResource("classpath:TestTypeSchema.json"); String jsonSchema = IOUtils.toString(r.getInputStream(), Charset.defaultCharset()); JSONObject schemaObj = new JSONObject(jsonSchema); com.fns.grivet.model.Class c = schemaService.linkSchema(schemaObj); String type = c.getName();//from ww w. j a v a2s . c o m Assertions.assertEquals("TestType", type); Assertions.assertTrue(c.isValidatable()); JsonAssert.assertJsonEquals(c.getJsonSchema(), jsonSchema); r = resolver.getResource("classpath:TestTypeData.json"); String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset()); JSONObject payload = new JSONObject(json); entityService.create("TestType", payload); String result = entityService.findByCreatedTime("TestType", LocalDateTime.now().minusSeconds(3), LocalDateTime.now(), null); JSONArray resultAsJsonArray = new JSONArray(result); JsonAssert.assertJsonEquals(payload.toString(), resultAsJsonArray.get(0).toString()); c = schemaService.unlinkSchema(type); Assertions.assertFalse(c.isValidatable()); Assertions.assertNull(c.getJsonSchema()); }
From source file:ch.sbb.releasetrain.director.Director.java
private boolean laysInPast(LocalDateTime date) { return date.isBefore(LocalDateTime.now()); }
From source file:cz.muni.fi.editor.database.dao.NotificationDAOImpl.java
@Override public void markSeen(List<Notification> notifications) { if (notifications.size() > 100) { log.warn("Marking too many notifications: {}.", notifications.size()); }// w ww . ja v a 2 s.c o m LocalDateTime now = LocalDateTime.now(); getEntityManager().createQuery("UPDATE notification n SET n.seenDate = :now WHERE n.id IN :notifications") .setParameter("now", now).setParameter("notifications", notifications.stream().map(n -> n.getId()).collect(Collectors.toList())) .executeUpdate(); // direct update bypasses jpa context // hibernate does not know about entities being updated in the background // following cycle makes sure hibernate WILL refresh new values from database notifications.stream().filter(n -> getEntityManager().contains(n)) .forEach(n -> getEntityManager().refresh(n)); }