Search in sources :

Example 6 with Version

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;
        }
    }
}
Also used : Version(org.openforis.commons.versioning.Version)

Example 7 with Version

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);
    }
}
Also used : Version(org.openforis.commons.versioning.Version) CollectSurvey(org.openforis.collect.model.CollectSurvey) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException)

Example 8 with Version

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;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) CollectRecord(org.openforis.collect.model.CollectRecord) Entity(org.openforis.idm.model.Entity) Version(org.openforis.commons.versioning.Version) ModelVersion(org.openforis.idm.metamodel.ModelVersion) Schema(org.openforis.idm.metamodel.Schema) ModelSerializer(org.openforis.idm.model.ModelSerializer)

Example 9 with Version

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);
    }
}
Also used : Version(org.openforis.commons.versioning.Version) CollectSurvey(org.openforis.collect.model.CollectSurvey) IdmlParseException(org.openforis.idm.metamodel.xml.IdmlParseException)

Example 10 with Version

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);
    }
}
Also used : Version(org.openforis.commons.versioning.Version) ApplicationInfo(org.openforis.collect.model.ApplicationInfo)

Aggregations

Version (org.openforis.commons.versioning.Version)11 CollectCompleteInfo (org.openforis.collect.CollectCompleteInfo)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 IdmlParseException (org.openforis.idm.metamodel.xml.IdmlParseException)2 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 DocumentBuilderFactory (javax.xml.parsers.DocumentBuilderFactory)1 HttpEntity (org.apache.http.HttpEntity)1 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)1 SurveyBackupInfo (org.openforis.collect.io.SurveyBackupInfo)1 ApplicationInfo (org.openforis.collect.model.ApplicationInfo)1 CollectRecord (org.openforis.collect.model.CollectRecord)1 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 ModelVersion (org.openforis.idm.metamodel.ModelVersion)1 Schema (org.openforis.idm.metamodel.Schema)1 Entity (org.openforis.idm.model.Entity)1 ModelSerializer (org.openforis.idm.model.ModelSerializer)1 Document (org.w3c.dom.Document)1