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