View Javadoc
1   /**
2    * Copyright 2005-2016 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.rule;
17  
18  import java.util.ArrayList;
19  import java.util.List;
20  
21  import org.apache.commons.lang.StringUtils;
22  import org.kuali.rice.kew.api.identity.Id;
23  import org.kuali.rice.kew.api.rule.RoleName;
24  import org.kuali.rice.kew.util.Utilities;
25  import org.kuali.rice.kew.workgroup.GroupNameId;
26  
27  /**
28   * A generic Role Attribute that can be used to route to a Workgroup Name.  Can take as configuration the
29   * label to use for the element name in the XML.  This allows for re-use of this component in different
30   * contexts.
31   * 
32   * @author Kuali Rice Team (rice.collab@kuali.org)
33   */
34  public class WorkgroupRoleAttribute extends AbstractIdRoleAttribute {
35  
36      private static final long serialVersionUID = 5562142284908152678L;
37      
38      private static final String WORKGROUP_ROLE_NAME = "workgroupName";
39      private static final String ATTRIBUTE_ELEMENT = "WorkgroupRoleAttribute";
40      private static final String WORKGROUP_ELEMENT = "workgroupName";
41          
42      public List<RoleName> getRoleNames() {
43  	List<RoleName> roleNames = new ArrayList<RoleName>();
44  	roleNames.add(new RoleName(getClass().getName(), WORKGROUP_ROLE_NAME, "Workgroup Name"));
45  	return roleNames;
46      }
47      
48      protected String getAttributeElementName() {
49  	return ATTRIBUTE_ELEMENT;
50      }
51      
52      protected Id resolveId(String id) {
53      	if (StringUtils.isBlank(id)) {
54      		return null;
55      	}
56      	String groupName = Utilities.parseGroupName(id);
57      	String namespace = Utilities.parseGroupNamespaceCode(id);
58      	return new GroupNameId(namespace, groupName);
59      }
60      
61      protected String getIdName() {
62  	return WORKGROUP_ELEMENT;
63      }
64  
65      public String getWorkgroupName() {
66  	return getIdValue();
67      }
68  
69      public void setWorkgroupName(String workgroupName) {
70          setIdValue(workgroupName);
71      }
72  
73  }