| 1 | |
package org.kuali.student.enrollment.class2.courseoffering.service.transformer; |
| 2 | |
|
| 3 | |
import org.kuali.student.enrollment.courseoffering.dto.CourseOfferingInfo; |
| 4 | |
import org.kuali.student.enrollment.courseoffering.dto.OfferingInstructorInfo; |
| 5 | |
import org.kuali.student.enrollment.courseoffering.service.R1ToR2CopyHelper; |
| 6 | |
import org.kuali.student.enrollment.lpr.dto.LuiPersonRelationInfo; |
| 7 | |
import org.kuali.student.enrollment.lpr.service.LuiPersonRelationService; |
| 8 | |
import org.kuali.student.enrollment.lui.dto.LuiIdentifierInfo; |
| 9 | |
import org.kuali.student.enrollment.lui.dto.LuiInfo; |
| 10 | |
import org.kuali.student.lum.course.dto.CourseInfo; |
| 11 | |
import org.kuali.student.lum.lrc.dto.ResultComponentInfo; |
| 12 | |
import org.kuali.student.r2.common.dto.AttributeInfo; |
| 13 | |
import org.kuali.student.r2.common.dto.ContextInfo; |
| 14 | |
import org.kuali.student.r2.common.exceptions.OperationFailedException; |
| 15 | |
import org.kuali.student.r2.common.infc.Attribute; |
| 16 | |
import org.kuali.student.r2.common.util.constants.CourseOfferingServiceConstants; |
| 17 | |
import org.kuali.student.r2.common.util.constants.CourseOfferingSetServiceConstants; |
| 18 | |
import org.kuali.student.r2.common.util.constants.LuiPersonRelationServiceConstants; |
| 19 | |
import org.kuali.student.r2.common.util.constants.LuiServiceConstants; |
| 20 | |
import org.kuali.student.r2.lum.clu.dto.LuCodeInfo; |
| 21 | |
|
| 22 | |
import java.util.ArrayList; |
| 23 | |
import java.util.List; |
| 24 | |
|
| 25 | 0 | public class CourseOfferingTransformer { |
| 26 | |
|
| 27 | |
public void lui2CourseOffering(LuiInfo lui, CourseOfferingInfo co, ContextInfo context) { |
| 28 | 0 | co.setId(lui.getId()); |
| 29 | 0 | co.setTypeKey(lui.getTypeKey()); |
| 30 | 0 | co.setStateKey(lui.getStateKey()); |
| 31 | 0 | co.setDescr(lui.getDescr()); |
| 32 | 0 | co.setMeta(lui.getMeta()); |
| 33 | 0 | co.setCourseOfferingURL(lui.getReferenceURL()); |
| 34 | |
|
| 35 | |
|
| 36 | 0 | List<AttributeInfo> attributes = co.getAttributes(); |
| 37 | 0 | for (Attribute attr : lui.getAttributes()) { |
| 38 | 0 | if (CourseOfferingServiceConstants.WAIT_LIST_LEVEL_TYPE_KEY_ATTR.equals(attr.getKey())){ |
| 39 | 0 | co.setWaitlistLevelTypeKey(attr.getValue()); |
| 40 | 0 | } else if (CourseOfferingServiceConstants.WAIT_LIST_INDICATOR_ATTR.equals((attr.getKey()))){ |
| 41 | 0 | co.setHasWaitlist(Boolean.valueOf(attr.getValue())); |
| 42 | 0 | } else if (CourseOfferingServiceConstants.FINAL_EXAM_INDICATOR_ATTR.equals(attr.getKey())){ |
| 43 | 0 | co.setFinalExamType(attr.getValue()); |
| 44 | 0 | } else if(CourseOfferingServiceConstants.COURSE_EVALUATION_INDICATOR_ATTR.equals(attr.getKey())){ |
| 45 | 0 | co.setEvaluated(Boolean.valueOf(attr.getValue())); |
| 46 | 0 | } else if (CourseOfferingServiceConstants.WHERE_FEES_ATTACHED_FLAG_ATTR.equals(attr.getKey())){ |
| 47 | 0 | co.setFeeAtActivityOffering(Boolean.valueOf(attr.getValue())); |
| 48 | 0 | } else if (CourseOfferingServiceConstants.FUNDING_SOURCE_ATTR.equals(attr.getKey())){ |
| 49 | 0 | co.setFundingSource(attr.getValue()); |
| 50 | |
} else { |
| 51 | 0 | attributes.add(new AttributeInfo(attr)); |
| 52 | |
} |
| 53 | |
} |
| 54 | 0 | co.setAttributes(attributes); |
| 55 | |
|
| 56 | |
|
| 57 | 0 | co.setMaximumEnrollment(lui.getMaximumEnrollment()); |
| 58 | 0 | co.setMinimumEnrollment(lui.getMinimumEnrollment()); |
| 59 | |
|
| 60 | 0 | co.setCourseId(lui.getCluId()); |
| 61 | 0 | co.setTermId(lui.getAtpId()); |
| 62 | 0 | co.setUnitsDeployment(lui.getUnitsDeployment()); |
| 63 | 0 | co.setUnitsContentOwner(lui.getUnitsContentOwner()); |
| 64 | |
|
| 65 | 0 | co.setGradingOptionIds(lui.getResultValuesGroupKeys()); |
| 66 | |
|
| 67 | 0 | LuiIdentifierInfo identifier = lui.getOfficialIdentifier(); |
| 68 | 0 | if (identifier == null) { |
| 69 | 0 | co.setCourseOfferingCode(null); |
| 70 | 0 | co.setCourseNumberSuffix(null); |
| 71 | 0 | co.setCourseOfferingTitle(null); |
| 72 | 0 | co.setSubjectArea(null); |
| 73 | |
} else { |
| 74 | 0 | co.setCourseOfferingCode(identifier.getCode()); |
| 75 | 0 | co.setCourseNumberSuffix(identifier.getSuffixCode()); |
| 76 | 0 | co.setCourseOfferingTitle(identifier.getLongName()); |
| 77 | 0 | co.setSubjectArea(identifier.getDivision()); |
| 78 | |
} |
| 79 | |
|
| 80 | |
|
| 81 | 0 | LuCodeInfo luCode = this.findLuCode(lui, LuiServiceConstants.HONORS_LU_CODE); |
| 82 | 0 | if (luCode == null) { |
| 83 | 0 | co.setIsHonorsOffering(false); |
| 84 | |
} else { |
| 85 | 0 | co.setIsHonorsOffering(string2Boolean(luCode.getValue())); |
| 86 | |
} |
| 87 | |
|
| 88 | |
|
| 89 | |
|
| 90 | |
|
| 91 | |
|
| 92 | |
|
| 93 | |
|
| 94 | |
|
| 95 | |
|
| 96 | |
|
| 97 | |
|
| 98 | |
|
| 99 | |
|
| 100 | |
|
| 101 | 0 | return; |
| 102 | |
} |
| 103 | |
|
| 104 | |
private String boolean2String(Boolean bval) { |
| 105 | 0 | if (bval == null) { |
| 106 | 0 | return null; |
| 107 | |
} |
| 108 | 0 | return bval.toString(); |
| 109 | |
} |
| 110 | |
|
| 111 | |
private Boolean string2Boolean(String sval) { |
| 112 | 0 | if (sval == null) { |
| 113 | 0 | return null; |
| 114 | |
} |
| 115 | 0 | return Boolean.parseBoolean(sval.toString()); |
| 116 | |
} |
| 117 | |
|
| 118 | |
private LuCodeInfo findLuCode(LuiInfo lui, String typeKey) { |
| 119 | 0 | for (LuCodeInfo info : lui.getLuiCodes()) { |
| 120 | 0 | if (info.getTypeKey().equals(typeKey)) { |
| 121 | 0 | return info; |
| 122 | |
} |
| 123 | |
} |
| 124 | 0 | return null; |
| 125 | |
} |
| 126 | |
|
| 127 | |
private LuCodeInfo findAddLuCode(LuiInfo lui, String typeKey) { |
| 128 | 0 | LuCodeInfo info = this.findLuCode(lui, typeKey); |
| 129 | 0 | if (info != null) { |
| 130 | 0 | return info; |
| 131 | |
} |
| 132 | 0 | info = new LuCodeInfo(); |
| 133 | 0 | info.setTypeKey(typeKey); |
| 134 | 0 | lui.getLuiCodes().add(info); |
| 135 | 0 | return info; |
| 136 | |
} |
| 137 | |
|
| 138 | |
public void courseOffering2Lui(CourseOfferingInfo co, LuiInfo lui, ContextInfo context) { |
| 139 | 0 | lui.setId(co.getId()); |
| 140 | 0 | lui.setTypeKey(co.getTypeKey()); |
| 141 | 0 | lui.setStateKey(co.getStateKey()); |
| 142 | 0 | lui.setDescr(co.getDescr()); |
| 143 | 0 | lui.setMeta(co.getMeta()); |
| 144 | 0 | lui.setReferenceURL(co.getCourseOfferingURL()); |
| 145 | |
|
| 146 | |
|
| 147 | 0 | List<AttributeInfo> attributes = lui.getAttributes(); |
| 148 | 0 | for (Attribute attr : co.getAttributes()) { |
| 149 | 0 | attributes.add(new AttributeInfo(attr)); |
| 150 | |
} |
| 151 | |
|
| 152 | 0 | AttributeInfo waitlistLevelTypeKey = new AttributeInfo(); |
| 153 | 0 | waitlistLevelTypeKey.setKey(CourseOfferingServiceConstants.WAIT_LIST_LEVEL_TYPE_KEY_ATTR); |
| 154 | 0 | waitlistLevelTypeKey.setValue(String.valueOf(co.getWaitlistLevelTypeKey())); |
| 155 | 0 | attributes.add(waitlistLevelTypeKey); |
| 156 | |
|
| 157 | 0 | AttributeInfo waitlistIndicator = new AttributeInfo(); |
| 158 | 0 | waitlistIndicator.setKey(CourseOfferingServiceConstants.WAIT_LIST_INDICATOR_ATTR); |
| 159 | 0 | waitlistIndicator.setValue(String.valueOf(co.getHasWaitlist())); |
| 160 | 0 | attributes.add(waitlistIndicator); |
| 161 | |
|
| 162 | 0 | AttributeInfo finalExamIndicator = new AttributeInfo(); |
| 163 | 0 | finalExamIndicator.setKey(CourseOfferingServiceConstants.FINAL_EXAM_INDICATOR_ATTR); |
| 164 | 0 | finalExamIndicator.setValue(co.getFinalExamType()); |
| 165 | 0 | attributes.add(finalExamIndicator); |
| 166 | |
|
| 167 | 0 | AttributeInfo courseEvaluationIndicator = new AttributeInfo(); |
| 168 | 0 | courseEvaluationIndicator.setKey(CourseOfferingServiceConstants.COURSE_EVALUATION_INDICATOR_ATTR); |
| 169 | 0 | courseEvaluationIndicator.setValue(String.valueOf(co.getIsEvaluated())); |
| 170 | 0 | attributes.add(courseEvaluationIndicator); |
| 171 | |
|
| 172 | 0 | AttributeInfo whereFeesAttachedFlag = new AttributeInfo(); |
| 173 | 0 | whereFeesAttachedFlag.setKey(CourseOfferingServiceConstants.WHERE_FEES_ATTACHED_FLAG_ATTR); |
| 174 | 0 | whereFeesAttachedFlag.setValue(String.valueOf(co.getIsFeeAtActivityOffering())); |
| 175 | 0 | attributes.add(whereFeesAttachedFlag); |
| 176 | |
|
| 177 | 0 | AttributeInfo fundingSource = new AttributeInfo(); |
| 178 | 0 | fundingSource.setKey(CourseOfferingServiceConstants.FUNDING_SOURCE_ATTR); |
| 179 | 0 | fundingSource.setValue(co.getFundingSource()); |
| 180 | 0 | attributes.add(fundingSource); |
| 181 | |
|
| 182 | 0 | lui.setAttributes(attributes); |
| 183 | |
|
| 184 | |
|
| 185 | 0 | lui.setCluId(co.getCourseId()); |
| 186 | 0 | lui.setAtpId(co.getTermId()); |
| 187 | 0 | lui.setUnitsContentOwner(co.getUnitsContentOwnerOrgIds()); |
| 188 | 0 | lui.setUnitsDeployment(co.getUnitsDeploymentOrgIds()); |
| 189 | 0 | lui.setMaximumEnrollment(co.getMaximumEnrollment()); |
| 190 | 0 | lui.setMinimumEnrollment(co.getMinimumEnrollment()); |
| 191 | 0 | lui.setResultValuesGroupKeys(co.getGradingOptionIds()); |
| 192 | |
|
| 193 | 0 | LuiIdentifierInfo oi = lui.getOfficialIdentifier(); |
| 194 | 0 | if (oi == null) { |
| 195 | 0 | oi = new LuiIdentifierInfo(); |
| 196 | 0 | lui.setOfficialIdentifier(oi); |
| 197 | 0 | oi.setStateKey(LuiServiceConstants.LUI_IDENTIFIER_ACTIVE_STATE_KEY); |
| 198 | 0 | oi.setTypeKey(LuiServiceConstants.LUI_IDENTIFIER_OFFICIAL_TYPE_KEY); |
| 199 | |
} |
| 200 | 0 | oi.setCode(co.getCourseOfferingCode()); |
| 201 | 0 | oi.setSuffixCode(co.getCourseNumberSuffix()); |
| 202 | 0 | oi.setLongName(co.getCourseOfferingTitle()); |
| 203 | 0 | oi.setDivision(co.getSubjectArea()); |
| 204 | |
|
| 205 | 0 | LuCodeInfo luCode = this.findAddLuCode(lui, LuiServiceConstants.HONORS_LU_CODE); |
| 206 | 0 | luCode.setValue(boolean2String(co.getIsHonorsOffering())); |
| 207 | |
|
| 208 | |
|
| 209 | |
|
| 210 | |
|
| 211 | |
|
| 212 | |
|
| 213 | |
|
| 214 | |
|
| 215 | |
|
| 216 | |
|
| 217 | |
|
| 218 | |
|
| 219 | |
|
| 220 | |
|
| 221 | 0 | } |
| 222 | |
|
| 223 | |
public void copyFromCanonical(CourseInfo courseInfo, CourseOfferingInfo courseOfferingInfo, List<String> optionKeys) { |
| 224 | 0 | courseOfferingInfo.setCourseId(courseInfo.getId()); |
| 225 | 0 | courseOfferingInfo.setCourseNumberSuffix(courseInfo.getCourseNumberSuffix()); |
| 226 | 0 | if (!optionKeys.contains(CourseOfferingSetServiceConstants.NOT_COURSE_TITLE_OPTION_KEY)) { |
| 227 | 0 | courseOfferingInfo.setCourseOfferingTitle(courseInfo.getCourseTitle()); |
| 228 | |
} |
| 229 | 0 | courseOfferingInfo.setSubjectArea(courseInfo.getSubjectArea()); |
| 230 | 0 | courseOfferingInfo.setCourseOfferingCode(courseInfo.getCode()); |
| 231 | 0 | courseOfferingInfo.setUnitsContentOwner(courseInfo.getUnitsContentOwner()); |
| 232 | 0 | courseOfferingInfo.setUnitsDeployment(courseInfo.getUnitsDeployment()); |
| 233 | 0 | courseOfferingInfo.setGradingOptionIds(courseInfo.getGradingOptions()); |
| 234 | 0 | if (courseInfo.getCreditOptions() == null) { |
| 235 | 0 | courseOfferingInfo.setCreditOptionIds(null); |
| 236 | 0 | } else if (courseInfo.getCreditOptions().isEmpty()) { |
| 237 | 0 | courseOfferingInfo.setCreditOptionIds(null); |
| 238 | |
} else { |
| 239 | 0 | List<String> creditOptionIds = new ArrayList<String>(); |
| 240 | 0 | for( ResultComponentInfo creditOption: courseInfo.getCreditOptions()){ |
| 241 | 0 | creditOptionIds.add(creditOption.getId()); |
| 242 | |
|
| 243 | |
} |
| 244 | |
|
| 245 | 0 | courseOfferingInfo.setCreditOptionIds(creditOptionIds); |
| 246 | |
|
| 247 | |
} |
| 248 | 0 | courseOfferingInfo.setDescr(new R1ToR2CopyHelper().copyRichText(courseInfo.getDescr())); |
| 249 | 0 | courseOfferingInfo.setInstructors(new R1ToR2CopyHelper().copyInstructors(courseInfo.getInstructors())); |
| 250 | 0 | } |
| 251 | |
|
| 252 | |
|
| 253 | |
public void assembleInstructors(CourseOfferingInfo co, String luiId, ContextInfo context, LuiPersonRelationService lprService) |
| 254 | |
throws OperationFailedException { |
| 255 | 0 | List<LuiPersonRelationInfo> lprs = null;; |
| 256 | |
try { |
| 257 | 0 | lprs = lprService.getLprsByLui(luiId, context); |
| 258 | 0 | } catch (Exception e) { |
| 259 | 0 | throw new OperationFailedException("DoesNotExistException: " + e.getMessage()); |
| 260 | 0 | } |
| 261 | |
|
| 262 | 0 | for (LuiPersonRelationInfo lpr : lprs) { |
| 263 | 0 | if (lpr.getTypeKey().equals(LuiPersonRelationServiceConstants.INSTRUCTOR_MAIN_TYPE_KEY)) { |
| 264 | 0 | OfferingInstructorInfo instructor = new OfferingInstructorInfo(); |
| 265 | 0 | instructor.setPersonId(lpr.getPersonId()); |
| 266 | 0 | instructor.setPercentageEffort(lpr.getCommitmentPercent()); |
| 267 | 0 | instructor.setId(lpr.getId()); |
| 268 | 0 | instructor.setTypeKey(lpr.getTypeKey()); |
| 269 | 0 | instructor.setStateKey(lpr.getStateKey()); |
| 270 | 0 | co.getInstructors().add(instructor); |
| 271 | 0 | } |
| 272 | |
} |
| 273 | 0 | } |
| 274 | |
} |