@@ -25,6 +25,7 @@ use editoast_schemas::infra::DoubleSlipSwitch;
2525use editoast_schemas:: infra:: Electrification ;
2626use editoast_schemas:: infra:: Endpoint ;
2727use editoast_schemas:: infra:: Link ;
28+ use editoast_schemas:: infra:: NeutralSection ;
2829use editoast_schemas:: infra:: OperationalPointPart ;
2930use editoast_schemas:: infra:: PointSwitch ;
3031use 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
9496impl 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 ( )
0 commit comments