private List < ODocument > recursivePathSearch ( String start , String end , List < String > ids , ODocument ... steps ) { List < ODocument > neighbors = getNeighborsOfModel ( start ) ; for ( ODocument neighbor : neighbors ) { if ( alreadyVisited ( neighbor , steps ) || ! OrientModelGraphUtils . getActiveFieldValue ( neighbor ) ) { continue ; } ODocument nextStep = getEdgeWithPossibleId ( start , OrientModelGraphUtils . getIdFieldValue ( neighbor ) , ids ) ; if ( nextStep == null ) { continue ; } if ( OrientModelGraphUtils . getIdFieldValue ( neighbor ) . equals ( end ) ) { List < ODocument > result = new ArrayList < ODocument > ( ) ; List < String > copyIds = new ArrayList < String > ( ids ) ; for ( ODocument step : steps ) { String id = OrientModelGraphUtils . getIdFieldValue ( step ) ; if ( id != null && copyIds . contains ( id ) ) { copyIds . remove ( id ) ; } result . add ( step ) ; } String id = OrientModelGraphUtils . getIdFieldValue ( nextStep ) ; if ( id != null && copyIds . contains ( id ) ) { copyIds . remove ( id ) ; } result . add ( nextStep ) ; if ( copyIds . isEmpty ( ) ) { return result ; } } ODocument [ ] path = Arrays . copyOf ( steps , steps . length + 1 ) ; path [ path . length - 1 ] = nextStep ; List < ODocument > check = recursivePathSearch ( OrientModelGraphUtils . getIdFieldValue ( neighbor ) , end , ids , path ) ; if ( check != null ) { return check ; } } return null ; }
Recursive path search function . It performs a depth first search with integrated loop check to find a path from the start model to the end model . If the id list is not empty then the function only returns a path as valid if all transformations defined with the id list are in the path . It also takes care of models which aren t available . Returns null if there is no path found .