Skip to content

Commit

Permalink
apache#2144 added migration for Plc4xModbusAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaakKrut committed Jan 8, 2024
1 parent 5c6e9b0 commit 0d0be23
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package org.apache.streampipes.extensions.connectors.plc.adapter.migration;

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.sdk.helpers.Labels;
import org.apache.streampipes.vocabulary.XSD;

import java.net.URI;

import static org.apache.streampipes.extensions.connectors.plc.adapter.modbus.Plc4xModbusAdapter.PLC_PORT;

public class Plc4xModbusAdapterMigrationV1 implements IAdapterMigrator {
@Override
public ModelMigratorConfig config() {
return new ModelMigratorConfig(
"org.apache.streampipes.connect.iiot.adapters.plc4x.modbus",
SpServiceTagPrefix.ADAPTER,
0,
1
);
}

@Override
public MigrationResult<AdapterDescription> migrate(AdapterDescription element, IStaticPropertyExtractor extractor) throws RuntimeException {
var newConfigs = element.getConfig().stream().map(config->{
if (isPortConfig(config)){
var label = Labels.withId(PLC_PORT);
return new FreeTextStaticProperty(label.getInternalId(),
label.getLabel(),
label.getDescription(),
XSD.INTEGER);
} else {
return config;
}
}).toList();
element.setConfig(newConfigs);

return MigrationResult.success(element);
}

private boolean isPortConfig(StaticProperty config) {
return config.getInternalName().equals(PLC_PORT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public class Plc4xModbusAdapter implements StreamPipesAdapter, IPullAdapter {
* Keys of user configuration parameters
*/
private static final String PLC_IP = "plc_ip";
private static final String PLC_PORT = "plc_port";
public static final String PLC_PORT = "plc_port";

private static final String PLC_NODES = "plc_nodes";
private static final String PLC_NODE_ID = "plc_node_id";
Expand Down Expand Up @@ -273,7 +273,7 @@ public PollingSettings getPollingInterval() {
*/
@Override
public IAdapterConfiguration declareConfig() {
return AdapterConfigurationBuilder.create(ID, 0, Plc4xModbusAdapter::new)
return AdapterConfigurationBuilder.create(ID, 1, Plc4xModbusAdapter::new)
.withLocales(Locales.EN)
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withCategory(AdapterType.Manufacturing)
Expand Down

0 comments on commit 0d0be23

Please sign in to comment.