/** * Adds the scheduled notifications. * * @param reportDefinition the report definition * @param report the report */ public void addScheduledNotifications(ReportDefinition reportDefinition, Report report) { // Note : there is a change in busineess requirement, that at firing time only we generate the // message/recipients // So only one Scheduled Notification per Planned Notification. if (CollectionUtils.isEmpty(reportDefinition.getPlannedNotifications())) return; Date now = nowFactory.getNow(); Calendar cal = GregorianCalendar.getInstance(); for (PlannedNotification plannedNotification : reportDefinition.getPlannedNotifications()) { ScheduledNotification scheduledNotification = plannedNotification.createScheduledNotification("dummy"); if (plannedNotification instanceof PlannedEmailNotification) { ScheduledEmailNotification scheduledEmailNotification = (ScheduledEmailNotification) scheduledNotification; scheduledEmailNotification.setBody("dummy"); scheduledEmailNotification.setSubjectLine("dummy"); } // set the scheduled dates if (reportDefinition.getBaseDate() != null) cal.setTime(reportDefinition.getBaseDate()); else cal.setTime(now); cal.add( reportDefinition.getTimeScaleUnitType().getCalendarTypeCode(), plannedNotification.getIndexOnTimeScale()); scheduledNotification.setScheduledOn(cal.getTime()); if (plannedNotification.getIndexOnTimeScale() == 0 || DateUtils.compateDateAndTime(now, cal.getTime()) < 0) report.addScheduledNotification(scheduledNotification); } }
@Override public Map<String, Object> referenceData( HttpServletRequest request, ReportDefinitionCommand command) { Map<String, Object> map = new LinkedHashMap<String, Object>(); BeanWrapper wrappedCommand = new BeanWrapperImpl(command); // basic details tab fields TabWithFields<ReportDefinitionCommand> tab = getTabFromFlow(getFlow(), BasicsTab.class); Map<String, InputFieldGroup> fieldGroupMap = tab.createFieldGroups(command); InputFieldGroup fieldGroup = fieldGroupMap.get("reportDefinitionOrganization"); List<Pair> fieldList = fetchFieldValues(fieldGroup, wrappedCommand); fieldGroup = fieldGroupMap.get("reportDefinitionFieldGroup"); // the name of the // fieldgroup fieldList.addAll(fetchFieldValues(fieldGroup, wrappedCommand)); map.put(tab.getShortTitle(), fieldList); // report definition tab List<ReportDeliveryDefinition> deliveries = command.getReportDefinition().getDeliveryDefinitions(); if (deliveries != null) { List<Pair> pairs = new ArrayList<Pair>(); for (ReportDeliveryDefinition rdd : deliveries) { if (rdd.getEntityType() == ReportDeliveryDefinition.ENTITY_TYPE_PERSON) { Pair p = new Pair("Person", rdd.getEntityName()); p.setAttribute1(rdd.getEndPoint()); p.setAttribute2(rdd.getFormat().getDisplayName()); pairs.add(p); } if (rdd.getEntityType() == ReportDeliveryDefinition.ENTITY_TYPE_ROLE) { Pair p = new Pair("Role", rdd.getEntityName()); p.setAttribute1(String.valueOf(command.getRoles().get(rdd.getEndPoint()))); p.setAttribute2(rdd.getFormat().getDisplayName()); pairs.add(p); } } for (ReportDeliveryDefinition rdd : deliveries) { if (rdd.getEntityType() == ReportDeliveryDefinition.ENTITY_TYPE_SYSTEM) { Pair p = new Pair("System", rdd.getEntityName()); p.setAttribute1(rdd.getEndPoint()); p.setAttribute2(rdd.getFormat().getDisplayName()); pairs.add(p); } } map.put("rdd", pairs); } // Mandatory Field Definition Tab tab = getTabFromFlow(getFlow(), ReportMandatoryFieldDefinitionTab.class); fieldGroupMap = tab.createFieldGroups(command); map.put("mandatoryFields", fieldGroupMap); // Notification details tab tab = getTabFromFlow(getFlow(), NotificationsTab.class); fieldGroupMap = tab.createFieldGroups(command); Map<String, Object> pnfMap = new LinkedHashMap<String, Object>(); int i = 0; for (PlannedNotification nf : command.getReportDefinition().getPlannedNotifications()) { PlannedEmailNotification penf = (PlannedEmailNotification) nf; List<Pair> pairs = new ArrayList<Pair>(); i++; // - recipient StringBuilder sb = new StringBuilder(); for (Recipient r : penf.getRecipients()) { if (sb.length() > 0) sb.append(","); if (r instanceof RoleBasedRecipient) { sb.append(command.getRoles().get(r.getContact())); } else { sb.append(r.getContact()); } } pairs.add(new Pair("Recipients", sb.toString())); // - subject pairs.add(new Pair("Subject", penf.getSubjectLine())); // - body NotificationBodyContent body = penf.getNotificationBodyContent(); if (body != null) { pairs.add(new Pair("Message", body.getBody())); } else { pairs.add(new Pair("Message", null)); } ReportDefinition rep = command.getReportDefinition(); TimeScaleUnit unit = null; if (rep != null) { unit = rep.getTimeScaleUnitType(); } if (unit != null) { pnfMap.put( "Notification " + i + " of " + unit.getDisplayName() + " " + penf.getIndexOnTimeScale(), pairs); } else { pnfMap.put("Notification " + i + " of UNKNOWN " + penf.getIndexOnTimeScale(), pairs); } } map.put("PENF", pnfMap); Map<String, Object> refDataMap = super.referenceData(command); refDataMap.put("FIELDS", map); return refDataMap; }
/** * The logic for comparing these reports definitons is reverse in the sense that, lesser is the * period of reporting, higher is the priority In other words, we are comparing the priorties */ public int compare(ReportDefinition o1, ReportDefinition o2) { long l1 = o1.getTimeScaleUnitType().getMilliSecondConversionFactor() * o1.getDuration(); long l2 = o2.getTimeScaleUnitType().getMilliSecondConversionFactor() * o2.getDuration(); return (int) (l2 - l1); }