use of org.openforis.commons.versioning.Version in project collect by openforis.
the class DatabaseVersionManager method isVersionCompatible.
private boolean isVersionCompatible(Version appVersion, Version schemaVersion) {
if ((schemaVersion == null && appVersion == null) || appVersion.equals(schemaVersion)) {
return true;
} else {
String lastMigrationVersion = MIGRATION_REQUIRED_VERSIONS[MIGRATION_REQUIRED_VERSIONS.length - 1];
Version lastMigrationVersionInfo = new Version(lastMigrationVersion);
if (appVersion.compareTo(lastMigrationVersionInfo) >= 0) {
return true;
} else {
return false;
}
}
}
use of org.openforis.commons.versioning.Version in project collect by openforis.
the class SurveyDao method processSurveyRow.
protected CollectSurvey processSurveyRow(Record row) {
try {
if (row == null) {
return null;
}
String idml = row.getValue(OFC_SURVEY.IDML);
CollectSurvey s = unmarshalIdml(idml);
s.setCollectVersion(new Version(row.getValue(OFC_SURVEY.COLLECT_VERSION)));
s.setCreationDate(row.getValue(OFC_SURVEY.DATE_CREATED));
s.setId(row.getValue(OFC_SURVEY.ID));
s.setModifiedDate(row.getValue(OFC_SURVEY.DATE_MODIFIED));
s.setName(row.getValue(OFC_SURVEY.NAME));
s.setPublishedId(row.getValue(OFC_SURVEY.PUBLISHED_ID));
s.setTarget(SurveyTarget.fromCode(row.getValue(OFC_SURVEY.TARGET)));
s.setTemporary(row.getValue(OFC_SURVEY.TEMPORARY));
s.setUri(row.getValue(OFC_SURVEY.URI));
s.setUserGroupId(row.getValue(OFC_SURVEY.USERGROUP_ID));
return s;
} catch (IdmlParseException e) {
throw new RuntimeException("Error deserializing IDML from database", e);
}
}
use of org.openforis.commons.versioning.Version in project collect by openforis.
the class RecordDao method fromQueryResult.
public CollectRecord fromQueryResult(CollectSurvey survey, Record r, boolean recordToBeUpdated) {
int rootEntityId = r.getValue(OFC_RECORD.ROOT_ENTITY_DEFINITION_ID);
String version = r.getValue(OFC_RECORD.MODEL_VERSION);
Schema schema = survey.getSchema();
EntityDefinition rootEntityDefn = schema.getDefinitionById(rootEntityId);
CollectRecord c = new CollectRecord(survey, version, rootEntityDefn, recordToBeUpdated);
c.setId(r.getValue(OFC_RECORD.ID));
c.setStep(Step.valueOf(r.getValue(OFC_RECORD.STEP)));
c.setWorkflowSequenceNumber(r.getValue(OFC_RECORD.DATA_SEQ_NUM));
c.setCreationDate(r.getValue(OFC_RECORD.DATE_CREATED));
c.setModifiedDate(r.getValue(OFC_RECORD.DATE_MODIFIED));
c.setCreatedBy(createDetachedUser(r.getValue(OFC_RECORD.CREATED_BY_ID)));
c.setModifiedBy(createDetachedUser(r.getValue(OFC_RECORD.MODIFIED_BY_ID)));
c.setWarnings(r.getValue(OFC_RECORD.WARNINGS));
c.setErrors(r.getValue(OFC_RECORD.ERRORS));
c.setSkipped(r.getValue(OFC_RECORD.SKIPPED));
c.setMissing(r.getValue(OFC_RECORD.MISSING));
c.setOwner(createDetachedUser(r.getValue(OFC_RECORD.OWNER_ID)));
c.setDataStep(Step.valueOf(r.getValue(OFC_RECORD_DATA.STEP)));
c.setDataWorkflowSequenceNumber(r.getValue(OFC_RECORD_DATA.SEQ_NUM));
c.setDataCreationDate(r.getValue(OFC_RECORD_DATA.DATE_CREATED));
c.setDataModifiedDate(r.getValue(OFC_RECORD_DATA.DATE_MODIFIED));
c.setDataCreatedBy(createDetachedUser(r.getValue(OFC_RECORD_DATA.CREATED_BY)));
c.setDataModifiedBy(createDetachedUser(r.getValue(OFC_RECORD_DATA.MODIFIED_BY)));
c.setDataRootEntityKeyValues(getFieldValues(r, rootEntityDefn.getKeyAttributeDefinitions(), RECORD_DATA_KEY_FIELDS, String.class));
c.setDataEntityCounts(getFieldValues(r, schema.getCountableEntitiesInRecordList(rootEntityDefn), RECORD_DATA_COUNT_FIELDS, Integer.class));
c.setDataQualifierValues(getFieldValues(r, schema.getQualifierAttributeDefinitions(rootEntityDefn), RECORD_DATA_QUALIFIER_FIELDS, String.class));
c.setDataSummaryValues(getFieldValues(r, schema.getSummaryAttributeDefinitions(rootEntityDefn), RECORD_DATA_SUMMARY_FIELDS, String.class));
String state = r.getValue(OFC_RECORD.STATE);
c.setState(state == null ? null : State.fromCode(state));
c.setApplicationVersion(new Version(r.getValue(OFC_RECORD_DATA.APP_VERSION)));
byte[] data = r.getValue(OFC_RECORD_DATA.DATA);
ModelSerializer modelSerializer = new ModelSerializer(SERIALIZATION_BUFFER_SIZE);
Entity rootEntity = c.getRootEntity();
modelSerializer.mergeFrom(data, rootEntity);
c.setRootEntityKeyValues(getFieldValues(r, rootEntityDefn.getKeyAttributeDefinitions(), RECORD_KEY_FIELDS, String.class));
c.setEntityCounts(getFieldValues(r, schema.getCountableEntitiesInRecordList(rootEntityDefn), RECORD_COUNT_FIELDS, Integer.class));
c.setQualifierValues(getFieldValues(r, schema.getQualifierAttributeDefinitions(rootEntityDefn), RECORD_QUALIFIER_FIELDS, String.class));
c.setSummaryValues(getFieldValues(r, schema.getSummaryAttributeDefinitions(rootEntityDefn), RECORD_SUMMARY_FIELDS, String.class));
return c;
}
use of org.openforis.commons.versioning.Version in project collect by openforis.
the class SurveyWorkDao method processSurveyRow.
@Override
protected CollectSurvey processSurveyRow(Record row) {
if (row == null) {
return null;
}
String name = null;
Integer id = null;
try {
id = row.getValue(OFC_SURVEY_WORK.ID);
name = row.getValue(OFC_SURVEY_WORK.NAME);
String idml = row.getValue(OFC_SURVEY_WORK.IDML);
CollectSurvey survey = unmarshalIdml(idml);
survey.setId(id);
survey.setName(name);
survey.setWork(true);
survey.setTarget(SurveyTarget.fromCode(row.getValue(OFC_SURVEY.TARGET)));
survey.setCreationDate(row.getValue(OFC_SURVEY.DATE_CREATED));
survey.setModifiedDate(row.getValue(OFC_SURVEY.DATE_MODIFIED));
survey.setCollectVersion(new Version(row.getValue(OFC_SURVEY.COLLECT_VERSION)));
return survey;
} catch (IdmlParseException e) {
throw new RuntimeException(String.format("Error deserializing temporary survey from database (id=%d, name=%s)", id, name), e);
}
}
use of org.openforis.commons.versioning.Version in project collect by openforis.
the class DatabaseVersionManager method checkIsVersionCompatible.
public void checkIsVersionCompatible() throws DatabaseVersionNotCompatibleException {
ApplicationInfo info = applicationInfoDao.load();
Version schemaVersion = null;
if (info != null && StringUtils.isNotBlank(info.getVersion())) {
schemaVersion = new Version(info.getVersion());
}
Version appVersion = Collect.VERSION;
if (!isVersionCompatible(appVersion, schemaVersion)) {
throw new DatabaseVersionNotCompatibleException("Database version (" + (schemaVersion != null ? schemaVersion : "not specified") + ") is not compatible with Application version: " + appVersion);
}
}
Aggregations