diff --git a/backend/src/main/java/ch/puzzle/okr/service/business/AlignmentBusinessService.java b/backend/src/main/java/ch/puzzle/okr/service/business/AlignmentBusinessService.java index f7d8caee6a..dfef1ee5a4 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/business/AlignmentBusinessService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/business/AlignmentBusinessService.java @@ -47,7 +47,7 @@ public String getTargetIdByAlignedObjectiveId(Long alignedObjectiveId) { } public void createEntity(Objective alignedObjective) { - Alignment alignment = buildAlignmentModel(alignedObjective); + Alignment alignment = buildAlignmentModel(alignedObjective, 0); alignmentValidationService.validateOnCreate(alignment); alignmentPersistenceService.save(alignment); } @@ -56,7 +56,7 @@ public void updateEntity(Long objectiveId, Objective objective) { Alignment savedAlignment = alignmentPersistenceService.findByAlignedObjectiveId(objectiveId); if (savedAlignment == null) { - Alignment alignment = buildAlignmentModel(objective); + Alignment alignment = buildAlignmentModel(objective, 0); alignmentValidationService.validateOnCreate(alignment); alignmentPersistenceService.save(alignment); } else { @@ -64,7 +64,8 @@ public void updateEntity(Long objectiveId, Objective objective) { alignmentValidationService.validateOnDelete(savedAlignment.getId()); alignmentPersistenceService.deleteById(savedAlignment.getId()); } else { - Alignment alignment = buildAlignmentModel(objective); + Alignment alignment = buildAlignmentModel(objective, savedAlignment.getVersion()); + alignment.setId(savedAlignment.getId()); alignmentValidationService.validateOnUpdate(savedAlignment.getId(), alignment); if (isAlignmentTypeChange(alignment, savedAlignment)) { @@ -76,18 +77,17 @@ public void updateEntity(Long objectiveId, Objective objective) { } } - public Alignment buildAlignmentModel(Objective alignedObjective) { + public Alignment buildAlignmentModel(Objective alignedObjective, int version) { if (alignedObjective.getAlignedEntityId().startsWith("O")) { Objective targetObjective = objectivePersistenceService .findById(Long.valueOf(alignedObjective.getAlignedEntityId().replace("O", ""))); return ObjectiveAlignment.Builder.builder().withAlignedObjective(alignedObjective) - .withTargetObjective(targetObjective).build(); + .withTargetObjective(targetObjective).withVersion(version).build(); } else if (alignedObjective.getAlignedEntityId().startsWith("K")) { KeyResult targetKeyResult = keyResultPersistenceService .findById(Long.valueOf(alignedObjective.getAlignedEntityId().replace("K", ""))); - return KeyResultAlignment.Builder.builder().withAlignedObjective(alignedObjective) - .withTargetKeyResult(targetKeyResult).build(); + .withTargetKeyResult(targetKeyResult).withVersion(version).build(); } else { throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NOT_SET, List.of("alignedEntityId", alignedObjective.getAlignedEntityId())); diff --git a/backend/src/main/resources/db/h2-db/data-test-h2/V100_0_0__TestData.sql b/backend/src/main/resources/db/h2-db/data-test-h2/V100_0_0__TestData.sql index 4dc4efad8a..c712d2532c 100644 --- a/backend/src/main/resources/db/h2-db/data-test-h2/V100_0_0__TestData.sql +++ b/backend/src/main/resources/db/h2-db/data-test-h2/V100_0_0__TestData.sql @@ -41,6 +41,7 @@ values (1, 'GJ 22/23-Q4', '2023-04-01', '2023-06-30'), (7, 'GJ 23/24-Q2', '2023-10-01', '2023-12-31'), (8, 'GJ 23/24-Q3', '2024-01-01', '2024-03-31'), (9, 'GJ 23/24-Q4', '2024-04-01', '2024-06-30'), + (10, 'GJ 24/25-Q1', '2024-07-01', '2024-09-30'), (199, 'Backlog', null, null); insert into team (id, version, name)