Skip to content

Commit c5e31b6

Browse files
committed
Merge pull request #5 from openworm/development
Release 0.3.0
2 parents 3490a5c + cd7b7cf commit c5e31b6

6 files changed

Lines changed: 154 additions & 13 deletions

File tree

pom.xml

Lines changed: 7 additions & 2 deletions
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.2.8.1</version>
8+
<version>0.3.0</version>
99
<packaging>bundle</packaging>
1010
<properties>
1111
<spring.version>3.1.3.RELEASE</spring.version>
@@ -33,6 +33,11 @@
3333
<artifactId>org.springframework.context</artifactId>
3434
<version>${spring.version}</version>
3535
</dependency>
36+
<dependency>
37+
<groupId>org.apache.log4j</groupId>
38+
<artifactId>com.springsource.org.apache.log4j</artifactId>
39+
<version>1.2.16</version>
40+
</dependency>
3641
<!-- test dependencies -->
3742
<dependency>
3843
<groupId>org.junit</groupId>
@@ -100,7 +105,7 @@
100105
<version>2.15</version>
101106
<configuration>
102107
<junitArtifactName>org.junit:com.springsource.org.junit</junitArtifactName>
103-
</configuration>
108+
</configuration>
104109
</plugin>
105110
<plugin>
106111
<groupId>org.apache.felix</groupId>

src/main/java/org/geppetto/datasources/Neo4jDataSourceService.java

Lines changed: 37 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,16 @@
3333
package org.geppetto.datasources;
3434

3535
import org.geppetto.core.datasources.ADataSourceService;
36+
import org.geppetto.core.datasources.ExecuteQueryVisitor;
3637
import org.geppetto.core.datasources.GeppettoDataSourceException;
3738
import org.geppetto.core.datasources.IDataSourceService;
3839
import org.geppetto.core.datasources.IQueryListener;
3940
import org.geppetto.model.Query;
4041
import org.geppetto.model.QueryResults;
41-
import org.geppetto.model.SimpleQuery;
42+
import org.geppetto.model.util.GeppettoModelTraversal;
43+
import org.geppetto.model.util.GeppettoVisitingException;
4244
import org.geppetto.model.variables.Variable;
45+
import org.geppetto.model.variables.VariablesFactory;
4346

4447
/**
4548
* @author matteocantarelli
@@ -48,6 +51,11 @@
4851
public class Neo4jDataSourceService extends ADataSourceService implements IDataSourceService
4952
{
5053

54+
public Neo4jDataSourceService()
55+
{
56+
super("/templates/neo4j/queryTemplate.vm");
57+
}
58+
5159
/*
5260
* (non-Javadoc)
5361
*
@@ -56,12 +64,19 @@ public class Neo4jDataSourceService extends ADataSourceService implements IDataS
5664
@Override
5765
public int getNumberOfResults(Query query, Variable variable) throws GeppettoDataSourceException
5866
{
59-
int count = -1;
60-
SimpleQuery simpleQuery = (SimpleQuery) query;
61-
String queryURL = getQueryURL(getConfiguration().getUrl(), simpleQuery.getCountQuery());
62-
String rawResults = execute(queryURL);
63-
// TODO go from rawResults to actual count
64-
return count;
67+
Query fetchVariableQuery = getConfiguration().getFetchVariableQuery();
68+
ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor(this.getConfiguration(), getTemplate(), variable, getGeppettoModelAccess(), true);
69+
try
70+
{
71+
GeppettoModelTraversal.apply(fetchVariableQuery, runQueryVisitor);
72+
73+
}
74+
catch(GeppettoVisitingException e)
75+
{
76+
throw new GeppettoDataSourceException(e);
77+
}
78+
79+
return runQueryVisitor.getCount();
6580
}
6681

6782
/*
@@ -107,10 +122,22 @@ public QueryResults execute(Query query, Variable variable, QueryResults results
107122
* @see org.geppetto.core.model.IDataSource#fetchVariable(java.lang.String)
108123
*/
109124
@Override
110-
public Variable fetchVariable(String variableId) throws GeppettoDataSourceException
125+
public void fetchVariable(String variableId) throws GeppettoDataSourceException
111126
{
112-
// TODO Auto-generated method stub
113-
return null;
127+
Variable fetchedVariable = VariablesFactory.eINSTANCE.createVariable();
128+
fetchedVariable.setId(variableId);
129+
getGeppettoModelAccess().addVariable(fetchedVariable);
130+
Query fetchVariableQuery = getConfiguration().getFetchVariableQuery();
131+
ExecuteQueryVisitor runQueryVisitor = new ExecuteQueryVisitor(this.getConfiguration(), getTemplate(), fetchedVariable, getGeppettoModelAccess());
132+
try
133+
{
134+
GeppettoModelTraversal.apply(fetchVariableQuery, runQueryVisitor);
135+
136+
}
137+
catch(GeppettoVisitingException e)
138+
{
139+
throw new GeppettoDataSourceException(e);
140+
}
114141
}
115142

116143
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"statements":[
3+
{
4+
"statement":"$QUERY",
5+
"resultDataContents":[
6+
"row",
7+
"graph"
8+
],
9+
"includeStats":true
10+
}
11+
]
12+
}

src/test/java/log4j.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
</appender>
1313

1414
<!-- Application loggers -->
15-
<logger name="org.geppetto.model">
15+
<logger name="org.geppetto.datasources">
1616
<level value="debug" />
1717
</logger>
1818

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
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.io.IOException;
36+
import java.io.InputStream;
37+
import java.util.HashMap;
38+
import java.util.Map;
39+
40+
import junit.framework.Assert;
41+
42+
import org.geppetto.core.common.GeppettoCommonUtils;
43+
import org.geppetto.core.datasources.GeppettoDataSourceException;
44+
import org.geppetto.core.datasources.VelocityUtils;
45+
import org.geppetto.model.GeppettoFactory;
46+
import org.geppetto.model.SimpleQuery;
47+
import org.junit.Before;
48+
import org.junit.Test;
49+
50+
/**
51+
* @author matteocantarelli
52+
*
53+
*/
54+
public class VelocityUtilsTest
55+
{
56+
57+
/**
58+
* @throws java.lang.Exception
59+
*/
60+
@Before
61+
public void setUp() throws Exception
62+
{
63+
}
64+
65+
/**
66+
* Test method for {@link org.geppetto.core.datasources.VelocityUtils#processTemplate(java.lang.String, java.util.Map)}.
67+
*
68+
* @throws GeppettoDataSourceException
69+
* @throws IOException
70+
*/
71+
@Test
72+
public void testProcessTemplate() throws GeppettoDataSourceException, IOException
73+
{
74+
SimpleQuery query = GeppettoFactory.eINSTANCE.createSimpleQuery();
75+
query.setQuery("MATCH (n:Class)<-[:SUBCLASSOF*]-(:Class)<-[:INSTANCEOF]-(i) WHERE n.short_form='$ID' RETURN n AS columnName limit 5;");
76+
Map<String, Object> properties = new HashMap<String, Object>();
77+
properties.put("ID", "FBbt_00100219");
78+
properties.put("QUERY", query.getQuery());
79+
String queryString = VelocityUtils.processTemplate("/templates/neo4j/queryTemplate.vm", properties);
80+
InputStream in = VelocityUtilsTest.class.getClassLoader().getResourceAsStream("expectedQueryTemplateResultTest.json");
81+
String expected = GeppettoCommonUtils.readString(in);
82+
Assert.assertEquals(expected, queryString);
83+
}
84+
85+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"statements":[
3+
{
4+
"statement":"MATCH (n:Class)<-[:SUBCLASSOF*]-(:Class)<-[:INSTANCEOF]-(i) WHERE n.short_form='FBbt_00100219' RETURN n AS columnName limit 5;",
5+
"resultDataContents":[
6+
"row",
7+
"graph"
8+
],
9+
"includeStats":true
10+
}
11+
]
12+
}

0 commit comments

Comments
 (0)