List of usage examples for java.time LocalDateTime now
public static LocalDateTime now()
From source file:org.jgrades.backup.creator.StartBackupJob.java
private BackupEvent saveBackupEventMetadataToDb(Backup backup) { 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 . j a v a2 s .c om event.setMessage("Creating directory for backup content"); backupEventRepository.save(event); return event; }
From source file:com.github.jrh3k5.habitat4j.rest.CachingAccessTokenProvider.java
/** * Determines whether or not the given access token is in need of being refreshed and evicted from the cache. * //from w w w . j a va 2s .co m * @param accessToken * The {@link AccessToken} to be evaluated for eviction from the cache. * @return {@code true} if the given access token requires a refresh; {@code false} if not. */ private boolean needsRefresh(AccessToken accessToken) { final long expirationDiff = accessToken.getExpiration().toEpochSecond(ZoneOffset.UTC) - LocalDateTime.now().toEpochSecond(ZoneOffset.UTC); return expirationDiff <= EXPIRATION_WINDOW; }
From source file:nc.noumea.mairie.appock.services.impl.StockServiceImpl.java
@Override public void creeEntreeSortieEtMouvement(ArticleStock articleStock, Integer quantiteRenseigne, TypeMouvementStock typeMouvementStock, String observation) { Integer oldQuantite = articleStock.getQuantiteStock(); String reference = articleStock.getReferenceArticleStock(); Stock stock = articleStock.getStock(); Integer quantiteActuelle = articleStock.getQuantiteStock(); Integer nouvelleQuantite = typeMouvementStock == TypeMouvementStock.SORTIE ? (quantiteActuelle - quantiteRenseigne) : (quantiteActuelle + quantiteRenseigne); if (nouvelleQuantite.equals(0)) { stock.removeArticleStock(articleStock); } else {/*from ww w .j a v a 2 s. co m*/ articleStock.setQuantiteStock(nouvelleQuantite); articleStockRepository.save(articleStock); } AppUser currentUser = authHelper.getCurrentUser(); MouvementStock mouvementStock = new MouvementStock(); mouvementStock.setDateMouvement(LocalDateTime.now()); mouvementStock.setMouvementUser(currentUser.getNomComplet()); mouvementStock.setQuantiteRenseigne(quantiteRenseigne); mouvementStock.setOldQuantiteStock(oldQuantite); mouvementStock.setNewQuantiteStock(nouvelleQuantite); mouvementStock.setObservation(observation); mouvementStock.setReference(reference); mouvementStock.setTypeMouvementStock(typeMouvementStock); mouvementStock.setStock(stock); stock.getListeMouvementStock().add(mouvementStock); stockRepository.save(stock); }
From source file:net.jmhertlein.mcanalytics.api.auth.SSLUtil.java
/** * Creates a new self-signed X509 certificate * * @param pair the public/private keypair- the pubkey will be added to the cert and the private * key will be used to sign the certificate * @param subject the distinguished name of the subject * @param isAuthority true to make the cert a CA cert, false otherwise * @return// w w w . j a v a2s. c o m */ public static X509Certificate newSelfSignedCertificate(KeyPair pair, X500Name subject, boolean isAuthority) { X509v3CertificateBuilder b = new JcaX509v3CertificateBuilder(subject, BigInteger.probablePrime(128, new SecureRandom()), Date.from(Instant.now().minusSeconds(1)), Date.from(LocalDateTime.now().plusYears(3).toInstant(ZoneOffset.UTC)), subject, pair.getPublic()); try { b.addExtension(Extension.basicConstraints, true, new BasicConstraints(isAuthority)); } catch (CertIOException ex) { Logger.getLogger(SSLUtil.class.getName()).log(Level.SEVERE, null, ex); } try { X509CertificateHolder bcCert = b.build( new JcaContentSignerBuilder(SIGNING_ALGORITHM).setProvider("BC").build(pair.getPrivate())); return new JcaX509CertificateConverter().setProvider("BC").getCertificate(bcCert); } catch (CertificateException | OperatorCreationException ex) { Logger.getLogger(SSLUtil.class.getName()).log(Level.SEVERE, null, ex); return null; } }
From source file:no.kantega.openaksess.search.searchlog.action.ViewSearchLogAction.java
private void defaultSearch(Map<String, Object> model, int siteId) { LocalDateTime now = LocalDateTime.now(); LocalDateTime thirtyMinutesAgo = now.minusMinutes(30); model.put("last30min", searchLogDao.getSearchCountForPeriod(thirtyMinutesAgo, now, siteId)); LocalDateTime oneMonthAgo = now.minusDays(30); model.put("sumLastMonth", searchLogDao.getSearchCountForPeriod(oneMonthAgo, now, siteId)); model.put("most", searchLogDao.getMostPopularQueries(siteId, 100)); model.put("least", searchLogDao.getQueriesWithLeastHits(siteId, 100)); }
From source file:com.poc.restfulpoc.controller.CustomerControllerTest.java
@Test void testUpdateCustomer() throws Exception { given(this.customerService.getCustomer(ArgumentMatchers.anyLong())).willReturn(this.customer); LocalDateTime dateOfBirth = LocalDateTime.now(); this.customer.setDateOfBirth(dateOfBirth); given(this.customerService.updateCustomer(ArgumentMatchers.any(Customer.class), ArgumentMatchers.anyLong())) .willReturn(this.customer); this.mockMvc/*from w ww . j a va2 s . c om*/ .perform(MockMvcRequestBuilders.put("/rest/customers/{customerId}", RandomUtils.nextLong()) .content(this.objectMapper.writeValueAsString(this.customer)) .contentType(MediaType.APPLICATION_JSON_UTF8)) .andExpect(status().isOk()).andExpect(jsonPath("firstName").value("firstName")) .andExpect(jsonPath("lastName").value("lastName")) .andExpect(jsonPath("dateOfBirth").value(dateOfBirth.toString())); }
From source file:net.ceos.project.poi.annotated.bean.MultiTypeObjectBuilder.java
/** * Validate the MultiTypeObject based on the object build with the method * 'buildMultiTypeObject'//from w w w . j a v a 2 s . co m * * @param toValidate * the object to validate */ public static void validateMultiTypeObject(MultiTypeObject toValidate) { MultiTypeObject base = buildMultiTypeObject(); Calendar calendar = Calendar.getInstance(); calendar.setTime(new Date()); Calendar calendarUnmarshal = Calendar.getInstance(); calendarUnmarshal.setTime(toValidate.getDateAttribute()); assertEquals(calendar.get(Calendar.YEAR), calendarUnmarshal.get(Calendar.YEAR)); assertEquals(calendar.get(Calendar.MONTH), calendarUnmarshal.get(Calendar.MONTH)); assertEquals(calendar.get(Calendar.DAY_OF_MONTH), calendarUnmarshal.get(Calendar.DAY_OF_MONTH)); LocalDate localDate = LocalDate.now(); assertEquals(localDate.getDayOfMonth(), toValidate.getLocalDateAttribute().getDayOfMonth()); assertEquals(localDate.getMonth(), toValidate.getLocalDateAttribute().getMonth()); assertEquals(localDate.getYear(), toValidate.getLocalDateAttribute().getYear()); LocalDateTime localDateTime = LocalDateTime.now(); assertEquals(localDateTime.getDayOfMonth(), toValidate.getLocalDateTimeAttribute().getDayOfMonth()); assertEquals(localDateTime.getMonth(), toValidate.getLocalDateTimeAttribute().getMonth()); assertEquals(localDateTime.getYear(), toValidate.getLocalDateTimeAttribute().getYear()); assertEquals(localDateTime.getHour(), toValidate.getLocalDateTimeAttribute().getHour()); /* it is possible to have an error below due the time of execution of the test */ assertEquals(localDateTime.getMinute(), toValidate.getLocalDateTimeAttribute().getMinute()); assertEquals(base.getStringAttribute(), toValidate.getStringAttribute()); assertEquals(base.getIntegerAttribute(), toValidate.getIntegerAttribute()); assertEquals(base.getDoubleAttribute(), toValidate.getDoubleAttribute()); assertEquals(base.getLongAttribute(), toValidate.getLongAttribute()); assertEquals(base.getBooleanAttribute(), toValidate.getBooleanAttribute()); assertEquals(base.getJob().getJobCode(), toValidate.getJob().getJobCode()); assertEquals(base.getJob().getJobFamily(), toValidate.getJob().getJobFamily()); assertEquals(base.getJob().getJobName(), toValidate.getJob().getJobName()); assertEquals(base.getIntegerPrimitiveAttribute(), toValidate.getIntegerPrimitiveAttribute()); assertEquals(base.getDoublePrimitiveAttribute(), toValidate.getDoublePrimitiveAttribute()); assertEquals(base.getLongPrimitiveAttribute(), toValidate.getLongPrimitiveAttribute()); assertEquals(base.isBooleanPrimitiveAttribute(), toValidate.isBooleanPrimitiveAttribute()); assertEquals(base.getAddressInfo().getAddress(), toValidate.getAddressInfo().getAddress()); assertEquals(base.getAddressInfo().getNumber(), toValidate.getAddressInfo().getNumber()); assertEquals(base.getAddressInfo().getCity(), toValidate.getAddressInfo().getCity()); assertEquals(base.getAddressInfo().getCityCode(), toValidate.getAddressInfo().getCityCode()); assertEquals(base.getAddressInfo().getCountry(), toValidate.getAddressInfo().getCountry()); assertEquals(base.getFloatAttribute(), toValidate.getFloatAttribute()); assertEquals(base.getFloatPrimitiveAttribute(), toValidate.getFloatPrimitiveAttribute()); assertEquals(base.getUnitFamily(), toValidate.getUnitFamily()); assertEquals(base.getBigDecimalAttribute(), toValidate.getBigDecimalAttribute()); assertEquals(base.getShortAttribute(), toValidate.getShortAttribute()); assertEquals(base.getShortPrimitiveAttribute(), toValidate.getShortPrimitiveAttribute()); // TODO add new validation below }
From source file:fi.vrk.xroad.catalog.persistence.MemberRepositoryTest.java
private Member createTestMember(String name) { Member member = new Member(); member.setName(name);/*from www. j a v a 2 s .co m*/ member.setXRoadInstance("xroadinstance-" + name); member.setMemberClass("mclass-" + name); member.setMemberCode("mcode-" + name); member.getStatusInfo().setTimestampsForNew(LocalDateTime.now()); Subsystem ss1 = new Subsystem(); Subsystem ss2 = new Subsystem(); ss1.setSubsystemCode(name + "ss1"); ss2.setSubsystemCode(name + "ss2"); ss1.setMember(member); ss2.setMember(member); ss1.getStatusInfo().setTimestampsForNew(LocalDateTime.now()); ss2.getStatusInfo().setTimestampsForNew(LocalDateTime.now()); member.setSubsystems(new HashSet<>()); member.getAllSubsystems().add(ss1); member.getAllSubsystems().add(ss2); Service s1 = new Service(); Service s2 = new Service(); s1.getStatusInfo().setTimestampsForNew(LocalDateTime.now()); s2.getStatusInfo().setTimestampsForNew(LocalDateTime.now()); s1.setSubsystem(ss1); s2.setSubsystem(ss1); ss2.setServices(new HashSet<>()); ss2.getAllServices().add(s1); ss2.getAllServices().add(s2); s1.setServiceCode(name + "service1"); s2.setServiceCode(name + "service2"); Wsdl wsdl = new Wsdl(); wsdl.getStatusInfo().setTimestampsForNew(LocalDateTime.now()); s1.setWsdl(wsdl); wsdl.setService(s1); wsdl.initializeExternalId(); wsdl.setData("<?xml version=\"1.0\" standalone=\"no\"?><wsdl/>"); return member; }
From source file:controller.UpdateEC.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods./*w w w. ja v a2s.c o m*/ * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html;charset=UTF-8"); ExtenuatingCircumstance ec = new ExtenuatingCircumstance(); if (ServletFileUpload.isMultipartContent(request)) { try { String fname = StringUtils.EMPTY; String title = StringUtils.EMPTY; String desciption = StringUtils.EMPTY; String status = StringUtils.EMPTY; int id = 0; List<FileItem> multiparts = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); ArrayList<FileItem> files = new ArrayList<>(); for (FileItem item : multiparts) { if (item.isFormField()) { if (item.getFieldName().equals("id")) { id = Integer.parseInt(item.getString()); System.out.println("id: " + id); } if (item.getFieldName().equals("title")) { title = item.getString(); } if (item.getFieldName().equals("description")) { desciption = item.getString(); } if (item.getFieldName().equals("status")) { status = item.getString(); System.out.println("status: " + status); } } else { if (StringUtils.isNotEmpty(item.getName())) { files.add(item); } } } HttpSession session = request.getSession(false); Account studentAccount = (Account) session.getAttribute("account"); DateTimeFormatter dtf = DateTimeFormatter.ofPattern("dd/MM/yyyy HH:mm:ss"); LocalDateTime now = LocalDateTime.now(); // insert EC ec.setId(id); ec.setTitle(title); ec.setDescription(desciption); ec.setProcess_status(status); //ec.setSubmitted_date(now.toString()); ec.setAccount(studentAccount.getId()); new ExtenuatingCircumstanceDAO().updateEC(ec, "student"); //insert additional evident evidence if (files.size() > 0) { insertedEvidence(files, now, ec, studentAccount); } request.setAttribute("resultMsg", "updated"); request.getRequestDispatcher("AddNewECResult.jsp").forward(request, response); } catch (Exception e) { e.printStackTrace(); } } else { request.setAttribute("message", "Sorry this Servlet only handles file upload request"); } }
From source file:beans.BL.java
public void test(TPVObject tpv) { /**//w ww .j a v a2s .co m * Neue Idee alles zu speichern */ /*Umwandlung von Double in LDT Problem das es zu ungenau ist Double test = (tpv.getTimestamp()); long int_timestamp = test.longValue(); LocalDateTime ldt = LocalDateTime.ofEpochSecond(int_timestamp, 0, ZoneOffset.UTC); */ System.out.println( tpv.getTimestamp() + " Longitude: " + tpv.getLatitude() + " Latitude: " + tpv.getLongitude()); //TODO: /** * Algorithmus um die gefahrenen Km zu messen */ if (tpv.getSpeed() > 2.77) { if (latOld == -1 && lonOld == -1) { latNew = tpv.getLatitude(); lonNew = tpv.getLongitude(); } latOld = latNew; lonOld = lonNew; latNew = tpv.getLatitude(); lonNew = tpv.getLongitude(); double R = 6371000; // metres double dLat = Math.toRadians(latNew - latOld); double dLon = Math.toRadians(lonNew - lonOld); double a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(Math.toRadians(latOld)) * Math.cos(Math.toRadians(latNew)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); d = d + (R * c); System.out.println("Distance:" + d + "Speed:" + tpv.getSpeed()); } Point point = new Point(LocalDateTime.now(), tpv.getLatitude(), tpv.getLongitude(), d, tpv.getSpeed(), track); try { points.put(point); } catch (InterruptedException ex) { Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex); } try { System.out.println("points size:" + points.size()); System.out.println("traks size:" + tracks.size()); for (Track track1 : tracks) { System.out.println("track: " + track1.getId()); } data_manager.writeFile(points); } catch (ParseException ex) { Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex); } catch (IOException ex) { Logger.getLogger(BL.class.getName()).log(Level.SEVERE, null, ex); } }