Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes #1584: apoc.custom.asProcedure() doesn't work when there is input parameters #1591

Merged
merged 1 commit into from
Jul 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fixes #1584: apoc.custom.asProcedure() doesn't work when there is inp…
…ut parameters
  • Loading branch information
conker84 committed Jul 13, 2020
commit d6560b879fea6b85e9c392e51c0a725dc6eb8f82
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jar {

ext {
// NB: due to version.json generation by parsing this file, the next line must not have any if/then/else logic
neo4jVersion = "4.0.4"
neo4jVersion = "4.0.6"
// instead we apply the override logic here
neo4jVersionEffective = project.hasProperty("neo4jVersionOverride") ? project.getProperty("neo4jVersionOverride") : neo4jVersion
testContainersVersion = '1.12.2'
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/apoc/custom/CypherProceduresHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ private ProcedureDescriptor procedureDescriptor(Node node) {
List<FieldSignature> inputs = deserializeSignatures(property);

List<FieldSignature> outputSignature = deserializeSignatures((String) node.getProperty(SystemPropertyKeys.outputs.name()));
return new ProcedureDescriptor(new ProcedureSignature(
return new ProcedureDescriptor(Signatures.createProcedureSignature(
new QualifiedName(new String[]{PREFIX}, name),
inputs,
outputSignature,
Expand All @@ -174,6 +174,7 @@ private ProcedureDescriptor procedureDescriptor(Node node) {
null,
false,
false,
false,
false
), statement);
}
Expand Down Expand Up @@ -317,7 +318,7 @@ private long getLastUpdate() {
public ProcedureSignature procedureSignature(String name, String mode, List<List<String>> outputs, List<List<String>> inputs, String description) {
boolean admin = false; // TODO
return new ProcedureSignature(qualifiedName(name), inputSignatures(inputs), outputSignatures(outputs),
Mode.valueOf(mode.toUpperCase()), admin, null, new String[0], description, null, false, false, true
Mode.valueOf(mode.toUpperCase()), admin, null, new String[0], description, null, false, false, true, false
);
}

Expand Down
61 changes: 60 additions & 1 deletion src/main/java/apoc/custom/Signatures.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.neo4j.internal.kernel.api.procs.*;
import org.neo4j.procedure.Mode;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
Expand Down Expand Up @@ -72,7 +73,7 @@ public ProcedureSignature toProcedureSignature(SignatureParser.ProcedureContext
String warning = null; // "todo warning";
boolean eager = false;
boolean caseInsensitive = true;
return new ProcedureSignature(name, inputSignatures, outputSignature, mode, admin, deprecated, allowed, description, warning, eager, caseInsensitive, false);
return createProcedureSignature(name, inputSignatures, outputSignature, mode, admin, deprecated, allowed, description, warning, eager, caseInsensitive, false, false);
}

public List<String> namespace(SignatureParser.NamespaceContext namespaceContext) {
Expand Down Expand Up @@ -213,4 +214,62 @@ public ProcedureSignature asProcedureSignature(String signature, String descript
SignatureParser.ProcedureContext ctx = parseProcedure(signature);
return toProcedureSignature(ctx, description, mode);
}

public static ProcedureSignature createProcedureSignature(QualifiedName name,
List<FieldSignature> inputSignature,
List<FieldSignature> outputSignature,
Mode mode,
boolean admin,
String deprecated,
String[] allowed,
String description,
String warning,
boolean eager,
boolean caseInsensitive,
boolean systemProcedure,
boolean internal) {
try {
// in Neo4j 4.0.5 org.neo4j.internal.kernel.api.procs.ProcedureSignature
// changed the signature adding a boolean at the end and without leaving the old signature
// in order to maintain the backwards compatibility with version prior to 4.0.5 we use the
// reflection to create a new instance of the class
final Class<?> clazz = Class.forName("org.neo4j.internal.kernel.api.procs.ProcedureSignature");
final Constructor<?>[] constructors = clazz.getConstructors();
for (int i = 0; i < constructors.length; i++) {
final Constructor<?> constructor = constructors[i];
switch (constructor.getParameterCount()) {
case 13:
return (ProcedureSignature) constructor.newInstance(name,
inputSignature,
outputSignature,
mode,
admin,
deprecated,
allowed,
description,
warning,
eager,
caseInsensitive,
systemProcedure,
internal);
case 12:
return (ProcedureSignature) constructor.newInstance(name,
inputSignature,
outputSignature,
mode,
admin,
deprecated,
allowed,
description,
warning,
eager,
caseInsensitive,
systemProcedure);
}
}
throw new RuntimeException("Constructor of org.neo4j.internal.kernel.api.procs.ProcedureSignature not found");
} catch (Exception e) {
throw new RuntimeException(e);
}
}
}