@Override public String execute() throws Exception { TaskId taskId = new TaskId(TaskCategory.DATAMART, currentUserService.getCurrentUser()); notifier.clear(taskId); ScheduledTasks tasks = new ScheduledTasks(); // --------------------------------------------------------------------- // Analytics // --------------------------------------------------------------------- if (analytics) { analyticsTableTask.setTaskId(taskId); tasks.addTask(resourceTableTask); tasks.addTask(analyticsTableTask); } // --------------------------------------------------------------------- // Data mart // --------------------------------------------------------------------- if (dataMart) { Date start = DateUtils.getMediumDate(startDate); Date end = DateUtils.getMediumDate(endDate); List<Period> periods = new ArrayList<Period>(); for (String type : periodTypes) { CalendarPeriodType periodType = (CalendarPeriodType) PeriodType.getPeriodTypeByName(type); periods.addAll(periodType.generatePeriods(start, end)); } if (periods.size() > 0) { dataMartTask.setPeriods(periods); dataMartTask.setTaskId(taskId); tasks.addTask(dataMartTask); } } if (!tasks.isEmpty()) { scheduler.executeTask(tasks); } return SUCCESS; }
/** * Gets the current and most recent periods to search, based on the period types from the rules to * run. * * <p>For each period type, return the period containing the current date (if any), and the most * recent previous period. Add whichever of these periods actually exist in the database. * * <p>TODO If the last successful daily run was more than one day ago, we might add some * additional periods of type DailyPeriodType not to miss any alerts. * * @param rules the ValidationRules to be evaluated on this run * @return periods to search for new alerts */ private Set<Period> getAlertPeriodsFromRules(Set<ValidationRule> rules) { Set<Period> periods = new HashSet<>(); Set<PeriodType> rulePeriodTypes = getPeriodTypesFromRules(rules); for (PeriodType periodType : rulePeriodTypes) { CalendarPeriodType calendarPeriodType = (CalendarPeriodType) periodType; Period currentPeriod = calendarPeriodType.createPeriod(); Period previousPeriod = calendarPeriodType.getPreviousPeriod(currentPeriod); periods.addAll( periodService.getIntersectingPeriodsByPeriodType( periodType, previousPeriod.getStartDate(), currentPeriod.getEndDate())); } return periods; }
private List<Period> getPeriodsForDataSet(int id) { DataSet dataSet = dataSetService.getDataSet(id); if (dataSet == null) { return new ArrayList<Period>(); } CalendarPeriodType periodType = (CalendarPeriodType) dataSet.getPeriodType(); List<Period> periods = periodType.generateLast5Years(new Date()); FilterUtils.filter(periods, new PastAndCurrentPeriodFilter()); Collections.reverse(periods); if (periods.size() > 10) { periods = periods.subList(0, 10); } return periods; }
public List<Period> getPeriods(Period lastPeriod, int historyLength) { List<Period> periods = new ArrayList<Period>(historyLength); lastPeriod = periodStore.reloadForceAddPeriod(lastPeriod); CalendarPeriodType periodType = (CalendarPeriodType) lastPeriod.getPeriodType(); Period p = new Period(); for (int i = 0; i < historyLength; ++i) { p = getPeriodFromDates(lastPeriod.getStartDate(), lastPeriod.getEndDate(), periodType); periods.add(p != null ? p : lastPeriod); lastPeriod = periodType.getPreviousPeriod(lastPeriod); } Collections.reverse(periods); return periods; }
public String execute() throws Exception { String periodType = "Quarterly"; // periodType = periodType != null && !periodType.isEmpty() ? periodType : // MonthlyPeriodType.NAME; CalendarPeriodType _periodType = (CalendarPeriodType) CalendarPeriodType.getPeriodTypeByName(periodType); int thisYear = Calendar.getInstance().get(Calendar.YEAR); int currentYear = (Integer) SessionUtils.getSessionVar(SessionUtils.KEY_CURRENT_YEAR, thisYear); Calendar cal = PeriodType.createCalendarInstance(); // Cannot go to next year if current year equals this year if (!(currentYear == thisYear && year > 0)) { cal.set(Calendar.YEAR, currentYear); cal.add(Calendar.YEAR, year); SessionUtils.setSessionVar(SessionUtils.KEY_CURRENT_YEAR, cal.get(Calendar.YEAR)); } periods = _periodType.generatePeriods(cal.getTime()); FilterUtils.filter(periods, new PastAndCurrentPeriodFilter()); Collections.reverse(periods); for (Period period : periods) { period.setName(format.formatPeriod(period)); } return SUCCESS; }