Example usage for java.time LocalDateTime now

List of usage examples for java.time LocalDateTime now

Introduction

In this page you can find the example usage for java.time LocalDateTime now.

Prototype

public static LocalDateTime now() 

Source Link

Document

Obtains the current date-time from the system clock in the default time-zone.

Usage

From source file:org.wallride.service.PostService.java

@Transactional(propagation = Propagation.NOT_SUPPORTED)
public void updatePostViews() {
    LocalDateTime now = LocalDateTime.now();
    Set<JobExecution> jobExecutions = jobExplorer.findRunningJobExecutions("updatePostViewsJob");
    for (JobExecution jobExecution : jobExecutions) {
        LocalDateTime startTime = LocalDateTime.ofInstant(jobExecution.getStartTime().toInstant(),
                ZoneId.systemDefault());
        Duration d = Duration.between(now, startTime);
        if (Math.abs(d.toMinutes()) == 0) {
            logger.info("Skip processing because the job is running.");
            return;
        }//from   w  w  w  .  ja  v a2  s  .  com
    }

    JobParameters params = new JobParametersBuilder()
            .addDate("now", Date.from(now.atZone(ZoneId.systemDefault()).toInstant())).toJobParameters();
    try {
        jobLauncher.run(updatePostViewsJob, params);
    } catch (Exception e) {
        throw new ServiceException(e);
    }
}

From source file:org.ow2.proactive.workflow_catalog.rest.service.BucketService.java

public BucketMetadata createBucket(String name, String owner) {
    Bucket bucket = new Bucket(name, LocalDateTime.now(), owner);
    try {// w w w  .j  av  a  2 s . com
        bucket = bucketRepository.save(bucket);
    } catch (DataIntegrityViolationException exception) {
        throw new BucketAlreadyExisting("The bucket named " + name + " owned by " + owner + " already exist");
    }
    return new BucketMetadata(bucket);
}

From source file:com.fns.grivet.service.NamedQueryServiceSprocTest.java

@Test
public void testNamedQueryNotExecutedBecauseParamSuppliedForExecutionNotCorrectlyNamed() throws IOException {
    Assertions.assertThrows(IllegalArgumentException.class, () -> {
        Resource r = resolver.getResource("classpath:TestSprocQuery.json");
        String json = IOUtils.toString(r.getInputStream(), Charset.defaultCharset());
        NamedQuery namedQuery = objectMapper.readValue(json, NamedQuery.class);
        namedQueryService.create(namedQuery);

        MultiValueMap<String, Object> params = new LinkedMultiValueMap<>();
        Timestamp tomorrow = Timestamp.valueOf(LocalDateTime.now().plusDays(1));
        params.add("timeCreated", tomorrow);
        namedQueryService.get("sproc.getAttributesCreatedBefore", params);
    });/*from  w w  w.  ja v  a 2s .  co m*/
}

From source file:kitt.admin.service.UserService.java

/**
 * ?? -- ?/*from  www  . j  a v  a  2  s.c om*/
 * @param company   ?
 * @param remarks   
 * @return          true of false
 */
@Transactional
public boolean doCompanyVerifyNotPassMethod(Company company, String remarks) {
    CompanyVerify companyVerify = companyMapper.getTheLatestCompanyVerifyByCompanyIdUserIdStatus(
            company.getId(), company.getUserid(), "");
    if (companyVerify != null) {
        String status = EnumCommonString.VerifyNotPass.value();
        int row1 = companyMapper.setCompVerify(status, session.getAdmin().getUsername(), LocalDateTime.now(),
                remarks, company.getId(), companyVerify.getId());
        int row2 = companyMapper.setCompanyStatus(status, remarks, company.getId());
        int row3 = userMapper.setUserVerifyStatus(status, LocalDateTime.now(), company.getUserid());
        if (row1 == 1 && row2 == 1 && row3 == 1) {
            String phone = userMapper.getUserById(company.getUserid()).getSecurephone();
            final String content = "????:" + remarks
                    + ", ?400-960-1180";
            MessageNotice.CommonMessage.noticeUser(phone, content);
            return true;
        }
    }
    throw new BusinessException("???");
}

From source file:com.swcguild.capstoneproject.dao.BlogDaoDbImplTest.java

/**
 * Test of updatePost method, of class BlogDaoDbImpl.
 *///w  w w  .j av  a  2  s.com
@Test
public void testUpdatePost() {
    System.out.println("updatePost");
    Post post1 = new Post("SuperMAN", "Clark Kent", "hot new cousin saves city", "super, girl",
            LocalDateTime.now().toString(), "2015-12-30");

    dao.updatePost(post1);
    assertEquals("SuperMAN", post1.getTitle());
}

From source file:nc.noumea.mairie.appock.services.impl.StockServiceImpl.java

@Override
public ArticleStock creeArticleStockEtMouvement(ArticleCatalogue articleCatalogue, Integer quantiteRenseigne,
        Stock stock, String observation) {
    ArticleStock articleStock = new ArticleStock();
    articleStock.setQuantiteStock(quantiteRenseigne);
    articleStock.setReferenceArticleStock(articleCatalogue.getReference());
    articleStock.setStock(stock);//from w  w  w . j a v a 2s .  com
    stock.getListeArticleStock().add(articleStock);

    AppUser currentUser = authHelper.getCurrentUser();

    MouvementStock mouvementStock = new MouvementStock();
    mouvementStock.setDateMouvement(LocalDateTime.now());
    mouvementStock.setQuantiteRenseigne(quantiteRenseigne);
    mouvementStock.setMouvementUser(currentUser.getNomComplet());
    mouvementStock.setReference(articleCatalogue.getReference());
    mouvementStock.setNewQuantiteStock(quantiteRenseigne);
    mouvementStock.setTypeMouvementStock(TypeMouvementStock.NOUVEL_ARTICLE);
    mouvementStock.setObservation(observation);
    mouvementStock.setStock(stock);
    stock.getListeMouvementStock().add(mouvementStock);

    stockRepository.save(stock);

    return articleStock;

}

From source file:org.nuxeo.ecm.blob.azure.TestAzureBinaryManager.java

@Test
public void testSigning() throws IOException, URISyntaxException, StorageException, InvalidKeyException {
    CloudBlobContainer container = binaryManager.container;
    Binary binary = binaryManager.getBinary(Blobs.createBlob(CONTENT));
    assertNotNull(binary);//from w w w  . j av a 2 s  .  c  om

    CloudBlockBlob blockBlobReference = container.getBlockBlobReference(CONTENT_MD5);
    SharedAccessBlobPolicy policy = new SharedAccessBlobPolicy();
    policy.setPermissionsFromString("r");

    // rscd content-dispositoon
    // rsct content-type

    Instant endDateTime = LocalDateTime.now().plusHours(1).atZone(ZoneId.systemDefault()).toInstant();
    policy.setSharedAccessExpiryTime(Date.from(endDateTime));

    SharedAccessBlobHeaders headers = new SharedAccessBlobHeaders();
    headers.setContentDisposition("attachment; filename=\"blabla.txt\"");
    headers.setContentType("text/plain");

    String something = blockBlobReference.generateSharedAccessSignature(policy, headers, null);
    System.out.println(something);

    CloudBlockBlob blob = new CloudBlockBlob(blockBlobReference.getUri(),
            new StorageCredentialsSharedAccessSignature(something));

    System.out.println(blob.getQualifiedUri());
}

From source file:org.wallride.web.controller.guest.user.PasswordResetController.java

@RequestMapping(value = "/{token}", method = RequestMethod.PUT)
public String reset(@PathVariable String token,
        @Validated @ModelAttribute(FORM_MODEL_KEY) PasswordResetForm form, BindingResult errors,
        BlogLanguage blogLanguage, RedirectAttributes redirectAttributes) {
    redirectAttributes.addFlashAttribute(FORM_MODEL_KEY, form);
    redirectAttributes.addFlashAttribute(ERRORS_MODEL_KEY, errors);

    PasswordResetToken passwordResetToken = userService.getPasswordResetToken(token);
    if (passwordResetToken == null) {
        redirectAttributes.addFlashAttribute(INVALID_PASSOWRD_RESET_LINK_ATTR_NAME, true);
        return "redirect:/password-reset";
    }/* w w  w .j  a v a  2s  .c o m*/
    LocalDateTime now = LocalDateTime.now();
    if (now.isAfter(passwordResetToken.getExpiredAt())) {
        redirectAttributes.addFlashAttribute(INVALID_PASSOWRD_RESET_LINK_ATTR_NAME, true);
        return "redirect:/password-reset";
    }

    if (!errors.hasFieldErrors("newPassword")) {
        if (!ObjectUtils.nullSafeEquals(form.getNewPassword(), form.getNewPasswordRetype())) {
            errors.rejectValue("newPasswordRetype", "MatchRetype");
        }
    }
    if (errors.hasFieldErrors("newPassword*")) {
        return "redirect:/password-reset/{token}";
    }

    PasswordUpdateRequest request = new PasswordUpdateRequest().withUserId(passwordResetToken.getUser().getId())
            .withPassword(form.getNewPassword()).withLanguage(blogLanguage.getLanguage());
    userService.updatePassword(request, passwordResetToken);

    redirectAttributes.getFlashAttributes().clear();
    return "redirect:/login";
}

From source file:org.apache.metron.parsers.syslog.Syslog5424Parser.java

@SuppressWarnings("unchecked")
private void setTimestamp(JSONObject message) {
    String timeStampString = (String) message.get(SyslogFieldKeys.HEADER_TIMESTAMP.getField());
    if (!StringUtils.isBlank(timeStampString) && !timeStampString.equals("-")) {
        message.put("timestamp", timeStampString);
    } else {/*  www  . ja v  a  2  s .c o  m*/
        message.put("timestamp", LocalDateTime.now().format(DateTimeFormatter.ISO_DATE_TIME));
    }
}

From source file:org.apache.rya.benchmark.periodic.KafkaLatencyBenchmark.java

public KafkaLatencyBenchmark(final CommonOptions options, final BenchmarkOptions benchmarkOptions)
        throws AccumuloException, AccumuloSecurityException {
    this.options = Objects.requireNonNull(options);
    this.benchmarkOptions = Objects.requireNonNull(benchmarkOptions);
    this.client = Objects.requireNonNull(options.buildRyaClient());
    this.startTime = LocalDateTime.now();

    logger.info("Running {} with the following input parameters:\n{}\n{}", this.getClass(), options,
            benchmarkOptions);//w w  w.j a  va 2  s . c  o  m
}