Skip to content

Commit b34d987

Browse files
committed
Fix sonar code smells
1 parent 77fdbc8 commit b34d987

File tree

3 files changed

+17
-16
lines changed

3 files changed

+17
-16
lines changed

backend/src/main/java/ch/puzzle/okr/service/validation/AlignmentValidationService.java

+11-11
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ private void throwExceptionWhenAlignedObjectIsNull(Alignment model) {
5959
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL,
6060
List.of("targetObjectiveId", objectiveAlignment.getAlignedObjective().getId()));
6161
}
62-
} else if (model instanceof KeyResultAlignment keyResultAlignment) {
63-
if (keyResultAlignment.getAlignmentTarget() == null) {
64-
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL,
65-
List.of("targetKeyResultId", keyResultAlignment.getAlignedObjective().getId()));
66-
}
62+
} else if (model instanceof KeyResultAlignment keyResultAlignment
63+
&& (keyResultAlignment.getAlignmentTarget() == null)) {
64+
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.ATTRIBUTE_NULL,
65+
List.of("targetKeyResultId", keyResultAlignment.getAlignedObjective().getId()));
66+
6767
}
6868
}
6969

@@ -85,12 +85,12 @@ private void throwExceptionWhenAlignmentIsInSameTeam(Alignment model) {
8585
}
8686

8787
private void throwExceptionWhenAlignedIdIsSameAsTargetId(Alignment model) {
88-
if (model instanceof ObjectiveAlignment objectiveAlignment) {
89-
if (Objects.equals(objectiveAlignment.getAlignedObjective().getId(),
90-
objectiveAlignment.getAlignmentTarget().getId())) {
91-
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.NOT_LINK_YOURSELF,
92-
List.of("targetObjectiveId", objectiveAlignment.getAlignmentTarget().getId()));
93-
}
88+
if (model instanceof ObjectiveAlignment objectiveAlignment
89+
&& (Objects.equals(objectiveAlignment.getAlignedObjective().getId(),
90+
objectiveAlignment.getAlignmentTarget().getId()))) {
91+
throw new OkrResponseStatusException(HttpStatus.BAD_REQUEST, ErrorKey.NOT_LINK_YOURSELF,
92+
List.of("targetObjectiveId", objectiveAlignment.getAlignmentTarget().getId()));
93+
9494
}
9595
}
9696

backend/src/test/java/ch/puzzle/okr/service/persistence/AlignmentPersistenceServiceIT.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ class AlignmentPersistenceServiceIT {
2828
@Autowired
2929
private AlignmentPersistenceService alignmentPersistenceService;
3030
private Alignment createdAlignment;
31+
private final String ALIGNMENT = "Alignment";
3132

3233
private static ObjectiveAlignment createObjectiveAlignment(Long id) {
3334
return ObjectiveAlignment.Builder.builder().withId(id)
@@ -102,7 +103,7 @@ void updateAlignmentShouldThrowExceptionWhenAlreadyUpdated() {
102103
OkrResponseStatusException exception = assertThrows(OkrResponseStatusException.class,
103104
() -> alignmentPersistenceService.save(updateAlignment));
104105

105-
List<ErrorDto> expectedErrors = List.of(new ErrorDto("DATA_HAS_BEEN_UPDATED", List.of("Alignment")));
106+
List<ErrorDto> expectedErrors = List.of(new ErrorDto("DATA_HAS_BEEN_UPDATED", List.of(ALIGNMENT)));
106107

107108
assertEquals(UNPROCESSABLE_ENTITY, exception.getStatusCode());
108109
assertThat(expectedErrors).hasSameElementsAs(exception.getErrors());
@@ -114,7 +115,7 @@ void findByAlignedObjectiveIdShouldReturnAlignmentModel() {
114115
Alignment alignment = alignmentPersistenceService.findByAlignedObjectiveId(4L);
115116

116117
assertNotNull(alignment);
117-
assertEquals(alignment.getAlignedObjective().getId(), 4);
118+
assertEquals(4, alignment.getAlignedObjective().getId());
118119
}
119120

120121
@Test
@@ -162,7 +163,7 @@ void recreateEntityShouldUpdateAlignmentNoTypeChange() {
162163
() -> alignmentPersistenceService.findById(alignmentId));
163164

164165
List<ErrorDto> expectedErrors = List
165-
.of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of("Alignment", alignmentId)));
166+
.of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of(ALIGNMENT, alignmentId)));
166167

167168
assertEquals(NOT_FOUND, exception.getStatusCode());
168169
assertThat(expectedErrors).hasSameElementsAs(exception.getErrors());
@@ -202,7 +203,7 @@ void recreateEntityShouldUpdateAlignmentWithTypeChange() {
202203
() -> alignmentPersistenceService.findById(alignmentId));
203204

204205
List<ErrorDto> expectedErrors = List
205-
.of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of("Alignment", alignmentId)));
206+
.of(ErrorDto.of("MODEL_WITH_ID_NOT_FOUND", List.of(ALIGNMENT, alignmentId)));
206207

207208
assertEquals(NOT_FOUND, exception.getStatusCode());
208209
assertThat(expectedErrors).hasSameElementsAs(exception.getErrors());

frontend/src/app/shared/dialog/objective-dialog/objective-form.component.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ export class ObjectiveFormComponent implements OnInit {
249249
this.alignmentPossibilities$ = this.objectiveService.getAlignmentPossibilities(quarterId);
250250
this.alignmentPossibilities$.subscribe((value: AlignmentPossibility[]) => {
251251
if (teamId) {
252-
value = value.filter((item: AlignmentPossibility) => !(item.teamId == teamId));
252+
value = value.filter((item: AlignmentPossibility) => item.teamId != teamId);
253253
}
254254

255255
if (objective) {

0 commit comments

Comments
 (0)