001: /*
002: * Copyright 2006-2007 The Kuali Foundation.
003: *
004: * Licensed under the Educational Community License, Version 1.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/ecl1.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: */
016: package org.kuali.workflow.module.kra.attribute;
017:
018: import java.util.ArrayList;
019: import java.util.Collections;
020: import java.util.List;
021:
022: import javax.xml.xpath.XPath;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.workflow.KualiWorkflowUtils;
026:
027: import edu.iu.uis.eden.engine.RouteContext;
028: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
029: import edu.iu.uis.eden.routeheader.DocumentContent;
030: import edu.iu.uis.eden.routeheader.DocumentRouteHeaderValue;
031: import edu.iu.uis.eden.routetemplate.AbstractRoleAttribute;
032: import edu.iu.uis.eden.routetemplate.ResolvedQualifiedRole;
033: import edu.iu.uis.eden.routetemplate.Role;
034: import edu.iu.uis.eden.user.WorkflowUserId;
035:
036: public class ResearchProjectDirectorRoleAttribute extends
037: AbstractRoleAttribute {
038:
039: private static final String PROJECT_DIRECTOR_ROLE_KEY = "PROJECT_DIRECTOR";
040: private static final String PROJECT_DIRECTOR_ROLE_LABEL = "Project Director";
041: private static final Role ROLE = new Role(
042: ResearchProjectDirectorRoleAttribute.class,
043: PROJECT_DIRECTOR_ROLE_KEY, PROJECT_DIRECTOR_ROLE_LABEL);
044:
045: private static final List ROLES;
046: static {
047: ArrayList list = new ArrayList(0);
048: list.add(ROLE);
049: ROLES = Collections.unmodifiableList(list);
050: }
051:
052: private static final List QUALIFIED_ROLE_NAMES;
053: static {
054: ArrayList list = new ArrayList(0);
055: list.add(PROJECT_DIRECTOR_ROLE_KEY);
056: QUALIFIED_ROLE_NAMES = Collections.unmodifiableList(list);
057: }
058:
059: public List getRoleNames() {
060: return ROLES;
061: }
062:
063: public List getQualifiedRoleNames(String roleName,
064: DocumentContent documentContent)
065: throws EdenUserNotFoundException {
066: // deferring all "logic" to the resolve stage
067: return QUALIFIED_ROLE_NAMES;
068: }
069:
070: public ResolvedQualifiedRole resolveQualifiedRole(
071: RouteContext routeContext, String roleName,
072: String qualifiedRole) throws EdenUserNotFoundException {
073: if (!PROJECT_DIRECTOR_ROLE_KEY.equals(roleName)) {
074: throw new IllegalArgumentException(
075: "resolveQualifiedRole was called with a role name other than '"
076: + PROJECT_DIRECTOR_ROLE_KEY + "'");
077: }
078:
079: List members = new ArrayList();
080: try {
081: DocumentContent docContent = routeContext
082: .getDocumentContent();
083: DocumentRouteHeaderValue document = routeContext
084: .getDocument();
085: XPath xpath = KualiWorkflowUtils.getXPath(docContent
086: .getDocument());
087: String xpathExp = new StringBuffer(
088: KualiWorkflowUtils.XSTREAM_SAFE_PREFIX).append(
089: KualiWorkflowUtils.XSTREAM_MATCH_ANYWHERE_PREFIX)
090: .append("projectDirector").append(
091: KualiWorkflowUtils.XSTREAM_SAFE_SUFFIX)
092: .toString();
093: String projectDirector = xpath.evaluate(xpathExp,
094: docContent.getDocument());
095: if (!StringUtils.isBlank(projectDirector)) {
096: members.add(new WorkflowUserId(projectDirector));
097: }
098: } catch (Exception e) {
099: throw new RuntimeException(e);
100: }
101:
102: return new ResolvedQualifiedRole(PROJECT_DIRECTOR_ROLE_KEY,
103: members);
104: }
105: }
|