001: /**
002: * Copyright (c) 2000-2008 Liferay, Inc. All rights reserved.
003: *
004: * Permission is hereby granted, free of charge, to any person obtaining a copy
005: * of this software and associated documentation files (the "Software"), to deal
006: * in the Software without restriction, including without limitation the rights
007: * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
008: * copies of the Software, and to permit persons to whom the Software is
009: * furnished to do so, subject to the following conditions:
010: *
011: * The above copyright notice and this permission notice shall be included in
012: * all copies or substantial portions of the Software.
013: *
014: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
015: * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
016: * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
017: * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
018: * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
019: * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
020: * SOFTWARE.
021: */package com.liferay.jbpm.handler;
022:
023: import com.liferay.client.portal.model.GroupSoap;
024: import com.liferay.client.portal.model.RoleSoap;
025: import com.liferay.client.portal.model.UserSoap;
026: import com.liferay.portal.kernel.util.GetterUtil;
027: import com.liferay.portal.kernel.util.Validator;
028:
029: import org.jbpm.graph.exe.ExecutionContext;
030: import org.jbpm.taskmgmt.def.AssignmentHandler;
031: import org.jbpm.taskmgmt.exe.Assignable;
032:
033: /**
034: * <a href="IdentityAssignmentHandler.java.html"><b><i>View Source</i></b></a>
035: *
036: * @author Charles May
037: *
038: */
039: public class IdentityAssignmentHandler extends DefaultHandler implements
040: AssignmentHandler {
041:
042: public void assign(Assignable assignable,
043: ExecutionContext executionContext) {
044:
045: try {
046: if (type.equals("user")) {
047: if (Validator.isNotNull(id)) {
048: assignable.setActorId(id);
049: } else {
050: UserSoap user = getUserService()
051: .getUserByEmailAddress(
052: GetterUtil.getLong(companyId), name);
053:
054: assignable.setActorId(String.valueOf(user
055: .getUserId()));
056: }
057: } else if (type.equals("community")) {
058: if (Validator.isNull(id)) {
059: GroupSoap group = getGroupService().getGroup(
060: GetterUtil.getLong(companyId), name);
061:
062: id = String.valueOf(group.getGroupId());
063: }
064:
065: UserSoap[] users = getUserService().getGroupUsers(
066: GetterUtil.getLong(id));
067:
068: String[] actorIds = new String[users.length];
069:
070: for (int i = 0; i < users.length; i++) {
071: actorIds[i] = String.valueOf(users[i].getUserId());
072: }
073:
074: assignable.setPooledActors(actorIds);
075: } else if (type.equals("role")) {
076: if (Validator.isNull(id)) {
077: RoleSoap role = getRoleService().getRole(
078: GetterUtil.getLong(companyId), name);
079:
080: id = String.valueOf(role.getRoleId());
081: }
082:
083: UserSoap[] users = getUserService().getRoleUsers(
084: GetterUtil.getLong(id));
085:
086: String[] actorIds = new String[users.length];
087:
088: for (int i = 0; i < users.length; i++) {
089: actorIds[i] = String.valueOf(users[i].getUserId());
090: }
091:
092: assignable.setPooledActors(actorIds);
093: }
094: } catch (Exception e) {
095: assignable.setPooledActors(null);
096: }
097: }
098:
099: protected String type;
100: protected String companyId;
101: protected String id;
102: protected String name;
103:
104: }
|