Skip to content

Commit

Permalink
Merge pull request #12 from openworm/development
Browse files Browse the repository at this point in the history
Release 0.3.4
  • Loading branch information
tarelli authored Feb 14, 2017
2 parents 9716a15 + 81968db commit 102ad9a
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 30 deletions.
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,5 @@ src/main/java/META-INF/MANIFEST.MF
/.externalToolBuilders/
/.settings/
.classpath
bin/
geppettoTmp/
/bin/
/bin
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>org.geppetto</groupId>
<artifactId>datasources</artifactId>
<name>Geppetto Data Sources bundle</name>
<version>0.3.3</version>
<version>0.3.4</version>
<packaging>bundle</packaging>
<properties>
<spring.version>3.1.3.RELEASE</spring.version>
Expand Down
35 changes: 22 additions & 13 deletions src/main/java/org/geppetto/datasources/ExecuteQueryVisitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
import org.geppetto.model.util.GeppettoModelTraversal;
import org.geppetto.model.util.GeppettoVisitingException;
import org.geppetto.model.variables.Variable;
import com.google.gson.JsonSyntaxException;

/**
* @author matteocantarelli
Expand Down Expand Up @@ -183,12 +184,14 @@ public Object caseSimpleQuery(SimpleQuery query)
{
if(!count || (count && query.isRunForCount()))
{
String processedQueryString = "";
String url = "";
try
{
if(QueryChecker.check(query, getVariable()))
{
ADataSourceService dataSourceService = getDataSourceService(query);
String url = getDataSource(query).getUrl();
url = getDataSource(query).getUrl();
String queryString = null;
if(count)
{
Expand All @@ -208,7 +211,7 @@ public Object caseSimpleQuery(SimpleQuery query)
properties.putAll(processingOutputMap);
}

String processedQueryString = VelocityUtils.processTemplate(dataSourceService.getTemplate(), properties);
processedQueryString = VelocityUtils.processTemplate(dataSourceService.getTemplate(), properties);

String response = null;
switch(dataSourceService.getConnectionType())
Expand All @@ -226,6 +229,7 @@ public Object caseSimpleQuery(SimpleQuery query)
}
catch(GeppettoDataSourceException e)
{
System.out.println("Query request: " + url + "?" + processedQueryString);
return new GeppettoVisitingException(e);
}
catch(GeppettoInitializationException e)
Expand All @@ -242,18 +246,23 @@ public Object caseSimpleQuery(SimpleQuery query)
*/
private void processResponse(String response, ADataSourceService dataSourceService) throws GeppettoDataSourceException
{
if(count)
{
Map<String, Object> responseMap = JSONUtility.getAsMap(response);
results = dataSourceService.getQueryResponseProcessor().processResponse(responseMap);
// TODO How to get the count if it is actually specified?
}
else
{
Map<String, Object> responseMap = JSONUtility.getAsMap(response);
results = dataSourceService.getQueryResponseProcessor().processResponse(responseMap);
try{
if(count)
{
Map<String, Object> responseMap = JSONUtility.getAsMap(response);
results = dataSourceService.getQueryResponseProcessor().processResponse(responseMap);
// TODO How to get the count if it is actually specified?
}
else
{
Map<String, Object> responseMap = JSONUtility.getAsMap(response);
results = dataSourceService.getQueryResponseProcessor().processResponse(responseMap);
}
}catch (JsonSyntaxException e){
System.out.println("JsonSyntaxException handling: " + response);
System.out.println(e);
throw new GeppettoDataSourceException(e);
}

}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,21 +27,28 @@ public class Neo4jResponseProcessor implements IQueryResponseProcessor
public QueryResults processResponse(Map<String, Object> response)
{
QueryResults results = DatasourcesFactory.eINSTANCE.createQueryResults();
List<String> headers = (List<String>) ((List) ((Map<String, Object>) ((List) response.get("results")).get(0)).get("columns"));
if(((List) response.get("results")).size() > 0)
{
List<String> headers = (List<String>) ((List) ((Map<String, Object>) ((List) response.get("results")).get(0)).get("columns"));

results.getHeader().addAll(headers);
results.getHeader().addAll(headers);

results.getResults().clear();
List<Map<String, Object>> data = (List<Map<String, Object>>) ((List) ((Map<String, Object>) ((List) response.get("results")).get(0)).get("data"));
for(Map<String, Object> rowObject : data)
{
QueryResult resultRow = DatasourcesFactory.eINSTANCE.createQueryResult();
List<Object> row = (List<Object>) rowObject.get("row");
for(Object value : row)
results.getResults().clear();
List<Map<String, Object>> data = (List<Map<String, Object>>) ((List) ((Map<String, Object>) ((List) response.get("results")).get(0)).get("data"));
for(Map<String, Object> rowObject : data)
{
resultRow.getValues().add(value);
QueryResult resultRow = DatasourcesFactory.eINSTANCE.createQueryResult();
List<Object> row = (List<Object>) rowObject.get("row");
for(Object value : row)
{
resultRow.getValues().add(value);
}
results.getResults().add(resultRow);
}
results.getResults().add(resultRow);
}
else
{
// TODO: report reponse to log
}
return results;
}
Expand Down
5 changes: 2 additions & 3 deletions src/main/resources/templates/neo4j/queryTemplate.vm
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
{
"statement":"$QUERY",
"resultDataContents":[
"row",
"graph"
"row"
],
"includeStats":true
"includeStats":false
}
]
}

0 comments on commit 102ad9a

Please sign in to comment.