code cleanup
This commit is contained in:
parent
1498fa4150
commit
6ad231f1ed
1 changed files with 19 additions and 22 deletions
|
@ -262,8 +262,7 @@ public class ExamDAOImpl implements ExamDAO {
|
||||||
return Result.tryCatch(() -> {
|
return Result.tryCatch(() -> {
|
||||||
|
|
||||||
final List<String> stateNames = (status != null && status.length > 0)
|
final List<String> stateNames = (status != null && status.length > 0)
|
||||||
? Arrays.asList(status)
|
? Arrays.stream(status).map(Enum::name)
|
||||||
.stream().map(s -> s.name())
|
|
||||||
.collect(Collectors.toList())
|
.collect(Collectors.toList())
|
||||||
: null;
|
: null;
|
||||||
return this.examRecordDAO
|
return this.examRecordDAO
|
||||||
|
@ -443,7 +442,7 @@ public class ExamDAOImpl implements ExamDAO {
|
||||||
|
|
||||||
if (lockedRecords != null && !lockedRecords.isEmpty()) {
|
if (lockedRecords != null && !lockedRecords.isEmpty()) {
|
||||||
final long millisecondsNow = Utils.getMillisecondsNow();
|
final long millisecondsNow = Utils.getMillisecondsNow();
|
||||||
lockedRecords.stream().forEach(record -> {
|
lockedRecords.forEach(record -> {
|
||||||
try {
|
try {
|
||||||
final String lastUpdateString = record.getLastupdate();
|
final String lastUpdateString = record.getLastupdate();
|
||||||
if (StringUtils.isNotBlank(lastUpdateString)) {
|
if (StringUtils.isNotBlank(lastUpdateString)) {
|
||||||
|
@ -454,7 +453,7 @@ public class ExamDAOImpl implements ExamDAO {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
log.warn("Failed to release aged write lock for exam: {} cause:", record, e.getMessage());
|
log.warn("Failed to release aged write lock for exam: {} cause: {}", record, e.getMessage());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -522,7 +521,7 @@ public class ExamDAOImpl implements ExamDAO {
|
||||||
return Collections.emptyList();
|
return Collections.emptyList();
|
||||||
}
|
}
|
||||||
|
|
||||||
// notify exam deletion listener about following deletion, to cleanup stuff before deletion
|
// notify exam deletion listener about following deletion, to clean up stuff before deletion
|
||||||
this.applicationEventPublisher.publishEvent(new ExamDeletionEvent(ids));
|
this.applicationEventPublisher.publishEvent(new ExamDeletionEvent(ids));
|
||||||
|
|
||||||
this.examRecordMapper.deleteByExample()
|
this.examRecordMapper.deleteByExample()
|
||||||
|
@ -531,8 +530,7 @@ public class ExamDAOImpl implements ExamDAO {
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
// delete all additional attributes
|
// delete all additional attributes
|
||||||
ids.stream()
|
ids.forEach(id -> this.additionalAttributesDAO.deleteAll(EntityType.EXAM, id));
|
||||||
.forEach(id -> this.additionalAttributesDAO.deleteAll(EntityType.EXAM, id));
|
|
||||||
|
|
||||||
return ids.stream()
|
return ids.stream()
|
||||||
.map(id -> new EntityKey(id, EntityType.EXAM))
|
.map(id -> new EntityKey(id, EntityType.EXAM))
|
||||||
|
@ -549,7 +547,7 @@ public class ExamDAOImpl implements ExamDAO {
|
||||||
}
|
}
|
||||||
|
|
||||||
// define the select function in case of source type
|
// define the select function in case of source type
|
||||||
Function<EntityKey, Result<Collection<EntityDependency>>> selectionFunction;
|
final Function<EntityKey, Result<Collection<EntityDependency>>> selectionFunction;
|
||||||
switch (bulkAction.sourceType) {
|
switch (bulkAction.sourceType) {
|
||||||
case INSTITUTION:
|
case INSTITUTION:
|
||||||
selectionFunction = this::allIdsOfInstitution;
|
selectionFunction = this::allIdsOfInstitution;
|
||||||
|
@ -744,11 +742,9 @@ public class ExamDAOImpl implements ExamDAO {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result<Collection<Exam>> toDomainModel(final Collection<ExamRecord> records) {
|
private Result<Collection<Exam>> toDomainModel(final Collection<ExamRecord> records) {
|
||||||
return Result.tryCatch(() -> {
|
return Result.tryCatch(() -> records.stream()
|
||||||
return records.stream()
|
.map(rec -> this.toDomainModel(rec).getOrThrow())
|
||||||
.map(rec -> this.toDomainModel(rec).getOrThrow())
|
.collect(Collectors.toList()));
|
||||||
.collect(Collectors.toList());
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Result<Exam> toDomainModel(final ExamRecord record) {
|
private Result<Exam> toDomainModel(final ExamRecord record) {
|
||||||
|
@ -771,7 +767,9 @@ public class ExamDAOImpl implements ExamDAO {
|
||||||
.getAdditionalAttributes(EntityType.EXAM, record.getId())
|
.getAdditionalAttributes(EntityType.EXAM, record.getId())
|
||||||
.getOrThrow()
|
.getOrThrow()
|
||||||
.stream()
|
.stream()
|
||||||
.collect(Collectors.toMap(rec -> rec.getName(), rec -> rec.getValue()));
|
.collect(Collectors.toMap(
|
||||||
|
AdditionalAttributeRecord::getName,
|
||||||
|
AdditionalAttributeRecord::getValue));
|
||||||
|
|
||||||
return new Exam(
|
return new Exam(
|
||||||
record.getId(),
|
record.getId(),
|
||||||
|
@ -824,21 +822,20 @@ public class ExamDAOImpl implements ExamDAO {
|
||||||
additionalAttributes.put(QuizData.QUIZ_ATTR_START_URL, quizData.startURL);
|
additionalAttributes.put(QuizData.QUIZ_ATTR_START_URL, quizData.startURL);
|
||||||
}
|
}
|
||||||
|
|
||||||
additionalAttributes.entrySet().forEach(entry -> {
|
additionalAttributes.forEach((key, value) -> {
|
||||||
final String value = entry.getValue();
|
|
||||||
if (value == null) {
|
if (value == null) {
|
||||||
this.additionalAttributesDAO.delete(
|
this.additionalAttributesDAO.delete(
|
||||||
EntityType.EXAM,
|
EntityType.EXAM,
|
||||||
examId,
|
examId,
|
||||||
entry.getKey());
|
key);
|
||||||
} else {
|
} else {
|
||||||
this.additionalAttributesDAO.saveAdditionalAttribute(
|
this.additionalAttributesDAO.saveAdditionalAttribute(
|
||||||
EntityType.EXAM,
|
EntityType.EXAM,
|
||||||
examId,
|
examId,
|
||||||
entry.getKey(),
|
key,
|
||||||
value)
|
value)
|
||||||
.onError(error -> log.error("Failed to save additional quiz attribute: {}",
|
.onError(error -> log.error("Failed to save additional quiz attribute: {}",
|
||||||
entry.getKey(),
|
key,
|
||||||
error));
|
error));
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue