]> gerrit.simantics Code Review - simantics/platform.git/blobdiff - bundles/org.simantics.charts/src/org/simantics/charts/query/MilestoneSpecQuery.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.charts / src / org / simantics / charts / query / MilestoneSpecQuery.java
diff --git a/bundles/org.simantics.charts/src/org/simantics/charts/query/MilestoneSpecQuery.java b/bundles/org.simantics.charts/src/org/simantics/charts/query/MilestoneSpecQuery.java
new file mode 100644 (file)
index 0000000..cb19ae7
--- /dev/null
@@ -0,0 +1,73 @@
+/*******************************************************************************\r
+ * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
+ * Industry THTH ry.\r
+ * All rights reserved. This program and the accompanying materials\r
+ * are made available under the terms of the Eclipse Public License v1.0\r
+ * which accompanies this distribution, and is available at\r
+ * http://www.eclipse.org/legal/epl-v10.html\r
+ *\r
+ * Contributors:\r
+ *     VTT Technical Research Centre of Finland - initial API and implementation\r
+ *******************************************************************************/\r
+package org.simantics.charts.query;\r
+\r
+import org.simantics.db.ReadGraph;\r
+import org.simantics.db.Resource;\r
+import org.simantics.db.common.request.ResourceRead;\r
+import org.simantics.db.exception.DatabaseException;\r
+import org.simantics.event.ontology.EventResource;\r
+import org.simantics.event.view.handler.MilestoneList;\r
+import org.simantics.event.view.handler.MilestoneListQuery;\r
+import org.simantics.layer0.Layer0;\r
+import org.simantics.trend.impl.Milestone;\r
+import org.simantics.trend.impl.MilestoneSpec;\r
+\r
+public class MilestoneSpecQuery extends ResourceRead<MilestoneSpec> {\r
+       \r
+       public MilestoneSpecQuery(Resource eventlog) {\r
+               super(eventlog);\r
+       }\r
+       \r
+    @Override\r
+    public MilestoneSpec perform(ReadGraph graph) throws DatabaseException {\r
+       MilestoneSpec result = new MilestoneSpec();\r
+       result.init();\r
+       result.baseline = -1;\r
+       Layer0 L0 = Layer0.getInstance(graph);\r
+        EventResource EVENT = EventResource.getInstance(graph);\r
+\r
+        Resource experiment = resource;\r
+        Resource eventLog = graph.getPossibleObject(experiment, EVENT.IsEventProducerOf);        \r
+        if (eventLog != null) {\r
+               MilestoneList ml = graph.sync( new MilestoneListQuery(eventLog) );\r
+               for (Resource event : ml.milestones) \r
+               {                       \r
+                       boolean isMilestone = graph.hasStatement(event, EVENT.Milestone);\r
+                       boolean isHidden = graph.hasStatement(event, EVENT.Hidden);\r
+                       boolean isBaseline = event.equals(ml.baseline);\r
+                       if (!isMilestone && !isBaseline) continue;\r
+\r
+                       Double creationTime = graph.getPossibleRelatedValue(event, EVENT.HasTimestamp);\r
+                       String milestoneLabel = graph.getPossibleRelatedValue(event, EVENT.Event_milestoneLabel);\r
+                       String label = graph.getPossibleRelatedValue(event, L0.HasLabel);  \r
+                       \r
+                       Milestone ms = new Milestone();\r
+                       ms.label = milestoneLabel==null ? "" : milestoneLabel;\r
+                       ms.description = label==null ? "" : label;\r
+                       ms.id = graph.getRelatedValue(event, L0.HasName);\r
+                       ms.time = creationTime==null ? 0.0 : creationTime;\r
+                       ms.hidden = isHidden;\r
+                       if (isBaseline) result.baseline = result.milestones.size(); \r
+                       result.milestones.add( ms );\r
+               }\r
+        }\r
+        \r
+        return result;\r
+    }\r
+\r
+       public Resource getEventLog() {\r
+               return resource;\r
+       }       \r
+\r
+\r
+}\r