Search in sources :

Example 6 with RecordLock

use of org.openforis.collect.model.RecordLock in project collect by openforis.

the class RecordLockManager method checkIsLocked.

public synchronized boolean checkIsLocked(int recordId, User user, String sessionId) throws RecordUnlockedException {
    RecordLock lock = getLock(recordId);
    String lockUserName = null;
    if (lock != null) {
        String lockSessionId = lock.getSessionId();
        int lockRecordId = lock.getRecordId();
        User lUser = lock.getUser();
        if (recordId == lockRecordId && (lUser == user || lUser.getId().equals(user.getId())) && lockSessionId.equals(sessionId)) {
            lock.keepAlive();
            return true;
        } else {
            User lockUser = lock.getUser();
            lockUserName = lockUser.getUsername();
        }
    }
    throw new RecordUnlockedException(lockUserName);
}
Also used : User(org.openforis.collect.model.User) RecordLock(org.openforis.collect.model.RecordLock) RecordUnlockedException(org.openforis.collect.persistence.RecordUnlockedException)

Example 7 with RecordLock

use of org.openforis.collect.model.RecordLock in project collect by openforis.

the class RecordLockManager method clearInactiveLocks.

private synchronized void clearInactiveLocks() {
    Set<Entry<Integer, RecordLock>> entrySet = locks.entrySet();
    Iterator<Entry<Integer, RecordLock>> iterator = entrySet.iterator();
    while (iterator.hasNext()) {
        Entry<Integer, RecordLock> entry = iterator.next();
        RecordLock lock = entry.getValue();
        if (!lock.isActive()) {
            iterator.remove();
        }
    }
}
Also used : Entry(java.util.Map.Entry) RecordLock(org.openforis.collect.model.RecordLock)

Aggregations

RecordLock (org.openforis.collect.model.RecordLock)7 User (org.openforis.collect.model.User)2 RecordLockedException (org.openforis.collect.persistence.RecordLockedException)2 Entry (java.util.Map.Entry)1 MultipleEditException (org.openforis.collect.persistence.MultipleEditException)1 RecordLockedByActiveUserException (org.openforis.collect.persistence.RecordLockedByActiveUserException)1 RecordUnlockedException (org.openforis.collect.persistence.RecordUnlockedException)1 Transactional (org.springframework.transaction.annotation.Transactional)1