001 /**
002 * Copyright 2005-2013 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 */
016 package org.kuali.rice.kew.engine.simulation;
017
018 import java.io.Serializable;
019
020 import org.apache.commons.lang.StringUtils;
021 import org.kuali.rice.kew.api.action.RoutingReportActionToTake;
022 import org.kuali.rice.kew.service.KEWServiceLocator;
023 import org.kuali.rice.kim.api.identity.Person;
024 import org.kuali.rice.kim.api.identity.principal.Principal;
025 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
026
027 /**
028 * An object represnting an action to take in the simulation engine
029 *
030 * @author Kuali Rice Team (rice.collab@kuali.org)
031 */
032 public class SimulationActionToTake implements Serializable {
033 private static final long serialVersionUID = 5212455086079117671L;
034
035 private String actionToPerform;
036 private Person user;
037 private String nodeName;
038
039 public SimulationActionToTake() {
040 }
041
042 public String getActionToPerform() {
043 return actionToPerform;
044 }
045
046 public void setActionToPerform(String actionToPerform) {
047 this.actionToPerform = actionToPerform;
048 }
049
050 public String getNodeName() {
051 return nodeName;
052 }
053
054 public void setNodeName(String nodeName) {
055 this.nodeName = nodeName;
056 }
057
058 public Person getUser() {
059 return user;
060 }
061
062 public void setUser(Person user) {
063 this.user = user;
064 }
065
066 public static SimulationActionToTake from(RoutingReportActionToTake actionToTake) {
067 if (actionToTake == null) {
068 return null;
069 }
070 SimulationActionToTake simActionToTake = new SimulationActionToTake();
071 simActionToTake.setNodeName(actionToTake.getNodeName());
072 if (StringUtils.isBlank(actionToTake.getActionToPerform())) {
073 throw new IllegalArgumentException("ReportActionToTakeVO must contain an action taken code and does not");
074 }
075 simActionToTake.setActionToPerform(actionToTake.getActionToPerform());
076 if (actionToTake.getPrincipalId() == null) {
077 throw new IllegalArgumentException("ReportActionToTakeVO must contain a principalId and does not");
078 }
079 Principal kPrinc = KEWServiceLocator.getIdentityHelperService().getPrincipal(actionToTake.getPrincipalId());
080 Person user = KimApiServiceLocator.getPersonService().getPerson(kPrinc.getPrincipalId());
081 if (user == null) {
082 throw new IllegalStateException("Could not locate Person for the given id: " + actionToTake.getPrincipalId());
083 }
084 simActionToTake.setUser(user);
085 return simActionToTake;
086 }
087
088 }