| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
package org.kuali.student.lum.program.service.impl; |
| 5 |
|
|
| 6 |
|
import static org.apache.commons.collections.CollectionUtils.isEmpty; |
| 7 |
|
import static org.apache.commons.lang.StringUtils.isEmpty; |
| 8 |
|
|
| 9 |
|
import java.util.HashMap; |
| 10 |
|
import java.util.List; |
| 11 |
|
import java.util.Map; |
| 12 |
|
|
| 13 |
|
import org.apache.log4j.Logger; |
| 14 |
|
import org.kuali.student.common.util.UUIDHelper; |
| 15 |
|
import org.kuali.student.core.assembly.BOAssembler; |
| 16 |
|
import org.kuali.student.core.assembly.BaseDTOAssemblyNode; |
| 17 |
|
import org.kuali.student.core.assembly.BaseDTOAssemblyNode.NodeOperation; |
| 18 |
|
import org.kuali.student.core.assembly.data.AssemblyException; |
| 19 |
|
import org.kuali.student.core.exceptions.DoesNotExistException; |
| 20 |
|
import org.kuali.student.core.exceptions.InvalidParameterException; |
| 21 |
|
import org.kuali.student.core.exceptions.MissingParameterException; |
| 22 |
|
import org.kuali.student.core.exceptions.OperationFailedException; |
| 23 |
|
import org.kuali.student.core.statement.dto.RefStatementRelationInfo; |
| 24 |
|
import org.kuali.student.core.statement.dto.StatementTreeViewInfo; |
| 25 |
|
import org.kuali.student.core.statement.service.StatementService; |
| 26 |
|
import org.kuali.student.core.statement.service.assembler.StatementTreeViewAssembler; |
| 27 |
|
import org.kuali.student.lum.course.service.assembler.LoAssembler; |
| 28 |
|
import org.kuali.student.lum.lo.service.LearningObjectiveService; |
| 29 |
|
import org.kuali.student.lum.lu.dto.CluCluRelationInfo; |
| 30 |
|
import org.kuali.student.lum.lu.dto.CluIdentifierInfo; |
| 31 |
|
import org.kuali.student.lum.lu.dto.CluInfo; |
| 32 |
|
import org.kuali.student.lum.lu.service.LuService; |
| 33 |
|
import org.kuali.student.lum.program.dto.ProgramRequirementInfo; |
| 34 |
|
import org.kuali.student.lum.program.service.assembler.ProgramAssemblerConstants; |
| 35 |
|
import org.kuali.student.lum.program.service.assembler.ProgramAssemblerUtils; |
| 36 |
|
import org.kuali.student.lum.service.assembler.CluAssemblerUtils; |
| 37 |
|
|
| 38 |
|
|
| 39 |
|
|
| 40 |
|
@author |
| 41 |
|
|
| 42 |
|
|
|
|
|
| 80.8% |
Uncovered Elements: 35 (182) |
Complexity: 50 |
Complexity Density: 0.42 |
|
| 43 |
|
public class ProgramRequirementAssembler implements BOAssembler<ProgramRequirementInfo, CluInfo> { |
| 44 |
|
final static Logger LOG = Logger.getLogger(ProgramRequirementAssembler.class); |
| 45 |
|
|
| 46 |
|
private StatementService statementService; |
| 47 |
|
private StatementTreeViewAssembler statementTreeViewAssembler; |
| 48 |
|
private LearningObjectiveService loService; |
| 49 |
|
private LuService luService; |
| 50 |
|
private LoAssembler loAssembler; |
| 51 |
|
private CluAssemblerUtils cluAssemblerUtils; |
| 52 |
|
private ProgramAssemblerUtils programAssemblerUtils; |
| 53 |
|
|
| 54 |
|
|
|
|
|
| 87.5% |
Uncovered Elements: 4 (32) |
Complexity: 8 |
Complexity Density: 0.36 |
|
| 55 |
12
|
@Override... |
| 56 |
|
public ProgramRequirementInfo assemble(CluInfo clu, |
| 57 |
|
ProgramRequirementInfo progReqInfo, boolean shallowBuild) |
| 58 |
|
throws AssemblyException { |
| 59 |
12
|
ProgramRequirementInfo progReq = (progReqInfo != null ? progReqInfo : new ProgramRequirementInfo()); |
| 60 |
|
|
| 61 |
12
|
if (clu.getOfficialIdentifier() != null) { |
| 62 |
12
|
progReq.setShortTitle(clu.getOfficialIdentifier().getShortName()); |
| 63 |
12
|
progReq.setLongTitle(clu.getOfficialIdentifier().getLongName()); |
| 64 |
|
} |
| 65 |
12
|
progReq.setDescr(clu.getDescr()); |
| 66 |
|
|
| 67 |
|
|
| 68 |
12
|
assembleCredits(clu, progReq); |
| 69 |
|
|
| 70 |
12
|
if (progReq.getStatement() == null) { |
| 71 |
5
|
try { |
| 72 |
5
|
List<RefStatementRelationInfo> relations = statementService.getRefStatementRelationsByRef(ProgramAssemblerConstants.PROGRAM_REQUIREMENT, clu.getId()); |
| 73 |
|
|
| 74 |
|
|
| 75 |
5
|
StatementTreeViewInfo statementTree = new StatementTreeViewInfo(); |
| 76 |
5
|
if (relations != null) { |
| 77 |
5
|
statementTreeViewAssembler.assemble(statementService.getStatementTreeView(relations.get(0).getStatementId()), statementTree, shallowBuild); |
| 78 |
|
} |
| 79 |
5
|
progReq.setStatement(statementTree); |
| 80 |
|
} catch (AssemblyException e) { |
| 81 |
0
|
throw e; |
| 82 |
|
} catch (Exception e) { |
| 83 |
0
|
throw new AssemblyException(e); |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
|
| 87 |
12
|
if (isEmpty(progReq.getLearningObjectives())) { |
| 88 |
5
|
progReq.setLearningObjectives(cluAssemblerUtils.assembleLos(clu.getId(), shallowBuild)); |
| 89 |
|
} |
| 90 |
|
|
| 91 |
12
|
progReq.setMetaInfo(clu.getMetaInfo()); |
| 92 |
12
|
progReq.setType(clu.getType()); |
| 93 |
12
|
progReq.setAttributes(clu.getAttributes()); |
| 94 |
12
|
progReq.setId(clu.getId()); |
| 95 |
|
|
| 96 |
12
|
return progReq; |
| 97 |
|
} |
| 98 |
|
|
|
|
|
| 84.5% |
Uncovered Elements: 13 (84) |
Complexity: 16 |
Complexity Density: 0.25 |
|
| 99 |
9
|
@Override... |
| 100 |
|
public BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo> disassemble( |
| 101 |
|
ProgramRequirementInfo progReq, NodeOperation operation) |
| 102 |
|
throws AssemblyException { |
| 103 |
|
|
| 104 |
9
|
if (progReq == null) { |
| 105 |
|
|
| 106 |
|
|
| 107 |
0
|
LOG.error("ProgramRequirementInfo to disassemble is null!"); |
| 108 |
0
|
throw new AssemblyException("ProgramRequirementInfo can not be null"); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
9
|
BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo> result = new BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo>(null); |
| 112 |
|
|
| 113 |
|
|
| 114 |
9
|
StatementTreeViewInfo statement = progReq.getStatement(); |
| 115 |
9
|
statement.setId(UUIDHelper.genStringUUID(statement.getId())); |
| 116 |
9
|
BaseDTOAssemblyNode<StatementTreeViewInfo, StatementTreeViewInfo> statementTree; |
| 117 |
9
|
try { |
| 118 |
9
|
statementTree = statementTreeViewAssembler.disassemble(statement, operation); |
| 119 |
|
} catch (AssemblyException e) { |
| 120 |
0
|
throw e; |
| 121 |
|
} catch (Exception e) { |
| 122 |
0
|
throw new AssemblyException(e); |
| 123 |
|
} |
| 124 |
9
|
result.getChildNodes().add(statementTree); |
| 125 |
|
|
| 126 |
9
|
CluInfo clu; |
| 127 |
9
|
try { |
| 128 |
9
|
clu = (NodeOperation.UPDATE == operation) ? luService.getClu(progReq.getId()) : new CluInfo(); |
| 129 |
|
} catch (Exception e) { |
| 130 |
0
|
throw new AssemblyException("Error getting existing learning unit during program requirement update", e); |
| 131 |
|
} |
| 132 |
|
|
| 133 |
9
|
if (operation.equals(NodeOperation.DELETE)) { |
| 134 |
2
|
try { |
| 135 |
2
|
final List<CluCluRelationInfo> relations = luService.getCluCluRelationsByClu(progReq.getId()); |
| 136 |
2
|
final BaseDTOAssemblyNode<ProgramRequirementInfo, CluCluRelationInfo> cluRelation = new BaseDTOAssemblyNode<ProgramRequirementInfo, CluCluRelationInfo>(null); |
| 137 |
2
|
if (relations.size() > 1) { |
| 138 |
0
|
throw new AssemblyException("Unable to dissamble ProgramRequirement, more than one CluCluRelation found"); |
| 139 |
2
|
} else if (relations.size() == 1) { |
| 140 |
1
|
cluRelation.setNodeData(relations.get(0)); |
| 141 |
1
|
cluRelation.setOperation(operation); |
| 142 |
1
|
result.getChildNodes().add(cluRelation); |
| 143 |
|
} |
| 144 |
|
} catch (Exception e) { |
| 145 |
0
|
throw new AssemblyException(e); |
| 146 |
|
} |
| 147 |
|
} |
| 148 |
|
|
| 149 |
9
|
BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo> cluResult = new BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo>(this); |
| 150 |
|
|
| 151 |
9
|
cluResult.setNodeData(clu); |
| 152 |
9
|
cluResult.setBusinessDTORef(progReq); |
| 153 |
9
|
cluResult.setOperation(operation); |
| 154 |
9
|
result.getChildNodes().add(cluResult); |
| 155 |
|
|
| 156 |
9
|
programAssemblerUtils.disassembleBasics(clu, progReq); |
| 157 |
|
|
| 158 |
|
|
| 159 |
9
|
disassembleCredits(clu, progReq); |
| 160 |
|
|
| 161 |
9
|
progReq.setId(clu.getId()); |
| 162 |
9
|
CluIdentifierInfo official = null != clu.getOfficialIdentifier() ? clu.getOfficialIdentifier() : new CluIdentifierInfo(); |
| 163 |
9
|
official.setLongName(progReq.getLongTitle()); |
| 164 |
9
|
official.setShortName(progReq.getShortTitle()); |
| 165 |
9
|
official.setState(!isEmpty(clu.getState()) ? clu.getState() : ProgramAssemblerConstants.ACTIVE); |
| 166 |
|
|
| 167 |
9
|
official.setType(ProgramAssemblerConstants.OFFICIAL); |
| 168 |
9
|
clu.setOfficialIdentifier(official); |
| 169 |
|
|
| 170 |
9
|
clu.setDescr(progReq.getDescr()); |
| 171 |
9
|
clu.setState(!isEmpty(clu.getState()) ? clu.getState() : ProgramAssemblerConstants.ACTIVE); |
| 172 |
9
|
if (progReq.getLearningObjectives() != null) { |
| 173 |
9
|
disassembleLearningObjectives(progReq, operation, result); |
| 174 |
|
} |
| 175 |
|
|
| 176 |
9
|
RefStatementRelationInfo relation; |
| 177 |
9
|
if (operation == NodeOperation.CREATE) { |
| 178 |
6
|
relation = new RefStatementRelationInfo(); |
| 179 |
6
|
relation.setId(UUIDHelper.genStringUUID(null)); |
| 180 |
|
} else { |
| 181 |
3
|
try { |
| 182 |
3
|
relation = statementService.getRefStatementRelationsByRef(ProgramAssemblerConstants.PROGRAM_REQUIREMENT, clu.getId()).get(0); |
| 183 |
|
} catch (Exception e) { |
| 184 |
0
|
throw new AssemblyException("Unable to find RefStatementRelation", e); |
| 185 |
|
} |
| 186 |
|
} |
| 187 |
|
|
| 188 |
9
|
relation.setType(ProgramAssemblerConstants.PROGRAM_REFERENCE_TYPE); |
| 189 |
9
|
relation.setRefObjectId(clu.getId()); |
| 190 |
9
|
relation.setRefObjectTypeKey(ProgramAssemblerConstants.PROGRAM_REQUIREMENT); |
| 191 |
9
|
relation.setStatementId(statement.getId()); |
| 192 |
9
|
relation.setState(ProgramAssemblerConstants.ACTIVE); |
| 193 |
|
|
| 194 |
9
|
BaseDTOAssemblyNode<ProgramRequirementInfo, RefStatementRelationInfo> relationNode = new BaseDTOAssemblyNode<ProgramRequirementInfo, RefStatementRelationInfo>(null); |
| 195 |
9
|
relationNode.setNodeData(relation); |
| 196 |
9
|
relationNode.setOperation(operation); |
| 197 |
|
|
| 198 |
9
|
result.getChildNodes().add(relationNode); |
| 199 |
9
|
result.setBusinessDTORef(progReq); |
| 200 |
9
|
result.setOperation(operation); |
| 201 |
9
|
return result; |
| 202 |
|
} |
| 203 |
|
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 4 |
Complexity Density: 0.8 |
|
| 204 |
9
|
private void disassembleLearningObjectives(ProgramRequirementInfo progReq,... |
| 205 |
|
NodeOperation operation, |
| 206 |
|
BaseDTOAssemblyNode<ProgramRequirementInfo, CluInfo> result) throws AssemblyException { |
| 207 |
9
|
try { |
| 208 |
9
|
List<BaseDTOAssemblyNode<?, ?>> loResults = cluAssemblerUtils.disassembleLos(progReq.getId(), progReq.getState(), progReq.getLearningObjectives(), operation); |
| 209 |
9
|
if (loResults != null) { |
| 210 |
9
|
result.getChildNodes().addAll(loResults); |
| 211 |
|
} |
| 212 |
|
} catch (DoesNotExistException e) { |
| 213 |
|
} catch (Exception e) { |
| 214 |
0
|
throw new AssemblyException("Error while disassembling los", e); |
| 215 |
|
} |
| 216 |
|
} |
| 217 |
|
|
|
|
|
| 92.9% |
Uncovered Elements: 1 (14) |
Complexity: 4 |
Complexity Density: 0.5 |
|
| 218 |
9
|
private void disassembleCredits(CluInfo clu, ProgramRequirementInfo progReq){... |
| 219 |
9
|
Map<String,String> attributes = null != clu.getAttributes() ? clu.getAttributes() : new HashMap<String,String>(); |
| 220 |
|
|
| 221 |
9
|
if(progReq.getMinCredits() != null){ |
| 222 |
1
|
attributes.put(ProgramAssemblerConstants.MIN_CREDITS, Integer.toString(progReq.getMinCredits())); |
| 223 |
|
}else{ |
| 224 |
8
|
attributes.put(ProgramAssemblerConstants.MIN_CREDITS, null); |
| 225 |
|
} |
| 226 |
9
|
if(progReq.getMaxCredits() != null) { |
| 227 |
1
|
attributes.put(ProgramAssemblerConstants.MAX_CREDITS, Integer.toString(progReq.getMaxCredits())); |
| 228 |
|
}else{ |
| 229 |
8
|
attributes.put(ProgramAssemblerConstants.MAX_CREDITS, null); |
| 230 |
|
} |
| 231 |
|
|
| 232 |
9
|
clu.setAttributes(attributes); |
| 233 |
|
} |
| 234 |
|
|
|
|
|
| 91.7% |
Uncovered Elements: 1 (12) |
Complexity: 4 |
Complexity Density: 0.67 |
|
| 235 |
12
|
private void assembleCredits(CluInfo clu, ProgramRequirementInfo progReq){... |
| 236 |
12
|
Map<String,String> attributes = clu.getAttributes(); |
| 237 |
12
|
if(attributes != null){ |
| 238 |
12
|
String minCredits = attributes.get(ProgramAssemblerConstants.MIN_CREDITS); |
| 239 |
12
|
String maxCredits = attributes.get(ProgramAssemblerConstants.MAX_CREDITS); |
| 240 |
12
|
progReq.setMinCredits(isEmpty(minCredits)?null:Integer.parseInt(minCredits)); |
| 241 |
12
|
progReq.setMaxCredits(isEmpty(maxCredits)?null:Integer.parseInt(maxCredits)); |
| 242 |
|
} |
| 243 |
|
} |
| 244 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 245 |
0
|
public StatementTreeViewAssembler getStatementTreeViewAssembler() {... |
| 246 |
0
|
return statementTreeViewAssembler; |
| 247 |
|
} |
| 248 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 249 |
1
|
public void setStatementTreeViewAssembler(... |
| 250 |
|
StatementTreeViewAssembler statementTreeViewAssembler) { |
| 251 |
1
|
this.statementTreeViewAssembler = statementTreeViewAssembler; |
| 252 |
|
} |
| 253 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 254 |
0
|
public StatementService getStatementService() {... |
| 255 |
0
|
return statementService; |
| 256 |
|
} |
| 257 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 258 |
1
|
public void setStatementService(StatementService statementService) {... |
| 259 |
1
|
this.statementService = statementService; |
| 260 |
|
} |
| 261 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 262 |
0
|
public LearningObjectiveService getLoService() {... |
| 263 |
0
|
return loService; |
| 264 |
|
} |
| 265 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 266 |
1
|
public void setLoService(LearningObjectiveService loService) {... |
| 267 |
1
|
this.loService = loService; |
| 268 |
|
} |
| 269 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 270 |
0
|
public LuService getLuService() {... |
| 271 |
0
|
return luService; |
| 272 |
|
} |
| 273 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 274 |
1
|
public void setLuService(LuService luService) {... |
| 275 |
1
|
this.luService = luService; |
| 276 |
|
} |
| 277 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 278 |
0
|
public LoAssembler getLoAssembler() {... |
| 279 |
0
|
return loAssembler; |
| 280 |
|
} |
| 281 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 282 |
1
|
public void setLoAssembler(LoAssembler loAssembler) {... |
| 283 |
1
|
this.loAssembler = loAssembler; |
| 284 |
|
} |
| 285 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 286 |
0
|
public CluAssemblerUtils getCluAssemblerUtils() {... |
| 287 |
0
|
return cluAssemblerUtils; |
| 288 |
|
} |
| 289 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 290 |
1
|
public void setCluAssemblerUtils(CluAssemblerUtils cluAssemblerUtils) {... |
| 291 |
1
|
this.cluAssemblerUtils = cluAssemblerUtils; |
| 292 |
|
} |
| 293 |
|
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 294 |
0
|
public ProgramAssemblerUtils getProgramAssemblerUtils() {... |
| 295 |
0
|
return programAssemblerUtils; |
| 296 |
|
} |
| 297 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 298 |
1
|
public void setProgramAssemblerUtils(ProgramAssemblerUtils programAssemblerUtils) {... |
| 299 |
1
|
this.programAssemblerUtils = programAssemblerUtils; |
| 300 |
|
} |
| 301 |
|
} |