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++;
}
}
Aggregations