List of usage examples for java.time LocalDateTime now
public static LocalDateTime now()
From source file:com.doctor.esper.reference_5_2_0.Chapter6EPLReferenceNamedWindowsAndTables.java
/** * 6.2.2. Inserting Into Named Windows//from w ww .j a v a 2 s . c o m * FIFO? * jdbc? * * @throws InterruptedException */ @Test public void test_Inserting_Into_Named_Windows() 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(2, UUID.randomUUID().toString(), "www.baidu.com/tie", "www.baidu.com/ba", "userAgent 2", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); List<HttpLog> list = httpLogWinTime10SecQuery .executeQuery(Chapter6EPLReferenceNamedWindowsAndTables::httpLogMapRow); System.out.println(list); TimeUnit.SECONDS.sleep(5); List<HttpLog> list2 = httpLogWinTime10SecQuery .executeQuery(Chapter6EPLReferenceNamedWindowsAndTables::httpLogMapRow); System.out.println(list2); httpLog = new HttpLog(3, UUID.randomUUID().toString(), "www.baidu.com/tie", "www.baidu.com/ba", "userAgent 2", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); httpLog = new HttpLog(4, UUID.randomUUID().toString(), "www.baidu.com/tie", "www.baidu.com/ba", "userAgent 2", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); httpLog = new HttpLog(5, UUID.randomUUID().toString(), "www.baidu.com/tie", "www.baidu.com/ba", "userAgent 2", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); list = httpLogWinTime10SecQuery.executeQuery(Chapter6EPLReferenceNamedWindowsAndTables::httpLogMapRow); System.out.println(list); TimeUnit.SECONDS.sleep(5); for (int i = 0; i < 10; i++) { httpLog = new HttpLog(i + 15, UUID.randomUUID().toString(), "www.baidu.com/tie", "www.baidu.com/ba", "userAgent 2", LocalDateTime.now()); esperTemplateBean.sendEvent(httpLog); list = httpLogWinTime10SecQuery.executeQuery(Chapter6EPLReferenceNamedWindowsAndTables::httpLogMapRow); System.out.println(list); TimeUnit.SECONDS.sleep(2); } }
From source file:fr.lepellerin.ecole.service.internal.CantineServiceImpl.java
@Override @Transactional(readOnly = true)//from w w w .j a v a 2 s. c om public PlanningDto getDateOuvert(final YearMonth anneeMois, final Famille famille) throws TechnicalException { final Date startDate = Date.from(Instant.from(anneeMois.atDay(1).atStartOfDay(ZoneId.systemDefault()))); final Date endDate = Date.from(Instant.from(anneeMois.atEndOfMonth().atStartOfDay(ZoneId.systemDefault()))); final Activite activite = getCantineActivite(); final LocalDateTime heureH = LocalDateTime.now(); final List<Inscription> icts = this.ictRepository.findByActiviteAndFamille(activite, famille); final PlanningDto planning = new PlanningDto(); icts.forEach(ict -> { planning.getHeaders().add(ict.getIndividu().getPrenom()); final List<Consommation> consos = this.consommationRepository .findByFamilleInscriptionActiviteUniteEtatsPeriode(famille, activite, ict.getGroupe(), Arrays.asList("reservation"), startDate, endDate); final List<Ouverture> ouvertures = this.ouvertureRepository.findByActiviteAndGroupeAndPeriode(activite, ict.getGroupe(), startDate, endDate); ouvertures.forEach(o -> { final LocalDate date = LocalDate.from(((java.sql.Date) o.getDate()).toLocalDate()); final LocalDateTime heureResa = this.getLimiteResaCantine(date); final LigneDto ligne = planning.getOrCreateLigne(date); final CaseDto c = new CaseDto(); c.setDate(date); c.setIndividu(ict.getIndividu()); c.setActivite(o.getActivite()); c.setUnite(o.getUnite()); c.setReservable(heureResa.isAfter(heureH)); final Optional<Consommation> cOpt = consos.stream().filter(conso -> { final LocalDate dateConso = LocalDate.from(((java.sql.Date) conso.getDate()).toLocalDate()); return dateConso.equals(date); }).findAny(); c.setReserve(cOpt.isPresent()); ligne.getCases().add(c); }); }); return planning; }
From source file:de.alpharogroup.user.service.UserTokensBusinessService.java
/** * {@inheritDoc}/* w ww . j a v a 2 s. c om*/ */ @Override public String newAuthenticationToken(String username) { UserTokens userTokens = find(username); if (userTokens == null) { userTokens = merge(newUserTokens(username)); } // check if expired Date now = Date.from(LocalDateTime.now().atZone(ZoneId.systemDefault()).toInstant()); if (userTokens.getExpiry().before(now)) { // expires in one year Date expiry = Date.from(LocalDateTime.now().plusMonths(12).atZone(ZoneId.systemDefault()).toInstant()); // create a token String token = RandomExtensions.randomToken(); userTokens.setExpiry(expiry); userTokens.setToken(token); userTokens = merge(userTokens); } return userTokens.getToken(); }
From source file:com.fns.grivet.service.NamedQueryServiceSprocTest.java
@Test public void testNamedQueryNotFound() throws IOException { Assertions.assertThrows(IllegalArgumentException.class, () -> { MultiValueMap<String, Object> params = new LinkedMultiValueMap<>(); Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1)); params.add("createdTime", tomorrow); namedQueryService.get("sproc.getAttributesCreatedBefore", params); });/*from w w w . j a va 2 s.c o m*/ }
From source file:org.wallride.service.TagService.java
@CacheEvict(value = { WallRideCacheConfiguration.ARTICLE_CACHE, WallRideCacheConfiguration.PAGE_CACHE }, allEntries = true) public Tag updateTag(TagUpdateRequest request, AuthorizedUser authorizedUser) { Tag tag = tagRepository.findOneForUpdateByIdAndLanguage(request.getId(), request.getLanguage()); LocalDateTime now = LocalDateTime.now(); if (!ObjectUtils.nullSafeEquals(tag.getName(), request.getName())) { Tag duplicate = tagRepository.findOneByNameAndLanguage(request.getName(), request.getLanguage()); if (duplicate != null) { throw new DuplicateNameException(request.getName()); }/*from ww w. j av a2 s . c o m*/ } tag.setName(request.getName()); tag.setLanguage(request.getLanguage()); tag.setUpdatedAt(now); tag.setUpdatedBy(authorizedUser.toString()); return tagRepository.saveAndFlush(tag); }
From source file:fr.pilato.elasticsearch.crawler.fs.rest.UploadApi.java
@POST @Produces(MediaType.APPLICATION_JSON)//from ww w .j av a2s.co m @Consumes(MediaType.MULTIPART_FORM_DATA) public UploadResponse post(@QueryParam("debug") String debug, @QueryParam("simulate") String simulate, @FormDataParam("id") String id, @FormDataParam("file") InputStream filecontent, @FormDataParam("file") FormDataContentDisposition d) throws IOException, NoSuchAlgorithmException { // Create the Doc object Doc doc = new Doc(); String filename = new String(d.getFileName().getBytes("ISO-8859-1"), "UTF-8"); long filesize = d.getSize(); // File doc.getFile().setFilename(filename); doc.getFile().setExtension(FilenameUtils.getExtension(filename).toLowerCase()); doc.getFile().setIndexingDate(localDateTimeToDate(LocalDateTime.now())); // File // Path if (id == null) { id = SignTool.sign(filename); } else if (id.equals("_auto_")) { // We are using a specific id which tells us to generate a unique _id like elasticsearch does id = TIME_UUID_GENERATOR.getBase64UUID(); } doc.getPath().setVirtual(filename); doc.getPath().setReal(filename); // Path // Read the file content TikaDocParser.generate(settings, filecontent, filename, doc, messageDigest, filesize); String url = null; if (Boolean.parseBoolean(simulate)) { logger.debug("Simulate mode is on, so we skip sending document [{}] to elasticsearch.", filename); } else { logger.debug("Sending document [{}] to elasticsearch.", filename); bulkProcessor .add(new org.elasticsearch.action.index.IndexRequest(settings.getElasticsearch().getIndex(), "doc", id).setPipeline(settings.getElasticsearch().getPipeline()) .source(DocParser.toJson(doc), XContentType.JSON)); // Elasticsearch entity coordinates (we use the first node address) Elasticsearch.Node node = settings.getElasticsearch().getNodes().get(0); url = buildUrl(node.getScheme().toLowerCase(), node.getHost(), node.getPort()) + "/" + settings.getElasticsearch().getIndex() + "/" + "doc" + "/" + id; } UploadResponse response = new UploadResponse(); response.setOk(true); response.setFilename(filename); response.setUrl(url); if (logger.isDebugEnabled() || Boolean.parseBoolean(debug)) { // We send the content back if debug is on or if we got in the query explicitly a debug command response.setDoc(doc); } return response; }
From source file:org.eclipse.smarthome.core.scheduler.CronHelper.java
/** * Returns CRON expression that denotes the repetition every provided * seconds/*from www. j a v a2 s. c o m*/ * * @param totalSecs the seconds (cannot be zero or negative or more than 86400) * @return the CRON expression * @throws IllegalArgumentException * if {@code totalSecs} is zero or negative or more than 86400 */ public static String createCronForRepeatEverySeconds(int totalSecs) { if (totalSecs < 0 && totalSecs <= 86400) { throw new IllegalArgumentException("Seconds cannot be zero or negative or more than 86400"); } StringBuilder builder = new StringBuilder(); if (totalSecs < 60) { builder.append(ANY).append(EACH).append(totalSecs).append(SPACE).append(ANY).append(SPACE).append(ANY) .append(SPACE).append(ANY).append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK) .append(SPACE).append(ANY); return builder.toString(); } if (totalSecs >= 60 && totalSecs < 60 * 60) { int secs = totalSecs % 60; int mins = totalSecs / 60; builder.append(secs).append(SPACE).append(ANY).append(EACH).append(mins).append(SPACE).append(ANY) .append(SPACE).append(ANY).append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK) .append(SPACE).append(ANY); return builder.toString(); } if (totalSecs >= 60 * 60 && totalSecs < 60 * 60 * 24) { int secs = totalSecs % 60; int mins = totalSecs % 3600 / 60; int hours = totalSecs / 3600; builder.append(secs).append(SPACE).append(mins).append(SPACE).append(ANY).append(EACH).append(hours) .append(SPACE).append(ANY).append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK) .append(SPACE).append(ANY); return builder.toString(); } if (totalSecs == 60 * 60 * 24) { LocalDateTime now = LocalDateTime.now(); int minute = now.getMinute(); int hour = now.getHour(); builder.append("0").append(SPACE).append(minute).append(SPACE).append(hour).append(SPACE).append(ANY) .append(SPACE).append(ANY).append(SPACE).append(DAYS_OF_WEEK).append(SPACE).append(ANY); return builder.toString(); } return EMPTY; }
From source file:com.poc.restfulpoc.service.CustomerServiceTest.java
License:asdf
@Test void testUpdateCustomer() throws EntityNotFoundException { LocalDateTime dateOfBirth = LocalDateTime.now(); this.customer.setDateOfBirth(dateOfBirth); Customer res = this.customerService.updateCustomer(this.customer, RandomUtils.nextLong()); assertThat(res).isNotNull();/*from w w w. j a v a2 s . com*/ assertThat(res.getFirstName()).isNotNull().isEqualTo("firstName"); assertThat(res.getDateOfBirth()).isNotNull().isEqualTo(dateOfBirth.toString()); }
From source file:org.jspare.jsdbc.JsdbcMockedImpl.java
@Override public ListInstancesResult listInstances() throws JsdbcException { return new ListInstancesResult(Status.SUCCESS, LocalDateTime.now(), "tid", new ListInstancesResult.ListInstances(instances)); }
From source file:com.ccserver.digital.service.LoginServiceTest.java
private CreditCardApplicationDTO getCreditCardApplicationDTO() { CreditCardApplicationDTO creditCardApplicationDTO = new CreditCardApplicationDTO(); // ----- cardType // ----- DoB/*from w w w.j av a 2s. c om*/ creditCardApplicationDTO.setDob(LocalDateTime.now()); // ----- Name creditCardApplicationDTO.setFirstName("LE"); creditCardApplicationDTO.setMiddleName("Hong"); creditCardApplicationDTO.setLastName("Thanh"); // ----- gender creditCardApplicationDTO.setGender(Gender.Male); // ----- Moblie PhoneDTO moblie = new PhoneDTO(); moblie.setCountryCode("+84"); moblie.setPhoneNumber("985481179"); creditCardApplicationDTO.setMobile(moblie); // ----- phoneBusiness PhoneDTO phoneBusiness = new PhoneDTO(); phoneBusiness.setCountryCode("+84"); phoneBusiness.setPhoneNumber("985481179"); creditCardApplicationDTO.setBusinessPhone(phoneBusiness); // ----- email creditCardApplicationDTO.setEmail("letuanthuongtin@gmail.com"); // ----- passportNumber creditCardApplicationDTO.setPassportNumber("123456789"); // ----- dateOfIssue creditCardApplicationDTO.setDateOfIssue(LocalDateTime.now()); // ----- placeOfIssue SelectionList selectionListDTO = new SelectionList(); selectionListDTO.setCategory("plauceOfise"); selectionListDTO.setCode("11"); creditCardApplicationDTO.setPlaceOfIssue(selectionListDTO); // ----- citizenship CountryDTO citizenship = new CountryDTO(); citizenship.setId(1L); citizenship.setCode("VN"); citizenship.setVi("Viet Nam"); citizenship.setEn("VietNam"); creditCardApplicationDTO.setCitizenship(citizenship); // ----- haveGreenCard creditCardApplicationDTO.setHaveGreenCard(true); // ----- isUSResident creditCardApplicationDTO.setUSResident(true); // ----- education // creditCardApplicationDTO.setEducation(EducationQualification.HighShool); // ----- maritalStatus // creditCardApplicationDTO.setMaritalStatus(MaritalStatus.Single); // ----- numberOfChildren creditCardApplicationDTO.setNumberOfChildren(4); // ----- permanent address--- // TODO: create province and district for integration test AddressDTO permanentAddress = new AddressDTO(); BaseProvinceDTO province = new BaseProvinceDTO(); province.setName("Ha Noi"); province.setId(1L); DistrictDTO districtDTO1 = new DistrictDTO(); districtDTO1.setName("Hai Ba Trung"); districtDTO1.setId(1L); permanentAddress.setDistrict(districtDTO1); permanentAddress.setProvince(province); permanentAddress.setStreet("LE Thanh NGhi"); permanentAddress.setAddressDetails("So Nha 18"); creditCardApplicationDTO.setPermanentAddress(permanentAddress); // ----- currentIsPermanent creditCardApplicationDTO.setCurrentIsPermanent(true); // ----- currentAddress creditCardApplicationDTO.setCurrentAddress(permanentAddress); // ----- typeOfEmployement creditCardApplicationDTO.setTypeOfEmployement(TypeOfEmployment.Business); // ----- licenseNumber creditCardApplicationDTO.setLicenseNumber("12345"); // ----- businessStartDate creditCardApplicationDTO.setBusinessStartDate(LocalDateTime.now()); // ----- businessTelephone PhoneDTO businessTelephone = new PhoneDTO(); businessTelephone.setCountryCode("+84"); businessTelephone.setPhoneNumber("985481179"); businessTelephone.setExt("01"); creditCardApplicationDTO.setBusinessTelephone(businessTelephone); // ----- businessAddress creditCardApplicationDTO.setBusinessAddress(permanentAddress); // ----- nameOfEmployer CompanyDTO companyDTO = new CompanyDTO(); companyDTO.setCode("111"); creditCardApplicationDTO.setNameOfEmployer(companyDTO); // ----- occupation //creditCardApplicationDTO.setOccupation("Engineer"); // ----- industry // creditCardApplicationDTO.setIndustry("finance"); // ----- yearsOfWorking creditCardApplicationDTO.setYearsOfWorking(1); // ----- monthsOfWorking creditCardApplicationDTO.setMonthsOfWorking(8); // ----- employerAddress creditCardApplicationDTO.setEmployerAddress(permanentAddress); // ----- monthlyIncome creditCardApplicationDTO.setMonthlyIncome(new BigDecimal("10")); // ----- monthlyExpenses creditCardApplicationDTO.setMonthlyExpenses(new BigDecimal("5")); // ----- securityQuestion SelectionListDTO securityQuestion = new SelectionListDTO(); securityQuestion.setId(3L); creditCardApplicationDTO.setSecurityQuestion(securityQuestion); // ----- securityAnswer creditCardApplicationDTO.setSecurityAnswer("Thanh"); // ----- referenceName creditCardApplicationDTO.setReferenceName("LE Tuan"); // ----- relationshipReference SelectionListDTO relationship = new SelectionListDTO(); relationship.setId(3L); creditCardApplicationDTO.setRelationshipReference(relationship); // ----- phoneOfReference creditCardApplicationDTO.setPhoneOfReference(moblie); // ----- branchDelivery // creditCardApplicationDTO.setDeliveryCard("Branch 1"); // ----- isSecondaryCard creditCardApplicationDTO.setSecondaryCard(true); // ----- isAccurateCommit creditCardApplicationDTO.setAccurateCommit(true); // ----- agreeTermsConditions creditCardApplicationDTO.setAgreeTermsConditions(true); return creditCardApplicationDTO; }