Skip to content

Commit f3aa657

Browse files
Version bump of Tableschema lib.
Allow Packages to hold images
1 parent 066afbd commit f3aa657

File tree

6 files changed

+175
-159
lines changed

6 files changed

+175
-159
lines changed

src/main/java/io/frictionlessdata/datapackage/JSONBase.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import com.fasterxml.jackson.databind.node.TextNode;
99
import io.frictionlessdata.datapackage.exceptions.DataPackageException;
1010
import io.frictionlessdata.datapackage.exceptions.DataPackageFileOrUrlNotFoundException;
11+
import io.frictionlessdata.datapackage.exceptions.DataPackageValidationException;
1112
import io.frictionlessdata.datapackage.resource.Resource;
1213
import io.frictionlessdata.tableschema.exception.JsonParsingException;
1314
import io.frictionlessdata.tableschema.io.FileReference;
@@ -291,6 +292,8 @@ static String getFileContentAsString(URL url) {
291292
try {
292293
return getFileContentAsString(url.openStream());
293294
} catch (Exception ex) {
295+
if (ex instanceof FileNotFoundException)
296+
throw new DataPackageValidationException(ex.getMessage(), ex);
294297
throw new DataPackageException(ex);
295298
}
296299
}

src/main/java/io/frictionlessdata/datapackage/Package.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import io.frictionlessdata.datapackage.resource.AbstractDataResource;
1414
import io.frictionlessdata.datapackage.resource.AbstractReferencebasedResource;
1515
import io.frictionlessdata.datapackage.resource.Resource;
16+
import io.frictionlessdata.tableschema.exception.JsonParsingException;
1617
import io.frictionlessdata.tableschema.exception.ValidationException;
1718
import io.frictionlessdata.tableschema.io.LocalFileReference;
1819
import io.frictionlessdata.tableschema.schema.Schema;
@@ -111,7 +112,12 @@ public Package(String jsonStringSource, Path basePath, boolean strict) throws Ex
111112
this.basePath = basePath;
112113

113114
// Create and set the JsonNode for the String representation of descriptor JSON object.
114-
this.setJson((ObjectNode) JsonUtil.getInstance().createNode(jsonStringSource));
115+
try {
116+
this.setJson((ObjectNode) JsonUtil.getInstance().createNode(jsonStringSource));
117+
} catch(JsonParsingException ex) {
118+
throw new DataPackageException(ex.getMessage(), ex);
119+
}
120+
115121
}
116122

117123
/**
@@ -796,7 +802,7 @@ private void addResource(Resource resource, boolean validate)
796802
throws IOException, ValidationException, DataPackageException{
797803
DataPackageException dpe = null;
798804
if (resource.getName() == null){
799-
dpe = new DataPackageException("Invalid Resource, it does not have a name property.");
805+
dpe = new DataPackageValidationException("Invalid Resource, it does not have a name property.");
800806
}
801807
if (resource instanceof AbstractDataResource)
802808
addResource((AbstractDataResource) resource, validate);
@@ -811,7 +817,7 @@ private void addResource(AbstractDataResource resource, boolean validate)
811817
DataPackageException dpe = null;
812818
// If a name property isn't given...
813819
if ((resource.getDataProperty() == null) || (resource).getFormat() == null) {
814-
dpe = new DataPackageException("Invalid Resource. The data and format properties cannot be null.");
820+
dpe = new DataPackageValidationException("Invalid Resource. The data and format properties cannot be null.");
815821
} else {
816822
dpe = checkDuplicates(resource);
817823
}
@@ -825,7 +831,7 @@ private void addResource(AbstractReferencebasedResource resource, boolean valida
825831
throws IOException, ValidationException, DataPackageException{
826832
DataPackageException dpe = null;
827833
if (resource.getPaths() == null) {
828-
dpe = new DataPackageException("Invalid Resource. The path property cannot be null.");
834+
dpe = new DataPackageValidationException("Invalid Resource. The path property cannot be null.");
829835
} else {
830836
dpe = checkDuplicates(resource);
831837
}

src/main/java/io/frictionlessdata/datapackage/exceptions/DataPackageValidationException.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,12 @@ public DataPackageValidationException(String msg) {
3131
public DataPackageValidationException(Throwable t) {
3232
super(t.getMessage(), t);
3333
}
34+
/**
35+
* Constructs an instance of <code>DataPackageException</code> by wrapping a Throwable
36+
*
37+
* @param t the wrapped exception.
38+
*/
39+
public DataPackageValidationException(String msg, Throwable t) {
40+
super(msg, t);
41+
}
3442
}

src/main/java/io/frictionlessdata/datapackage/resource/FilebasedResource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.fasterxml.jackson.annotation.JsonInclude;
55
import com.fasterxml.jackson.annotation.JsonInclude.Include;
66
import io.frictionlessdata.datapackage.exceptions.DataPackageException;
7+
import io.frictionlessdata.datapackage.exceptions.DataPackageValidationException;
78
import io.frictionlessdata.tableschema.Table;
89
import io.frictionlessdata.tableschema.tabledatasource.TableDataSource;
910

@@ -39,7 +40,7 @@ public FilebasedResource(String name, Collection<File> paths, File basePath, Cha
3940
super(name, paths);
4041
this.encoding = encoding.name();
4142
if (null == paths) {
42-
throw new DataPackageException("Invalid Resource. " +
43+
throw new DataPackageValidationException("Invalid Resource. " +
4344
"The path property cannot be null for file-based Resources.");
4445
}
4546
this.setSerializationFormat(sniffFormat(paths));
@@ -52,7 +53,7 @@ public FilebasedResource(String name, Collection<File> paths, File basePath, Cha
5253
https://frictionlessdata.io/specs/data-resource/index.html#url-or-path
5354
*/
5455
if (path.isAbsolute()) {
55-
throw new DataPackageException("Path entries for file-based Resources cannot be absolute");
56+
throw new DataPackageValidationException("Path entries for file-based Resources cannot be absolute");
5657
}
5758
}
5859
serializeToFile = true;

src/main/java/io/frictionlessdata/datapackage/resource/Resource.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import io.frictionlessdata.datapackage.Dialect;
99
import io.frictionlessdata.datapackage.JSONBase;
1010
import io.frictionlessdata.datapackage.exceptions.DataPackageException;
11+
import io.frictionlessdata.datapackage.exceptions.DataPackageValidationException;
1112
import io.frictionlessdata.tableschema.Table;
1213
import io.frictionlessdata.tableschema.iterator.TableIterator;
1314
import io.frictionlessdata.tableschema.schema.Schema;
@@ -417,7 +418,7 @@ static AbstractResource build(ObjectNode resourceJson, Object basePath, boolean
417418
// from the spec: " a JSON string - in this case the format or
418419
// mediatype properties MUST be provided
419420
// https://specs.frictionlessdata.io/data-resource/#data-inline-data
420-
throw new DataPackageException(
421+
throw new DataPackageValidationException(
421422
"Invalid Resource. The format property cannot be null for inlined CSV data.");
422423
}
423424
resource = new JSONDataResource(name, data.toString());
@@ -426,7 +427,7 @@ static AbstractResource build(ObjectNode resourceJson, Object basePath, boolean
426427
else if (format.equals(Resource.FORMAT_CSV))
427428
resource = new CSVDataResource(name, data.toString());
428429
} else {
429-
throw new DataPackageException(
430+
throw new DataPackageValidationException(
430431
"Invalid Resource. The path property or the data and format properties cannot be null.");
431432
}
432433
resource.setDialect(dialect);

0 commit comments

Comments
 (0)