Skip to content

Commit

Permalink
Merge pull request #2 from Cambio-Project/dev
Browse files Browse the repository at this point in the history
Changes JSON schema to allow predicates. Looks good
  • Loading branch information
MarvinTaube authored Mar 14, 2024
2 parents 01ae9af + 5772770 commit 0f019f9
Show file tree
Hide file tree
Showing 3 changed files with 144 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@
import psp.sel.EventImpl;

public class TimeBoundFactory {
public static TimeBound getTimeBound(JsonParser p, String type, EventImpl timedEvent, Long lowerLimit, long upperLimit, String timeUnit) throws JsonMappingException {
public static TimeBound getTimeBound(JsonParser p, String type, EventImpl timedEvent, Long lowerLimit, Long upperLimit, String timeUnit) throws JsonMappingException {
if("Upper".equalsIgnoreCase(type)) {
if(upperLimit == null) {
throw JsonMappingException.from(p, "An upper time limit needs to be specified.");
}
return new UpperTimeBound(timedEvent, upperLimit, timeUnit);
}
else if("Lower".equalsIgnoreCase(type) && lowerLimit != null) {
else if("Lower".equalsIgnoreCase(type)) {
if(lowerLimit == null) {
throw JsonMappingException.from(p, "A lower time limit needs to be specified.");
}
return new LowerTimeBound(timedEvent, lowerLimit, timeUnit);
}
else if("Interval".equalsIgnoreCase(type)) {
if(lowerLimit == null || upperLimit == null) {
throw JsonMappingException.from(p, "An upper and a lower time limit need to be specified.");
}
return new Interval(timedEvent, lowerLimit, upperLimit, timeUnit);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,21 @@ public Pattern deserialize(JsonParser parser, DeserializationContext ctx) throws

if(constrainsNode.has("time_bound")) {
JsonNode timeBoundNode = constrainsNode.get("time_bound");
Long lowerLimit = null;
Long lowerTimeLimit = null;
Long upperTimeLimit = null;

if (timeBoundNode.has("lower_limit")) {
lowerLimit = timeBoundNode.get("lower_limit").asLong();
lowerTimeLimit = timeBoundNode.get("lower_limit").asLong();
}

if (timeBoundNode.has("upper_limit")) {
upperTimeLimit = timeBoundNode.get("upper_limit").asLong();
}

timeBound = TimeBoundFactory.getTimeBound(parser,timeBoundNode.get("type").asText(),
pEvent,
lowerLimit,
timeBoundNode.get("upper_limit").asLong(),
lowerTimeLimit,
upperTimeLimit,
timeBoundNode.get("time_unit").asText());
}

Expand Down Expand Up @@ -122,15 +127,21 @@ private ChainEvents buildChainEvents(JsonParser parser, JsonNode chainedEventsNo
}

if (jsonNode.has("time_bound")) {
Long lowerLimit = null;
Long lowerTimeLimit = null;
Long upperTimeLimit = null;

if (jsonNode.get("time_bound").has("lower_limit")) {
lowerLimit = jsonNode.get("time_bound").get("lower_limit").asLong();
lowerTimeLimit = jsonNode.get("time_bound").get("lower_limit").asLong();
}

if (jsonNode.get("time_bound").has("upper_limit")) {
upperTimeLimit = jsonNode.get("time_bound").get("upper_limit").asLong();
}

chainTimeBound = TimeBoundFactory.getTimeBound(parser,jsonNode.get("time_bound").get("type").asText(),
event,
lowerLimit,
jsonNode.get("time_bound").get("upper_limit").asLong(),
lowerTimeLimit,
upperTimeLimit,
jsonNode.get("time_bound").get("time_unit").asText());
}
ChainEvent chainEvent = new ChainEvent(event, chainConstrainEvent, chainTimeBound);
Expand Down
132 changes: 114 additions & 18 deletions restAPI/src/main/resources/request_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,23 @@
},
"specification": {
"type": [
"string",
"object",
"null"
]
],
"properties": {
"predicate_name" : {
"type": "string"
},
"predicate_logic" : {
"type": "string"
},
"measurement_source" : {
"type": "string"
},
"predicate_comparison_value" : {
"type": "string"
}
}
}
},
"required": [
Expand All @@ -47,9 +61,23 @@
},
"specification": {
"type": [
"string",
"object",
"null"
]
],
"properties": {
"predicate_name" : {
"type": "string"
},
"predicate_logic" : {
"type": "string"
},
"measurement_source" : {
"type": "string"
},
"predicate_comparison_value" : {
"type": "string"
}
}
}
},
"required": [
Expand Down Expand Up @@ -95,9 +123,23 @@
},
"specification": {
"type": [
"string",
"object",
"null"
]
],
"properties": {
"predicate_name" : {
"type": "string"
},
"predicate_logic" : {
"type": "string"
},
"measurement_source" : {
"type": "string"
},
"predicate_comparison_value" : {
"type": "string"
}
}
}
},
"required": [
Expand All @@ -113,9 +155,23 @@
},
"specification": {
"type": [
"string",
"object",
"null"
]
],
"properties": {
"predicate_name" : {
"type": "string"
},
"predicate_logic" : {
"type": "string"
},
"measurement_source" : {
"type": "string"
},
"predicate_comparison_value" : {
"type": "string"
}
}
}
},
"required": [
Expand All @@ -136,9 +192,23 @@
},
"specification": {
"type": [
"string",
"object",
"null"
]
],
"properties": {
"predicate_name" : {
"type": "string"
},
"predicate_logic" : {
"type": "string"
},
"measurement_source" : {
"type": "string"
},
"predicate_comparison_value" : {
"type": "string"
}
}
}
},
"required": [
Expand All @@ -154,9 +224,23 @@
},
"specification": {
"type": [
"string",
"object",
"null"
]
],
"properties": {
"predicate_name" : {
"type": "string"
},
"predicate_logic" : {
"type": "string"
},
"measurement_source" : {
"type": "string"
},
"predicate_comparison_value" : {
"type": "string"
}
}
}
},
"required": [
Expand Down Expand Up @@ -187,8 +271,7 @@
},
"required": [
"type",
"time_unit",
"upper_limit"
"time_unit"
]
}
},
Expand Down Expand Up @@ -237,8 +320,7 @@
},
"required": [
"type",
"time_unit",
"upper_limit"
"time_unit"
]
},
"probability_bound": {
Expand Down Expand Up @@ -271,9 +353,23 @@
},
"specification": {
"type": [
"string",
"object",
"null"
]
],
"properties": {
"predicate_name" : {
"type": "string"
},
"predicate_logic" : {
"type": "string"
},
"measurement_source" : {
"type": "string"
},
"predicate_comparison_value" : {
"type": "string"
}
}
}
},
"required": [
Expand Down

0 comments on commit 0f019f9

Please sign in to comment.