diff --git a/backend/src/main/java/ch/puzzle/okr/service/validation/AlignmentValidationService.java b/backend/src/main/java/ch/puzzle/okr/service/validation/AlignmentValidationService.java index efba046531..8a656cd679 100644 --- a/backend/src/main/java/ch/puzzle/okr/service/validation/AlignmentValidationService.java +++ b/backend/src/main/java/ch/puzzle/okr/service/validation/AlignmentValidationService.java @@ -59,11 +59,11 @@ private void throwExceptionWhenAlignedObjectIsNull(Alignment model) { throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL, List.of("targetObjectiveId", objectiveAlignment.getAlignedObjective().getId())); } - } else if (model instanceof KeyResultAlignment keyResultAlignment) { - if (keyResultAlignment.getAlignmentTarget() == null) { - throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL, - List.of("targetKeyResultId", keyResultAlignment.getAlignedObjective().getId())); - } + } else if (model instanceof KeyResultAlignment keyResultAlignment + && (keyResultAlignment.getAlignmentTarget() == null)) { + throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL, + List.of("targetKeyResultId", keyResultAlignment.getAlignedObjective().getId())); + } } @@ -85,12 +85,12 @@ private void throwExceptionWhenAlignmentIsInSameTeam(Alignment model) { } private void throwExceptionWhenAlignedIdIsSameAsTargetId(Alignment model) { - if (model instanceof ObjectiveAlignment objectiveAlignment) { - if (Objects.equals(objectiveAlignment.getAlignedObjective().getId(), - objectiveAlignment.getAlignmentTarget().getId())) { - throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.NOT_LINK_YOURSELF, - List.of("targetObjectiveId", objectiveAlignment.getAlignmentTarget().getId())); - } + if (model instanceof ObjectiveAlignment objectiveAlignment + && (Objects.equals(objectiveAlignment.getAlignedObjective().getId(), + objectiveAlignment.getAlignmentTarget().getId()))) { + throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.NOT_LINK_YOURSELF, + List.of("targetObjectiveId", objectiveAlignment.getAlignmentTarget().getId())); + } } diff --git a/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentPersistenceServiceIT.java b/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentPersistenceServiceIT.java index 6fb132da9a..6908afe2d4 100644 --- a/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentPersistenceServiceIT.java +++ b/backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentPersistenceServiceIT.java @@ -28,6 +28,7 @@ class AlignmentPersistenceServiceIT { @Autowired private AlignmentPersistenceService alignmentPersistenceService; private Alignment createdAlignment; + private final String ALIGNMENT = "alignment"; private static ObjectiveAlignment createObjectiveAlignment(Long id) { return ObjectiveAlignment.Builder.builder().withId(id) @@ -102,7 +103,7 @@ void updateAlignmentShouldThrowExceptionWhenAlreadyUpdated() { OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class, () -> alignmentPersistenceService.save(updateAlignment)); - List expectedErrors = List.of(new ErrorDto("DATA_HAS_BEEN_UPDATED", List.of("Alignment"))); + List expectedErrors = List.of(new ErrorDto("DATA_HAS_BEEN_UPDATED", List.of(ALIGNMENT))); assertEquals(UNPROCESSABLE_ENTITY, exception.getStatusCode()); assertThat(expectedErrors).hasSameElementsAs(exception.getErrors()); @@ -114,7 +115,7 @@ void findByAlignedObjectiveIdShouldReturnAlignmentModel() { Alignment alignment = alignmentPersistenceService.findByAlignedObjectiveId(4L); assertNotNull(alignment); - assertEquals(alignment.getAlignedObjective().getId(), 4); + assertEquals(4, alignment.getAlignedObjective().getId()); } @Test @@ -162,7 +163,7 @@ void recreateEntityShouldUpdateAlignmentNoTypeChange() { () -> alignmentPersistenceService.findById(alignmentId)); List expectedErrors = List - .of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of("Alignment", alignmentId))); + .of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of(ALIGNMENT, alignmentId))); assertEquals(NOT_FOUND, exception.getStatusCode()); assertThat(expectedErrors).hasSameElementsAs(exception.getErrors()); @@ -202,7 +203,7 @@ void recreateEntityShouldUpdateAlignmentWithTypeChange() { () -> alignmentPersistenceService.findById(alignmentId)); List expectedErrors = List - .of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of("Alignment", alignmentId))); + .of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of(ALIGNMENT, alignmentId))); assertEquals(NOT_FOUND, exception.getStatusCode()); assertThat(expectedErrors).hasSameElementsAs(exception.getErrors()); diff --git a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts index 7725c7ca2f..767716d530 100644 --- a/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts +++ b/frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts @@ -249,7 +249,7 @@ export class ObjectiveFormComponent implements OnInit { this.alignmentPossibilities$ = this.objectiveService.getAlignmentPossibilities(quarterId); this.alignmentPossibilities$.subscribe((value: AlignmentPossibility[]) => { if (teamId) { - value = value.filter((item: AlignmentPossibility) => !(item.teamId == teamId)); + value = value.filter((item: AlignmentPossibility) => item.teamId != teamId); } if (objective) {