From: <ap...@vh...> - 2005-11-05 23:45:49
|
Author: apevec Date: 2005-11-06 00:44:53 +0100 (Sun, 06 Nov 2005) New Revision: 972 Modified: trunk/ccm-cms/src/com/arsdigita/cms/workflow/CMSTask.java Log: Add optional suffix to the operation name, to define task alert recipients. e.g. com.arsdigita.cms.default_task_alerts=Approval:enable_ALL:disable_LASTAUTHOR,Deploy:finish_LASTAUTHOR Sufix _LASTAUTHOR to send the alert only to auditing.lastModifiedUser default is _ALL - send alert to all task assignees Modified: trunk/ccm-cms/src/com/arsdigita/cms/workflow/CMSTask.java =================================================================== --- trunk/ccm-cms/src/com/arsdigita/cms/workflow/CMSTask.java 2005-11-05 23:04:11 UTC (rev 971) +++ trunk/ccm-cms/src/com/arsdigita/cms/workflow/CMSTask.java 2005-11-05 23:44:53 UTC (rev 972) @@ -85,8 +85,15 @@ // a Map containing a list of the list of operations that // alerts should be sent out for private static final Map s_alerts = new HashMap(5); + private static final String ALERT_OPERATIONS = "operations"; + private static final String ALERT_RECIPIENTS = "recipients"; + private static final String ALERT_RECIPIENT_ALL = "_ALL"; + private static final String ALERT_RECIPIENT_LASTAUTHOR = "_LASTAUTHOR"; private static final Logger s_log = Logger.getLogger(CMSTask.class); + + private boolean m_authorOnly = false; + public CMSTask() { this(BASE_DATA_OBJECT_TYPE); } @@ -332,6 +339,7 @@ // UnfinishedTaskNotifier TimerTask, and that task will never // be scheduled unless we're supposed to send these messages Message msg = generateMessage(UNFINISHED_OP, sender); + m_authorOnly = false; sendMessageToAssignees(msg); } } @@ -352,20 +360,53 @@ typeMap = new HashMap(5); s_alerts.put(section.getID(), typeMap); } - Set operationSet = (Set) typeMap.get(typeLabel); + Map operations = (Map) typeMap.get(typeLabel); + if (operations == null) { + operations = new HashMap(2); + typeMap.put(typeLabel,operations); + } + Set operationSet = (Set) operations.get(ALERT_OPERATIONS); if (operationSet == null) { operationSet = new HashSet(5); - typeMap.put(typeLabel, operationSet); + operations.put(ALERT_OPERATIONS, operationSet); } + Set authorOnlySet = (Set) operations.get(ALERT_RECIPIENTS); + if (authorOnlySet == null) { + authorOnlySet = new HashSet(5); + operations.put(ALERT_RECIPIENTS, authorOnlySet); + } + // sufix _LASTAUTHOR to send the alert only to auditing.lastModifiedUser + // default if _ALL - send alert to all task assignees + String recipients = ALERT_RECIPIENT_ALL; + if (operation.endsWith(ALERT_RECIPIENT_LASTAUTHOR)) { + operation = operation.substring(0,operation.length() - ALERT_RECIPIENT_LASTAUTHOR.length()); + authorOnlySet.add(operation); + recipients = ALERT_RECIPIENT_LASTAUTHOR; + } else if (operation.endsWith(ALERT_RECIPIENT_ALL)) { + operation = operation.substring(0,operation.length() - ALERT_RECIPIENT_ALL.length()); + } operationSet.add(operation); s_log.info("Added alert for \"" + operation + "\" of " + typeLabel + - " task in section \"" + section.getName() + "\""); + " task in section \"" + section.getName() + "\" recipients flag: "+recipients); } protected static boolean shouldSendAlert(ContentSection section, + String typeLabel, + String operation) { + return checkAlertsConfig(section, typeLabel, operation, ALERT_OPERATIONS); + } + + protected static boolean shouldSendToAuthorOnly(ContentSection section, + String typeLabel, + String operation) { + return checkAlertsConfig(section, typeLabel, operation, ALERT_RECIPIENTS); + } + + private static boolean checkAlertsConfig(ContentSection section, String typeLabel, - String operation) { + String operation, + String field) { if (section == null || typeLabel == null || operation == null) { @@ -381,20 +422,24 @@ Map typeMap = (Map) s_alerts.get(section.getID()); Set operationSet = null; if (typeMap != null) { - operationSet = (Set) typeMap.get(typeLabel); + Map operations = (Map) typeMap.get(typeLabel); + if (operations != null) { + operationSet = (Set) operations.get(field); + } } if (operationSet != null) { send = operationSet.contains(operation); } - s_log.debug("Send email for operation " + operation + " of task " + typeLabel + "?: " + send); + s_log.debug("operation " + operation + " field " + field + " of task " + typeLabel + "?: " + send); return send; } protected boolean sendAlerts(String operation) { + ContentSection section = getContentSection(); + String label = getLabel(); + m_authorOnly = shouldSendToAuthorOnly(section, label, operation); return (super.sendAlerts(operation) && - shouldSendAlert(getContentSection(), - getLabel(), - operation)); + shouldSendAlert(section, label, operation)); } /** @@ -412,6 +457,20 @@ * @see #filterUsersAndSendMessage */ protected void sendMessageToAssignees(Message msg) { + if (m_authorOnly) { + ContentItem item = getItem(); + User author = item.getLastModifiedUser(); + if (author == null) { + // fallback: creator is always available in audit trail + author = item.getCreationUser(); + } + if (s_log.isDebugEnabled()) { + s_log.debug("spamming ONLY author " + author); + } + Notification notification = new Notification(author, msg); + notification.save(); + return; + } /* NOTE: * it would be cleaner to simply change getAssignedUsers() * to do what we want; however that is used by cms.ui.workflow.UserTaskComponent |