View Javadoc

1   /**
2    * Copyright 2005-2011 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.engine;
17  
18  import org.jdom.Document;
19  import org.jdom.Element;
20  import org.kuali.rice.core.api.util.xml.XmlHelper;
21  import org.kuali.rice.kew.api.identity.Id;
22  import org.kuali.rice.kew.api.rule.RoleName;
23  import org.kuali.rice.kew.routeheader.DocumentContent;
24  import org.kuali.rice.kew.rule.AbstractRoleAttribute;
25  import org.kuali.rice.kew.rule.ResolvedQualifiedRole;
26  import org.kuali.rice.kew.workgroup.GroupNameId;
27  
28  import java.util.ArrayList;
29  import java.util.Arrays;
30  import java.util.Collection;
31  import java.util.Iterator;
32  import java.util.List;
33  
34  
35  public class ChartOrgDispatchAttribute extends AbstractRoleAttribute {
36  
37      private static final long serialVersionUID = -9114899910238607996L;
38  	public static final String DISPATCH_ROLE = "DISPATCH";
39      private String workgroupName;
40      
41      public ChartOrgDispatchAttribute() {}
42      
43      public ChartOrgDispatchAttribute(String workgroupName) {
44          this.workgroupName = workgroupName;
45      }
46  
47      public List getRoleNames() {
48          return Arrays.asList(new RoleName[] { new RoleName(getClass().getName(), DISPATCH_ROLE, DISPATCH_ROLE) });
49      }
50  
51      public List getQualifiedRoleNames(String roleName, DocumentContent documentContent) {
52          return parseWorkgroups(documentContent);
53      }
54  
55      public ResolvedQualifiedRole resolveQualifiedRole(RouteContext routeContext, String roleName, String qualifiedRole) {
56          List<Id> recipients = new ArrayList<Id>();
57          recipients.add(new GroupNameId(qualifiedRole));
58          return new ResolvedQualifiedRole(roleName, recipients);
59      }
60  
61      public String getDocContent() {
62          return "<"+DISPATCH_ROLE+">"+workgroupName+"</"+DISPATCH_ROLE+">";
63      }
64      
65      private List<String> parseWorkgroups(DocumentContent documentContent) {
66          Document document = XmlHelper.buildJDocument(documentContent.getDocument());
67          Collection<Element> dispatchElements = XmlHelper.findElements(document.getRootElement(), DISPATCH_ROLE);
68          List<String> workgroupNames = new ArrayList<String>();
69          for (Iterator<Element> iterator = dispatchElements.iterator(); iterator.hasNext();) {
70              Element element = (Element) iterator.next();
71              workgroupNames.add(element.getText());
72          }
73          return workgroupNames;
74      }
75      
76      
77      
78      
79  
80  }