Permalink
Browse files

JSON rules initial version complete

  • Loading branch information...
richturner committed Jan 3, 2019
1 parent c0e485c commit 5289d9b152426b404b50bd0ae371385de6cde245
@@ -806,7 +806,7 @@ protected String buildFromString(BaseAssetQuery query, int level) {
}

if (level == 1) {
if (query.parent != null && !query.parent.noParent && (query.parent.id != null || query.parent.type != null)) {
if (query.parent != null && !query.parent.noParent && (query.parent.id != null || query.parent.type != null || query.parent.name != null)) {
sb.append("cross join ASSET P ");
} else {
sb.append("left outer join ASSET P on A.PARENT_ID = P.ID ");
@@ -890,19 +890,27 @@ protected String buildWhereClause(BaseAssetQuery query, int level, List<Paramete
}

if (query.parent != null) {
// Can only restrict recursive query parent by asset type
if (level == 1 && query.parent.id != null) {
sb.append(" and p.ID = a.PARENT_ID");
sb.append(" and A.PARENT_ID = ?");
final int pos = binders.size() + 1;
binders.add(st -> st.setString(pos, query.parent.id));
} else if (query.parent.type != null) {
sb.append(" and p.ID = a.PARENT_ID");
sb.append(" and P.ASSET_TYPE = ?");
final int pos = binders.size() + 1;
binders.add(st -> st.setString(pos, query.parent.type));
} else if (level == 1 && query.parent.noParent) {
sb.append(" and A.PARENT_ID is null");
} else if (query.parent.type != null || query.parent.name != null) {

sb.append(" and p.ID = a.PARENT_ID");

if (query.parent.type != null) {
sb.append(" and P.ASSET_TYPE = ?");
final int pos = binders.size() + 1;
binders.add(st -> st.setString(pos, query.parent.type));
}
if (query.parent.name != null) {
sb.append(" and P.NAME = ?");
final int pos = binders.size() + 1;
binders.add(st -> st.setString(pos, query.parent.name));
}
}
}

@@ -235,6 +235,7 @@ public boolean test(AssetState assetState) {
return assetState ->
(predicate.id == null || predicate.id.equals(assetState.getParentId()))
&& (predicate.type == null || predicate.type.equals(assetState.getParentTypeString()))
&& (predicate.name == null || predicate.name.equals(assetState.getParentName()))
&& (!predicate.noParent || assetState.getParentId() == null);
}

@@ -260,14 +261,20 @@ public boolean test(AssetState assetState) {
GeodeticCalculator calculator = new GeodeticCalculator();
calculator.setStartingGeographicPoint(radialLocationPredicate.lng, radialLocationPredicate.lat);
calculator.setDestinationGeographicPoint(coordinate.y, coordinate.x);
return calculator.getOrthodromicDistance() < radialLocationPredicate.radius;
if (predicate.negated) {
return calculator.getOrthodromicDistance() > radialLocationPredicate.radius;
}
return calculator.getOrthodromicDistance() <= radialLocationPredicate.radius;
} else if (predicate instanceof RectangularGeofencePredicate) {
// Again this is a euclidean plane so doesn't work perfectly for WGS lat/lng - the bigger the rectangle to less accurate it is)
RectangularGeofencePredicate rectangularLocationPredicate = (RectangularGeofencePredicate) predicate;
Envelope envelope = new Envelope(rectangularLocationPredicate.latMin,
rectangularLocationPredicate.lngMin,
rectangularLocationPredicate.latMax,
rectangularLocationPredicate.lngMax);
if (predicate.negated) {
return !envelope.contains(coordinate);
}
return envelope.contains(coordinate);
} else {
throw new UnsupportedOperationException("Location predicate '" + predicate.getClass().getSimpleName() + "' not supported in rules matching");
Oops, something went wrong.

0 comments on commit 5289d9b

Please sign in to comment.