Skip to content

Commit f0ebbcf

Browse files
authored
Merge pull request #23 from SlicingDice/feature/correct-data-extraction-validators
Correct data extraction validator
2 parents d9d84e7 + c6710ab commit f0ebbcf

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Change Log
22

3+
## [2.0.2]
4+
### Updated
5+
- Correct data extraction validator to accept columns: all
6+
37
## [2.0.1]
48
### Updated
59
- Improve exception throwing in case of JSON parsing error.

src/main/java/com/slicingdice/jslicer/utils/validators/QueryDataExtractionValidator.java

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import com.slicingdice.jslicer.exceptions.client.InvalidQueryException;
1919
import com.slicingdice.jslicer.exceptions.client.MaxLimitException;
20+
import org.json.JSONArray;
2021
import org.json.JSONObject;
2122

2223
import java.util.Iterator;
@@ -48,9 +49,20 @@ private boolean validKeys() {
4849
throw new InvalidQueryException("The key 'limit' in query has a invalid value.");
4950
}
5051
} else if (key.equals("columns")) {
51-
if (this.data.getJSONArray("columns").length() > 10) {
52-
throw new MaxLimitException("The key 'columns' in data extraction result must" +
53-
" have up to 10 columns.");
52+
final Object columns = this.data.get("columns");
53+
if (columns instanceof JSONArray) {
54+
if (((JSONArray) columns).length() > 10) {
55+
throw new MaxLimitException("The key 'columns' in data extraction result" +
56+
" must have up to 10 columns.");
57+
}
58+
} else if (columns instanceof String) {
59+
if (!columns.equals("all")) {
60+
throw new InvalidQueryException("The key 'columns' should be a list of" +
61+
" columns or the keyword 'all'");
62+
}
63+
} else {
64+
throw new InvalidQueryException("The key 'columns' should be a list of" +
65+
" columns or the keyword 'all'");
5466
}
5567
}
5668
}

0 commit comments

Comments
 (0)