Skip to content

Commit

Permalink
Add missing quarter in testdata and fix bug when editing alignment mu…
Browse files Browse the repository at this point in the history
…ltiple times
  • Loading branch information
lkleisa committed May 22, 2024
1 parent a945aa0 commit 0fdbef7
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -56,15 +56,16 @@ 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 {
if (objective.getAlignedEntityId() == null) {
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)) {
Expand All @@ -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()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 0fdbef7

Please sign in to comment.