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