Skip to content

Commit 21906b8

Browse files
committed
editoast: split track section endpoint
1 parent 31078d8 commit 21906b8

File tree

15 files changed

+1104
-57
lines changed

15 files changed

+1104
-57
lines changed

editoast/editoast_schemas/src/infra/neutral_section.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ pub struct NeutralSectionExtensions {
4343
#[derive(Debug, Default, Clone, Deserialize, Serialize, PartialEq, ToSchema)]
4444
#[serde(deny_unknown_fields)]
4545
pub struct NeutralSectionNeutralSncfExtension {
46-
announcement: Vec<Sign>,
47-
exe: Sign,
48-
end: Vec<Sign>,
49-
rev: Vec<Sign>,
46+
pub announcement: Vec<Sign>,
47+
pub exe: Sign,
48+
pub end: Vec<Sign>,
49+
pub rev: Vec<Sign>,
5050
}
5151

5252
impl OSRDTyped for NeutralSection {

editoast/openapi.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,36 @@ components:
759759
- status
760760
- message
761761
type: object
762+
EditoastEditionErrorSplitTrackSectionBadOffset:
763+
properties:
764+
context:
765+
properties:
766+
infra_id:
767+
type: integer
768+
tracksection_id:
769+
type: string
770+
tracksection_length:
771+
type: number
772+
required:
773+
- infra_id
774+
- tracksection_id
775+
- tracksection_length
776+
type: object
777+
message:
778+
type: string
779+
status:
780+
enum:
781+
- 400
782+
type: integer
783+
type:
784+
enum:
785+
- editoast:infra:edition:SplitTrackSectionBadOffset
786+
type: string
787+
required:
788+
- type
789+
- status
790+
- message
791+
type: object
762792
EditoastEditoastUrlErrorInvalidUrl:
763793
properties:
764794
context:
@@ -828,6 +858,7 @@ components:
828858
- $ref: '#/components/schemas/EditoastCoreErrorUnparsableErrorOutput'
829859
- $ref: '#/components/schemas/EditoastDocumentErrorsNotFound'
830860
- $ref: '#/components/schemas/EditoastEditionErrorInfraIsLocked'
861+
- $ref: '#/components/schemas/EditoastEditionErrorSplitTrackSectionBadOffset'
831862
- $ref: '#/components/schemas/EditoastEditoastUrlErrorInvalidUrl'
832863
- $ref: '#/components/schemas/EditoastElectricalProfilesErrorNotFound'
833864
- $ref: '#/components/schemas/EditoastGeometryErrorUnexpectedGeometry'
@@ -9989,6 +10020,33 @@ paths:
998910020
summary: Returns the set of speed limit tags for a given infra
999010021
tags:
999110022
- infra
10023+
/infra/{infra_id}/split_track_section/:
10024+
post:
10025+
parameters:
10026+
- description: An existing infra ID
10027+
in: path
10028+
name: infra_id
10029+
required: true
10030+
schema:
10031+
format: int64
10032+
type: integer
10033+
requestBody:
10034+
content:
10035+
application/json:
10036+
schema:
10037+
$ref: '#/components/schemas/TrackOffset'
10038+
required: true
10039+
responses:
10040+
'200':
10041+
content:
10042+
application/json:
10043+
schema:
10044+
items:
10045+
type: string
10046+
type: array
10047+
description: ID of the trackSections created
10048+
tags:
10049+
- infra
999210050
/infra/{infra_id}/switch_types/:
999310051
get:
999410052
parameters:

editoast/src/generated_data/sql/insert_neutral_sign_layer.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ WITH signs AS (
1919
FROM infra_object_neutral_section
2020
WHERE infra_id = $1
2121
AND obj_id = ANY($2)
22-
AND infra_object_neutral_section.data @ ? '$.extensions.neutral_sncf.announcement'
22+
AND infra_object_neutral_section.data @? '$.extensions.neutral_sncf.announcement'
2323
UNION
2424
SELECT obj_id AS sc_id,
2525
(
@@ -41,7 +41,7 @@ WITH signs AS (
4141
FROM infra_object_neutral_section
4242
WHERE infra_id = $1
4343
AND obj_id = ANY($2)
44-
AND infra_object_neutral_section.data @ ? '$.extensions.neutral_sncf.rev'
44+
AND infra_object_neutral_section.data @? '$.extensions.neutral_sncf.rev'
4545
UNION
4646
SELECT obj_id AS sc_id,
4747
(
@@ -57,7 +57,7 @@ WITH signs AS (
5757
FROM infra_object_neutral_section
5858
WHERE infra_id = $1
5959
AND obj_id = ANY($2)
60-
AND infra_object_neutral_section.data @ ? '$.extensions.neutral_sncf.end'
60+
AND infra_object_neutral_section.data @? '$.extensions.neutral_sncf.end'
6161
UNION
6262
SELECT obj_id AS sc_id,
6363
(
@@ -71,7 +71,7 @@ WITH signs AS (
7171
FROM infra_object_neutral_section
7272
WHERE infra_id = $1
7373
AND obj_id = ANY($2)
74-
AND infra_object_neutral_section.data @ ? '$.extensions.neutral_sncf.exe'
74+
AND infra_object_neutral_section.data @? '$.extensions.neutral_sncf.exe'
7575
),
7676
collect AS (
7777
SELECT signs.sc_id,

editoast/src/infra_cache/mod.rs

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use editoast_schemas::infra::DoubleSlipSwitch;
2525
use editoast_schemas::infra::Electrification;
2626
use editoast_schemas::infra::Endpoint;
2727
use editoast_schemas::infra::Link;
28+
use editoast_schemas::infra::NeutralSection;
2829
use editoast_schemas::infra::OperationalPointPart;
2930
use editoast_schemas::infra::PointSwitch;
3031
use editoast_schemas::infra::Route;
@@ -89,14 +90,15 @@ pub enum ObjectCache {
8990
OperationalPoint(OperationalPointCache),
9091
SwitchType(SwitchType),
9192
Electrification(Electrification),
93+
NeutralSection(NeutralSection),
9294
}
9395

9496
impl From<RailjsonObject> for ObjectCache {
9597
fn from(railjson: RailjsonObject) -> Self {
9698
match railjson {
9799
RailjsonObject::TrackSection { railjson } => ObjectCache::TrackSection(railjson.into()),
98100
RailjsonObject::Signal { railjson } => ObjectCache::Signal(railjson.into()),
99-
RailjsonObject::NeutralSection { .. } => unimplemented!(),
101+
RailjsonObject::NeutralSection { railjson } => ObjectCache::NeutralSection(railjson),
100102
RailjsonObject::SpeedSection { railjson } => ObjectCache::SpeedSection(railjson),
101103
RailjsonObject::Switch { railjson } => ObjectCache::Switch(railjson.into()),
102104
RailjsonObject::SwitchType { railjson } => ObjectCache::SwitchType(railjson),
@@ -130,6 +132,7 @@ impl OSRDIdentified for ObjectCache {
130132
ObjectCache::OperationalPoint(obj) => obj.get_id(),
131133
ObjectCache::SwitchType(obj) => obj.get_id(),
132134
ObjectCache::Electrification(obj) => obj.get_id(),
135+
ObjectCache::NeutralSection(obj) => obj.get_id(),
133136
}
134137
}
135138
}
@@ -147,6 +150,7 @@ impl OSRDObject for ObjectCache {
147150
ObjectCache::OperationalPoint(_) => ObjectType::OperationalPoint,
148151
ObjectCache::SwitchType(_) => ObjectType::SwitchType,
149152
ObjectCache::Electrification(_) => ObjectType::Electrification,
153+
ObjectCache::NeutralSection(_) => ObjectType::NeutralSection,
150154
}
151155
}
152156
}
@@ -166,6 +170,9 @@ impl ObjectCache {
166170
ObjectCache::Electrification(electrification) => {
167171
electrification.get_track_referenced_id()
168172
}
173+
ObjectCache::NeutralSection(neutral_section) => {
174+
neutral_section.get_track_referenced_id()
175+
}
169176
}
170177
}
171178

@@ -248,6 +255,14 @@ impl ObjectCache {
248255
_ => panic!("ObjectCache is not a Electrification"),
249256
}
250257
}
258+
259+
/// Unwrap a neutral section from the object cache
260+
pub fn unwrap_neutral_section(&self) -> &NeutralSection {
261+
match self {
262+
ObjectCache::NeutralSection(neutral_section) => neutral_section,
263+
_ => panic!("ObjectCache is not a NeutralSection"),
264+
}
265+
}
251266
}
252267

253268
#[derive(QueryableByName, Debug, Clone)]
@@ -376,6 +391,11 @@ impl InfraCache {
376391
&self.objects[ObjectType::SpeedSection]
377392
}
378393

394+
/// Retrieve the cache of neutral sections
395+
pub fn neutral_sections(&self) -> &HashMap<String, ObjectCache> {
396+
&self.objects[ObjectType::NeutralSection]
397+
}
398+
379399
/// Retrieve the cache of routes
380400
pub fn routes(&self) -> &HashMap<String, ObjectCache> {
381401
&self.objects[ObjectType::Route]
@@ -442,6 +462,12 @@ impl InfraCache {
442462
.into_iter()
443463
.try_for_each(|speed| infra_cache.add(speed))?;
444464

465+
// Load speed sections tracks references
466+
find_all_schemas::<NeutralSection, Vec<_>>(conn, infra_id)
467+
.await?
468+
.into_iter()
469+
.try_for_each(|neutralsection| infra_cache.add(neutralsection))?;
470+
445471
// Load routes tracks references
446472
find_all_schemas::<_, Vec<Route>>(conn, infra_id)
447473
.await?
@@ -594,6 +620,9 @@ impl InfraCache {
594620
ObjectCache::Electrification(electrification) => {
595621
self.add::<Electrification>(electrification)?
596622
}
623+
ObjectCache::NeutralSection(neutral_section) => {
624+
self.add::<NeutralSection>(neutral_section)?
625+
}
597626
}
598627
Ok(())
599628
}
@@ -643,6 +672,17 @@ impl InfraCache {
643672
.unwrap_speed_section())
644673
}
645674

675+
pub fn get_neutral_section(&self, neutral_section_id: &str) -> Result<&NeutralSection> {
676+
Ok(self
677+
.neutral_sections()
678+
.get(neutral_section_id)
679+
.ok_or_else(|| InfraCacheEditoastError::ObjectNotFound {
680+
obj_type: ObjectType::NeutralSection.to_string(),
681+
obj_id: neutral_section_id.to_string(),
682+
})?
683+
.unwrap_neutral_section())
684+
}
685+
646686
pub fn get_detector(&self, detector_id: &str) -> Result<&DetectorCache> {
647687
Ok(self
648688
.detectors()
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod buffer_stop_cache;
22
mod detector_cache;
33
mod electrification_cache;
4+
mod neutral_section_cache;
45
mod operational_point_cache;
56
mod route_cache;
67
mod signal_cache;
@@ -12,12 +13,7 @@ mod track_section_cache;
1213
pub use buffer_stop_cache::BufferStopCache;
1314
pub use detector_cache::DetectorCache;
1415
pub use operational_point_cache::OperationalPointCache;
16+
pub use operational_point_cache::OperationalPointPartCache;
1517
pub use signal_cache::SignalCache;
1618
pub use switch_cache::SwitchCache;
1719
pub use track_section_cache::TrackSectionCache;
18-
19-
cfg_if! {
20-
if #[cfg(test)] {
21-
pub use operational_point_cache::OperationalPointPartCache;
22-
}
23-
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
use crate::infra_cache::Cache;
2+
use crate::infra_cache::ObjectCache;
3+
use editoast_schemas::infra::NeutralSection;
4+
5+
impl Cache for NeutralSection {
6+
fn get_track_referenced_id(&self) -> Vec<&String> {
7+
let mut res: Vec<_> = self.track_ranges.iter().map(|tr| &*tr.track).collect();
8+
res.extend(self.announcement_track_ranges.iter().map(|tr| &*tr.track));
9+
if let Some(ext) = &self.extensions.neutral_sncf {
10+
res.push(&*ext.exe.track);
11+
res.extend(ext.announcement.iter().map(|sign| &*sign.track));
12+
res.extend(ext.end.iter().map(|sign| &*sign.track));
13+
res.extend(ext.rev.iter().map(|sign| &*sign.track));
14+
}
15+
res
16+
}
17+
18+
fn get_object_cache(&self) -> ObjectCache {
19+
ObjectCache::NeutralSection(self.clone())
20+
}
21+
}

editoast/src/infra_cache/operation/create.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,14 @@ impl From<SpeedSection> for RailjsonObject {
199199
}
200200
}
201201

202+
impl From<NeutralSection> for RailjsonObject {
203+
fn from(neutralsection: NeutralSection) -> Self {
204+
RailjsonObject::NeutralSection {
205+
railjson: neutralsection,
206+
}
207+
}
208+
}
209+
202210
impl From<Switch> for RailjsonObject {
203211
fn from(switch: Switch) -> Self {
204212
RailjsonObject::Switch { railjson: switch }

editoast/src/main.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
#[macro_use]
22
extern crate diesel;
3-
#[macro_use]
4-
extern crate cfg_if;
53

64
mod client;
75
mod core;

editoast/src/views/infra/auto_fixes/electrifications.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use itertools::Itertools;
2-
use serde_json::from_value;
3-
use serde_json::json;
2+
use json_patch::Patch;
3+
use json_patch::PatchOperation;
4+
use json_patch::RemoveOperation;
45
use std::collections::HashMap;
56
use tracing::debug;
67
use tracing::error;
@@ -53,11 +54,9 @@ pub fn fix_electrification(
5354
Operation::Update(UpdateOperation {
5455
obj_id: electrification.get_id().clone(),
5556
obj_type: electrification.get_type(),
56-
railjson_patch: from_value(json!([{
57-
"op": "remove",
58-
"path": format!("/track_ranges/{track_range_idx}"),
59-
}]))
60-
.unwrap(),
57+
railjson_patch: Patch(vec![PatchOperation::Remove(RemoveOperation {
58+
path: format!("/track_ranges/{track_range_idx}").parse().unwrap(),
59+
})]),
6160
})
6261
}
6362
OrderedOperation::Delete => {

editoast/src/views/infra/auto_fixes/speed_section.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use itertools::Itertools;
2-
use serde_json::from_value;
3-
use serde_json::json;
2+
use json_patch::Patch;
3+
use json_patch::PatchOperation;
4+
use json_patch::RemoveOperation;
45
use std::collections::HashMap;
56
use tracing::debug;
67
use tracing::error;
@@ -53,11 +54,9 @@ pub fn fix_speed_section(
5354
Operation::Update(UpdateOperation {
5455
obj_id: speed_section.get_id().clone(),
5556
obj_type: speed_section.get_type(),
56-
railjson_patch: from_value(json!([{
57-
"op": "remove",
58-
"path": format!("/track_ranges/{track_range_idx}"),
59-
}]))
60-
.unwrap(),
57+
railjson_patch: Patch(vec![PatchOperation::Remove(RemoveOperation {
58+
path: format!("/track_ranges/{track_range_idx}").parse().unwrap(),
59+
})]),
6160
})
6261
}
6362
OrderedOperation::Delete => {

0 commit comments

Comments
 (0)