X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=org.simantics.district.route%2Fsrc%2Forg%2Fsimantics%2Fdistrict%2Froute%2Finternal%2FRoutePersistence.java;h=4bc0c6f0cc4fa3d73d93a5fae9eda5ab25796147;hb=13925a0278736f3880bd659160b99815aed8fa96;hp=c3ba7571e82c3af15c96c4534a45a3d55c3965a4;hpb=00103b12908c5071e641ca2bea2c42030ff67770;p=simantics%2Fdistrict.git diff --git a/org.simantics.district.route/src/org/simantics/district/route/internal/RoutePersistence.java b/org.simantics.district.route/src/org/simantics/district/route/internal/RoutePersistence.java index c3ba7571..4bc0c6f0 100644 --- a/org.simantics.district.route/src/org/simantics/district/route/internal/RoutePersistence.java +++ b/org.simantics.district.route/src/org/simantics/district/route/internal/RoutePersistence.java @@ -16,12 +16,14 @@ import org.simantics.db.ReadGraph; import org.simantics.db.Resource; import org.simantics.db.WriteGraph; import org.simantics.db.common.request.ObjectsWithType; +import org.simantics.db.common.request.ResourceRead; import org.simantics.db.common.request.UniqueRead; import org.simantics.db.common.utils.ListUtils; import org.simantics.db.common.utils.NameUtils; 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; @@ -78,7 +80,7 @@ public class RoutePersistence { Layer0 L0 = Layer0.getInstance(graph); String existingLabel = graph.getPossibleRelatedValue(route, L0.HasLabel, Bindings.STRING); - if (ObjectUtils.objectEquals(existingLabel, label)) { + if (!ObjectUtils.objectEquals(existingLabel, label)) { graph.claimLiteral(route, L0.HasLabel, label, Bindings.STRING); } @@ -124,7 +126,7 @@ public class RoutePersistence { } public static List findRoutes(ReadGraph graph, Resource model) throws DatabaseException { - Resource rf = getRouteFolder(graph, model); + Resource rf = model != null ? getRouteFolder(graph, model) : null; if (rf == null) return Collections.emptyList(); @@ -134,16 +136,43 @@ public class RoutePersistence { List 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 { + 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> { + public ModelRoutesRequest(Resource model) { + super(model); + } + @Override + public List perform(ReadGraph graph) throws DatabaseException { + return findRoutes(graph, resource); + } + } + public static class ActiveModelRoutesRequest extends UniqueRead> { @Override public List perform(ReadGraph graph) throws DatabaseException {