Further improvements over multiple lock handling
This commit is contained in:
parent
c82b7ed0b7
commit
ec0901e791
|
@ -95,12 +95,15 @@ public class LockManager {
|
||||||
LockCriteria criteria = new LockCriteria();
|
LockCriteria criteria = new LockCriteria();
|
||||||
criteria.setTarget(UUID.fromString(targetId));
|
criteria.setTarget(UUID.fromString(targetId));
|
||||||
Long availableLocks = this.apiContext.getOperationsContext().getDatabaseRepository().getLockDao().getWithCriteria(criteria).count();
|
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();
|
eu.eudat.data.entities.Lock lock = this.apiContext.getOperationsContext().getDatabaseRepository().getLockDao().getWithCriteria(criteria).getSingle();
|
||||||
if (!lock.getLockedBy().getId().equals(principal.getId())) {
|
if (!lock.getLockedBy().getId().equals(principal.getId())) {
|
||||||
throw new Exception("Only the user who created that lock can delete it");
|
throw new Exception("Only the user who created that lock can delete it");
|
||||||
}
|
}
|
||||||
this.apiContext.getOperationsContext().getDatabaseRepository().getLockDao().delete(lock);
|
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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue