Search in sources :

Example 51 with ZoneId

use of java.time.ZoneId in project carbon-apimgt by wso2.

the class ApiApiServiceImpl method apiCountOverTimeGet.

/**
 * Get list of API count information
 *
 * @param startTime Filter for start time stamp
 * @param endTime   Filter for end time stamp
 * @param createdBy Filter for created user
 * @param request   MSF4J request
 * @return API Count information
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response apiCountOverTimeGet(String startTime, String endTime, String createdBy, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        log.debug("Retrieving APIs created over time. [From: {}  To: {} Created By: {}]", startTime, endTime, createdBy);
        Analyzer analyzer = RestApiUtil.getAnalyzer(username);
        ZoneId requestTimezone = RestApiUtil.getRequestTimeZone(startTime);
        List<APICount> apiCountList = analyzer.getAPICount(fromISO8601ToInstant(startTime), fromISO8601ToInstant(endTime), createdBy);
        APICountListDTO apiCountListDTO = AnalyticsMappingUtil.fromAPICountToListDTO(apiCountList, requestTimezone);
        return Response.ok().entity(apiCountListDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API created over time info";
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APICount(org.wso2.carbon.apimgt.core.models.analytics.APICount) ZoneId(java.time.ZoneId) APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) APICountListDTO(org.wso2.carbon.apimgt.rest.api.analytics.dto.APICountListDTO) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) Analyzer(org.wso2.carbon.apimgt.core.api.Analyzer)

Example 52 with ZoneId

use of java.time.ZoneId in project alf.io by alfio-event.

the class TicketReservationManager method sendAssignmentReminder.

private void sendAssignmentReminder(Pair<Event, List<String>> p) {
    try {
        requiresNewTransactionTemplate.execute(status -> {
            Event event = p.getLeft();
            ZoneId eventZoneId = event.getZoneId();
            int quietPeriod = configurationManager.getIntConfigValue(Configuration.from(event.getOrganizationId(), event.getId(), ConfigurationKeys.ASSIGNMENT_REMINDER_INTERVAL), 3);
            p.getRight().stream().map(id -> findByIdForNotification(id, eventZoneId, quietPeriod)).filter(Optional::isPresent).map(Optional::get).forEach(reservation -> {
                Map<String, Object> model = prepareModelForReservationEmail(event, reservation);
                ticketReservationRepository.updateLatestReminderTimestamp(reservation.getId(), ZonedDateTime.now(eventZoneId));
                Locale locale = findReservationLanguage(reservation.getId());
                notificationManager.sendSimpleEmail(event, reservation.getEmail(), messageSource.getMessage("reminder.ticket-not-assigned.subject", new Object[] { event.getDisplayName() }, locale), () -> templateManager.renderTemplate(event, TemplateResource.REMINDER_TICKETS_ASSIGNMENT_EMAIL, model, locale));
            });
            return null;
        });
    } catch (Exception ex) {
        log.warn("cannot send reminder message", ex);
    }
}
Also used : alfio.repository(alfio.repository) PaymentProxy(alfio.model.transaction.PaymentProxy) DiscountType(alfio.model.PromoCodeDiscount.DiscountType) ZonedDateTime(java.time.ZonedDateTime) PaymentResult(alfio.manager.support.PaymentResult) AdditionalServicePriceContainer(alfio.model.decorator.AdditionalServicePriceContainer) PartialTicketTextGenerator(alfio.manager.support.PartialTicketTextGenerator) Mailer(alfio.manager.system.Mailer) TicketStatus(alfio.model.Ticket.TicketStatus) StringUtils(org.apache.commons.lang3.StringUtils) Collections.singletonList(java.util.Collections.singletonList) BigDecimal(java.math.BigDecimal) MonetaryUtil.formatCents(alfio.util.MonetaryUtil.formatCents) DateUtils.truncate(org.apache.commons.lang3.time.DateUtils.truncate) Pair(org.apache.commons.lang3.tuple.Pair) OFFLINE_PAYMENT(alfio.model.TicketReservation.TicketReservationStatus.OFFLINE_PAYMENT) Arrays.asList(java.util.Arrays.asList) ASReservationWithOptionalCodeModification(alfio.model.modification.ASReservationWithOptionalCodeModification) DefaultTransactionDefinition(org.springframework.transaction.support.DefaultTransactionDefinition) Triple(org.apache.commons.lang3.tuple.Triple) OrganizationRepository(alfio.repository.user.OrganizationRepository) Organization(alfio.model.user.Organization) Predicate(java.util.function.Predicate) FeeCalculator(alfio.manager.support.FeeCalculator) Visit(de.danielbechler.diff.node.Visit) Collectors(java.util.stream.Collectors) ZoneId(java.time.ZoneId) DiffNode(de.danielbechler.diff.node.DiffNode) Role(alfio.model.user.Role) Stream(java.util.stream.Stream) PlatformTransactionManager(org.springframework.transaction.PlatformTransactionManager) alfio.model(alfio.model) UserRepository(alfio.repository.user.UserRepository) AdditionalServiceItemPriceContainer(alfio.model.decorator.AdditionalServiceItemPriceContainer) Configuration(alfio.model.system.Configuration) AdditionalServiceItemStatus(alfio.model.AdditionalServiceItem.AdditionalServiceItemStatus) AdditionalServiceReservationModification(alfio.model.modification.AdditionalServiceReservationModification) OptionalWrapper.optionally(alfio.util.OptionalWrapper.optionally) IntStream(java.util.stream.IntStream) java.util(java.util) MonetaryUtil.unitToCents(alfio.util.MonetaryUtil.unitToCents) TransactionDefinition(org.springframework.transaction.TransactionDefinition) ConfigurationManager(alfio.manager.system.ConfigurationManager) Function(java.util.function.Function) alfio.util(alfio.util) TicketPriceContainer(alfio.model.decorator.TicketPriceContainer) IN_PAYMENT(alfio.model.TicketReservation.TicketReservationStatus.IN_PAYMENT) UserDetails(org.springframework.security.core.userdetails.UserDetails) TicketReservationStatus(alfio.model.TicketReservation.TicketReservationStatus) MessageSource(org.springframework.context.MessageSource) ObjectDifferBuilder(de.danielbechler.diff.ObjectDifferBuilder) TicketReservationWithOptionalCodeModification(alfio.model.modification.TicketReservationWithOptionalCodeModification) UpdateTicketOwnerForm(alfio.controller.form.UpdateTicketOwnerForm) IOException(java.io.IOException) Status(alfio.model.SpecialPrice.Status) DateUtils.addHours(org.apache.commons.lang3.time.DateUtils.addHours) Component(org.springframework.stereotype.Component) Validate(org.apache.commons.lang3.Validate) ChronoUnit(java.time.temporal.ChronoUnit) CategoryEvaluator(alfio.manager.support.CategoryEvaluator) TransactionTemplate(org.springframework.transaction.support.TransactionTemplate) Log4j2(lombok.extern.log4j.Log4j2) Clock(java.time.Clock) ConfigurationKeys(alfio.model.system.ConfigurationKeys) Transactional(org.springframework.transaction.annotation.Transactional) ZoneId(java.time.ZoneId) IOException(java.io.IOException)

Example 53 with ZoneId

use of java.time.ZoneId in project SimpleFlatMapper by arnaudroger.

the class JavaTimeConverterServiceTest method testObjectToOffsetTime.

@Test
public void testObjectToOffsetTime() throws Exception {
    ZoneId zoneId = ZoneId.systemDefault();
    OffsetTime offsetTime = OffsetTime.now(zoneId);
    testObjectToOffsetTime(null, null);
    testObjectToOffsetTime(offsetTime, offsetTime);
    testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()), offsetTime);
    testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).atZoneSimilarLocal(zoneId), offsetTime);
    testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).toLocalDateTime(), offsetTime);
    testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).toLocalTime(), offsetTime);
    testObjectToOffsetTime(offsetTime.atDate(LocalDate.now()).toInstant(), offsetTime);
    testObjectToOffsetTime(Date.from(offsetTime.atDate(LocalDate.now()).toInstant()), offsetTime.truncatedTo(ChronoUnit.MILLIS));
    try {
        testObjectToOffsetTime("a string", offsetTime);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : ZoneId(java.time.ZoneId) OffsetTime(java.time.OffsetTime) Test(org.junit.Test)

Example 54 with ZoneId

use of java.time.ZoneId in project SimpleFlatMapper by arnaudroger.

the class JavaTimeConverterServiceTest method testObjectToInstant.

@Test
public void testObjectToInstant() throws Exception {
    ZoneId zoneId = ZoneId.systemDefault();
    Instant instant = Instant.now();
    testObjectToInstant(null, null);
    testObjectToInstant(instant, instant);
    testObjectToInstant(instant.atZone(zoneId), instant);
    testObjectToInstant(instant.atZone(zoneId).toInstant(), instant);
    testObjectToInstant(instant.atZone(zoneId).toLocalDateTime(), instant);
    testObjectToInstant(instant.atZone(zoneId).toOffsetDateTime(), instant);
    testObjectToInstant(Date.from(instant), instant.truncatedTo(ChronoUnit.MILLIS));
    testObjectToInstant(instant.toEpochMilli(), instant.truncatedTo(ChronoUnit.MILLIS));
    try {
        testObjectToInstant("a string", instant);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : ZoneId(java.time.ZoneId) Instant(java.time.Instant) Test(org.junit.Test)

Example 55 with ZoneId

use of java.time.ZoneId in project SimpleFlatMapper by arnaudroger.

the class JavaTimeConverterServiceTest method testObjectToYearMonth.

@Test
public void testObjectToYearMonth() throws Exception {
    ZoneId zoneId = ZoneId.systemDefault();
    Date now = new Date();
    YearMonth yearMonth = YearMonth.from(now.toInstant().atZone(zoneId));
    testObjectToYearMonth(null, null);
    testObjectToYearMonth(yearMonth, yearMonth);
    testObjectToYearMonth(yearMonth.atEndOfMonth().atTime(1, 0).atZone(zoneId), yearMonth);
    testObjectToYearMonth(now, yearMonth);
    testObjectToYearMonth(yearMonth.getYear() * 100 + yearMonth.getMonthValue(), yearMonth);
    try {
        testObjectToYearMonth("a string", yearMonth);
        fail();
    } catch (IllegalArgumentException e) {
    // expected
    }
}
Also used : ZoneId(java.time.ZoneId) YearMonth(java.time.YearMonth) Date(java.util.Date) LocalDate(java.time.LocalDate) Test(org.junit.Test)

Aggregations

ZoneId (java.time.ZoneId)420 Test (org.junit.Test)137 ZonedDateTime (java.time.ZonedDateTime)108 LocalDateTime (java.time.LocalDateTime)69 LocalDate (java.time.LocalDate)55 Instant (java.time.Instant)49 Test (org.testng.annotations.Test)41 ZoneOffset (java.time.ZoneOffset)37 DateTimeFormatter (java.time.format.DateTimeFormatter)32 Date (java.util.Date)29 ArrayList (java.util.ArrayList)23 LocalTime (java.time.LocalTime)21 TemporalAccessor (java.time.temporal.TemporalAccessor)15 List (java.util.List)15 HashMap (java.util.HashMap)14 Clock (java.time.Clock)13 Collectors (java.util.stream.Collectors)13 DateTimeException (java.time.DateTimeException)12 Duration (java.time.Duration)12 OffsetDateTime (java.time.OffsetDateTime)11