Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@
<java.version>17</java.version>
<camel.version>4.10.6</camel.version>
<entur.helpers.version>5.34.0</entur.helpers.version>
<netex-validator-java.version>10.3.0</netex-validator-java.version>
<netex-parser-java.version>3.1.52</netex-parser-java.version>
<netex-validator-java.version>11.0.0-SNAPSHOT</netex-validator-java.version>
<netex-parser-java.version>4.0.0-SNAPSHOT</netex-parser-java.version>
<netex-java-model.version>1.0.16-SNAPSHOT</netex-java-model.version>
<jts-core.version>1.20.0</jts-core.version>
<commons-io.version>2.11.0</commons-io.version>
<zt-zip.version>1.17</zt-zip.version>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package no.entur.antu.validation.validator.servicejourney.servicealteration.support;

import jakarta.xml.bind.JAXBElement;
import java.util.Collection;
import org.entur.netex.validation.validator.jaxb.JAXBValidationContext;
import org.rutebanken.netex.model.DatedServiceJourney;
import org.rutebanken.netex.model.DatedServiceJourneyRefStructure;

public class ServiceAlterationUtils {

Expand All @@ -17,11 +15,11 @@ public static Collection<DatedServiceJourney> datedServiceJourneysWithReferenceT
.datedServiceJourneys()
.stream()
.filter(dsj ->
dsj
.getJourneyRef()
.stream()
.map(JAXBElement::getValue)
.anyMatch(DatedServiceJourneyRefStructure.class::isInstance)
dsj.getReplacedJourneys() != null &&
!dsj
.getReplacedJourneys()
.getDatedVehicleJourneyRefOrNormalDatedVehicleJourneyRef()
.isEmpty()
)
.toList();
}
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/configuration.antu.sweden.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ validationRuleConfigs:
name: SE/Authority URL
severity: WARNING

# Reduced severity for invalid service links
- code: SERVICE_LINK_3
name: SE/ServiceLink missing element Projections
severity: WARNING


Original file line number Diff line number Diff line change
Expand Up @@ -794,30 +794,32 @@ public CreateDatedServiceJourney withDatedServiceJourneyRef(

public DatedServiceJourney create() {
DatedServiceJourney datedServiceJourney = new DatedServiceJourney()
.withId(ref());

Collection<JAXBElement<? extends JourneyRefStructure>> journeyRefs =
new ArrayList<>();
journeyRefs.add(
createJaxbElement(
new ServiceJourneyRefStructure().withRef(serviceJourneyRef.ref())
)
);
if (datedServiceJourneyRef != null) {
journeyRefs.add(
.withId(ref())
.withJourneyRef(
createJaxbElement(
new DatedServiceJourneyRefStructure()
.withRef(datedServiceJourneyRef.ref())
new ServiceJourneyRefStructure().withRef(serviceJourneyRef.ref())
)
);
}

return datedServiceJourney
.withJourneyRef(journeyRefs)
)
.withOperatingDayRef(
new OperatingDayRefStructure().withRef(operatingDayRef.ref())
)
.withServiceAlteration(serviceAlteration);

if (datedServiceJourneyRef != null) {
ReplacedJourneys_RelStructure replacedDSJ =
new ReplacedJourneys_RelStructure();
replacedDSJ
.getDatedVehicleJourneyRefOrNormalDatedVehicleJourneyRef()
.add(
createJaxbElement(
new DatedVehicleJourneyRefStructure()
.withRef(datedServiceJourneyRef.ref())
)
);
datedServiceJourney.withReplacedJourneys(replacedDSJ);
}

return datedServiceJourney;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
import org.apache.commons.io.IOUtils;
import org.entur.netex.NetexParser;
import org.entur.netex.index.api.NetexEntitiesIndex;
import org.entur.netex.validation.validator.ValidationIssue;
Expand All @@ -21,34 +23,60 @@ class InvalidServiceAlterationValidatorIntegrationTest {

private static final String TEST_CODESPACE = "NSB";
private static final String TEST_LINE_XML_FILE = "line.xml";
private static final String TEST_FILE_INVALID =
"servicealteration/NSB_L1.xml";
private static final String TEST_FILE_VALID = "servicealteration/VYG_41.xml";
private static final String TEST_FILE = "servicealteration/NSB_L1.xml";
private static final NetexParser NETEX_PARSER = new NetexParser();

@Test
void testMissingServiceAlterationOnReplacedDSJs() throws IOException {
List<ValidationIssue> issues = getValidationIssues(TEST_FILE_INVALID);
assertEquals(2, issues.size());
List<ValidationIssue> issues = getValidationIssues(
TEST_FILE,
"${SERVICE_ALTERATION}",
""
);
assertEquals(1, issues.size());
}

@Test
void testMismatchedServiceAlterationOnReplacedDSJs() throws IOException {
List<ValidationIssue> issues = getValidationIssues(
TEST_FILE,
"${SERVICE_ALTERATION}",
"<ServiceAlteration>cancellation</ServiceAlteration>"
);
assertEquals(1, issues.size());
}

@Test
void testCorrectServiceAlterationOnReplacedDSJs() throws IOException {
List<ValidationIssue> issues = getValidationIssues(TEST_FILE_VALID);
List<ValidationIssue> issues = getValidationIssues(
TEST_FILE,
"${SERVICE_ALTERATION}",
"<ServiceAlteration>replaced</ServiceAlteration>"
);
assertTrue(issues.isEmpty());
}

private List<ValidationIssue> getValidationIssues(String testFile)
throws IOException {
private List<ValidationIssue> getValidationIssues(
String testFile,
String placeholder,
String replacement
) throws IOException {
String validationReportId = "Test1122";

try (
InputStream testDatasetAsStream = getClass()
.getResourceAsStream('/' + testFile)
) {
assert testDatasetAsStream != null;

String netex = new String(
testDatasetAsStream.readAllBytes(),
StandardCharsets.UTF_8
)
.replace(placeholder, replacement);

NetexEntitiesIndex netexEntitiesIndex = NETEX_PARSER.parse(
testDatasetAsStream
IOUtils.toInputStream(netex)
);

CommonDataRepository commonDataRepository = mock(
Expand Down
Loading
Loading