Search in sources :

Example 1 with RecordUnlockedException

use of org.openforis.collect.persistence.RecordUnlockedException in project collect by openforis.

the class SessionManager method invalidateSession.

public void invalidateSession() {
    try {
        releaseRecord();
    } catch (RecordUnlockedException e) {
    // do nothing
    }
    GraniteContext graniteContext = GraniteContext.getCurrentInstance();
    if (graniteContext != null && graniteContext instanceof HttpGraniteContext) {
        HttpGraniteContext httpGraniteContext = (HttpGraniteContext) graniteContext;
        HttpServletRequest request = httpGraniteContext.getRequest();
        HttpSession session = request.getSession();
        session.invalidate();
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) GraniteContext(org.granite.context.GraniteContext) HttpGraniteContext(org.granite.messaging.webapp.HttpGraniteContext) HttpSession(javax.servlet.http.HttpSession) RecordUnlockedException(org.openforis.collect.persistence.RecordUnlockedException) HttpGraniteContext(org.granite.messaging.webapp.HttpGraniteContext)

Example 2 with RecordUnlockedException

use of org.openforis.collect.persistence.RecordUnlockedException 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 3 with RecordUnlockedException

use of org.openforis.collect.persistence.RecordUnlockedException in project collect by openforis.

the class SessionManager method checkIsActiveRecordLocked.

public void checkIsActiveRecordLocked() throws RecordUnlockedException {
    SessionState sessionState = getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    if (record == null) {
        throw new RecordUnlockedException();
    } else if (record.getId() != null) {
        User user = sessionState.getUser();
        String lockId = sessionState.getSessionId();
        try {
            recordManager.checkIsLocked(record.getId(), user, lockId);
            sessionState.keepActiveRecordAlive();
        } catch (RecordUnlockedException e) {
            clearActiveRecord();
            throw e;
        }
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordUnlockedException(org.openforis.collect.persistence.RecordUnlockedException)

Aggregations

RecordUnlockedException (org.openforis.collect.persistence.RecordUnlockedException)3 User (org.openforis.collect.model.User)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 HttpSession (javax.servlet.http.HttpSession)1 GraniteContext (org.granite.context.GraniteContext)1 HttpGraniteContext (org.granite.messaging.webapp.HttpGraniteContext)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 RecordLock (org.openforis.collect.model.RecordLock)1 SessionState (org.openforis.collect.web.session.SessionState)1