List of usage examples for java.time LocalDateTime now
public static LocalDateTime now()
From source file:fr.lepellerin.ecole.service.internal.CantineServiceImpl.java
@Override @Transactional(readOnly = false)/*from ww w . j a v a 2 s .co m*/ public String reserver(final LocalDate date, final int individuId, final Famille famille, final Boolean reserve) throws FunctionalException, TechnicalException { final LocalDateTime heureResa = this.getLimiteResaCantine(date); if (!heureResa.isAfter(LocalDateTime.now())) { throw new ActNonModifiableException("activite non reservable"); } final Date d = Date.from(Instant.from(date.atStartOfDay(ZoneId.systemDefault()))); final Activite activite = getCantineActivite(); final List<Inscription> icts = this.ictRepository.findByActiviteAndFamille(activite, famille); final Inscription ict = icts.stream().filter(i -> individuId == i.getIndividu().getId()).findFirst().get(); final List<Consommation> consos = this.consommationRepository.findByInscriptionActiviteUniteDate(ict, activite, ict.getGroupe(), d); final Unite unite = this.uniteRepository.findOneByActiviteAndType(ict.getActivite(), "Unitaire"); if ((reserve == null && consos != null && !consos.isEmpty()) || (reserve != null && reserve == false && consos != null && !consos.isEmpty())) { consos.forEach(c -> this.consommationRepository.delete(c)); return "libre"; // on supprime la conso } else if ((reserve == null && (consos == null || consos.isEmpty())) || (reserve == true && (consos == null || consos.isEmpty()))) { // cree la conso final Consommation conso = new Consommation(); conso.setActivite(activite); conso.setDate(d); conso.setDateSaisie(new Date()); conso.setEtat("reservation"); conso.setGroupe(ict.getGroupe()); conso.setIndividu(ict.getIndividu()); conso.setInscription(ict); conso.setComptePayeur(ict.getComptePayeur()); conso.setCategorieTarif(ict.getCategorieTarif()); conso.setUnite(unite); conso.setHeureDebut(unite.getHeureDebut()); conso.setHeureFin(unite.getHeureFin()); this.consommationRepository.save(conso); return "reserve"; } return "rien"; }
From source file:com.onyxscheduler.OnyxSchedulerIT.java
private Date buildPastDate() { return toDate(LocalDateTime.now().minusMinutes(1)); }
From source file:hash.HashFilesController.java
private void generateChecksums(File file) { FileInputStream md5fis;/*from w w w .j av a 2 s. c o m*/ String md5 = ""; try { md5fis = new FileInputStream(file); md5 = DigestUtils.md5Hex(md5fis); md5fis.close(); } catch (IOException ex) { Logger.getLogger(HashFilesController.class.getName()).log(Level.SEVERE, null, ex); } Checksum aChecksum = new Checksum(); aChecksum.setMD5Value(md5); ; aChecksum.setFileName(file.getName()); aChecksum.setFilePath(file.getPath()); DateTimeFormatter format = DateTimeFormatter.ofLocalizedDateTime(FormatStyle.SHORT, FormatStyle.SHORT); LocalDateTime currentDateTime = LocalDateTime.now(); currentDateTime.format(format); aChecksum.setDateTimeGenerated(currentDateTime); SessionFactory sFactory = HibernateUtilities.getSessionFactory(); Session session = sFactory.openSession(); session.beginTransaction(); session.saveOrUpdate(aChecksum); CaseFile currentCase = (CaseFile) session.get(CaseFile.class, CreateCaseController.getCaseNumber()); currentCase.getMd5Details().add(aChecksum); aChecksum.setCaseFile(currentCase); session.getTransaction().commit(); session.close(); checksumTableView.getItems().add(aChecksum); System.out.println(aChecksum.getMD5Value()); System.out.println(aChecksum.getFileName()); System.out.println(aChecksum.getFilePath()); }
From source file:nc.noumea.mairie.appock.services.impl.CommandeServiceImpl.java
private String findNextNumero() { String prefixe = LocalDateTime.now().getYear() + "-"; Commande commande = commandeRepository.findTopByNumeroStartingWithOrderByNumeroDesc(prefixe); int numero = 1; if (commande != null) { numero = Integer//from ww w. ja va 2s . co m .parseInt(commande.getNumero().substring(prefixe.length(), commande.getNumero().length())) + 1; } return prefixe + StringUtils.leftPad(String.valueOf(numero), 4, "0"); }
From source file:eu.crydee.alignment.aligner.ae.MetricsSummaryAE.java
@Override public void collectionProcessComplete() throws AnalysisEngineProcessException { try {//w w w . ja v a 2 s .co m String template = IOUtils.toString(getClass() .getResourceAsStream("/eu/crydee/alignment/aligner/ae/" + "metrics-summarizer-template.html")); String titledTemplate = template.replace("@@TITLE@@", "Metrics summarizer" + LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME)); StringBuilder sb = new StringBuilder(); sb.append("<table class=\"table table-striped ").append("table-condensed\">\n") .append(" <thead>\n").append(" <tr>\n") .append(" <th>City\\Metric</th>\n"); for (String key : keys) { sb.append(" <th>").append(methodsMetadata.get(key).getRight()).append("</th>\n"); } sb.append(" <tr>\n").append(" </thead>\n").append(" <tbody>\n"); for (String ele : results.rowKeySet()) { sb.append(" <tr>\n").append(" <td>").append(ele) .append("</td>\n"); Map<String, Samples> metricResults = results.row(ele); for (String key : keys) { Samples samples = metricResults.get(key); SummaryStatistics ss = new SummaryStatistics(); samples.samples.forEach(d -> ss.addValue(d)); double mean = ss.getMean(); boolean significant = TestUtils.tTest(samples.mu, ArrayUtils.toPrimitive(samples.samples.toArray(new Double[0])), 0.05), above = samples.mu > mean; String summary = String.format("%.3f", samples.mu) + " <small class=\"text-muted\">" + String.format("%.3f", ss.getMean()) + "" + String.format("%.3f", ss.getStandardDeviation()) + "</small>"; logger.info(ele + "\t" + key + "\t" + summary + "\t" + significant); sb.append(" <td class=\"") .append(significant ? (above ? "success" : "danger") : "warning").append("\">") .append(summary).append("</td>\n"); } sb.append(" </tr>\n"); } sb.append(" </tbody>\n").append(" </table>"); FileUtils.write(new File(htmlFilepath), titledTemplate.replace("@@TABLE@@", sb.toString()), StandardCharsets.UTF_8); } catch (IOException ex) { logger.error("IO problem with the HTML output."); throw new AnalysisEngineProcessException(ex); } }
From source file:net.sf.gazpachoquest.dbpopulator.DBPopulator.java
public void populateForJUnitTest(Set<UserDTO> respondents) { QuestionnaireDefinitionDTO questionnaireDefinition = demoSurveyCreator.create(); asignDefaultMailTemplate(questionnaireDefinition); questionnaireDefinitionEditorFacade.confirm(questionnaireDefinition); ResearchDTO research = ResearchDTO.with().type(ResearchAccessType.BY_INVITATION) .name("New private Questionnaire " + 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); }/*from w w w . jav a 2 s . c om*/ researchFacade.changeStatus(researchId, EntityStatus.CONFIRMED); research = ResearchDTO.with().type(ResearchAccessType.OPEN_ACCESS) .name("New open Questionnaire " + 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.jspare.jsdbc.JsdbcMockedImpl.java
@Override public ListDomainsResult listDomains() throws JsdbcException { List<String> domains = new ArrayList<>(); data.keySet().forEach(item -> {/*from w w w . jav a2s.co m*/ domains.add(item); }); return new ListDomainsResult(Status.SUCCESS, LocalDateTime.now(), "tid", new ListDomainsResult.ListDomain(StringUtils.EMPTY, domains)); }
From source file:com.ccserver.digital.validator.CreditCardApplicationValidatorTest.java
@Test public void validatorGeneralTest() { CreditCardApplicationDTO creditCardApplicationDTO = new CreditCardApplicationDTO(); creditCardApplicationDTO.setProcessStep(ProcessStep.General); LocalDateTime ldt = LocalDateTime.now(); creditCardApplicationDTO.setDateOfIssue(ldt); BindingResult errors = new BeanPropertyBindingResult(creditCardApplicationDTO, "target"); creditCardApplicationValidator.validate(creditCardApplicationDTO, errors); Assert.assertNull(errors.getFieldError("dateOfIssue")); }
From source file:com.doctor.esper.reference_5_2_0.Chapter6EPLReferenceNamedWindowsAndTables.java
/** * jdbc?/*from w ww. j a v a2 s . c o m*/ * * @throws InterruptedException * */ @Test public void test_jdbc_like_query() throws InterruptedException { HttpLog httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); httpLog = new HttpLog(11, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); httpLog = new HttpLog(1, UUID.randomUUID().toString(), "www.baidu.com/tieba", "www.baidu.com", "userAgent", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); String sql = "select * from HttpLogWindowTime5Sec where id = ?"; EPOnDemandPreparedQueryParameterized queryWithParameters = esperTemplateBean.getEsperNativeRuntime() .prepareQueryWithParameters(sql); queryWithParameters.setObject(1, 1); EPOnDemandQueryResult result = esperTemplateBean.getEsperNativeRuntime().executeQuery(queryWithParameters); EventBean[] beans = result.getArray(); assertThat(beans.length, equalTo(5)); System.out.println("jdbc:" + beans.length); Stream.of(beans).map(eventBean -> (HttpLog) eventBean.getUnderlying()).forEach(System.out::println); TimeUnit.SECONDS.sleep(10); result = esperTemplateBean.getEsperNativeRuntime().executeQuery(queryWithParameters); beans = result.getArray(); assertThat(beans.length, equalTo(0)); }
From source file:com.esri.geoevent.test.tools.GetMapServiceCountRunnable.java
@Override public void run() { // Trust https urls trustAll();/*from ww w .j ava2 s .com*/ // Get start count int stCnt = -3; stCnt = getMsLayerCount(this.msLayerUrl); int cnt1 = stCnt; if (stCnt < 0) { throw new UnsupportedOperationException("Couldn't get start count from BDS"); } // Wait for count to increase by the right number of events int curCnt = -3; curCnt = getMsLayerCount(this.msLayerUrl); if (curCnt < 0) { throw new UnsupportedOperationException("Couldn't get count from BDS"); } // if count stop increase for 30 seconds then exit int newCnt = curCnt; LocalDateTime et = LocalDateTime.now(); LocalDateTime st = LocalDateTime.now(); Boolean firstCountChange = true; LocalDateTime s1 = LocalDateTime.now(); LocalDateTime s2 = LocalDateTime.now(); int sampleRateCnt = stCnt + sampleInterval; while (curCnt < stCnt + numEvents) { newCnt = getMsLayerCount(this.msLayerUrl); //System.out.println(newCnt); if (newCnt < 0) { System.out.println("Couldn't get count from BDS"); } if (newCnt > curCnt) { if (firstCountChange) { sampleRateCnt = newCnt + sampleInterval; st = LocalDateTime.now(); s1 = st; firstCountChange = false; } curCnt = newCnt; et = LocalDateTime.now(); } LocalDateTime et2 = LocalDateTime.now(); Duration delta = Duration.between(et, et2); Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0; if (isSingle && curCnt > sampleRateCnt) { // Calculate the rate for the sample rates s2 = LocalDateTime.now(); Duration tm = Duration.between(s1, s2); Double secnds = (double) tm.getSeconds() + tm.getNano() / 1000000000.0; int cntChg = curCnt - cnt1; cnt1 = curCnt; Double rt = (double) cntChg / secnds; sampleRateCnt = cnt1 + sampleInterval; s1 = s2; System.out.println(curCnt - stCnt + "," + rt); if (rt < 200.0) { this.num_events_read = curCnt - stCnt; throw new UnsupportedOperationException("Rate has dropped below 200 e/s"); } } if (elapsed_seconds > 30.0) { // count hasn't changed for 30 seconds System.out.println("Features lost"); System.out.println(curCnt); break; } try { // This delay was added to prevent calls from overloading map service Thread.sleep(100); } catch (InterruptedException ex) { Logger.getLogger(GetMapServiceCountRunnable.class.getName()).log(Level.SEVERE, null, ex); } } if (st != null) { et = LocalDateTime.now(); Duration delta = Duration.between(st, et); Double elapsed_seconds = (double) delta.getSeconds() + delta.getNano() / 1000000000.0; int eventsRcvd = curCnt - stCnt; //System.out.println("Events received: " + eventsRcvd); this.average_read_per_second = (double) eventsRcvd / elapsed_seconds; this.num_events_read = eventsRcvd; } }