View Javadoc

1   /**
2    * Copyright 2005-2013 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.kuali.rice.kew.engine.simulation;
17  
18  import java.io.Serializable;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.rice.kew.api.action.RoutingReportActionToTake;
22  import org.kuali.rice.kew.service.KEWServiceLocator;
23  import org.kuali.rice.kim.api.identity.Person;
24  import org.kuali.rice.kim.api.identity.principal.Principal;
25  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
26  
27  /**
28   * An object represnting an action to take in the simulation engine
29   *
30   * @author Kuali Rice Team (rice.collab@kuali.org)
31   */
32  public class SimulationActionToTake implements Serializable {
33  	private static final long serialVersionUID = 5212455086079117671L;
34  
35  	private String actionToPerform;
36      private Person user;
37      private String nodeName;
38  
39      public SimulationActionToTake() {
40      }
41  
42  	public String getActionToPerform() {
43  		return actionToPerform;
44  	}
45  
46  	public void setActionToPerform(String actionToPerform) {
47  		this.actionToPerform = actionToPerform;
48  	}
49  
50  	public String getNodeName() {
51  		return nodeName;
52  	}
53  
54  	public void setNodeName(String nodeName) {
55  		this.nodeName = nodeName;
56  	}
57  
58  	public Person getUser() {
59  		return user;
60  	}
61  
62  	public void setUser(Person user) {
63  		this.user = user;
64  	}
65  
66      public static SimulationActionToTake from(RoutingReportActionToTake actionToTake) {
67          if (actionToTake == null) {
68              return null;
69          }
70          SimulationActionToTake simActionToTake = new SimulationActionToTake();
71          simActionToTake.setNodeName(actionToTake.getNodeName());
72          if (StringUtils.isBlank(actionToTake.getActionToPerform())) {
73              throw new IllegalArgumentException("ReportActionToTakeVO must contain an action taken code and does not");
74          }
75          simActionToTake.setActionToPerform(actionToTake.getActionToPerform());
76          if (actionToTake.getPrincipalId() == null) {
77              throw new IllegalArgumentException("ReportActionToTakeVO must contain a principalId and does not");
78          }
79          Principal kPrinc = KEWServiceLocator.getIdentityHelperService().getPrincipal(actionToTake.getPrincipalId());
80          Person user = KimApiServiceLocator.getPersonService().getPerson(kPrinc.getPrincipalId());
81          if (user == null) {
82              throw new IllegalStateException("Could not locate Person for the given id: " + actionToTake.getPrincipalId());
83          }
84          simActionToTake.setUser(user);
85          return simActionToTake;
86      }
87  
88  }