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:edu.usu.sdl.openstorefront.service.UserServiceImpl.java

@Override
public void cleanupOldUserMessages() {
    int maxDays = Convert.toInteger(PropertiesManager.getValue(PropertiesManager.KEY_MESSAGE_KEEP_DAYS, "30"));

    LocalDateTime archiveTime = LocalDateTime.now();
    archiveTime = archiveTime.minusDays(maxDays);
    archiveTime = archiveTime.truncatedTo(ChronoUnit.DAYS);
    String deleteQuery = "updateDts < :maxUpdateDts AND activeStatus = :activeStatusParam";

    ZonedDateTime zdt = archiveTime.atZone(ZoneId.systemDefault());
    Date archiveDts = Date.from(zdt.toInstant());

    Map<String, Object> queryParams = new HashMap<>();
    queryParams.put("maxUpdateDts", archiveDts);
    queryParams.put("activeStatusParam", UserMessage.INACTIVE_STATUS);

    persistenceService.deleteByQuery(UserMessage.class, deleteQuery, queryParams);
}

From source file:org.kitodo.production.forms.IndexingForm.java

private void runIndexing(IndexWorker worker, ObjectType type) {
    currentState = IndexStates.NO_STATE;
    int attempts = 0;
    while (attempts < 10) {
        try {//from  w  w  w. j  a va  2 s .  com
            if (Objects.equals(currentIndexState, ObjectType.NONE) || Objects.equals(currentIndexState, type)) {
                if (Objects.equals(currentIndexState, ObjectType.NONE)) {
                    indexingStartedTime = LocalDateTime.now();
                    currentIndexState = type;
                    objectIndexingStates.put(type, IndexingStates.INDEXING_STARTED);
                    pollingChannel.send(INDEXING_STARTED_MESSAGE + currentIndexState);
                }
                indexerThread = new Thread(worker);
                indexerThread.setDaemon(true);
                indexerThread.start();
                indexerThread.join();
                break;
            } else {
                logger.debug("Cannot start '{}' indexing while a different indexing process running: '{}'",
                        type, this.currentIndexState);
                Thread.sleep(pause);
                attempts++;
            }
        } catch (InterruptedException e) {
            Helper.setErrorMessage(e.getLocalizedMessage(), logger, e);
            Thread.currentThread().interrupt();
        }
    }
}

From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java

@Test
public void testNoPublicCategoryAvailable() {
    LocalDateTime start = LocalDateTime.now().minusHours(1);
    LocalDateTime end = LocalDateTime.now().plusHours(1);

    List<TicketCategoryModification> categories = Arrays.asList(
            new TicketCategoryModification(null, "default", 2,
                    new DateTimeModification(start.toLocalDate(), start.toLocalTime()),
                    new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN,
                    false, "", true, null, null, null, null, null),
            new TicketCategoryModification(null, "default2", 10,
                    new DateTimeModification(start.toLocalDate(), start.toLocalTime()),
                    new DateTimeModification(end.toLocalDate(), end.toLocalTime()), DESCRIPTION, BigDecimal.TEN,
                    true, "", true, null, null, null, null, null));

    configurationManager.saveSystemConfiguration(ConfigurationKeys.ENABLE_WAITING_QUEUE, "true");
    Pair<Event, String> eventAndUsername = initEvent(categories, organizationRepository, userManager,
            eventManager, eventRepository);
    Event event = eventAndUsername.getKey();
    List<TicketCategory> ticketCategories = ticketCategoryRepository.findByEventId(event.getId());
    TicketCategory first = ticketCategories.stream().filter(tc -> !tc.isAccessRestricted()).findFirst()
            .orElseThrow(IllegalStateException::new);
    reserveTickets(event, first, 2);/*  w  ww .ja  va2  s  . c  o  m*/
    assertTrue(
            waitingQueueManager.subscribe(event, customerJohnDoe(event), "john@doe.com", null, Locale.ENGLISH));
    assertTrue(waitingQueueManager.subscribe(event, new CustomerName("John Doe 2", "John", "Doe 2", event),
            "john@doe2.com", null, Locale.ENGLISH));

    ZoneId zoneId = event.getZoneId();
    Result<TicketCategory> ticketCategoryResult = eventManager.updateCategory(first.getId(), event,
            new TicketCategoryModification(first.getId(), first.getName(), 3,
                    fromZonedDateTime(first.getInception(zoneId)),
                    fromZonedDateTime(first.getExpiration(zoneId)), Collections.emptyMap(), first.getPrice(),
                    false, "", true, null, null, null, null, null),
            eventAndUsername.getValue());
    assertTrue(ticketCategoryResult.isSuccess());
    assertEquals(1, ticketRepository.countReleasedTicketInCategory(event.getId(), first.getId()).intValue());
    //now we should have an extra available ticket
    List<Triple<WaitingQueueSubscription, TicketReservationWithOptionalCodeModification, ZonedDateTime>> subscriptions = waitingQueueManager
            .distributeSeats(event).collect(Collectors.toList());
    assertEquals(1, subscriptions.size());
}

From source file:ch.wisv.areafiftylan.UserRestIntegrationTest.java

@Test
public void testExpiredUsersSingleExpired() {
    User tempUser = makeAndGetTempUser("");

    VerificationToken token = verificationTokenRepository.findByUser(tempUser).get();
    token.setExpiryDate(LocalDateTime.now().minusDays(1));
    verificationTokenRepository.save(token);

    int expiredCount = verificationTokenRepository.findAllByExpiryDateBefore(LocalDateTime.now()).size();
    Assert.assertEquals(1, expiredCount);

    taskScheduler.CleanUpUsers();//from  w  w w  . ja  v  a  2s .co  m

    Assert.assertFalse(verificationTokenRepository.findByUser(tempUser).isPresent());
}

From source file:fr.landel.utils.assertor.OperatorTest.java

/**
 * Test method for {@link Operator#nand()}.
 *///ww w  . ja  v a 2s . com
@Test
public void testNand() {
    final String text = "text";
    assertFalse(Assertor.that(text).isEmpty().nand().isNotBlank().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(true).isTrue().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(true).isFalse().isOK());

    assertFalse(
            Assertor.that(text).isEmpty().nand(text.getClass()).isAssignableFrom(CharSequence.class).isOK());
    assertTrue(
            Assertor.that(text).isEmpty().nand(text.getClass()).isAssignableFrom(StringBuilder.class).isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(Calendar.getInstance())
            .isAfter(DateUtils.getCalendar(new Date(0))).isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Calendar.getInstance())
            .isBefore(DateUtils.getCalendar(new Date(0))).isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(new Date()).isAfter(new Date(0)).isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(new Date()).isBefore(new Date(0)).isOK());

    assertFalse(Assertor.that(text).isNotEmpty().nand(LocalDateTime.now()).isAfter(LocalDateTime.MAX).isOK());
    assertFalse(Assertor.that(text).isNotEmpty().nand(LocalDateTime.now()).isAfter(LocalDateTime.MIN).isOK());

    assertFalse(Assertor.that(text).isNotEmpty().nandNumber(t -> t.length()).isGT(Integer.MAX_VALUE).isOK());
    assertFalse(Assertor.that(text).isNotEmpty().nandNumber(t -> t.length()).isGT(Integer.MIN_VALUE).isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(2).isGT(1).isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(2).isLT(1).isOK());

    assertFalse(Assertor.that(text).isEmpty().nand("tt").isNotEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand("tt").isEmpty().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(new String[] {}).isEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(new String[] {}).isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(new String[] {}, EnumAnalysisMode.STREAM).isEmpty().isOK());
    assertTrue(
            Assertor.that(text).isEmpty().nand(new String[] {}, EnumAnalysisMode.STREAM).isNotEmpty().isOK());
    assertFalse(
            Assertor.that(text).isEmpty().nand(new String[] {}, EnumAnalysisMode.PARALLEL).isEmpty().isOK());
    assertTrue(
            Assertor.that(text).isEmpty().nand(new String[] {}, EnumAnalysisMode.PARALLEL).isNotEmpty().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyList()).isEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyList()).isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyList(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyList(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyList(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyList(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyMap()).isEmpty().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyMap()).isNotEmpty().isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyMap(), EnumAnalysisMode.STREAM).isEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyMap(), EnumAnalysisMode.STREAM).isNotEmpty()
            .isOK());
    assertFalse(Assertor.that(text).isEmpty().nand(Collections.emptyMap(), EnumAnalysisMode.PARALLEL).isEmpty()
            .isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(Collections.emptyMap(), EnumAnalysisMode.PARALLEL)
            .isNotEmpty().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand((Object) 0).isNotNull().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand((Object) 0).isNull().isOK());

    assertFalse(Assertor.that(text).isEmpty().nand(new Exception()).isNotNull().isOK());
    assertTrue(Assertor.that(text).isEmpty().nand(new Exception()).isNull().isOK());

    assertFalse(Assertor.that(Color.BLACK).isNull().nand().isEqual(Color.black).isOK());
    assertFalse(Assertor.that(Color.BLACK).isNull().nand((Object) 0).isNotNull().isOK());

    assertFalse(Assertor.that(Color.BLACK).isNotNull().nand(Assertor.that(text).isEmpty()).isOK());
    assertEquals("the combination 'true' and ' NAND ' is invalid",
            Assertor.that(Color.BLACK).isNotNull().nand(Assertor.that(text).isEmpty()).getErrors().get());

    // SUB ASSERTOR

    assertTrue(Assertor.that(text).isEmpty().nandAssertor(t -> Assertor.that(t.length()).isGT(4)).isOK());
    assertEquals("the combination 'true' and ' NAND ' is invalid", Assertor.that(text).isNotEmpty()
            .nandAssertor(t -> Assertor.that(t.length()).isGT(4)).getErrors().get());

    assertException(
            () -> Assertor.that(text).isNotEmpty()
                    .nandAssertor((Function<String, StepCharSequence<String>>) null).isOK(),
            IllegalStateException.class, "sub assertor cannot be null");

    // MAPPER

    assertException(() -> Assertor.that(text).isNotEmpty().nandNumber((Function<String, Integer>) null)
            .isGT(Integer.MAX_VALUE).isOK(), IllegalStateException.class, "property cannot be null");

    assertTrue(Assertor.that(false).isTrue().nandObject(b -> b.toString()).hasHashCode(0).isOK());
    assertTrue(Assertor.that(false).isTrue().nandCharSequence(b -> b.toString()).contains("ue").isOK());
    assertTrue(Assertor.that("test").isEmpty()
            .nandArray(s -> ArrayUtils.toObject(s.getBytes(StandardCharsets.UTF_8))).contains((byte) 'x')
            .isOK());
    assertTrue(Assertor.that(false).isTrue().nandBoolean(b -> !b).isFalse().isOK());
    assertTrue(Assertor.that(false).isTrue().nandClass(b -> b.getClass()).hasSimpleName("Bool").isOK());
    assertTrue(Assertor.that(false).isTrue().nandDate(b -> new Date(1464475553641L))
            .isBefore(new Date(1464475553640L)).isOK());
    assertTrue(Assertor.that(false).isTrue().nandCalendar(b -> DateUtils.getCalendar(new Date(1464475553641L)))
            .isAfter(Calendar.getInstance()).isOK());
    assertTrue(Assertor.that(false).isTrue()
            .nandTemporal(b -> DateUtils.getLocalDateTime(new Date(1464475553641L)))
            .isAfter(LocalDateTime.now()).isOK());
    assertTrue(Assertor.that(false).isTrue().nandEnum(b -> EnumOperator.OR).hasName("AND").isOK());
    assertTrue(Assertor.that(false).isTrue().nandIterable(b -> Arrays.asList('t', 'r')).contains('u').isOK());
    assertTrue(Assertor.that(false).isTrue().nandMap(b -> MapUtils2.newHashMap("key", b)).contains("key", true)
            .isOK());
    assertTrue(Assertor.that(false).isTrue().nandNumber(b -> b.hashCode()).isGT(Integer.MAX_VALUE).isOK()); // 1231
    assertTrue(Assertor.that(false).isTrue().nandThrowable(b -> new IOException(b.toString()))
            .validates(e -> e.getMessage().contains("true")).isOK());
}

From source file:ch.wisv.areafiftylan.UserRestIntegrationTest.java

@Test
public void testExpiredUsersMultipleExpired() {
    User tempUser1 = makeAndGetTempUser("1");
    User tempUser2 = makeAndGetTempUser("2");

    VerificationToken token1 = verificationTokenRepository.findByUser(tempUser1).get();
    VerificationToken token2 = verificationTokenRepository.findByUser(tempUser2).get();
    token1.setExpiryDate(LocalDateTime.now().minusDays(1));
    token2.setExpiryDate(LocalDateTime.now().minusDays(1));
    verificationTokenRepository.save(token1);
    verificationTokenRepository.save(token2);

    int expiredCount = verificationTokenRepository.findAllByExpiryDateBefore(LocalDateTime.now()).size();
    Assert.assertEquals(2, expiredCount);

    taskScheduler.CleanUpUsers();// w w  w . j av  a  2s .  co  m

    Assert.assertFalse(verificationTokenRepository.findByUser(tempUser1).isPresent());
    Assert.assertFalse(verificationTokenRepository.findByUser(tempUser2).isPresent());
}

From source file:de.sub.goobi.forms.IndexingForm.java

/**
 * Return the progress in percent of the currently running indexing process. If
 * the list of entries to be indexed is empty, this will return "0".
 *
 * @param numberOfObjects/*from  ww  w  .  j av  a  2s. c om*/
 *            the number of existing objects of the given ObjectType in the
 *            database
 * @param currentType
 *            the ObjectType for which the progress will be determined
 * @param nrOfindexedObjects
 *            the number of objects of the given ObjectType that have already
 *            been indexed
 *
 * @return the progress of the current indexing process in percent
 */
private int getProgress(long numberOfObjects, ObjectType currentType, long nrOfindexedObjects) {
    int progress = numberOfObjects > 0 ? (int) ((nrOfindexedObjects / (float) numberOfObjects) * 100) : 0;
    if (Objects.equals(currentIndexState, currentType)) {
        if (numberOfObjects == 0 || progress == 100) {
            lastIndexed.put(currentIndexState, LocalDateTime.now());
            currentIndexState = ObjectType.NONE;
            indexerThread.interrupt();
            pollingChannel.send(INDEXING_FINISHED_MESSAGE + currentType + "!");
        }
    }
    return progress;
}

From source file:no.asgari.civilization.server.action.GameAction.java

/**
 * Gets public chat which is 1 week old and maximum 50 entries, sorted on created
 */// w  ww.  j  ava2 s.  com
public List<ChatDTO> getPublicChat() {
    return chatCollection.find(DBQuery.notExists("pbfId")).sort(DBSort.desc("created")).toArray().stream()
            .filter(c -> c.getCreated().isAfter(LocalDateTime.now().minusWeeks(2)))
            .sorted((a, b) -> a.getCreated().compareTo(b.getCreated()))
            .map(c -> new ChatDTO(c.getUsername(), c.getMessage(), c.getCreatedInMillis())).limit(50)
            .collect(toList());
}

From source file:alfio.manager.WaitingQueueManagerIntegrationTest.java

private List<TicketCategoryModification> getPreSalesTicketCategoryModifications(boolean firstBounded,
        int firstSeats, boolean lastBounded, int lastSeats) {
    LocalDateTime start = LocalDateTime.now().plusMinutes(4);
    return Arrays.asList(
            new TicketCategoryModification(null, "defaultFirst", firstSeats,
                    new DateTimeModification(start.toLocalDate(), start.toLocalTime()),
                    new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()), DESCRIPTION,
                    BigDecimal.TEN, false, "", firstBounded, null, null, null, null, null),
            new TicketCategoryModification(null, "defaultLast", lastSeats,
                    new DateTimeModification(LocalDate.now().plusDays(1), LocalTime.now()),
                    new DateTimeModification(LocalDate.now().plusDays(2), LocalTime.now()), DESCRIPTION,
                    BigDecimal.TEN, false, "", lastBounded, null, null, null, null, null));
}