001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.workgroup;
018:
019: import edu.iu.uis.eden.KEWServiceLocator;
020: import edu.iu.uis.eden.actionitem.ActionItem;
021: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
022: import edu.iu.uis.eden.exception.WorkflowException;
023: import edu.iu.uis.eden.messaging.KEWXMLService;
024: import edu.iu.uis.eden.messaging.ParameterTranslator;
025: import edu.iu.uis.eden.user.AuthenticationUserId;
026: import edu.iu.uis.eden.user.WorkflowUser;
027:
028: /**
029: * Executes the updating of {@link ActionItem}s for a {@link Workgroup} when
030: * the membership of a Workgroup changes.
031: *
032: * @see ActionItem
033: * @see Workgroup
034: *
035: * @author ewestfal
036: * @author rkirkend
037: */
038: public class WorkgroupMembershipChangeProcessor implements
039: KEWXMLService {
040:
041: private static final String ADDED_OPERATION = "ADDED";
042: private static final String REMOVED_OPERATION = "REMOVED";
043:
044: public void invoke(String contents) throws Exception {
045: ParameterTranslator translator = new ParameterTranslator(
046: contents);
047: String[] parameters = translator.getParameters();
048: if (parameters.length != 4) {
049: throw new IllegalArgumentException(
050: "The Workgroup Membership Change Processor requires four parameters.");
051: }
052: String operation = parameters[0];
053: WorkflowUser user = KEWServiceLocator.getUserService()
054: .getWorkflowUser(
055: new AuthenticationUserId(parameters[1]));
056: if (user == null) {
057: throw new EdenUserNotFoundException(
058: "Could not locate the user for the given authentication id '"
059: + parameters[1] + "'");
060: }
061: Long versionNumber = new Long(parameters[3]);
062: GroupNameId workgroupName = new GroupNameId(parameters[2]);
063: Workgroup workgroup = KEWServiceLocator.getWorkgroupService()
064: .getWorkgroup(workgroupName);
065: if (workgroup != null
066: && !workgroup.getLockVerNbr().equals(versionNumber)) {
067: // if the lock version numbers don't match, then refresh the workgroup from the cache
068: KEWServiceLocator.getWorkgroupService()
069: .removeNameFromCache(workgroupName);
070: workgroup = KEWServiceLocator.getWorkgroupService()
071: .getWorkgroup(workgroupName);
072: }
073: if (workgroup == null) {
074: throw new WorkflowException(
075: "Could not locate the workgroup with the given name '"
076: + workgroupName + "'");
077: }
078: if (ADDED_OPERATION.equals(operation)) {
079: KEWServiceLocator.getActionListService()
080: .updateActionListForUserAddedToWorkgroup(user,
081: workgroup);
082: } else if (REMOVED_OPERATION.equals(operation)) {
083: KEWServiceLocator.getActionListService()
084: .updateActionListForUserRemovedFromWorkgroup(user,
085: workgroup);
086: } else {
087: throw new WorkflowException(
088: "Did not understand requested workgroup membership change operation '"
089: + operation + "'");
090: }
091: }
092:
093: public static String getMemberAddedMessageContents(
094: WorkflowUser user, Workgroup workgroup) {
095: return getMessageContents(user, workgroup, ADDED_OPERATION);
096: }
097:
098: public static String getMemberRemovedMessageContents(
099: WorkflowUser user, Workgroup workgroup) {
100: return getMessageContents(user, workgroup, REMOVED_OPERATION);
101: }
102:
103: public static String getMessageContents(WorkflowUser user,
104: Workgroup workgroup, String operation) {
105: ParameterTranslator translator = new ParameterTranslator();
106: translator.addParameter(operation);
107: translator.addParameter(user.getAuthenticationUserId()
108: .getAuthenticationId());
109: translator.addParameter(workgroup.getGroupNameId().getNameId());
110: translator.addParameter(workgroup.getLockVerNbr().toString());
111: // delay for about 10 seconds to allow a reasonable amount of time for the workgroup cache to be updated
112: // (and hopefully prevent thrashing of the workgroup cache), regardless we will fall back on the version
113: // number of the workgroup and check it against the machine this processor is processed on to ensure that
114: // it's cache is up to date
115: //SpringServiceLocator.getRouteQueueService().requeueDocument(new Long(-1), EdenConstants.ROUTE_QUEUE_DEFAULT_PRIORITY, new Long(10*1000), WorkgroupMembershipChangeProcessor.class.getName(), translator.getUntranslatedString());
116: return translator.getUntranslatedString();
117: }
118:
119: }
|