Search in sources :

Example 26 with SessionState

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

the class DataImportService method getSummary.

@Secured(CLEANSING)
public DataImportSummaryProxy getSummary() {
    if (summaryJob != null) {
        DataImportSummary summary = summaryJob.getSummary();
        SessionState sessionState = sessionManager.getSessionState();
        Locale locale = sessionState.getLocale();
        DataImportSummaryProxy proxy = new DataImportSummaryProxy(summary, locale);
        return proxy;
    } else {
        return null;
    }
}
Also used : Locale(java.util.Locale) SessionState(org.openforis.collect.web.session.SessionState) DataImportSummary(org.openforis.collect.io.data.DataImportSummary) DataImportSummaryProxy(org.openforis.collect.remoting.service.dataimport.DataImportSummaryProxy) Secured(org.springframework.security.access.annotation.Secured)

Example 27 with SessionState

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

the class DataService method demote.

protected void demote(Step toStep) throws RecordPersistenceException {
    sessionManager.checkIsActiveRecordLocked();
    SessionState sessionState = sessionManager.getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    Step fromStep = record.getStep();
    Step exptectedFromStep = toStep.getNext();
    if (exptectedFromStep != fromStep) {
        throw new IllegalStateException("The active record cannot be demoted: it is not in the exptected phase: " + exptectedFromStep);
    }
    CollectSurvey survey = sessionState.getActiveSurvey();
    String userName = sessionState.getUser().getUsername();
    User user = sessionState.getUser();
    Integer recordId = record.getId();
    publishRecordDeletedEvent(record, fromStep.toRecordStep(), userName);
    recordManager.demote(survey, recordId, record.getStep(), user);
    recordManager.releaseLock(recordId);
    sessionManager.clearActiveRecord();
}
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) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 28 with SessionState

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

Example 29 with SessionState

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

the class DataService method searchAutoCompleteValues.

@Secured(USER)
public List<String> searchAutoCompleteValues(int attributeDefnId, int fieldIndex, String searchText) throws Exception {
    SessionState sessionState = sessionManager.getSessionState();
    CollectSurvey survey = sessionState.getActiveSurvey();
    int maxResults = 10;
    List<String> result = recordIndexService.search(SearchType.STARTS_WITH, survey, attributeDefnId, fieldIndex, searchText, maxResults);
    return result;
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectSurvey(org.openforis.collect.model.CollectSurvey) Secured(org.springframework.security.access.annotation.Secured)

Example 30 with SessionState

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

the class DataService method saveActiveRecord.

@Transactional
@Secured(ENTRY_LIMITED)
public void saveActiveRecord() throws RecordPersistenceException, RecordIndexException {
    sessionManager.checkIsActiveRecordLocked();
    SessionState sessionState = sessionManager.getSessionState();
    CollectRecord record = sessionState.getActiveRecord();
    User user = sessionState.getUser();
    record.setModifiedDate(new Date());
    record.setModifiedBy(user);
    record.setOwner(user);
    String sessionId = sessionState.getSessionId();
    recordManager.save(record, sessionId);
    if (sessionManager.commitRecordFileChanges(record)) {
        recordManager.save(record, sessionId);
    }
    if (isCurrentRecordIndexable()) {
        recordIndexService.permanentlyIndex(record);
    }
    sessionEventDispatcher.recordSaved(record);
}
Also used : SessionState(org.openforis.collect.web.session.SessionState) CollectRecord(org.openforis.collect.model.CollectRecord) User(org.openforis.collect.model.User) Date(java.util.Date) 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