/** Define an input field */ public Builder in( String name, Neo4jTypes.AnyType type ) { inputSignature.add( FieldSignature.inputField( name, type ) ); return this; }
public static FieldSignature outputField( String name, Neo4jTypes.AnyType type ) { return outputField( name, type, false ); }
public static FieldSignature inputField( String name, Neo4jTypes.AnyType type ) { return new FieldSignature( name, type, null, false ); }
@Test public void equalsShouldConsiderType() { assertEquals( "input without default", inputField( "name", Neo4jTypes.NTString ), inputField( "name", Neo4jTypes.NTString ) ); assertNotEquals( "input without default", inputField( "name", Neo4jTypes.NTString ), inputField( "name", Neo4jTypes.NTInteger ) ); assertEquals( "output", outputField( "name", Neo4jTypes.NTString, false ), outputField( "name", Neo4jTypes.NTString, false ) ); assertNotEquals( "output", outputField( "name", Neo4jTypes.NTString, false ), outputField( "name", Neo4jTypes.NTInteger, false ) ); assertEquals( "deprecated output", outputField( "name", Neo4jTypes.NTString, true ), outputField( "name", Neo4jTypes.NTString, true ) ); assertNotEquals( "deprecated output", outputField( "name", Neo4jTypes.NTString, true ), outputField( "name", Neo4jTypes.NTInteger, true ) ); }
protected Object[] mapToObjects( String type, QualifiedName name, List<FieldSignature> inputSignature, AnyValue[] input ) throws ProcedureException { // Verify that the number of passed arguments matches the number expected in the mthod signature if ( inputSignature.size() != input.length ) { throw new ProcedureException( Status.Procedure.ProcedureCallFailed, "%s `%s` takes %d arguments but %d was provided.", type, name, inputSignature.size(), input.length ); } Object[] args = new Object[input.length]; for ( int i = 0; i < input.length; i++ ) { args[i] = inputSignature.get( i ).map( input[i], mapper ); } return args; } }
private static int[] computeIndexesToMap( List<FieldSignature> inputSignature ) { ArrayList<Integer> integers = new ArrayList<>(); for ( int i = 0; i < inputSignature.size(); i++ ) { if ( inputSignature.get( i ).needsMapping() ) { integers.add( i ); } } return integers.stream().mapToInt( i -> i ).toArray(); } }
private void validateSignature( String descriptiveName, List<FieldSignature> fields, String fieldType ) throws ProcedureException { Set<String> names = new HashSet<>(); for ( FieldSignature field : fields ) { if ( !names.add( field.name() ) ) { throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, "Procedure `%s` cannot be registered, because it contains a duplicated " + fieldType + " field, '%s'. " + "You need to rename or remove one of the duplicate fields.", descriptiveName, field.name() ); } } }
inputField( "name", Neo4jTypes.NTString ), inputField( "name", Neo4jTypes.NTString ) ); assertNotEquals( "input without default", inputField( "name", Neo4jTypes.NTString ), inputField( "other", Neo4jTypes.NTString ) ); inputField( "name", Neo4jTypes.NTString, ntString( "hello" ) ), inputField( "name", Neo4jTypes.NTString, ntString( "hello" ) ) ); assertNotEquals( "input with default", inputField( "name", Neo4jTypes.NTString, ntString( "hello" ) ), inputField( "other", Neo4jTypes.NTString, ntString( "hello" ) ) ); outputField( "name", Neo4jTypes.NTString, false ), outputField( "name", Neo4jTypes.NTString, false ) ); assertNotEquals( "output", outputField( "name", Neo4jTypes.NTString, false ), outputField( "other", Neo4jTypes.NTString, false ) ); outputField( "name", Neo4jTypes.NTString, true ), outputField( "name", Neo4jTypes.NTString, true ) ); assertNotEquals( "deprecated output", outputField( "name", Neo4jTypes.NTString, true ), outputField( "other", Neo4jTypes.NTString, true ) );
input[indexToMap] = inputSignature.get( indexToMap ).map( input[indexToMap] );
private static int[] computeIndexesToMap( List<FieldSignature> inputSignature ) { ArrayList<Integer> integers = new ArrayList<>(); for ( int i = 0; i < inputSignature.size(); i++ ) { if ( inputSignature.get( i ).needsMapping() ) { integers.add( i ); } } return integers.stream().mapToInt( i -> i ).toArray(); } }
private void validateSignature( String descriptiveName, List<FieldSignature> fields, String fieldType ) throws ProcedureException { Set<String> names = new HashSet<>(); for ( FieldSignature field : fields ) { if ( !names.add( field.name() ) ) { throw new ProcedureException( Status.Procedure.ProcedureRegistrationFailed, "Procedure `%s` cannot be registered, because it contains a duplicated " + fieldType + " field, '%s'. " + "You need to rename or remove one of the duplicate fields.", descriptiveName, field.name() ); } } }
/** Define an input field */ public Builder in( String name, Neo4jTypes.AnyType type ) { inputSignature.add( FieldSignature.inputField( name, type ) ); return this; }
public List<FieldSignature> outputSignatures(@Name(value = "outputs", defaultValue = "null") List<List<String>> outputs) { return outputs == null ? singletonList(FieldSignature.inputField("row", NTMap)) : outputs.stream().map(pair -> FieldSignature.outputField(pair.get(0),typeof(pair.get(1)))).collect(Collectors.toList()); }
/** Define an output field */ public Builder out( String name, Neo4jTypes.AnyType type ) { outputSignature.add( FieldSignature.outputField( name, type ) ); return this; }
public static FieldSignature outputField( String name, Neo4jTypes.AnyType type, boolean deprecated ) { return new FieldSignature( name, type, null, deprecated ); }
input[indexToMap] = inputSignature.get( indexToMap ).map( input[indexToMap] );
signature.add( defaultValue.map( neo4jValue -> inputField( name, valueConverter.type(), neo4jValue, mapper ) ).orElseGet( () -> inputField( name, valueConverter.type(), mapper ) ) ); signature.add( defaultValue.map( neo4jValue -> inputField( name, valueConverter.type(), neo4jValue ) ).orElseGet( () -> inputField( name, valueConverter.type() ) ) );
@Test public void equalsShouldConsiderDeprecation() { assertEquals( outputField( "name", Neo4jTypes.NTString, true ), outputField( "name", Neo4jTypes.NTString, true ) ); assertEquals( outputField( "name", Neo4jTypes.NTString, false ), outputField( "name", Neo4jTypes.NTString, false ) ); assertNotEquals( outputField( "name", Neo4jTypes.NTString, true ), outputField( "name", Neo4jTypes.NTString, false ) ); } }
public static FieldSignature inputField( String name, Neo4jTypes.AnyType type, DefaultParameterValue defaultValue ) { return new FieldSignature( name, type, requireNonNull( defaultValue, "defaultValue" ), false ); }
protected Object[] mapToObjects( String type, QualifiedName name, List<FieldSignature> inputSignature, AnyValue[] input ) throws ProcedureException { // Verify that the number of passed arguments matches the number expected in the mthod signature if ( inputSignature.size() != input.length ) { throw new ProcedureException( Status.Procedure.ProcedureCallFailed, "%s `%s` takes %d arguments but %d was provided.", type, name, inputSignature.size(), input.length ); } Object[] args = new Object[input.length]; for ( int i = 0; i < input.length; i++ ) { args[i] = inputSignature.get( i ).map( input[i], mapper ); } return args; } }