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