| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
package org.kuali.student.lum.program.service.assembler; |
| 17 | |
|
| 18 | |
import java.util.List; |
| 19 | |
|
| 20 | |
import org.apache.log4j.Logger; |
| 21 | |
import org.kuali.student.common.assembly.BOAssembler; |
| 22 | |
import org.kuali.student.common.assembly.BaseDTOAssemblyNode; |
| 23 | |
import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation; |
| 24 | |
import org.kuali.student.common.assembly.data.AssemblyException; |
| 25 | |
import org.kuali.student.common.exceptions.DoesNotExistException; |
| 26 | |
import org.kuali.student.lum.course.service.assembler.CourseAssembler; |
| 27 | |
import org.kuali.student.lum.lu.dto.CluInfo; |
| 28 | |
import org.kuali.student.lum.lu.service.LuService; |
| 29 | |
import org.kuali.student.lum.program.dto.CoreProgramInfo; |
| 30 | |
import org.kuali.student.lum.service.assembler.CluAssemblerUtils; |
| 31 | |
|
| 32 | |
|
| 33 | |
|
| 34 | |
|
| 35 | |
|
| 36 | 0 | public class CoreProgramAssembler implements BOAssembler<CoreProgramInfo, CluInfo> { |
| 37 | 0 | final static Logger LOG = Logger.getLogger(CourseAssembler.class); |
| 38 | |
|
| 39 | |
private LuService luService; |
| 40 | |
private ProgramAssemblerUtils programAssemblerUtils; |
| 41 | |
private CluAssemblerUtils cluAssemblerUtils; |
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
@Override |
| 46 | |
public CoreProgramInfo assemble(CluInfo clu, CoreProgramInfo coreProgram, boolean shallowBuild) throws AssemblyException { |
| 47 | |
|
| 48 | 0 | CoreProgramInfo cpInfo = (null != coreProgram) ? coreProgram : new CoreProgramInfo(); |
| 49 | |
|
| 50 | |
|
| 51 | 0 | programAssemblerUtils.assembleBasics(clu, cpInfo); |
| 52 | 0 | programAssemblerUtils.assembleIdentifiers(clu, cpInfo); |
| 53 | 0 | programAssemblerUtils.assembleBasicAdminOrgs(clu, cpInfo); |
| 54 | 0 | programAssemblerUtils.assembleAtps(clu, cpInfo); |
| 55 | 0 | programAssemblerUtils.assembleLuCodes(clu, cpInfo); |
| 56 | 0 | programAssemblerUtils.assemblePublications(clu, cpInfo); |
| 57 | |
|
| 58 | 0 | cpInfo.setDescr(clu.getDescr()); |
| 59 | 0 | cpInfo.setVersionInfo(clu.getVersionInfo()); |
| 60 | |
|
| 61 | 0 | if (!shallowBuild) { |
| 62 | 0 | programAssemblerUtils.assembleRequirements(clu, cpInfo); |
| 63 | 0 | cpInfo.setLearningObjectives(cluAssemblerUtils.assembleLos(clu.getId(), shallowBuild)); |
| 64 | |
} |
| 65 | |
|
| 66 | 0 | return cpInfo; |
| 67 | |
} |
| 68 | |
|
| 69 | |
@Override |
| 70 | |
public BaseDTOAssemblyNode<CoreProgramInfo, CluInfo> disassemble(CoreProgramInfo core, NodeOperation operation) throws AssemblyException { |
| 71 | 0 | BaseDTOAssemblyNode<CoreProgramInfo, CluInfo> result = new BaseDTOAssemblyNode<CoreProgramInfo, CluInfo>(this); |
| 72 | |
|
| 73 | 0 | if (core == null) { |
| 74 | |
|
| 75 | |
|
| 76 | 0 | LOG.error("CoreProgram to disassemble is null!"); |
| 77 | 0 | throw new AssemblyException("CoreProgram can not be null"); |
| 78 | |
} |
| 79 | |
|
| 80 | |
CluInfo clu; |
| 81 | |
try { |
| 82 | 0 | clu = (NodeOperation.UPDATE == operation) ? luService.getClu(core.getId()) : new CluInfo(); |
| 83 | 0 | } catch (Exception e) { |
| 84 | 0 | throw new AssemblyException("Error getting existing learning unit during CoreProgram update", e); |
| 85 | 0 | } |
| 86 | |
|
| 87 | 0 | boolean stateChanged = NodeOperation.UPDATE == operation && core.getState() != null && !core.getState().equals(core.getState()); |
| 88 | |
|
| 89 | 0 | programAssemblerUtils.disassembleBasics(clu, core); |
| 90 | 0 | if (core.getId() == null) |
| 91 | 0 | core.setId(clu.getId()); |
| 92 | 0 | programAssemblerUtils.disassembleIdentifiers(clu, core, operation); |
| 93 | 0 | programAssemblerUtils.disassembleAdminOrgs(clu, core, operation); |
| 94 | 0 | programAssemblerUtils.disassembleAtps(clu, core, operation); |
| 95 | 0 | programAssemblerUtils.disassembleLuCodes(clu, core, operation); |
| 96 | 0 | programAssemblerUtils.disassemblePublications(clu, core, operation, result); |
| 97 | |
|
| 98 | 0 | if(core.getProgramRequirements() != null && !core.getProgramRequirements().isEmpty()) { |
| 99 | 0 | programAssemblerUtils.disassembleRequirements(clu, core, operation, result, stateChanged); |
| 100 | |
} |
| 101 | |
|
| 102 | 0 | if (core.getLearningObjectives() != null) { |
| 103 | 0 | disassembleLearningObjectives(core, operation, result); |
| 104 | |
} |
| 105 | |
|
| 106 | 0 | clu.setDescr(core.getDescr()); |
| 107 | |
|
| 108 | |
|
| 109 | 0 | result.setNodeData(clu); |
| 110 | 0 | result.setOperation(operation); |
| 111 | 0 | result.setBusinessDTORef(core); |
| 112 | 0 | return result; |
| 113 | |
|
| 114 | |
} |
| 115 | |
|
| 116 | |
private void disassembleLearningObjectives(CoreProgramInfo core, NodeOperation operation, BaseDTOAssemblyNode<CoreProgramInfo, CluInfo> result) throws AssemblyException { |
| 117 | |
try { |
| 118 | 0 | List<BaseDTOAssemblyNode<?, ?>> loResults = cluAssemblerUtils.disassembleLos(core.getId(), core.getState(), core.getLearningObjectives(), operation); |
| 119 | 0 | if (loResults != null) { |
| 120 | 0 | result.getChildNodes().addAll(loResults); |
| 121 | |
} |
| 122 | 0 | } catch (DoesNotExistException e) { |
| 123 | 0 | } catch (Exception e) { |
| 124 | 0 | throw new AssemblyException("Error while disassembling los", e); |
| 125 | 0 | } |
| 126 | 0 | } |
| 127 | |
|
| 128 | |
|
| 129 | |
public void setLuService(LuService luService) { |
| 130 | 0 | this.luService = luService; |
| 131 | 0 | } |
| 132 | |
|
| 133 | |
public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) { |
| 134 | 0 | this.programAssemblerUtils = programAssemblerUtils; |
| 135 | 0 | } |
| 136 | |
|
| 137 | |
public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) { |
| 138 | 0 | this.cluAssemblerUtils = cluAssemblerUtils; |
| 139 | 0 | } |
| 140 | |
} |