001: /*
002: * Copyright 2005-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.core.service.impl;
017:
018: import java.util.ArrayList;
019: import java.util.Arrays;
020: import java.util.Collection;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: import org.apache.commons.lang.StringUtils;
025: import org.kuali.core.bo.user.KualiGroup;
026: import org.kuali.core.bo.user.UniversalUser;
027: import org.kuali.core.exceptions.GroupNotFoundException;
028: import org.kuali.core.exceptions.InfrastructureException;
029: import org.kuali.core.service.KualiGroupService;
030: import org.kuali.core.util.Timer;
031: import org.kuali.core.workflow.service.KualiWorkflowInfo;
032: import org.kuali.core.workflow.service.WorkflowGroupService;
033: import org.springframework.transaction.annotation.Transactional;
034:
035: import edu.iu.uis.eden.clientapp.vo.NetworkIdVO;
036: import edu.iu.uis.eden.clientapp.vo.UserVO;
037: import edu.iu.uis.eden.clientapp.vo.WorkgroupNameIdVO;
038: import edu.iu.uis.eden.clientapp.vo.WorkgroupVO;
039: import edu.iu.uis.eden.exception.WorkflowException;
040:
041: /**
042: * This class is the service implementation for the KualiGroupService structure. This is the default implementation, that is
043: * delivered with Kuali which utilizes the workgroup concept in OneStart Workflow.
044: */
045: @Transactional
046: public class KualiGroupServiceImpl implements KualiGroupService {
047:
048: private WorkflowGroupService workflowGroupService;
049: private KualiWorkflowInfo kualiWorkflowInfo;
050:
051: private static final org.apache.log4j.Logger LOG = org.apache.log4j.Logger
052: .getLogger(KualiGroupServiceImpl.class);
053:
054: /**
055: * @see org.kuali.core.service.KualiGroupService#getByGroupName(java.lang.String)
056: */
057: public KualiGroup getByGroupName(String groupName)
058: throws GroupNotFoundException {
059: Timer t0 = new Timer("getByGroupName");
060: KualiGroup kualiGroup = null;
061:
062: if (StringUtils.isEmpty(groupName)) {
063: throw new GroupNotFoundException(
064: "unable to process empty groupName");
065: }
066:
067: if (StringUtils.equals(groupName,
068: KualiGroup.KUALI_UNIVERSAL_GROUP.getGroupName())) {
069: kualiGroup = KualiGroup.KUALI_UNIVERSAL_GROUP;
070: } else {
071:
072: WorkgroupVO workgroup = null;
073:
074: try {
075: workgroup = getKualiWorkflowInfo().getWorkgroup(
076: new WorkgroupNameIdVO(groupName));
077: } catch (WorkflowException e) {
078: t0.log();
079: throw new GroupNotFoundException(
080: "Error retrieving groupName " + groupName
081: + " from workflow", e);
082: }
083:
084: if (workgroup != null) {
085: kualiGroup = new KualiGroup();
086: kualiGroup.setGroupDescription(workgroup
087: .getDescription());
088: kualiGroup.setGroupName(workgroup.getWorkgroupName());
089: kualiGroup.setGroupUsers(getGroupUsers(workgroup));
090: }
091: }
092: t0.log();
093: return kualiGroup;
094:
095: }
096:
097: public boolean groupExists(String groupName) {
098: boolean exists = false;
099:
100: if (!StringUtils.isEmpty(groupName)) {
101: if (StringUtils.equals(groupName,
102: KualiGroup.KUALI_UNIVERSAL_GROUP.getGroupName())) {
103: exists = true;
104: } else {
105: try {
106: exists = getKualiWorkflowInfo().getWorkgroup(
107: new WorkgroupNameIdVO(groupName)) != null;
108: } catch (WorkflowException e) {
109: throw new InfrastructureException(
110: "error retrieving groupName " + groupName
111: + " from workflow", e);
112: }
113: }
114: }
115:
116: return exists;
117:
118: }
119:
120: /**
121: * @see org.kuali.core.service.KualiGroupService#getUsersGroups(org.kuali.bo.KualiUser)
122: */
123: public List getUsersGroups(UniversalUser universalUser) {
124: List usersGroups = null;
125:
126: String userId = universalUser.getPersonUserIdentifier();
127: if (StringUtils.isNotBlank(userId)) {
128: userId = "";
129: }
130: try {
131: Collection workflowUsersGroups = getWorkflowGroupService()
132: .getWorkflowUsersGroups(
133: new NetworkIdVO(userId.toUpperCase()));
134: if (workflowUsersGroups != null) {
135: usersGroups = new ArrayList(workflowUsersGroups.size());
136:
137: Iterator iter = workflowUsersGroups.iterator();
138: while (iter.hasNext()) {
139: WorkgroupVO workgroup = (WorkgroupVO) iter.next();
140: KualiGroup kualiGroup = new KualiGroup();
141: kualiGroup.setGroupDescription(workgroup
142: .getDescription());
143: kualiGroup.setGroupName(workgroup
144: .getWorkgroupName());
145:
146: List groupUsers = getGroupUsers(workgroup);
147:
148: kualiGroup.setGroupUsers(groupUsers);
149: usersGroups.add(kualiGroup);
150: }
151:
152: usersGroups.add(KualiGroup.KUALI_UNIVERSAL_GROUP);
153: }
154: } catch (WorkflowException e) {
155: throw new RuntimeException(
156: "Caught workflow exception in KualiGroupServiceImpl.getUsersGroups",
157: e);
158: }
159:
160: return usersGroups;
161: }
162:
163: /**
164: * Retrieves all the users in a OneStart Workflow workgroup.
165: *
166: * @param workgroup
167: * @return
168: */
169: private List getGroupUsers(WorkgroupVO workgroup) {
170: // TODO do we want empty list here instead of null groupUsers attribute?
171: List groupUsers = new ArrayList();
172:
173: List members = Arrays.asList(workgroup.getMembers());
174: if (members != null) {
175: Iterator iter = members.iterator();
176: while (iter.hasNext()) {
177: groupUsers.add(((UserVO) iter.next()).getNetworkId());
178: }
179: }
180: return groupUsers;
181:
182: }
183:
184: /**
185: * @param workflowGroupService The workflowGroupService to set.
186: */
187: public void setWorkflowGroupService(
188: WorkflowGroupService workflowGroupService) {
189: this .workflowGroupService = workflowGroupService;
190: }
191:
192: /**
193: * @return Returns the workflowGroupService.
194: */
195: public WorkflowGroupService getWorkflowGroupService() {
196: return workflowGroupService;
197: }
198:
199: public void setKualiWorkflowInfo(KualiWorkflowInfo kualiWorkflowInfo) {
200: this .kualiWorkflowInfo = kualiWorkflowInfo;
201: }
202:
203: public KualiWorkflowInfo getKualiWorkflowInfo() {
204: return kualiWorkflowInfo;
205: }
206: }
|