You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@streampipes.apache.org by ze...@apache.org on 2020/05/28 07:57:02 UTC
[incubator-streampipes-extensions] branch dev updated: Added new
processor to transform boolean values into a state
This is an automated email from the ASF dual-hosted git repository.
zehnder pushed a commit to branch dev
in repository https://gitbox.apache.org/repos/asf/incubator-streampipes-extensions.git
The following commit(s) were added to refs/heads/dev by this push:
new a734d3f Added new processor to transform boolean values into a state
a734d3f is described below
commit a734d3f9a0f6c561e1d3e88d7e3987abadf4e930
Author: Philipp Zehnder <ze...@fzi.de>
AuthorDate: Thu May 28 09:56:27 2020 +0200
Added new processor to transform boolean values into a state
---
.../transformation/jvm/TransformationJvmInit.java | 2 +
.../booloperator/state/BooleanToState.java | 61 ++++++++++++++++
.../state/BooleanToStateController.java | 79 +++++++++++++++++++++
.../state/BooleanToStateParameters.java | 41 +++++++++++
.../documentation.md | 45 ++++++++++++
.../icon.png | Bin 0 -> 13037 bytes
.../strings.en | 23 ++++++
7 files changed, 251 insertions(+)
diff --git a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/TransformationJvmInit.java b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/TransformationJvmInit.java
index 9da848f..f0590b7 100644
--- a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/TransformationJvmInit.java
+++ b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/TransformationJvmInit.java
@@ -31,6 +31,7 @@ import org.apache.streampipes.processors.transformation.jvm.processor.array.coun
import org.apache.streampipes.processors.transformation.jvm.processor.array.split.SplitArrayController;
import org.apache.streampipes.processors.transformation.jvm.processor.booloperator.counter.BooleanCounterController;
import org.apache.streampipes.processors.transformation.jvm.processor.booloperator.inverter.BooleanInverterController;
+import org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state.BooleanToStateController;
import org.apache.streampipes.processors.transformation.jvm.processor.booloperator.timekeeping.BooleanTimekeepingController;
import org.apache.streampipes.processors.transformation.jvm.processor.booloperator.timer.BooleanTimerController;
import org.apache.streampipes.processors.transformation.jvm.processor.csvmetadata.CsvMetadataEnrichmentController;
@@ -61,6 +62,7 @@ public class TransformationJvmInit extends StandaloneModelSubmitter {
.add(new BooleanInverterController())
.add(new TransformToBooleanController())
.add(new StringTimerController())
+ .add(new BooleanToStateController())
.add(new StringCounterController());
DeclarersSingleton.getInstance().registerDataFormats(new JsonDataFormatFactory(),
diff --git a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/booloperator/state/BooleanToState.java b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/booloperator/state/BooleanToState.java
new file mode 100644
index 0000000..9f4207f
--- /dev/null
+++ b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/booloperator/state/BooleanToState.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state;
+
+import org.apache.streampipes.logging.api.Logger;
+import org.apache.streampipes.model.runtime.Event;
+import org.apache.streampipes.wrapper.context.EventProcessorRuntimeContext;
+import org.apache.streampipes.wrapper.routing.SpOutputCollector;
+import org.apache.streampipes.wrapper.runtime.EventProcessor;
+
+import java.util.ArrayList;
+import java.util.List;
+
+public class BooleanToState implements EventProcessor<BooleanToStateParameters> {
+
+ private static Logger LOG;
+
+ private List<String> stateFields;
+
+ @Override
+ public void onInvocation(BooleanToStateParameters booleanInverterParameters,
+ SpOutputCollector spOutputCollector,
+ EventProcessorRuntimeContext runtimeContext) {
+ LOG = booleanInverterParameters.getGraph().getLogger(BooleanToState.class);
+ this.stateFields = booleanInverterParameters.getStateFields();
+ }
+
+ @Override
+ public void onEvent(Event inputEvent, SpOutputCollector out) {
+ List<String> states = new ArrayList<>();
+
+ for (String stateField : stateFields) {
+ if (inputEvent.getFieldBySelector(stateField).getAsPrimitive().getAsBoolean().equals(true)) {
+ states.add(inputEvent.getFieldBySelector(stateField).getFieldNameIn());
+ }
+ }
+
+ inputEvent.addField(BooleanToStateController.RESULT_RUNTIME_NAME, states.toArray());
+ out.collect(inputEvent);
+ }
+
+ @Override
+ public void onDetach() {
+ }
+}
diff --git a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/booloperator/state/BooleanToStateController.java b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/booloperator/state/BooleanToStateController.java
new file mode 100644
index 0000000..2fd42e5
--- /dev/null
+++ b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/booloperator/state/BooleanToStateController.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state;
+
+import org.apache.streampipes.model.graph.DataProcessorDescription;
+import org.apache.streampipes.model.graph.DataProcessorInvocation;
+import org.apache.streampipes.model.schema.PropertyScope;
+import org.apache.streampipes.model.staticproperty.MappingPropertyUnary;
+import org.apache.streampipes.sdk.StaticProperties;
+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.sdk.utils.Assets;
+import org.apache.streampipes.vocabulary.SPSensor;
+import org.apache.streampipes.wrapper.standalone.ConfiguredEventProcessor;
+import org.apache.streampipes.wrapper.standalone.declarer.StandaloneEventProcessingDeclarer;
+
+import java.util.List;
+
+public class BooleanToStateController extends StandaloneEventProcessingDeclarer<BooleanToStateParameters> {
+
+ public static final String COLLECTION_ID = "collection-id";
+ public static final String GROUP_ID = "group-id";
+ public static final String STATE_NAME_ID = "state-name-id";
+ public static final String STATE_MAPPING_ID = "state-mapping-id";
+ public static final String STATE_RESULT_FIELD_ID = "state-result-field";
+ public static final String BOOLEAN_STATE_FIELD = "boolean_state_field";
+
+ public static final String RESULT_RUNTIME_NAME = "current_state";
+
+
+ @Override
+ public DataProcessorDescription declareModel() {
+ return ProcessingElementBuilder.create("org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state")
+ .withLocales(Locales.EN)
+ .withAssets(Assets.DOCUMENTATION, Assets.ICON)
+ .requiredStream(StreamRequirementsBuilder.create()
+ .requiredPropertyWithNaryMapping(EpRequirements.booleanReq(), Labels.withId(BOOLEAN_STATE_FIELD), PropertyScope.NONE)
+ .build())
+ // TODO UI does not render collections with group
+// .requiredParameterAsCollection(
+// Labels.withId(COLLECTION_ID),
+// StaticProperties.group(
+// Labels.withId(GROUP_ID),
+// StaticProperties.stringFreeTextProperty(Labels.withId(STATE_NAME_ID)),
+// StaticProperties.mappingPropertyUnary(Labels.withId(STATE_MAPPING_ID), PropertyScope.NONE)))
+ .outputStrategy(OutputStrategies.append(
+ EpProperties.listStringEp(Labels.withId(STATE_RESULT_FIELD_ID), RESULT_RUNTIME_NAME, SPSensor.STATE)
+ ))
+ .build();
+ }
+
+ @Override
+ public ConfiguredEventProcessor<BooleanToStateParameters> onInvocation(DataProcessorInvocation graph, ProcessingElementParameterExtractor extractor) {
+
+ List<String> stateFields = extractor.mappingPropertyValues(BOOLEAN_STATE_FIELD);
+
+ BooleanToStateParameters params = new BooleanToStateParameters(graph, stateFields);
+
+ return new ConfiguredEventProcessor<>(params, BooleanToState::new);
+ }
+}
diff --git a/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/booloperator/state/BooleanToStateParameters.java b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/booloperator/state/BooleanToStateParameters.java
new file mode 100644
index 0000000..63209e6
--- /dev/null
+++ b/streampipes-processors-transformation-jvm/src/main/java/org/apache/streampipes/processors/transformation/jvm/processor/booloperator/state/BooleanToStateParameters.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state;
+
+import org.apache.streampipes.model.graph.DataProcessorInvocation;
+import org.apache.streampipes.wrapper.params.binding.EventProcessorBindingParams;
+
+import java.util.List;
+
+public class BooleanToStateParameters extends EventProcessorBindingParams {
+ private List<String> stateFields;
+
+ public BooleanToStateParameters(DataProcessorInvocation graph, List<String> stateFields) {
+ super(graph);
+ this.stateFields = stateFields;
+ }
+
+ public List<String> getStateFields() {
+ return stateFields;
+ }
+
+ public void setStateFields(List<String> stateFields) {
+ this.stateFields = stateFields;
+ }
+}
diff --git a/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state/documentation.md b/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state/documentation.md
new file mode 100644
index 0000000..6328e29
--- /dev/null
+++ b/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state/documentation.md
@@ -0,0 +1,45 @@
+<!--
+ ~ Licensed to the Apache Software Foundation (ASF) under one or more
+ ~ contributor license agreements. See the NOTICE file distributed with
+ ~ this work for additional information regarding copyright ownership.
+ ~ The ASF licenses this file to You under the Apache License, Version 2.0
+ ~ (the "License"); you may not use this file except in compliance with
+ ~ the License. You may obtain a copy of the License at
+ ~
+ ~ http://www.apache.org/licenses/LICENSE-2.0
+ ~
+ ~ Unless required by applicable law or agreed to in writing, software
+ ~ distributed under the License is distributed on an "AS IS" BASIS,
+ ~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ ~ See the License for the specific language governing permissions and
+ ~ limitations under the License.
+ ~
+ -->
+
+## Boolean To State
+
+<p align="center">
+ <img src="icon.png" width="150px;" class="pe-image-documentation"/>
+</p>
+
+***
+
+## Description
+
+With this processors boolean values can be converted to a state field representing the current state of the system.
+This processor requires one or multiple boolean values in the data stream.
+For each of the selected values which are true, the runtime name is added to the states field.
+***
+
+## Required input
+
+### Boolean Fields
+Boolean fields that are converted to the state when true
+
+***
+
+## Configuration
+No further configuration required
+
+## Output
+The output contains a new value with the string values of the state
diff --git a/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state/icon.png b/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state/icon.png
new file mode 100644
index 0000000..bed5d6b
Binary files /dev/null and b/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state/icon.png differ
diff --git a/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state/strings.en b/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state/strings.en
new file mode 100644
index 0000000..82ee552
--- /dev/null
+++ b/streampipes-processors-transformation-jvm/src/main/resources/org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state/strings.en
@@ -0,0 +1,23 @@
+org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state.title=Boolean To State
+org.apache.streampipes.processors.transformation.jvm.processor.booloperator.state.description=Transforms boolean properties into a string state property
+
+state-field.title=State field
+state-field.description=Test
+
+collection-id.title=Collection Field
+collection-id.description=Test
+
+group-id.title=Group Field
+group-id.description=Test
+
+state-name-id.title=State Name
+state-name-id.description=Enter the name of the state
+
+state-mapping-id.title=State Mapping
+state-mapping-id.description=When boolean variable is true, the state is set to active
+
+state-result-field.title=Result Field
+state-result-field.description=Test
+
+boolean_state_field.title=Result Field
+boolean_state_field.description=Test