Skip to content
Merged
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
40 changes: 40 additions & 0 deletions src/main/java/no/entur/mummu/resources/RestResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import org.rutebanken.netex.model.Parking;
import org.rutebanken.netex.model.ParkingsInFrame_RelStructure;
import org.rutebanken.netex.model.Quay;
import org.rutebanken.netex.model.ScheduledStopPoint;
import org.rutebanken.netex.model.ScheduledStopPointsInFrame_RelStructure;
import org.rutebanken.netex.model.StopPlace;
import org.rutebanken.netex.model.StopPlacesInFrame_RelStructure;
import org.rutebanken.netex.model.StopTypeEnumeration;
Expand Down Expand Up @@ -108,6 +110,17 @@ public JAXBElement<StopPlace> getJAXBElementStopPlaceById(@PathVariable String i
return netexObjectFactory.createStopPlace(stopPlace);
}

@GetMapping(value = "/stop-places/{id}/scheduled-stop-points", produces = "application/json")
public Collection<ScheduledStopPoint> getScheduledStopPointsForStopPlace(@PathVariable String id) {
return netexEntitiesService.getScheduledStopPointsForStopPlaceWithId(id);
}

@GetMapping(value = "/stop-places/{id}/scheduled-stop-points", produces = "application/xml")
public JAXBElement<ScheduledStopPointsInFrame_RelStructure> getJAXBElementScheduledStopPointsForStopPlace(@PathVariable String id) {
var scheduledStopPoints = netexEntitiesService.getScheduledStopPointsForStopPlaceWithId(id);
return netexObjectFactory.createScheduledStopPoints(scheduledStopPoints);
}

@GetMapping(value = "/stop-places/{id}/versions", produces = "application/json")
public Collection<StopPlace> getStopPlaceVersions(@PathVariable String id) {
return netexEntitiesService.getStopPlaceVersions(id);
Expand Down Expand Up @@ -441,4 +454,31 @@ public JAXBElement<FareZone> getJAXBElementFareZoneVersion(@PathVariable String
var fareZone = netexEntitiesService.getFareZoneVersion(id, version);
return netexObjectFactory.createFareZone(fareZone);
}

@GetMapping(value = "/scheduled-stop-points", produces = "application/json")
public List<ScheduledStopPoint> getScheduledStopPoints(
@RequestParam(defaultValue = "10") Integer count,
@RequestParam(defaultValue = "0") Integer skip
) {
return netexEntitiesService.getScheduledStopPoints(count, skip);
}

@GetMapping(value = "/scheduled-stop-points", produces = "application/xml")
public JAXBElement<ScheduledStopPointsInFrame_RelStructure> getJAXBElementScheduledStopPoints(
@RequestParam(defaultValue = "10") Integer count,
@RequestParam(defaultValue = "0") Integer skip
) {
var scheduledStopPoints = netexEntitiesService.getScheduledStopPoints(count, skip);
return netexObjectFactory.createScheduledStopPoints(scheduledStopPoints);
}

@GetMapping(value = "/scheduled-stop-points/{id}", produces = "application/json")
public ScheduledStopPoint getScheduledStopPointById(@PathVariable String id) {
return netexEntitiesService.getScheduledStopPoint(id);
}

@GetMapping(value = "/scheduled-stop-points/{id}", produces = "application/xml")
public JAXBElement<ScheduledStopPoint> getJAXBElementScheduledStopPointById(@PathVariable String id) {
return netexObjectFactory.createScheduledStopPoint(netexEntitiesService.getScheduledStopPoint(id));
}
}
26 changes: 26 additions & 0 deletions src/main/java/no/entur/mummu/services/NetexEntitiesService.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.rutebanken.netex.model.GroupOfTariffZones;
import org.rutebanken.netex.model.Parking;
import org.rutebanken.netex.model.Quay;
import org.rutebanken.netex.model.ScheduledStopPoint;
import org.rutebanken.netex.model.StopPlace;
import org.rutebanken.netex.model.StopTypeEnumeration;
import org.rutebanken.netex.model.TariffZone;
Expand Down Expand Up @@ -316,4 +317,29 @@ public FareZone getFareZoneVersion(String id, String version) {
netexEntitiesIndex.getFareZoneIndex().getVersion(id, version)
).orElseThrow(NotFoundException::new);
}

public List<ScheduledStopPoint> getScheduledStopPoints(
Integer count,
Integer skip
) {
return netexEntitiesIndex.getScheduledStopPointIndex().getLatestVersions().stream()
.sorted(new NetexIdComparator())
.skip(skip)
.limit(count)
.collect(Collectors.toList());
}

public Collection<ScheduledStopPoint> getScheduledStopPointsForStopPlaceWithId(String id) {
return netexEntitiesIndex.getPassengerStopAssignmentsByStopPointRefIndex().entries().stream().filter(entry -> {
var passengerStopAssignment = entry.getValue();
return passengerStopAssignment.getStopPlaceRef() != null && passengerStopAssignment.getStopPlaceRef().getRef().equals(id);
}).map(entry -> {
var stopPointRef = entry.getKey();
return netexEntitiesIndex.getScheduledStopPointIndex().getLatestVersion(stopPointRef);
}).collect(Collectors.toSet());
}

public ScheduledStopPoint getScheduledStopPoint(String id) {
return netexEntitiesIndex.getScheduledStopPointIndex().getLatestVersion(id);
}
}
8 changes: 8 additions & 0 deletions src/main/java/no/entur/mummu/services/NetexObjectFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import org.rutebanken.netex.model.ObjectFactory;
import org.rutebanken.netex.model.Parking;
import org.rutebanken.netex.model.ParkingsInFrame_RelStructure;
import org.rutebanken.netex.model.ScheduledStopPoint;
import org.rutebanken.netex.model.ScheduledStopPointsInFrame_RelStructure;
import org.rutebanken.netex.model.StopPlace;
import org.rutebanken.netex.model.StopPlacesInFrame_RelStructure;
import org.rutebanken.netex.model.TariffZone;
Expand All @@ -33,6 +35,7 @@ public class NetexObjectFactory extends ObjectFactory {
private static final QName _groupsOfTariffZones_QNAME = new QName(NAMESPACE_URI, "groupsOfTariffZones");
private static final QName _parkings_QNAME = new QName(NAMESPACE_URI, "parkings");
private static final QName _topographicPlaces_QNAME = new QName(NAMESPACE_URI, "topographicPlaces");
private static final QName _scheduledStopPoints_QNAME = new QName(NAMESPACE_URI, "scheduledStopPoints");

public JAXBElement<GroupsOfStopPlacesInFrame_RelStructure> createGroupsOfStopPlaces(List<GroupOfStopPlaces> groupsOfStopPlaces) {
var groupsOfStopPlacesInFrame = createGroupsOfStopPlacesInFrame_RelStructure().withGroupOfStopPlaces(groupsOfStopPlaces);
Expand Down Expand Up @@ -72,4 +75,9 @@ public JAXBElement<TopographicPlacesInFrame_RelStructure> createTopographicPlace
var topographicPlacesInFrame = createTopographicPlacesInFrame_RelStructure().withTopographicPlace(topographicPlaces);
return new JAXBElement<>(_topographicPlaces_QNAME, TopographicPlacesInFrame_RelStructure.class, topographicPlacesInFrame);
}

public JAXBElement<ScheduledStopPointsInFrame_RelStructure> createScheduledStopPoints(Collection<ScheduledStopPoint> scheduledStopPoints) {
var scheduledStopPointsInFrame = createScheduledStopPointsInFrame_RelStructure().withScheduledStopPoint(scheduledStopPoints);
return new JAXBElement<>(_scheduledStopPoints_QNAME, ScheduledStopPointsInFrame_RelStructure.class, scheduledStopPointsInFrame);
}
}
42 changes: 42 additions & 0 deletions src/test/java/no/entur/mummu/RestResourceIntegrationTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.xml.bind.JAXBElement;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.rutebanken.netex.model.ScheduledStopPoint;
import org.rutebanken.netex.model.StopPlace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
Expand Down Expand Up @@ -283,4 +284,45 @@ void testXMLOutputCanBeMarshalled() throws Exception {
JAXBElement<StopPlace> stopPlace = (JAXBElement<StopPlace>) unmarshaller.unmarshal(new ByteArrayInputStream(contentAsString.getBytes()));
Assertions.assertEquals("NSR:StopPlace:4004", stopPlace.getValue().getId());
}

@Test
void testGetScheduledStopPointForStopPlace() throws Exception {
mvc.perform(get("/stop-places/NSR:StopPlace:4004/scheduled-stop-points"))
.andExpect(status().isOk())
.andExpect(content()
.contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$[0].name.value").value("Jernbanetorget"));
}

@Test
void testGetScheduledStopPoints() throws Exception {
mvc.perform(get("/scheduled-stop-points"))
.andExpect(status().isOk())
.andExpect(content()
.contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$[0].name.value").value("Jernbanetorget"));
}

@Test
void testGetScheduledStopPointById() throws Exception {
mvc.perform(get("/scheduled-stop-points/NSR:ScheduledStopPoint:S4004"))
.andExpect(status().isOk())
.andExpect(content()
.contentTypeCompatibleWith(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.name.value").value("Jernbanetorget"));
}

@Test
void testGetScheduledStopPointByIdAsXML() throws Exception {
ResultActions resultActions = mvc.perform(get("/scheduled-stop-points/NSR:ScheduledStopPoint:S4004")
.accept(MediaType.APPLICATION_XML))
.andExpect(status().isOk());
MvcResult mvcResult = resultActions.andReturn();
String contentAsString = mvcResult.getResponse().getContentAsString();
Unmarshaller unmarshaller = JAXBContext
.newInstance(ScheduledStopPoint.class)
.createUnmarshaller();
JAXBElement<ScheduledStopPoint> scheduledStopPoint = (JAXBElement<ScheduledStopPoint>) unmarshaller.unmarshal(new ByteArrayInputStream(contentAsString.getBytes()));
Assertions.assertEquals("NSR:ScheduledStopPoint:S4004", scheduledStopPoint.getValue().getId());
}
}
46 changes: 45 additions & 1 deletion src/test/resources/IntegrationTestFixture.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,50 @@
<TimeZone>Europe/Oslo</TimeZone>
</DefaultLocale>
</FrameDefaults>
<scheduledStopPoints>
<ScheduledStopPoint version="1" id="NSR:ScheduledStopPoint:S4004">
<ValidBetween>
<FromDate>2017-06-19T19:12:29.887</FromDate>
<ToDate>2021-10-05T12:11:14.999</ToDate>
</ValidBetween>
<Name>Jernbanetorget</Name>
</ScheduledStopPoint>
<ScheduledStopPoint version="5" id="NSR:ScheduledStopPoint:Q105942">
<ValidBetween/>
<Name>Jernbanetorget</Name>
</ScheduledStopPoint>
<ScheduledStopPoint version="1" id="NSR:ScheduledStopPoint:S16597">
<ValidBetween>
<FromDate>2017-06-19T19:33:17.697</FromDate>
</ValidBetween>
<Name>Norefjell skiheis</Name>
</ScheduledStopPoint>
</scheduledStopPoints>
<stopAssignments>
<PassengerStopAssignment order="1" version="1" id="NSR:PassengerStopAssignment:PS4004">
<ValidBetween>
<FromDate>2017-06-19T19:12:29.887</FromDate>
<ToDate>2021-10-05T12:11:14.999</ToDate>
</ValidBetween>
<ScheduledStopPointRef ref="NSR:ScheduledStopPoint:S4004" versionRef="1"/>
<StopPlaceRef ref="NSR:StopPlace:4004" version="1"/>
</PassengerStopAssignment>
<PassengerStopAssignment order="4" version="1" id="NSR:PassengerStopAssignment:PQ105942">
<ValidBetween>
<FromDate>2017-06-19T19:12:30.689</FromDate>
<ToDate>2018-01-18T12:00:54.999</ToDate>
</ValidBetween>
<ScheduledStopPointRef ref="NSR:ScheduledStopPoint:Q105942" versionRef="1"/>
<QuayRef ref="NSR:Quay:105942" version="1"/>
</PassengerStopAssignment>
<PassengerStopAssignment order="44866" version="1" id="NSR:PassengerStopAssignment:PS16597">
<ValidBetween>
<FromDate>2017-06-19T19:33:17.697</FromDate>
</ValidBetween>
<ScheduledStopPointRef ref="NSR:ScheduledStopPoint:S16597" versionRef="1"/>
<StopPlaceRef ref="NSR:StopPlace:16597" version="1"/>
</PassengerStopAssignment>
</stopAssignments>
</ServiceFrame>
<SiteFrame modification="new" version="1" id="NSR:SiteFrame:1">
<Description>Site frame ExportParams{topographicPlaceExportMode=RELEVANT, municipalityReferences=[], countyReferences=[], countryReferences=[], stopPlaceSearch=StopPlaceSearch{stopPlaceType=[], netexIdList=[], allVersions=false, versionValidity=CURRENT, withoutLocationOnly=false, withoutQuaysOnly=false, withDuplicatedQuayImportedIds=false, withTags=[], tags=[], page=0, size=20}, tariffZoneExportMode=RELEVANT, serviceFrameExportMode=ALL}</Description>
Expand Down Expand Up @@ -1041,4 +1085,4 @@
</fareZones>
</FareFrame>
</dataObjects>
</PublicationDelivery>
</PublicationDelivery>
Binary file modified src/test/resources/IntegrationTestFixture.xml.zip
Binary file not shown.