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