X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;f=bundles%2Forg.simantics.event%2Fsrc%2Forg%2Fsimantics%2Fevent%2Fview%2Fhandler%2FMilestoneListQuery.java;fp=bundles%2Forg.simantics.event%2Fsrc%2Forg%2Fsimantics%2Fevent%2Fview%2Fhandler%2FMilestoneListQuery.java;h=ddd236991399d69ed19ab19c3eec0a294937b2e0;hb=0ae2b770234dfc3cbb18bd38f324125cf0faca07;hp=b5fc41d26d00e177df5875de180515d375597893;hpb=24e2b34260f219f0d1644ca7a138894980e25b14;p=simantics%2Fplatform.git diff --git a/bundles/org.simantics.event/src/org/simantics/event/view/handler/MilestoneListQuery.java b/bundles/org.simantics.event/src/org/simantics/event/view/handler/MilestoneListQuery.java index b5fc41d26..ddd236991 100644 --- a/bundles/org.simantics.event/src/org/simantics/event/view/handler/MilestoneListQuery.java +++ b/bundles/org.simantics.event/src/org/simantics/event/view/handler/MilestoneListQuery.java @@ -1,83 +1,83 @@ -/******************************************************************************* - * 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.event.view.handler; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.Comparator; - -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.db.exception.ManyObjectsForFunctionalRelationException; -import org.simantics.db.exception.ServiceException; -import org.simantics.event.ontology.EventResource; -import org.simantics.layer0.Layer0; - -/** - * Query the all milestones of an event log. - * The result is an array if resourcs, ordered by time in ascending order. - * - * @author toni.kalajainen - */ -public class MilestoneListQuery extends ResourceRead { - - public MilestoneListQuery(Resource eventlog) { - super(eventlog); - } - - @Override - public MilestoneList perform(final ReadGraph graph) throws DatabaseException { - MilestoneList result = new MilestoneList(); - result.milestones = new ArrayList(); - Layer0 L0 = Layer0.getInstance(graph); - final EventResource EVENT = EventResource.getInstance(graph); - - //System.out.println("listing milestones"); - ArrayList list = new ArrayList(); - Resource eventLog = resource; - if (eventLog != null) { - result.baseline = graph.getPossibleObject(eventLog, EVENT.EventLog_HasBaselineEvent); - for (Resource slice : graph.getObjects(eventLog, L0.ConsistsOf)) { - for (Resource event : graph.getObjects(slice, L0.ConsistsOf)) { - if (!graph.hasStatement(event, EVENT.Milestone)) continue; - list.add(event); - } - } - } - - Collections.sort(list, new Comparator() { - @Override - public int compare(Resource o1, Resource o2) { - try { - Double t1 = graph.getPossibleRelatedValue(o1, EVENT.HasTimestamp); - Double t2 = graph.getPossibleRelatedValue(o2, EVENT.HasTimestamp); - if (t1==null) t1 = 0.0; - if (t2==null) t2 = 0.0; - return Double.compare(t1, t2); - } catch (ManyObjectsForFunctionalRelationException e) { - return 0; - } catch (ServiceException e) { - return 0; - } - }}); - result.milestones = list; - return result; - } - - public Resource getEventLog() { - return resource; - } - - -} +/******************************************************************************* + * 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.event.view.handler; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; + +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.db.exception.ManyObjectsForFunctionalRelationException; +import org.simantics.db.exception.ServiceException; +import org.simantics.event.ontology.EventResource; +import org.simantics.layer0.Layer0; + +/** + * Query the all milestones of an event log. + * The result is an array if resourcs, ordered by time in ascending order. + * + * @author toni.kalajainen + */ +public class MilestoneListQuery extends ResourceRead { + + public MilestoneListQuery(Resource eventlog) { + super(eventlog); + } + + @Override + public MilestoneList perform(final ReadGraph graph) throws DatabaseException { + MilestoneList result = new MilestoneList(); + result.milestones = new ArrayList(); + Layer0 L0 = Layer0.getInstance(graph); + final EventResource EVENT = EventResource.getInstance(graph); + + //System.out.println("listing milestones"); + ArrayList list = new ArrayList(); + Resource eventLog = resource; + if (eventLog != null) { + result.baseline = graph.getPossibleObject(eventLog, EVENT.EventLog_HasBaselineEvent); + for (Resource slice : graph.getObjects(eventLog, L0.ConsistsOf)) { + for (Resource event : graph.getObjects(slice, L0.ConsistsOf)) { + if (!graph.hasStatement(event, EVENT.Milestone)) continue; + list.add(event); + } + } + } + + Collections.sort(list, new Comparator() { + @Override + public int compare(Resource o1, Resource o2) { + try { + Double t1 = graph.getPossibleRelatedValue(o1, EVENT.HasTimestamp); + Double t2 = graph.getPossibleRelatedValue(o2, EVENT.HasTimestamp); + if (t1==null) t1 = 0.0; + if (t2==null) t2 = 0.0; + return Double.compare(t1, t2); + } catch (ManyObjectsForFunctionalRelationException e) { + return 0; + } catch (ServiceException e) { + return 0; + } + }}); + result.milestones = list; + return result; + } + + public Resource getEventLog() { + return resource; + } + + +}