View Javadoc

1   /**
2    * Copyright 2005-2013 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.Collections;
20  import java.util.List;
21  
22  import org.kuali.rice.kew.api.identity.PrincipalId;
23  import org.kuali.rice.kew.api.rule.RoleName;
24  import org.kuali.rice.kew.engine.RouteContext;
25  
26  /**
27   * RoleAttribute that exposes a document's user who routed the document
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   */
31  public class RoutedByUserRoleAttribute extends UnqualifiedRoleAttribute {
32      private static final long serialVersionUID = -7099014184598851664L;
33  	private static final String ROUTED_BY_USER_ROLE_KEY = "ROUTED_BY_USER";
34      private static final String ROUTED_BY_USER_ROLE_LABEL = "Routed By User";
35  
36      private static final RoleName ROLE = new RoleName(RoutedByUserRoleAttribute.class.getName(), ROUTED_BY_USER_ROLE_KEY, ROUTED_BY_USER_ROLE_LABEL);
37      private static final List<RoleName> ROLES;
38      static {
39          ArrayList<RoleName> roles = new ArrayList<RoleName>(1);
40          roles.add(ROLE);
41          ROLES = Collections.unmodifiableList(roles);
42      }
43  
44      public RoutedByUserRoleAttribute() {
45          super(ROLES);
46      }
47  
48      public ResolvedQualifiedRole resolveRole(RouteContext routeContext, String roleName) {
49          // sounds like the role label should be specified as the first parameter here,
50          // but I'll follow AccountAttribute's lead and specify the role key
51          List members = new ArrayList(1);
52          //members.add(routeContext.getDocument().getRoutedByPrincipal().getPrincipalId());
53          members.add(new PrincipalId(routeContext.getDocument().getRoutedByUserWorkflowId()));
54          return new ResolvedQualifiedRole(ROUTED_BY_USER_ROLE_LABEL, members);
55      }
56  }