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.event.view.handler;
14 import java.util.ArrayList;
15 import java.util.Collections;
16 import java.util.Comparator;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.request.ResourceRead;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.db.exception.ManyObjectsForFunctionalRelationException;
23 import org.simantics.db.exception.ServiceException;
24 import org.simantics.event.ontology.EventResource;
25 import org.simantics.layer0.Layer0;
28 * Query the all milestones of an event log.
29 * The result is an array if resourcs, ordered by time in ascending order.
31 * @author toni.kalajainen
33 public class MilestoneListQuery extends ResourceRead<MilestoneList> {
35 public MilestoneListQuery(Resource eventlog) {
40 public MilestoneList perform(final ReadGraph graph) throws DatabaseException {
41 MilestoneList result = new MilestoneList();
42 result.milestones = new ArrayList<Resource>();
43 Layer0 L0 = Layer0.getInstance(graph);
44 final EventResource EVENT = EventResource.getInstance(graph);
46 //System.out.println("listing milestones");
47 ArrayList<Resource> list = new ArrayList<Resource>();
48 Resource eventLog = resource;
49 if (eventLog != null) {
50 result.baseline = graph.getPossibleObject(eventLog, EVENT.EventLog_HasBaselineEvent);
51 for (Resource slice : graph.getObjects(eventLog, L0.ConsistsOf)) {
52 for (Resource event : graph.getObjects(slice, L0.ConsistsOf)) {
53 if (!graph.hasStatement(event, EVENT.Milestone)) continue;
59 Collections.sort(list, new Comparator<Resource>() {
61 public int compare(Resource o1, Resource o2) {
63 Double t1 = graph.getPossibleRelatedValue(o1, EVENT.HasTimestamp);
64 Double t2 = graph.getPossibleRelatedValue(o2, EVENT.HasTimestamp);
65 if (t1==null) t1 = 0.0;
66 if (t2==null) t2 = 0.0;
67 return Double.compare(t1, t2);
68 } catch (ManyObjectsForFunctionalRelationException e) {
70 } catch (ServiceException e) {
74 result.milestones = list;
78 public Resource getEventLog() {