Skip to content

Commit

Permalink
#2144 Enhance Static Properties by UI validation V2 (#2443)
Browse files Browse the repository at this point in the history
* #2144 updated port number fields to Integer type for ui validation

* #2144 added migration for Plc4xModbusAdapter

* #2144 added migration for Plc4xModbusAdapter

* #2144 added migration V2 for OpcUaAdapter

* #2144 added migration V2 for OpcUaAdapter

* #2144 added migration for RosBridgeAdapter

* checkstyle changes

* #2144 Added migration test for Plc4xModbusAdapter

* #2144 Added migration test for RosBridgeAdapter

* #2144 Added migration test for OpcUaAdapterMigrationV2

* fix(#2144): Fix label generation for migrated elements

* fix(#2144): Set default static property values for adapter instance

* fix(#2144): Set default static property values for adapter instance

* Updated OpcUaAdapterMigrationTest (#2454)

* fix(#2144): Rename test for opc migration v2

* fix(#2144): Add methods to provide default if not set by user

* fix(#2144): Change logic of opc ua migration

* fix(#2144): Update modbus adapater migration

* fix(#2144): Update ros bridge adapter migration

* fix(#2144): Change default value of replaceTitles

---------

Co-authored-by: Isaak <krutisaak099@gmail.com>
  • Loading branch information
tenthe and IsaakKrut authored Mar 6, 2024
1 parent 0035d12 commit 9cf1473
Show file tree
Hide file tree
Showing 26 changed files with 969 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,25 @@ public class LabelGenerator<T extends NamedStreamPipesEntity> {

private T desc;

public LabelGenerator(T desc) {
private boolean replaceTitles;

public LabelGenerator(T desc, boolean replaceTitles) {
this.desc = desc;
this.replaceTitles = replaceTitles;
}

public LabelGenerator(T desc) {
this(desc, true);
}

public T generateLabels() throws IOException {
if (existsLocalesFile()) {
Properties props = laodResourceAndMakeProperties();
desc.setName(getTitle(props, desc.getAppId()));
desc.setDescription(getDescription(props, desc.getAppId()));

if (replaceTitles) {
desc.setName(getTitle(props, desc.getAppId()));
desc.setDescription(getDescription(props, desc.getAppId()));
}

if (isAdapter()) {
((AdapterDescription) desc).getConfig()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.streampipes.connect.iiot;

import org.apache.streampipes.connect.iiot.adapters.iolink.IfmAlMqttAdapter;
import org.apache.streampipes.connect.iiot.adapters.migrations.RosBridgeAdapterMigrationV1;
import org.apache.streampipes.connect.iiot.adapters.ros.RosBridgeAdapter;
import org.apache.streampipes.connect.iiot.adapters.simulator.machine.MachineDataSimulatorAdapter;
import org.apache.streampipes.connect.iiot.protocol.stream.FileReplayAdapter;
Expand Down Expand Up @@ -52,6 +53,8 @@ public List<IStreamPipesPipelineElement<?>> pipelineElements() {

@Override
public List<IModelMigrator<?, ?>> migrators() {
return Collections.emptyList();
return List.of(
new RosBridgeAdapterMigrationV1()
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.connect.iiot.adapters.migrations;

import org.apache.streampipes.extensions.api.extractor.IStaticPropertyExtractor;
import org.apache.streampipes.extensions.api.migration.IAdapterMigrator;
import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.model.extensions.svcdiscovery.SpServiceTagPrefix;
import org.apache.streampipes.model.migration.MigrationResult;
import org.apache.streampipes.model.migration.ModelMigratorConfig;
import org.apache.streampipes.model.staticproperty.FreeTextStaticProperty;
import org.apache.streampipes.model.staticproperty.StaticProperty;
import org.apache.streampipes.vocabulary.XSD;

import static org.apache.streampipes.connect.iiot.adapters.ros.RosBridgeAdapter.ROS_PORT_KEY;

public class RosBridgeAdapterMigrationV1 implements IAdapterMigrator {

@Override
public ModelMigratorConfig config() {
return new ModelMigratorConfig(
"org.apache.streampipes.connect.iiot.adapters.ros",
SpServiceTagPrefix.ADAPTER,
0,
1);
}

@Override
public MigrationResult<AdapterDescription> migrate(AdapterDescription element,
IStaticPropertyExtractor extractor) throws RuntimeException {

var portProperty = extractPortProperty(element);
portProperty.setRequiredDatatype(XSD.INTEGER);

return MigrationResult.success(element);
}

protected FreeTextStaticProperty extractPortProperty(AdapterDescription adapterDescription) {
return (FreeTextStaticProperty) adapterDescription.getConfig().stream()
.filter(this::isPortConfig)
.findFirst()
.orElseThrow();
}

private boolean isPortConfig(StaticProperty config) {
return config.getInternalName().equals(ROS_PORT_KEY);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ public class RosBridgeAdapter implements StreamPipesAdapter, ResolvesContainerPr

public static final String ID = "org.apache.streampipes.connect.iiot.adapters.ros";

private static final String ROS_HOST_KEY = "ROS_HOST_KEY";
private static final String ROS_PORT_KEY = "ROS_PORT_KEY";
private static final String TOPIC_KEY = "TOPIC_KEY";
public static final String ROS_HOST_KEY = "ROS_HOST_KEY";
public static final String ROS_PORT_KEY = "ROS_PORT_KEY";
public static final String TOPIC_KEY = "TOPIC_KEY";

private String topic;
private String host;
Expand Down Expand Up @@ -92,12 +92,12 @@ public List<Option> resolveOptions(String requestId,

@Override
public IAdapterConfiguration declareConfig() {
return AdapterConfigurationBuilder.create(ID, 0, RosBridgeAdapter::new)
return AdapterConfigurationBuilder.create(ID, 1, RosBridgeAdapter::new)
.withLocales(Locales.EN)
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withCategory(AdapterType.Manufacturing)
.requiredTextParameter(Labels.withId(ROS_HOST_KEY))
.requiredTextParameter(Labels.withId(ROS_PORT_KEY))
.requiredIntegerParameter(Labels.withId(ROS_PORT_KEY))
.requiredSingleValueSelectionFromContainer(
Labels.withId(TOPIC_KEY), Arrays.asList(ROS_HOST_KEY, ROS_PORT_KEY))
.buildConfiguration();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.connect.iiot.adapters.migrations;

import org.apache.streampipes.connect.iiot.adapters.migrations.config.RosBridgeAdapterVersionedConfig;
import org.apache.streampipes.extensions.api.extractor.IStaticPropertyExtractor;
import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.vocabulary.XSD;

import org.junit.Before;
import org.junit.Test;

import java.net.URI;

import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;


public class RosBridgeAdapterMigrationV1Test {

private RosBridgeAdapterMigrationV1 migrationV1;

@Before
public void setUp() {
migrationV1 = new RosBridgeAdapterMigrationV1();
}

@Test
public void testMigrationV1(){
var rosBridgeAdapterDescriptionV0 = RosBridgeAdapterVersionedConfig.getRosBridgeAdapterDescriptionV0();
var extractorMock = mock(IStaticPropertyExtractor.class);

var rosBridgeAdapterDescriptionV1 = migrationV1.migrate(rosBridgeAdapterDescriptionV0 , extractorMock);

var typeOfPortProperty = getTypeOfPortProperty(rosBridgeAdapterDescriptionV1.element());
assertEquals(XSD.INTEGER, typeOfPortProperty);
}

private URI getTypeOfPortProperty(AdapterDescription adapterDescription) {
return migrationV1
.extractPortProperty(adapterDescription)
.getRequiredDatatype();
}

}
Original file line number Diff line number Diff line change
@@ -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.connect.iiot.adapters.migrations.config;

import org.apache.streampipes.connect.iiot.adapters.ros.RosBridgeAdapter;
import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.sdk.builder.adapter.AdapterConfigurationBuilder;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
import org.apache.streampipes.sdk.utils.Assets;

import java.util.Arrays;

import static org.apache.streampipes.connect.iiot.adapters.ros.RosBridgeAdapter.ID;
import static org.apache.streampipes.connect.iiot.adapters.ros.RosBridgeAdapter.ROS_HOST_KEY;
import static org.apache.streampipes.connect.iiot.adapters.ros.RosBridgeAdapter.ROS_PORT_KEY;
import static org.apache.streampipes.connect.iiot.adapters.ros.RosBridgeAdapter.TOPIC_KEY;

public class RosBridgeAdapterVersionedConfig {

public static AdapterDescription getRosBridgeAdapterDescriptionV0(){
return AdapterConfigurationBuilder.create(ID, 0, RosBridgeAdapter::new)
.withLocales(Locales.EN)
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withCategory(AdapterType.Manufacturing)
.requiredTextParameter(Labels.withId(ROS_HOST_KEY))
.requiredTextParameter(Labels.withId(ROS_PORT_KEY))
.requiredSingleValueSelectionFromContainer(
Labels.withId(TOPIC_KEY), Arrays.asList(ROS_HOST_KEY, ROS_PORT_KEY))
.buildConfiguration().getAdapterDescription();
}

public static AdapterDescription getRosBridgeAdapterDescriptionV1(){
return AdapterConfigurationBuilder.create(ID, 1, RosBridgeAdapter::new)
.withLocales(Locales.EN)
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withCategory(AdapterType.Manufacturing)
.requiredTextParameter(Labels.withId(ROS_HOST_KEY))
.requiredIntegerParameter(Labels.withId(ROS_PORT_KEY))
.requiredSingleValueSelectionFromContainer(
Labels.withId(TOPIC_KEY), Arrays.asList(ROS_HOST_KEY, ROS_PORT_KEY))
.buildConfiguration().getAdapterDescription();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.apache.streampipes.extensions.api.pe.IStreamPipesPipelineElement;
import org.apache.streampipes.extensions.connectors.opcua.adapter.OpcUaAdapter;
import org.apache.streampipes.extensions.connectors.opcua.migration.OpcUaAdapterMigrationV1;
import org.apache.streampipes.extensions.connectors.opcua.migration.OpcUaAdapterMigrationV2;
import org.apache.streampipes.extensions.connectors.opcua.sink.OpcUaSink;

import java.util.List;
Expand All @@ -46,7 +47,8 @@ public List<IStreamPipesPipelineElement<?>> pipelineElements() {
@Override
public List<IModelMigrator<?, ?>> migrators() {
return List.of(
new OpcUaAdapterMigrationV1()
new OpcUaAdapterMigrationV1(),
new OpcUaAdapterMigrationV2()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ public StaticProperty resolveConfiguration(String staticPropertyInternalName,

@Override
public IAdapterConfiguration declareConfig() {
var builder = AdapterConfigurationBuilder.create(ID, 1, OpcUaAdapter::new)
var builder = AdapterConfigurationBuilder.create(ID, 2, OpcUaAdapter::new)
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withLocales(Locales.EN)
.withCategory(AdapterType.Generic, AdapterType.Manufacturing)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public static void appendSharedOpcUaConfig(AbstractConfigurablePipelineElementBu
Labels.withId(HOST_PORT),
StaticProperties.stringFreeTextProperty(
Labels.withId(OPC_SERVER_HOST)),
StaticProperties.stringFreeTextProperty(
StaticProperties.integerFreeTextProperty(
Labels.withId(OPC_SERVER_PORT))
))
)
Expand Down
Loading

0 comments on commit 9cf1473

Please sign in to comment.