001/**
002 * Copyright 2005-2014 The Kuali Foundation
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.kuali.rice.kew.rule;
017
018import java.util.ArrayList;
019import java.util.Collections;
020import java.util.List;
021
022import org.kuali.rice.kew.api.identity.PrincipalId;
023import org.kuali.rice.kew.api.rule.RoleName;
024import org.kuali.rice.kew.engine.RouteContext;
025
026/**
027 * RoleAttribute that exposes an INITIATOR abstract role which resolves to the
028 * initiator of the document.
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032public class InitiatorRoleAttribute extends UnqualifiedRoleAttribute {
033    private static final String INITIATOR_ROLE_KEY = "INITIATOR";
034    private static final String INITIATOR_ROLE_LABEL = "Initiator";
035
036    private static final RoleName ROLE = new RoleName(InitiatorRoleAttribute.class.getName(), INITIATOR_ROLE_KEY, INITIATOR_ROLE_LABEL);
037    private static final List<RoleName> ROLES;
038    static {
039        ArrayList<RoleName> roles = new ArrayList<RoleName>(1);
040        roles.add(ROLE);
041        ROLES = Collections.unmodifiableList(roles);
042    }
043
044    public InitiatorRoleAttribute() {
045        super(ROLES);
046    }
047
048    public ResolvedQualifiedRole resolveRole(RouteContext routeContext, String roleName) {
049        List members = new ArrayList(1);
050        members.add(new PrincipalId(routeContext.getDocument().getInitiatorWorkflowId()));
051        return new ResolvedQualifiedRole(INITIATOR_ROLE_LABEL, members);
052    }
053}