]> gerrit.simantics Code Review - simantics/platform.git/blob - 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
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.charts.query;\r
13 \r
14 import org.simantics.db.ReadGraph;\r
15 import org.simantics.db.Resource;\r
16 import org.simantics.db.common.request.ResourceRead;\r
17 import org.simantics.db.exception.DatabaseException;\r
18 import org.simantics.event.ontology.EventResource;\r
19 import org.simantics.event.view.handler.MilestoneList;\r
20 import org.simantics.event.view.handler.MilestoneListQuery;\r
21 import org.simantics.layer0.Layer0;\r
22 import org.simantics.trend.impl.Milestone;\r
23 import org.simantics.trend.impl.MilestoneSpec;\r
24 \r
25 public class MilestoneSpecQuery extends ResourceRead<MilestoneSpec> {\r
26         \r
27         public MilestoneSpecQuery(Resource eventlog) {\r
28                 super(eventlog);\r
29         }\r
30         \r
31     @Override\r
32     public MilestoneSpec perform(ReadGraph graph) throws DatabaseException {\r
33         MilestoneSpec result = new MilestoneSpec();\r
34         result.init();\r
35         result.baseline = -1;\r
36         Layer0 L0 = Layer0.getInstance(graph);\r
37         EventResource EVENT = EventResource.getInstance(graph);\r
38 \r
39         Resource experiment = resource;\r
40         Resource eventLog = graph.getPossibleObject(experiment, EVENT.IsEventProducerOf);        \r
41         if (eventLog != null) {\r
42                 MilestoneList ml = graph.sync( new MilestoneListQuery(eventLog) );\r
43                 for (Resource event : ml.milestones) \r
44                 {                       \r
45                         boolean isMilestone = graph.hasStatement(event, EVENT.Milestone);\r
46                         boolean isHidden = graph.hasStatement(event, EVENT.Hidden);\r
47                         boolean isBaseline = event.equals(ml.baseline);\r
48                         if (!isMilestone && !isBaseline) continue;\r
49 \r
50                         Double creationTime = graph.getPossibleRelatedValue(event, EVENT.HasTimestamp);\r
51                         String milestoneLabel = graph.getPossibleRelatedValue(event, EVENT.Event_milestoneLabel);\r
52                         String label = graph.getPossibleRelatedValue(event, L0.HasLabel);  \r
53                         \r
54                         Milestone ms = new Milestone();\r
55                         ms.label = milestoneLabel==null ? "" : milestoneLabel;\r
56                         ms.description = label==null ? "" : label;\r
57                         ms.id = graph.getRelatedValue(event, L0.HasName);\r
58                         ms.time = creationTime==null ? 0.0 : creationTime;\r
59                         ms.hidden = isHidden;\r
60                         if (isBaseline) result.baseline = result.milestones.size(); \r
61                         result.milestones.add( ms );\r
62                 }\r
63         }\r
64         \r
65         return result;\r
66     }\r
67 \r
68         public Resource getEventLog() {\r
69                 return resource;\r
70         }       \r
71 \r
72 \r
73 }\r