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();
}
}
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);
}
}
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
}
}
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
}
}
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
}
}
Aggregations