1 /*******************************************************************************
2 * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
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
10 * VTT Technical Research Centre of Finland - initial API and implementation
11 *******************************************************************************/
12 package org.simantics.charts.query;
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;
25 public class MilestoneSpecQuery extends ResourceRead<MilestoneSpec> {
27 public MilestoneSpecQuery(Resource eventlog) {
32 public MilestoneSpec perform(ReadGraph graph) throws DatabaseException {
33 MilestoneSpec result = new MilestoneSpec();
36 Layer0 L0 = Layer0.getInstance(graph);
37 EventResource EVENT = EventResource.getInstance(graph);
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)
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;
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);
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;
60 if (isBaseline) result.baseline = result.milestones.size();
61 result.milestones.add( ms );
68 public Resource getEventLog() {