Skip to content

Commit

Permalink
Updated epoch range condition to work with null values.
Browse files Browse the repository at this point in the history
  • Loading branch information
timronan committed Dec 6, 2019
1 parent ab63d0f commit ae126de
Show file tree
Hide file tree
Showing 7 changed files with 1,298 additions and 6 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<groupId>edu.iris.dmc</groupId>
<artifactId>stationxml-validator</artifactId>
<packaging>jar</packaging>
<version>1.6.0.1-SNAPSHOT</version>
<version>1.6.0.2-SNAPSHOT</version>
<name>FDSN StationXML Validator</name>

<properties>
Expand Down Expand Up @@ -96,7 +96,7 @@
<dependency>
<groupId>edu.iris.dmc</groupId>
<artifactId>stationxml-seed-converter</artifactId>
<version>2.0.6-SNAPSHOT</version>
<version>2.0.7-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public Message evaluate(Network network) {

if (network.getStations() != null) {
for (Station s : network.getStations()) {
if (network.getEndDate() != null && s.getEndDate() == null) {
return Result.error("Station endDate cannot be null"
+ " if network endDate is defined as: " + XmlUtil.toText(network.getEndDate()));
}
if (s.getStartDate() != null && TimeUtil.isBefore(s.getStartDate(), network.getStartDate())) {
return Result.error("Station startDate " + XmlUtil.toText(s.getStartDate())
+ " cannot occur before network startDate " + XmlUtil.toText(network.getStartDate()));
Expand All @@ -35,6 +39,7 @@ public Message evaluate(Network network) {
return Result.error("Station endDate " + XmlUtil.toText(s.getEndDate())
+ " cannot occur after network endDate " + XmlUtil.toText(network.getEndDate()));
}

}
}
}
Expand All @@ -53,6 +58,12 @@ public Message evaluate(Station station) {

if (station.getChannels() != null) {
for (Channel c : station.getChannels()) {
System.out.println(c.getEndDate());

if (station.getEndDate() != null && c.getEndDate() == null) {
return Result.error("Channel endDate cannot be null"
+ " if station endDate is defined as: " + XmlUtil.toText(station.getEndDate()));
}
if (c.getStartDate() != null && TimeUtil.isBefore(c.getStartDate(), station.getStartDate())) {
return Result.error("Channel startDate " + XmlUtil.toText(c.getStartDate())
+ " cannot occur before Station startDate " + XmlUtil.toText(station.getStartDate()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,24 @@ public class Condition112Pass {
public void init() throws Exception {

}

@Test
public void fail() throws Exception {
try (InputStream is = RuleEngineServiceTest.class.getClassLoader().getResourceAsStream("F2_112.xml")) {
theDocument = DocumentMarshaller.unmarshal(is);

Network n = theDocument.getNetwork().get(0);
//Station s = n.getStations().get(0);
EpochRangeCondition condition = new EpochRangeCondition(true, "");

Message result = condition.evaluate(n);
assertTrue(result instanceof edu.iris.dmc.station.rules.Error);
}

}

@Test
public void pass_EpochRange() throws Exception {
try (InputStream is = RuleEngineServiceTest.class.getClassLoader().getResourceAsStream("P1_112.xml")) {
theDocument = DocumentMarshaller.unmarshal(is);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import org.junit.jupiter.api.Test;

import edu.iris.dmc.DocumentMarshaller;
import edu.iris.dmc.fdsn.station.model.Channel;
import edu.iris.dmc.fdsn.station.model.FDSNStationXML;
import edu.iris.dmc.fdsn.station.model.Network;
import edu.iris.dmc.fdsn.station.model.Station;
Expand Down Expand Up @@ -38,6 +39,23 @@ public void fail() throws Exception {
}

}

@Test
public void fail2() throws Exception {
try (InputStream is = RuleEngineServiceTest.class.getClassLoader().getResourceAsStream("F2_212.xml")) {
theDocument = DocumentMarshaller.unmarshal(is);

Network n = theDocument.getNetwork().get(0);
Station s = n.getStations().get(0);
Channel c = s.getChannels().get(0);
EpochRangeCondition condition = new EpochRangeCondition(true, "");

Message result = condition.evaluate(s);
assertTrue(result instanceof edu.iris.dmc.station.rules.Error);
}

}


@Test
public void pass() throws Exception {
Expand Down
Loading

0 comments on commit ae126de

Please sign in to comment.