View Javadoc

1   /**
2    * Copyright 2010 The Kuali Foundation Licensed under the
3    * Educational Community License, Version 2.0 (the "License"); you may
4    * not use this file except in compliance with the License. You may
5    * obtain a copy of the License at
6    *
7    * http://www.osedu.org/licenses/ECL-2.0
8    *
9    * Unless required by applicable law or agreed to in writing,
10   * software distributed under the License is distributed on an "AS IS"
11   * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
12   * or implied. See the License for the specific language governing
13   * permissions and limitations under the License.
14   */
15  
16  package org.kuali.student.lum.lu.service.impl;
17  
18  import java.util.ArrayList;
19  import java.util.HashMap;
20  import java.util.List;
21  import java.util.Map;
22  import java.util.Map.Entry;
23  
24  import org.kuali.student.common.dto.AmountInfo;
25  import org.kuali.student.common.dto.CurrencyAmountInfo;
26  import org.kuali.student.common.dto.TimeAmountInfo;
27  import org.kuali.student.common.entity.Amount;
28  import org.kuali.student.common.entity.CurrencyAmount;
29  import org.kuali.student.common.entity.TimeAmount;
30  import org.kuali.student.common.exceptions.DoesNotExistException;
31  import org.kuali.student.common.exceptions.InvalidParameterException;
32  import org.kuali.student.common.exceptions.VersionMismatchException;
33  import org.kuali.student.common.search.dto.SearchParam;
34  import org.kuali.student.common.service.impl.BaseAssembler;
35  import org.kuali.student.lum.lrc.dto.ResultComponentTypeInfo;
36  import org.kuali.student.lum.lu.dao.LuDao;
37  import org.kuali.student.lum.lu.dto.AccreditationInfo;
38  import org.kuali.student.lum.lu.dto.AdminOrgInfo;
39  import org.kuali.student.lum.lu.dto.AffiliatedOrgInfo;
40  import org.kuali.student.lum.lu.dto.CluAccountingInfo;
41  import org.kuali.student.lum.lu.dto.CluCluRelationInfo;
42  import org.kuali.student.lum.lu.dto.CluFeeInfo;
43  import org.kuali.student.lum.lu.dto.CluFeeRecordInfo;
44  import org.kuali.student.lum.lu.dto.CluIdentifierInfo;
45  import org.kuali.student.lum.lu.dto.CluInfo;
46  import org.kuali.student.lum.lu.dto.CluInstructorInfo;
47  import org.kuali.student.lum.lu.dto.CluLoRelationInfo;
48  import org.kuali.student.lum.lu.dto.CluLoRelationTypeInfo;
49  import org.kuali.student.lum.lu.dto.CluPublicationInfo;
50  import org.kuali.student.lum.lu.dto.CluResultInfo;
51  import org.kuali.student.lum.lu.dto.CluResultTypeInfo;
52  import org.kuali.student.lum.lu.dto.CluSetInfo;
53  import org.kuali.student.lum.lu.dto.CluSetTypeInfo;
54  import org.kuali.student.lum.lu.dto.DeliveryMethodTypeInfo;
55  import org.kuali.student.lum.lu.dto.FieldInfo;
56  import org.kuali.student.lum.lu.dto.InstructionalFormatTypeInfo;
57  import org.kuali.student.lum.lu.dto.LuCodeInfo;
58  import org.kuali.student.lum.lu.dto.LuCodeTypeInfo;
59  import org.kuali.student.lum.lu.dto.LuLuRelationTypeInfo;
60  import org.kuali.student.lum.lu.dto.LuPublicationTypeInfo;
61  import org.kuali.student.lum.lu.dto.LuTypeInfo;
62  import org.kuali.student.lum.lu.dto.LuiInfo;
63  import org.kuali.student.lum.lu.dto.LuiLuiRelationInfo;
64  import org.kuali.student.lum.lu.dto.MembershipQueryInfo;
65  import org.kuali.student.lum.lu.dto.ResultOptionInfo;
66  import org.kuali.student.lum.lu.dto.ResultUsageTypeInfo;
67  import org.kuali.student.lum.lu.entity.AffiliatedOrg;
68  import org.kuali.student.lum.lu.entity.Clu;
69  import org.kuali.student.lum.lu.entity.CluAccounting;
70  import org.kuali.student.lum.lu.entity.CluAccreditation;
71  import org.kuali.student.lum.lu.entity.CluAdminOrg;
72  import org.kuali.student.lum.lu.entity.CluAtpTypeKey;
73  import org.kuali.student.lum.lu.entity.CluCampusLocation;
74  import org.kuali.student.lum.lu.entity.CluCluRelation;
75  import org.kuali.student.lum.lu.entity.CluFee;
76  import org.kuali.student.lum.lu.entity.CluFeeAmount;
77  import org.kuali.student.lum.lu.entity.CluFeeAttribute;
78  import org.kuali.student.lum.lu.entity.CluFeeRecord;
79  import org.kuali.student.lum.lu.entity.CluFeeRecordAttribute;
80  import org.kuali.student.lum.lu.entity.CluIdentifier;
81  import org.kuali.student.lum.lu.entity.CluIdentifierAttribute;
82  import org.kuali.student.lum.lu.entity.CluInstructor;
83  import org.kuali.student.lum.lu.entity.CluLoRelation;
84  import org.kuali.student.lum.lu.entity.CluLoRelationType;
85  import org.kuali.student.lum.lu.entity.CluPublication;
86  import org.kuali.student.lum.lu.entity.CluPublicationVariant;
87  import org.kuali.student.lum.lu.entity.CluResult;
88  import org.kuali.student.lum.lu.entity.CluResultType;
89  import org.kuali.student.lum.lu.entity.CluSet;
90  import org.kuali.student.lum.lu.entity.CluSetAttribute;
91  import org.kuali.student.lum.lu.entity.CluSetJoinVersionIndClu;
92  import org.kuali.student.lum.lu.entity.CluSetType;
93  import org.kuali.student.lum.lu.entity.DeliveryMethodType;
94  import org.kuali.student.lum.lu.entity.InstructionalFormatType;
95  import org.kuali.student.lum.lu.entity.LuCode;
96  import org.kuali.student.lum.lu.entity.LuCodeType;
97  import org.kuali.student.lum.lu.entity.LuLuRelationType;
98  import org.kuali.student.lum.lu.entity.LuPublicationType;
99  import org.kuali.student.lum.lu.entity.LuRichText;
100 import org.kuali.student.lum.lu.entity.LuType;
101 import org.kuali.student.lum.lu.entity.Lui;
102 import org.kuali.student.lum.lu.entity.LuiAttribute;
103 import org.kuali.student.lum.lu.entity.LuiLuiRelation;
104 import org.kuali.student.lum.lu.entity.MembershipQuery;
105 import org.kuali.student.lum.lu.entity.ResultOption;
106 import org.kuali.student.lum.lu.entity.ResultUsageType;
107 import org.kuali.student.lum.lu.entity.SearchParameter;
108 import org.kuali.student.lum.lu.entity.SearchParameterValue;
109 import org.springframework.beans.BeanUtils;
110 
111 public class LuServiceAssembler extends BaseAssembler {
112 
113 	public static List<CluLoRelationTypeInfo> toCluLoRelationTypeInfos(
114 			List<CluLoRelationType> entities) {
115 		return toGenericTypeInfoList(CluLoRelationTypeInfo.class, entities);
116 	}
117 
118 	public static CluLoRelationTypeInfo toCluLoRelationTypeInfo(
119 			CluLoRelationType entity) {
120 		return toGenericTypeInfo(CluLoRelationTypeInfo.class, entity);
121 	}
122 
123 	public static List<CluCluRelationInfo> toCluCluRelationInfos(
124 			List<CluCluRelation> entities) {
125 		List<CluCluRelationInfo> dtos = new ArrayList<CluCluRelationInfo>(
126 				entities.size());
127 		if (entities != null) {
128 			for (CluCluRelation entity : entities) {
129 				dtos.add(toCluCluRelationInfo(entity));
130 			}
131 		}
132 		return dtos;
133 
134 	}
135 
136 	public static CluCluRelationInfo toCluCluRelationInfo(CluCluRelation entity) {
137 		if (entity == null) {
138 			return null;
139 		}
140 		CluCluRelationInfo dto = new CluCluRelationInfo();
141 		BeanUtils.copyProperties(entity, dto,
142 				new String[] { "cluId", "relatedCluId", "cluRelationRequired",
143 						"attributes", "metaInfo" });
144 
145 		dto.setIsCluRelationRequired(entity.isCluRelationRequired());
146 		dto.setCluId(entity.getClu().getId());
147 		dto.setRelatedCluId(entity.getRelatedClu().getId());
148 		dto.setType(entity.getLuLuRelationType().getId());
149 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
150 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
151 
152 		return dto;
153 
154 	}
155 
156 	public static List<CluLoRelationInfo> toCluLoRelationInfos(
157 			List<CluLoRelation> entities) {
158 		
159 		List<CluLoRelationInfo> dtos = new ArrayList<CluLoRelationInfo>(
160 				entities.size());
161 		if (entities != null) {
162 			for (CluLoRelation entity : entities) {
163 				dtos.add(toCluLoRelationInfo(entity));
164 			}
165 		}
166 		return dtos;
167 	}
168 
169 	public static CluLoRelationInfo toCluLoRelationInfo(CluLoRelation entity) {
170 		if (entity == null) {
171 			return null;
172 		}
173 		CluLoRelationInfo dto = new CluLoRelationInfo();
174 		BeanUtils.copyProperties(entity, dto, new String[] { "cluId",
175 				"attributes", "metaInfo", "type" });
176 
177 		dto.setCluId(entity.getClu().getId());
178 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
179 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
180 		dto.setType(entity.getType().getId());
181 		
182 		return dto;
183 	}
184 
185 	public static List<CluInfo> toCluInfos(List<Clu> entities) {
186 
187 		// return an empty list (Effective Java 2ndEd, item #43)
188 		if (entities == null) {
189 			return  new ArrayList<CluInfo>(0);
190 		}
191 
192 		List<CluInfo> dtos = new ArrayList<CluInfo>(entities.size());
193 		for (Clu entity : entities) {
194 			dtos.add(toCluInfo(entity));
195 		}
196 		return dtos;
197 
198 	}
199 
200 	public static CluInfo toCluInfo(Clu entity) {
201 		if (entity == null) {
202 			return null;
203 		}
204 		CluInfo dto = new CluInfo();
205 
206 		// copy all simple fields - exclude complex data types
207 		BeanUtils.copyProperties(entity, dto, new String[] {
208 				"officialIdentifier", "alternateIdentifiers", "descr",
209 				"participatingOrgs", "primaryInstructor", "instructors",
210 				"stdDuration", "luCodes", "credit", "offeredAtpTypes", "fee",
211 				"accounting", "intensity",
212 				"campusLocationList", "accreditationList",
213 				"adminOrgs", "attributes", "metaInfo", "versionInfo" });
214 		dto.setOfficialIdentifier(toCluIdentifierInfo(entity
215 				.getOfficialIdentifier()));
216 		dto.setAlternateIdentifiers(toCluIdentifierInfos(entity
217 				.getAlternateIdentifiers()));
218 		dto.setDescr(toRichTextInfo(entity.getDescr()));
219 
220 		// accreditingOrg Deprecated in v 1.0-rc2 Replaced by Primary and
221 		// Alternate admin orgs
222 		dto.setAccreditations(toAccreditationInfos(entity.getAccreditations()));
223 
224 		dto.setAdminOrgs(toCluAdminOrgInfos(entity
225 				.getAdminOrgs()));
226 
227 		dto.setPrimaryInstructor(toCluInstructorInfo(entity
228 				.getPrimaryInstructor()));
229 		dto.setInstructors(toCluInstructorInfos(entity.getInstructors()));
230 		dto.setStdDuration(toTimeAmountInfo(entity.getStdDuration()));
231 		dto.setLuCodes(toLuCodeInfos(entity.getLuCodes()));
232 
233 		if (entity.getOfferedAtpTypes() != null) {
234 			List<String> offeredAtpTypes = new ArrayList<String>(entity
235 					.getOfferedAtpTypes().size());
236 			for (CluAtpTypeKey key : entity.getOfferedAtpTypes()) {
237 				offeredAtpTypes.add(key.getAtpTypeKey());
238 			}
239 			dto.setOfferedAtpTypes(offeredAtpTypes);
240 		}
241 
242 		dto.setFeeInfo(toCluFeeInfo(entity.getFee()));
243 		dto.setAccountingInfo(toCluAccountingInfo(entity.getAccounting()));
244 
245 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
246 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
247 
248 		dto.setType(entity.getLuType().getId());
249 
250 		if (entity.getCampusLocations() != null) {
251 			List<String> campusLocations = new ArrayList<String>(entity
252 					.getCampusLocations().size());
253 			for (CluCampusLocation cluCamp : entity.getCampusLocations()) {
254 				campusLocations.add(cluCamp.getCampusLocation());
255 			}
256 			dto.setCampusLocations(campusLocations);
257 		}
258 
259 		dto.setIntensity(toAmountInfo(entity.getIntensity()));
260 
261 		dto.setVersionInfo(toVersionInfo(entity.getVersion()));
262 		
263 		return dto;
264 
265 	}
266 
267 	public static List<CluSetInfo> toCluSetInfos(List<CluSet> entities) {
268 		List<CluSetInfo> dtos = new ArrayList<CluSetInfo>(entities.size());
269 		if (entities != null) {
270 			for (CluSet entity : entities) {
271 				dtos.add(toCluSetInfo(entity));
272 			}
273 		}
274 		return dtos;
275 	}
276 
277 	public static CluSet toCluSetEntity(CluSetInfo cluSetInfo, LuDao luDao) throws InvalidParameterException, DoesNotExistException {
278 		CluSet cluSet = new CluSet();
279 
280 		BeanUtils.copyProperties(cluSetInfo, cluSet, new String[] { "id",
281 				"descr", "attributes", "metaInfo", "membershipQuery" });
282 		cluSet.setAttributes(toGenericAttributes(
283 				CluSetAttribute.class, cluSetInfo.getAttributes(), cluSet, luDao));
284 		cluSet.setType(cluSetInfo.getType());
285 		cluSet.setDescr(toRichText(LuRichText.class, cluSetInfo.getDescr()));
286 
287 		for (String cluId : cluSetInfo.getCluIds()) {
288 			CluSetJoinVersionIndClu join = new CluSetJoinVersionIndClu();
289 			join.setCluSet(cluSet);
290 			join.setCluVersionIndId(cluId);
291 			cluSet.getCluVerIndIds().add(join);
292 		}
293 		for (String cluSetId : cluSetInfo.getCluSetIds()) {
294 			CluSet c = luDao.fetch(CluSet.class, cluSetId);
295 			if(cluSet.getCluSets()==null){
296 				cluSet.setCluSets(new ArrayList<CluSet>());
297 			}
298 			cluSet.getCluSets().add(c);
299 		}
300 		cluSet.setMembershipQuery(toMembershipQueryEntity(cluSetInfo.getMembershipQuery()));
301 
302 		return cluSet;
303 	}
304 
305 	public static CluSetInfo toCluSetInfo(CluSet entity) {
306 		if (entity == null) {
307 			return null;
308 		}
309 		CluSetInfo dto = new CluSetInfo();
310 
311 		BeanUtils.copyProperties(entity, dto, new String[] { "descr",
312 				"cluCriteria", "cluSets", "clus", "attributes", "metaInfo", "membershipQuery" });
313 
314 		dto.setDescr(toRichTextInfo(entity.getDescr()));
315 		// TODO dto.setCluCriteria()
316 		if(entity.getCluSets()!=null){
317 			List<String> cluSetIds = new ArrayList<String>(entity.getCluSets()
318 					.size());
319 			for (CluSet id : entity.getCluSets()) {
320 				cluSetIds.add(id.getId());
321 			}
322 			dto.setCluSetIds(cluSetIds);
323 		}
324 
325 		List<String> cluIds = new ArrayList<String>(entity.getCluVerIndIds().size());
326 		for (CluSetJoinVersionIndClu join : entity.getCluVerIndIds()) {
327 			cluIds.add(join.getCluVersionIndId());
328 		}
329 		dto.setCluIds(cluIds);
330 
331 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
332 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
333 
334 		MembershipQueryInfo mqInfo = toMembershipQueryInfo(entity.getMembershipQuery());
335 		dto.setMembershipQuery(mqInfo);
336 		dto.setIsReusable(entity.getIsReusable());
337 		dto.setIsReferenceable(entity.getIsReferenceable());
338 
339 		return dto;
340 	}
341 
342 	public static MembershipQueryInfo toMembershipQueryInfo(MembershipQuery entity) {
343 		if(entity == null) {
344 			return null;
345 		}
346 		MembershipQueryInfo dto = new MembershipQueryInfo();
347 		dto.setId(entity.getId());
348 		dto.setSearchTypeKey(entity.getSearchTypeKey());
349 		List<SearchParam> list = new ArrayList<SearchParam>();
350 		for(SearchParameter param : entity.getSearchParameters()) {
351 			SearchParam sp = toSearchParam(param);
352 			list.add(sp);
353 		}
354 		dto.setQueryParamValueList(list);
355 
356 		return dto;
357 	}
358 
359 	public static SearchParam toSearchParam(SearchParameter entity) {
360 		SearchParam dto = new SearchParam();
361 		dto.setKey(entity.getKey());
362 		List<String> values = new ArrayList<String>();
363 		for(SearchParameterValue value : entity.getValues()) {
364 			values.add(value.getValue());
365 		}
366 		dto.setValue(values);
367 		if(entity.getValues().size() == 1) {
368 			dto.setValue(entity.getValues().get(0).getValue());
369 		}
370 		return dto;
371 	}
372 
373 	public static MembershipQuery toMembershipQueryEntity(MembershipQueryInfo dto) {
374 		if(dto == null) {
375 			return null;
376 		}
377 		MembershipQuery entity = new MembershipQuery();
378 		entity.setSearchTypeKey(dto.getSearchTypeKey());
379 		List<SearchParameter> list = new ArrayList<SearchParameter>();
380 		for(SearchParam param : dto.getQueryParamValueList()) {
381 			SearchParameter sp = toSearchParameterEntity(param);
382 			list.add(sp);
383 		}
384 		entity.setSearchParameters(list);
385 
386 		return entity;
387 	}
388 
389 	public static SearchParameter toSearchParameterEntity(SearchParam dto) {
390 		if(dto == null) {
391 			return null;
392 		}
393 		SearchParameter entity = new SearchParameter();
394 		entity.setKey(dto.getKey());
395 		List<SearchParameterValue> values = new ArrayList<SearchParameterValue>();
396 		if(dto.getValue() instanceof String) {
397 			SearchParameterValue value = new SearchParameterValue();
398 			value.setValue((String) dto.getValue());
399 			values.add(value);
400 		} else if(dto.getValue() instanceof List<?>) {
401 			List<String> stringList = (List<String>)dto.getValue();
402 			for(String s : stringList) {
403 				SearchParameterValue value = new SearchParameterValue();
404 				value.setValue(s);
405 				values.add(value);
406 			}
407 		}
408 		entity.setValues(values);
409 		return entity;
410 	}
411 
412 	public static List<ResultUsageTypeInfo> toResultUsageTypeInfos(
413 			List<ResultUsageType> entities) {
414 		return toGenericTypeInfoList(ResultUsageTypeInfo.class, entities);
415 	}
416 
417 	public static ResultUsageTypeInfo toResultUsageTypeInfo(
418 			ResultUsageType entity) {
419 		return toGenericTypeInfo(ResultUsageTypeInfo.class, entity);
420 	}
421 
422 	public static List<DeliveryMethodTypeInfo> toDeliveryMethodTypeInfos(
423 			List<DeliveryMethodType> entities) {
424 		return toGenericTypeInfoList(DeliveryMethodTypeInfo.class, entities);
425 	}
426 
427 	public static DeliveryMethodTypeInfo toDeliveryMethodTypeInfo(
428 			DeliveryMethodType entity) {
429 		return toGenericTypeInfo(DeliveryMethodTypeInfo.class, entity);
430 	}
431 
432 	public static List<InstructionalFormatTypeInfo> toInstructionalFormatTypeInfos(
433 			List<InstructionalFormatType> entities) {
434 		return toGenericTypeInfoList(InstructionalFormatTypeInfo.class,
435 				entities);
436 	}
437 
438 	public static InstructionalFormatTypeInfo toInstructionalFormatTypeInfo(
439 			InstructionalFormatType entity) {
440 		return toGenericTypeInfo(InstructionalFormatTypeInfo.class, entity);
441 	}
442 
443 	public static List<LuCodeTypeInfo> toLuCodeTypeInfos(
444 			List<LuCodeType> entities) {
445 		return toGenericTypeInfoList(LuCodeTypeInfo.class, entities);
446 	}
447 
448 	public static LuCodeTypeInfo toLuCodeTypeInfo(LuCodeType entity) {
449 		return toGenericTypeInfo(LuCodeTypeInfo.class, entity);
450 	}
451 
452 	public static List<CluResultTypeInfo> toCluResultTypeInfos(
453 			List<CluResultType> entities) {
454 		return toGenericTypeInfoList(CluResultTypeInfo.class, entities);
455 	}
456 
457 	public static CluResultTypeInfo toCluResultTypeInfo(CluResultType entity) {
458 		return toGenericTypeInfo(CluResultTypeInfo.class, entity);
459 	}
460 
461 	public static CluSetTypeInfo toCluSetTypeInfo(CluSetType entity) {
462 		return toGenericTypeInfo(CluSetTypeInfo.class, entity);
463 	}
464 
465 	public static List<CluSetTypeInfo> toCluSetTypeInfos(
466 			List<CluSetType> entities) {
467 		return toGenericTypeInfoList(CluSetTypeInfo.class, entities);
468 	}
469 
470 	public static CluResultInfo toCluResultInfo(CluResult entity) {
471 		if (entity == null) {
472 			return null;
473 		}
474 
475 		CluResultInfo dto = new CluResultInfo();
476 
477 		BeanUtils.copyProperties(entity, dto, new String[] { "resultOptions", "desc" });
478 
479 		List<ResultOptionInfo> resultOptions = toResultOptionInfos(entity.getResultOptions());
480 		dto.setResultOptions(resultOptions);
481 		dto.setDesc(toRichTextInfo(entity.getDesc()));
482 		dto.setCluId(entity.getClu().getId());
483 		CluResultTypeInfo type = toCluResultTypeInfo(entity.getCluResultType());
484 		if(type!=null){
485 			dto.setType(type.getId());
486 		}
487 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
488 
489 		return dto;
490 	}
491 
492 	public static List<CluResultInfo> toCluResultInfos(List<CluResult> entities) {
493 		List<CluResultInfo> dtos = new ArrayList<CluResultInfo>();
494 		if (entities != null) {
495 			for (CluResult entity : entities) {
496 				dtos.add(toCluResultInfo(entity));
497 			}
498 		}
499 		return dtos;
500 	}
501 
502 	public static List<ResultOptionInfo> toResultOptionInfos(
503 			List<ResultOption> entities) {
504 		List<ResultOptionInfo> dtos = new ArrayList<ResultOptionInfo>();
505 		if (entities != null) {
506 			for (ResultOption entity : entities) {
507 				dtos.add(toResultOptionInfo(entity));
508 			}
509 		}
510 		return dtos;
511 	}
512 
513 	public static ResultOptionInfo toResultOptionInfo(ResultOption entity) {
514 		if (entity == null) {
515 			return null;
516 		}
517 
518 		ResultOptionInfo dto = new ResultOptionInfo();
519 
520 		BeanUtils.copyProperties(entity, dto, new String[] { "resultUsageType", "desc" });
521 		if(entity.getResultUsageType() != null) {
522 			dto.setResultUsageTypeKey(entity.getResultUsageType().getId());
523 		}
524 		dto.setDesc(toRichTextInfo(entity.getDesc()));
525 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
526 
527 		return dto;
528 	}
529 
530 	public static List<LuLuRelationTypeInfo> toLuLuRelationTypeInfos(
531 			List<LuLuRelationType> entities) {
532 		List<LuLuRelationTypeInfo> dtos = new ArrayList<LuLuRelationTypeInfo>(
533 				entities.size());
534 		if(entities!=null){
535 			for (LuLuRelationType entity : entities) {
536 				dtos.add(toLuLuRelationTypeInfo(entity));
537 			}
538 		}
539 		return dtos;
540 
541 	}
542 
543 	public static LuLuRelationTypeInfo toLuLuRelationTypeInfo(
544 			LuLuRelationType entity) {
545 		if (entity == null) {
546 			return null;
547 		}
548 		LuLuRelationTypeInfo dto = new LuLuRelationTypeInfo();
549 
550 		BeanUtils.copyProperties(entity, dto, new String[] { "attributes" });
551 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
552 
553 		return dto;
554 	}
555 
556 	public static List<LuTypeInfo> toLuTypeInfos(List<LuType> entities) {
557 		return toGenericTypeInfoList(LuTypeInfo.class, entities);
558 	}
559 
560 	public static LuTypeInfo toLuTypeInfo(LuType entity) {
561 		LuTypeInfo typeInfo = toGenericTypeInfo(LuTypeInfo.class, entity);
562 		typeInfo.setDeliveryMethod(entity.getDeliveryMethod());
563 		typeInfo.setInstructionalFormat(entity.getInstructionalFormat());
564 
565 		return typeInfo;
566 	}
567 
568 	public static List<LuiInfo> toLuiInfos(List<Lui> entities) {
569 		List<LuiInfo> dtos = new ArrayList<LuiInfo>(entities.size());
570 		if (entities != null) {
571 			for (Lui entity : entities) {
572 				dtos.add(toLuiInfo(entity));
573 			}
574 		}
575 		return dtos;
576 
577 	}
578 
579 	public static LuiInfo toLuiInfo(Lui entity) {
580 		if (entity == null) {
581 			return null;
582 		}
583 		LuiInfo luiInfo = new LuiInfo();
584 
585 		BeanUtils.copyProperties(entity, luiInfo, new String[] { "clu",
586 				"metaInfo", "attributes" });
587 
588 		luiInfo.setCluId(entity.getClu().getId());
589 
590 		luiInfo
591 				.setMetaInfo(toMetaInfo(entity.getMeta(), entity
592 						.getVersionNumber()));
593 
594 		luiInfo.setAttributes(toAttributeMap(entity.getAttributes()));
595 
596 		return luiInfo;
597 	}
598 
599 	public static Lui toLui(boolean isUpdate, LuiInfo luiInfo, LuDao dao)
600 			throws DoesNotExistException, VersionMismatchException,
601 			InvalidParameterException {
602 		if (luiInfo == null) {
603 			return null;
604 		}
605 		Lui lui;
606 
607 		if (isUpdate) {
608 			lui = dao.fetch(Lui.class, luiInfo.getId());
609 			if (null == lui) {
610 				throw new DoesNotExistException((new StringBuilder()).append(
611 						"Lui does not exist for id: ").append(luiInfo.getId())
612 						.toString());
613 			}
614 			if (!String.valueOf(lui.getVersionNumber()).equals(
615 					luiInfo.getMetaInfo().getVersionInd())) {
616 				throw new VersionMismatchException(
617 						"Lui to be updated is not the current version");
618 			}
619 		} else {
620 			lui = new Lui();
621 		}
622 
623 		BeanUtils.copyProperties(luiInfo, lui, new String[] { "cluId",
624 				"attributes", "metaInfo" });
625 
626 		lui.setAttributes(toGenericAttributes(LuiAttribute.class, luiInfo
627 				.getAttributes(), lui, dao));
628 
629 		Clu clu = dao.fetch(Clu.class, luiInfo.getCluId());
630 		if (null == clu) {
631 			throw new InvalidParameterException((new StringBuilder()).append(
632 					"Clu does not exist for id: ").append(luiInfo.getCluId())
633 					.toString());
634 		}
635 		lui.setClu(clu);
636 		return lui;
637 	}
638 
639 	public static List<LuiLuiRelationInfo> toLuiLuiRelationInfos(
640 			List<LuiLuiRelation> entities) {
641 		List<LuiLuiRelationInfo> dtos = new ArrayList<LuiLuiRelationInfo>(
642 				entities.size());
643 		if (entities != null) {
644 			for (LuiLuiRelation entity : entities) {
645 				dtos.add(toLuiLuiRelationInfo(entity));
646 			}
647 		}
648 		return dtos;
649 	}
650 
651 	public static LuiLuiRelationInfo toLuiLuiRelationInfo(LuiLuiRelation entity) {
652 		if (entity == null) {
653 			return null;
654 		}
655 		LuiLuiRelationInfo dto = new LuiLuiRelationInfo();
656 
657 		BeanUtils.copyProperties(entity, dto, new String[] { "lui",
658 				"relatedLui", "attributes" });
659 
660 		dto.setLuiId(entity.getLui().getId());
661 		dto.setRelatedLuiId(entity.getRelatedLui().getId());
662 		dto.setType(entity.getLuLuRelationType().getId());
663 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
664 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
665 		return dto;
666 	}
667 
668 	public static List<CluIdentifierInfo> toCluIdentifierInfos(
669 			List<CluIdentifier> entities) {
670 		List<CluIdentifierInfo> dtos = new ArrayList<CluIdentifierInfo>(
671 				entities.size());
672 		if(entities!=null){
673 			for (CluIdentifier entity : entities) {
674 				dtos.add(toCluIdentifierInfo(entity));
675 			}
676 		}
677 		return dtos;
678 	}
679 
680 	public static CluIdentifierInfo toCluIdentifierInfo(CluIdentifier entity) {
681 		if (entity == null) {
682 			return null;
683 		}
684 
685 		CluIdentifierInfo dto = new CluIdentifierInfo();
686 
687 		BeanUtils.copyProperties(entity, dto,
688 		        new String[] { "attributes" });
689 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
690 		return dto;
691 	}
692 
693 	public static List<CluInstructorInfo> toCluInstructorInfos(
694 			List<CluInstructor> entities) {
695 		List<CluInstructorInfo> dtos = new ArrayList<CluInstructorInfo>(
696 				entities.size());
697 		if(entities!=null){
698 			for (CluInstructor entity : entities) {
699 				dtos.add(toCluInstructorInfo(entity));
700 			}
701 		}
702 		return dtos;
703 	}
704 
705 	public static CluInstructorInfo toCluInstructorInfo(CluInstructor entity) {
706 		if (entity == null) {
707 			return null;
708 		}
709 		CluInstructorInfo dto = new CluInstructorInfo();
710 
711 		BeanUtils.copyProperties(entity, dto,
712 				new String[] { "id", "attributes" });
713 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
714 
715 		return dto;
716 	}
717 
718 	public static AmountInfo toAmountInfo(Amount entity) {
719 		if (entity == null) {
720 			return null;
721 		}
722 		AmountInfo dto = new AmountInfo();
723 
724 		BeanUtils.copyProperties(entity, dto);
725 
726 		return dto;
727 	}
728 
729 	public static TimeAmountInfo toTimeAmountInfo(TimeAmount entity) {
730 		if (entity == null) {
731 			return null;
732 		}
733 		TimeAmountInfo dto = new TimeAmountInfo();
734 
735 		BeanUtils.copyProperties(entity, dto);
736 
737 		return dto;
738 	}
739 
740 	public static List<LuCodeInfo> toLuCodeInfos(List<LuCode> entities) {
741 		List<LuCodeInfo> dtos = new ArrayList<LuCodeInfo>(entities.size());
742 		if(entities!=null){
743 			for (LuCode entity : entities) {
744 				dtos.add(toLuCodeInfo(entity));
745 			}
746 		}
747 		return dtos;
748 	}
749 
750 	public static LuCodeInfo toLuCodeInfo(LuCode entity) {
751 		if (entity == null) {
752 			return null;
753 		}
754 		LuCodeInfo dto = new LuCodeInfo();
755 
756 		BeanUtils.copyProperties(entity, dto, new String[] { "attributes",
757 				"metInfo" });
758 
759 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
760 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
761 
762 		return dto;
763 	}
764 
765 	public static List<ResultComponentTypeInfo> toResultComponentTypeInfo(
766 			List<String> componentIds) {
767 		List<ResultComponentTypeInfo> dtos = new ArrayList<ResultComponentTypeInfo>();
768 		if(componentIds!=null){
769 			for (String id : componentIds) {
770 				ResultComponentTypeInfo comp = new ResultComponentTypeInfo();
771 				comp.setId(id);
772 				dtos.add(comp);
773 			}
774 		}
775 		return dtos;
776 	}
777 
778 	public static CluFeeInfo toCluFeeInfo(CluFee entity) {
779 		if (entity == null) {
780 			return null;
781 		}
782 		CluFeeInfo dto = new CluFeeInfo();
783 
784 		dto.setCluFeeRecords(toCluFeeRecordInfos(entity.getCluFeeRecords()));
785 		dto.setId(entity.getId());
786 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
787 		dto.setDescr(toRichTextInfo(entity.getDescr()));
788 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
789 
790 		return dto;
791 	}
792 
793 	private static List<CluFeeRecordInfo> toCluFeeRecordInfos(
794 			List<CluFeeRecord> entities) {
795 		List<CluFeeRecordInfo> dtos = new ArrayList<CluFeeRecordInfo>();
796 		if (entities != null) {
797 			for (CluFeeRecord record : entities) {
798 				dtos.add(toCluFeeRecordInfo(record));
799 			}
800 		}
801 		return dtos;
802 	}
803 
804 	private static CluFeeRecordInfo toCluFeeRecordInfo(CluFeeRecord entity) {
805 		if (entity == null) {
806 			return null;
807 		}
808 
809 		CluFeeRecordInfo dto = new CluFeeRecordInfo();
810 
811 		BeanUtils.copyProperties(entity, dto,
812 				new String[] { "affiliatedOrgs", "currencyAmount","attributes","descr" });
813 
814 		dto.setAffiliatedOrgs(toAffiliatedOrgInfos(entity.getAffiliatedOrgs()));
815 		dto.setFeeAmounts(toFeeAmounts(entity.getFeeAmounts()));
816 		dto.setDescr(toRichTextInfo(entity.getDescr()));
817 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
818 		dto.setMetaInfo(toMetaInfo(entity.getMeta(), entity.getVersionNumber()));
819 
820 		return dto;
821 	}
822 
823 	private static List<CurrencyAmountInfo> toFeeAmounts(List<CluFeeAmount> cluFees) {
824 		List<CurrencyAmountInfo> feeAmounts = new ArrayList<CurrencyAmountInfo>();
825 		
826 		if (cluFees != null){
827 			for (CluFeeAmount cluFeeAmount:cluFees){
828 				CurrencyAmountInfo dto = new CurrencyAmountInfo();
829 				CurrencyAmount ca = cluFeeAmount.getCurrencyAmount();
830 				if(ca!=null){
831 					dto.setCurrencyQuantity(ca.getCurrencyQuantity());
832 					dto.setCurrencyTypeKey(ca.getCurrencyTypeKey());
833 				}
834 				feeAmounts.add(dto);
835 			}
836 		}
837 		
838 		return feeAmounts;
839 	}
840 
841 	private static List<AffiliatedOrgInfo> toAffiliatedOrgInfos(
842 			List<AffiliatedOrg> entities) {
843 		List<AffiliatedOrgInfo> dtos = new ArrayList<AffiliatedOrgInfo>();
844 		if (entities != null) {
845 			for (AffiliatedOrg record : entities) {
846 				dtos.add(toAffiliatedOrgInfo(record));
847 			}
848 		}
849 		return dtos;
850 	}
851 
852 	private static AffiliatedOrgInfo toAffiliatedOrgInfo(AffiliatedOrg entity) {
853 		if (entity == null) {
854 			return null;
855 		}
856 
857 		AffiliatedOrgInfo dto = new AffiliatedOrgInfo();
858 
859 		BeanUtils.copyProperties(entity, dto);
860 		return dto;
861 	}
862 
863 	public static CluAccountingInfo toCluAccountingInfo(CluAccounting entity) {
864 		if (entity == null) {
865 			return null;
866 		}
867 		CluAccountingInfo dto = new CluAccountingInfo();
868 		dto.setId(entity.getId());
869 		dto.setAffiliatedOrgs(toAffiliatedOrgInfos(entity.getAffiliatedOrgs()));
870 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
871 		return dto;
872 	}
873 
874 	public static Amount toAmount(AmountInfo amountInfo) {
875 		if (amountInfo == null) {
876 			return null;
877 		}
878 		Amount amount = new Amount();
879 		BeanUtils.copyProperties(amountInfo, amount);
880 		return amount;
881 	}
882 
883 	public static TimeAmount toTimeAmount(TimeAmountInfo timeAmountInfo) {
884 		if (timeAmountInfo == null) {
885 			return null;
886 		}
887 		TimeAmount timeAmount = new TimeAmount();
888 		BeanUtils.copyProperties(timeAmountInfo, timeAmount);
889 		return timeAmount;
890 	}
891 
892 	public static List<AccreditationInfo> toAccreditationInfos(
893 			List<CluAccreditation> entities) {
894 		List<AccreditationInfo> dtos = new ArrayList<AccreditationInfo>(entities.size());
895 
896 		if (entities != null) {
897 			for (CluAccreditation entity : entities) {
898 				dtos.add(toAccreditationInfo(entity));
899 			}
900 		}
901 		return dtos;
902 	}
903 
904 	public static AccreditationInfo toAccreditationInfo(CluAccreditation entity) {
905 		if (entity == null) {
906 			return null;
907 		}
908 		AccreditationInfo dto = new AccreditationInfo();
909 
910 		BeanUtils.copyProperties(entity, dto, new String[] { "attributes" });
911 
912 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
913 
914 		return dto;
915 
916 	}
917 
918 	public static List<AdminOrgInfo> toCluAdminOrgInfos(
919 			List<CluAdminOrg> entities) {
920 		List<AdminOrgInfo> dtos = new ArrayList<AdminOrgInfo>(entities.size());
921 		if (entities != null) {
922 			for (CluAdminOrg entity : entities) {
923 				dtos.add(toAdminOrgInfo(entity));
924 			}
925 		}
926 		return dtos;
927 	}
928 
929 	public static AdminOrgInfo toAdminOrgInfo(CluAdminOrg entity) {
930 		if (entity == null) {
931 			return null;
932 		}
933 		AdminOrgInfo dto = new AdminOrgInfo();
934 		BeanUtils.copyProperties(entity, dto, new String[] { "attributes" });
935 		dto.setAttributes(toAttributeMap(entity.getAttributes()));
936 
937 		return dto;
938 	}
939 
940 	public static List<LuPublicationTypeInfo> toLuPublicationTypeInfos(
941 			List<LuPublicationType> entities) {
942 		return toGenericTypeInfoList(LuPublicationTypeInfo.class, entities);
943 	}
944 
945 	public static LuPublicationTypeInfo toLuPublicationTypeInfo(
946 			LuPublicationType entity) {
947 		return toGenericTypeInfo(LuPublicationTypeInfo.class, entity);
948 	}
949 
950 	public static CluFee toCluFee(Clu clu, boolean isUpdate, CluFeeInfo feeInfo,
951 			LuDao dao) throws DoesNotExistException, VersionMismatchException,
952 			InvalidParameterException {
953 		if (feeInfo == null) {
954 			return null;
955 		}
956 
957 		CluFee fee = null;
958 
959 		if (isUpdate) {
960 			fee = clu.getFee();
961 			if (!String.valueOf(fee.getVersionNumber()).equals(
962 					feeInfo.getMetaInfo().getVersionInd())) {
963 				throw new VersionMismatchException(
964 						"CluFee to be updated is not the current version");
965 			}
966 		} 
967 		if(fee == null){
968 			fee = new CluFee();
969 		}
970 
971 		if (feeInfo.getDescr() != null && (feeInfo.getDescr().getPlain() != null || feeInfo.getDescr().getFormatted() != null)) {
972 			if (fee.getDescr() == null) {
973 				fee.setDescr(new LuRichText());
974 			}
975 			BeanUtils.copyProperties(feeInfo.getDescr(), fee.getDescr());
976 		} else if (isUpdate && fee.getDescr() != null) {
977 			dao.delete(fee.getDescr());
978 			fee.setDescr(null);
979 		}
980 
981 		fee.setAttributes(LuServiceAssembler.toGenericAttributes(
982 				CluFeeAttribute.class, feeInfo.getAttributes(), fee, dao));
983 		toCluFeeRecords(isUpdate, fee, feeInfo.getCluFeeRecords(), dao);
984 
985 		return fee;
986 	}
987 
988 	public static void toCluFeeRecords(boolean isUpdate,
989 			CluFee cluFee, List<CluFeeRecordInfo> cluFeeRecords, LuDao dao) throws InvalidParameterException {
990 
991 		if (cluFeeRecords == null) {
992 			return;
993 		}
994 
995 		if (!isUpdate) {
996 
997 			for (CluFeeRecordInfo feeRecordInfo : cluFeeRecords) {
998 				CluFeeRecord feeRec = new CluFeeRecord();
999 				feeRec.setAffiliatedOrgs(toAffiliatedOrgs(isUpdate, feeRec.getAffiliatedOrgs(), feeRecordInfo.getAffiliatedOrgs(), dao));
1000 				feeRec.setFeeType(feeRecordInfo.getFeeType());
1001 				feeRec.setRateType(feeRecordInfo.getRateType());
1002 				feeRec.setDescr(toRichText(LuRichText.class, feeRecordInfo.getDescr()));
1003 				feeRec.setFeeAmounts(toFeeAmounts(isUpdate, feeRec.getFeeAmounts(), feeRecordInfo.getFeeAmounts(), dao));
1004 				feeRec.setAttributes(LuServiceAssembler.toGenericAttributes(
1005 						CluFeeRecordAttribute.class, feeRecordInfo
1006 								.getAttributes(), feeRec, dao));
1007 				if(cluFee.getCluFeeRecords()==null){
1008 					cluFee.setCluFeeRecords(new ArrayList<CluFeeRecord>());
1009 				}
1010 				cluFee.getCluFeeRecords().add(feeRec);
1011 			}
1012 		} else {
1013 			Map<String, CluFeeRecord> oldFeeRecMap = new HashMap<String, CluFeeRecord>();
1014 			if(cluFee.getCluFeeRecords()!=null){
1015 				for (CluFeeRecord feeRec : cluFee.getCluFeeRecords()) {
1016 					oldFeeRecMap.put(feeRec.getId(), feeRec);
1017 				}
1018 				cluFee.getCluFeeRecords().clear();
1019 			}
1020 			
1021 			// Loop through the new list, if the item exists already update and
1022 			// remove from the list
1023 			// otherwise create a new entry
1024 			for (CluFeeRecordInfo feeRecordInfo : cluFeeRecords) {
1025 				CluFeeRecord feeRec = oldFeeRecMap.remove(feeRecordInfo.getId());
1026 				if (feeRec == null) {
1027 					feeRec = new CluFeeRecord();
1028 				}
1029 
1030 				feeRec.setAffiliatedOrgs(toAffiliatedOrgs(isUpdate, feeRec.getAffiliatedOrgs(), feeRecordInfo.getAffiliatedOrgs(),dao));
1031 				feeRec.setFeeType(feeRecordInfo.getFeeType());
1032 				feeRec.setRateType(feeRecordInfo.getRateType());
1033 				feeRec.setDescr(toRichText(LuRichText.class, feeRecordInfo.getDescr()));
1034 				feeRec.setFeeAmounts(toFeeAmounts(isUpdate, feeRec.getFeeAmounts(), feeRecordInfo.getFeeAmounts(),dao));
1035 				feeRec.setAttributes(LuServiceAssembler.toGenericAttributes(
1036 						CluFeeRecordAttribute.class, feeRecordInfo
1037 								.getAttributes(), feeRec, dao));
1038 				if(cluFee.getCluFeeRecords()==null){
1039 					cluFee.setCluFeeRecords(new ArrayList<CluFeeRecord>());
1040 				}
1041 				cluFee.getCluFeeRecords().add(feeRec);
1042 			}
1043 
1044 			// Now delete anything left over
1045 			for (Entry<String, CluFeeRecord> entry : oldFeeRecMap.entrySet()) {
1046 				dao.delete(entry.getValue());
1047 			}
1048 		}
1049 	}
1050 
1051 	public static List<AffiliatedOrg> toAffiliatedOrgs(boolean isUpdate, List<AffiliatedOrg> orgList, List<AffiliatedOrgInfo> affiliatedOrgInfoList, LuDao dao) {
1052 		if(null == affiliatedOrgInfoList) {
1053 			return orgList;
1054 		}
1055 		if(orgList==null){
1056 			orgList = new ArrayList<AffiliatedOrg>();
1057 		}
1058 		
1059 		if (!isUpdate) {
1060 
1061 			for (AffiliatedOrgInfo orgInfo : affiliatedOrgInfoList) {
1062 				AffiliatedOrg org = new AffiliatedOrg();
1063 				BeanUtils.copyProperties(orgInfo, org);
1064 				orgList.add(org);
1065 			}
1066 		} else {
1067 			Map<String, AffiliatedOrg> oldOrgMap = new HashMap<String, AffiliatedOrg>();
1068 			for (AffiliatedOrg org : orgList) {
1069 				oldOrgMap.put(org.getId(), org);
1070 			}
1071 			orgList.clear();
1072 
1073 			for (AffiliatedOrgInfo orgInfo : affiliatedOrgInfoList) {
1074 				AffiliatedOrg org = oldOrgMap.remove(orgInfo.getId());
1075 				if (org == null) {
1076 					org = new AffiliatedOrg();
1077 				}
1078 
1079 				BeanUtils.copyProperties(orgInfo, org);
1080 
1081 				orgList.add(org);
1082 			}
1083 
1084 			// Now delete anything left over
1085 			for (Entry<String, AffiliatedOrg> entry : oldOrgMap.entrySet()) {
1086 				dao.delete(entry.getValue());
1087 			}
1088 		}
1089 
1090 		return orgList;
1091 	}
1092 
1093 	public static List<CluFeeAmount> toFeeAmounts(boolean isUpdate, List<CluFeeAmount> caList, List<CurrencyAmountInfo> caInfoList, LuDao dao){
1094 		if(null == caInfoList) {
1095 			return caList;
1096 		}
1097 		if(caList==null){
1098 			caList = new ArrayList<CluFeeAmount>(caInfoList.size());
1099 		}
1100 		
1101 		if (!isUpdate) {
1102 			for (CurrencyAmountInfo caInfo:caInfoList){
1103 				CurrencyAmount ca = new CurrencyAmount();
1104 				ca.setCurrencyQuantity(caInfo.getCurrencyQuantity());
1105 				ca.setCurrencyTypeKey(caInfo.getCurrencyTypeKey());
1106 				CluFeeAmount cluFeeAmount = new CluFeeAmount();
1107 				cluFeeAmount.setCurrencyAmount(ca);
1108 				caList.add(cluFeeAmount);
1109 			}
1110 		} else {
1111 			// Delete existing fee amounts (this assumes feeAmounts are not individually updated)
1112 			for (CluFeeAmount cluFeeAmount:caList) {
1113 				dao.delete(cluFeeAmount);
1114 			}					
1115 			caList.clear();
1116 
1117 			for (CurrencyAmountInfo caInfo : caInfoList) {
1118 				CurrencyAmount ca = new CurrencyAmount();
1119 
1120 				ca.setCurrencyQuantity(caInfo.getCurrencyQuantity());
1121 				ca.setCurrencyTypeKey(caInfo.getCurrencyTypeKey());
1122 				CluFeeAmount cluFeeAmount = new CluFeeAmount();
1123 				cluFeeAmount.setCurrencyAmount(ca);
1124 				caList.add(cluFeeAmount);
1125 			}
1126 		}
1127 
1128 		return caList;
1129 	}
1130 	
1131 	public static CluIdentifier createOfficialIdentifier(CluInfo cluInfo, LuDao dao) throws InvalidParameterException {
1132         CluIdentifier officialIdentifier = new CluIdentifier();
1133         BeanUtils.copyProperties(cluInfo.getOfficialIdentifier(),
1134                 officialIdentifier, new String[] { "attributes"});
1135         officialIdentifier.setAttributes(LuServiceAssembler.toGenericAttributes(
1136                 CluIdentifierAttribute.class, cluInfo.getOfficialIdentifier()
1137                         .getAttributes(), officialIdentifier, dao));
1138         
1139         return officialIdentifier;
1140 	}
1141 
1142     public static void updateOfficialIdentifier(Clu clu, CluInfo cluInfo, LuDao dao) throws InvalidParameterException {
1143         if (clu.getOfficialIdentifier() == null) {
1144             clu.setOfficialIdentifier(new CluIdentifier());
1145         }
1146         BeanUtils.copyProperties(cluInfo.getOfficialIdentifier(), clu
1147                 .getOfficialIdentifier(), new String[] { "id" , "attributes"});
1148         
1149         clu.getOfficialIdentifier().setAttributes(LuServiceAssembler.toGenericAttributes(
1150                 CluIdentifierAttribute.class, cluInfo.getOfficialIdentifier()
1151                         .getAttributes(), clu.getOfficialIdentifier(), dao));
1152         
1153     }
1154 
1155 	public static List<CluIdentifier> createAlternateIdentifiers(CluInfo cluInfo, LuDao dao) throws InvalidParameterException {
1156 	    List<CluIdentifier> alternateIdentifiers = new ArrayList<CluIdentifier>(0);
1157 	    for (CluIdentifierInfo cluIdInfo : cluInfo.getAlternateIdentifiers()) {
1158 	        CluIdentifier identifier = new CluIdentifier();
1159 	        BeanUtils.copyProperties(cluIdInfo, identifier, new String[] { "attributes"} );
1160 
1161 	        identifier.setAttributes(LuServiceAssembler.toGenericAttributes(
1162 	                CluIdentifierAttribute.class, cluIdInfo.getAttributes(), identifier, dao));
1163 	        	        
1164 	        alternateIdentifiers.add(identifier);
1165 	    }
1166 	    return alternateIdentifiers;
1167 	}
1168 
1169     public static void updateAlternateIdentifier(Map<String, CluIdentifier> oldAltIdMap, Clu clu, CluInfo cluInfo, LuDao dao) throws InvalidParameterException {
1170         for (CluIdentifier altIdentifier : clu.getAlternateIdentifiers()) {
1171             oldAltIdMap.put(altIdentifier.getId(), altIdentifier);
1172         }
1173         clu.getAlternateIdentifiers().clear();
1174 
1175         // Loop through the new list, if the item exists already update and
1176         // remove from the list
1177         // otherwise create a new entry
1178         for (CluIdentifierInfo cluIdInfo : cluInfo.getAlternateIdentifiers()) {
1179             CluIdentifier identifier = oldAltIdMap.remove(cluIdInfo.getId());
1180             if (identifier == null) {
1181                 identifier = new CluIdentifier();
1182             }
1183             // Do Copy
1184             BeanUtils.copyProperties(cluIdInfo, identifier, new String[] { "attributes"});
1185             
1186             identifier.setAttributes(LuServiceAssembler.toGenericAttributes(
1187                     CluIdentifierAttribute.class, cluIdInfo.getAttributes(), identifier, dao));
1188             
1189             clu.getAlternateIdentifiers().add(identifier);
1190         }
1191     }
1192 
1193 	public static List<CluPublicationVariant> toCluPublicationVariants(
1194 			List<FieldInfo> variantInfos, CluPublication cluPub, LuDao luDao) {
1195 		List<CluPublicationVariant> variants = new ArrayList<CluPublicationVariant>();
1196 
1197 		if(cluPub.getVariants()==null){
1198 			cluPub.setVariants(new ArrayList<CluPublicationVariant>());
1199 		}
1200 		
1201 		// Delete all the old attributes(if the owner is not null)
1202 		for (CluPublicationVariant variant : cluPub.getVariants()) {
1203 			luDao.delete(variant);
1204 		}
1205 		cluPub.getVariants().clear();
1206 
1207 		for (FieldInfo variantInfo: variantInfos) {
1208 			CluPublicationVariant variant = new CluPublicationVariant();
1209 			variant.setKey(variantInfo.getId());
1210 			variant.setValue(variantInfo.getValue());
1211 			variant.setOwner(cluPub);
1212 			variants.add(variant);
1213 		}
1214 
1215 		return variants;
1216 	}
1217 
1218 	public static CluPublicationInfo toCluPublicationInfo(CluPublication cluPub) {
1219 		if(cluPub==null){
1220 			return null;
1221 		}
1222 		CluPublicationInfo cluPubInfo = new CluPublicationInfo();
1223 		cluPubInfo.setCluId(cluPub.getClu().getId());
1224 		cluPubInfo.setId(cluPub.getId());
1225 		cluPubInfo.setEndCycle(cluPub.getEndCycle());
1226 		cluPubInfo.setStartCycle(cluPub.getStartCycle());
1227 		cluPubInfo.setEffectiveDate(cluPub.getEffectiveDate());
1228 		cluPubInfo.setExpirationDate(cluPub.getExpirationDate());
1229 		cluPubInfo.setState(cluPub.getState());
1230 		cluPubInfo.setType(cluPub.getType().getId());
1231 		cluPubInfo.setMetaInfo(toMetaInfo(cluPub.getMeta(), cluPub.getVersionNumber()));
1232 		cluPubInfo.setAttributes(LuServiceAssembler.toAttributeMap(cluPub.getAttributes()));
1233 		cluPubInfo.setVariants(LuServiceAssembler.toCluPublicationVariantInfos(cluPub.getVariants()));
1234 		
1235 		return cluPubInfo;
1236 	}
1237 
1238 	private static List<FieldInfo> toCluPublicationVariantInfos(
1239 			List<CluPublicationVariant> variants) {
1240 		if(variants == null){
1241 			return  new ArrayList<FieldInfo>(0);
1242 		}
1243 		List<FieldInfo> fields = new ArrayList<FieldInfo>();
1244 		for(CluPublicationVariant variant:variants){
1245 			FieldInfo field = new FieldInfo();
1246 			field.setId(variant.getKey());
1247 			field.setValue(variant.getValue());
1248 			fields.add(field);
1249 		}
1250 		return fields;
1251 	}
1252 
1253 	public static List<CluPublicationInfo> toCluPublicationInfos(
1254 			List<CluPublication> cluPublications) {
1255 		if(cluPublications == null){
1256 			return new ArrayList<CluPublicationInfo>(0);
1257 		}
1258 		List<CluPublicationInfo> cluPublicationInfos = new ArrayList<CluPublicationInfo>(cluPublications.size());
1259 		for(CluPublication cluPublication:cluPublications){
1260 			cluPublicationInfos.add(toCluPublicationInfo(cluPublication));
1261 		}
1262 		return cluPublicationInfos;
1263 	}
1264 }