Search in sources :

Example 1 with ModelVersion

use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.

the class RecordDao method fromSummaryQueryRecord.

public CollectRecordSummary fromSummaryQueryRecord(CollectSurvey survey, Record r) {
    int rootEntityDefId = r.getValue(OFC_RECORD.ROOT_ENTITY_DEFINITION_ID);
    String versionName = r.getValue(OFC_RECORD.MODEL_VERSION);
    ModelVersion modelVersion = versionName == null ? null : survey.getVersion(versionName);
    CollectRecordSummary s = new CollectRecordSummary();
    s.setSurvey(survey);
    s.setVersion(modelVersion);
    s.setRootEntityDefinitionId(rootEntityDefId);
    s.setId(r.getValue(OFC_RECORD.ID));
    s.setOwner(createDetachedUser(r.getValue(OFC_RECORD.OWNER_ID)));
    Step step = Step.valueOf(r.getValue(OFC_RECORD.STEP));
    s.setStep(step);
    s.setWorkflowSequenceNumber(r.getValue(OFC_RECORD.DATA_SEQ_NUM));
    s.setCreationDate(r.getValue(OFC_RECORD.DATE_CREATED));
    s.setModifiedDate(r.getValue(OFC_RECORD.DATE_MODIFIED));
    s.setCreatedBy(createDetachedUser(r.getValue(OFC_RECORD.CREATED_BY_ID)));
    s.setModifiedBy(createDetachedUser(r.getValue(OFC_RECORD.MODIFIED_BY_ID)));
    StepSummary stepSummary = new StepSummary(step);
    stepSummary.setSequenceNumber(r.getValue(OFC_RECORD.DATA_SEQ_NUM));
    stepSummary.setErrors(r.getValue(OFC_RECORD.ERRORS));
    stepSummary.setWarnings(r.getValue(OFC_RECORD.WARNINGS));
    stepSummary.setSkipped(r.getValue(OFC_RECORD.SKIPPED));
    stepSummary.setMissing(r.getValue(OFC_RECORD.MISSING));
    int totalErrors = step == Step.ENTRY ? Numbers.sum(stepSummary.getErrors(), stepSummary.getSkipped()) : Numbers.sum(stepSummary.getErrors(), stepSummary.getMissingErrors());
    stepSummary.setTotalErrors(totalErrors);
    Schema schema = survey.getSchema();
    EntityDefinition rootEntityDef = schema.getRootEntityDefinition(rootEntityDefId);
    stepSummary.setRootEntityKeyValues(getFieldValues(r, rootEntityDef.getKeyAttributeDefinitions(), RECORD_KEY_FIELDS, String.class));
    stepSummary.setEntityCounts(getFieldValues(r, schema.getCountableEntitiesInRecordList(rootEntityDef), RECORD_COUNT_FIELDS, Integer.class));
    stepSummary.setQualifierValues(getFieldValues(r, schema.getQualifierAttributeDefinitions(rootEntityDef), RECORD_QUALIFIER_FIELDS, String.class));
    stepSummary.setSummaryValues(getFieldValues(r, schema.getSummaryAttributeDefinitions(rootEntityDef), RECORD_SUMMARY_FIELDS, String.class));
    String state = r.getValue(OFC_RECORD.STATE);
    stepSummary.setState(state == null ? null : State.fromCode(state));
    s.addStepSummary(stepSummary);
    return s;
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) StepSummary(org.openforis.collect.model.CollectRecordSummary.StepSummary) CollectRecordSummary(org.openforis.collect.model.CollectRecordSummary) Schema(org.openforis.idm.metamodel.Schema) ModelVersion(org.openforis.idm.metamodel.ModelVersion) Step(org.openforis.collect.model.CollectRecord.Step)

Example 2 with ModelVersion

use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.

the class CodeValueFKColumnValueExtractor method extractValue.

private Object extractValue(CodeAttribute valNode) {
    CodeListItem item = findCodeListItem(valNode);
    if (item == null) {
        String defaultCodeValue = column.getDefaultCodeValue();
        String codeValue = getCodeValue(valNode);
        if (defaultCodeValue == null || (codeValue != null && !codeValue.equals(defaultCodeValue))) {
            // no default code value specified or code list item not found (invalid code?)
            return null;
        } else {
            CodeAttributeDefinition definition = valNode.getDefinition();
            CodeList list = definition.getList();
            Record record = valNode.getRecord();
            ModelVersion version = record.getVersion();
            return getDefaultCodeItemId(list, version);
        }
    } else {
        return item.getId();
    }
}
Also used : CodeList(org.openforis.idm.metamodel.CodeList) CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) Record(org.openforis.idm.model.Record) ModelVersion(org.openforis.idm.metamodel.ModelVersion) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 3 with ModelVersion

use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.

the class CodeAttribute method getCodeListItem.

/**
 * @deprecated Access code list items using manager class.
 *
 * @return
 */
@Deprecated
public CodeListItem getCodeListItem() {
    Code code = getValue();
    if (code != null) {
        String codeValue = code.getCode();
        if (StringUtils.isNotBlank(codeValue)) {
            ModelVersion currentVersion = getRecord().getVersion();
            CodeAttributeDefinition definition = getDefinition();
            String parentExpression = definition.getParentExpression();
            if (StringUtils.isBlank(parentExpression)) {
                return findCodeListItem(definition.getList().getItems(), codeValue, currentVersion);
            } else {
                CodeAttribute codeParent = getCodeParent();
                if (codeParent != null) {
                    CodeListItem codeListItemParent = codeParent.getCodeListItem();
                    if (codeListItemParent != null) {
                        return findCodeListItem(codeListItemParent.getChildItems(), codeValue, currentVersion);
                    }
                }
            }
        }
    }
    return null;
}
Also used : CodeAttributeDefinition(org.openforis.idm.metamodel.CodeAttributeDefinition) ModelVersion(org.openforis.idm.metamodel.ModelVersion) CodeListItem(org.openforis.idm.metamodel.CodeListItem)

Example 4 with ModelVersion

use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.

the class ModelVersionUtil method isInVersion.

public static boolean isInVersion(Versionable versionable, ModelVersion currentVersion) {
    boolean result;
    ModelVersion since = versionable.getSinceVersion();
    ModelVersion deprecated = versionable.getDeprecatedVersion();
    String currentDate = currentVersion.getDate();
    int compareToSince;
    if (since == null) {
        compareToSince = 1;
    } else {
        compareToSince = currentDate.compareTo(since.getDate());
    }
    int compareToDeprecated;
    if (deprecated == null) {
        compareToDeprecated = -1;
    } else {
        compareToDeprecated = currentDate.compareTo(deprecated.getDate());
    }
    result = compareToSince >= 0 && compareToDeprecated <= 0;
    return result;
}
Also used : ModelVersion(org.openforis.idm.metamodel.ModelVersion)

Example 5 with ModelVersion

use of org.openforis.idm.metamodel.ModelVersion in project collect by openforis.

the class DataHandler method startChildNode.

public void startChildNode(String localName, Attributes attributes) {
    Entity entity = (Entity) node;
    NodeDefinition childDefn = getNodeDefinition(entity, localName, attributes);
    if (childDefn == null) {
        warn(localName, "Undefined node");
        pushIgnore();
    } else {
        ModelVersion version = record.getVersion();
        if (version == null || version.isApplicable(childDefn)) {
            Node<?> newNode = childDefn.createNode();
            entity.add(newNode);
            Integer stateValue = getNodeState();
            if (stateValue != null) {
                entity.setChildState(localName, stateValue);
            }
            this.node = newNode;
        } else {
            warn(localName, "Node definition is not applicable to the record version");
            pushIgnore();
        }
    }
}
Also used : Entity(org.openforis.idm.model.Entity) NodeDefinition(org.openforis.idm.metamodel.NodeDefinition) ModelVersion(org.openforis.idm.metamodel.ModelVersion)

Aggregations

ModelVersion (org.openforis.idm.metamodel.ModelVersion)40 ArrayList (java.util.ArrayList)9 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)9 Record (org.openforis.idm.model.Record)9 CollectSurvey (org.openforis.collect.model.CollectSurvey)7 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)7 CodeListItem (org.openforis.idm.metamodel.CodeListItem)7 CodeList (org.openforis.idm.metamodel.CodeList)5 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)5 ExternalCodeListItem (org.openforis.idm.metamodel.ExternalCodeListItem)5 PersistedCodeListItem (org.openforis.idm.metamodel.PersistedCodeListItem)5 CodeAttribute (org.openforis.idm.model.CodeAttribute)5 Code (org.openforis.idm.model.Code)4 Entity (org.openforis.idm.model.Entity)4 SessionStatus (org.openforis.collect.designer.session.SessionStatus)2 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 Survey (org.openforis.idm.metamodel.Survey)2 NodePointer (org.openforis.idm.model.NodePointer)2 Command (org.zkoss.bind.annotation.Command)2 GlobalCommand (org.zkoss.bind.annotation.GlobalCommand)2