Commit a5c76585 authored by Ryan Berkheimer's avatar Ryan Berkheimer
Browse files

added error exits in exception blocks for cases where parsing or computation issues are encountered

parent 3a527da5
{
"collections": [
{
"id": "testTable1",
"classifiers": {"namespace": "/path/to/test.db"},
"fields": ["key", "record", "filename", "type"]
},
{
"id": "testTable2",
"classifiers": {"namespace": "/path/to/test2.db"},
"fields": ["key", "type", "receipt_date", "insert_date"]
}
]
}
{
"metadata": {
"id": "email",
"version": 1.0,
"classifiers": {},
"description": null
}
}
{
"transformations": [
{
"id": "test1",
"type": "left join",
"parent": "testTable1",
"child": "testTable2",
"field": "key"
}
]
}
{
"connections": [
{
"id": "/path/to/test.db",
"url": "whatever",
"user": "test",
"password": null
}
]
}
{
"conditions": [
{
"id": "1",
"type": "comparison",
"operator": ">=",
"field": "key",
"value": null
},
{
"id": "2",
"type": "comparison",
"operator": "<",
"field": "key",
"value": null
},
{
"id": "three",
"type": "composite",
"operator": "or",
"conditions": ["1","2","hi"]
},
{
"id": "hi",
"type": "comparison",
"operator": "=",
"field": "type",
"value": null
},
{
"id": "dummy",
"type": "comparison",
"operator": "=",
"field": "type",
"value": null
},
{
"id": "nested_join",
"type": "composite",
"operator": "and",
"conditions": ["dummy", "three"]
}
]
}
{
"fields": [
{
"id": "id",
"type": "integer",
"required": false
},
{
"id": "key",
"type": "string",
"required": true
},
{
"id": "record",
"type": "string",
"required": true
},
{
"id": "filename",
"type": "string",
"required": true
},
{
"id": "type",
"type": "string",
"required": true
},
{
"id": "receipt_date",
"type": "datetime",
"required": true
},
{
"id": "insert_date",
"type": "datetime",
"required": true
}
]
}
{
"metadata": {
"id": "clisam",
"version": 1.0,
"classifiers": {},
"description": null
}
}
......@@ -4,27 +4,28 @@
"schema": {
"plugin": "gov.noaa.messageapi.schemas.DefaultSchema",
"constructor": {
"metadata": "{}/resources/main/storage/schemas/simple/clisam/metadata.json",
"fields": "{}/resources/main/storage/schemas/simple/clisam/fields.json",
"conditions": "{}/resources/main/storage/schemas/simple/clisam/conditions.json",
"condition-operators": "gov.noaa.messageapi.factories.SimpleConditionOperatorFactory"
"metadata": "{_standard_}",
"fields": "{_standard_}"
}
},
"container": {
"plugin": "gov.noaa.messageapi.containers.DefaultContainer",
"constructor": {
"metadata": "{}/resources/main/storage/containers/simple/clisam/metadata.json",
"collections": "{}/resources/main/storage/containers/simple/clisam/collections.json",
"transformations": "{}/resources/main/storage/containers/simple/clisam/transformations.json"
"metadata": "{_standard_}",
"collections": "{_standard_}"
}
},
"protocol": {
"plugin": "gov.noaa.messageapi.protocols.DefaultProtocol",
"constructor": {
"metadata": "{}/resources/main/storage/protocols/jdbc/metadata.json",
"endpoint": "gov.noaa.messageapi.test.ClisamEndpoint",
"connections": "{}/resources/main/storage/protocols/jdbc/connections.json"
"metadata": "{_standard_}",
"endpoints": [
{
"plugin": "gov.noaa.messageapi.endpoints.NativeEndpoint",
"connections": "{_standard_}"
}
]
}
}
}
}
}
\ No newline at end of file
......@@ -18,7 +18,6 @@
"protocol": {
"plugin": "gov.noaa.messageapi.protocols.DefaultProtocol",
"constructor": {
"metadata": "{}/resources/test/metadata/basic-native/protocol.json",
"endpoints": [{
"plugin": "gov.noaa.messageapi.endpoints.NativeEndpoint",
"connections": "{}/resources/test/basic-native/parameters.json"
......
......@@ -17,9 +17,7 @@
"constructor": {
"metadata": "{}/resources/test/metadata/file-reader/container.json",
"collections": "{}/resources/test/file-reader/parameters.json",
"transformations": {
"map": "{}/resources/test/file-reader/parameters.json"
}
"transformations": "{}/resources/test/file-reader/parameters.json"
}
},
"protocol": {
......
......@@ -11,7 +11,7 @@
"plugin": "gov.noaa.messageapi.containers.DefaultContainer",
"constructor": {
"collections": "{}/resources/test/native-transformation/parameters.json",
"transformations": {"map": "{}/resources/test/native-transformation/parameters.json"}
"transformations": "{}/resources/test/native-transformation/parameters.json"
}
},
"protocol": {
......
......@@ -12,7 +12,7 @@
"constructor": {
"metadata": "{}/resources/test/containers/simple/condition-test/metadata.json",
"collections": "{}/resources/test/containers/simple/condition-test/collections.json",
"transformations": {"map": "{}/resources/test/containers/simple/condition-test/transformations.json"}
"transformations": "{}/resources/test/containers/simple/condition-test/transformations.json"
}
},
"protocol": {
......
......@@ -7,7 +7,7 @@
"container": {"plugin": "gov.noaa.messageapi.containers.DefaultContainer",
"constructor": {"metadata": "{}/resources/test/containers/simple/email/metadata.json",
"collections": "{}/resources/test/containers/simple/email/collections.json",
"transformations": {"map": "{}/resources/test/containers/simple/email/transformations.json"}}},
"transformations": "{}/resources/test/containers/simple/email/transformations.json"}},
"protocol": {"plugin": "gov.noaa.messageapi.protocols.DefaultProtocol",
"constructor": {"metadata": "{}/resources/test/protocols/email/simple/metadata.json",
"endpoints": [{"plugin": "gov.noaa.messageapi.test.endpoints.EmailEndpointTest",
......
......@@ -7,7 +7,7 @@
"container": {"plugin": "gov.noaa.messageapi.containers.DefaultContainer",
"constructor": {"metadata": "{}/resources/test/containers/simple/clisam/metadata.json",
"collections": "{}/resources/test/containers/simple/clisam/collections.json",
"transformations": {"map": "{}/resources/test/containers/simple/clisam/transformations.json"}}},
"transformations": "{}/resources/test/containers/simple/clisam/transformations.json"}},
"protocol": {"plugin": "gov.noaa.messageapi.protocols.DefaultProtocol",
"constructor": {"metadata": "{}/resources/test/protocols/jdbc/sqlite/clisam/metadata.json",
"endpoints": [{"plugin": "gov.noaa.messageapi.test.endpoints.EmailEndpointTest",
......
......@@ -28,7 +28,6 @@ public class ContainerDefinition {
private List<String> transformations = null;
private List<Map.Entry<String,String>> classifiers = null;
@SuppressWarnings("unchecked")
public ContainerDefinition(Map<String, Object> properties) throws Exception {
if (properties.containsKey("metadata")) {
this.parseMetadataSpec((String) properties.get("metadata"));
......@@ -41,7 +40,7 @@ public class ContainerDefinition {
throw new Exception("Missing necessary 'collections' key when parsing container definition.");
}
if (properties.containsKey("transformations")) {
this.parseTransformationSpec((Map<String,String>) properties.get("transformations"));
this.parseTransformationSpec(properties.get("transformations"));
} else {
this.setEmptyTransformationMaps();
}
......@@ -56,7 +55,6 @@ public class ContainerDefinition {
this.transformationMaps = new ArrayList<Map<String,Object>>(definition.getTransformationMaps());
}
private void parseMetadataSpec(String spec) throws Exception {
MetadataParser parser = new MetadataParser(spec);
this.metadataMap = parser.getMetadataMap();
......@@ -69,12 +67,22 @@ public class ContainerDefinition {
this.classifiers = parser.getClassifiers();
}
private void parseTransformationSpec(Map<String,String> transformationSpec) throws Exception {
if (transformationSpec.containsKey("map")) {
TransformationParser parser = new TransformationParser(transformationSpec.get("map"));
this.transformationMaps = parser.getTransformationMaps();
this.transformations = parser.getTransformations();
} else {
@SuppressWarnings("unchecked")
private void parseTransformationSpec(Object transformationSpec) throws Exception {
try {
if (transformationSpec instanceof String) {
TransformationParser parser = new TransformationParser(((String) transformationSpec));
this.transformationMaps = parser.getTransformationMaps();
this.transformations = parser.getTransformations();
} else if (transformationSpec instanceof List) {
TransformationParser parser = new TransformationParser((List<Map<String,Object>>)transformationSpec);
this.transformationMaps = parser.getTransformationMaps();
this.transformations = parser.getTransformations();
} else {
this.setEmptyTransformationMaps();
}
} catch (Exception e) {
System.out.println("WARNING - transformation parsing failed. Setting empty transformations.");
this.setEmptyTransformationMaps();
}
}
......
......@@ -22,9 +22,12 @@ public abstract class BaseParser {
update();
} catch (Exception e) {
System.err.println("Exception thrown in resource string constructor: " + e.getMessage());
System.exit(1);
}
}
public BaseParser(){}
@SuppressWarnings("unchecked")
public BaseParser(Object jsonModel) throws Exception {
try {
......@@ -36,6 +39,7 @@ public abstract class BaseParser {
}
} catch (Exception e) {
System.err.println("Exception thrown in resource hashmap constructor: " + e.getMessage());
System.exit(1);
}
}
......@@ -47,6 +51,7 @@ public abstract class BaseParser {
keys = JsonUtils.keys(jsonModel);
} catch (Exception e){
System.err.println("Exception thrown while gathering resource keys: " + e.getMessage());
System.exit(1);
}
}
......@@ -79,6 +84,7 @@ public abstract class BaseParser {
}
} catch (Exception e) {
System.err.println("Exception thrown while updating the resource: " + e.getMessage());
System.exit(1);
}
}
......
......@@ -14,13 +14,20 @@ import gov.noaa.messageapi.utils.general.PathUtils;
*/
public class TransformationParser extends BaseParser {
private List<Map<String,Object>> transformationMaps;
@SuppressWarnings("unchecked")
public TransformationParser(String spec) throws Exception {
super(PathUtils.reconcileKeywords(spec));
this.setTransformationMaps((List<Map<String, Object>>)super.getValue("transformations"));
}
public TransformationParser(List<Map<String,Object>> transformationMapList) throws Exception {
this.setTransformationMaps(transformationMapList);
}
@SuppressWarnings("unchecked")
public List<Map<String, Object>> getTransformationMaps() {
return (List<Map<String,Object>>) super.getValue("transformations");
return this.transformationMaps;
}
public List<String> getTransformations() {
......@@ -30,6 +37,10 @@ public class TransformationParser extends BaseParser {
public void process(){
}
private void setTransformationMaps(List<Map<String,Object>> transformationMapList){
this.transformationMaps = transformationMapList;
}
public Set<String> getRequiredKeys() {
Set<String> set = new HashSet<String>();
set.add("transformations");
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment