X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fquery%2FMilestoneSpecQuery.java;fp=bundles%2Forg.simantics.charts%2Fsrc%2Forg%2Fsimantics%2Fcharts%2Fquery%2FMilestoneSpecQuery.java;h=cb19ae791c7b2ba47bc228af4282f504b140fd8a;hb=969bd23cab98a79ca9101af33334000879fb60c5;hp=0000000000000000000000000000000000000000;hpb=866dba5cd5a3929bbeae85991796acb212338a08;p=simantics%2Fplatform.git 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 index 000000000..cb19ae791 --- /dev/null +++ b/bundles/org.simantics.charts/src/org/simantics/charts/query/MilestoneSpecQuery.java @@ -0,0 +1,73 @@ +/******************************************************************************* + * Copyright (c) 2007, 2011 Association for Decentralized Information Management in + * Industry THTH ry. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * VTT Technical Research Centre of Finland - initial API and implementation + *******************************************************************************/ +package org.simantics.charts.query; + +import org.simantics.db.ReadGraph; +import org.simantics.db.Resource; +import org.simantics.db.common.request.ResourceRead; +import org.simantics.db.exception.DatabaseException; +import org.simantics.event.ontology.EventResource; +import org.simantics.event.view.handler.MilestoneList; +import org.simantics.event.view.handler.MilestoneListQuery; +import org.simantics.layer0.Layer0; +import org.simantics.trend.impl.Milestone; +import org.simantics.trend.impl.MilestoneSpec; + +public class MilestoneSpecQuery extends ResourceRead { + + public MilestoneSpecQuery(Resource eventlog) { + super(eventlog); + } + + @Override + public MilestoneSpec perform(ReadGraph graph) throws DatabaseException { + MilestoneSpec result = new MilestoneSpec(); + result.init(); + result.baseline = -1; + Layer0 L0 = Layer0.getInstance(graph); + EventResource EVENT = EventResource.getInstance(graph); + + Resource experiment = resource; + Resource eventLog = graph.getPossibleObject(experiment, EVENT.IsEventProducerOf); + if (eventLog != null) { + MilestoneList ml = graph.sync( new MilestoneListQuery(eventLog) ); + for (Resource event : ml.milestones) + { + boolean isMilestone = graph.hasStatement(event, EVENT.Milestone); + boolean isHidden = graph.hasStatement(event, EVENT.Hidden); + boolean isBaseline = event.equals(ml.baseline); + if (!isMilestone && !isBaseline) continue; + + Double creationTime = graph.getPossibleRelatedValue(event, EVENT.HasTimestamp); + String milestoneLabel = graph.getPossibleRelatedValue(event, EVENT.Event_milestoneLabel); + String label = graph.getPossibleRelatedValue(event, L0.HasLabel); + + Milestone ms = new Milestone(); + ms.label = milestoneLabel==null ? "" : milestoneLabel; + ms.description = label==null ? "" : label; + ms.id = graph.getRelatedValue(event, L0.HasName); + ms.time = creationTime==null ? 0.0 : creationTime; + ms.hidden = isHidden; + if (isBaseline) result.baseline = result.milestones.size(); + result.milestones.add( ms ); + } + } + + return result; + } + + public Resource getEventLog() { + return resource; + } + + +}