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