| 1 |
|
package org.kuali.student.lum.program.service.assembler; |
| 2 |
|
|
| 3 |
|
import org.apache.log4j.Logger; |
| 4 |
|
import org.kuali.student.common.assembly.BOAssembler; |
| 5 |
|
import org.kuali.student.common.assembly.BaseDTOAssemblyNode; |
| 6 |
|
import org.kuali.student.common.assembly.BaseDTOAssemblyNode.NodeOperation; |
| 7 |
|
import org.kuali.student.common.assembly.data.AssemblyException; |
| 8 |
|
import org.kuali.student.common.exceptions.DoesNotExistException; |
| 9 |
|
import org.kuali.student.lum.lu.dto.AdminOrgInfo; |
| 10 |
|
import org.kuali.student.lum.lu.dto.CluCluRelationInfo; |
| 11 |
|
import org.kuali.student.lum.lu.dto.CluInfo; |
| 12 |
|
import org.kuali.student.lum.lu.service.LuService; |
| 13 |
|
import org.kuali.student.lum.program.dto.CredentialProgramInfo; |
| 14 |
|
import org.kuali.student.lum.service.assembler.CluAssemblerUtils; |
| 15 |
|
|
| 16 |
|
import java.util.List; |
| 17 |
|
import java.util.Map; |
| 18 |
|
|
|
|
|
| 0% |
Uncovered Elements: 125 (125) |
Complexity: 34 |
Complexity Density: 0.41 |
|
| 19 |
|
public class CredentialProgramAssembler implements BOAssembler<CredentialProgramInfo, CluInfo> { |
| 20 |
|
final static Logger LOG = Logger.getLogger(CredentialProgramAssembler.class); |
| 21 |
|
|
| 22 |
|
private ProgramAssemblerUtils programAssemblerUtils; |
| 23 |
|
private CluAssemblerUtils cluAssemblerUtils; |
| 24 |
|
private LuService luService; |
| 25 |
|
|
|
|
|
| 0% |
Uncovered Elements: 34 (34) |
Complexity: 7 |
Complexity Density: 0.29 |
|
| 26 |
0
|
@Override... |
| 27 |
|
public CredentialProgramInfo assemble(CluInfo clu, |
| 28 |
|
CredentialProgramInfo credentialProgram, |
| 29 |
|
boolean shallowBuild) |
| 30 |
|
throws AssemblyException { |
| 31 |
|
|
| 32 |
0
|
CredentialProgramInfo cpInfo = (null != credentialProgram) ? credentialProgram : new CredentialProgramInfo(); |
| 33 |
|
|
| 34 |
|
|
| 35 |
0
|
if (!ProgramAssemblerConstants.CREDENTIAL_PROGRAM_TYPES.contains(clu.getType())) { |
| 36 |
0
|
throw new AssemblyException("CredentialProgramAssembler.assemble() called for Clu of incorrect type: " + clu.getType()); |
| 37 |
|
} |
| 38 |
0
|
cpInfo.setCredentialProgramType(clu.getType()); |
| 39 |
0
|
cpInfo.setDescr(clu.getDescr()); |
| 40 |
0
|
cpInfo.setVersionInfo(clu.getVersionInfo()); |
| 41 |
|
|
| 42 |
0
|
programAssemblerUtils.assembleBasics(clu, cpInfo); |
| 43 |
0
|
programAssemblerUtils.assembleIdentifiers(clu, cpInfo); |
| 44 |
0
|
if (null != clu.getOfficialIdentifier().getLevel()) { |
| 45 |
0
|
cpInfo.setProgramLevel(clu.getOfficialIdentifier().getLevel()); |
| 46 |
|
} |
| 47 |
0
|
programAssemblerUtils.assembleBasicAdminOrgs(clu, cpInfo); |
| 48 |
0
|
for (AdminOrgInfo org : clu.getAdminOrgs()) { |
| 49 |
0
|
if (ProgramAssemblerConstants.INSTITUTION.equals(org.getType())) { |
| 50 |
0
|
cpInfo.setInstitution(org); |
| 51 |
|
} |
| 52 |
|
} |
| 53 |
0
|
programAssemblerUtils.assembleAtps(clu, cpInfo); |
| 54 |
0
|
programAssemblerUtils.assembleLuCodes(clu, cpInfo); |
| 55 |
|
|
| 56 |
0
|
if (!shallowBuild) { |
| 57 |
0
|
programAssemblerUtils.assembleRequirements(clu, cpInfo); |
| 58 |
0
|
cpInfo.setLearningObjectives(cluAssemblerUtils.assembleLos(clu.getId(), shallowBuild)); |
| 59 |
0
|
cpInfo.setResultOptions(programAssemblerUtils.assembleResultOptions(clu.getId())); |
| 60 |
|
} |
| 61 |
|
|
| 62 |
0
|
try { |
| 63 |
0
|
cpInfo.setCoreProgramIds(luService.getRelatedCluIdsByCluId(clu.getId(), ProgramAssemblerConstants.HAS_CORE_PROGRAM)); |
| 64 |
|
} catch (Exception e) { |
| 65 |
0
|
throw new AssemblyException(e); |
| 66 |
|
} |
| 67 |
|
|
| 68 |
0
|
return cpInfo; |
| 69 |
|
} |
| 70 |
|
|
|
|
|
| 0% |
Uncovered Elements: 44 (44) |
Complexity: 11 |
Complexity Density: 0.37 |
|
| 71 |
0
|
@Override... |
| 72 |
|
public BaseDTOAssemblyNode<CredentialProgramInfo, CluInfo> disassemble( |
| 73 |
|
CredentialProgramInfo credential, NodeOperation operation) |
| 74 |
|
throws AssemblyException { |
| 75 |
|
|
| 76 |
0
|
BaseDTOAssemblyNode<CredentialProgramInfo, CluInfo> result = new BaseDTOAssemblyNode<CredentialProgramInfo, CluInfo>(this); |
| 77 |
|
|
| 78 |
0
|
if (credential == null) { |
| 79 |
|
|
| 80 |
|
|
| 81 |
0
|
LOG.error("credentialProgram to disassemble is null!"); |
| 82 |
0
|
throw new AssemblyException("credentialProgram can not be null"); |
| 83 |
|
} |
| 84 |
|
|
| 85 |
0
|
CluInfo clu; |
| 86 |
0
|
try { |
| 87 |
0
|
clu = (NodeOperation.UPDATE == operation) ? luService.getClu(credential.getId()) : new CluInfo(); |
| 88 |
|
} catch (Exception e) { |
| 89 |
0
|
throw new AssemblyException("Error getting existing learning unit during CoreProgram update", e); |
| 90 |
|
} |
| 91 |
|
|
| 92 |
0
|
boolean stateChanged = NodeOperation.UPDATE == operation && credential.getState() != null && !credential.getState().equals(clu.getState()); |
| 93 |
|
|
| 94 |
0
|
programAssemblerUtils.disassembleBasics(clu, credential); |
| 95 |
0
|
if (credential.getId() == null) |
| 96 |
0
|
credential.setId(clu.getId()); |
| 97 |
0
|
programAssemblerUtils.disassembleIdentifiers(clu, credential, operation); |
| 98 |
0
|
programAssemblerUtils.disassembleAdminOrgs(clu, credential, operation); |
| 99 |
0
|
programAssemblerUtils.disassembleAtps(clu, credential, operation); |
| 100 |
0
|
programAssemblerUtils.disassembleLuCodes(clu, credential, operation); |
| 101 |
|
|
| 102 |
0
|
if (credential.getProgramRequirements() != null && !credential.getProgramRequirements().isEmpty()) { |
| 103 |
0
|
programAssemblerUtils.disassembleRequirements(clu, credential, operation, result, stateChanged); |
| 104 |
|
} |
| 105 |
|
|
| 106 |
0
|
if (credential.getResultOptions() != null) { |
| 107 |
0
|
disassembleResultOptions(credential, operation, result); |
| 108 |
|
} |
| 109 |
|
|
| 110 |
0
|
if (credential.getLearningObjectives() != null) { |
| 111 |
0
|
disassembleLearningObjectives(credential, operation, result); |
| 112 |
|
} |
| 113 |
|
|
| 114 |
0
|
clu.setDescr(credential.getDescr()); |
| 115 |
0
|
clu.setType(credential.getCredentialProgramType()); |
| 116 |
|
|
| 117 |
|
|
| 118 |
|
|
| 119 |
0
|
if (credential.getCoreProgramIds() != null && credential.getCoreProgramIds().size() > 0) { |
| 120 |
0
|
disassembleCorePrograms(credential, operation, result); |
| 121 |
|
} |
| 122 |
|
|
| 123 |
|
|
| 124 |
0
|
result.setNodeData(clu); |
| 125 |
0
|
result.setOperation(operation); |
| 126 |
0
|
result.setBusinessDTORef(credential); |
| 127 |
0
|
return result; |
| 128 |
|
} |
| 129 |
|
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
| 130 |
0
|
private void disassembleResultOptions(CredentialProgramInfo credential, NodeOperation operation, BaseDTOAssemblyNode<CredentialProgramInfo, CluInfo> result) throws AssemblyException {... |
| 131 |
0
|
BaseDTOAssemblyNode<?, ?> resultOptions = cluAssemblerUtils.disassembleCluResults( |
| 132 |
|
credential.getId(), credential.getState(), credential.getResultOptions(), operation, ProgramAssemblerConstants.DEGREE_RESULTS, "Result options", "Result option"); |
| 133 |
0
|
if (resultOptions != null) { |
| 134 |
0
|
result.getChildNodes().add(resultOptions); |
| 135 |
|
} |
| 136 |
|
} |
| 137 |
|
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 138 |
0
|
private void disassembleLearningObjectives(CredentialProgramInfo credential, NodeOperation operation, BaseDTOAssemblyNode<CredentialProgramInfo, CluInfo> result) throws AssemblyException {... |
| 139 |
0
|
try { |
| 140 |
0
|
List<BaseDTOAssemblyNode<?, ?>> loResults = cluAssemblerUtils.disassembleLos(credential.getId(), credential.getState(), credential.getLearningObjectives(), operation); |
| 141 |
0
|
if (loResults != null) { |
| 142 |
0
|
result.getChildNodes().addAll(loResults); |
| 143 |
|
} |
| 144 |
|
} catch (DoesNotExistException e) { |
| 145 |
|
} catch (Exception e) { |
| 146 |
0
|
throw new AssemblyException("Error while disassembling los", e); |
| 147 |
|
} |
| 148 |
|
} |
| 149 |
|
|
|
|
|
| 0% |
Uncovered Elements: 24 (24) |
Complexity: 7 |
Complexity Density: 0.39 |
|
| 150 |
0
|
private void disassembleCorePrograms(CredentialProgramInfo credential, NodeOperation operation, BaseDTOAssemblyNode<CredentialProgramInfo, CluInfo> result) throws AssemblyException {... |
| 151 |
0
|
List<BaseDTOAssemblyNode<?, ?>> coreResults; |
| 152 |
|
|
| 153 |
0
|
try { |
| 154 |
0
|
Map<String, String> currentRelations = null; |
| 155 |
|
|
| 156 |
0
|
if (!NodeOperation.CREATE.equals(operation)) { |
| 157 |
0
|
currentRelations = programAssemblerUtils.getCluCluRelations(credential.getId(), ProgramAssemblerConstants.HAS_CORE_PROGRAM); |
| 158 |
|
} |
| 159 |
|
|
| 160 |
0
|
for (String coreProgramId : credential.getCoreProgramIds()) { |
| 161 |
0
|
coreResults = programAssemblerUtils.addAllRelationNodes(credential.getId(), coreProgramId, ProgramAssemblerConstants.HAS_CORE_PROGRAM, operation, currentRelations); |
| 162 |
0
|
if (coreResults != null && coreResults.size() > 0) { |
| 163 |
0
|
result.getChildNodes().addAll(coreResults); |
| 164 |
|
} |
| 165 |
|
} |
| 166 |
|
|
| 167 |
0
|
if (currentRelations != null && currentRelations.size() > 0) { |
| 168 |
0
|
for (Map.Entry<String, String> entry : currentRelations.entrySet()) { |
| 169 |
|
|
| 170 |
|
|
| 171 |
0
|
CluCluRelationInfo relationToDelete = new CluCluRelationInfo(); |
| 172 |
0
|
relationToDelete.setId(entry.getValue()); |
| 173 |
0
|
BaseDTOAssemblyNode<Object, CluCluRelationInfo> relationToDeleteNode = new BaseDTOAssemblyNode<Object, CluCluRelationInfo>( |
| 174 |
|
null); |
| 175 |
0
|
relationToDeleteNode.setNodeData(relationToDelete); |
| 176 |
0
|
relationToDeleteNode.setOperation(NodeOperation.DELETE); |
| 177 |
0
|
result.getChildNodes().add(relationToDeleteNode); |
| 178 |
|
} |
| 179 |
|
} |
| 180 |
|
} catch (Exception e) { |
| 181 |
0
|
throw new AssemblyException("Error while disassembling Core programs", e); |
| 182 |
|
} |
| 183 |
|
} |
| 184 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 185 |
0
|
public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) {... |
| 186 |
0
|
this.programAssemblerUtils = programAssemblerUtils; |
| 187 |
|
} |
| 188 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 189 |
0
|
public void setLuService(LuService luService) {... |
| 190 |
0
|
this.luService = luService; |
| 191 |
|
} |
| 192 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 193 |
0
|
public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) {... |
| 194 |
0
|
this.cluAssemblerUtils = cluAssemblerUtils; |
| 195 |
|
} |
| 196 |
|
|
| 197 |
|
} |