001/**
002 * Copyright 2005-2017 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.List;
020
021import org.apache.commons.lang.StringUtils;
022import org.kuali.rice.kew.api.identity.Id;
023import org.kuali.rice.kew.api.rule.RoleName;
024import org.kuali.rice.kew.util.Utilities;
025import org.kuali.rice.kew.workgroup.GroupNameId;
026
027/**
028 * A generic Role Attribute that can be used to route to a Workgroup Name.  Can take as configuration the
029 * label to use for the element name in the XML.  This allows for re-use of this component in different
030 * contexts.
031 * 
032 * @author Kuali Rice Team (rice.collab@kuali.org)
033 */
034public class WorkgroupRoleAttribute extends AbstractIdRoleAttribute {
035
036    private static final long serialVersionUID = 5562142284908152678L;
037    
038    private static final String WORKGROUP_ROLE_NAME = "workgroupName";
039    private static final String ATTRIBUTE_ELEMENT = "WorkgroupRoleAttribute";
040    private static final String WORKGROUP_ELEMENT = "workgroupName";
041        
042    public List<RoleName> getRoleNames() {
043        List<RoleName> roleNames = new ArrayList<RoleName>();
044        roleNames.add(new RoleName(getClass().getName(), WORKGROUP_ROLE_NAME, "Workgroup Name"));
045        return roleNames;
046    }
047    
048    protected String getAttributeElementName() {
049        return ATTRIBUTE_ELEMENT;
050    }
051    
052    protected Id resolveId(String id) {
053        if (StringUtils.isBlank(id)) {
054                return null;
055        }
056        String groupName = Utilities.parseGroupName(id);
057        String namespace = Utilities.parseGroupNamespaceCode(id);
058        return new GroupNameId(namespace, groupName);
059    }
060    
061    protected String getIdName() {
062        return WORKGROUP_ELEMENT;
063    }
064
065    public String getWorkgroupName() {
066        return getIdValue();
067    }
068
069    public void setWorkgroupName(String workgroupName) {
070        setIdValue(workgroupName);
071    }
072
073}