Search in sources :

Example 1 with MultipleEditException

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

the class DataService method checkoutRecord.

@Secured(ENTRY_LIMITED)
public RecordProxy checkoutRecord(int id, Integer stepNumber, boolean forceUnlock) throws RecordPersistenceException, RecordIndexException {
    SessionState sessionState = sessionManager.getSessionState();
    if (sessionState.isActiveRecordBeingEdited()) {
        throw new MultipleEditException();
    }
    final CollectSurvey survey = sessionState.getActiveSurvey();
    User user = sessionState.getUser();
    Step step = stepNumber == null ? null : Step.valueOf(stepNumber);
    CollectRecord record = step == null ? recordManager.checkout(survey, user, id, sessionState.getSessionId(), forceUnlock) : recordManager.checkout(survey, user, id, step, sessionState.getSessionId(), forceUnlock);
    sessionManager.setActiveRecord(record);
    prepareRecordIndexing();
    return toProxy(record);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) MultipleEditException(org.openforis.collect.persistence.MultipleEditException) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

Example 2 with MultipleEditException

use of org.openforis.collect.persistence.MultipleEditException 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 MultipleEditException

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

the class DataService method createRecord.

@Secured(ENTRY)
public RecordProxy createRecord(String rootEntityName, String versionName, Step recordStep) throws RecordPersistenceException, RecordIndexException {
    SessionState sessionState = sessionManager.getSessionState();
    if (sessionState.isActiveRecordBeingEdited()) {
        throw new MultipleEditException();
    }
    CollectSurvey activeSurvey = sessionState.getActiveSurvey();
    User user = sessionState.getUser();
    CollectRecord record = recordManager.instantiateRecord(activeSurvey, rootEntityName, user, versionName, recordStep);
    NodeChangeSet changeSet = recordManager.initializeRecord(record);
    List<RecordEvent> events = new EventProducer().produceFor(changeSet, user.getUsername());
    sessionManager.onEvents(events);
    sessionManager.setActiveRecord(record);
    prepareRecordIndexing();
    RecordProxy recordProxy = new RecordProxy(record, getProxyContext(), true);
    return recordProxy;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) NodeChangeSet(org.openforis.collect.model.NodeChangeSet) RecordProxy(org.openforis.collect.model.proxy.RecordProxy) User(org.openforis.collect.model.User) EventProducer(org.openforis.collect.event.EventProducer) MultipleEditException(org.openforis.collect.persistence.MultipleEditException) RecordEvent(org.openforis.collect.event.RecordEvent) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

Aggregations

MultipleEditException (org.openforis.collect.persistence.MultipleEditException)3 CollectRecord (org.openforis.collect.model.CollectRecord)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 User (org.openforis.collect.model.User)2 SessionState (org.openforis.collect.web.session.SessionState)2 Secured (org.springframework.security.access.annotation.Secured)2 EventProducer (org.openforis.collect.event.EventProducer)1 RecordEvent (org.openforis.collect.event.RecordEvent)1 RecordStep (org.openforis.collect.event.RecordStep)1 Step (org.openforis.collect.model.CollectRecord.Step)1 NodeChangeSet (org.openforis.collect.model.NodeChangeSet)1 RecordLock (org.openforis.collect.model.RecordLock)1 RecordProxy (org.openforis.collect.model.proxy.RecordProxy)1 RecordLockedByActiveUserException (org.openforis.collect.persistence.RecordLockedByActiveUserException)1 RecordLockedException (org.openforis.collect.persistence.RecordLockedException)1