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.Collection;
16 import java.util.List;
18 import org.simantics.db.ReadGraph;
19 import org.simantics.db.Resource;
20 import org.simantics.db.common.request.UniqueRead;
21 import org.simantics.db.exception.DatabaseException;
22 import org.simantics.event.ontology.EventResource;
23 import org.simantics.layer0.Layer0;
26 * Given a list of events, return respective eventlogs.
28 public class GetEventLogsQuery extends UniqueRead<Collection<Resource>> {
30 Collection<Resource> events;
32 public GetEventLogsQuery(Collection<Resource> events) {
37 public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {
38 Layer0 L0 = Layer0.getInstance(graph);
39 EventResource EVENT = EventResource.getInstance(graph);
40 List<Resource> eventlogs = new ArrayList<Resource>(1);
41 for (Resource event : events) {
42 Resource eventslice = graph.getPossibleObject(event, L0.PartOf);
43 if (eventslice==null || !graph.isInstanceOf(eventslice, EVENT.EventSlice)) continue;
44 Resource eventlog = graph.getPossibleObject(eventslice, L0.PartOf);
45 if (eventlog==null || !graph.isInstanceOf(eventlog, EVENT.EventLog)) continue;
46 if (!eventlogs.contains( event )) {
47 eventlogs.add( eventlog );