Search in sources :

Example 6 with SourceRow

use of org.activityinfo.ui.client.component.importDialog.model.source.SourceRow in project activityinfo by bedatadriven.

the class SchemaImporterV2 method processRows.

private void processRows(SourceTable source) {
    int rowCount = 1;
    for (SourceRow row : source.getRows()) {
        ActivityFormDTO activity = getActivity(row);
        String fieldType = formFieldType.get(row);
        if ("Indicator".equals(fieldType)) {
            DtoWrapper indicatorWrapper = new DtoWrapper(new IndicatorKey(activity.getName(), fieldName.get(row), fieldCategory.get(row)));
            if (!newIndicators.contains(indicatorWrapper)) {
                IndicatorDTO indicator = new IndicatorDTO();
                indicator.setName(fieldName.get(row));
                indicator.setCategory(fieldCategory.get(row));
                indicator.setDescription(fieldDescription.get(row));
                indicator.setUnits(fieldUnits.get(row));
                indicator.set("activityId", activity);
                indicator.setNameInExpression(fieldCode.get(row));
                indicator.setExpression(fieldExpression.get(row));
                if (isTruthy(fieldRequired.get(row))) {
                    indicator.setMandatory(true);
                }
                if (isTruthy(fieldVisible.get(row))) {
                    indicator.setVisible(true);
                }
                indicatorWrapper.setDto(indicator);
                newIndicators.add(indicatorWrapper);
            }
        } else if ("AttributeGroup".equals(fieldType)) {
            String name = fieldName.get(row);
            AttributeGroupDTO group = activity.getAttributeGroupByName(name);
            DtoWrapper attributeGroupWrapper = new DtoWrapper(new AttributeGroupKey(activity.getName(), name));
            if (group == null && !newAttributeGroups.contains(attributeGroupWrapper)) {
                group = new AttributeGroupDTO();
                group.setId(-1);
                group.setName(name);
                group.set("activityId", activity);
                if (isTruthy(multipleAllowed.get(row))) {
                    group.setMultipleAllowed(true);
                }
                if (isTruthy(fieldRequired.get(row))) {
                    group.setMandatory(true);
                }
                activity.getAttributeGroups().add(group);
                attributeGroupWrapper.setDto(group);
                newAttributeGroups.add(attributeGroupWrapper);
            }
            String attribName = choiceLabel.get(row);
            AttributeDTO attrib = findAttrib(group, attribName);
            DtoWrapper attributeWrapper = new DtoWrapper(new AttributeKey((AttributeGroupKey) attributeGroupWrapper.getKey(), attribName));
            if (attrib == null && !newAttributes.contains(attributeWrapper)) {
                if (!Strings.isNullOrEmpty(attribName)) {
                    attrib = new AttributeDTO();
                    attrib.setId(-1);
                    attrib.setName(attribName);
                    attrib.set("attributeGroupId", group);
                    attributeWrapper.setDto(attrib);
                    newAttributes.add(attributeWrapper);
                } else {
                    hasSkippedAttributes = true;
                    warnings.add(templates.missingAttribueValue(rowCount));
                }
            }
        }
        rowCount++;
    }
}
Also used : SourceRow(org.activityinfo.ui.client.component.importDialog.model.source.SourceRow)

Aggregations

SourceRow (org.activityinfo.ui.client.component.importDialog.model.source.SourceRow)6 ValidatedRow (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRow)3 ImportModel (org.activityinfo.ui.client.component.importDialog.model.ImportModel)2 FieldImporter (org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporter)2 ValidatedRowTable (org.activityinfo.ui.client.component.importDialog.model.validation.ValidatedRowTable)2 ValidationResult (org.activityinfo.ui.client.component.importDialog.model.validation.ValidationResult)2 Cell (com.google.gwt.cell.client.Cell)1 TableCellBuilder (com.google.gwt.dom.builder.shared.TableCellBuilder)1 TableRowBuilder (com.google.gwt.dom.builder.shared.TableRowBuilder)1 Nullable (javax.annotation.Nullable)1 FormClass (org.activityinfo.model.form.FormClass)1 FormField (org.activityinfo.model.form.FormField)1 FormInstance (org.activityinfo.model.form.FormInstance)1 ResourceId (org.activityinfo.model.resource.ResourceId)1 EnumType (org.activityinfo.model.type.enumerated.EnumType)1 CalculatedFieldType (org.activityinfo.model.type.expr.CalculatedFieldType)1 SubFormReferenceType (org.activityinfo.model.type.subform.SubFormReferenceType)1 FieldImporterColumn (org.activityinfo.ui.client.component.importDialog.model.strategy.FieldImporterColumn)1