View Javadoc

1   /**
2    * Copyright 2005-2014 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.util;
17  
18  import org.kuali.rice.kew.actionrequest.KimGroupRecipient;
19  import org.kuali.rice.kew.actionrequest.Recipient;
20  import org.kuali.rice.kew.role.KimRoleRecipient;
21  import org.kuali.rice.kim.api.group.Group;
22  import org.kuali.rice.kim.api.identity.Person;
23  
24  /**
25   * Class was declared multiple times in different classes.  Removed
26   * from classes and placed here.  Also changed some of the logic
27   * so that we can stop using workflowUser
28   *
29   * @author Kuali Rice Team (rice.collab@kuali.org)
30   *
31   */
32  public class WebFriendlyRecipient implements Recipient{
33  
34  	private static final long serialVersionUID = 2259350039081951688L;
35  
36  	private String displayName;
37  	private String recipientId;
38  
39       public WebFriendlyRecipient(String recipientId, String displayName) {
40      	 this.recipientId = recipientId;
41      	 this.displayName = displayName;
42       }
43  
44       public WebFriendlyRecipient(Object recipient) {
45      	 if (recipient instanceof WebFriendlyRecipient) {
46               recipientId = ((WebFriendlyRecipient) recipient).getRecipientId();
47               displayName = ((WebFriendlyRecipient) recipient).getDisplayName();
48  
49           // NOTE: ActionItemDAO code is constructing WebFriendlyRecipient directly w/ Person objects
50           // this should probably be changed to return only Recipients from DAO tier to web tier
51           } else if(recipient instanceof Person){
52           	recipientId = ((Person)recipient).getPrincipalId();
53          	displayName = ((Person)recipient).getLastName() + ", " + ((Person)recipient).getFirstName();
54  
55           } else if(recipient instanceof KimGroupRecipient){
56               recipientId = ((KimGroupRecipient)recipient).getGroupId();
57               displayName = ((KimGroupRecipient)recipient).getGroup().getNamespaceCode() + ":" + ((KimGroupRecipient)recipient).getGroup().getName();
58  
59           }else {
60          	throw new IllegalArgumentException("Must pass in type Recipient or Person");
61          }
62       }
63  
64       public String getRecipientId() {
65           return recipientId;
66       }
67  
68  	/**
69  	 *
70  	 * @see org.kuali.rice.kew.actionrequest.Recipient#getDisplayName()
71  	 */
72  	public String getDisplayName() {
73  		return this.displayName;
74  	}
75  
76  }