Further improvements over multiple lock handling

This commit is contained in:
George Kalampokis 2020-02-14 11:08:26 +02:00
parent c82b7ed0b7
commit ec0901e791
1 changed files with 4 additions and 1 deletions

View File

@ -95,12 +95,15 @@ public class LockManager {
LockCriteria criteria = new LockCriteria();
criteria.setTarget(UUID.fromString(targetId));
Long availableLocks = this.apiContext.getOperationsContext().getDatabaseRepository().getLockDao().getWithCriteria(criteria).count();
if (availableLocks > 0) {
if (availableLocks == 1) {
eu.eudat.data.entities.Lock lock = this.apiContext.getOperationsContext().getDatabaseRepository().getLockDao().getWithCriteria(criteria).getSingle();
if (!lock.getLockedBy().getId().equals(principal.getId())) {
throw new Exception("Only the user who created that lock can delete it");
}
this.apiContext.getOperationsContext().getDatabaseRepository().getLockDao().delete(lock);
} else if (availableLocks > 1) {
List<eu.eudat.data.entities.Lock> locks = this.apiContext.getOperationsContext().getDatabaseRepository().getLockDao().getWithCriteria(criteria).toList();
locks.stream().filter(lock -> lock.getLockedBy().getId().equals(principal.getId())).forEach(lock -> this.apiContext.getOperationsContext().getDatabaseRepository().getLockDao().delete(lock));
}
}