import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.QueryIndexUtils;
import org.simantics.db.layer0.request.PossibleActiveModel;
+import org.simantics.db.layer0.request.PossibleModel;
import org.simantics.db.layer0.util.RemoverUtil;
import org.simantics.district.network.ontology.DistrictNetworkResource;
import org.simantics.district.route.Waypoint;
List<RouteImpl> routes = new ArrayList<>();
for (Resource route : graph.syncRequest(new ObjectsWithType(rf, L0.ConsistsOf, RR.Route))) {
- RouteImpl ri = new RouteImpl(graph.getRelatedValue(route, L0.HasLabel, Bindings.STRING))
- .backend(route)
- .modelEntity(model)
- .waypoints(toWaypoints(graph, ListUtils.toList(graph, route)));
- routes.add(ri);
+ routes.add(getRoute(graph, model, route));
}
return routes;
}
+ public static RouteImpl getRoute(ReadGraph graph, Resource model, Resource route) throws DatabaseException {
+ Layer0 L0 = Layer0.getInstance(graph);
+ RouteImpl ri = new RouteImpl(graph.getRelatedValue(route, L0.HasLabel, Bindings.STRING))
+ .backend(route)
+ .modelEntity(model)
+ .waypoints(toWaypoints(graph, ListUtils.toList(graph, route)));
+ return ri;
+ }
+
+ public static class RouteRequest extends ResourceRead<RouteImpl> {
+ public RouteRequest(Resource resource) {
+ super(resource);
+ }
+
+ @Override
+ public RouteImpl perform(ReadGraph graph) throws DatabaseException {
+ Resource model = graph.syncRequest(new PossibleModel(resource));
+ return model != null ? getRoute(graph, model, resource) : null;
+ }
+ }
+
public static class ModelRoutesRequest extends ResourceRead<List<RouteImpl>> {
public ModelRoutesRequest(Resource model) {
super(model);
return findRoutes(graph, resource);
}
}
-
+
public static class ActiveModelRoutesRequest extends UniqueRead<List<RouteImpl>> {
@Override
public List<RouteImpl> perform(ReadGraph graph) throws DatabaseException {
import org.simantics.db.Session;
import org.simantics.db.common.procedure.adapter.DisposableListener;
import org.simantics.db.common.procedure.adapter.DisposableSyncListener;
+import org.simantics.db.exception.DatabaseException;
import org.simantics.db.layer0.request.PossibleActiveModel;
import org.simantics.db.management.ISessionContext;
import org.simantics.db.management.ISessionContextChangedListener;
});
}
+ @Override
+ public Route readRoute(Object backendRouteObject) {
+ if (!(backendRouteObject instanceof Resource))
+ return null;
+
+ try {
+ return Simantics.getSession().syncRequest(new RoutePersistence.RouteRequest((Resource)backendRouteObject));
+ } catch (DatabaseException e) {
+ LOGGER.error("Failed to read district route object for " + backendRouteObject, e);
+ return null;
+ }
+ }
+
}