]> gerrit.simantics Code Review - simantics/platform.git/blob - bundles/org.simantics.event/src/org/simantics/event/view/handler/GetEventLogsQuery.java
Migrated source code from Simantics SVN
[simantics/platform.git] / bundles / org.simantics.event / src / org / simantics / event / view / handler / GetEventLogsQuery.java
1 /*******************************************************************************\r
2  * Copyright (c) 2007, 2011 Association for Decentralized Information Management in\r
3  * Industry THTH ry.\r
4  * All rights reserved. This program and the accompanying materials\r
5  * are made available under the terms of the Eclipse Public License v1.0\r
6  * which accompanies this distribution, and is available at\r
7  * http://www.eclipse.org/legal/epl-v10.html\r
8  *\r
9  * Contributors:\r
10  *     VTT Technical Research Centre of Finland - initial API and implementation\r
11  *******************************************************************************/\r
12 package org.simantics.event.view.handler;\r
13 \r
14 import java.util.ArrayList;\r
15 import java.util.Collection;\r
16 import java.util.List;\r
17 \r
18 import org.simantics.db.ReadGraph;\r
19 import org.simantics.db.Resource;\r
20 import org.simantics.db.common.request.UniqueRead;\r
21 import org.simantics.db.exception.DatabaseException;\r
22 import org.simantics.event.ontology.EventResource;\r
23 import org.simantics.layer0.Layer0;\r
24 \r
25 /**\r
26  * Given a list of events, return respective eventlogs.\r
27  */\r
28 public class GetEventLogsQuery extends UniqueRead<Collection<Resource>> {\r
29 \r
30         Collection<Resource> events;\r
31         \r
32         public GetEventLogsQuery(Collection<Resource> events) {\r
33                 this.events = events;\r
34         }\r
35 \r
36         @Override\r
37         public Collection<Resource> perform(ReadGraph graph) throws DatabaseException {\r
38                 Layer0 L0 = Layer0.getInstance(graph);\r
39                 EventResource EVENT = EventResource.getInstance(graph);\r
40                 List<Resource> eventlogs = new ArrayList<Resource>(1);\r
41                 for (Resource event : events) {\r
42                         Resource eventslice = graph.getPossibleObject(event, L0.PartOf);\r
43                         if (eventslice==null || !graph.isInstanceOf(eventslice, EVENT.EventSlice)) continue;\r
44                         Resource eventlog = graph.getPossibleObject(eventslice, L0.PartOf);\r
45                         if (eventlog==null || !graph.isInstanceOf(eventlog, EVENT.EventLog)) continue;\r
46                         if (!eventlogs.contains( event )) {\r
47                                 eventlogs.add( eventlog );\r
48                         }\r
49                 }\r
50                 return eventlogs;\r
51         }\r
52         \r
53 \r
54 }\r