Skip to content

Commit eec19cb

Browse files
authored
Merge pull request #8 from openworm/development
Release 0.3.2
2 parents ca53b3b + 450c35f commit eec19cb

22 files changed

Lines changed: 1974 additions & 353 deletions

pom.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<groupId>org.geppetto</groupId>
66
<artifactId>datasources</artifactId>
77
<name>Geppetto Data Sources bundle</name>
8-
<version>0.3.1</version>
8+
<version>0.3.2</version>
99
<packaging>bundle</packaging>
1010
<properties>
1111
<spring.version>3.1.3.RELEASE</spring.version>
@@ -18,6 +18,11 @@
1818
<artifactId>core</artifactId>
1919
<version>${project.version}</version>
2020
</dependency>
21+
<dependency>
22+
<groupId>org.geppetto</groupId>
23+
<artifactId>simulation</artifactId>
24+
<version>${project.version}</version>
25+
</dependency>
2126
<dependency>
2227
<groupId>org.springframework</groupId>
2328
<artifactId>org.springframework.core</artifactId>

src/main/java/META-INF/spring/osgi-config.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@
1414
<osgi:service id="Neo4jDataSourceExporter" ref="neo4jDataSource"
1515
interface="org.geppetto.core.datasources.IDataSourceService">
1616
</osgi:service>
17-
<bean id="neo4jDataSource" scope="prototype" class="org.geppetto.datasources.Neo4jDataSourceService">
17+
<bean id="neo4jDataSource" scope="prototype" class="org.geppetto.datasources.neo4j.Neo4jDataSourceService">
1818
<aop:scoped-proxy proxy-target-class="false"/>
1919
</bean>
2020

21-
<osgi:service id="AmberOWLDataSourceExporter" ref="amberOWLDataSource"
21+
<osgi:service id="AberOWLDataSourceExporter" ref="aberOWLDataSource"
2222
interface="org.geppetto.core.datasources.IDataSourceService">
2323
</osgi:service>
24-
<bean id="amberOWLDataSource" scope="prototype" class="org.geppetto.datasources.AmberOWLDataSourceService">
24+
<bean id="aberOWLDataSource" scope="prototype" class="org.geppetto.datasources.aberowl.AberOWLDataSourceService">
2525
<aop:scoped-proxy proxy-target-class="false"/>
2626
</bean>
2727

Lines changed: 195 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,195 @@
1+
/*******************************************************************************
2+
* The MIT License (MIT)
3+
*
4+
* Copyright (c) 2011 - 2015 OpenWorm.
5+
* http://openworm.org
6+
*
7+
* All rights reserved. This program and the accompanying materials
8+
* are made available under the terms of the MIT License
9+
* which accompanies this distribution, and is available at
10+
* http://opensource.org/licenses/MIT
11+
*
12+
* Contributors:
13+
* OpenWorm - http://openworm.org/people.html
14+
*
15+
* Permission is hereby granted, free of charge, to any person obtaining a copy
16+
* of this software and associated documentation files (the "Software"), to deal
17+
* in the Software without restriction, including without limitation the rights
18+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
19+
* copies of the Software, and to permit persons to whom the Software is
20+
* furnished to do so, subject to the following conditions:
21+
*
22+
* The above copyright notice and this permission notice shall be included in
23+
* all copies or substantial portions of the Software.
24+
*
25+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
26+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
27+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
28+
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
29+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
30+
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
31+
* USE OR OTHER DEALINGS IN THE SOFTWARE.
32+
*******************************************************************************/
33+
package org.geppetto.datasources;
34+
35+
import java.util.ArrayList;
36+
import java.util.LinkedHashMap;
37+
import java.util.List;
38+
import java.util.Map;
39+
40+
import org.eclipse.emf.common.util.EList;
41+
import org.geppetto.core.datasources.GeppettoDataSourceException;
42+
import org.geppetto.core.datasources.IDataSourceService;
43+
import org.geppetto.core.datasources.QueryChecker;
44+
import org.geppetto.core.model.GeppettoModelAccess;
45+
import org.geppetto.core.services.AService;
46+
import org.geppetto.model.datasources.DataSource;
47+
import org.geppetto.model.datasources.Query;
48+
import org.geppetto.model.datasources.QueryResults;
49+
import org.geppetto.model.datasources.RunnableQuery;
50+
import org.geppetto.model.util.GeppettoModelTraversal;
51+
import org.geppetto.model.util.GeppettoVisitingException;
52+
import org.geppetto.model.variables.Variable;
53+
import org.geppetto.model.variables.VariablesFactory;
54+
55+
/**
56+
* @author matteocantarelli
57+
*
58+
*/
59+
public abstract class ADataSourceService extends AService implements IDataSourceService
60+
{
61+
62+
public abstract ConnectionType getConnectionType();
63+
64+
public abstract IQueryResponseProcessor getQueryResponseProcessor();
65+
66+
public enum ConnectionType
67+
{
68+
GET, POST
69+
}
70+
71+
protected IQueryResponseProcessor queryResponseProcessor;
72+
73+
private DataSource configuration;
74+
75+
private String dataSourceTemplate;
76+
77+
private GeppettoModelAccess geppettoModelAccess;
78+
79+
// Cache is shared
80+
private static Map<String, QueryResults> cachedResults = new LinkedHashMap<String, QueryResults>();
81+
private static Map<String, List<String>> cachedIds = new LinkedHashMap<String, List<String>>();
82+
83+
public ADataSourceService(String dataSourceTemplate)
84+
{
85+
this.dataSourceTemplate = dataSourceTemplate;
86+
}
87+
88+
@Override
89+
public void initialize(DataSource configuration, GeppettoModelAccess geppettoModelAccess)
90+
{
91+
this.configuration = configuration;
92+
this.geppettoModelAccess = geppettoModelAccess;
93+
}
94+
95+
@Override
96+
public int getNumberOfResults(List<RunnableQuery> queries) throws GeppettoDataSourceException
97+
{
98+
try
99+
{
100+
ExecuteMultipleQueriesVisitor executeMultipleQueriesVisitor = new ExecuteMultipleQueriesVisitor(geppettoModelAccess, cachedResults, cachedIds);
101+
GeppettoModelTraversal.apply((EList) queries, executeMultipleQueriesVisitor);
102+
return executeMultipleQueriesVisitor.getCount();
103+
}
104+
catch(GeppettoVisitingException e)
105+
{
106+
throw new GeppettoDataSourceException(e);
107+
}
108+
}
109+
110+
@Override
111+
public QueryResults execute(List<RunnableQuery> queries) throws GeppettoDataSourceException
112+
{
113+
try
114+
{
115+
ExecuteMultipleQueriesVisitor executeMultipleQueriesVisitor = new ExecuteMultipleQueriesVisitor(geppettoModelAccess, cachedResults, cachedIds);
116+
GeppettoModelTraversal.apply((EList) queries, executeMultipleQueriesVisitor);
117+
return executeMultipleQueriesVisitor.getResults();
118+
}
119+
catch(GeppettoVisitingException e)
120+
{
121+
throw new GeppettoDataSourceException(e);
122+
}
123+
}
124+
125+
/**
126+
* @return
127+
*/
128+
protected GeppettoModelAccess getGeppettoModelAccess()
129+
{
130+
return geppettoModelAccess;
131+
}
132+
133+
/**
134+
* @return
135+
*/
136+
protected String getTemplate()
137+
{
138+
return dataSourceTemplate;
139+
}
140+
141+
/**
142+
* @return the configuration for this DataSourceService
143+
*/
144+
protected DataSource getConfiguration()
145+
{
146+
return configuration;
147+
}
148+
149+
/*
150+
* (non-Javadoc)
151+
*
152+
* @see org.geppetto.core.model.QueryProvider#getAvailableQueries(org.geppetto.model.variables.Variable)
153+
*/
154+
@Override
155+
public List<Query> getAvailableQueries(Variable variable)
156+
{
157+
List<Query> availableQueries = new ArrayList<Query>();
158+
for(Query query : configuration.getQueries())
159+
{
160+
if(QueryChecker.check(query, variable))
161+
{
162+
availableQueries.add(query);
163+
}
164+
}
165+
return availableQueries;
166+
}
167+
168+
/*
169+
* (non-Javadoc)
170+
*
171+
* @see org.geppetto.core.model.IDataSource#fetchVariable(java.lang.String)
172+
*/
173+
@Override
174+
public void fetchVariable(String variableId) throws GeppettoDataSourceException
175+
{
176+
Variable fetchedVariable = VariablesFactory.eINSTANCE.createVariable();
177+
fetchedVariable.setId(variableId);
178+
getGeppettoModelAccess().addVariable(fetchedVariable);
179+
Query fetchVariableQuery = getConfiguration().getFetchVariableQuery();
180+
ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor(fetchedVariable, getGeppettoModelAccess());
181+
runQueryVisitor.doSwitch(fetchVariableQuery);
182+
}
183+
184+
/*
185+
* (non-Javadoc)
186+
*
187+
* @see org.geppetto.core.services.IService#registerGeppettoService()
188+
*/
189+
@Override
190+
public void registerGeppettoService() throws Exception
191+
{
192+
// Nothing to do here
193+
}
194+
195+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/**
2+
*
3+
*/
4+
package org.geppetto.datasources;
5+
6+
import java.util.Map;
7+
8+
import org.geppetto.core.datasources.IQueryProcessor;
9+
import org.geppetto.core.features.IFeature;
10+
import org.geppetto.core.services.GeppettoFeature;
11+
import org.geppetto.core.services.registry.ServicesRegistry;
12+
13+
/**
14+
* @author matteocantarelli
15+
*
16+
*/
17+
public abstract class AQueryProcessor implements IQueryProcessor
18+
{
19+
20+
@Override
21+
public void registerGeppettoService() throws Exception
22+
{
23+
ServicesRegistry.registerQueryProcessorService(this);
24+
}
25+
26+
@Override
27+
public boolean isSupported(GeppettoFeature feature)
28+
{
29+
return false;
30+
}
31+
32+
@Override
33+
public IFeature getFeature(GeppettoFeature feature)
34+
{
35+
return null;
36+
}
37+
38+
@Override
39+
public void addFeature(IFeature feature)
40+
{
41+
42+
}
43+
44+
/*
45+
* (non-Javadoc)
46+
*
47+
* @see org.geppetto.core.datasources.IQueryProcessor#getProcessingOutputMap()
48+
*/
49+
@Override
50+
public Map<String, Object> getProcessingOutputMap()
51+
{
52+
return null;
53+
}
54+
55+
}

0 commit comments

Comments
 (0)