Skip to content

Commit 0f3e5e0

Browse files
committed
code cleanup
1 parent 2f307e3 commit 0f3e5e0

File tree

4 files changed

+65
-47
lines changed

4 files changed

+65
-47
lines changed

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/ScreenshotDataDAO.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,8 +70,8 @@ Result<Long> save(
7070

7171
Result<Long> countDistinctMetadataWindowForExam(String metadataApplication, List<Long> groupIds);
7272

73-
Result<Collection<UserListForApplicationSearch>> getUserListForApplicationSearch(String metadataWindowTitle, String metadataApplication, List<Long> groupIds);
73+
Result<List<UserListForApplicationSearch>> getUserListForApplicationSearch(String metadataWindowTitle, String metadataApplication, List<Long> groupIds);
7474

75-
Result<Collection<Long>> getTimestampListForApplicationSearch(final String sessionUuid, final String metadataApplication, final String metadataWindowTitle);
75+
Result<List<Long>> getTimestampListForApplicationSearch(String sessionUuid, String metadataApplication, String metadataWindowTitle);
7676

7777
}

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/impl/ScreenshotDAOBatis.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.io.InputStream;
1414
import java.util.List;
1515

16+
import org.slf4j.Logger;
17+
import org.slf4j.LoggerFactory;
1618
import org.springframework.boot.autoconfigure.condition.ConditionalOnExpression;
1719
import org.springframework.context.event.EventListener;
1820
import org.springframework.stereotype.Service;
@@ -31,6 +33,8 @@
3133
@ConditionalOnExpression("'${sps.data.store.adapter}'.equals('FULL_RDBMS')")
3234
public class ScreenshotDAOBatis implements ScreenshotDAO {
3335

36+
private static final Logger log = LoggerFactory.getLogger(ScreenshotDAOBatis.class);
37+
3438
private final ScreenshotMapper screenshotMapper;
3539
private final ScreenshotRecordMapper screenshotRecordMapper;
3640

@@ -52,11 +56,17 @@ public void init() {
5256
public Result<InputStream> getImage(
5357
final Long pk,
5458
final String sessionUUID) {
55-
56-
return Result.tryCatch(() ->
57-
this.screenshotMapper
58-
.selectScreenshotByPK(pk)
59-
.getImage());
59+
60+
return Result.tryCatch(() -> {
61+
BlobContent blobContent = this.screenshotMapper.selectScreenshotByPK(pk);
62+
if (blobContent == null) {
63+
log.warn("No screenshot with id: {} found on session {}", pk, sessionUUID);
64+
return InputStream.nullInputStream();
65+
}
66+
return blobContent.getImage();
67+
});
68+
69+
6070
}
6171

6272
//todo: discuss if we have to remove this method

src/main/java/ch/ethz/seb/sps/server/datalayer/dao/impl/ScreenshotDataDAOBatis.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,9 @@ public Result<Map<String, ScreenshotDataRecord>> allLatestIn(final List<String>
271271
return sessionUUIDs.stream()
272272
.map(this::getLatestScreenshotDataRec)
273273
.filter(Objects::nonNull)
274-
.collect(Collectors.toMap(r -> r.getSessionUuid(), Function.identity()));
274+
.collect(Collectors.toMap(
275+
ScreenshotDataRecord::getSessionUuid,
276+
Function.identity()));
275277
});
276278
}
277279

@@ -364,8 +366,7 @@ public Result<Collection<ScreenshotDataRecord>> searchScreenshotData(final Filte
364366
// group constraint
365367
if (groupPKs != null) {
366368
if (groupPKs.contains(Constants.LIST_SEPARATOR)) {
367-
final List<Long> pksAsList = Arrays.asList(StringUtils.split(groupPKs, Constants.LIST_SEPARATOR))
368-
.stream()
369+
final List<Long> pksAsList = Arrays.stream(StringUtils.split(groupPKs, Constants.LIST_SEPARATOR))
369370
.map(Long::parseLong)
370371
.collect(Collectors.toList());
371372
queryBuilder = queryBuilder.and(
@@ -484,7 +485,7 @@ public Result<ScreenshotData> createNew(final ScreenshotData data) {
484485
@Transactional
485486
public Result<ScreenshotData> save(final ScreenshotData data) {
486487
return save(data.sessionUUID, data.timestamp, data.imageFormat, data.metaData)
487-
.map(pk -> this.screenshotDataRecordMapper.selectByPrimaryKey(pk))
488+
.map(this.screenshotDataRecordMapper::selectByPrimaryKey)
488489
.map(this::toDomainModel);
489490
}
490491

@@ -631,7 +632,11 @@ public Result<Long> countDistinctMetadataWindowForExam(final String metadataAppl
631632

632633
@Override
633634
@Transactional(readOnly = true)
634-
public Result<Collection<UserListForApplicationSearch>> getUserListForApplicationSearch(final String metadataApplication, final String metadataWindowTitle, final List<Long> groupIds) {
635+
public Result<List<UserListForApplicationSearch>> getUserListForApplicationSearch(
636+
final String metadataApplication,
637+
final String metadataWindowTitle,
638+
final List<Long> groupIds) {
639+
635640
return Result.tryCatch(() -> {
636641

637642
final String metadataAppValue = createMetadataSearchString(API.SCREENSHOT_META_DATA_APPLICATION, metadataApplication);
@@ -665,7 +670,11 @@ public Result<Collection<UserListForApplicationSearch>> getUserListForApplicatio
665670

666671
@Override
667672
@Transactional(readOnly = true)
668-
public Result<Collection<Long>> getTimestampListForApplicationSearch(final String sessionUuid, final String metadataApplication, final String metadataWindowTitle) {
673+
public Result<List<Long>> getTimestampListForApplicationSearch(
674+
final String sessionUuid,
675+
final String metadataApplication,
676+
final String metadataWindowTitle) {
677+
669678
return Result.tryCatch(() -> {
670679

671680
final String metadataAppValue = createMetadataSearchString(API.SCREENSHOT_META_DATA_APPLICATION, metadataApplication);

src/main/java/ch/ethz/seb/sps/server/weblayer/AdminProctorController.java

Lines changed: 33 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,16 @@ public Collection<GroupSessionCount> getActivateGroupSessionCounts() {
110110

111111
@Operation(
112112
summary = "Get a page of all groups the requesting user can access for proctoring",
113-
description = "Sorting: the sort parameter to sort the list of entities before paging\n"
114-
+ "the sort parameter is the name of the entity-model attribute to sort with a leading '-' sign for\n"
115-
+ "descending sort order. Note that not all entity-model attribute are suited for sorting while the most\n"
116-
+ "are.\n"
117-
+ "</p>\n"
118-
+ "Filter: The filter attributes accepted by this API depend on the actual entity model (domain object)\n"
119-
+ "and are of the form [domain-attribute-name]=[filter-value]. E.g.: name=abc or type=EXAM. Usually\n"
120-
+ "filter attributes of text type are treated as SQL wildcard with %[text]% to filter all text containing\n"
121-
+ "a given text-snippet.",
113+
description = """
114+
Sorting: the sort parameter to sort the list of entities before paging
115+
the sort parameter is the name of the entity-model attribute to sort with a leading '-' sign for
116+
descending sort order. Note that not all entity-model attribute are suited for sorting while the most
117+
are.
118+
</p>
119+
Filter: The filter attributes accepted by this API depend on the actual entity model (domain object)
120+
and are of the form [domain-attribute-name]=[filter-value]. E.g.: name=abc or type=EXAM. Usually
121+
filter attributes of text type are treated as SQL wildcard with %[text]% to filter all text containing
122+
a given text-snippet.""",
122123
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
123124
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
124125
parameters = {
@@ -167,15 +168,16 @@ public Page<GroupViewData> getGroups(
167168

168169
@Operation(
169170
summary = "Get a page of screen proctoring session data of a given group",
170-
description = "Sorting: the sort parameter to sort the list of entities before paging\n"
171-
+ "the sort parameter is the name of the entity-model attribute to sort with a leading '-' sign for\n"
172-
+ "descending sort order. Note that not all entity-model attribute are suited for sorting while the most\n"
173-
+ "are.\n"
174-
+ "</p>\n"
175-
+ "Filter: The filter attributes accepted by this API depend on the actual entity model (domain object)\n"
176-
+ "and are of the form [domain-attribute-name]=[filter-value]. E.g.: name=abc or type=EXAM. Usually\n"
177-
+ "filter attributes of text type are treated as SQL wildcard with %[text]% to filter all text containing\n"
178-
+ "a given text-snippet.",
171+
description = """
172+
Sorting: the sort parameter to sort the list of entities before paging
173+
the sort parameter is the name of the entity-model attribute to sort with a leading '-' sign for
174+
descending sort order. Note that not all entity-model attribute are suited for sorting while the most
175+
are.
176+
</p>
177+
Filter: The filter attributes accepted by this API depend on the actual entity model (domain object)
178+
and are of the form [domain-attribute-name]=[filter-value]. E.g.: name=abc or type=EXAM. Usually
179+
filter attributes of text type are treated as SQL wildcard with %[text]% to filter all text containing
180+
a given text-snippet.""",
179181
requestBody = @io.swagger.v3.oas.annotations.parameters.RequestBody(
180182
content = { @Content(mediaType = MediaType.APPLICATION_FORM_URLENCODED_VALUE) }),
181183
parameters = {
@@ -196,12 +198,11 @@ public Page<GroupViewData> getGroups(
196198
description = "The sorting order"),
197199
@Parameter(
198200
name = "filterCriteria",
199-
description = "Additional search filter criteria \n" +
200-
"This is a collecting map of all request parameter and used by the method to extract "
201-
+
202-
"known search filter criteria and if available in the mapping use it for the search request\n"
203-
+
204-
"NOTE: For OpenAPI 3 input please use the form: {\"columnName\":\"filterValue\"}",
201+
description = """
202+
Additional search filter criteria\s
203+
This is a collecting map of all request parameter and used by the method to extract \
204+
known search filter criteria and if available in the mapping use it for the search request
205+
NOTE: For OpenAPI 3 input please use the form: {"columnName":"filterValue"}""",
205206
example = "{\"active\":true}",
206207
required = false,
207208
allowEmptyValue = true)
@@ -973,10 +974,9 @@ public List<UserListForApplicationSearch> getUserListForApplicationSearch(
973974
@RequestParam(name = API.SCREENSHOT_META_DATA_ACTIVE_WINDOW_TITLE, required = true) final String metadataWindowTitle,
974975
@RequestParam(name = API.PARAM_GROUP_IDS, required = true) final String groupIds){
975976

976-
return this.screenshotDataDAO.getUserListForApplicationSearch(metadataApplication, metadataWindowTitle, getIdListFromParameter(groupIds))
977-
.getOrThrow()
978-
.stream()
979-
.toList();
977+
return this.screenshotDataDAO
978+
.getUserListForApplicationSearch(metadataApplication, metadataWindowTitle, getIdListFromParameter(groupIds))
979+
.getOrThrow();
980980
}
981981

982982
@Operation(
@@ -1005,10 +1005,9 @@ public List<Long> getTimestampListForApplicationSearch(
10051005
@RequestParam(name = API.SCREENSHOT_META_DATA_APPLICATION, required = true) final String metadataApplication,
10061006
@RequestParam(name = API.SCREENSHOT_META_DATA_ACTIVE_WINDOW_TITLE, required = true) final String metadataWindowTitle){
10071007

1008-
return this.screenshotDataDAO.getTimestampListForApplicationSearch(sessionUuid, metadataApplication, metadataWindowTitle)
1009-
.getOrThrow()
1010-
.stream()
1011-
.toList();
1008+
return this.screenshotDataDAO
1009+
.getTimestampListForApplicationSearch(sessionUuid, metadataApplication, metadataWindowTitle)
1010+
.getOrThrow();
10121011
}
10131012

10141013

@@ -1058,8 +1057,8 @@ private List<Long> getIdListFromParameter(final String ids){
10581057
String[] idsString = StringUtils.split(ids, Constants.LIST_SEPARATOR_CHAR);
10591058
List<Long> idsList = new ArrayList<>();
10601059

1061-
for(int i = 0; i < idsString.length; i++){
1062-
idsList.add(Long.parseLong(idsString[i]));
1060+
for (String s : idsString) {
1061+
idsList.add(Long.parseLong(s));
10631062
}
10641063

10651064
return idsList;

0 commit comments

Comments
 (0)