View Javadoc
1   /**
2    * Copyright 2005-2015 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 an INITIATOR abstract role which resolves to the
28   * initiator of the document.
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class InitiatorRoleAttribute extends UnqualifiedRoleAttribute {
33      private static final String INITIATOR_ROLE_KEY = "INITIATOR";
34      private static final String INITIATOR_ROLE_LABEL = "Initiator";
35  
36      private static final RoleName ROLE = new RoleName(InitiatorRoleAttribute.class.getName(), INITIATOR_ROLE_KEY, INITIATOR_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 InitiatorRoleAttribute() {
45          super(ROLES);
46      }
47  
48      public ResolvedQualifiedRole resolveRole(RouteContext routeContext, String roleName) {
49          List members = new ArrayList(1);
50          members.add(new PrincipalId(routeContext.getDocument().getInitiatorWorkflowId()));
51          return new ResolvedQualifiedRole(INITIATOR_ROLE_LABEL, members);
52      }
53  }