List of usage examples for org.joda.time DateTime getHourOfDay
public int getHourOfDay()
From source file:org.egov.eventnotification.scheduler.NotificationSchedulerJob.java
License:Open Source License
/** * This method build the messageContent object and send it to pushbox to send the notification. * @param notificationSchedule/*from w w w .j av a 2s.c o m*/ * @param messageBody * @param seandAll * @param userIdList */ private void buildAndSendNotifications(Schedule notificationSchedule, String messageBody, Boolean seandAll, List<Long> userIdList) { User user = userService.getCurrentUser(); DateTime calendar = new DateTime(notificationSchedule.getStartDate()); int hours = calendar.getHourOfDay(); int minutes = calendar.getMinuteOfHour(); calendar.plusHours(hours); calendar.plusMinutes(minutes); DateTime calendarEnd = new DateTime(notificationSchedule.getStartDate()); int hours1 = calendarEnd.getHourOfDay(); int minutes1 = calendarEnd.getMinuteOfHour(); calendarEnd.plusHours(hours1 + 1); calendarEnd.plusMinutes(minutes1); MessageContent messageContent = new MessageContent(); MessageContentDetails messageDetails = new MessageContentDetails(); messageContent.setCreatedDateTime(new Date().getTime()); messageDetails.setEventDateTime(calendar.getMillis()); messageContent.setExpiryDate(calendarEnd.getMillis()); if (messageBody == null) messageContent.setMessageBody(notificationSchedule.getMessageTemplate()); else messageContent.setMessageBody(messageBody); messageContent.setModuleName(notificationSchedule.getTemplateName()); messageContent.setNotificationDateTime(new Date().getTime()); messageContent.setNotificationType(notificationSchedule.getDraftType().getName()); messageDetails.setSendAll(seandAll); if (userIdList != null) messageDetails.setUserIdList(userIdList); messageContent.setSenderId(user.getId()); messageContent.setSenderName(user.getName()); messageContent.setDetails(messageDetails); messageContent.setCityName(ApplicationThreadLocals.getCityName()); messageContent.setUlbCode(ApplicationThreadLocals.getCityCode()); pushNotificationService.sendNotifications(messageContent); }
From source file:org.egov.eventnotification.service.EventDetailsService.java
License:Open Source License
protected void populateEventDetails(Event event) { EventDetails details = new EventDetails(); DateTime sd = new DateTime(event.getStartDate()); details.setStartDt(getDate(getDefaultFormattedDate(event.getStartDate()), DDMMYYYY)); if (sd.getHourOfDay() < MAX_TEN) details.setStartHH(ZERO + String.valueOf(sd.getHourOfDay())); else/* w w w.j a v a2s. co m*/ details.setStartHH(String.valueOf(sd.getHourOfDay())); if (sd.getMinuteOfHour() < MAX_TEN) details.setStartMM(ZERO + String.valueOf(sd.getMinuteOfHour())); else details.setStartMM(String.valueOf(sd.getMinuteOfHour())); DateTime ed = new DateTime(event.getEndDate()); details.setEndDt(getDate(getDefaultFormattedDate(event.getEndDate()), DDMMYYYY)); if (ed.getHourOfDay() < MAX_TEN) details.setEndHH(ZERO + String.valueOf(ed.getHourOfDay())); else details.setEndHH(String.valueOf(ed.getHourOfDay())); if (ed.getMinuteOfHour() < MAX_TEN) details.setEndMM(ZERO + String.valueOf(ed.getMinuteOfHour())); else details.setEndMM(String.valueOf(ed.getMinuteOfHour())); if (event.isPaid()) details.setPaid("Yes"); else details.setPaid("No"); event.setDetails(details); }
From source file:org.egov.eventnotification.service.ScheduleDetailsService.java
License:Open Source License
/** * This method take a cron expression from properties file and replace the hour,minute,day and month into the placeholder to * make dynamic cron expression.// ww w. java2 s . co m * * @param notificationschedule * @return */ private String getCronExpression(Schedule notificationschedule) { String cronExpression = null; DateTime calendar = new DateTime(notificationschedule.getStartDate()); int hours = calendar.getHourOfDay(); int minutes = calendar.getMinuteOfHour(); switch (notificationschedule.getScheduleRepeat().getName().toLowerCase()) { case "day": cronExpression = appProperties.getDailyCron().replace(MINUTES_CRON, String.valueOf(minutes)); cronExpression = cronExpression.replace(HOURS_CRON, String.valueOf(hours)); break; case "month": cronExpression = appProperties.getMonthlyCron().replace(MINUTES_CRON, String.valueOf(minutes)); cronExpression = cronExpression.replace(HOURS_CRON, String.valueOf(hours)); cronExpression = cronExpression.replace(DAY_CRON, String.valueOf(calendar.getDayOfMonth())); break; case "year": cronExpression = appProperties.getYearlyCron().replace(MINUTES_CRON, String.valueOf(minutes)); cronExpression = cronExpression.replace(HOURS_CRON, String.valueOf(hours)); cronExpression = cronExpression.replace(DAY_CRON, String.valueOf(calendar.getDayOfMonth())); cronExpression = cronExpression.replace(MONTH_CRON, String.valueOf(calendar.getMonthOfYear())); break; default: break; } return cronExpression; }
From source file:org.egov.eventnotification.service.ScheduleService.java
License:Open Source License
public List<Schedule> getAllSchedule() { List<Schedule> notificationScheduleList = null; notificationScheduleList = scheduleRepository.findByOrderByIdDesc(); if (!notificationScheduleList.isEmpty()) for (Schedule notificationSchedule : notificationScheduleList) { EventDetails details = new EventDetails(); DateTime sd = new DateTime(notificationSchedule.getStartDate()); details.setStartDt(getDate(getDefaultFormattedDate(notificationSchedule.getStartDate()), DDMMYYYY)); if (sd.getHourOfDay() < MAX_TEN) details.setStartHH(ZERO + String.valueOf(sd.getHourOfDay())); else//w ww . j a v a 2 s . co m details.setStartHH(String.valueOf(sd.getHourOfDay())); if (sd.getMinuteOfHour() < MAX_TEN) details.setStartMM(ZERO + String.valueOf(sd.getMinuteOfHour())); else details.setStartMM(String.valueOf(sd.getMinuteOfHour())); notificationSchedule.setDetails(details); } return notificationScheduleList; }
From source file:org.egov.eventnotification.service.ScheduleService.java
License:Open Source License
public Schedule getScheduleById(Long id) { Schedule schedule = scheduleRepository.findOne(id); EventDetails details = new EventDetails(); DateTime sd = new DateTime(schedule.getStartDate()); details.setStartDt(getDate(getDefaultFormattedDate(schedule.getStartDate()), DDMMYYYY)); if (sd.getHourOfDay() < MAX_TEN) details.setStartHH(ZERO + String.valueOf(sd.getHourOfDay())); else/*from www . ja v a2 s .c o m*/ details.setStartHH(String.valueOf(sd.getHourOfDay())); if (sd.getMinuteOfHour() < MAX_TEN) details.setStartMM(ZERO + String.valueOf(sd.getMinuteOfHour())); else details.setStartMM(String.valueOf(sd.getMinuteOfHour())); schedule.setDetails(details); return schedule; }
From source file:org.envirocar.analyse.categories.TimeBasedCategory.java
License:Apache License
public static TimeBasedCategory fromTime(DateTime dt) { int dow = dt.getDayOfWeek(); int hod = dt.getHourOfDay(); String prefix;/*from ww w. j ava2 s. c o m*/ if (dow < DateTimeConstants.SATURDAY) { prefix = "WEEKDAY"; } else if (dow == DateTimeConstants.SATURDAY) { prefix = "SATURDAY"; } else if (dow == DateTimeConstants.SUNDAY) { prefix = "SUNDAY"; } else { return NO_CATEGORY; } if (hod >= 6 && hod < 10) { return TimeBasedCategory.valueOf(prefix.concat("_6_10")); } if (hod >= 10 && hod < 15) { return TimeBasedCategory.valueOf(prefix.concat("_10_15")); } if (hod >= 15 && hod < 19) { return TimeBasedCategory.valueOf(prefix.concat("_15_19")); } else { return TimeBasedCategory.valueOf(prefix.concat("_OTHER")); } }
From source file:org.epics.archiverappliance.common.TimeUtils.java
/** * Returns a partition name for the given epoch second based on the partition granularity. * //from ww w . j a v a2s .co m * @param epochseconds * @return */ public static String getPartitionName(long epochSeconds, PartitionGranularity granularity) { DateTime dateTime = new DateTime(epochSeconds * 1000, DateTimeZone.UTC); switch (granularity) { case PARTITION_YEAR: return "" + dateTime.getYear(); case PARTITION_MONTH: return "" + dateTime.getYear() + "_" + (dateTime.getMonthOfYear() < 10 ? TWO_DIGIT_EXPANSIONS[dateTime.getMonthOfYear()] : dateTime.getMonthOfYear()); case PARTITION_DAY: return "" + dateTime.getYear() + "_" + (dateTime.getMonthOfYear() < 10 ? TWO_DIGIT_EXPANSIONS[dateTime.getMonthOfYear()] : dateTime.getMonthOfYear()) + "_" + (dateTime.getDayOfMonth() < 10 ? TWO_DIGIT_EXPANSIONS[dateTime.getDayOfMonth()] : dateTime.getDayOfMonth()); case PARTITION_HOUR: return "" + dateTime.getYear() + "_" + (dateTime.getMonthOfYear() < 10 ? TWO_DIGIT_EXPANSIONS[dateTime.getMonthOfYear()] : dateTime.getMonthOfYear()) + "_" + (dateTime.getDayOfMonth() < 10 ? TWO_DIGIT_EXPANSIONS[dateTime.getDayOfMonth()] : dateTime.getDayOfMonth()) + "_" + (dateTime.getHourOfDay() < 10 ? TWO_DIGIT_EXPANSIONS[dateTime.getHourOfDay()] : dateTime.getHourOfDay()); case PARTITION_5MIN: case PARTITION_15MIN: case PARTITION_30MIN: int approxMinutesPerChunk = granularity.getApproxMinutesPerChunk(); int startOfPartition_Min = (dateTime.getMinuteOfHour() / approxMinutesPerChunk) * approxMinutesPerChunk; return "" + dateTime.getYear() + "_" + (dateTime.getMonthOfYear() < 10 ? TWO_DIGIT_EXPANSIONS[dateTime.getMonthOfYear()] : dateTime.getMonthOfYear()) + "_" + (dateTime.getDayOfMonth() < 10 ? TWO_DIGIT_EXPANSIONS[dateTime.getDayOfMonth()] : dateTime.getDayOfMonth()) + "_" + (dateTime.getHourOfDay() < 10 ? TWO_DIGIT_EXPANSIONS[dateTime.getHourOfDay()] : dateTime.getHourOfDay()) + "_" + (startOfPartition_Min < 10 ? TWO_DIGIT_EXPANSIONS[startOfPartition_Min] : startOfPartition_Min); default: throw new UnsupportedOperationException("Invalid Partition type " + granularity); } }
From source file:org.everit.jira.timetracker.plugin.util.DateTimeConverterUtil.java
License:Apache License
/** * Convert joda DateTime to java Date. Convert the date and time without Time Zone correction. * (the joda DateTime toDate metod add the time zone). * * @param dateTime/*from w ww. ja va2s . c om*/ * The dateTime. * @return The new date. */ @SuppressWarnings("deprecation") public static Date convertDateTimeToDate(final DateTime dateTime) { return new Date(dateTime.getYear() - YEAR_1900, dateTime.getMonthOfYear() - 1, dateTime.getDayOfMonth(), dateTime.getHourOfDay(), dateTime.getMinuteOfHour(), dateTime.getSecondOfMinute()); }
From source file:org.fenixedu.academic.service.CreateUnavailablePeriod.java
License:Open Source License
private static void sendEmail(Person person, DateTime begin, DateTime end, String justification, List<VigilantGroup> groups) { for (VigilantGroup group : groups) { String bccs = group.getContactEmail(); String beginDate = begin.getDayOfMonth() + "/" + begin.getMonthOfYear() + "/" + begin.getYear() + " - " + String.format("%02d", begin.getHourOfDay()) + ":" + String.format("%02d", begin.getMinuteOfHour()) + "h"; String endDate = end.getDayOfMonth() + "/" + end.getMonthOfYear() + "/" + end.getYear() + " - " + String.format("%02d", end.getHourOfDay()) + ":" + String.format("%02d", end.getMinuteOfHour()) + "h"; ;//from w w w. j av a2 s . c o m String message = BundleUtil.getString("resources.VigilancyResources", "email.convoke.unavailablePeriod", new String[] { person.getName(), beginDate, endDate, justification }); String subject = BundleUtil.getString("resources.VigilancyResources", "email.convoke.unavailablePeriod.subject", new String[] { group.getName() }); Sender sender = Bennu.getInstance().getSystemSender(); new Message(sender, new ConcreteReplyTo(group.getContactEmail()).asCollection(), Collections.EMPTY_LIST, subject, message, bccs); } }
From source file:org.fenixedu.academic.ui.struts.action.operator.SubmitPhotoAction.java
License:Open Source License
public ActionForward photoUpload(ActionMapping mapping, ActionForm actionForm, HttpServletRequest request, HttpServletResponse response) throws Exception { PhotographUploadBean photo = getRenderedObject(); RenderUtils.invalidateViewState();//from w w w. j a v a 2s . c o m String base64Thumbnail = request.getParameter("encodedThumbnail"); String base64Image = request.getParameter("encodedPicture"); if (base64Image != null && base64Thumbnail != null) { DateTime now = new DateTime(); photo.setFilename("mylovelypic_" + now.getYear() + now.getMonthOfYear() + now.getDayOfMonth() + now.getHourOfDay() + now.getMinuteOfDay() + now.getSecondOfMinute() + ".png"); photo.setBase64RawContent(base64Image.split(",")[1]); photo.setBase64RawThumbnail(base64Thumbnail.split(",")[1]); photo.setContentType(base64Image.split(",")[0].split(":")[1].split(";")[0]); } ActionMessages actionMessages = new ActionMessages(); try (InputStream stream = photo.getFileInputStream()) { if (stream == null) { actionMessages.add("error", new ActionMessage("errors.fileRequired")); saveMessages(request, actionMessages); return preparePhotoUpload(mapping, actionForm, request, response); } } if (ContentType.getContentType(photo.getContentType()) == null) { actionMessages.add("error", new ActionMessage("errors.unsupportedFile")); saveMessages(request, actionMessages); return preparePhotoUpload(mapping, actionForm, request, response); } if (photo.getRawSize() > MAX_RAW_SIZE) { actionMessages.add("error", new ActionMessage("errors.fileTooLarge")); saveMessages(request, actionMessages); photo.deleteTemporaryFiles(); return preparePhotoUpload(mapping, actionForm, request, response); } try { photo.processImage(); } catch (UnableToProcessTheImage e) { actionMessages.add("error", new ActionMessage("errors.unableToProcessImage")); saveMessages(request, actionMessages); photo.deleteTemporaryFiles(); return preparePhotoUpload(mapping, actionForm, request, response); } try { updatePersonPhoto(photo); } catch (Exception e) { actionMessages.add("error", new ActionMessage("errors.unableToSaveImage")); saveMessages(request, actionMessages); photo.deleteTemporaryFiles(); return preparePhotoUpload(mapping, actionForm, request, response); } actionMessages.add("success", new ActionMessage("label.operator.submit.ok", "")); saveMessages(request, actionMessages); return preparePhotoUpload(mapping, actionForm, request, response); }