Skip to content

Commit bf3b0ac

Browse files
author
Dennis Labordus
committed
Fixed Sonar issues.
Signed-off-by: Dennis Labordus <[email protected]>
1 parent ee98e0e commit bf3b0ac

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

app/src/main/java/org/lfenergy/compas/scl/data/rest/v1/CompasCommonResource.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import javax.ws.rs.core.MediaType;
2323
import java.util.Arrays;
2424
import java.util.Comparator;
25-
import java.util.stream.Collectors;
2625

2726
import static org.lfenergy.compas.scl.data.rest.Constants.READ_ROLE;
2827

@@ -54,7 +53,7 @@ public TypeListResponse list(@HeaderParam("Authorization") String authHeader) {
5453
.filter(sclFileType -> roles.contains(sclFileType.name() + "_" + READ_ROLE))
5554
.map(sclFileType -> new Type(sclFileType.name(), sclFileType.getDescription()))
5655
.sorted(Comparator.comparing(Type::getDescription))
57-
.collect(Collectors.toList()));
56+
.toList());
5857
return response;
5958
}
6059

repository-basex/src/main/java/org/lfenergy/compas/scl/data/basex/repository/CompasSclDataBaseXRepository.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,16 @@ public CompasSclDataBaseXRepository(BaseXClientFactory baseXClientFactory,
7474
this.baseXClientFactory = baseXClientFactory;
7575
this.sclDataMarshaller = sclDataMarshaller;
7676

77+
var command = """
78+
declare variable $db := '%s';
79+
if (not(db:exists($db)))
80+
then
81+
db:create($db)
82+
""";
7783
// At startup create all needed databases.
7884
Arrays.stream(SclFileType.values()).forEach(type ->
7985
executeCommand(client -> {
80-
client.executeXQuery("""
81-
declare variable $db := '%s';
82-
if (not(db:exists($db)))
83-
then
84-
db:create($db)
85-
""".formatted(type));
86+
client.executeXQuery(command.formatted(type));
8687
return true;
8788
}));
8889
}

repository/src/test/java/org/lfenergy/compas/scl/data/repository/AbstractCompasSclDataRepositoryTest.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,9 @@ void listVersionsByUUID_WhenTwoVersionsOfARecordAdded_ThenAllRecordAreFound() {
135135
void findByUUID_WhenCalledWithUnknownUUID_ThenExceptionIsThrown() {
136136
var uuid = UUID.randomUUID();
137137

138+
var repository = getRepository();
138139
var exception = assertThrows(CompasNoDataFoundException.class, () -> {
139-
getRepository().findByUUID(TYPE, uuid);
140+
repository.findByUUID(TYPE, uuid);
140141
});
141142
assertEquals(NO_DATA_FOUND_ERROR_CODE, exception.getErrorCode());
142143
}
@@ -163,11 +164,13 @@ void findByUUIDWithVersion_WhenCalledWithUnknownVersion_ThenExceptionIsThrown()
163164
var version = new Version(1, 0, 0);
164165
var uuid = UUID.randomUUID();
165166
var scl = readSCL(uuid, version, NAME_1);
166-
getRepository().create(TYPE, uuid, NAME_1, scl, version, WHO);
167+
168+
var repository = getRepository();
169+
repository.create(TYPE, uuid, NAME_1, scl, version, WHO);
167170

168171
var unknownVersion = new Version(1, 1, 1);
169172
var exception = assertThrows(CompasNoDataFoundException.class, () -> {
170-
getRepository().findByUUID(TYPE, uuid, unknownVersion);
173+
repository.findByUUID(TYPE, uuid, unknownVersion);
171174
});
172175
assertEquals(NO_DATA_FOUND_ERROR_CODE, exception.getErrorCode());
173176
}
@@ -221,8 +224,9 @@ void findMetaInfoByUUID_WhenTwoVersionsOfARecordAdded_ThenLastRecordIsFound() {
221224
void findMetaInfoByUUID_WhenCalledWithUnknownUUID_ThenExceptionIsThrown() {
222225
var uuid = UUID.randomUUID();
223226

227+
var repository = getRepository();
224228
var exception = assertThrows(CompasNoDataFoundException.class, () -> {
225-
getRepository().findMetaInfoByUUID(TYPE, uuid);
229+
repository.findMetaInfoByUUID(TYPE, uuid);
226230
});
227231
assertEquals(NO_DATA_FOUND_ERROR_CODE, exception.getErrorCode());
228232
}
@@ -283,14 +287,15 @@ void createAndDelete_WhenSclAddedAndDelete_ThenScLStoredAndRemoved() {
283287
var uuid = UUID.randomUUID();
284288
var scl = readSCL(uuid, version, NAME_1);
285289

286-
getRepository().create(TYPE, uuid, NAME_1, scl, version, WHO);
287-
var foundScl = getRepository().findByUUID(TYPE, uuid);
290+
var repository = getRepository();
291+
repository.create(TYPE, uuid, NAME_1, scl, version, WHO);
292+
var foundScl = repository.findByUUID(TYPE, uuid);
288293
assertNotNull(foundScl);
289294
assertEquals(getIdFromHeader(scl), getIdFromHeader(foundScl));
290295

291-
getRepository().delete(TYPE, uuid, version);
296+
repository.delete(TYPE, uuid, version);
292297
var exception = assertThrows(CompasNoDataFoundException.class, () -> {
293-
getRepository().findByUUID(TYPE, uuid);
298+
repository.findByUUID(TYPE, uuid);
294299
});
295300
assertEquals(NO_DATA_FOUND_ERROR_CODE, exception.getErrorCode());
296301
}
@@ -301,22 +306,23 @@ void createAndDeleteAll_WhenSclAddedAndDelete_ThenScLStoredAndRemoved() {
301306
var uuid = UUID.randomUUID();
302307
var scl = readSCL(uuid, version, NAME_1);
303308

304-
getRepository().create(TYPE, uuid, NAME_1, scl, version, WHO);
305-
var foundScl = getRepository().findByUUID(TYPE, uuid);
309+
var repository = getRepository();
310+
repository.create(TYPE, uuid, NAME_1, scl, version, WHO);
311+
var foundScl = repository.findByUUID(TYPE, uuid);
306312
assertNotNull(foundScl);
307313
assertEquals(getIdFromHeader(scl), getIdFromHeader(foundScl));
308314
assertEquals(getVersionFromHeader(scl), getVersionFromHeader(foundScl));
309315

310316
version = version.getNextVersion(ChangeSetType.MAJOR);
311-
getRepository().create(TYPE, uuid, NAME_1, scl, version, WHO);
312-
foundScl = getRepository().findByUUID(TYPE, uuid);
317+
repository.create(TYPE, uuid, NAME_1, scl, version, WHO);
318+
foundScl = repository.findByUUID(TYPE, uuid);
313319
assertNotNull(foundScl);
314320
assertEquals(getIdFromHeader(scl), getIdFromHeader(foundScl));
315321
assertEquals(getVersionFromHeader(scl), getVersionFromHeader(foundScl));
316322

317-
getRepository().delete(TYPE, uuid);
323+
repository.delete(TYPE, uuid);
318324
var exception = assertThrows(CompasNoDataFoundException.class, () -> {
319-
getRepository().findByUUID(TYPE, uuid);
325+
repository.findByUUID(TYPE, uuid);
320326
});
321327
assertEquals(NO_DATA_FOUND_ERROR_CODE, exception.getErrorCode());
322328
}

0 commit comments

Comments
 (0)