Skip to content
Snippets Groups Projects
Commit ec7606c0 authored by Jan Tymel's avatar Jan Tymel
Browse files

Fix DecisionMatrixRows alignment when phases' order are changed

Related to #1
parent 5e76cf20
No related branches found
No related tags found
No related merge requests found
...@@ -69,8 +69,10 @@ public class PhaseLevelService { ...@@ -69,8 +69,10 @@ public class PhaseLevelService {
public void alignDecisionMatrixForPhasesInTrainingDefinition(Long trainingDefinitionId) { public void alignDecisionMatrixForPhasesInTrainingDefinition(Long trainingDefinitionId) {
List<PhaseLevel> phaseLevels = phaseLevelRepository.findAllByTrainingDefinitionIdOrderByOrder(trainingDefinitionId); List<PhaseLevel> phaseLevels = phaseLevelRepository.findAllByTrainingDefinitionIdOrderByOrder(trainingDefinitionId);
int currentPhaseOrder = 0;
for (PhaseLevel phaseLevel : phaseLevels) { for (PhaseLevel phaseLevel : phaseLevels) {
alignDecisionMatrixForPhase(phaseLevel); alignDecisionMatrixForPhase(phaseLevel, currentPhaseOrder);
currentPhaseOrder++;
} }
} }
...@@ -91,7 +93,7 @@ public class PhaseLevelService { ...@@ -91,7 +93,7 @@ public class PhaseLevelService {
return result; return result;
} }
private void alignDecisionMatrixForPhase(PhaseLevel phaseLevel) { private void alignDecisionMatrixForPhase(PhaseLevel phaseLevel, int currentPhaseOrder) {
if (Objects.isNull(phaseLevel)) { if (Objects.isNull(phaseLevel)) {
return; return;
} }
...@@ -101,15 +103,15 @@ public class PhaseLevelService { ...@@ -101,15 +103,15 @@ public class PhaseLevelService {
numberOfRows = phaseLevel.getDecisionMatrix().size(); numberOfRows = phaseLevel.getDecisionMatrix().size();
} }
final int expextedNumberOfRows = phaseLevel.getOrder() + 1; final int expectedNumberOfRows = currentPhaseOrder + 1;
if (numberOfRows == expextedNumberOfRows) { if (numberOfRows == expectedNumberOfRows) {
return; return;
} else if (numberOfRows < expextedNumberOfRows) { } else if (numberOfRows < expectedNumberOfRows) {
List<DecisionMatrixRow> newDecisionMatrixRows = getNewDecisionMatrixRows(numberOfRows, expextedNumberOfRows, phaseLevel); List<DecisionMatrixRow> newDecisionMatrixRows = getNewDecisionMatrixRows(numberOfRows, expectedNumberOfRows, phaseLevel);
phaseLevel.getDecisionMatrix().addAll(newDecisionMatrixRows); phaseLevel.getDecisionMatrix().addAll(newDecisionMatrixRows);
} else { } else {
List<DecisionMatrixRow> neededDecisionMatrixRows = getOnlyNeededDecisionMatrixRows(expextedNumberOfRows, phaseLevel); List<DecisionMatrixRow> neededDecisionMatrixRows = getOnlyNeededDecisionMatrixRows(expectedNumberOfRows, phaseLevel);
phaseLevel.getDecisionMatrix().clear(); phaseLevel.getDecisionMatrix().clear();
phaseLevel.getDecisionMatrix().addAll(neededDecisionMatrixRows); phaseLevel.getDecisionMatrix().addAll(neededDecisionMatrixRows);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment