Search in sources :

Example 61 with AttributeDefinition

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

the class DataCleansingStepValidator method validateUpdateValues.

private void validateUpdateValues(DataCleansingStepForm target, Errors errors) {
    CollectSurvey survey = getActiveSurvey();
    DataQuery query = dataQueryManager.loadById(survey, target.getQueryId());
    AttributeDefinition attrDef = query.getAttributeDefinition();
    List<DataCleansingStepValue> updateValues = target.getUpdateValues();
    int updateValueIndex = 0;
    for (DataCleansingStepValue updateValue : updateValues) {
        validateCondition(target, errors, updateValue, updateValueIndex == updateValues.size() - 1);
        switch(updateValue.getUpdateType()) {
            case ATTRIBUTE:
                validateUpdateByAttribute(errors, updateValue, attrDef, updateValueIndex);
                break;
            case FIELD:
                validateUpdateByField(errors, attrDef, updateValueIndex, updateValue);
                break;
        }
        updateValueIndex++;
    }
}
Also used : DataCleansingStepValue(org.openforis.collect.datacleansing.DataCleansingStepValue) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) DataQuery(org.openforis.collect.datacleansing.DataQuery) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 62 with AttributeDefinition

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

the class DataCleansingStepValueValidator method validateForm.

@Override
public void validateForm(DataCleansingStepValueForm target, Errors errors) {
    CollectSurvey survey = getActiveSurvey();
    DataQuery query = dataQueryManager.loadById(survey, target.getQueryId());
    AttributeDefinition attrDef = query.getAttributeDefinition();
    int index = target.getIndex();
    // if (validateUniqueness(target, errors, step)) {
    validateCondition(target, errors, attrDef);
    switch(target.getUpdateType()) {
        case ATTRIBUTE:
            validateUpdateByAttribute(errors, target, attrDef, index);
            break;
        case FIELD:
            validateUpdateByField(errors, target, attrDef, index);
            break;
    }
// }
}
Also used : AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) DataQuery(org.openforis.collect.datacleansing.DataQuery) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 63 with AttributeDefinition

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

the class NodeDefinitionFormObject method loadFrom.

@Override
public void loadFrom(T source, String language) {
    super.loadFrom(source, language);
    CollectSurvey survey = (CollectSurvey) source.getSurvey();
    UIOptions uiOptions = survey.getUIOptions();
    // generic
    name = source.getName();
    multiple = source.isMultiple();
    if (source.isAlwaysRequired()) {
        requirenessType = RequirenessType.ALWAYS_REQUIRED.name();
    } else {
        requiredWhenExpression = source.extractRequiredExpression();
        if (requiredWhenExpression == null) {
            requirenessType = RequirenessType.NOT_REQUIRED.name();
        } else {
            requirenessType = RequirenessType.REQUIRED_WHEN.name();
        }
    }
    relevanceType = source.getRelevantExpression() == null ? RelevanceType.ALWAYS_RELEVANT.name() : RelevanceType.RELEVANT_WHEN.name();
    relevantExpression = source.getRelevantExpression();
    minCountExpression = source.getMinCountExpression();
    maxCountExpression = multiple ? source.getMaxCountExpression() : null;
    // labels
    headingLabel = source.getLabel(Type.HEADING, language);
    instanceLabel = source.getLabel(Type.INSTANCE, language);
    numberLabel = source.getLabel(Type.NUMBER, language);
    abbreviatedLabel = source.getLabel(Type.ABBREVIATED, language);
    reportingLabel = source.getLabel(Type.REPORTING, language);
    interviewPromptLabel = source.getPrompt(Prompt.Type.INTERVIEW, language);
    paperPromptLabel = source.getPrompt(Prompt.Type.PAPER, language);
    handheldPromptLabel = source.getPrompt(Prompt.Type.HANDHELD, language);
    pcPromptLabel = source.getPrompt(Prompt.Type.PC, language);
    description = source.getDescription(language);
    defaultInstanceLabel = source.getLabel(Type.INSTANCE);
    defaultHeadingLabel = source.getLabel(Type.HEADING);
    defaultDescription = source.getDescription();
    // layout
    hideWhenNotRelevant = uiOptions.isHideWhenNotRelevant(source);
    column = uiOptions.getColumn(source);
    columnSpan = uiOptions.getColumnSpan(source);
    width = uiOptions.getWidth(source);
    labelWidth = uiOptions.getLabelWidth(source);
    labelOrientation = uiOptions.getLabelOrientation(source).name();
    CollectAnnotations annotations = survey.getAnnotations();
    autoGenerateMinItems = annotations.isAutoGenerateMinItems(source);
    if (source instanceof AttributeDefinition) {
        fromCollectEarthCSV = annotations.isFromCollectEarthCSV((AttributeDefinition) source);
        includedInCollectEarthHeader = annotations.isIncludedInCollectEarthHeader((AttributeDefinition) source);
        showReadOnlyFieldInCollectEarth = annotations.isShowReadOnlyFieldInCollectEarth((AttributeDefinition) source);
        hideKeyInCollectEarthRecordList = annotations.isHideKeyInCollectEarthRecordList((AttributeDefinition) source);
        showInSummary = annotations.isShowInSummary((AttributeDefinition) source);
        qualifier = annotations.isQualifier((AttributeDefinition) source);
    }
    if (source instanceof Calculable) {
        calculated = ((Calculable) source).isCalculated();
        // show in UI
        showInUI = !uiOptions.isHidden(source);
        includeInDataExport = annotations.isIncludedInDataExport(source);
    }
    backgroundColor = annotations.getBackgroundColor(source);
    backgroundTransparency = fromAlphaToTransparency(annotations.getBackgroundAlpha(source));
}
Also used : Calculable(org.openforis.idm.metamodel.Calculable) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 64 with AttributeDefinition

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

the class NodeDefinitionFormObject method saveTo.

@Override
public void saveTo(T dest, String languageCode) {
    super.saveTo(dest, languageCode);
    if (!name.equals(dest.getName())) {
        dest.rename(name);
    }
    dest.setLabel(Type.HEADING, languageCode, headingLabel);
    dest.setLabel(Type.INSTANCE, languageCode, instanceLabel);
    dest.setLabel(Type.NUMBER, languageCode, numberLabel);
    dest.setLabel(Type.ABBREVIATED, languageCode, abbreviatedLabel);
    dest.setLabel(Type.REPORTING, languageCode, reportingLabel);
    dest.setPrompt(Prompt.Type.HANDHELD, languageCode, handheldPromptLabel);
    dest.setPrompt(Prompt.Type.INTERVIEW, languageCode, interviewPromptLabel);
    dest.setPrompt(Prompt.Type.PAPER, languageCode, paperPromptLabel);
    dest.setPrompt(Prompt.Type.PC, languageCode, pcPromptLabel);
    dest.setDescription(languageCode, description);
    dest.setMinCountExpression(null);
    dest.setMaxCountExpression(null);
    dest.setRequiredExpression(null);
    CollectSurvey survey = (CollectSurvey) dest.getSurvey();
    CollectAnnotations annotations = survey.getAnnotations();
    annotations.setAutoGenerateMinItems(dest, isMultiple() && StringUtils.isNotBlank(getMinCountExpression()) && autoGenerateMinItems);
    if (dest instanceof EntityDefinition && parentDefinition == null) {
        // root entity is always true
        dest.setMultiple(true);
    } else if (!(dest instanceof AttributeDefinition && calculated)) {
        dest.setMultiple(multiple);
        if (multiple) {
            dest.setMinCountExpression(StringUtils.trimToNull(minCountExpression));
            dest.setMaxCountExpression(StringUtils.trimToNull(maxCountExpression));
        } else {
            RequirenessType requirenessTypeEnum = RequirenessType.valueOf(requirenessType);
            switch(requirenessTypeEnum) {
                case ALWAYS_REQUIRED:
                    dest.setAlwaysRequired();
                    break;
                case REQUIRED_WHEN:
                    dest.setRequiredExpression(StringUtils.trimToNull(requiredWhenExpression));
                    break;
                default:
                    break;
            }
        }
    }
    UIOptions uiOptions = survey.getUIOptions();
    RelevanceType relevanceTypeEnum = RelevanceType.valueOf(relevanceType);
    switch(relevanceTypeEnum) {
        case RELEVANT_WHEN:
            dest.setRelevantExpression(StringUtils.trimToNull(relevantExpression));
            uiOptions.setHideWhenNotRelevant(dest, hideWhenNotRelevant);
            break;
        default:
            dest.setRelevantExpression(null);
            uiOptions.setHideWhenNotRelevant(dest, false);
    }
    if (dest instanceof AttributeDefinition) {
        AttributeDefinition attrDef = (AttributeDefinition) dest;
        annotations.setFromCollectEarthCSV(attrDef, fromCollectEarthCSV);
        annotations.setIncludedInCollectEarthHeader(attrDef, includedInCollectEarthHeader);
        annotations.setShowReadOnlyFieldInCollectEarth(attrDef, showReadOnlyFieldInCollectEarth);
        annotations.setHideKeyInCollectEarthRecordList(attrDef, hideKeyInCollectEarthRecordList);
        annotations.setShowInSummary(attrDef, showInSummary);
        annotations.setQualifier(attrDef, qualifier);
    }
    // layout
    uiOptions.setColumn(dest, column);
    uiOptions.setColumnSpan(dest, columnSpan);
    uiOptions.setWidth(dest, width);
    uiOptions.setLabelWidth(dest, labelWidth);
    uiOptions.setLabelOrientation(dest, Orientation.valueOf(labelOrientation));
    if (dest instanceof Calculable) {
        ((Calculable) dest).setCalculated(calculated);
        // include in data export
        annotations.setIncludeInDataExport(dest, includeInDataExport);
        // show in ui
        uiOptions.setHidden(dest, !showInUI);
    }
    annotations.setBackgroundColor(dest, backgroundColor);
    annotations.setBackgroundAlpha(dest, fromTransparencyToAlpha(backgroundTransparency));
}
Also used : EntityDefinition(org.openforis.idm.metamodel.EntityDefinition) Calculable(org.openforis.idm.metamodel.Calculable) UIOptions(org.openforis.collect.metamodel.ui.UIOptions) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Example 65 with AttributeDefinition

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

the class AttributeDefinitionFormObject method saveTo.

@Override
public void saveTo(T dest, String languageCode) {
    super.saveTo(dest, languageCode);
    dest.setKey(key);
    // save attribute defaults
    dest.removeAllAttributeDefaults();
    if (attributeDefaults != null) {
        for (AttributeDefault attrDefault : attributeDefaults) {
            dest.addAttributeDefault(attrDefault);
        }
    }
    dest.setReferencedAttribute(referencedAttributePath == null ? null : (AttributeDefinition) dest.getSchema().getDefinitionByPath(referencedAttributePath));
    CollectSurvey survey = (CollectSurvey) dest.getSurvey();
    CollectAnnotations annotations = survey.getAnnotations();
    annotations.setPhaseToApplyDefaultValue(dest, Step.valueOf(phaseToApplyDefaultValue));
    annotations.setEditable(dest, editable);
    annotations.setMeasurementAttribute(dest, measurement);
    annotations.setShowInMapBalloon(dest, showInMapBalloon);
    // save checks
    dest.removeAllChecks();
    if (checks != null) {
        for (Check<?> check : checks) {
            dest.addCheck(check);
        }
    }
    UIOptions uiOptions = getUIOptions(dest);
    uiOptions.setVisibleFields(dest, visibleFields);
}
Also used : UIOptions(org.openforis.collect.metamodel.ui.UIOptions) AttributeDefault(org.openforis.idm.metamodel.AttributeDefault) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) CollectAnnotations(org.openforis.collect.metamodel.CollectAnnotations) CollectSurvey(org.openforis.collect.model.CollectSurvey)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)107 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)47 CodeAttributeDefinition (org.openforis.idm.metamodel.CodeAttributeDefinition)37 ArrayList (java.util.ArrayList)33 NodeDefinition (org.openforis.idm.metamodel.NodeDefinition)27 BooleanAttributeDefinition (org.openforis.idm.metamodel.BooleanAttributeDefinition)21 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)20 DateAttributeDefinition (org.openforis.idm.metamodel.DateAttributeDefinition)18 NumberAttributeDefinition (org.openforis.idm.metamodel.NumberAttributeDefinition)18 CollectSurvey (org.openforis.collect.model.CollectSurvey)17 CoordinateAttributeDefinition (org.openforis.idm.metamodel.CoordinateAttributeDefinition)16 KeyAttributeDefinition (org.openforis.idm.metamodel.KeyAttributeDefinition)16 TextAttributeDefinition (org.openforis.idm.metamodel.TextAttributeDefinition)12 TimeAttributeDefinition (org.openforis.idm.metamodel.TimeAttributeDefinition)12 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)11 Schema (org.openforis.idm.metamodel.Schema)10 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)9 Entity (org.openforis.idm.model.Entity)9 Value (org.openforis.idm.model.Value)9 RangeAttributeDefinition (org.openforis.idm.metamodel.RangeAttributeDefinition)8