Search in sources :

Example 6 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class DataService method promote.

protected void promote(Step to) throws RecordPersistenceException, RecordPromoteException {
    sessionManager.checkIsActiveRecordLocked();
    SessionState sessionState = sessionManager.getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    String userName = sessionState.getUser().getUsername();
    Step currentStep = record.getStep();
    Step exptectedStep = to.getPrevious();
    if (exptectedStep == currentStep) {
        User user = sessionState.getUser();
        sessionEventDispatcher.recordSaved(record);
        recordManager.promote(record, user);
        publishRecordPromotedEvents(record, userName);
        recordManager.releaseLock(record.getId());
        sessionManager.clearActiveRecord();
        if (isCurrentRecordIndexable()) {
            recordIndexService.permanentlyIndex(record);
        }
    } else {
        throw new IllegalStateException("The active record cannot be submitted: it is not in the exptected phase: " + exptectedStep);
    }
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) RecordStep(org.openforis.collect.event.RecordStep) Step(org.openforis.collect.model.CollectRecord.Step)

Example 7 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class DataService method getCurrentLocale.

protected Locale getCurrentLocale() {
    SessionState sessionState = getSessionState();
    Locale locale = sessionState.getLocale();
    return locale;
}
Also used : Locale(java.util.Locale) SessionState(org.openforis.collect.web.session.SessionState)

Example 8 with SessionState

use of org.openforis.collect.web.session.SessionState 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 9 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class DataService method moveNode.

@Secured(ENTRY_LIMITED)
public void moveNode(int nodeId, int index) {
    SessionState sessionState = sessionManager.getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    recordManager.moveNode(record, nodeId, index);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) Secured(org.springframework.security.access.annotation.Secured)

Example 10 with SessionState

use of org.openforis.collect.web.session.SessionState in project collect by openforis.

the class DataService method deleteRecord.

@Transactional
@Secured(ENTRY)
public void deleteRecord(int id) throws RecordPersistenceException {
    SessionState sessionState = sessionManager.getSessionState();
    CollectSurvey survey = sessionState.getActiveSurvey();
    String userName = sessionState.getUser().getUsername();
    CollectRecord record = recordManager.load(survey, id);
    if (record.getStep() != Step.ENTRY) {
        throw new IllegalStateException("Cannot delete a record not in ENTRY phase");
    }
    fileManager.deleteAllFiles(record);
    recordManager.delete(id);
    publishRecordDeletedEvent(record, record.getStep().toRecordStep(), userName);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

SessionState (org.openforis.collect.web.session.SessionState)44 CollectSurvey (org.openforis.collect.model.CollectSurvey)18 User (org.openforis.collect.model.User)16 CollectRecord (org.openforis.collect.model.CollectRecord)15 Secured (org.springframework.security.access.annotation.Secured)13 Step (org.openforis.collect.model.CollectRecord.Step)8 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)8 RecordFilter (org.openforis.collect.model.RecordFilter)7 Locale (java.util.Locale)5 RecordStep (org.openforis.collect.event.RecordStep)5 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)5 File (java.io.File)3 HashMap (java.util.HashMap)3 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)3 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)3 Transactional (org.springframework.transaction.annotation.Transactional)3 IOException (java.io.IOException)2 Date (java.util.Date)2 ServletOutputStream (javax.servlet.ServletOutputStream)2 BulkRecordMoveJob (org.openforis.collect.io.data.BulkRecordMoveJob)2