Permalink
Browse files

Merge pull request #42 from mattcasters/master

Issues #35 (Metadata Injection) and #41 (Cypher dialog fix)
  • Loading branch information...
mattcasters committed Sep 28, 2018
2 parents a3d1ac4 + 41656ea commit 4254fc5d6f0abe5760d23912483fdef392df1536
@@ -4,7 +4,7 @@
<groupId>bi.know.kettle.neo4j.output</groupId>
<artifactId>Neo4JOutput</artifactId>
<version>3.11.0-SNAPSHOT</version>
<version>3.12.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Neo4JOutput</name>
@@ -36,7 +36,7 @@ public static final AreaOwner findArea( List<AreaOwner> areaOwners, int x, int y
while(li.hasPrevious()) {
AreaOwner areaOwner = li.previous();
if (areaOwner.contains(x, y)) {
System.out.println("Match: "+areaOwner.getAreaType()+" on ("+x+", "+y+")");
// System.out.println("Match: "+areaOwner.getAreaType()+" on ("+x+", "+y+")");
return areaOwner;
}
}

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -1,13 +1,18 @@
package bi.know.kettle.neo4j.steps.cypher;
import bi.know.kettle.neo4j.model.GraphPropertyType;
import com.sun.jersey.spi.inject.Inject;
import org.apache.commons.lang.StringUtils;
import org.pentaho.di.core.KettleAttributeInterface;
import org.pentaho.di.core.annotations.Step;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettlePluginException;
import org.pentaho.di.core.exception.KettleStepException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.injection.Injection;
import org.pentaho.di.core.injection.InjectionDeep;
import org.pentaho.di.core.injection.InjectionSupported;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.row.ValueMetaInterface;
import org.pentaho.di.core.row.value.ValueMetaFactory;
@@ -19,8 +24,10 @@
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepInjectionMetaEntry;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInjectionInterface;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.pentaho.metastore.api.IMetaStore;
import org.w3c.dom.Node;
@@ -36,18 +43,57 @@
categoryDescription = "Neo4j",
documentationUrl = "https://github.com/knowbi/knowbi-pentaho-pdi-neo4j-output/wiki/Neo4j-Cypher#description"
)
@InjectionSupported( localizationPrefix = "Cypher.Injection.", groups = { "PARAMETERS", "RETURNS" } )
public class CypherMeta extends BaseStepMeta implements StepMetaInterface {
public static final String CONNECTION = "connection";
public static final String CYPHER = "cypher";
public static final String BATCH_SIZE = "batch_size";
public static final String CYPHER_FROM_FIELD = "cypher_from_field";
public static final String CYPHER_FIELD = "cypher_field";
public static final String UNWIND = "unwind";
public static final String UNWIND_MAP = "unwind_map";
public static final String MAPPINGS = "mappings";
public static final String MAPPING = "mapping";
public static final String PARAMETERS = "parameters";
public static final String PARAMETER = "parameter";
public static final String FIELD = "field";
public static final String TYPE = "type";
public static final String RETURNS = "returns";
public static final String RETURN = "return";
public static final String NAME = "name";
public static final String PARAMETER_NAME = "parameter_name";
public static final String PARAMETER_FIELD = "parameter_field";
public static final String PARAMETER_TYPE = "parameter_type";
public static final String RETURN_NAME = "return_name";
public static final String RETURN_TYPE = "return_type";
@Injection( name = "CONNECTION" )
private String connectionName;
@Injection( name = "CYPHER")
private String cypher;
@Injection( name = "BATCH_SIZE" )
private String batchSize;
@Injection( name = "CYPHER_FROM_FIELD" )
private boolean cypherFromField;
@Injection( name = "CYPHER_FIELD" )
private String cypherField;
@Injection( name = "UNWIND" )
private boolean usingUnwind;
@Injection( name = "UNWIND_MAP" )
private String unwindMapName;
@InjectionDeep
private List<ParameterMapping> parameterMappings;
@InjectionDeep
private List<ReturnValue> returnValues;
public CypherMeta() {
@@ -99,55 +145,55 @@ public CypherMeta() {
@Override public String getXML() {
StringBuilder xml = new StringBuilder();
xml.append( XMLHandler.addTagValue( "connection", connectionName ) );
xml.append( XMLHandler.addTagValue( "cypher", cypher ) );
xml.append( XMLHandler.addTagValue( "batch_size", batchSize ) );
xml.append( XMLHandler.addTagValue( "cypher_from_field", cypherFromField ) );
xml.append( XMLHandler.addTagValue( "cypher_field", cypherField ) );
xml.append( XMLHandler.addTagValue( "unwind", usingUnwind ) );
xml.append( XMLHandler.addTagValue( "unwind_map", unwindMapName) );
xml.append( XMLHandler.openTag( "mappings" ) );
xml.append( XMLHandler.addTagValue( CONNECTION, connectionName ) );
xml.append( XMLHandler.addTagValue( CYPHER, cypher ) );
xml.append( XMLHandler.addTagValue( BATCH_SIZE, batchSize ) );
xml.append( XMLHandler.addTagValue( CYPHER_FROM_FIELD, cypherFromField ) );
xml.append( XMLHandler.addTagValue( CYPHER_FIELD, cypherField ) );
xml.append( XMLHandler.addTagValue( UNWIND, usingUnwind ) );
xml.append( XMLHandler.addTagValue( UNWIND_MAP, unwindMapName) );
xml.append( XMLHandler.openTag( MAPPINGS ) );
for ( ParameterMapping parameterMapping : parameterMappings ) {
xml.append( XMLHandler.openTag( "mapping" ) );
xml.append( XMLHandler.addTagValue( "parameter", parameterMapping.getParameter() ) );
xml.append( XMLHandler.addTagValue( "field", parameterMapping.getField() ) );
xml.append( XMLHandler.addTagValue( "type", parameterMapping.getNeoType() ) );
xml.append( XMLHandler.closeTag( "mapping" ) );
xml.append( XMLHandler.openTag( MAPPING ) );
xml.append( XMLHandler.addTagValue( PARAMETER, parameterMapping.getParameter() ) );
xml.append( XMLHandler.addTagValue( FIELD, parameterMapping.getField() ) );
xml.append( XMLHandler.addTagValue( TYPE, parameterMapping.getNeoType() ) );
xml.append( XMLHandler.closeTag( MAPPING ) );
}
xml.append( XMLHandler.closeTag( "mappings" ) );
xml.append( XMLHandler.closeTag( MAPPINGS ) );
xml.append( XMLHandler.openTag( "returns" ) );
xml.append( XMLHandler.openTag( RETURNS ) );
for ( ReturnValue returnValue : returnValues ) {
xml.append( XMLHandler.openTag( "return" ) );
xml.append( XMLHandler.addTagValue( "name", returnValue.getName() ) );
xml.append( XMLHandler.addTagValue( "type", returnValue.getType() ) );
xml.append( XMLHandler.closeTag( "return" ) );
xml.append( XMLHandler.openTag( RETURN ) );
xml.append( XMLHandler.addTagValue( NAME, returnValue.getName() ) );
xml.append( XMLHandler.addTagValue( TYPE, returnValue.getType() ) );
xml.append( XMLHandler.closeTag( RETURN ) );
}
xml.append( XMLHandler.closeTag( "returns" ) );
xml.append( XMLHandler.closeTag( RETURNS ) );
return xml.toString();
}
@Override public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException {
connectionName = XMLHandler.getTagValue( stepnode, "connection" );
cypher = XMLHandler.getTagValue( stepnode, "cypher" );
batchSize = XMLHandler.getTagValue( stepnode, "batch_size" );
cypherFromField = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "cypher_from_field" ) );
cypherField = XMLHandler.getTagValue( stepnode, "cypher_field" );
usingUnwind = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, "unwind" ) );
unwindMapName = XMLHandler.getTagValue( stepnode, "unwind_map" );
connectionName = XMLHandler.getTagValue( stepnode, CONNECTION );
cypher = XMLHandler.getTagValue( stepnode, CYPHER );
batchSize = XMLHandler.getTagValue( stepnode, BATCH_SIZE );
cypherFromField = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, CYPHER_FROM_FIELD ) );
cypherField = XMLHandler.getTagValue( stepnode, CYPHER_FIELD );
usingUnwind = "Y".equalsIgnoreCase( XMLHandler.getTagValue( stepnode, UNWIND ) );
unwindMapName = XMLHandler.getTagValue( stepnode, UNWIND_MAP );
// Parse parameter mappings
//
Node mappingsNode = XMLHandler.getSubNode( stepnode, "mappings" );
List<Node> mappingNodes = XMLHandler.getNodes( mappingsNode, "mapping" );
Node mappingsNode = XMLHandler.getSubNode( stepnode, MAPPINGS );
List<Node> mappingNodes = XMLHandler.getNodes( mappingsNode, MAPPING );
parameterMappings = new ArrayList<>();
for ( Node mappingNode : mappingNodes ) {
String parameter = XMLHandler.getTagValue( mappingNode, "parameter" );
String field = XMLHandler.getTagValue( mappingNode, "field" );
String neoType = XMLHandler.getTagValue( mappingNode, "type" );
String parameter = XMLHandler.getTagValue( mappingNode, PARAMETER );
String field = XMLHandler.getTagValue( mappingNode, FIELD );
String neoType = XMLHandler.getTagValue( mappingNode, TYPE );
if ( StringUtils.isEmpty( neoType ) ) {
neoType = GraphPropertyType.String.name();
}
@@ -156,65 +202,65 @@ public CypherMeta() {
// Parse return values
//
Node returnsNode = XMLHandler.getSubNode( stepnode, "returns" );
List<Node> returnNodes = XMLHandler.getNodes( returnsNode, "return" );
Node returnsNode = XMLHandler.getSubNode( stepnode, RETURNS );
List<Node> returnNodes = XMLHandler.getNodes( returnsNode, RETURN );
returnValues = new ArrayList<>();
for ( Node returnNode : returnNodes ) {
String name = XMLHandler.getTagValue( returnNode, "name" );
String type = XMLHandler.getTagValue( returnNode, "type" );
String name = XMLHandler.getTagValue( returnNode, NAME );
String type = XMLHandler.getTagValue( returnNode, TYPE );
returnValues.add( new ReturnValue( name, type ) );
}
super.loadXML( stepnode, databases, metaStore );
}
@Override public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ) throws KettleException {
rep.saveStepAttribute( id_transformation, id_step, "connection", connectionName );
rep.saveStepAttribute( id_transformation, id_step, "cypher", cypher );
rep.saveStepAttribute( id_transformation, id_step, "batch_size", batchSize );
rep.saveStepAttribute( id_transformation, id_step, "cypher_from_field", cypherFromField );
rep.saveStepAttribute( id_transformation, id_step, "cypher_field", cypherField );
rep.saveStepAttribute( id_transformation, id_step, "unwind", usingUnwind );
rep.saveStepAttribute( id_transformation, id_step, "unwind_map", unwindMapName );
rep.saveStepAttribute( id_transformation, id_step, CONNECTION, connectionName );
rep.saveStepAttribute( id_transformation, id_step, CYPHER, cypher );
rep.saveStepAttribute( id_transformation, id_step, BATCH_SIZE, batchSize );
rep.saveStepAttribute( id_transformation, id_step, CYPHER_FROM_FIELD, cypherFromField );
rep.saveStepAttribute( id_transformation, id_step, CYPHER_FIELD, cypherField );
rep.saveStepAttribute( id_transformation, id_step, UNWIND, usingUnwind );
rep.saveStepAttribute( id_transformation, id_step, UNWIND_MAP, unwindMapName );
for ( int i = 0; i < parameterMappings.size(); i++ ) {
ParameterMapping parameterMapping = parameterMappings.get( i );
rep.saveStepAttribute( id_transformation, id_step, i, "parameter_name", parameterMapping.getParameter() );
rep.saveStepAttribute( id_transformation, id_step, i, "parameter_field", parameterMapping.getField() );
rep.saveStepAttribute( id_transformation, id_step, i, "parameter_type", parameterMapping.getNeoType() );
rep.saveStepAttribute( id_transformation, id_step, i, PARAMETER_NAME, parameterMapping.getParameter() );
rep.saveStepAttribute( id_transformation, id_step, i, PARAMETER_FIELD, parameterMapping.getField() );
rep.saveStepAttribute( id_transformation, id_step, i, PARAMETER_TYPE, parameterMapping.getNeoType() );
}
for ( int i = 0; i < returnValues.size(); i++ ) {
ReturnValue returnValue = returnValues.get( i );
rep.saveStepAttribute( id_transformation, id_step, i, "return_name", returnValue.getName() );
rep.saveStepAttribute( id_transformation, id_step, i, "return_type", returnValue.getType() );
rep.saveStepAttribute( id_transformation, id_step, i, RETURN_NAME, returnValue.getName() );
rep.saveStepAttribute( id_transformation, id_step, i, RETURN_TYPE, returnValue.getType() );
}
}
@Override public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException {
connectionName = rep.getStepAttributeString( id_step, "connection" );
cypher = rep.getStepAttributeString( id_step, "cypher" );
batchSize = rep.getStepAttributeString( id_step, "batch_size" );
cypherFromField = rep.getStepAttributeBoolean( id_step, "cypher_from_field" );
cypherField = rep.getStepAttributeString( id_step, "cypher_field" );
usingUnwind = rep.getStepAttributeBoolean( id_step, "unwind" );
unwindMapName = rep.getStepAttributeString( id_step, "unwind_map" );
connectionName = rep.getStepAttributeString( id_step, CONNECTION );
cypher = rep.getStepAttributeString( id_step, CYPHER );
batchSize = rep.getStepAttributeString( id_step, BATCH_SIZE );
cypherFromField = rep.getStepAttributeBoolean( id_step, CYPHER_FROM_FIELD );
cypherField = rep.getStepAttributeString( id_step, CYPHER_FIELD );
usingUnwind = rep.getStepAttributeBoolean( id_step, UNWIND );
unwindMapName = rep.getStepAttributeString( id_step, UNWIND_MAP );
parameterMappings = new ArrayList<>();
int nrMappings = rep.countNrStepAttributes( id_step, "parameter" );
int nrMappings = rep.countNrStepAttributes( id_step, PARAMETER );
for ( int i = 0; i < nrMappings; i++ ) {
String parameter = rep.getStepAttributeString( id_step, i, "parameter_name" );
String field = rep.getStepAttributeString( id_step, i, "parameter_field" );
String neoType = rep.getStepAttributeString( id_step, i, "parameter_type" );
String parameter = rep.getStepAttributeString( id_step, i, PARAMETER_NAME );
String field = rep.getStepAttributeString( id_step, i, PARAMETER_FIELD );
String neoType = rep.getStepAttributeString( id_step, i, PARAMETER_TYPE );
if ( StringUtils.isEmpty( neoType ) ) {
neoType = GraphPropertyType.String.name();
}
parameterMappings.add( new ParameterMapping( parameter, field, neoType ) );
}
returnValues = new ArrayList<>();
int nrReturns = rep.countNrStepAttributes( id_step, "return_name" );
int nrReturns = rep.countNrStepAttributes( id_step, RETURN_NAME );
for ( int i = 0; i < nrReturns; i++ ) {
String name = rep.getStepAttributeString( id_step, i, "return_name" );
String type = rep.getStepAttributeString( id_step, i, "return_type" );
String name = rep.getStepAttributeString( id_step, i, RETURN_NAME );
String type = rep.getStepAttributeString( id_step, i, RETURN_TYPE );
returnValues.add( new ReturnValue( name, type ) );
}
@@ -1,9 +1,16 @@
package bi.know.kettle.neo4j.steps.cypher;
import org.pentaho.di.core.injection.Injection;
public class ParameterMapping {
@Injection( name = "PARAMETER_NAME", group = "PARAMETERS" )
private String parameter;
@Injection( name = "PARAMETER_FIELD", group = "PARAMETERS" )
private String field;
@Injection( name = "PARAMETER_NEO4J_TYPE", group = "PARAMETERS" )
private String neoType;
public ParameterMapping() {
@@ -1,7 +1,13 @@
package bi.know.kettle.neo4j.steps.cypher;
import org.pentaho.di.core.injection.Injection;
public class ReturnValue {
@Injection( name = "RETURN_NAME", group = "RETURNS" )
private String name;
@Injection( name = "RETURN_TYPE", group = "RETURNS" )
private String type;
public ReturnValue() {
@@ -1,3 +1,18 @@
CypherDialog.PreviewSize.DialogTitle = Preview size
CypherDialog.PreviewSize.DialogMessage = Enter the number of rows to preview:
Cypher.Injection.CONNECTION = The Neo4j Connection name
Cypher.Injection.CYPHER = The Cypher statement to execute
Cypher.Injection.BATCH_SIZE = The batch size, used for updating
Cypher.Injection.CYPHER_FROM_FIELD = Get this Cypher from an input field?
Cypher.Injection.CYPHER_FIELD = The field to read the Cypher statements from
Cypher.Injection.UNWIND = Collect parameter values map?
Cypher.Injection.UNWIND_MAP = Name of values map list
Cypher.Injection.PARAMETERS = The list of parameters to pass to the Cypher statement
Cypher.Injection.PARAMETER_NAME = The name of the parameter to pass
Cypher.Injection.PARAMETER_FIELD = The field name to use as parameter value
Cypher.Injection.PARAMETER_NEO4J_TYPE = The Neo4j data type to set
Cypher.Injection.RETURNS = The list of return values from the Cypher query
Cypher.Injection.RETURN_NAME = The name of the value to return
Cypher.Injection.RETURN_TYPE = The Kettle return type to convert to
@@ -0,0 +1,54 @@
package bi.know.kettle.neo4j.steps.graph;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/**
* The class contains a cypher statement and the mapping between each parameter name and the input field
*/
public class CypherParameters {
private String cypher;
private List<TargetParameter> targetParameters;
public CypherParameters() {
targetParameters = new ArrayList<>();
}
public CypherParameters( String cypher, List<TargetParameter> targetParameters ) {
this.cypher = cypher;
this.targetParameters = targetParameters;
}
/**
* Gets cypher
*
* @return value of cypher
*/
public String getCypher() {
return cypher;
}
/**
* @param cypher The cypher to set
*/
public void setCypher( String cypher ) {
this.cypher = cypher;
}
/**
* Gets targetParameters
*
* @return value of targetParameters
*/
public List<TargetParameter> getTargetParameters() {
return targetParameters;
}
/**
* @param targetParameters The targetParameters to set
*/
public void setTargetParameters( List<TargetParameter> targetParameters ) {
this.targetParameters = targetParameters;
}
}
Oops, something went wrong.

0 comments on commit 4254fc5

Please sign in to comment.