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

#2144 Enhance Static Properties by UI validation V2 #2443

Merged
merged 23 commits into from
Mar 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
5c6e9b0
#2144 updated port number fields to Integer type for ui validation
IsaakKrut Jan 7, 2024
58dec0e
Merge branch 'apache:dev' into dev
IsaakKrut Jan 7, 2024
0d0be23
#2144 added migration for Plc4xModbusAdapter
IsaakKrut Jan 8, 2024
4b51b3c
#2144 added migration for Plc4xModbusAdapter
IsaakKrut Jan 8, 2024
f227991
#2144 added migration V2 for OpcUaAdapter
IsaakKrut Jan 8, 2024
eb3014a
#2144 added migration V2 for OpcUaAdapter
IsaakKrut Jan 8, 2024
fb609d9
#2144 added migration for RosBridgeAdapter
IsaakKrut Jan 8, 2024
db958a6
Merge remote-tracking branch 'origin/dev' into dev
IsaakKrut Jan 8, 2024
803af51
checkstyle changes
IsaakKrut Jan 8, 2024
28a522e
#2144 Added migration test for Plc4xModbusAdapter
IsaakKrut Jan 9, 2024
cc9769b
#2144 Added migration test for RosBridgeAdapter
IsaakKrut Jan 17, 2024
8b1ade9
#2144 Added migration test for OpcUaAdapterMigrationV2
IsaakKrut Jan 17, 2024
af2f621
fix(#2144): Fix label generation for migrated elements
tenthe Jan 29, 2024
246b73e
fix(#2144): Set default static property values for adapter instance
tenthe Jan 29, 2024
19ade2b
fix(#2144): Set default static property values for adapter instance
tenthe Jan 29, 2024
c84125b
Updated OpcUaAdapterMigrationTest (#2454)
IsaakKrut Mar 4, 2024
73f6333
Merge branch 'dev' into fork/dev
tenthe Mar 4, 2024
9cec95f
fix(#2144): Rename test for opc migration v2
tenthe Mar 4, 2024
b0d8768
fix(#2144): Add methods to provide default if not set by user
tenthe Mar 4, 2024
484f7b3
fix(#2144): Change logic of opc ua migration
tenthe Mar 4, 2024
fb345ea
fix(#2144): Update modbus adapater migration
tenthe Mar 4, 2024
2fc3be7
fix(#2144): Update ros bridge adapter migration
tenthe Mar 4, 2024
de07528
fix(#2144): Change default value of replaceTitles
tenthe Mar 5, 2024
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
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
Loading