View Javadoc
1   /**
2    * Copyright 2004-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.kpme.core.departmentaffiliation;
17  
18  import org.kuali.kpme.core.bo.HrBusinessObject;
19  import org.kuali.kpme.core.api.departmentaffiliation.DepartmentAffiliation;
20  import org.kuali.kpme.core.api.departmentaffiliation.DepartmentAffiliationContract;
21  import org.kuali.rice.core.api.mo.ModelObjectUtils;
22  
23  import com.google.common.collect.ImmutableList;
24  import com.google.common.collect.ImmutableMap;
25  public class DepartmentAffiliationBo extends HrBusinessObject implements DepartmentAffiliationContract {
26  
27  	private static final String DEPT_AFFL_TYPE = "deptAfflType";
28  
29  	public static final ImmutableList<String> BUSINESS_KEYS = new ImmutableList.Builder<String>()
30  			.add(DEPT_AFFL_TYPE)
31  			.build();
32  
33  	private static final long serialVersionUID = 1L;
34  
35  	private String hrDeptAfflId;
36  	private String deptAfflType;
37  	private boolean primaryIndicator;
38  
39  	@Override
40  	public ImmutableMap<String, Object> getBusinessKeyValuesMap() {
41  		return new ImmutableMap.Builder<String, Object>()
42  				.put(DEPT_AFFL_TYPE, this.getDeptAfflType())
43  				.build();
44  	}
45  
46  
47  	/*
48  	 * convert bo to immutable
49  	 *
50  	 * Can be used with ModelObjectUtils:
51  	 *
52  	 * org.kuali.rice.core.api.mo.ModelObjectUtils.transform(listOfDepartmentAffiliationBo, DepartmentAffiliationBo.toImmutable);
53  	 */
54  	public static final ModelObjectUtils.Transformer<DepartmentAffiliationBo, DepartmentAffiliation> toImmutable =
55  			new ModelObjectUtils.Transformer<DepartmentAffiliationBo, DepartmentAffiliation>() {
56  		public DepartmentAffiliation transform(DepartmentAffiliationBo input) {
57  			return DepartmentAffiliationBo.to(input);
58  		};
59  	};
60  
61  	/*
62  	 * convert immutable to bo
63  	 * 
64  	 * Can be used with ModelObjectUtils:
65  	 * 
66  	 * org.kuali.rice.core.api.mo.ModelObjectUtils.transform(listOfDepartmentAffiliation, DepartmentAffiliationBo.toBo);
67  	 */
68  	public static final ModelObjectUtils.Transformer<DepartmentAffiliation, DepartmentAffiliationBo> toBo =
69  			new ModelObjectUtils.Transformer<DepartmentAffiliation, DepartmentAffiliationBo>() {
70  		public DepartmentAffiliationBo transform(DepartmentAffiliation input) {
71  			return DepartmentAffiliationBo.from(input);
72  		};
73  	};
74  
75  
76  	@Override
77  	public String getId() {
78  		return this.getHrDeptAfflId();
79  	}
80  
81  	@Override
82  	public void setId(String id) {
83  		setHrDeptAfflId(id);
84  	}
85  
86  	@Override
87  	protected String getUniqueKey() {
88  		return getDeptAfflType();
89  	}
90  
91  	/**
92  	 * @return the hrDeptAfflId
93  	 */
94  	public String getHrDeptAfflId() {
95  		return hrDeptAfflId;
96  	}
97  
98  	/**
99  	 * @param hrDeptAfflId the hrDeptAfflId to set
100 	 */
101 	public void setHrDeptAfflId(String hrDeptAfflId) {
102 		this.hrDeptAfflId = hrDeptAfflId;
103 	}
104 
105 	/**
106 	 * @return the deptAfflType
107 	 */
108 	public String getDeptAfflType() {
109 		return deptAfflType;
110 	}
111 
112 	/**
113 	 * @param deptAfflType the deptAfflType to set
114 	 */
115 	public void setDeptAfflType(String deptAfflType) {
116 		this.deptAfflType = deptAfflType;
117 	}
118 
119 	/**
120 	 * @return the primaryIndicator
121 	 */
122 	public boolean isPrimaryIndicator() {
123 		return primaryIndicator;
124 	}
125 
126 	/**
127 	 * @param primaryIndicator the primaryIndicator to set
128 	 */
129 	public void setPrimaryIndicator(boolean primaryIndicator) {
130 		this.primaryIndicator = primaryIndicator;
131 	}
132 
133 	public static DepartmentAffiliationBo from(DepartmentAffiliation im) {
134 		if (im == null) {
135 			return null;
136 		}
137 		DepartmentAffiliationBo da = new DepartmentAffiliationBo();
138 		da.setHrDeptAfflId(im.getHrDeptAfflId());
139 		da.setDeptAfflType(im.getDeptAfflType());
140 		da.setPrimaryIndicator(im.isPrimaryIndicator());
141 
142 		// finally copy over the common fields into da from im
143 		copyCommonFields(da, im);
144 
145 		return da;
146 	} 
147 
148 	public static DepartmentAffiliation to(DepartmentAffiliationBo bo) {
149 		if (bo == null) {
150 			return null;
151 		}
152 		return DepartmentAffiliation.Builder.create(bo).build();
153 	}
154 
155 }