From 0f4bd436752e5d9c2a284f791bd450e6fdb92f69 Mon Sep 17 00:00:00 2001 From: Marco Grassi Date: Tue, 23 Jul 2024 09:12:13 +0200 Subject: [PATCH 1/3] add generated camel jsons --- .../src/generated/resources/com/cefriel/component/graph.json | 2 +- .../src/generated/resources/com/cefriel/component/mapt.json | 2 +- .../src/generated/resources/com/cefriel/component/rml.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/camel-chimera-graph/src/generated/resources/com/cefriel/component/graph.json b/camel-chimera-graph/src/generated/resources/com/cefriel/component/graph.json index 691334c..d7553b1 100644 --- a/camel-chimera-graph/src/generated/resources/com/cefriel/component/graph.json +++ b/camel-chimera-graph/src/generated/resources/com/cefriel/component/graph.json @@ -11,7 +11,7 @@ "supportLevel": "Stable", "groupId": "com.cefriel", "artifactId": "camel-chimera-graph", - "version": "4.1.1-SNAPSHOT", + "version": "4.1.1", "scheme": "graph", "extendsScheme": "", "syntax": "graph:name", diff --git a/camel-chimera-mapping-template/src/generated/resources/com/cefriel/component/mapt.json b/camel-chimera-mapping-template/src/generated/resources/com/cefriel/component/mapt.json index 284017b..dd97a7d 100644 --- a/camel-chimera-mapping-template/src/generated/resources/com/cefriel/component/mapt.json +++ b/camel-chimera-mapping-template/src/generated/resources/com/cefriel/component/mapt.json @@ -11,7 +11,7 @@ "supportLevel": "Stable", "groupId": "com.cefriel", "artifactId": "camel-chimera-mapping-template", - "version": "4.1.1-SNAPSHOT", + "version": "4.1.1", "scheme": "mapt", "extendsScheme": "", "syntax": "mapt:name", diff --git a/camel-chimera-rmlmapper/src/generated/resources/com/cefriel/component/rml.json b/camel-chimera-rmlmapper/src/generated/resources/com/cefriel/component/rml.json index 6ff1152..0600c07 100644 --- a/camel-chimera-rmlmapper/src/generated/resources/com/cefriel/component/rml.json +++ b/camel-chimera-rmlmapper/src/generated/resources/com/cefriel/component/rml.json @@ -11,7 +11,7 @@ "supportLevel": "Stable", "groupId": "com.cefriel", "artifactId": "camel-chimera-rmlmapper", - "version": "4.1.1-SNAPSHOT", + "version": "4.1.1", "scheme": "rml", "extendsScheme": "", "syntax": "rml:name", From ff776cf6a3c76bbf43d1013a6c6832979654fb78 Mon Sep 17 00:00:00 2001 From: Marco Grassi Date: Thu, 5 Sep 2024 14:22:36 +0200 Subject: [PATCH 2/3] feat: add 'operation' parameter to graph-component Closes #22 The name of the operation must be specified in one the following ways: 1) .to("graph://get?...) 2) .to("graph://?operation=get") The parameter is case insensitive --- .../component/GraphEndpointConfigurer.java | 3 ++ .../component/GraphEndpointUriFactory.java | 5 +-- .../com/cefriel/component/graph.json | 29 ++++++++-------- .../java/com/cefriel/component/GraphBean.java | 19 ++++++++++- .../com/cefriel/component/GraphConsumer.java | 15 +++++++- .../com/cefriel/component/GraphEndpoint.java | 22 ++++++++++-- .../com/cefriel/component/GraphProducer.java | 12 ++++++- .../com/cefriel/OperationParameterTest.java | 34 +++++++++++++++++++ .../resources/com/cefriel/component/mapt.json | 2 +- .../resources/com/cefriel/component/rml.json | 2 +- 10 files changed, 119 insertions(+), 24 deletions(-) create mode 100644 camel-chimera-graph/src/test/java/com/cefriel/OperationParameterTest.java diff --git a/camel-chimera-graph/src/generated/java/com/cefriel/component/GraphEndpointConfigurer.java b/camel-chimera-graph/src/generated/java/com/cefriel/component/GraphEndpointConfigurer.java index a6ba3dc..ed87c3a 100644 --- a/camel-chimera-graph/src/generated/java/com/cefriel/component/GraphEndpointConfigurer.java +++ b/camel-chimera-graph/src/generated/java/com/cefriel/component/GraphEndpointConfigurer.java @@ -51,6 +51,7 @@ public boolean configure(CamelContext camelContext, Object obj, String name, Obj case "newGraph": target.setNewGraph(property(camelContext, boolean.class, value)); return true; case "ontologyformat": case "ontologyFormat": target.setOntologyFormat(property(camelContext, java.lang.String.class, value)); return true; + case "operation": target.setOperation(property(camelContext, java.lang.String.class, value)); return true; case "pathdatadir": case "pathDataDir": target.setPathDataDir(property(camelContext, java.lang.String.class, value)); return true; case "query": target.setQuery(property(camelContext, java.lang.String.class, value)); return true; @@ -103,6 +104,7 @@ public Class getOptionType(String name, boolean ignoreCase) { case "newGraph": return boolean.class; case "ontologyformat": case "ontologyFormat": return java.lang.String.class; + case "operation": return java.lang.String.class; case "pathdatadir": case "pathDataDir": return java.lang.String.class; case "query": return java.lang.String.class; @@ -156,6 +158,7 @@ public Object getOptionValue(Object obj, String name, boolean ignoreCase) { case "newGraph": return target.isNewGraph(); case "ontologyformat": case "ontologyFormat": return target.getOntologyFormat(); + case "operation": return target.getOperation(); case "pathdatadir": case "pathDataDir": return target.getPathDataDir(); case "query": return target.getQuery(); diff --git a/camel-chimera-graph/src/generated/java/com/cefriel/component/GraphEndpointUriFactory.java b/camel-chimera-graph/src/generated/java/com/cefriel/component/GraphEndpointUriFactory.java index f86d359..8d41a66 100644 --- a/camel-chimera-graph/src/generated/java/com/cefriel/component/GraphEndpointUriFactory.java +++ b/camel-chimera-graph/src/generated/java/com/cefriel/component/GraphEndpointUriFactory.java @@ -21,7 +21,7 @@ public class GraphEndpointUriFactory extends org.apache.camel.support.component. private static final Set SECRET_PROPERTY_NAMES; private static final Set MULTI_VALUE_PREFIXES; static { - Set props = new HashSet<>(25); + Set props = new HashSet<>(26); props.add("allRules"); props.add("baseConfig"); props.add("baseIri"); @@ -39,6 +39,7 @@ public class GraphEndpointUriFactory extends org.apache.camel.support.component. props.add("namedGraph"); props.add("newGraph"); props.add("ontologyFormat"); + props.add("operation"); props.add("pathDataDir"); props.add("query"); props.add("rdfFormat"); @@ -64,7 +65,7 @@ public String buildUri(String scheme, Map properties, boolean en Map copy = new HashMap<>(properties); - uri = buildPathParameter(syntax, uri, "name", null, true, copy); + uri = buildPathParameter(syntax, uri, "name", null, false, copy); uri = buildQueryParameters(uri, copy, encode); return uri; } diff --git a/camel-chimera-graph/src/generated/resources/com/cefriel/component/graph.json b/camel-chimera-graph/src/generated/resources/com/cefriel/component/graph.json index d7553b1..330f498 100644 --- a/camel-chimera-graph/src/generated/resources/com/cefriel/component/graph.json +++ b/camel-chimera-graph/src/generated/resources/com/cefriel/component/graph.json @@ -11,7 +11,7 @@ "supportLevel": "Stable", "groupId": "com.cefriel", "artifactId": "camel-chimera-graph", - "version": "4.1.1", + "version": "4.1.2-SNAPSHOT", "scheme": "graph", "extendsScheme": "", "syntax": "graph:name", @@ -28,7 +28,7 @@ "autowiredEnabled": { "index": 2, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc." } }, "properties": { - "name": { "index": 0, "kind": "path", "displayName": "Name", "group": "common", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "autowired": false, "secret": false, "description": "This parameter contains the name of the endpoint" }, + "name": { "index": 0, "kind": "path", "displayName": "Name", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "This parameter contains the name of the endpoint" }, "allRules": { "index": 1, "kind": "parameter", "displayName": "All Rules", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Parameter used to set certain InferenceRDFGraph rules" }, "baseConfig": { "index": 2, "kind": "parameter", "displayName": "Base Config", "group": "common", "label": "", "required": false, "type": "object", "javaType": "com.cefriel.component.GraphBean", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to set the base configuration of this endpoint" }, "baseIri": { "index": 3, "kind": "parameter", "displayName": "Base Iri", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "http:\/\/www.cefriel.com\/data\/", "description": "Parameter used to set the IRI of the graph you want to create" }, @@ -41,17 +41,18 @@ "namedGraph": { "index": 10, "kind": "parameter", "displayName": "Named Graph", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Can be used to pass multiple named graphs separated by ';'" }, "newGraph": { "index": 11, "kind": "parameter", "displayName": "New Graph", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Parameter set to true if you want to create a new graph with the result of a construct" }, "ontologyFormat": { "index": 12, "kind": "parameter", "displayName": "Ontology Format", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to express the rdfFormat you want to parse to ontologies" }, - "pathDataDir": { "index": 13, "kind": "parameter", "displayName": "Path Data Dir", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to create a Native RDF Graph or an Inference RDF Graph" }, - "query": { "index": 14, "kind": "parameter", "displayName": "Query", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "This parameter contains a query that has to be applied to the graph" }, - "rdfFormat": { "index": 15, "kind": "parameter", "displayName": "Rdf Format", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "This parameter contains the rdfFormat you want to parse a file or an InputStream" }, - "repoOff": { "index": 16, "kind": "parameter", "displayName": "Repo Off", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Parameter set to true if you want to shut down the repo" }, - "repositoryID": { "index": 17, "kind": "parameter", "displayName": "Repository ID", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to create a HTTPRDFGraph" }, - "routeOff": { "index": 18, "kind": "parameter", "displayName": "Route Off", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Parameter set to true if you want to stop the route" }, - "serverUrl": { "index": 19, "kind": "parameter", "displayName": "Server Url", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to create a HTTPRDFGraph" }, - "sparqlEndpoint": { "index": 20, "kind": "parameter", "displayName": "Sparql Endpoint", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to create a SPARQLEndpointGraph" }, - "bridgeErrorHandler": { "index": 21, "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored." }, - "exceptionHandler": { "index": 22, "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored." }, - "exchangePattern": { "index": 23, "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, - "lazyStartProducer": { "index": 24, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." } + "operation": { "index": 13, "kind": "parameter", "displayName": "Operation", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "GET", "ADD", "CONSTRUCT", "ASK", "SELECT", "INFERENCE", "DETACH", "DUMP", "SHACL" ], "deprecated": false, "autowired": false, "secret": false, "description": "Name of the operation to be executed. The name of the operations is not case sensitive." }, + "pathDataDir": { "index": 14, "kind": "parameter", "displayName": "Path Data Dir", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to create a Native RDF Graph or an Inference RDF Graph" }, + "query": { "index": 15, "kind": "parameter", "displayName": "Query", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "This parameter contains a query that has to be applied to the graph" }, + "rdfFormat": { "index": 16, "kind": "parameter", "displayName": "Rdf Format", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "This parameter contains the rdfFormat you want to parse a file or an InputStream" }, + "repoOff": { "index": 17, "kind": "parameter", "displayName": "Repo Off", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "Parameter set to true if you want to shut down the repo" }, + "repositoryID": { "index": 18, "kind": "parameter", "displayName": "Repository ID", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to create a HTTPRDFGraph" }, + "routeOff": { "index": 19, "kind": "parameter", "displayName": "Route Off", "group": "common", "label": "", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Parameter set to true if you want to stop the route" }, + "serverUrl": { "index": 20, "kind": "parameter", "displayName": "Server Url", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to create a HTTPRDFGraph" }, + "sparqlEndpoint": { "index": 21, "kind": "parameter", "displayName": "Sparql Endpoint", "group": "common", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Parameter used to create a SPARQLEndpointGraph" }, + "bridgeErrorHandler": { "index": 22, "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored." }, + "exceptionHandler": { "index": 23, "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored." }, + "exchangePattern": { "index": 24, "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, + "lazyStartProducer": { "index": 25, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing." } } } diff --git a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphBean.java b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphBean.java index 47e3ba8..0ed08b3 100644 --- a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphBean.java +++ b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphBean.java @@ -24,6 +24,9 @@ public class GraphBean { private String basePath = "./"; + + private String operation; + private List resources = new ArrayList<>(); private ChimeraResourceBean chimeraResource; private String rdfFormat; @@ -51,7 +54,7 @@ public GraphBean(String basePath, List resources, String rdfFormat, bool String ontologyFormat, String namedGraph, String baseIri, boolean defaultGraph, String serverUrl, String repositoryID, String sparqlEndpoint, String pathDataDir, String query, boolean newGraph, boolean clear, boolean repoOff, boolean routeOff, - String dumpFormat, String filename) { + String dumpFormat, String filename, String operation) { this.basePath = basePath; this.resources = resources; this.rdfFormat = rdfFormat; @@ -71,6 +74,7 @@ public GraphBean(String basePath, List resources, String rdfFormat, bool this.routeOff = routeOff; this.dumpFormat = dumpFormat; this.filename = filename; + this.operation = operation; } public GraphBean(GraphBean configuration){ @@ -93,6 +97,7 @@ public GraphBean(GraphBean configuration){ this.routeOff = configuration.isRouteOff(); this.dumpFormat = configuration.getDumpFormat(); this.filename = configuration.getFilename(); + this.operation = configuration.getOperation(); } public String getBasePath() { @@ -255,6 +260,14 @@ public void setChimeraResource(ChimeraResourceBean chimeraResources) { this.chimeraResource = chimeraResources; } + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + public void setEndpointParameters(GraphEndpoint endpoint){ if(endpoint.getChimeraResource()!=null){ this.setChimeraResource(endpoint.getChimeraResource()); @@ -308,5 +321,9 @@ public void setEndpointParameters(GraphEndpoint endpoint){ if(endpoint.getBasePath()!=null){ this.setBasePath(endpoint.getBasePath()); } + + if(endpoint.getOperation() != null) { + this.setOperation(endpoint.getOperation()); + } } } diff --git a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphConsumer.java b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphConsumer.java index ea0b323..38ba8d0 100644 --- a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphConsumer.java +++ b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphConsumer.java @@ -44,8 +44,21 @@ protected void doStart() throws Exception { } else { operationConfig = new GraphBean(); } + + // todo name of operation can either come from endpoint.getName() or endpoint.getOperationName() operationConfig.setEndpointParameters(endpoint); - if ("get".equals(endpoint.getName())) { + + String operation; + if (endpoint.getName().equals("") && endpoint.getOperation() != null) + operation = endpoint.getOperation(); + else if (endpoint.getName() != null && endpoint.getOperation() == null) + operation = endpoint.getName(); + else + throw new IllegalArgumentException("The operation name must be specified either by the 'name' or 'operation' parameter."); + + operation = operation.toLowerCase(); + + if ("get".equals(operation)) { GraphGet.obtainGraph(exchange, operationConfig); try { // send message to next processor in the route diff --git a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphEndpoint.java b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphEndpoint.java index 51e37ce..f40d3e8 100644 --- a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphEndpoint.java +++ b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphEndpoint.java @@ -32,8 +32,14 @@ */ @UriEndpoint(firstVersion = "1.0.0", scheme = "graph", title = "graph", syntax="graph:name", category = {Category.TRANSFORMATION}) public class GraphEndpoint extends DefaultEndpoint { - @UriPath @Metadata(required = true) - private String name; + @UriPath + private String name = null; + + @UriParam(defaultValue = "null", + description = "Name of the operation to be executed. The name of the operations is not case sensitive.", + enums = "GET, ADD, CONSTRUCT, ASK, SELECT, INFERENCE, DETACH, DUMP, SHACL") + private String operation; + @UriParam(defaultValue = "null") private String basePath; @UriParam(defaultValue = "null") @@ -50,7 +56,9 @@ public class GraphEndpoint extends DefaultEndpoint { private boolean allRules = true; @UriParam(defaultValue = "null") private String ontologyFormat; - @UriParam(name = "namedGraph", defaultValue = "null", description = "Can be used to pass multiple named graphs separated by ';'") + @UriParam(name = "namedGraph", + defaultValue = "null", + description = "Can be used to pass multiple named graphs separated by ';'") private String namedGraph; @UriParam(defaultValue = "http://www.cefriel.com/data/") private String baseIri; @@ -103,6 +111,14 @@ public String getName() { return name; } + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + /** * This parameter contains the rdfFormat you want to parse a file or an InputStream */ diff --git a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphProducer.java b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphProducer.java index e4772b6..988a42e 100644 --- a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphProducer.java +++ b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphProducer.java @@ -52,12 +52,22 @@ public void process(Exchange exchange) throws Exception { LOG.info("No GraphBean detected"); } operationConfig.setEndpointParameters(endpoint); + String operation; + if (endpoint.getName() == null && endpoint.getOperation() != null) + operation = endpoint.getOperation(); + else if (endpoint.getName() != null && endpoint.getOperation() == null) + operation = endpoint.getName(); + else + throw new IllegalArgumentException("The operation name must be specified either by the 'name' or 'operation' parameter."); + + operation = operation.toLowerCase(); // todo see if this can be avoided and only have operationLocalConfig // this is done to propagate the configuration from one producer operation to the other exchange.getMessage().setHeader(ChimeraConstants.CONFIGURATION, operationConfig); - switch (endpoint.getName()){ + + switch (operation){ case "config" -> exchange.getMessage().setHeader(ChimeraConstants.BASE_CONFIGURATION, endpoint.getBaseConfig()); case "get" -> { inputStream = exchange.getMessage().getBody(InputStream.class); diff --git a/camel-chimera-graph/src/test/java/com/cefriel/OperationParameterTest.java b/camel-chimera-graph/src/test/java/com/cefriel/OperationParameterTest.java new file mode 100644 index 0000000..96e9676 --- /dev/null +++ b/camel-chimera-graph/src/test/java/com/cefriel/OperationParameterTest.java @@ -0,0 +1,34 @@ +package com.cefriel; + +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.mock.MockEndpoint; +import org.apache.camel.test.junit5.CamelTestSupport; +import org.junit.jupiter.api.Test; + +public class OperationParameterTest extends CamelTestSupport { + + @Test + public void testOperationParameter() throws InterruptedException { + MockEndpoint mock = getMockEndpoint("mock:operation"); + mock.expectedMessageCount(3); + mock.assertIsSatisfied(); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + + public void configure() throws Exception { + + from("graph://?operation=get") + .to("mock:operation"); + + from("graph://?operation=Get") + .to("mock:operation"); + + from("graph://?operation=GET") + .to("mock:operation"); + } + }; + } +} diff --git a/camel-chimera-mapping-template/src/generated/resources/com/cefriel/component/mapt.json b/camel-chimera-mapping-template/src/generated/resources/com/cefriel/component/mapt.json index dd97a7d..2cd43b5 100644 --- a/camel-chimera-mapping-template/src/generated/resources/com/cefriel/component/mapt.json +++ b/camel-chimera-mapping-template/src/generated/resources/com/cefriel/component/mapt.json @@ -11,7 +11,7 @@ "supportLevel": "Stable", "groupId": "com.cefriel", "artifactId": "camel-chimera-mapping-template", - "version": "4.1.1", + "version": "4.1.2-SNAPSHOT", "scheme": "mapt", "extendsScheme": "", "syntax": "mapt:name", diff --git a/camel-chimera-rmlmapper/src/generated/resources/com/cefriel/component/rml.json b/camel-chimera-rmlmapper/src/generated/resources/com/cefriel/component/rml.json index 0600c07..7fc3d0f 100644 --- a/camel-chimera-rmlmapper/src/generated/resources/com/cefriel/component/rml.json +++ b/camel-chimera-rmlmapper/src/generated/resources/com/cefriel/component/rml.json @@ -11,7 +11,7 @@ "supportLevel": "Stable", "groupId": "com.cefriel", "artifactId": "camel-chimera-rmlmapper", - "version": "4.1.1", + "version": "4.1.2-SNAPSHOT", "scheme": "rml", "extendsScheme": "", "syntax": "rml:name", From 86e6993295b5ad559c5c1a4b2af7a1783e065443 Mon Sep 17 00:00:00 2001 From: Marco Grassi Date: Fri, 6 Sep 2024 12:06:31 +0200 Subject: [PATCH 3/3] fix: check when operation is given as parameter --- .../src/main/java/com/cefriel/component/GraphProducer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphProducer.java b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphProducer.java index 988a42e..21cbc54 100644 --- a/camel-chimera-graph/src/main/java/com/cefriel/component/GraphProducer.java +++ b/camel-chimera-graph/src/main/java/com/cefriel/component/GraphProducer.java @@ -53,7 +53,7 @@ public void process(Exchange exchange) throws Exception { } operationConfig.setEndpointParameters(endpoint); String operation; - if (endpoint.getName() == null && endpoint.getOperation() != null) + if (endpoint.getName().equals("") && endpoint.getOperation() != null) operation = endpoint.getOperation(); else if (endpoint.getName() != null && endpoint.getOperation() == null) operation = endpoint.getName();