diff --git a/src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java b/src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java index c8bc9ce..0c978bb 100644 --- a/src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java +++ b/src/main/java/edu/iris/dmc/station/RuleEngineRegistry.java @@ -166,12 +166,14 @@ private void defaultChannelRules(Set set) { } if (!set.contains(320)) { add(320, new AzimuthDipCondition(true, - "If Channel:Code[2]==(H | L | M | N) THEN Channel:Azimuth and Channel:Dip must be included."), + "If Channel:Code[2]==(H | L | M | N) THEN Channel:Azimuth and Channel:Dip must be included.", + new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }), Channel.class); } if (!set.contains(321)) { add(321, new InstrumentCodeUnitsCondition(true, - "If Channel:Code[2] == (H | L | N) then Stage[1]:InputUnit must equal *m/s* AND Stage[Last]:OutputUnits must equal count*"), + "If Channel:Code[2] == (H | L | N) then Stage[1]:InputUnit must equal *m/s* AND Stage[Last]:OutputUnits must equal count*", + new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }), Channel.class); } if (!set.contains(332)) { diff --git a/src/main/java/edu/iris/dmc/station/conditions/AzimuthDipCondition.java b/src/main/java/edu/iris/dmc/station/conditions/AzimuthDipCondition.java index c1c7ac6..470981f 100644 --- a/src/main/java/edu/iris/dmc/station/conditions/AzimuthDipCondition.java +++ b/src/main/java/edu/iris/dmc/station/conditions/AzimuthDipCondition.java @@ -5,14 +5,17 @@ import edu.iris.dmc.fdsn.station.model.Dip; import edu.iris.dmc.fdsn.station.model.Network; import edu.iris.dmc.fdsn.station.model.Station; +import edu.iris.dmc.station.restrictions.Restriction; import edu.iris.dmc.station.rules.Message; import edu.iris.dmc.station.rules.Result; public class AzimuthDipCondition extends AbstractCondition { - public AzimuthDipCondition(boolean required, String description) { - super(required, description); + private Restriction[] restrictions; + public AzimuthDipCondition(boolean required, String description, Restriction[] restrictions) { + super(required, description); + this.restrictions = restrictions; } @Override @@ -30,6 +33,11 @@ public Message evaluate(Channel channel) { Azimuth azimuth = channel.getAzimuth(); Dip dip = channel.getDip(); String code = channel.getCode(); + for (Restriction r : this.restrictions) { + if (r.qualifies(channel)) { + return Result.success(); + } + } try { if("HLMN".indexOf(code.charAt(1)) >=0 | "hlmn".indexOf(code.charAt(1)) >=0) { if (azimuth == null) { diff --git a/src/main/java/edu/iris/dmc/station/conditions/InstrumentCodeUnitsCondition.java b/src/main/java/edu/iris/dmc/station/conditions/InstrumentCodeUnitsCondition.java index 0b75d44..2cb6414 100644 --- a/src/main/java/edu/iris/dmc/station/conditions/InstrumentCodeUnitsCondition.java +++ b/src/main/java/edu/iris/dmc/station/conditions/InstrumentCodeUnitsCondition.java @@ -5,15 +5,17 @@ import edu.iris.dmc.fdsn.station.model.ResponseStage; import edu.iris.dmc.fdsn.station.model.Station; import edu.iris.dmc.station.exceptions.StationxmlException; +import edu.iris.dmc.station.restrictions.Restriction; import edu.iris.dmc.station.rules.Message; import edu.iris.dmc.station.rules.NestedMessage; import edu.iris.dmc.station.rules.Result; public class InstrumentCodeUnitsCondition extends AbstractCondition { + private Restriction[] restrictions; - public InstrumentCodeUnitsCondition(boolean required, String description) { + public InstrumentCodeUnitsCondition(boolean required, String description, Restriction[] restrictions) { super(required, description); - + this.restrictions = restrictions; } @Override @@ -50,7 +52,11 @@ public Message evaluate(Channel channel) { }else { return Result.success(); } - + for (Restriction r : this.restrictions) { + if (r.qualifies(channel)) { + return Result.success(); + } + } int lastindex = channel.getResponse().getStage().size()-1; ResponseStage stagelast = channel.getResponse().getStage().get(lastindex); String outputUnit =""; diff --git a/src/test/java/edu/iris/dmc/station/conditions/Condition320Test.java b/src/test/java/edu/iris/dmc/station/conditions/Condition320Test.java index 2e824ae..8673084 100644 --- a/src/test/java/edu/iris/dmc/station/conditions/Condition320Test.java +++ b/src/test/java/edu/iris/dmc/station/conditions/Condition320Test.java @@ -13,6 +13,9 @@ import edu.iris.dmc.fdsn.station.model.Network; import edu.iris.dmc.fdsn.station.model.Station; import edu.iris.dmc.station.RuleEngineServiceTest; +import edu.iris.dmc.station.restrictions.ChannelCodeRestriction; +import edu.iris.dmc.station.restrictions.ChannelTypeRestriction; +import edu.iris.dmc.station.restrictions.Restriction; import edu.iris.dmc.station.rules.Message; public class Condition320Test { @@ -32,8 +35,9 @@ public void azimuthfail() throws Exception { Network n = theDocument.getNetwork().get(0); Station s = n.getStations().get(0); Channel c = s.getChannels().get(0); + Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }; - AzimuthDipCondition condition = new AzimuthDipCondition(true, ""); + AzimuthDipCondition condition = new AzimuthDipCondition(true, "", restrictions); Message result = condition.evaluate(c); assertTrue(result instanceof edu.iris.dmc.station.rules.Error); } @@ -48,13 +52,33 @@ public void dipfail() throws Exception { Network n = theDocument.getNetwork().get(0); Station s = n.getStations().get(0); Channel c = s.getChannels().get(0); + Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }; - AzimuthDipCondition condition = new AzimuthDipCondition(true, ""); + + AzimuthDipCondition condition = new AzimuthDipCondition(true, "", restrictions); Message result = condition.evaluate(c); assertTrue(result instanceof edu.iris.dmc.station.rules.Error); } } + + @Test + public void dipPass2() throws Exception { + try (InputStream is = RuleEngineServiceTest.class.getClassLoader().getResourceAsStream("P3_3201.xml")) { + theDocument = DocumentMarshaller.unmarshal(is); + + Network n = theDocument.getNetwork().get(0); + Station s = n.getStations().get(0); + Channel c = s.getChannels().get(0); + Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }; + + + AzimuthDipCondition condition = new AzimuthDipCondition(true, "", restrictions); + Message result = condition.evaluate(c); + assertTrue(result instanceof edu.iris.dmc.station.rules.Success); + } + + } @Test public void pass() throws Exception { @@ -64,9 +88,10 @@ public void pass() throws Exception { Network n = theDocument.getNetwork().get(0); Station s = n.getStations().get(0); Channel c = s.getChannels().get(0); + Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }; - AzimuthDipCondition condition = new AzimuthDipCondition(true, ""); + AzimuthDipCondition condition = new AzimuthDipCondition(true, "", restrictions); Message result = condition.evaluate(c); assertTrue(result instanceof edu.iris.dmc.station.rules.Success); diff --git a/src/test/java/edu/iris/dmc/station/conditions/Condition321Test.java b/src/test/java/edu/iris/dmc/station/conditions/Condition321Test.java index dcd3a6b..5ffc551 100644 --- a/src/test/java/edu/iris/dmc/station/conditions/Condition321Test.java +++ b/src/test/java/edu/iris/dmc/station/conditions/Condition321Test.java @@ -13,6 +13,9 @@ import edu.iris.dmc.fdsn.station.model.Network; import edu.iris.dmc.fdsn.station.model.Station; import edu.iris.dmc.station.RuleEngineServiceTest; +import edu.iris.dmc.station.restrictions.ChannelCodeRestriction; +import edu.iris.dmc.station.restrictions.ChannelTypeRestriction; +import edu.iris.dmc.station.restrictions.Restriction; import edu.iris.dmc.station.rules.Message; import edu.iris.dmc.station.rules.NestedMessage; @@ -33,8 +36,9 @@ public void azimuthfail() throws Exception { Network n = theDocument.getNetwork().get(0); Station s = n.getStations().get(0); Channel c = s.getChannels().get(0); + Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }; - InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, ""); + InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, "", restrictions); Message result = condition.evaluate(c); NestedMessage nestedMessage=(NestedMessage)result; System.out.println(nestedMessage.getNestedMessages().get(0).getDescription()); @@ -56,9 +60,10 @@ public void pass() throws Exception { Network n = theDocument.getNetwork().get(0); Station s = n.getStations().get(0); Channel c = s.getChannels().get(0); + Restriction[] restrictions = new Restriction[] { new ChannelCodeRestriction(), new ChannelTypeRestriction() }; - InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, ""); + InstrumentCodeUnitsCondition condition = new InstrumentCodeUnitsCondition(true, "", restrictions); Message result = condition.evaluate(c); assertTrue(result instanceof edu.iris.dmc.station.rules.Success); diff --git a/src/test/resources/P3_3201.xml b/src/test/resources/P3_3201.xml new file mode 100644 index 0000000..889aa11 --- /dev/null +++ b/src/test/resources/P3_3201.xml @@ -0,0 +1,243 @@ + + + ANSS Station Information System + ANSS Station Information System + 2020-06-17T16:22:51.455299+00:00 + + USGS Northern California Regional Network + 53 + 1 + + 40.6415 + -121.94737 + 585.0 + + Whitmore + Whitmore + Shasta + CA + USA + + NCSN Standard + + NCSN + + 2020-06-01T00:00:00+00:00 + 18 + 18 + + + [SENSOR::TITAN::1954], [SENSOR::L-4C VERTICAL::6200], [LOGGER::CENTAUR::6859] + 2020-06-04T00:00:00+00:00 + + SIS Field Action + + + + New Install + 2020-06-04T00:00:00+00:00 + + jkrueger + + + 40.6415 + -121.94737 + 585.0 + 0.0 + CONTINUOUS + HEALTH + 1.0 + + Accelerometer + + + NANOMETRICS + NANOMETRICS + CENTAUR + 6859 + 2020-01-01T00:00:00+00:00 + + + + 1000.0 + 0.25 + + deg + Angle in Degree [0-360] + + + counts + Digital Count in Digital counts + + + + + + deg + Angle in Degree [0-360] + + + counts + Digital Count in Digital counts + + DIGITAL + + + 1.0 + 1 + 0 + 0.0 + 0.0 + + + 1000.0 + 0.25 + + + + + + + [SENSOR::TITAN::1954], [SENSOR::L-4C VERTICAL::6200], [LOGGER::CENTAUR::6859] + 2020-06-04T00:00:00+00:00 + + SIS Field Action + + + + New Install + 2020-06-04T00:00:00+00:00 + + jkrueger + + + 40.6415 + -121.94737 + 585.0 + 0.0 + CONTINUOUS + HEALTH + 1.0 + + Accelerometer + + + NANOMETRICS + NANOMETRICS + CENTAUR + 6859 + 2020-01-01T00:00:00+00:00 + + + + 1000.0 + 0.25 + + deg + Angle in Degree [0-360] + + + counts + Digital Count in Digital counts + + + + + + deg + Angle in Degree [0-360] + + + counts + Digital Count in Digital counts + + DIGITAL + + + 1.0 + 1 + 0 + 0.0 + 0.0 + + + 1000.0 + 0.25 + + + + + + + [SENSOR::TITAN::1954], [SENSOR::L-4C VERTICAL::6200], [LOGGER::CENTAUR::6859] + 2020-06-04T00:00:00+00:00 + + SIS Field Action + + + + New Install + 2020-06-04T00:00:00+00:00 + + jkrueger + + + 40.6415 + -121.94737 + 585.0 + 0.0 + CONTINUOUS + HEALTH + 1.0 + + Accelerometer + + + NANOMETRICS + NANOMETRICS + CENTAUR + 6859 + 2020-01-01T00:00:00+00:00 + + + + 1.0 + 0.25 + + counts + Digital Count in Digital counts + + + counts + Digital Count in Digital counts + + + + + + counts + Digital Count in Digital counts + + + counts + Digital Count in Digital counts + + DIGITAL + + + 1.0 + 1 + 0 + 0.0 + 0.0 + + + 1.0 + 0.25 + + + + + + +