Search in sources :

Example 16 with SessionState

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

the class BackupService method getBackup.

private BackupProcess getBackup(String rootEntityName) throws Exception {
    SessionState sessionState = sessionManager.getSessionState();
    CollectSurvey survey = sessionState.getActiveSurvey();
    Integer surveyId = survey.getId();
    Map<String, BackupProcess> backupsPerSurvey = backups.get(surveyId);
    if (backupsPerSurvey == null) {
        backupsPerSurvey = new HashMap<String, BackupProcess>();
        backups.put(surveyId, backupsPerSurvey);
    }
    BackupProcess backup = backupsPerSurvey.get(rootEntityName);
    if (backup == null) {
        int[] stepNumbers = { 1, 2, 3 };
        backup = new BackupProcess(surveyManager, recordManager, dataMarshaller, backupDirectory, survey, rootEntityName, stepNumbers);
        backupsPerSurvey.put(rootEntityName, backup);
    }
    return backup;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) BackupProcess(org.openforis.collect.remoting.service.backup.BackupProcess) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 17 with SessionState

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

the class SessionManager method clearActiveRecord.

public void clearActiveRecord() {
    SessionState sessionState = getSessionState();
    sessionState.setActiveRecord(null);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState)

Example 18 with SessionState

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

the class SessionManager method createSessionState.

public void createSessionState(HttpSession session) {
    String sessionId = session.getId();
    boolean developmentMode = CollectConfiguration.isDevelopmentMode();
    SessionState sessionState = new SessionState(sessionId);
    if (developmentMode) {
        sessionState.setUser(userManager.loadAdminUser());
    // sessionState.setUser(userManager.loadByUserName("view"));
    // sessionState.setUser(userManager.loadByUserName("entry"));
    }
    session.setAttribute(SessionState.SESSION_ATTRIBUTE_NAME, sessionState);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState)

Example 19 with SessionState

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

the class SessionManager method releaseRecord.

public void releaseRecord() throws RecordUnlockedException {
    checkIsActiveRecordLocked();
    SessionState sessionState = getSessionState();
    CollectRecord activeRecord = sessionState.getActiveRecord();
    if (activeRecord != null && activeRecord.getId() != null) {
        recordManager.releaseLock(activeRecord.getId());
    }
    sessionState.setActiveRecord(null);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord)

Example 20 with SessionState

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

the class RecordController method moveRecords.

@RequestMapping(value = "survey/{surveyId}/data/move/records", method = POST, produces = APPLICATION_JSON_VALUE)
@ResponseBody
public JobProxy moveRecords(@PathVariable("surveyId") int surveyId, @RequestParam String fromStep, @RequestParam boolean promote) {
    BulkRecordMoveJob job = jobManager.createJob(BulkRecordMoveJob.class);
    SessionState sessionState = sessionManager.getSessionState();
    User loggedUser = sessionState.getUser();
    CollectSurvey survey = surveyManager.getById(surveyId);
    EntityDefinition rootEntityDef = survey.getSchema().getFirstRootEntityDefinition();
    job.setSurvey(survey);
    job.setRootEntity(rootEntityDef.getName());
    job.setPromote(promote);
    job.setFromStep(Step.valueOf(fromStep));
    job.setUser(loggedUser);
    job.setRecordMovedCallback(new BulkRecordMoveJob.Callback() {

        @Override
        public void recordMoved(CollectRecord record) {
            if (promote) {
                publishRecordPromotedEvents(record, loggedUser.getUsername());
            } else {
                publishRecordDeletedEvent(record, RecordStep.valueOf(fromStep), loggedUser.getUsername());
            }
        }
    });
    jobManager.startSurveyJob(job);
    return new JobProxy(job);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) JobProxy(org.openforis.concurrency.proxy.JobProxy) CollectSurvey(org.openforis.collect.model.CollectSurvey) BulkRecordMoveJob(org.openforis.collect.io.data.BulkRecordMoveJob) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) ResponseBody(org.springframework.web.bind.annotation.ResponseBody)

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