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