Coverage Report - org.kuali.student.lum.lu.assembly.CluSetManagementAssembler
 
Classes in this File Line Coverage Branch Coverage Complexity
CluSetManagementAssembler
0%
0/306
0%
0/154
4.815
 
 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.assembly;
 17  
 
 18  
 import java.util.ArrayList;
 19  
 import java.util.Iterator;
 20  
 import java.util.List;
 21  
 import java.util.Map.Entry;
 22  
 
 23  
 import org.apache.log4j.Logger;
 24  
 import org.kuali.rice.kim.bo.types.dto.AttributeSet;
 25  
 import org.kuali.student.common.assembly.data.AssemblyException;
 26  
 import org.kuali.student.common.assembly.data.Data;
 27  
 import org.kuali.student.common.assembly.data.Data.Property;
 28  
 import org.kuali.student.common.assembly.data.Metadata;
 29  
 import org.kuali.student.common.assembly.dictionary.MetadataServiceImpl;
 30  
 import org.kuali.student.common.assembly.old.BaseAssembler;
 31  
 import org.kuali.student.common.assembly.old.data.SaveResult;
 32  
 import org.kuali.student.common.dto.MetaInfo;
 33  
 import org.kuali.student.common.dto.RichTextInfo;
 34  
 import org.kuali.student.common.exceptions.DoesNotExistException;
 35  
 import org.kuali.student.common.exceptions.MissingParameterException;
 36  
 import org.kuali.student.common.search.dto.SearchRequest;
 37  
 import org.kuali.student.common.search.dto.SearchResult;
 38  
 import org.kuali.student.common.search.dto.SearchResultCell;
 39  
 import org.kuali.student.common.search.dto.SearchResultRow;
 40  
 import org.kuali.student.common.validation.dto.ValidationResultInfo;
 41  
 import org.kuali.student.common.validation.dto.ValidationResultInfo.ErrorLevel;
 42  
 import org.kuali.student.common.versionmanagement.dto.VersionDisplayInfo;
 43  
 import org.kuali.student.lum.common.client.lo.MetaInfoHelper;
 44  
 import org.kuali.student.lum.common.client.widgets.CluSetHelper;
 45  
 import org.kuali.student.lum.common.client.widgets.CluSetRangeHelper;
 46  
 import org.kuali.student.lum.common.client.widgets.CluSetRangeModelUtil;
 47  
 import org.kuali.student.lum.lu.dto.CluInfo;
 48  
 import org.kuali.student.lum.lu.dto.CluSetInfo;
 49  
 import org.kuali.student.lum.lu.dto.MembershipQueryInfo;
 50  
 import org.kuali.student.lum.lu.service.LuService;
 51  
 import org.kuali.student.lum.lu.service.LuServiceConstants;
 52  
 import org.springframework.transaction.annotation.Transactional;
 53  
 
 54  0
 @Transactional(readOnly=true,rollbackFor={Throwable.class})
 55  0
 public class CluSetManagementAssembler extends BaseAssembler<Data, Void> {
 56  
 //  TODO Split out CluInfo assembly to its own class
 57  
 
 58  0
     final Logger LOG = Logger.getLogger(CluSetManagementAssembler.class);
 59  
 
 60  
     public static final String JOINT_RELATION_TYPE = "kuali.lu.relation.type.co-located";
 61  
 // FIXME: should have it's own proposal types
 62  
     public static final String FORMAT_LU_TYPE = "kuali.lu.type.CreditCourseFormatShell";
 63  
 
 64  
     public static final String FORMAT_RELATION_TYPE = "luLuRelationType.hasCourseFormat";
 65  
     public static final String ACTIVITY_RELATION_TYPE = "luLuRelationType.contains";
 66  
 
 67  
     public static final String PROPOSAL_REFERENCE_TYPE = "kuali.proposal.referenceType.clu"; // <- what the service says, but the dictionary says: "kuali.referenceType.CLU";
 68  
 //    public static final String CREDIT_COURSE_PROPOSAL_DATA_TYPE = "CreditCourseProposal";
 69  
     public static final String CLUSET_DATA_TYPE = "cluset";
 70  
 
 71  
     private LuService luService;
 72  
     private MetadataServiceImpl metadataService;
 73  
 
 74  
     public MetadataServiceImpl getMetadataService() {
 75  0
         return metadataService;
 76  
     }
 77  
 
 78  
     public void setMetadataService(MetadataServiceImpl metadataService) {
 79  0
         this.metadataService = metadataService;
 80  0
     }
 81  
 
 82  
     @Override
 83  
     public Data get(String id) throws AssemblyException {
 84  
 
 85  0
         CluSetHelper resultCluSetHelper = null;
 86  0
         Data resultData = null;
 87  
 
 88  
         try {
 89  0
             CluSetInfo cluSetInfo = getCluSetInfo(id);
 90  0
             resultCluSetHelper = toCluSetHelper(cluSetInfo);
 91  0
             if (resultCluSetHelper == null) {
 92  0
                 resultData = null;
 93  
             } else {
 94  
 //                resultData = new Data();
 95  
 //                resultData.set("cluset", resultCluSetHelper.getData());
 96  0
                 resultData = resultCluSetHelper.getData();
 97  
             }
 98  0
         } catch (Exception e) {
 99  0
             throw new AssemblyException("Could not retrive cluSet with id " + id, e);
 100  0
         }
 101  
 
 102  0
         return resultData;
 103  
     }
 104  
     
 105  
     public CluSetInfo getCluSetInfo(String cluSetId) throws Exception {
 106  0
         List<String> cluIds = null;
 107  0
         CluSetInfo cluSetInfo = null;
 108  
         // note: the cluIds returned by luService.getCluSetInfo also contains the clus
 109  
         //       that are the result of query parameter search.  Set to null here and
 110  
         //       retrieve the clus that are direct members.
 111  0
         cluSetInfo = luService.getCluSetInfo(cluSetId);
 112  0
         cluSetInfo.setCluIds(null);
 113  0
         cluIds = luService.getCluIdsFromCluSet(cluSetId);
 114  0
         cluSetInfo.setCluIds(cluIds);
 115  0
         upWrap(cluSetInfo);
 116  0
         return cluSetInfo;
 117  
     }
 118  
 
 119  
     public MetaInfoHelper toMetaInfoHelper(MetaInfo metaInfo) {
 120  0
         MetaInfoHelper metaInfoHelper = null;
 121  0
         Data metaData = new Data();
 122  0
         if (metaInfo == null) return null;
 123  0
         metaInfoHelper = MetaInfoHelper.wrap(metaData);
 124  0
         metaInfoHelper.setCreateId(metaInfo.getCreateId());
 125  0
         metaInfoHelper.setCreateTime(metaInfo.getCreateTime());
 126  0
         metaInfoHelper.setUpdateId(metaInfo.getUpdateId());
 127  0
         metaInfoHelper.setUpdateTime(metaInfo.getUpdateTime());
 128  0
         metaInfoHelper.setVersionInd(metaInfo.getVersionInd());
 129  0
         return metaInfoHelper;
 130  
     }
 131  
 
 132  
     public MetaInfo toMetaInfo(MetaInfoHelper metaInfoHelper) {
 133  0
         MetaInfo metaInfo = null;
 134  0
         if (metaInfoHelper == null) return null;
 135  0
         metaInfo = new MetaInfo();
 136  0
         metaInfo.setCreateId(metaInfoHelper.getCreateId());
 137  0
         metaInfo.setCreateTime(metaInfoHelper.getCreateTime());
 138  0
         metaInfo.setUpdateId(metaInfoHelper.getUpdateId());
 139  0
         metaInfo.setUpdateTime(metaInfoHelper.getUpdateTime());
 140  0
         metaInfo.setVersionInd(metaInfoHelper.getVersionInd());
 141  0
         return metaInfo;
 142  
     }
 143  
 
 144  
     public String richTextToString(RichTextInfo richTextInfo) {
 145  0
         String result = null;
 146  0
         if (richTextInfo == null) return null;
 147  0
         result = richTextInfo.getPlain();
 148  0
         return result;
 149  
     }
 150  
 
 151  
     @Override
 152  
         @Transactional(readOnly=false,noRollbackFor={DoesNotExistException.class},rollbackFor={Throwable.class})
 153  
     public SaveResult<Data> save(Data input)     throws AssemblyException {
 154  
 
 155  
         try {
 156  0
             SaveResult<Data> result = new SaveResult<Data>();
 157  0
             List<ValidationResultInfo> validationResults = validate(input);
 158  0
             if (hasValidationErrors(validationResults)) {
 159  0
                 result.setValidationResults(validationResults);
 160  0
                 result.setValue(input);
 161  0
                 return result;
 162  
             }
 163  
 
 164  0
             SaveResult<Data> clusetResult = saveCluSet(input);
 165  0
             result.setValidationResults(clusetResult.getValidationResults());
 166  0
             result.setValue(clusetResult.getValue());
 167  0
             return result;
 168  0
         } catch (Exception e) {
 169  0
             throw new AssemblyException("Unable to save ....", e);
 170  
         }
 171  
     }
 172  
 
 173  
     private void upWrap(CluSetInfo cluSetInfo) throws AssemblyException {
 174  0
         List<String> cluSetIds = (cluSetInfo == null)? null : cluSetInfo.getCluSetIds();
 175  0
         List<String> unWrappedCluSetIds = null;
 176  0
         List<CluSetInfo> wrappedCluSets = null;
 177  0
         List<CluSetInfo> subCluSets = null;
 178  
 
 179  
         try {
 180  0
             if (cluSetIds != null && !cluSetIds.isEmpty()) {
 181  0
                 subCluSets = luService.getCluSetInfoByIdList(cluSetIds);
 182  
             }
 183  0
         } catch (Exception e) {
 184  0
             LOG.error(e.getMessage(), e);
 185  0
             throw new AssemblyException("Failed to retrieve the sub clusets of cluset " +
 186  
                     cluSetInfo.getId());
 187  0
         }
 188  
         // goes through the list of sub clusets and ignore the ones that are not reusable
 189  0
         if (subCluSets != null) {
 190  0
             for (CluSetInfo subCluSet : subCluSets) {
 191  0
                 if (subCluSet.getIsReusable()) {
 192  0
                     unWrappedCluSetIds = (unWrappedCluSetIds == null)?
 193  
                             new ArrayList<String>() : unWrappedCluSetIds;
 194  0
                             unWrappedCluSetIds.add(subCluSet.getId());
 195  
                 } else {
 196  0
                     wrappedCluSets = (wrappedCluSets == null)?
 197  
                             new ArrayList<CluSetInfo>() : wrappedCluSets;
 198  0
                             wrappedCluSets.add(subCluSet);
 199  
                 }
 200  
             }
 201  
         }
 202  0
         cluSetInfo.setCluSetIds(unWrappedCluSetIds);
 203  0
         if (wrappedCluSets != null) {
 204  0
             for (CluSetInfo wrappedCluSet : wrappedCluSets) {
 205  0
                 MembershipQueryInfo mqInfo = wrappedCluSet.getMembershipQuery();
 206  0
                 if (wrappedCluSet.getCluIds() != null && !wrappedCluSet.getCluIds().isEmpty()) {
 207  0
                     cluSetInfo.setCluIds(wrappedCluSet.getCluIds());
 208  
                 }
 209  0
                 if (mqInfo != null && mqInfo.getSearchTypeKey() != null && !mqInfo.getSearchTypeKey().isEmpty()) {
 210  0
                     cluSetInfo.setMembershipQuery(mqInfo);
 211  
                 }
 212  0
             }
 213  
         }
 214  0
     }
 215  
 
 216  
     private void wrap(CluSetInfo cluSetInfo) throws AssemblyException {
 217  0
         int numCluSetElementTypes = 0;
 218  0
         boolean hasCluIds = false;
 219  0
         boolean hasCluSetIds = false;
 220  0
         boolean hasMembershipQuery = false;
 221  0
         List<String> wrapperCluSetIds = new ArrayList<String>();
 222  0
         MembershipQueryInfo mqInfo = null;
 223  0
         if (cluSetInfo.getCluIds() != null && !cluSetInfo.getCluIds().isEmpty()) {
 224  0
             numCluSetElementTypes++;
 225  0
             hasCluIds = true;
 226  
         }
 227  0
         if (cluSetInfo.getCluSetIds() != null && !cluSetInfo.getCluSetIds().isEmpty()) {
 228  0
             numCluSetElementTypes++;
 229  0
             hasCluSetIds = true;
 230  
         }
 231  0
         mqInfo = cluSetInfo.getMembershipQuery();
 232  0
         if (mqInfo != null && mqInfo.getSearchTypeKey() != null && !mqInfo.getSearchTypeKey().isEmpty()) {
 233  0
             numCluSetElementTypes++;
 234  0
             hasMembershipQuery = true;
 235  
         }
 236  
         // if more than one type
 237  0
         if (numCluSetElementTypes > 1) {
 238  0
             if (hasCluIds) {
 239  0
                 CluSetInfo wrapperCluSet = new CluSetInfo();
 240  0
                 setWrapperCluSetInfoValues(wrapperCluSet, cluSetInfo);
 241  
                 // copy the clus into the wrapper CluSet
 242  0
                 wrapperCluSet.setCluIds(cluSetInfo.getCluIds());
 243  0
                 cluSetInfo.setCluIds(null);
 244  
                 try {
 245  0
                     if (wrapperCluSet.getType() == null) {
 246  0
                             wrapperCluSet.setType("kuali.cluSet.type.CreditCourse");
 247  
                     }
 248  0
                     wrapperCluSet = luService.createCluSet(wrapperCluSet.getType(), wrapperCluSet);
 249  0
                 } catch (Exception e) {
 250  0
                     LOG.error("Failed to create wrapper cluset",e);
 251  0
                     throw new AssemblyException(e);
 252  0
                 }
 253  0
                 wrapperCluSetIds.add(wrapperCluSet.getId());
 254  
             }
 255  0
             if (hasMembershipQuery) {
 256  0
                 CluSetInfo wrapperCluSet = new CluSetInfo();
 257  0
                 setWrapperCluSetInfoValues(wrapperCluSet, cluSetInfo);
 258  
                 // copy the MembershipQuery into the wrapper CluSet
 259  0
                 wrapperCluSet.setMembershipQuery(mqInfo);
 260  0
                 cluSetInfo.setMembershipQuery(null);
 261  
                 try {
 262  0
                     wrapperCluSet = luService.createCluSet(wrapperCluSet.getType(), wrapperCluSet);
 263  0
                 } catch (Exception e) {
 264  0
                     LOG.error("Failed to create wrapper cluset",e);
 265  0
                     throw new AssemblyException(e);
 266  0
                 }
 267  0
                 wrapperCluSetIds.add(wrapperCluSet.getId());
 268  
             }
 269  0
             if (hasCluSetIds) {
 270  0
                 wrapperCluSetIds.addAll(cluSetInfo.getCluSetIds());
 271  
             }
 272  0
             cluSetInfo.setCluSetIds(wrapperCluSetIds);
 273  
         }
 274  0
     }
 275  
 
 276  
     private void setWrapperCluSetInfoValues(CluSetInfo wrapperCluSet, CluSetInfo cluSetInfo) {
 277  0
         wrapperCluSet.setAdminOrg(cluSetInfo.getAdminOrg());
 278  0
         wrapperCluSet.setEffectiveDate(cluSetInfo.getEffectiveDate());
 279  0
         wrapperCluSet.setExpirationDate(cluSetInfo.getExpirationDate());
 280  0
         wrapperCluSet.setIsReusable(false);
 281  0
         wrapperCluSet.setIsReferenceable(false);
 282  0
         wrapperCluSet.setName(cluSetInfo.getName());
 283  0
         wrapperCluSet.setState(cluSetInfo.getState());
 284  0
         wrapperCluSet.setType(cluSetInfo.getType());
 285  0
     }
 286  
 
 287  
     private SaveResult<Data> saveCluSet(Data input) throws AssemblyException {
 288  0
         SaveResult<Data> result = new SaveResult<Data>();
 289  
 //        CluSetHelper cluSetHelper = new CluSetHelper((Data)input.get("cluset"));
 290  0
         List<ValidationResultInfo> saveValidationResults = null;
 291  0
         CluSetHelper cluSetHelper = new CluSetHelper(input);
 292  0
         CluSetInfo cluSetInfo = toCluSetInfo(cluSetHelper);
 293  0
         CluSetInfo updatedCluSetInfo = null;
 294  0
         CluSetHelper resultCluSetHelper = null;
 295  0
         Data resultData = null;
 296  0
         wrap(cluSetInfo);
 297  
         
 298  0
         if ((cluSetInfo.getCluIds() == null || cluSetInfo.getCluIds().isEmpty()) &&
 299  
                 (cluSetInfo.getCluSetIds() == null || cluSetInfo.getCluSetIds().isEmpty()) &&
 300  
                 (cluSetInfo.getMembershipQuery() == null)){
 301  0
             ValidationResultInfo cluSetCannotBeEmpty = new ValidationResultInfo();
 302  0
             saveValidationResults = (saveValidationResults == null)? new ArrayList<ValidationResultInfo>() :
 303  
                 saveValidationResults;
 304  0
             result.setValue(null);
 305  0
             cluSetCannotBeEmpty.setElement("");
 306  0
             cluSetCannotBeEmpty.setMessage("Clu set cannot be empty");
 307  0
             cluSetCannotBeEmpty.setError("Clu set cannot be empty");
 308  0
             cluSetCannotBeEmpty.setLevel(ErrorLevel.ERROR);
 309  0
             saveValidationResults.add(cluSetCannotBeEmpty);
 310  0
             result.setValidationResults(saveValidationResults);
 311  0
             return result;
 312  
         }
 313  
         
 314  0
         if (cluSetInfo.getId() != null && cluSetInfo.getId().trim().length() > 0) {
 315  
             try {
 316  0
                 updatedCluSetInfo = luService.updateCluSet(cluSetInfo.getId(), cluSetInfo);
 317  0
             } catch (Exception e) {
 318  0
                     LOG.error("Failed to update cluset",e);
 319  0
                 throw new AssemblyException(e);
 320  0
             }
 321  
         } else {
 322  
             try {
 323  0
                 if (cluSetInfo.getType() == null) {
 324  0
                     cluSetInfo.setType("kuali.cluSet.type.CreditCourse");
 325  
                 }
 326  0
                 updatedCluSetInfo = luService.createCluSet(cluSetInfo.getType(), cluSetInfo);
 327  0
             } catch (Exception e) {
 328  0
                 LOG.error("Failed to create cluset",e);
 329  0
                 throw new AssemblyException(e);
 330  0
             }
 331  
         }
 332  
         try {
 333  0
             resultCluSetHelper = toCluSetHelper(updatedCluSetInfo);
 334  0
         } catch (Exception e) {
 335  0
             throw new AssemblyException(e);
 336  0
         }
 337  0
         if (resultCluSetHelper == null) {
 338  0
             resultData = null;
 339  
         } else {
 340  
 //            resultData = new Data();
 341  
 //            resultData.set("cluset", resultCluSetHelper.getData());
 342  0
             resultData = resultCluSetHelper.getData();
 343  
         }
 344  0
         result.setValue(resultData);
 345  0
         return result;
 346  
     }
 347  
 
 348  
     private List<String> getMembershipQuerySearchResult(MembershipQueryInfo query) throws MissingParameterException {
 349  0
         if(query == null) {
 350  0
             return null;
 351  
         }
 352  0
         SearchRequest sr = new SearchRequest();
 353  0
         sr.setSearchKey(query.getSearchTypeKey());
 354  0
         sr.setParams(query.getQueryParamValueList());
 355  
 
 356  0
         SearchResult result = luService.search(sr);
 357  
 
 358  0
         List<String> cluIds = new ArrayList<String>();
 359  0
         List<SearchResultRow> rows = result.getRows();
 360  0
         for(SearchResultRow row : rows) {
 361  0
             List<SearchResultCell> cells = row.getCells();
 362  0
             for(SearchResultCell cell : cells) {
 363  0
                 if(cell.getKey().equals("lu.resultColumn.cluId")) {
 364  0
                     cluIds.add(cell.getValue());
 365  
                 }
 366  
             }
 367  0
         }
 368  0
         return cluIds;
 369  
     }
 370  
 
 371  
     private CluSetHelper toCluSetHelper(CluSetInfo cluSetInfo) throws Exception {
 372  0
         Data data = new Data();
 373  0
         Data cluSetDetailData = new Data();
 374  0
         data.set("cluset", cluSetDetailData);
 375  0
         CluSetHelper result = CluSetHelper.wrap(cluSetDetailData);
 376  0
         if (cluSetInfo != null) {
 377  0
             if (cluSetInfo.getCluIds() != null && !cluSetInfo.getCluIds().isEmpty()) {
 378  0
                     List<CluInfo> cluInfos = new ArrayList<CluInfo>();
 379  0
                     for(String id:cluSetInfo.getCluIds()){
 380  0
                             VersionDisplayInfo versionInfo = luService.getCurrentVersion(LuServiceConstants.CLU_NAMESPACE_URI, id);
 381  0
                             cluInfos.add(luService.getClu(versionInfo.getId()));
 382  0
                     }
 383  0
                 result.setApprovedClus(new Data());
 384  0
                 for (CluInfo cluInfo : cluInfos) {
 385  0
                     if (cluInfo.getState().equals("Active")) {
 386  0
                         result.getApprovedClus().add(cluInfo.getVersionInfo().getVersionIndId());
 387  
                     } else {
 388  0
                         result.getProposedClus().add(cluInfo.getVersionInfo().getVersionIndId());
 389  
                     }
 390  0
                     result.getAllClus().add(cluInfo.getVersionInfo().getVersionIndId());
 391  
                 }
 392  
             }
 393  0
             if (cluSetInfo.getCluSetIds() != null && !cluSetInfo.getCluSetIds().isEmpty()) {
 394  0
                 result.setCluSets(new Data());
 395  0
                 for (String cluSetId : cluSetInfo.getCluSetIds()) {
 396  0
                     result.getCluSets().add(cluSetId);
 397  
                 }
 398  
             }
 399  0
             if (cluSetInfo.getMembershipQuery() != null) {
 400  0
                 MembershipQueryInfo mq = cluSetInfo.getMembershipQuery();
 401  0
                 List<String> cluRangeCluIds = getMembershipQuerySearchResult(mq);
 402  0
                 if (cluRangeCluIds != null) {
 403  0
                     result.setCluRangeViewDetails(new Data());
 404  0
                     for (String cluRangeCluId : cluRangeCluIds) {
 405  0
                         result.getCluRangeViewDetails().add(cluRangeCluId);
 406  
                     }
 407  
                 }
 408  
             }
 409  0
             result.setDescription(richTextToString(cluSetInfo.getDescr()));
 410  0
             result.setEffectiveDate(cluSetInfo.getEffectiveDate());
 411  0
             result.setExpirationDate(cluSetInfo.getExpirationDate());
 412  0
             result.setId(cluSetInfo.getId());
 413  0
             result.setMetaInfo(toMetaInfoHelper(cluSetInfo.getMetaInfo()));
 414  0
             result.setName(cluSetInfo.getName());
 415  0
             result.setOrganization(cluSetInfo.getAdminOrg());
 416  0
             result.setState(cluSetInfo.getState());
 417  0
             result.setType(cluSetInfo.getType());
 418  0
             result.setCluRangeParams(CluSetRangeModelUtil.INSTANCE.toData(
 419  
                     cluSetInfo.getMembershipQuery()));
 420  
             
 421  
             //Add all dynamic attributes
 422  0
             for(Entry<String,String> entry:cluSetInfo.getAttributes().entrySet()){
 423  0
                     result.getData().set(entry.getKey(), entry.getValue());
 424  
             }
 425  
         }
 426  0
         return result;
 427  
     }
 428  
 
 429  
     private void addToCluIds(Data clusData, final List<String> cluIds) {
 430  0
         if (clusData != null) {
 431  0
             for (Data.Property p : clusData) {
 432  0
                 if(!"_runtimeData".equals(p.getKey())){
 433  0
                     String cluId = p.getValue();
 434  0
                     cluIds.add(cluId);
 435  0
                 }
 436  
             }
 437  
         }
 438  0
     }
 439  
 
 440  
     private CluSetInfo toCluSetInfo(CluSetHelper cluSetHelper) {
 441  0
         CluSetInfo cluSetInfo = new CluSetInfo();
 442  0
         Data approvedClusData = cluSetHelper.getApprovedClus();
 443  0
         Data proposedClusData = cluSetHelper.getProposedClus();
 444  0
         Data cluSetsData = cluSetHelper.getCluSets();
 445  0
         final List<String> cluIds = new ArrayList<String>();
 446  0
         List<String> cluSetIds = null;
 447  
 
 448  0
         cluSetInfo.setId(cluSetHelper.getId());
 449  0
         if (approvedClusData != null) {
 450  0
             addToCluIds(approvedClusData, cluIds);
 451  
         }
 452  0
         if (proposedClusData != null) {
 453  0
             addToCluIds(proposedClusData, cluIds);
 454  
         }
 455  0
         if (cluIds != null && !cluIds.isEmpty()) {
 456  0
             cluSetInfo.setCluIds(cluIds);
 457  
         }
 458  0
         if (cluSetsData != null) {
 459  0
             for (Data.Property p : cluSetsData) {
 460  0
                 if(!"_runtimeData".equals(p.getKey())){
 461  0
                     String cluSetId = p.getValue();
 462  0
                     cluSetIds = (cluSetIds == null)? new ArrayList<String>(3) :
 463  
                         cluSetIds;
 464  0
                     cluSetIds.add(cluSetId);
 465  0
                 }
 466  
             }
 467  
         }
 468  0
         if (cluSetIds != null) {
 469  0
             cluSetInfo.setCluSetIds(cluSetIds);
 470  
         }
 471  0
         cluSetInfo.setAdminOrg(cluSetHelper.getOrganization());
 472  0
         cluSetInfo.setDescr(toRichTextInfo(cluSetHelper.getDescription()));
 473  0
         cluSetInfo.setEffectiveDate(cluSetHelper.getEffectiveDate());
 474  0
         cluSetInfo.setExpirationDate(cluSetHelper.getExpirationDate());
 475  0
         cluSetInfo.setMembershipQuery(toMembershipQueryInfo(cluSetHelper.getCluRangeParams()));
 476  
 
 477  0
         cluSetInfo.setMetaInfo(toMetaInfo(cluSetHelper.getMetaInfo()));
 478  0
         cluSetInfo.setName(cluSetHelper.getName());
 479  0
         cluSetInfo.setState(cluSetHelper.getState());
 480  0
         if (cluSetInfo.getState() == null) {
 481  0
             cluSetInfo.setState("Active");
 482  
         }
 483  0
         cluSetInfo.setType(cluSetHelper.getType());
 484  0
         cluSetInfo.setIsReusable(cluSetHelper.getReusable());
 485  0
         cluSetInfo.setIsReferenceable(cluSetHelper.getReferenceable());
 486  
         
 487  
         //Put in any additional properties
 488  0
         for(Iterator<Property> iter=cluSetHelper.getData().realPropertyIterator();iter.hasNext();){
 489  0
                 Property property = iter.next();
 490  0
                 if(property.getValue()!=null && !(property.getValue() instanceof Data ) && !CluSetHelper.getProperties().contains((String)property.getKey())){
 491  
                         //Add this as a dynamic attribute
 492  0
                         cluSetInfo.getAttributes().put((String)property.getKey(), property.getValue().toString());
 493  
                 }
 494  0
         }
 495  
         
 496  0
         return cluSetInfo;
 497  
     }
 498  
 
 499  
     private MembershipQueryInfo toMembershipQueryInfo(CluSetRangeHelper cluSetRangeHelper) {
 500  0
         return CluSetRangeModelUtil.INSTANCE.toMembershipQueryInfo(cluSetRangeHelper.getData());
 501  
     }
 502  
 
 503  
     private RichTextInfo toRichTextInfo(String text) {
 504  0
         RichTextInfo result = new RichTextInfo();
 505  0
         if (text == null) return null;
 506  0
         result.setPlain(text);
 507  0
         result.setFormatted(text);
 508  0
         return result;
 509  
     }
 510  
 
 511  
     @Override
 512  
     public Data assemble(Void input) throws AssemblyException {
 513  0
         throw new UnsupportedOperationException("Data assembly not supported");
 514  
     }
 515  
 
 516  
     @Override
 517  
     public Void disassemble(Data input) throws AssemblyException {
 518  0
         throw new UnsupportedOperationException("Data disassembly not supported");
 519  
     }
 520  
 
 521  
     public LuService getLuService() {
 522  0
         return luService;
 523  
     }
 524  
 
 525  
     public void setLuService(LuService luService) {
 526  0
         this.luService = luService;
 527  0
     }
 528  
 
 529  
         @Override
 530  
         protected String getDataType() {
 531  0
                 return CLUSET_DATA_TYPE;
 532  
         }
 533  
         
 534  
         @Override
 535  
     public Metadata getDefaultMetadata() {
 536  
         // TODO Auto-generated method stub
 537  0
         return metadataService.getMetadata(getDataType());
 538  
     }
 539  
 
 540  
     @Override
 541  
         protected String getDocumentPropertyName() {
 542  0
         return "course";                                                        //FIXME
 543  
         }
 544  
 
 545  
         @Override
 546  
         protected String getDtoName() {
 547  0
         return "kuali.lu.type.CreditCourse";                //FIXME
 548  
         }
 549  
 
 550  
         @Override
 551  
         protected AttributeSet getQualification(String idType, String id) {   //FIXME
 552  0
                 String DOCUMENT_TYPE_NAME = "documentTypeName";
 553  0
                 AttributeSet qualification = new AttributeSet();
 554  0
                 qualification.put(DOCUMENT_TYPE_NAME, "CluCreditCourse");
 555  
                 /*
 556  
                  *        This commented out for permission changes
 557  
                  *
 558  
                  *         String QUALIFICATION_PROPOSAL_ID = "courseId";
 559  
                  *         qualification.put(QUALIFICATION_PROPOSAL_ID, id);
 560  
                  */
 561  0
                 qualification.put(idType, id);
 562  0
                 return qualification;
 563  
         }
 564  
 
 565  
 }