Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright 2005-2013 The Kuali Foundation Licensed under the Educational Community License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.opensource.org/licenses/ecl2.php Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
 
 package org.kuali.rice.kew.actionrequest.service.impl;
 
 import java.util.List;
 
This utility class encapsulates functions used to provide notification suppression

Author(s):
Kuali Rice Team (rice.collab@kuali.org)
 
 public class NotificationSuppression {
 
     public static final String SUPPRESS_NOTIFY_KEY_START = "SuppressNotify";
    
add metadata (a NodeState) to the route node so that if this action request is regenerated verbatim, the notification email will suppressed (since it is a duplicate!).

Parameters:
nodeInstance where additional NodeState will be added
actionRequestValue
 
     public void addNotificationSuppression(
     		RouteNodeInstance nodeInstanceActionRequestValue actionRequestValue) {
 
     	// iterative depth first traversal of the action request tree
     	// push
     	stack.add(actionRequestValue);
 
     	while (stack.size() > 0) {
     		// pop our next action request 
     		ActionRequestValue childActionRequest = stack.removeLast(); 
 
     		// process this action request only if it is a leaf
     		if (childActionRequest.getChildrenRequests() == null || 
     				childActionRequest.getChildrenRequests().size() == 0) {
     			List<StringrequestKeys = getSuppressNotifyNodeStateKeys(childActionRequest);
     			if (requestKeys != nullfor (String requestKey : requestKeys) { 
     				if (nodeInstance.getNodeState(requestKey) == null) { // only add once
     					NodeState ns = new NodeState();
     					ns.setKey(requestKey);
     					ns.setValue("notification suppression");
     					nodeInstance.addNodeState(ns);
     				}
     			}
     		}
 
     		// put child action requests on the stack
     		if (childActionRequest.getChildrenRequests() != null) {
     			// equivalent to 'push' all
     			stack.addAll(childActionRequest.getChildrenRequests());
     		}
     	}
     }

This method filters any ActionItems whose related ActionRequestValueS have been flagged for notification suppression.

Parameters:
actionItems the ActionItemS to filter
routeNodeInstance the RouteNodeInstance that the actionItems are associated with
 
 	protected void filterNotificationSuppressedActionItems(List<ActionItemactionItems
 			final RouteNodeInstance routeNodeInstance) {
 		
 		// remove all actionItems from the collection whose request has a suppress notification node state element
 		CollectionUtils.filter(actionItemsnew Predicate() {
 			public boolean evaluate(Object object) {
 				boolean result = true;
 				ActionItem actionItem = (ActionItem)object;
 				ActionRequestValue actionRequest = 
				List<StringsuppressNotificationKeys = getSuppressNotifyNodeStateKeys(actionRequest);
				if (suppressNotificationKeys != null && suppressNotificationKeys.size() > 0) {
					// if any of the keys are not present, we need to notify
					boolean containsAll = true;
					for (String key : suppressNotificationKeys) {
						if (routeNodeInstance.getNodeState(key) == null) {
							containsAll = false;
							break;
						}
					}
					// actionItem will be filtered if this Predicate returns false
					result = !containsAll// only filters if all keys are present
				}
				return result;
			}
		});
	}

This method takes care of notification for ActionItemS. It has logic for suppressing notifications when the RouteNodeInstance has NodeState specifically hinting for notification suppression for a given ActionItem.

A side effect is that any notification suppression NodeStateS will be removed from the RouteNodeInstance after notifications are sent.

Parameters:
actionItems a list of ActionItemS related to the given routeNodeInstance
routeNodeInstance the RouteNodeInstance related to the given actionItems
	public void notify(List<ActionItemactionItemsRouteNodeInstance routeNodeInstance) {
		if (actionItems != null && actionItems.size() > 0) {
			actionItems = new ArrayList<ActionItem>(actionItems); // defensive copy since we will filter
			filterNotificationSuppressedActionItems(actionItemsrouteNodeInstance);
			// notify for any actionItems that were not filtered
			if (actionItems.size() > 0) { 
			    KEWServiceLocator.getNotificationService().notify(ActionItem.to(actionItems)); 
			}
		}
	}

This method removes all NodeStates related to notification suppression, saving the RouteNodeInstance if there were any removed.

Parameters:
routeNodeInstance
	@SuppressWarnings("unchecked")
			final RouteNodeInstance routeNodeInstance) {
		// remove all suppress notification node states
		List<NodeStatenodeStates = routeNodeInstance.getState();
		if (nodeStates != null && nodeStates.size() > 0) {
			List<StringnodeStateKeysToRemove = new ArrayList<String>(nodeStates.size());
			for (NodeState nodeState : nodeStates) {
					nodeStateKeysToRemove.add(nodeState.getKey());
				}
			}
			if (nodeStateKeysToRemove.size() > 0) {
				for (String nodeStateKeyToRemove : nodeStateKeysToRemove) {
					routeNodeInstance.removeNodeState(nodeStateKeyToRemove);
				}
				KEWServiceLocator.getRouteNodeService().save(routeNodeInstance);
			}
		}
	}


    
Builds keys for action requests used for notification suppression.

NOTE: This method needs to stay in sync with #getSuppressNotifyNodeStateKeys(org.kuali.rice.kew.dto.ActionRequestDTO ) Any changes here must be made there as well!

Parameters:
a
Returns:
List
		List<Stringresults = Collections.emptyList(); 
		if (a != null) {
			results = new ArrayList<String>(3);
		}
		return results;
    }

    
Builds keys for action requests used for notification suppression.

NOTE: This method needs to stay in sync with getSuppressNotifyNodeStateKeys(org.kuali.rice.kew.actionrequest.ActionRequestValue) Any changes here must be made there as well!

Parameters:
a
Returns:
List
		List<Stringresults = Collections.emptyList(); 
		if (a != null) {
			results = new ArrayList<String>(3);
		}
		return results;
	}


This method adds a suppress notify key to the passed in list

Parameters:
results the list that the key will be added to
responsiblePartyType
responsiblePartyId
	private void addSuppressNotifyNodeStateKey(List<StringresultsString responsiblePartyType,
			String responsiblePartyId) {
		if (responsiblePartyId != null && responsiblePartyType != null) {
			sb.append("(");
			sb.append(responsiblePartyType);
			sb.append(",");
			sb.append(responsiblePartyId);
			sb.append(")");
			results.add(sb.toString());
		}
	}
New to GrepCode? Check out our FAQ X