List of usage examples for java.util Date from
public static Date from(Instant instant)
From source file:retsys.client.controller.PurchaseOrderConfirmController.java
@Override Object buildRequestMsg() {/* w w w . j a va 2 s . co m*/ PurchaseOrder po = new PurchaseOrder(); po.setId(Integer.parseInt(po_no.getText())); po.setDate(Date.from(Instant.now())); Project projectObj = new Project(); projectObj.setId(splitId(project.getText())); po.setProject(projectObj); po.setDeliveryAddress(delivery_address.getText()); Vendor vendorObj = new Vendor(); vendorObj.setId(splitId(vendor.getText())); po.setVendor(vendorObj); Iterator<POItem> items = poDetail.getItems().iterator(); List<PurchaseOrderDetail> poDetails = new ArrayList<>(); while (items.hasNext()) { POItem poItem = items.next(); PurchaseOrderDetail poDetail = new PurchaseOrderDetail(); Item item = new Item(); item.setId(splitId(poItem.getName().get())); poDetail.setItem(item); poDetail.setId(poItem.getId().get()); poDetail.setQuantity(poItem.getQuantity().get()); poDetail.setConfirm(poItem.getConfirm().get() ? "Y" : "N"); poDetail.setReceivedDate(DateUtils.asDate(poItem.getReceivedDate().get())); poDetail.setBillNo(poItem.getBillNo().get()); poDetail.setSupervisor(poItem.getSupervisor().get()); poDetails.add(poDetail); } po.setPurchaseOrderDetail(poDetails); return po; }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testPerformRestartOperation() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmRestApi(restClient); Task task = vmApi.performRestartOperation("foo"); assertEquals(task, responseTask);/*from ww w .ja v a 2 s . c o m*/ }
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();//from w w w .j av 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:alfio.manager.EventManager.java
public void updateEventPrices(Event original, EventModification em, String username) { checkOwnership(original, username, em.getOrganizationId()); int eventId = original.getId(); int seatsDifference = em.getAvailableSeats() - eventRepository.countExistingTickets(original.getId()); if (seatsDifference < 0) { int allocatedSeats = ticketCategoryRepository.findByEventId(original.getId()).stream() .filter(TicketCategory::isBounded).mapToInt(TicketCategory::getMaxTickets).sum(); if (em.getAvailableSeats() < allocatedSeats) { throw new IllegalArgumentException(format( "cannot reduce max tickets to %d. There are already %d tickets allocated. Try updating categories first.", em.getAvailableSeats(), allocatedSeats)); }/*w w w .j a v a 2s .c o m*/ } String paymentProxies = collectPaymentProxies(em); BigDecimal vat = em.isFreeOfCharge() ? BigDecimal.ZERO : em.getVatPercentage(); eventRepository.updatePrices(em.getCurrency(), em.getAvailableSeats(), em.isVatIncluded(), vat, paymentProxies, eventId, em.getVatStatus(), em.getPriceInCents()); if (seatsDifference != 0) { Event modified = eventRepository.findById(eventId); if (seatsDifference > 0) { final MapSqlParameterSource[] params = generateEmptyTickets(modified, Date.from(ZonedDateTime.now(modified.getZoneId()).toInstant()), seatsDifference, TicketStatus.RELEASED).toArray(MapSqlParameterSource[]::new); jdbc.batchUpdate(ticketRepository.bulkTicketInitialization(), params); } else { List<Integer> ids = ticketRepository.selectNotAllocatedTicketsForUpdate(eventId, Math.abs(seatsDifference), singletonList(TicketStatus.FREE.name())); Validate.isTrue(ids.size() == Math.abs(seatsDifference), "cannot lock enough tickets for deletion."); int invalidatedTickets = ticketRepository.invalidateTickets(ids); Validate.isTrue(ids.size() == invalidatedTickets, String.format( "error during ticket invalidation: expected %d, got %d", ids.size(), invalidatedTickets)); } } }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testPerformRestartOperationAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.performRestartOperationAsync("foo", new FutureCallback<Task>() { @Override/* w w w . ja v a2 s.c o m*/ public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testPerformRestartOperationAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmRestApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.performRestartOperationAsync("foo", new FutureCallback<Task>() { @Override// www . j av a 2s . com public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }
From source file:org.apache.james.transport.mailets.DSNBounceTest.java
@Test public void serviceShouldAttachTheOriginalMailHeadersOnlyWhenAttachmentIsEqualToHeads() throws Exception { FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME) .mailetContext(fakeMailContext).setProperty("attachment", "heads").build(); dsnBounce.init(mailetConfig);/*w w w . j a v a 2s .com*/ MailAddress senderMailAddress = new MailAddress("sender@domain.com"); FakeMail mail = FakeMail.builder().sender(senderMailAddress) .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content") .addHeader("myHeader", "myValue").setSubject("mySubject")) .name(MAILET_NAME).recipient("recipient@domain.com") .lastUpdated(Date.from(Instant.parse("2016-09-08T14:25:52.000Z"))).build(); dsnBounce.service(mail); List<SentMail> sentMails = fakeMailContext.getSentMails(); assertThat(sentMails).hasSize(1); SentMail sentMail = sentMails.get(0); assertThat(sentMail.getSender()).isNull(); assertThat(sentMail.getRecipients()).containsOnly(senderMailAddress); MimeMessage sentMessage = sentMail.getMsg(); MimeMultipart content = (MimeMultipart) sentMessage.getContent(); BodyPart bodyPart = content.getBodyPart(2); SharedByteArrayInputStream actualContent = (SharedByteArrayInputStream) bodyPart.getContent(); assertThat(IOUtils.toString(actualContent, StandardCharsets.UTF_8)).contains("Subject: mySubject") .contains("myHeader: myValue"); assertThat(bodyPart.getContentType()).isEqualTo("text/rfc822-headers; name=mySubject"); }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testPerformResumeOperation() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmApi(restClient); Task task = vmApi.performResumeOperation("foo"); assertEquals(task, responseTask);// w w w.ja va 2s .c om }
From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java
@Test public void testPerformResumeOperation() throws IOException { Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmRestApi(restClient); Task task = vmApi.performResumeOperation("foo"); assertEquals(task, responseTask);/*from w ww . j av a2s . c o m*/ }
From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java
@Test public void testPerformResumeOperationAsync() throws IOException, InterruptedException { final Task responseTask = new Task(); responseTask.setId("12345"); responseTask.setState("QUEUED"); responseTask.setQueuedTime(Date.from(Instant.now())); ObjectMapper mapper = new ObjectMapper(); String serializedTask = mapper.writeValueAsString(responseTask); setupMocks(serializedTask, HttpStatus.SC_CREATED); VmApi vmApi = new VmApi(restClient); final CountDownLatch latch = new CountDownLatch(1); vmApi.performResumeOperationAsync("foo", new FutureCallback<Task>() { @Override//from w w w.j a v a 2 s . co m public void onSuccess(@Nullable Task result) { assertEquals(result, responseTask); latch.countDown(); } @Override public void onFailure(Throwable t) { fail(t.toString()); latch.countDown(); } }); assertThat(latch.await(COUNTDOWNLATCH_AWAIT_TIMEOUT, TimeUnit.SECONDS), is(true)); }