@Override public Date deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { if (parser.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) { final Calendar newCalendar = DateUtils.newCalendar(); newCalendar.setTimeInMillis(parser.getLongValue()); return newCalendar.getTime(); } return _parseDate(parser, context); }
@Override public String toString(final LocalDate value) { return String.valueOf(value.atStartOfDay(DateUtils.getApplicationTimeZone().toZoneId()).toInstant().toEpochMilli()); } }
/** * Update the application time zone. * * @param id * The new {@link TimeZone} identifier. */ @PUT @Path("timezone/application") public void setApplicationTimeZone(final String id) { DateUtils.setApplicationTimeZone(TimeZone.getTimeZone(id)); }
dateVo.setDate(DateUtils.newCalendar().getTime()); dateVo.setDefaultTimeZone(TimeZone.getDefault().getID()); dateVo.setTimeZone(DateUtils.getApplicationTimeZone().getID()); dateVo.setOriginalDefaultTimeZone(DateUtils.ORIGINAL_DEFAULT_TIMEZONE.getID());
/** * For each SLA, get the elapsed time for given issue. */ private List<SlaData> getSlaDurations(final IssueStatus issue, final List<Sla> slas, final List<Date> holidays, final List<BusinessHours> nonBusinessHours) { final List<SlaData> data = new ArrayList<>(); final Date now = DateUtils.newCalendar().getTime(); for (final Sla sla : slas) { if (checkAppliance(issue, sla)) { data.add(getSlaDuration(issue, sla, holidays, nonBusinessHours, now)); } else { // Not applicable -> null data.add(null); } } return data; }
@Override public void serialize(final LocalDate date, final JsonGenerator generator, final SerializerProvider provider) throws IOException { generator.writeNumber(date.atStartOfDay(DateUtils.getApplicationTimeZone().toZoneId()).toInstant().toEpochMilli()); }
@Override public UserDetails loadUserByUsername(final String username) { final Object[][] userAndRoles = userRepository.findByLoginFetchRoles(username); final SystemUser user; final Collection<GrantedAuthority> authorities; if (userAndRoles.length == 0) { user = new SystemUser(); user.setLogin(username); authorities = new ArrayList<>(); } else { user = (SystemUser) userAndRoles[0][0]; // Add all roles authorities = toSimpleRoles(userAndRoles, 1); } // Update last connection information only as needed for performance, delta is one minute final Date now = org.ligoj.bootstrap.core.DateUtils.newCalendar().getTime(); if (user.getLastConnection() == null || now.getTime() - user.getLastConnection().getTime() > DateUtils.MILLIS_PER_DAY) { user.setLastConnection(now); userRepository.saveAndFlush(user); } // Also add the default role as needed authorities.add(new SimpleGrantedAuthority(SystemRole.DEFAULT_ROLE)); return new User(username, "N/A", authorities); }
@Override public void serialize(final LocalDateTime date, final JsonGenerator generator, final SerializerProvider provider) throws IOException { generator.writeNumber(date.atZone(DateUtils.getApplicationTimeZone().toZoneId()).toInstant().toEpochMilli()); }
final Writer writer = new BufferedWriter(new OutputStreamWriter(output, "cp1252")); final FastDateFormat df = FastDateFormat.getInstance("yyyy/MM/dd HH:mm:ss"); final Date now = DateUtils.newCalendar().getTime(); writer.write(COMMON_CSV_HEADER + ";cron;operation;lastDateHMS;lastTimestamp;previousState;lastOperation;vm;lastTrigger;lastSucceed;lastStatusText;lastErrorText;nextDateHMS;nextTimestamp");
@Override public String toString(final Date value) { return String.valueOf(value.toInstant().atZone(DateUtils.getApplicationTimeZone().toZoneId()).toInstant().toEpochMilli()); } }
/** * Return all schedules related to given subscription. * * @param subscription * The subscription identifier. * @return All schedules related to given subscription. * @throws ParseException * When CRON cannot be parsed. */ @org.springframework.transaction.annotation.Transactional(readOnly = true) public List<VmScheduleVo> findAll(final int subscription) throws ParseException { final List<VmScheduleVo> schedules = new ArrayList<>(); final Date now = DateUtils.newCalendar().getTime(); for (final VmSchedule schedule : repository.findBySubscription(subscription)) { // Copy basic attributes final VmScheduleVo vo = new VmScheduleVo(); vo.setCron(schedule.getCron()); vo.setOperation(schedule.getOperation()); vo.setId(schedule.getId()); vo.setNext(new CronExpression(schedule.getCron()).getNextValidTimeAfter(now)); schedules.add(vo); } return schedules; }
@Override public LocalDate fromString(final String value) { if (value == null) { return null; } return Instant.ofEpochMilli(Long.parseLong(value)).atZone(DateUtils.getApplicationTimeZone().toZoneId()).toLocalDate(); }
/** * Get or create a new task associated to given subscription. * * @param lockedId * The locked entity's identifier. The related entity will be locked. * @return The task, never <code>null</code>. */ default T createAsNeeded(final I lockedId) { final T task = Optional.ofNullable(getTaskInternal(lockedId)).map(t -> { // Additional remote check (optional) if (!isFinished(t)) { // On this service, there is already a running remote task throw new BusinessException("concurrent-task-remote", t.getAuthor(), t.getStart(), lockedId); } return t; }).orElseGet(() -> { final T newTask = newTask().get(); newTask.setLocked(getLockedRepository().findOneExpected(lockedId)); return newTask; }); // Reset internal fields task.setAuthor(SpringUtils.getBean(SecurityHelper.class).getLogin()); task.setStart(DateUtils.newCalendar().getTime()); task.setEnd(null); task.setFailed(false); return task; }
/** * Pattern and data constructor. * * @param pattern * the pattern used to parse the input.. * @param data * the context data or another {@link Processor} instance. */ public ParseDateProcessor(final String pattern, final Object data) { super(data); this.format = FastDateFormat.getInstance(pattern, DateUtils.getApplicationTimeZone()); }
/** * Lock an user : * <ul> * <li>Clear the password to prevent new authentication</li> * <li>Set the disabled flag.</li> * </ul> * * @param principal * Principal user requesting the lock. * @param user * The LDAP user to disable. * @param isolate * When <code>true</code>, the user will be isolated in addition. */ private void lock(final String principal, final UserOrg user, final boolean isolate) { if (user.getLockedBy() == null) { // Not yet locked final ModificationItem[] mods = new ModificationItem[2]; final long timeInMillis = DateUtils.newCalendar().getTimeInMillis(); mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(lockedAttribute, String .format("%s|%s|%s|%s|", lockedValue, timeInMillis, principal, isolate ? user.getCompany() : ""))); mods[1] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute(PASSWORD_ATTRIBUTE, null)); template.modifyAttributes(org.springframework.ldap.support.LdapUtils.newLdapName(user.getDn()), mods); // Also update the disabled date user.setLocked(new Date(timeInMillis)); user.setLockedBy(principal); } }
@SuppressWarnings("unchecked") @Override public <D> D convert(final Class<D> type, final Object value) { return (D) Instant.ofEpochMilli(dateConverter.convert(Date.class, value).getTime()) .atZone(DateUtils.getApplicationTimeZone().toZoneId()).toLocalDate(); } }, LocalDate.class);
@Override public LocalDate deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { if (parser.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) { return Instant.ofEpochMilli(parser.getLongValue()).atZone(DateUtils.getApplicationTimeZone().toZoneId()).toLocalDate(); } return null; }
@Override public LocalDateTime deserialize(final JsonParser parser, final DeserializationContext context) throws IOException { if (parser.getCurrentToken() == JsonToken.VALUE_NUMBER_INT) { return Instant.ofEpochMilli(parser.getLongValue()).atZone(DateUtils.getApplicationTimeZone().toZoneId()).toLocalDateTime(); } return null; }
/** * Persist the trigger in the Quartz scheduler. */ private VmSchedule persistTrigger(final VmSchedule schedule) throws SchedulerException { // The trigger for the common VM Job will the following convention : // schedule.id-subscription.id final String id = VmJob.format(schedule); final JobDetailImpl object = (JobDetailImpl) vmJobDetailFactoryBean.getObject(); object.getJobDataMap().put("vmServicePlugin", this); final Trigger trigger = TriggerBuilder.newTrigger().withIdentity(id, SCHEDULE_TRIGGER_GROUP) .withSchedule(CronScheduleBuilder.cronSchedule(schedule.getCron()) .inTimeZone(DateUtils.getApplicationTimeZone())) .forJob(object).usingJobData("subscription", schedule.getSubscription().getId()) .usingJobData("operation", schedule.getOperation().name()).usingJobData("schedule", schedule.getId()) .build(); // Add this trigger vmSchedulerFactoryBean.getObject().scheduleJob(trigger); return schedule; }
dateConverter.setPatterns(DATE_PATTERNS); dateConverter.setLocale(Locale.FRANCE); dateConverter.setTimeZone(DateUtils.getApplicationTimeZone()); ConvertUtils.register(dateConverter, Date.class);