View Javadoc
1   package org.kuali.kpme.edo.candidate;
2   
3   import java.lang.reflect.Type;
4   import java.util.ArrayList;
5   import java.util.List;
6   
7   import org.kuali.kpme.core.bo.HrKeyedBusinessObject;
8   import org.kuali.kpme.core.groupkey.HrGroupKeyBo;
9   import org.kuali.kpme.edo.api.candidate.EdoCandidate;
10  import org.kuali.kpme.edo.api.candidate.EdoCandidateContract;
11  import org.kuali.rice.core.api.mo.ModelObjectUtils;
12  import org.kuali.rice.kim.api.identity.Person;
13  
14  import com.google.common.collect.ImmutableList;
15  import com.google.common.collect.ImmutableMap;
16  import com.google.gson.Gson;
17  import com.google.gson.reflect.TypeToken;
18  /**
19   * Date: 06/07/14
20   */
21  	
22  public class EdoCandidateBo extends HrKeyedBusinessObject implements EdoCandidateContract {
23  	
24  	static class KeyFields {
25  		private static final String PRINCIPAL_NAME = "principalName";
26  	}
27  	
28  	private static final long serialVersionUID = 6843318899816055301L;
29  	
30  	public static final ImmutableList<String> BUSINESS_KEYS = new ImmutableList.Builder<String>()
31              .add(KeyFields.PRINCIPAL_NAME)
32              .build();
33  	
34  	//public static final String CACHE_NAME = HrConstants.CacheNamespace.NAMESPACE_PREFIX + "PrincipalHRAttributes";
35  
36  	public static final ModelObjectUtils.Transformer<EdoCandidateBo, EdoCandidate> toImmutable = new ModelObjectUtils.Transformer<EdoCandidateBo, EdoCandidate>() {
37  		public EdoCandidate transform(EdoCandidateBo input) {
38  			return EdoCandidateBo.to(input);
39  		};
40  	};
41  
42  	public static final ModelObjectUtils.Transformer<EdoCandidate, EdoCandidateBo> toBo = new ModelObjectUtils.Transformer<EdoCandidate, EdoCandidateBo>() {
43  		public EdoCandidateBo transform(EdoCandidate input) {
44  			return EdoCandidateBo.from(input);
45  		};
46  	};
47  	
48  	@Override
49  	public ImmutableMap<String, Object> getBusinessKeyValuesMap() {
50      	return  new ImmutableMap.Builder<String, Object>()
51  			.put(KeyFields.PRINCIPAL_NAME, this.getPrincipalName())
52  			.build();
53  	}
54  	
55  	@Override
56  	public String getUniqueKey() {
57  		
58  		return getPrincipalName();
59  	}
60  	     
61  	private String edoCandidateId;
62      private String lastName ;
63      private String firstName;
64      private String principalName;
65      private String primaryDeptId ;
66      private String tnpDeptId;
67      private String candidacySchool;
68     
69      private transient Person principal;
70      
71      @Override
72  	public String getId() {
73  		return this.getEdoCandidateId();
74  	}
75  	@Override
76  	public void setId(String id) {
77  		setEdoCandidateId(id);
78  	}
79  
80  	public Person getPrincipal() {
81  		return principal;
82  	}
83  
84  	public void setPrincipal(Person principal) {
85  		this.principal = principal;
86  	}
87  
88      public String getLastName() {
89  		return lastName;
90  	}
91  
92  	public void setLastName(String lastName) {
93  		this.lastName = lastName;
94  	}
95  
96  	public String getFirstName() {
97  		return firstName;
98  	}
99  
100 	public void setFirstName(String firstName) {
101 		this.firstName = firstName;
102 	}
103 
104 	public String getPrincipalName() {
105 		return principalName;
106 	}
107 
108 	public void setPrincipalName(String principalName) {
109 		this.principalName = principalName;
110 	}
111 
112 	public String getEdoCandidateId() {
113         return edoCandidateId;
114     }
115 
116     public void setEdoCandidateId(String edoCandidateId) {
117         this.edoCandidateId = edoCandidateId;
118     }
119 
120     public String getPrimaryDeptId() {
121         return primaryDeptId;
122     }
123 
124     public void setPrimaryDeptId(String primaryDeptId) {
125         this.primaryDeptId = primaryDeptId;
126     }
127 
128     public String getTnpDeptId() {
129         return tnpDeptId;
130     }
131 
132     public void setTnpDeptId(String tnpDeptId) {
133         this.tnpDeptId = tnpDeptId;
134     }
135 
136     public String getCandidacySchool() {
137         return candidacySchool;
138     }
139 
140     public void setCandidacySchool(String candidacySchool) {
141         this.candidacySchool = candidacySchool;
142     }
143 
144     public String getCandidateJSONString() {
145         ArrayList<String> tmp = new ArrayList<String>();
146         Type tmpType = new TypeToken<List<String>>() {}.getType();
147         Gson gson = new Gson();
148 
149         tmp.add(this.getEdoCandidateId().toString());
150         tmp.add(this.getFirstName() + " " + this.getLastName());
151         tmp.add(this.getLastName());
152         tmp.add(this.getFirstName());
153         tmp.add(this.getPrincipalName());
154         tmp.add(this.getPrimaryDeptId());
155         tmp.add(this.getCandidacySchool());
156         return gson.toJson(tmp, tmpType).toString();
157     }
158     
159     public static EdoCandidateBo from(EdoCandidate edoCandidate) {
160         if (edoCandidate == null) {
161             return null;
162         }
163         EdoCandidateBo edoCandidateBo = new EdoCandidateBo();
164         
165         edoCandidateBo.setEdoCandidateId(edoCandidate.getEdoCandidateId());
166         edoCandidateBo.setPrincipalName(edoCandidate.getPrincipalName());
167         edoCandidateBo.setLastName(edoCandidate.getLastName());
168         edoCandidateBo.setFirstName(edoCandidate.getFirstName());
169         edoCandidateBo.setPrimaryDeptId(edoCandidate.getPrimaryDeptId());
170         edoCandidateBo.setTnpDeptId(edoCandidate.getTnpDeptId());
171         edoCandidateBo.setCandidacySchool(edoCandidate.getCandidacySchool());
172         
173         edoCandidateBo.setGroupKeyCode(edoCandidate.getGroupKeyCode());
174         edoCandidateBo.setGroupKey(HrGroupKeyBo.from(edoCandidate.getGroupKey()));
175         
176         // finally copy over the common fields into edoCandidateBo from im
177         copyCommonFields(edoCandidateBo, edoCandidate);
178 
179         return edoCandidateBo;
180     }
181 
182     public static EdoCandidate to(EdoCandidateBo bo) {
183         if (bo == null) {
184             return null;
185         }
186 
187         return EdoCandidate.Builder.create(bo).build();
188     }
189 
190 }