]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.event/src/org/simantics/event/view/handler/GetEventLogsQuery.java
Fixed all line endings of the repository
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / view / handler / GetEventLogsQuery.java
1 /*******************************************************************************
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in
3  * Industry THTH ry.
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
8  *
9  * Contributors:
10  *     VTT Technical Research Centre of Finland - initial API and implementation
11  *******************************************************************************/
12 package org.simantics.event.view.handler;
13
14 import java.util.ArrayList;
15 import java.util.Collection;
16 import java.util.List;
17
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;
24
25 /**
26  * Given a list of events, return respective eventlogs.
27  */
28 public class GetEventLogsQuery extends UniqueRead<Collection<Resource>> {
29
30         Collection<Resource> events;
31         
32         public GetEventLogsQuery(Collection<Resource> events) {
33                 this.events = events;
34         }
35
36         @Override
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 );
48                         }
49                 }
50                 return eventlogs;
51         }
52         
53
54 }