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