Fix Export for null features
@@ -108,7 +108,8 @@ public class CSVExportModularTask extends AbstractTask {
@Override
public String getTaskDescription() {
- return "Exporting feature list(s) " + Arrays.toString(featureLists) + " to CSV file(s) (new format)";
+ return "Exporting feature list(s) " + Arrays.toString(featureLists)
+ + " to CSV file(s) (new format)";
}
@Override
@@ -219,11 +220,40 @@ public class CSVExportModularTask extends AbstractTask {
// add feature types
for (RawDataFile raw : raws) {
ModularFeature feature = row.getFeature(raw);
+ if (feature != null) {
joinData(b, feature, featureTypes);
+ } else {
+ joinEmptyCells(b, featureTypes);
+ }
}
return b.toString();
}
+ /**
+ * Fills in empty cells for all data types and their sub types
+ *
+ * @param b the string builder
+ * @param dataTypes the list of types (with sub types) that are empty
+ */
+ private void joinEmptyCells(StringBuilder b, List<DataType> dataTypes) {
+ for (DataType t : dataTypes) {
+ if (t instanceof ModularType) {
+ ModularType modType = (ModularType) t;
+ // join all the sub headers
+ List<DataType> filteredSubTypes = modType.getSubDataTypes().stream()
+ .filter(this::filterType).collect(Collectors.toList());
+ joinEmptyCells(b, filteredSubTypes);
+ } else if (t instanceof SubColumnsFactory subCols) {
+ int numberOfSub = subCols.getNumberOfSubColumns();
+ for (int i = 0; i < numberOfSub; i++) {
+ b.append(fieldSeparator);
+ }
+ } else {
+ b.append(fieldSeparator);
+ }
+ }
+ }
+
/**
* @param b
* @param data {@link ModularFeatureListRow}, {@link ModularFeature}, {@link
