forked from apache/streampipes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
apache#2144 added migration for Plc4xModbusAdapter
- Loading branch information
Showing
2 changed files
with
52 additions
and
2 deletions.
There are no files selected for viewing
50 changes: 50 additions & 0 deletions
50
...treampipes/extensions/connectors/plc/adapter/migration/Plc4xModbusAdapterMigrationV1.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters