Search in sources :

Example 1 with RecordLock

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

the class RecordLockManager method getLockBySessionId.

private synchronized RecordLock getLockBySessionId(String sessionId) {
    clearInactiveLocks();
    Collection<RecordLock> lcks = locks.values();
    for (RecordLock l : lcks) {
        if (l.getSessionId().equals(sessionId)) {
            return l;
        }
    }
    return null;
}
Also used : RecordLock(org.openforis.collect.model.RecordLock)

Example 2 with RecordLock

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

the class RecordLockManager method isLockAllowed.

public synchronized boolean isLockAllowed(User user, int recordId, String sessionId, boolean forceUnlock) throws RecordLockedException, MultipleEditException {
    RecordLock uLock = getLockBySessionId(sessionId);
    if (uLock != null) {
        throw new MultipleEditException("User is editing another record: " + uLock.getRecordId());
    }
    RecordLock lock = getLock(recordId);
    if (lock == null || (forceUnlock && isForceUnlockAllowed(user, lock))) {
        return true;
    } else if (lock.getUser().getId().equals(user.getId())) {
        throw new RecordLockedByActiveUserException(user.getUsername());
    } else {
        String lockingUserName = lock.getUser().getUsername();
        throw new RecordLockedException("Record already locked", lockingUserName);
    }
}
Also used : RecordLockedException(org.openforis.collect.persistence.RecordLockedException) RecordLock(org.openforis.collect.model.RecordLock) RecordLockedByActiveUserException(org.openforis.collect.persistence.RecordLockedByActiveUserException) MultipleEditException(org.openforis.collect.persistence.MultipleEditException)

Example 3 with RecordLock

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

the class RecordLockManager method lock.

public synchronized void lock(int recordId, User user, String sessionId, boolean forceUnlock) throws RecordLockedException, MultipleEditException {
    RecordLock oldLock = getLock(recordId);
    if (oldLock != null) {
        locks.remove(recordId);
    }
    RecordLock lock = new RecordLock(sessionId, recordId, user, timeoutMillis);
    locks.put(recordId, lock);
}
Also used : RecordLock(org.openforis.collect.model.RecordLock)

Example 4 with RecordLock

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

the class RecordLockManager method getLock.

public synchronized RecordLock getLock(int recordId) {
    clearInactiveLocks();
    RecordLock lock = locks.get(recordId);
    return lock;
}
Also used : RecordLock(org.openforis.collect.model.RecordLock)

Example 5 with RecordLock

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

the class RecordManager method delete.

@Transactional(readOnly = false, propagation = REQUIRED)
public void delete(int recordId) throws RecordPersistenceException {
    if (isLockingEnabled() && lockManager.isLocked(recordId)) {
        RecordLock lock = lockManager.getLock(recordId);
        User lockUser = lock.getUser();
        throw new RecordLockedException(lockUser.getUsername());
    } else {
        recordDao.delete(recordId);
    }
}
Also used : User(org.openforis.collect.model.User) RecordLockedException(org.openforis.collect.persistence.RecordLockedException) RecordLock(org.openforis.collect.model.RecordLock) Transactional(org.springframework.transaction.annotation.Transactional)

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