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