Search in sources :

Example 1 with Calculable

use of org.openforis.idm.metamodel.Calculable 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 2 with Calculable

use of org.openforis.idm.metamodel.Calculable 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 3 with Calculable

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

the class AttributeDefinitionPR method onStartDefinition.

@Override
protected void onStartDefinition() throws XmlParseException, XmlPullParserException, IOException {
    super.onStartDefinition();
    Boolean key = getBooleanAttribute(KEY, false);
    AttributeDefinition defn = (AttributeDefinition) getDefinition();
    defn.setKey(key == null ? false : key);
    if (defn instanceof Calculable) {
        boolean calculated = getBooleanAttributeWithDefault(CALCULATED, false);
        ((Calculable) defn).setCalculated(calculated);
    }
    defn.setReferencedAttributeId(getIntegerAttribute(REFERENCED_ATTRIBUTE, false));
}
Also used : Calculable(org.openforis.idm.metamodel.Calculable) AttributeDefinition(org.openforis.idm.metamodel.AttributeDefinition) NumericAttributeDefinition(org.openforis.idm.metamodel.NumericAttributeDefinition)

Aggregations

AttributeDefinition (org.openforis.idm.metamodel.AttributeDefinition)3 Calculable (org.openforis.idm.metamodel.Calculable)3 CollectAnnotations (org.openforis.collect.metamodel.CollectAnnotations)2 UIOptions (org.openforis.collect.metamodel.ui.UIOptions)2 CollectSurvey (org.openforis.collect.model.CollectSurvey)2 EntityDefinition (org.openforis.idm.metamodel.EntityDefinition)1 NumericAttributeDefinition (org.openforis.idm.metamodel.NumericAttributeDefinition)1