package orientdb;

import java.io.File;

import com.orientechnologies.orient.graph.gremlin.OCommandGremlin;
import com.orientechnologies.orient.graph.gremlin.OGremlinHelper;
import com.tinkerpop.blueprints.*;
import com.tinkerpop.blueprints.impls.orient.OrientGraph;

public class Main {

	public static void main(String[] args) {
		String dbPath = "E:/Projects/OrientDB/railway-test-1";
		String graphmlPath = "E:/Drive/BME/Aktulis/nlab/railway-test-1.graphml";
		boolean dbExist = new File(dbPath).exists();
		// Open database
		OrientGraph g = new OrientGraph("plocal:" + dbPath);
		System.out.println("OrientGraph opened!");
		OGremlinHelper.global().create();
		try {
			// Load the graphml file. If it exists, don't load again!
			if (dbExist == false) {
				new OCommandGremlin("g.loadGraphML('" + graphmlPath + "')").execute();
				System.out.println("The railway-test-1.graphml has been loaded.");
			}
			
			// Check track elements segment length is negative or zero. (PosLength)
			
			OCommandGremlin gremcomm = new OCommandGremlin();
			gremcomm.setText("g.V.has('Segment_length', T.lte, 0).id");
			System.out.println("The segments id, where the segment lenght is negative or zero:");
			System.out.println(gremcomm.execute());
			
			// (SwitchSensor)
			gremcomm.setText("switches = []").execute();
			gremcomm.setText("g.V('labels',':Sensor').in('TrackElement_sensor').dedup()" + 
							 ".filter{it.labels == ':Switch:TrackElement'}.fill(switches).id").execute();
			gremcomm.setText("g.V('labels', ':Switch:TrackElement').has('id', T.notin, switches).id");
			System.out.println("The switches, which doesn't have sensor:");
			System.out.println(gremcomm.execute());
			
			/*
			OCommandGremlin h = new OCommandGremlin("hercules = g.V('name', 'hercules').next()");
			h.execute();
			System.out.println("Hercules variable created.");
			System.out.println(h.getText());
			h.setText("hercules.out('mother', 'father').name");
			System.out.println(h.getText());
			Object execute = h.execute();
			System.out.println(execute.getClass());
			System.out.println("Hercules parents name: " + execute);
			*/
		} finally {
			if (g != null) {
				g.shutdown();
				System.out.println("OrientGraph closed!");
			}
		}
		
	}

}

@@ -931,24 +931,83 @@
 %0A%09%09%09%7D%0D%0A%09%09%09%0D%0A
+%09%09%09OCommandGremlin gremcomm = new OCommandGremlin();%0D%0A%09%09%09%0D%0A
 %09%09%09// Check 
@@ -1074,67 +1074,8 @@
 h)%0D%0A
-%09%09%09%0D%0A%09%09%09OCommandGremlin gremcomm = new OCommandGremlin();%0D%0A
 %09%09%09g
@@ -1165,65 +1165,32 @@
 The 
-segments id, where the segment lenght is negative or zero
+PosLength pattern result
 :%22);
@@ -1515,17 +1515,16 @@
 labels',
- 
 ':Switch
@@ -1606,43 +1606,509 @@
 The 
-s
+S
 witch
-es, which doesn't have sensor
+Sensor pattern result:%22);%0D%0A%09%09%09System.out.println(gremcomm.execute());%0D%0A%09%09%09%0D%0A%09%09%09// (RouteSensor)%0D%0A%09%09%09gremcomm.setText(%22sensors = %5B%5D%22).execute();%0D%0A%09%09%09gremcomm.setText(%22g.V('labels',':Route').out('Route_routeDefinition').fill(sensors).id%22).execute();%0D%0A%09%09%09gremcomm.setText(%22g.V('labels',':Route').out('Route_switchPosition').%22 + %0D%0A%09%09%09%09%09%09%09 %22out('SwitchPosition_switch').out('TrackElement_sensor').%22 + %0D%0A%09%09%09%09%09%09%09 %22has('id', T.notin, sensors).id%22);%0D%0A%09%09%09System.out.println(%22The RouteSensor pattern result
 :%22);

Add RouteSensor pattern.