List of usage examples for java.time LocalDate now
public static LocalDate now()
From source file:com.epam.dlab.backendapi.service.impl.SchedulerJobServiceImpl.java
/** * Enriches existing scheduler job with the following data: * - sets current date as 'beginDate' if this parameter wasn't defined; * - sets current system time zone offset as 'timeZoneOffset' if this parameter wasn't defined. * * @param dto current scheduler job/*w w w. ja va 2 s .c om*/ */ private void enrichSchedulerJobIfNecessary(SchedulerJobDTO dto) { if (Objects.isNull(dto.getBeginDate()) || StringUtils.isBlank(dto.getBeginDate().toString())) { dto.setBeginDate(LocalDate.now()); } if (Objects.isNull(dto.getTimeZoneOffset()) || StringUtils.isBlank(dto.getTimeZoneOffset().toString())) { dto.setTimeZoneOffset(OffsetDateTime.now(ZoneId.systemDefault()).getOffset()); } }
From source file:sopho.Ofeloumenoi.AddOfeloumenoiController.java
@FXML public void Save(ActionEvent event) { if (barcode.getText().isEmpty() || onoma.getText().isEmpty() || eponimo.getText().isEmpty() || patronimo.getText().isEmpty()) { //checking if the user has filled the required fields sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null, "?!", " ? ? . ? ? Barcode, , ? ? ? ?", "error"); cm.showAndWait();/* w w w. j a v a 2 s . c o m*/ } else if (!NumberUtils.isNumber(barcode.getText()) && !barcode.getText().isEmpty()) { sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null, "?!", " barcode ? ? ??. ? ? .", "error"); cm.showAndWait(); } else if (!NumberUtils.isNumber(eisodima.getText()) && !eisodima.getText().isEmpty()) { sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null, "?!", " ? ? ??. ? ? .", "error"); cm.showAndWait(); } else {//the user has filled the required fields. We can proceed. sopho.DBClass db = new sopho.DBClass(); Connection conn = null; PreparedStatement pst = null; ResultSet rs = null; String teknaDB = ""; //we create a var to push data to db. for (int i = 0; i < tekna.getItems().size(); i++) {//we are converting the table rows to a single comma separated string to push it to the database in a single entry. tableManager tbl = (tableManager) tekna.getItems().get(i); if (!tbl.getEtos().equals("? ")) { //we are checking if the user has actually entered a number teknaDB += tbl.getEtos() + ","; //we have to call getEtos from the tableManager class to get the actual value. We add the value to teknaDB and seperate with comma. arithmosTeknon++; } } if (arithmosTeknon > 0) {// we need to catch the case that the user has not added any data to the table. teknaDB = teknaDB.substring(0, teknaDB.length() - 1); // we have to remove the last comma. } conn = db.ConnectDB(); //Now we will check if the user has already registered this ofeloumenos String sql = "SELECT * FROM ofeloumenoi WHERE barcode =?"; try { pst = conn.prepareStatement(sql); pst.setString(1, barcode.getText()); System.out.println("the query is:" + pst.toString()); rs = pst.executeQuery(); rs.last(); //i go to the last line of the result to find out the number of the line if (rs.getRow() > 0) {// ofeloumenos is already registered to the database sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null, "?!", "? ? barcode. ? ? . Barcode:" + rs.getString("barcode") + " : " + rs.getString("eponimo") + " : " + rs.getString("onoma") + " ?: " + rs.getString("patronimo"), "error"); cm.showAndWait(); } else { // we can push the data to database... sql = "INSERT INTO ofeloumenoi (barcode, eponimo, onoma, patronimo, mitronimo, imGennisis, dieuthinsi, dimos, tilefono, anergos, epaggelma, eisodima, eksartiseis, photoID, afm, tautotita, ethnikotita, metanastis, roma, oikKatastasi, hasTekna, arithmosTeknon, ilikiesTeknon, politeknos, monogoneiki, mellousaMama, amea, asfForeas, xronios, pathisi, anoTon60, monaxikos, emfiliVia, spoudastis, anenergos, loipa, registerDate) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"; pst = conn.prepareStatement(sql); //now we will set the values to the sql statement pst.setString(1, barcode.getText()); pst.setString(2, eponimo.getText()); pst.setString(3, onoma.getText()); pst.setString(4, patronimo.getText()); pst.setString(5, mitronimo.getText()); //now we have to convert the imGennisis to a suitable format to be able to push it to the database if (imGennisis.getValue() != null) { Date date = Date .from(imGennisis.getValue().atStartOfDay(ZoneId.systemDefault()).toInstant()); java.sql.Date sqlDate = new java.sql.Date(date.getTime()); pst.setDate(6, sqlDate); } else { pst.setDate(6, null); } pst.setString(7, dieuthinsi.getText()); pst.setString(8, dimos.getText()); pst.setString(9, tilefono.getText()); pst.setInt(10, anergos.isSelected() ? 1 : 0); //set 1 if selected and 0 if not. We will use this method for all the checkboxes. pst.setString(11, epaggelma.getText()); pst.setString(12, eisodima.getText()); pst.setString(13, eksartiseis.getText()); pst.setString(14, PhotoID); pst.setString(15, afm.getText()); pst.setString(16, tautotita.getText()); pst.setString(17, ethnikotita.getText()); pst.setInt(18, metanastis.isSelected() ? 1 : 0); pst.setInt(19, roma.isSelected() ? 1 : 0); pst.setInt(20, (int) oikKatastasi.getSelectionModel().getSelectedIndex());//we are pushing to database the selected index pst.setInt(21, arithmosTeknon > 0 ? 1 : 0); //checking number of tekna. if >0 has tekna gets 1 pst.setInt(22, arithmosTeknon); pst.setString(23, teknaDB); //here we use the converted to comma separated values variable in order to save the tableView data using only one field in database. pst.setInt(24, politeknos.isSelected() ? 1 : 0); pst.setInt(25, monogoneiki.isSelected() ? 1 : 0); pst.setInt(26, mellousaMama.isSelected() ? 1 : 0); pst.setInt(27, amea.isSelected() ? 1 : 0); pst.setInt(28, (int) asfForeas.getSelectionModel().getSelectedIndex());//we are pushing to database the selected index pst.setInt(29, xronios.isSelected() ? 1 : 0); pst.setString(30, pathisi.getText()); pst.setInt(31, monaxiko.isSelected() ? 1 : 0); pst.setInt(32, anoTon60.isSelected() ? 1 : 0); pst.setInt(33, emfiliVia.isSelected() ? 1 : 0); pst.setInt(34, spoudastis.isSelected() ? 1 : 0); pst.setInt(35, anenergos.isSelected() ? 1 : 0); pst.setString(36, loipa.getText()); //insert today's date as registerDate LocalDate now = LocalDate.now(); java.sql.Date sqlToday = java.sql.Date.valueOf(now); pst.setDate(37, sqlToday); System.out.println("the query is:" + pst.toString()); int linesAffected = pst.executeUpdate(); //checking if the data were inserted to the database successfully if (linesAffected > 0) { Stage stage = (Stage) barcode.getScene().getWindow(); try { sl.StageLoad("/sopho/Ofeloumenoi/AddMore.fxml", stage, false, true); //resizable false, utility true } catch (IOException ex) { Logger.getLogger(AddOfeloumenoiController.class.getName()).log(Level.SEVERE, null, ex); } } else {//problem inserting data... sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null, "?!", " ? ? ? . ? ...", "error"); cm.showAndWait(); } } } catch (SQLException e) { System.out.println( "? ? ? !" + e); } } }
From source file:net.jmhertlein.alphonseirc.AlphonseBot.java
private void handleDadCommand(final String target, String sender, String[] args) { if (args.length == 1) { sendMessage(target, "Usage: !dad [left|list|say]"); return;//w ww. ja va 2 s . c om } switch (args[1]) { case "left": ZonedDateTime now = ZonedDateTime.now(); this.dadLeaveTimes.put(LocalDate.now(), LocalTime.now()); sendMessage(target, "Marked dad's leave time as now (" + now.format(DateTimeFormatter.ISO_LOCAL_TIME) + ")."); break; case "list": int num = 3; if (args.length == 3) { try { num = Integer.parseInt(args[2]); if (num > 10) num = 10; } catch (NumberFormatException nfe) { sendMessage(target, "Error parsing " + args[2] + " into int: " + nfe.getMessage()); sendMessage(target, "Usage: !dad list (optional: number, default 3, max 10)"); return; } } final int prevDays = num; dadLeaveTimes.keySet().stream().sorted() .filter(date -> date.isAfter(LocalDate.now().minusDays(prevDays))) .map(date -> date.format(DateTimeFormatter.ISO_LOCAL_DATE) + " || " + dadLeaveTimes.get(date).format(DateTimeFormatter.ISO_LOCAL_TIME)) .forEach(leaveTime -> sendMessage(target, leaveTime)); break; case "say": String msg; switch (gen.nextInt(9)) { case 0: msg = "TYPES LOUDLY"; break; case 1: msg = "BREATHES DEEPLY"; break; case 2: msg = "ANGRILY TYPES AN EMAIL"; break; case 3: msg = "BACKSPACES WITH AUTHORITY"; break; case 4: msg = "STRETCHES WHILE EXHALING"; break; case 5: msg = "thinks about Happy Hour"; break; case 6: msg = "browses Yahoo! news"; break; case 7: msg = "tells everyone to GET BACK TO WORK"; break; case 8: msg = "ignores Lantzer standing in front of his desk"; break; default: msg = "Someone made nextInt() go too high"; break; } this.sendAction(target, msg); break; default: System.out.println("Bad switch on " + args[1]); } }
From source file:alfio.manager.system.DataMigratorIntegrationTest.java
@Test public void testFixStuckTickets() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", AVAILABLE_SEATS, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> eventUsername = initEvent(categories); Event event = eventUsername.getKey(); TicketReservationModification trm = new TicketReservationModification(); trm.setAmount(1);//from w w w . j a v a 2 s. c o m trm.setTicketCategoryId(eventManager.loadTicketCategories(event).get(0).getId()); TicketReservationWithOptionalCodeModification r = new TicketReservationWithOptionalCodeModification(trm, Optional.empty()); Date expiration = DateUtils.addDays(new Date(), 1); String reservationId = ticketReservationManager.createTicketReservation(event, Collections.singletonList(r), Collections.emptyList(), expiration, Optional.empty(), Optional.empty(), Locale.ENGLISH, false); //simulate the effect of a reservation cancellation after #392, as described in #391 ticketReservationRepository.updateReservationStatus(reservationId, TicketReservation.TicketReservationStatus.CANCELLED.name()); List<Ticket> ticketsInReservation = ticketRepository.findTicketsInReservation(reservationId); assertEquals(1, ticketsInReservation.size()); String uuid = ticketsInReservation.get(0).getUuid(); assertTrue(ticketsInReservation.stream().allMatch(t -> t.getStatus() == Ticket.TicketStatus.PENDING)); dataMigrator.fixStuckTickets(event.getId()); assertTrue(ticketRepository.findByUUID(uuid).getStatus() == Ticket.TicketStatus.RELEASED); }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testDecreaseEventSeatsWithABoundedCategory() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);/*from w w w . j av a 2 s. c o m*/ Event event = pair.getKey(); EventModification update = new EventModification(event.getId(), Event.EventType.INTERNAL, null, null, null, null, null, null, null, event.getOrganizationId(), null, "0.0", "0.0", ZoneId.systemDefault().getId(), null, DateTimeModification.fromZonedDateTime(event.getBegin()), DateTimeModification.fromZonedDateTime(event.getEnd()), event.getRegularPrice(), event.getCurrency(), 10, event.getVat(), event.isVatIncluded(), event.getAllowedPaymentProxies(), null, event.isFreeOfCharge(), null, 7, null, null); eventManager.updateEventPrices(event, update, pair.getValue()); List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId()); assertNotNull(tickets); assertFalse(tickets.isEmpty()); assertEquals(10, tickets.size()); assertTrue(tickets.stream().allMatch(t -> t.getCategoryId() != null)); }
From source file:org.openlmis.fulfillment.service.OrderServiceTest.java
private void generateTestData() { program = new ProgramDataBuilder().build(); facility = new FacilityDataBuilder().withSupportedPrograms(Collections.singletonList(program)).build(); period1 = new ProcessingPeriodDataBuilder().build(); period2 = new ProcessingPeriodDataBuilder().build(); orderNumberConfiguration = new OrderNumberConfiguration("prefix", true, true, true); userDto = new UserDataBuilder().build(); orderable = new OrderableDataBuilder().build(); OrderLineItem orderLineItem = new OrderLineItemDataBuilder().withOrderedQuantity(100L) .withOrderableId(orderable.getId()).build(); StatusChange statusChange = new StatusChangeDataBuilder().build(); order = new OrderDataBuilder().withQuotedCost(BigDecimal.ZERO).withProgramId(program.getId()) .withCreatedById(userDto.getId()).withEmergencyFlag().withStatus(OrderStatus.IN_ROUTE) .withStatusChanges(statusChange).withSupplyingFacilityId(facility.getId()) .withProcessingPeriodId(period1.getId()).withLineItems(orderLineItem).build(); userDto = new UserDataBuilder().build(); properties = new FtpTransferProperties(); startDate = LocalDate.now(); endDate = startDate.plusMonths(1);/*from www . j a v a 2s . c o m*/ }
From source file:alfio.manager.EventManagerIntegrationTest.java
@Test public void testAddBoundedCategoryToUnboundedEvent() { List<TicketCategoryModification> categories = Collections.singletonList(new TicketCategoryModification(null, "default", 0, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", false, null, null, null, null, null)); Pair<Event, String> pair = initEvent(categories, organizationRepository, userManager, eventManager, eventRepository);//www . j a v a 2 s .co m Event event = pair.getKey(); TicketCategoryModification tcm = new TicketCategoryModification(null, "default", 10, new DateTimeModification(LocalDate.now(), LocalTime.now()), new DateTimeModification(LocalDate.now(), LocalTime.now()), DESCRIPTION, BigDecimal.TEN, false, "", true, null, null, null, null, null); Result<Integer> result = eventManager.insertCategory(event, tcm, pair.getValue()); assertTrue(result.isSuccess()); List<Ticket> tickets = ticketRepository.findFreeByEventId(event.getId()); assertNotNull(tickets); assertFalse(tickets.isEmpty()); assertEquals(10, tickets.size()); assertEquals(10, tickets.stream().filter(t -> t.getCategoryId() == null).count()); assertEquals(10, ticketRepository.countReleasedTicketInCategory(event.getId(), result.getData()).intValue()); }
From source file:dhbw.clippinggorilla.userinterface.windows.PreferencesWindow.java
private Component buildSupportTab(User user) { VerticalLayout root = new VerticalLayout(); root.setCaption(Language.get(Word.SUPPORT)); root.setIcon(VaadinIcons.HEADSET);/*from w w w .j a va2 s.com*/ root.setWidth("100%"); root.setHeight("100%"); root.setSpacing(true); root.setMargin(true); TextArea textAreaMessage = new TextArea(Language.get(Word.MESSAGE)); textAreaMessage.setWidth("100%"); textAreaMessage.setHeight("100%"); Button buttonSend = new Button(Language.get(Word.SEND), VaadinIcons.ENVELOPE); buttonSend.addStyleName(ValoTheme.BUTTON_PRIMARY); buttonSend.addClickListener(ce -> { try { if (emailsSend.containsKey(user)) { Map<LocalDate, Integer> times = emailsSend.get(user); if (times.containsKey(LocalDate.now())) { if (times.get(LocalDate.now()) > 3) { if (times.get(LocalDate.now()) > 15) { UserUtils.banUser(user); VaadinUtils.errorNotification("BANNED DUE TO TOO MUCH EMAILS"); } else { VaadinUtils.errorNotification("TOO MUCH EMAILS"); } return; } else { times.put(LocalDate.now(), times.get(LocalDate.now()) + 1); } } else { times.put(LocalDate.now(), 1); } } else { HashMap<LocalDate, Integer> times = new HashMap<>(); times.put(LocalDate.now(), 1); emailsSend.put(user, times); } Mail.send(Props.get("supportmail"), "SUPPORT", user.toString() + "\n" + textAreaMessage.getValue()); VaadinUtils.middleInfoNotification(Language.get(Word.SUCCESSFULLY_SEND)); textAreaMessage.clear(); } catch (EmailException ex) { VaadinUtils.errorNotification(Language.get(Word.SEND_FAILED)); Log.error("Could not send Supportmail: ", ex); } }); root.addComponents(textAreaMessage, buttonSend); root.setExpandRatio(textAreaMessage, 5); root.setComponentAlignment(buttonSend, Alignment.MIDDLE_LEFT); return root; }
From source file:com.idrene.emefana.repositories.RepositoriesTest.java
@Ignore public void saveBookingTest() { bookingRepository.deleteAll();/*from www.ja v a2 s . c o m*/ List<Provider> prvs = providerRepository.findAll(); List<EventType> events = eventTypeRepository.findAll(); Provider p = prvs.get(0); EventType event = events.get(0); User customer = userRepository.findAll().get(0); Booking booking = new Booking(); booking.setBid(EmefanaIDGenerator.generateProviderId()); booking.setCustomer(customer); booking.setProvider(p); booking.setEvent(event); booking.setStartDate(DateConvertUtil.asUtilDate(LocalDate.now())); booking.setEndDate(DateConvertUtil.asUtilDate((LocalDate.now().plusDays(1)))); booking.setStatus(new BookingStatus(p.getPrice(), null, BOOKINGSTATE.NEW)); bookingRepository.save(booking); Booking savedb = bookingRepository.findOne(booking.getBid()); assertNotNull(savedb); }