You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ri...@apache.org on 2020/05/18 21:29:21 UTC

[incubator-streampipes-examples] branch dev updated: [STREAMPIPES-133] Add example for CodeInputStaticProperty

This is an automated email from the ASF dual-hosted git repository.

riemer pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-examples.git


The following commit(s) were added to refs/heads/dev by this push:
     new 101b9ba  [STREAMPIPES-133] Add example for CodeInputStaticProperty
101b9ba is described below

commit 101b9ba31e8991ce5b9656c7952d4a70aafebfbe
Author: Dominik Riemer <ri...@fzi.de>
AuthorDate: Mon May 18 23:28:22 2020 +0200

    [STREAMPIPES-133] Add example for CodeInputStaticProperty
---
 pom.xml                                            |  6 +--
 .../pom.xml                                        |  2 +-
 .../streampipes/pe/examples/jvm/ExamplesInit.java  | 13 +-----
 .../staticproperty/CodeInputExampleController.java | 47 ++++++++++++++++++++++
 4 files changed, 53 insertions(+), 15 deletions(-)

diff --git a/pom.xml b/pom.xml
index 68c5ed8..c66b0e5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -25,18 +25,18 @@
     <parent>
         <groupId>org.apache.streampipes</groupId>
         <artifactId>streampipes-parent</artifactId>
-        <version>0.65.1-SNAPSHOT</version>
+        <version>0.67.0-SNAPSHOT</version>
     </parent>
 
     <artifactId>streampipes-pipeline-elements-examples</artifactId>
     <packaging>pom</packaging>
-    <version>0.65.1-SNAPSHOT</version>
+    <version>0.67.0-SNAPSHOT</version>
     <modules>
         <module>streampipes-pipeline-elements-examples-processors-jvm</module>
     </modules>
 
     <properties>
-        <streampipes.version>0.65.1-SNAPSHOT</streampipes.version>
+        <streampipes.version>0.67.0-SNAPSHOT</streampipes.version>
         <lightcouch.version>0.1.8</lightcouch.version>
 
         <maven-shade-plugin.version>3.0.0</maven-shade-plugin.version>
diff --git a/streampipes-pipeline-elements-examples-processors-jvm/pom.xml b/streampipes-pipeline-elements-examples-processors-jvm/pom.xml
index 1f2d908..4593856 100644
--- a/streampipes-pipeline-elements-examples-processors-jvm/pom.xml
+++ b/streampipes-pipeline-elements-examples-processors-jvm/pom.xml
@@ -23,7 +23,7 @@
     <parent>
         <artifactId>streampipes-pipeline-elements-examples</artifactId>
         <groupId>org.apache.streampipes</groupId>
-        <version>0.65.1-SNAPSHOT</version>
+        <version>0.67.0-SNAPSHOT</version>
     </parent>
     <modelVersion>4.0.0</modelVersion>
 
diff --git a/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/apache/streampipes/pe/examples/jvm/ExamplesInit.java b/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/apache/streampipes/pe/examples/jvm/ExamplesInit.java
index 8fb9487..6a6550c 100644
--- a/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/apache/streampipes/pe/examples/jvm/ExamplesInit.java
+++ b/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/apache/streampipes/pe/examples/jvm/ExamplesInit.java
@@ -30,17 +30,7 @@ import org.apache.streampipes.pe.examples.jvm.outputstrategy.CustomTransformOutp
 import org.apache.streampipes.pe.examples.jvm.outputstrategy.FixedOutputController;
 import org.apache.streampipes.pe.examples.jvm.outputstrategy.KeepOutputController;
 import org.apache.streampipes.pe.examples.jvm.outputstrategy.TransformOutputController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.CollectionExampleController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.MultiValueSelectionExampleController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.NaryMappingPropertyExampleController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.NumberParameterExampleController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.NumberParameterWithRangeExampleController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.RuntimeResolvableSingleValue;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.SecretStaticPropertyExampleController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.SingleValueSelectionExampleController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.StaticPropertyAlternativesController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.TextParameterExampleController;
-import org.apache.streampipes.pe.examples.jvm.staticproperty.UnaryMappingPropertyExampleController;
+import org.apache.streampipes.pe.examples.jvm.staticproperty.*;
 
 public class ExamplesInit extends StandaloneModelSubmitter {
 
@@ -58,6 +48,7 @@ public class ExamplesInit extends StandaloneModelSubmitter {
             .add(new RuntimeResolvableSingleValue())
             .add(new StaticPropertyAlternativesController())
             .add(new SecretStaticPropertyExampleController())
+            .add(new CodeInputExampleController())
 
             .add(new AppendOutputController())
             .add(new CustomOutputController())
diff --git a/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/apache/streampipes/pe/examples/jvm/staticproperty/CodeInputExampleController.java b/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/apache/streampipes/pe/examples/jvm/staticproperty/CodeInputExampleController.java
new file mode 100644
index 0000000..447bd9c
--- /dev/null
+++ b/streampipes-pipeline-elements-examples-processors-jvm/src/main/java/org/apache/streampipes/pe/examples/jvm/staticproperty/CodeInputExampleController.java
@@ -0,0 +1,47 @@
+package org.apache.streampipes.pe.examples.jvm.staticproperty;
+
+import org.apache.streampipes.model.graph.DataProcessorDescription;
+import org.apache.streampipes.model.graph.DataProcessorInvocation;
+import org.apache.streampipes.pe.examples.jvm.base.DummyEngine;
+import org.apache.streampipes.pe.examples.jvm.base.DummyParameters;
+import org.apache.streampipes.sdk.builder.ProcessingElementBuilder;
+import org.apache.streampipes.sdk.builder.StreamRequirementsBuilder;
+import org.apache.streampipes.sdk.extractor.ProcessingElementParameterExtractor;
+import org.apache.streampipes.sdk.helpers.*;
+import org.apache.streampipes.wrapper.standalone.ConfiguredEventProcessor;
+import org.apache.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;
+
+public class CodeInputExampleController extends StandaloneEventProcessingDeclarer<DummyParameters> {
+
+  private static final String CODE_KEY = "code-key";
+
+  @Override
+  public DataProcessorDescription declareModel() {
+    return ProcessingElementBuilder.create("org.apache.streampipes.examples.staticproperty" +
+            ".codeinput", "Code Input Example", "")
+            .requiredStream(StreamRequirementsBuilder.
+                    create()
+                    .requiredProperty(EpRequirements.anyProperty())
+                    .build())
+            .outputStrategy(OutputStrategies.keep())
+            .supportedProtocols(SupportedProtocols.kafka())
+            .supportedFormats(SupportedFormats.jsonFormat())
+
+            // create a required code block
+            .requiredCodeblock(Labels.from(CODE_KEY, "Code", ""), CodeLanguage.Javascript)
+
+            .build();
+  }
+
+  @Override
+  public ConfiguredEventProcessor<DummyParameters> onInvocation(DataProcessorInvocation graph, ProcessingElementParameterExtractor extractor) {
+
+    // Extract the code parameter value
+    String code = extractor.codeblockValue(CODE_KEY);
+
+    // now the text parameter would be added to a parameter class (omitted for this example)
+
+    return new ConfiguredEventProcessor<>(new DummyParameters(graph), DummyEngine::new);
+  }
+}
+