Example usage for java.util Date from

List of usage examples for java.util Date from

Introduction

In this page you can find the example usage for java.util Date from.

Prototype

public static Date from(Instant instant) 

Source Link

Document

Obtains an instance of Date from an Instant object.

Usage

From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.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 VmRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.performResumeOperationAsync("foo", new FutureCallback<Task>() {
        @Override/*  w ww .  j  a 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:alfio.manager.AdminReservationManager.java

private Result<Pair<TicketReservation, List<Ticket>>> createReservation(Result<List<TicketsInfo>> input,
        Event event, AdminReservationModification arm) {
    final TicketsInfo empty = new TicketsInfo(null, null, false, false);
    return input.flatMap(t -> {
        String reservationId = UUID.randomUUID().toString();
        String specialPriceSessionId = UUID.randomUUID().toString();
        Date validity = Date.from(arm.getExpiration().toZonedDateTime(event.getZoneId()).toInstant());
        ticketReservationRepository.createNewReservation(reservationId, validity, null, arm.getLanguage(),
                event.getId(), event.getVat(), event.isVatIncluded());
        AdminReservationModification.CustomerData customerData = arm.getCustomerData();
        ticketReservationRepository.updateTicketReservation(reservationId,
                TicketReservationStatus.PENDING.name(), customerData.getEmailAddress(),
                customerData.getFullName(), customerData.getFirstName(), customerData.getLastName(),
                arm.getLanguage(), null, null, null);

        Result<List<Ticket>> result = flattenTicketsInfo(event, empty, t)
                .map(pair -> reserveForTicketsInfo(event, arm, reservationId, specialPriceSessionId, pair))
                .reduce(this::reduceReservationResults)
                .orElseGet(() -> Result.error(ErrorCode.custom("", "unknown error")));

        OrderSummary orderSummary = ticketReservationManager.orderSummaryForReservationId(reservationId, event,
                Locale.forLanguageTag(arm.getLanguage()));
        ticketReservationRepository.addReservationInvoiceOrReceiptModel(reservationId,
                Json.toJson(orderSummary));

        return result
                .map(list -> Pair.of(ticketReservationRepository.findReservationById(reservationId), list));
    });//from w  w w .  ja v  a  2  s  .  c om
}

From source file:org.sleuthkit.autopsy.experimental.autoingest.SingleUserCaseImporter.java

/**
 * Log a message to the case import log in the base output folder.
 *
 * @param message the message to log.//from w ww  .j  a va2  s. c o m
 */
private void log(String message) {
    if (writer != null) {
        writer.println(
                String.format("%s %s", simpleDateFormat.format((Date.from(Instant.now()).getTime())), message)); //NON-NLS
    }
}

From source file:org.apache.james.transport.mailets.DSNBounceTest.java

@Test
public void serviceShouldSetTheDateHeaderWhenNone() throws Exception {
    FakeMailetConfig mailetConfig = FakeMailetConfig.builder().mailetName(MAILET_NAME)
            .mailetContext(fakeMailContext).build();
    dsnBounce.init(mailetConfig);//  w  ww  .j av a  2s . c o m

    MailAddress senderMailAddress = new MailAddress("sender@domain.com");
    FakeMail mail = FakeMail.builder().sender(senderMailAddress)
            .mimeMessage(MimeMessageBuilder.mimeMessageBuilder().setText("My content")).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();
    assertThat(sentMessage.getHeader(RFC2822Headers.DATE)).isNotNull();
}

From source file:com.vmware.photon.controller.api.client.resource.ProjectApiTest.java

@Test
public void testCreateVm() 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);

    ProjectApi projectApi = new ProjectApi(restClient);

    Task task = projectApi.createVm("foo", new VmCreateSpec());
    assertEquals(task, responseTask);//from   w  w w. j  a  va 2 s  .  c  o  m
}

From source file:com.vmware.photon.controller.api.client.resource.VmApiTest.java

@Test
public void testPerformSuspendOperation() 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.performSuspendOperation("foo");
    assertEquals(task, responseTask);/*from w  ww  . j  av a2 s .  co m*/
}

From source file:com.vmware.photon.controller.api.client.resource.ProjectRestApiTest.java

@Test
public void testCreateVm() 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);

    ProjectApi projectApi = new ProjectRestApi(restClient);

    Task task = projectApi.createVm("foo", new VmCreateSpec());
    assertEquals(task, responseTask);/*from w ww.  j av  a  2  s .c om*/
}

From source file:com.vmware.photon.controller.api.client.resource.VmRestApiTest.java

@Test
public void testPerformSuspendOperation() 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.performSuspendOperation("foo");
    assertEquals(task, responseTask);// ww w  . j a  v  a2s  .c o m
}

From source file:sopho.Ofeloumenoi.EditOfeloumenoiController.java

@FXML
public void Save(ActionEvent event) throws IOException {

    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();/*www .  j  a v a 2 s.c  om*/

    } 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 rset = 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();

        try {
            // we can push the data to database...
            String sql = "UPDATE ofeloumenoi SET 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=? WHERE barcode=?";
            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());

            pst.setString(37, oldBarcode); // we update the values to the database table where barcode = oldBarcode

            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) {
                sopho.Messages.CustomMessageController cm = new sopho.Messages.CustomMessageController(null,
                        "!",
                        "   ?  ?  , ?     .",
                        "confirm");
                cm.showAndWait();

                if (le.LockEditing(false, selID, "ofeloumenoi")) {
                    Stage stage = (Stage) barcode.getScene().getWindow();
                    sl.StageLoad("/sopho/Ofeloumenoi/OfeloumenoiMain.fxml", stage, true, false); //resizable true, utility false
                } else {
                    sopho.Messages.CustomMessageController cm2 = new sopho.Messages.CustomMessageController(
                            null, "?",
                            "   ?  ?  ?.      ?   ? .   ?  ? ?    ??.",
                            "error");
                    cm2.showAndWait();
                }
            } 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:com.vmware.photon.controller.api.client.resource.TenantsApiTest.java

@Test
public void testCreateProject() 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);

    TenantsApi tenantsApi = new TenantsApi(restClient);

    Task task = tenantsApi.createProject("foo", new ProjectCreateSpec());
    assertEquals(task, responseTask);//w ww. j  a v  a 2s .c  o  m
}