Only consider headings till value grid size, but consider all values till this size (#4115)

* Only consider headings till value grid size, but consider all values till this size

* Switched from null to blank for consistency

* Whoops, we don't do null row objects anymore
This commit is contained in:
Nidhi 2021-04-26 12:11:18 +05:30 committed by GitHub
parent 275843e61a
commit f86f6a4de9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 15 additions and 21 deletions

View File

@ -3,7 +3,6 @@ package com.external.config;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginError;
import com.appsmith.external.exceptions.pluginExceptions.AppsmithPluginException;
import com.external.domains.RowObject;
import com.external.utils.SheetsUtil;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.node.ArrayNode;
@ -176,17 +175,20 @@ public class GetValuesMethod implements Method {
return this.objectMapper.createArrayNode();
}
final String headerRange = valueRanges.get(0).get("range").asText();
int valueSize = 0;
for (int i = 0; i < values.size(); i++) {
valueSize = Math.max(valueSize, values.get(i).size());
}
final String valueRange = valueRanges.get(1).get("range").asText();
headers = (ArrayNode) headers.get(0);
Set<String> columnsSet = sanitizeHeaders(headers, headerRange, valueRange);
Set<String> columnsSet = sanitizeHeaders(headers, valueSize);
final List<Map<String, String>> collectedCells = new LinkedList<>();
final String[] headerArray = columnsSet.toArray(new String[columnsSet.size()]);
final String range = valueRanges.get(1).get("range").asText();
final String[] headerArray = columnsSet.toArray(new String[0]);
final Matcher matcher = findOffsetRowPattern.matcher(range);
final Matcher matcher = findOffsetRowPattern.matcher(valueRange);
matcher.find();
final int rowOffset = Integer.parseInt(matcher.group(1));
final int tableHeaderIndex = Integer.parseInt(methodConfig.getTableHeaderIndex());
@ -202,21 +204,9 @@ public class GetValuesMethod implements Method {
return this.objectMapper.valueToTree(collectedCells);
}
private Set<String> sanitizeHeaders(ArrayNode headers, String headerRange, String valueRange) {
private Set<String> sanitizeHeaders(ArrayNode headers, int valueSize) {
final Set<String> headerSet = new LinkedHashSet<>();
int headerSize = headers.size();
final Matcher matcher1 = sheetRangePattern.matcher(headerRange);
matcher1.find();
final int headerStart = SheetsUtil.getColumnNumber(matcher1.group(1));
final int headerEnd = SheetsUtil.getColumnNumber(matcher1.group(2));
final Matcher matcher2 = sheetRangePattern.matcher(valueRange);
matcher2.find();
final int valuesStart = SheetsUtil.getColumnNumber(matcher2.group(1));
final int valuesEnd = SheetsUtil.getColumnNumber(matcher2.group(2));
final int valueSize = (valuesEnd - valuesStart + 1);
final int size = Math.max(headerSize, valueSize);
// Manipulation to find valid headers for all columns

View File

@ -48,9 +48,13 @@ public class RowObject {
public RowObject(String[] headerValues, String[] rowValues, int rowIndex) {
this.valueMap = new LinkedHashMap<>(rowValues.length + 1);
for (int i = 0; i < rowValues.length; i++) {
int i = 0;
for (; i < rowValues.length; i++) {
valueMap.put(headerValues[i], rowValues[i]);
}
while (i < headerValues.length) {
valueMap.put(headerValues[i++], "");
}
this.currentRowIndex = rowIndex;
this.rowIndex = String.valueOf(rowIndex);

View File

@ -105,7 +105,7 @@ public class GetValuesMethodTest {
Assert.assertNotNull(result);
Assert.assertTrue(result.isArray() && result.size() == 8);
Assert.assertNull(result.get(0).get("Some"));
Assert.assertTrue("".equalsIgnoreCase(result.get(0).get("Some").asText()));
Assert.assertTrue("Some".equalsIgnoreCase(result.get(3).get("Some").asText()));
}