private String buildNotificationGroupsHtml() { StringBuilder html = new StringBuilder(); StatsAggHtmlFramework statsAggHtmlFramework = new StatsAggHtmlFramework(); String htmlHeader = statsAggHtmlFramework.createHtmlHeader("StatsAgg - " + PAGE_NAME, ""); StringBuilder htmlBodyStringBuilder = new StringBuilder(); htmlBodyStringBuilder.append( "<div id=\"page-content-wrapper\">\n" + "<!-- Keep all page content within the page-content inset div! -->\n" + "<div class=\"page-content inset statsagg_page_content_font\">\n" + " <div class=\"content-header\"> \n" + " <div class=\"pull-left content-header-h2-min-width-statsagg\"> <h2> " + PAGE_NAME + " </h2> </div>\n" + " <div class=\"pull-right \">\n" + " <a href=\"CreateNotificationGroup\" class=\"btn btn-primary statsagg_page_content_font\">Create New Notification Group <i class=\"fa fa-long-arrow-right\"></i></a> \n" + " </div>" + " </div>" + " <table id=\"NotificationGroupsTable\" style=\"display:none\" class=\"table table-bordered table-hover \">\n" + " <thead>\n" + " <tr>\n" + " <th>Notification Group Name</th>\n" + " <th>Email addresses</th>\n" + " <th>Operations</th>\n" + " </tr>\n" + " </thead>\n" + " <tbody>\n"); AlertsDao alertsDao = new AlertsDao(); Set<Integer> notificationGroupIdsAssociatedWithAlerts = alertsDao.getAllDistinctNotificationGroupIds(); NotificationGroupsDao notificationGroupsDao = new NotificationGroupsDao(); List<NotificationGroup> notificationGroups = notificationGroupsDao.getAllDatabaseObjectsInTable(); for (NotificationGroup notificationGroup : notificationGroups) { String notificationGroupDetails = "<a href=\"NotificationGroupDetails?Name=" + StatsAggHtmlFramework.urlEncode(notificationGroup.getName()) + "\">" + StatsAggHtmlFramework.htmlEncode(notificationGroup.getName()) + "</a>"; StringBuilder emailAddressesOutput = new StringBuilder(); String[] emailAddresses = StringUtils.split(notificationGroup.getEmailAddresses(), ","); if ((emailAddresses != null) && (emailAddresses.length != 0)) { for (int i = 0; i < emailAddresses.length; i++) { String trimmedEmailAddress = emailAddresses[i].trim(); emailAddressesOutput.append(trimmedEmailAddress); if ((i + 1) != emailAddresses.length) emailAddressesOutput.append(", "); } } String alter = "<a href=\"CreateNotificationGroup?Operation=Alter&Name=" + StatsAggHtmlFramework.urlEncode(notificationGroup.getName()) + "\">alter</a>"; List<KeyValue> cloneKeysAndValues = new ArrayList<>(); cloneKeysAndValues.add(new KeyValue("Operation", "Clone")); cloneKeysAndValues.add( new KeyValue("Name", Encode.forHtmlAttribute(notificationGroup.getName()))); String clone = StatsAggHtmlFramework.buildJavaScriptPostLink( "Clone_" + notificationGroup.getName(), "NotificationGroups", "clone", cloneKeysAndValues); List<KeyValue> testKeysAndValues = new ArrayList<>(); testKeysAndValues.add(new KeyValue("Operation", "Test")); testKeysAndValues.add( new KeyValue("Name", Encode.forHtmlAttribute(notificationGroup.getName()))); String test = StatsAggHtmlFramework.buildJavaScriptPostLink( "Test_" + notificationGroup.getName(), "NotificationGroups", "test", testKeysAndValues, true, "Are you sure you want to send a test email alert to \\'" + Encode.forJavaScript(notificationGroup.getName()) + "\\'?"); List<KeyValue> removeKeysAndValues = new ArrayList<>(); removeKeysAndValues.add(new KeyValue("Operation", "Remove")); removeKeysAndValues.add( new KeyValue("Name", Encode.forHtmlAttribute(notificationGroup.getName()))); String remove = StatsAggHtmlFramework.buildJavaScriptPostLink( "Remove_" + notificationGroup.getName(), "NotificationGroups", "remove", removeKeysAndValues, true, "Are you sure you want to remove this notification group?"); htmlBodyStringBuilder .append("<tr>\n") .append("<td class=\"statsagg_force_word_break\">") .append(notificationGroupDetails) .append("</td>\n") .append("<td class=\"statsagg_force_word_break\">") .append(StatsAggHtmlFramework.htmlEncode(emailAddressesOutput.toString())) .append("</td>\n") .append("<td>") .append(alter) .append(", ") .append(clone) .append(", ") .append(test); if (notificationGroupIdsAssociatedWithAlerts == null) htmlBodyStringBuilder.append(", ").append(remove); else if (!notificationGroupIdsAssociatedWithAlerts.contains(notificationGroup.getId())) htmlBodyStringBuilder.append(", ").append(remove); htmlBodyStringBuilder.append("</td>\n").append("</tr>\n"); } htmlBodyStringBuilder.append( "" + "</tbody>\n" + "<tfoot> \n" + " <tr>\n" + " <th></th>\n" + " <th></th>\n" + " <th></th>\n" + " </tr>\n" + "</tfoot>" + "</table>\n" + "</div>\n" + "</div>\n"); String htmlBody = (statsAggHtmlFramework.createHtmlBody(htmlBodyStringBuilder.toString())); html.append("" + "<!DOCTYPE html>\n" + "<html>\n") .append(htmlHeader) .append(htmlBody) .append("</html>"); return html.toString(); }
protected String getNotificationGroup_AlertAssociations( String notificationGroupName, boolean excludeNavbar) { if (notificationGroupName == null) { return "<b>No notification group specified</b>"; } NotificationGroupsDao notificationGroupsDao = new NotificationGroupsDao(); NotificationGroup notificationGroup = notificationGroupsDao.getNotificationGroupByName(notificationGroupName); if (notificationGroup == null) return "<b>Notification group not found</b>"; StringBuilder outputString = new StringBuilder(); outputString .append("<b>Notification Group Name</b> = ") .append(StatsAggHtmlFramework.htmlEncode(notificationGroup.getName())) .append("<br>"); Map<Integer, Set<Integer>> alertIdAssociationsByByNotificationGroupId = null; // synchronized(GlobalVariables.notificationGroupIdAssociationsByAlertId) { // alertIdAssociationsByByNotificationGroupId = // com.pearson.statsagg.alerts.NotificationGroups.getAlertIdAssociationsByNotificationGroupId(GlobalVariables.notificationGroupIdAssociationsByAlertId); // } if (alertIdAssociationsByByNotificationGroupId == null) { outputString.append("<b>Total Alert Associations</b> = ").append("0"); return outputString.toString(); } Set<Integer> alertIdAssociations = alertIdAssociationsByByNotificationGroupId.get(notificationGroup.getId()); if (alertIdAssociations == null) alertIdAssociations = new HashSet<>(); int associationCount = alertIdAssociations.size(); outputString .append("<b>Total Alert Associations</b> = ") .append(associationCount) .append("<br><br>"); if (associationCount <= 0) return outputString.toString(); List<String> alertNames = new ArrayList<>(); AlertsDao alertsDao = new AlertsDao(false); for (Integer alertId : alertIdAssociations) { Alert alert = alertsDao.getAlert(alertId); if ((alert == null) || (alert.getName() == null)) continue; alertNames.add(alert.getName()); } alertsDao.close(); Collections.sort(alertNames); outputString.append("<b>Alert Associations...</b>").append("<br>"); outputString.append("<ul>"); for (String alertName : alertNames) { String alertDetailsUrl = "<a href=\"AlertDetails?" + "ExcludeNavbar=" + excludeNavbar + "&Name=" + StatsAggHtmlFramework.urlEncode(alertName) + "\">" + StatsAggHtmlFramework.htmlEncode(alertName) + "</a>"; outputString.append("<li>").append(alertDetailsUrl).append("</li>"); } outputString.append("</ul>"); return outputString.toString(); }