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);
}
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);
}
}
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);
}
}
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;
}
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;
}
Aggregations