Skip to content

Commit

Permalink
Merge pull request #7057 from JingMa87/7056-skip-unknown-field-type
Browse files Browse the repository at this point in the history
7056 Skip unknown types in a dataset which cause the whole dataset to…
  • Loading branch information
kcondon committed Jul 13, 2020
2 parents 4f8038a + 057a8af commit 865c57b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,10 @@ private List<DatasetField> parseFieldsFromArray(JsonArray fieldsArray, Boolean t
List<DatasetField> fields = new LinkedList<>();
for (JsonObject fieldJson : fieldsArray.getValuesAs(JsonObject.class)) {
try {
fields.add(parseField(fieldJson, testType));
DatasetField field = parseField(fieldJson, testType);
if (field != null) {
fields.add(field);
}
} catch (CompoundVocabularyException ex) {
DatasetFieldType fieldType = datasetFieldSvc.findByNameOpt(fieldJson.getString("typeName", ""));
if (lenient && (DatasetFieldConstant.geographicCoverage).equals(fieldType.getName())) {
Expand Down Expand Up @@ -566,7 +569,8 @@ public DatasetField parseField(JsonObject json, Boolean testType) throws JsonPar


if (type == null) {
throw new JsonParseException("Can't find type '" + json.getString("typeName", "") + "'");
logger.fine("Can't find type '" + json.getString("typeName", "") + "'");
return null;
}
if (testType && type.isAllowMultiples() != json.getBoolean("multiple")) {
throw new JsonParseException("incorrect multiple for field " + json.getString("typeName", ""));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -433,12 +433,12 @@ public void testParseEmptyDataset() throws JsonParseException {

/**
*
* Expect an exception when the dataset version JSON contains fields
* Expect no exception when the dataset version JSON contains fields
* that the {@link DatasetFieldService} doesn't know about.
* @throws JsonParseException as expected
* @throws JsonParseException should not happen here
* @throws IOException when test file IO goes wrong - this is bad.
*/
@Test(expected = JsonParseException.class)
@Test
public void testParseOvercompleteDatasetVersion() throws JsonParseException, IOException {
JsonObject dsJson;
try (InputStream jsonFile = ClassLoader.getSystemResourceAsStream("json/complete-dataset-version.json")) {
Expand Down

0 comments on commit 865c57b

Please sign in to comment.