Search in sources :

Example 66 with CollectRecord

use of org.openforis.collect.model.CollectRecord 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 67 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class RecordIndexManager method indexAllRecords.

public void indexAllRecords(CollectSurvey survey, String rootEntity) throws RecordIndexException {
    cancelled = false;
    RecordFilter filter = new RecordFilter(survey);
    filter.setRootEntityId(survey.getSchema().getRootEntityDefinition(rootEntity).getId());
    List<CollectRecordSummary> summaries = recordManager.loadSummaries(filter);
    IndexWriter indexWriter = null;
    try {
        indexWriter = createIndexWriter();
        for (CollectRecordSummary s : summaries) {
            if (!cancelled) {
                Integer recordId = s.getId();
                deleteDocuments(indexWriter, recordId);
                CollectRecord record = recordManager.load(survey, recordId, s.getStep());
                index(indexWriter, record);
            } else {
                break;
            }
        }
    } catch (Exception e) {
        throw new RecordIndexException(e);
    } finally {
        close(indexWriter);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) IndexWriter(org.apache.lucene.index.IndexWriter) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) RecordFilter(org.openforis.collect.model.RecordFilter) ParseException(org.apache.lucene.queryParser.ParseException) IOException(java.io.IOException)

Example 68 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class RecordManager method validateAndSave.

@Transactional(readOnly = false, propagation = REQUIRED)
public void validateAndSave(CollectSurvey survey, User user, String sessionId, int recordId, Step step) throws RecordLockedException, MultipleEditException {
    if (isLockingEnabled()) {
        lockManager.isLockAllowed(user, recordId, sessionId, true);
        lockManager.lock(recordId, user, sessionId, true);
    }
    CollectRecord record = recordDao.load(survey, recordId, step);
    validate(record);
    recordDao.update(record);
    if (isLockingEnabled()) {
        lockManager.releaseLock(recordId);
    }
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) Transactional(org.springframework.transaction.annotation.Transactional)

Example 69 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class RecordManager method load.

public CollectRecord load(CollectSurvey survey, int recordId, Step step, boolean validate) {
    if (survey == null) {
        int surveyId = recordDao.loadSurveyId(recordId);
        survey = surveyManager.getOrLoadSurveyById(surveyId);
    }
    CollectRecord r = recordDao.load(survey, recordId, step, validate);
    if (r == null) {
        throw new NullPointerException(format("Could not load record with id %d in phase %s in survey %s", recordId, step, survey.getName()));
    }
    loadDetachedObjects(r);
    recordConverter.convertToLatestVersion(r);
    RecordUpdater updater = new RecordUpdater();
    updater.setValidateAfterUpdate(validate);
    updater.initializeRecord(r);
    return r;
}
Also used : CollectRecord(org.openforis.collect.model.CollectRecord) RecordUpdater(org.openforis.collect.model.RecordUpdater)

Example 70 with CollectRecord

use of org.openforis.collect.model.CollectRecord in project collect by openforis.

the class RecordManager method instantiateRecord.

public CollectRecord instantiateRecord(CollectSurvey survey, String rootEntityName, User user, String modelVersionName, Step step) {
    EntityDefinition rootEntityDef = rootEntityName == null ? survey.getSchema().getFirstRootEntityDefinition() : survey.getSchema().getRootEntityDefinition(rootEntityName);
    CollectRecord record = survey.createRecord(modelVersionName, rootEntityDef);
    Date now = new Date();
    record.setCreationDate(now);
    record.setModifiedDate(now);
    record.setCreatedBy(user);
    record.setModifiedBy(user);
    record.setOwner(user);
    record.setStep(step);
    return record;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) Date(java.util.Date)

Aggregations

CollectRecord (org.openforis.collect.model.CollectRecord)141 Entity (org.openforis.idm.model.Entity)36 Test (org.junit.Test)30 CollectSurvey (org.openforis.collect.model.CollectSurvey)29 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)29 CollectIntegrationTest (org.openforis.collect.CollectIntegrationTest)27 CollectRecordSummary (org.openforis.collect.model.CollectRecordSummary)24 Step (org.openforis.collect.model.CollectRecord.Step)23 User (org.openforis.collect.model.User)19 SessionState (org.openforis.collect.web.session.SessionState)15 RecordFilter (org.openforis.collect.model.RecordFilter)14 Transactional (org.springframework.transaction.annotation.Transactional)14 ParsingError (org.openforis.collect.io.metadata.parsing.ParsingError)12 Secured (org.springframework.security.access.annotation.Secured)12 ArrayList (java.util.ArrayList)11 Date (org.openforis.idm.model.Date)10 GregorianCalendar (java.util.GregorianCalendar)9 Code (org.openforis.idm.model.Code)9 RealAttribute (org.openforis.idm.model.RealAttribute)9 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)9