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:org.wallride.web.support.AtomFeedView.java

@SuppressWarnings("unchecked")
@Override//w w w .ja  va 2 s.c o m
protected List<Entry> buildFeedEntries(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    Set<Article> articles = (Set<Article>) model.get("articles");
    List<Entry> entries = new ArrayList<>(articles.size());
    for (Article article : articles) {
        Entry entry = new Entry();
        entry.setTitle(article.getTitle());
        entry.setPublished(Date.from(article.getDate().atZone(ZoneId.systemDefault()).toInstant()));
        Content content = new Content();
        content.setValue(article.getBody());
        entry.setSummary(content);

        Link link = new Link();
        link.setHref(link(article));
        List<Link> links = new ArrayList<Link>();
        links.add(link);
        entry.setAlternateLinks(links);
        entries.add(entry);
    }
    return entries;
}

From source file:io.gravitee.management.service.impl.ApiKeyServiceImpl.java

@Override
public ApiKeyEntity generateOrRenew(String applicationName, String apiName) {
    try {//from  ww  w.  j a  v  a2  s  . co m
        LOGGER.debug("Generate a new key for {} - {}", applicationName, apiName);
        ApiKey apiKey = new ApiKey();

        apiKey.setApplication(applicationName);
        apiKey.setApi(apiName);
        apiKey.setCreatedAt(new Date());
        apiKey.setKey(apiKeyGenerator.generate());
        apiKey.setRevoked(false);

        Instant expirationInst = apiKey.getCreatedAt().toInstant().plus(Duration.ofHours(1));
        Date expirationDate = Date.from(expirationInst);

        // Previously generated keys should be set as revoked
        Set<ApiKey> oldKeys = apiKeyRepository.findByApplicationAndApi(applicationName, apiName);
        for (ApiKey oldKey : oldKeys) {
            setExpiration(expirationDate, oldKey);
        }

        apiKey = apiKeyRepository.create(applicationName, apiName, apiKey);
        return convert(apiKey);
    } catch (TechnicalException ex) {
        LOGGER.error("An error occurs while trying to generate a key for {} - {}", applicationName, apiName,
                ex);
        throw new TechnicalManagementException(
                "An error occurs while trying to generate a key for " + applicationName + " - " + apiName, ex);
    }
}

From source file:com.bccriskadvisory.link.monitor.EdgescanMonitorImpl.java

@Override
public void schedule() {
    synchronized (this) {
        if (scheduled)
            return;

        try {//from  w  w w .j a  v a2 s.co m
            Map<String, Object> jobDataMap = Collections.singletonMap(KEY, this);

            scheduler.scheduleJob(JOB_NAME, EdgescanLinkTask.class, jobDataMap,
                    Date.from(Utilities.now().toInstant()), interval);
        } catch (Exception e) {
            getLog().error("Unable to schedule edgescan link task.");
        }

        scheduled = true;
    }
}

From source file:RESTClient.java

@Test
public void hello() throws UnsupportedEncodingException, IOException {

    HistoryDao dao = new HistoryDao();
    dao.setDate(Date.from(Instant.EPOCH));
    dao.setPack("1");
    HistoryListDao dao1 = new HistoryListDao();
    dao1.setDepartement("1");
    ArrayList<HistoryDao> arrayList = new ArrayList<>();
    arrayList.add(dao);//from  www  .j a  va  2  s  .c  o m
    dao1.setHistory(arrayList);
    dao1.setDepartement("1");

    Gson g = new Gson();
    String toJson = g.toJson(dao1);
    logger.log(Level.INFO, "Gson: {0}", toJson);

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost("http://localhost:8080/sync");
    StringEntity input = new StringEntity(toJson);
    post.setEntity(input);
    HttpResponse response = client.execute(post);
    BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));

    String line;
    int statusCode = response.getStatusLine().getStatusCode();
    assertTrue(statusCode == 200);

    while ((line = rd.readLine()) != null) {
        System.out.println(line);
    }

}

From source file:org.ng200.openolympus.controller.task.TaskCreationController.java

@RequestMapping(method = RequestMethod.POST)
public String createTask(final Model model, final HttpServletRequest request, @Valid final TaskDto taskDto,
        final BindingResult bindingResult) throws IllegalStateException, IOException, ArchiveException {
    this.taskDtoValidator.validate(taskDto, bindingResult, null);
    if (bindingResult.hasErrors()) {
        model.addAttribute("submitURL", "/archive/add");
        model.addAttribute("mode", "add");
        return "tasks/add";
    }/*from  ww w. j a  v a2s .  co m*/
    final UUID uuid = UUID.randomUUID();

    Task task = new Task(taskDto.getName(), uuid.toString(), uuid.toString(), Date.from(Instant.now()));

    this.uploadTaskData(task, taskDto);

    task = this.taskRepository.save(task);

    return "redirect:/task/" + task.getId();
}

From source file:org.ojbc.util.model.rapback.IdentificationResultSearchRequest.java

public void setReportedDateStartLocalDate(LocalDate localDate) {
    this.reportedDateStartDate = localDate == null ? null
            : Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
}

From source file:com.ikanow.aleph2.core.shared.utils.TimeSliceDirUtils.java

/** Takes a stream of strings (paths) and adds the date range
 * @param dir_listing/*from  ww  w  . ja va  2  s.c om*/
 * @return
 */
public static Stream<Tuple3<String, Date, Date>> annotateTimedDirectories(final Stream<String> dir_listing) {
    //(first get to last element in path, then if it ends _<date> then grab <date>, else assume it's the whole thing)
    return candidateTimedDirectories(dir_listing).filter(dir_datestr_date -> dir_datestr_date._3().isSuccess())
            .map(dir_datestr_date -> {
                final Optional<Tuple2<String, ChronoUnit>> info = TimeUtils
                        .getFormatInfoFromDateString(dir_datestr_date._2());
                return Tuples._3T(dir_datestr_date._1(), info, dir_datestr_date._3());
            }).filter(dir_datestr_date -> dir_datestr_date._2().isPresent())
            .map(dir_datestr_date -> Tuples._3T(dir_datestr_date._1(), dir_datestr_date._3().success(),
                    adjustTime(Date.from(dir_datestr_date._3().success().toInstant()),
                            dir_datestr_date._2().get()._2())));
}

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

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

    TenantsApi tenantsApi = new TenantsApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    tenantsApi.createAsync("foo", new FutureCallback<Task>() {
        @Override/*from  w ww  .  j a v a 2s.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));
    ;
}

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

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

    TenantsApi tenantsApi = new TenantsRestApi(restClient);

    final CountDownLatch latch = new CountDownLatch(1);

    tenantsApi.createAsync("foo", new FutureCallback<Task>() {
        @Override/*  ww  w.j  a  v  a  2  s.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:com.hotelbeds.hotelapimodel.auto.util.AssignUtils.java

public static Date getDate(final LocalDateTime localDateTime) {
    Instant instant = localDateTime.atZone(ZoneId.systemDefault()).toInstant();
    return Date.from(instant);
}