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.VmApiTest.java

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

    Map<String, String> metadata = new HashMap<>();
    metadata.put("key", "value");

    VmMetadata vmMetadata = new VmMetadata();
    vmMetadata.setMetadata(metadata);//from   ww  w. j  a  v a 2  s. co m

    Task task = vmApi.setMetadata("foo", vmMetadata);
    assertEquals(task, responseTask);
}

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

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

    Map<String, String> metadata = new HashMap<>();
    metadata.put("key", "value");

    VmMetadata vmMetadata = new VmMetadata();
    vmMetadata.setMetadata(metadata);//from www .j  a v  a  2  s  .  c om

    Task task = vmApi.setMetadata("foo", vmMetadata);
    assertEquals(task, responseTask);
}

From source file:net.ceos.project.poi.annotated.core.CsvHandler.java

/**
 * Apply a date time value at the field.
 * /* www  . j ava2s  . co m*/
 * @param value
 *            the value
 * @param formatMask
 *            the decorator mask
 * @param transformMask
 *            the transformation mask
 * @return false if problem otherwise true
 * @throws ConverterException
 *             the conversion exception type
 */
protected static String toLocalDate(final LocalDate value, final String formatMask, final String transformMask)
        throws ConverterException {
    String dateMasked = StringUtils.EMPTY;
    if (value != null) {
        try {
            if (StringUtils.isNotBlank(transformMask)) {
                // apply transformation mask
                dateMasked = applyMaskToDate(Date.from(value.atStartOfDay(ZoneId.systemDefault()).toInstant()),
                        transformMask);

            } else if (StringUtils.isNotBlank(formatMask)) {
                // apply format mask
                dateMasked = applyMaskToDate(Date.from(value.atStartOfDay(ZoneId.systemDefault()).toInstant()),
                        formatMask);

            } else {
                // default mask
                dateMasked = applyMaskToDate(Date.from(value.atStartOfDay(ZoneId.systemDefault()).toInstant()),
                        Constants.DD_MMM_YYYY_HH_MM_SS);
            }
        } catch (Exception e) {
            throw new ConverterException(ExceptionMessage.CONVERTER_LOCALDATE.getMessage(), e);
        }
    }
    return dateMasked;
}

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

@Test
public void testCreateCluster() 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.createCluster("foo", new ClusterCreateSpec());
    assertEquals(task, responseTask);//from  ww w. jav  a  2s .  c om
}

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

@Test
public void testCreateCluster() 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.createCluster("foo", new ClusterCreateSpec());
    assertEquals(task, responseTask);//from w  w  w .java 2s.  c  o m
}

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

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

    Map<String, String> metadata = new HashMap<>();
    metadata.put("key", "value");

    VmMetadata vmMetadata = new VmMetadata();
    vmMetadata.setMetadata(metadata);//from ww w.j av a  2s  .  com

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.setMetadataAsync("foo", vmMetadata, new FutureCallback<Task>() {
        @Override
        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.EventManager.java

MapSqlParameterSource[] prepareTicketsBulkInsertParameters(ZonedDateTime creation, Event event,
        int requestedTickets, TicketStatus ticketStatus) {

    //FIXME: the date should be inserted as ZonedDateTime !
    Date creationDate = Date.from(creation.toInstant());

    List<TicketCategory> categories = ticketCategoryRepository.findByEventId(event.getId());
    Stream<MapSqlParameterSource> boundedTickets = categories.stream().filter(IS_CATEGORY_BOUNDED)
            .flatMap(tc -> generateTicketsForCategory(tc, event, creationDate, 0));
    int generatedTickets = categories.stream().filter(IS_CATEGORY_BOUNDED)
            .mapToInt(TicketCategory::getMaxTickets).sum();
    if (generatedTickets >= requestedTickets) {
        return boundedTickets.toArray(MapSqlParameterSource[]::new);
    }/*from  ww w  .  ja va2 s .co  m*/

    return Stream.concat(boundedTickets,
            generateEmptyTickets(event, creationDate, requestedTickets - generatedTickets, ticketStatus))
            .toArray(MapSqlParameterSource[]::new);
}

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

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

    Map<String, String> metadata = new HashMap<>();
    metadata.put("key", "value");

    VmMetadata vmMetadata = new VmMetadata();
    vmMetadata.setMetadata(metadata);/*from  w  w  w .j  av  a2s . c  o  m*/

    final CountDownLatch latch = new CountDownLatch(1);

    vmApi.setMetadataAsync("foo", vmMetadata, new FutureCallback<Task>() {
        @Override
        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.ProjectApiTest.java

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

    ProjectApi projectApi = new ProjectApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    projectApi.createClusterAsync("foo", new ClusterCreateSpec(), new FutureCallback<Task>() {
        @Override/* ww w .  j  a  va 2  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.ProjectRestApiTest.java

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

    ProjectApi projectApi = new ProjectRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    projectApi.createClusterAsync("foo", new ClusterCreateSpec(), new FutureCallback<Task>() {
        @Override/* w  w w  .j av  a2  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));
}