Skip to content

Commit

Permalink
checkstyle changes
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaakKrut committed Jan 8, 2024
1 parent db958a6 commit 803af51
Show file tree
Hide file tree
Showing 3 changed files with 168 additions and 102 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* 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;
Expand All @@ -16,34 +34,35 @@

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 newConfigs = element.getConfig().stream().map(config->{
if (isPortConfig(config)){
Label label = Labels.withId(ROS_PORT_KEY);
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(ROS_PORT_KEY);
}
@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 newConfigs = element.getConfig().stream().map(config->{
if (isPortConfig(config)){
Label label = Labels.withId(ROS_PORT_KEY);
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(ROS_PORT_KEY);
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* 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.extensions.connectors.opcua.migration;

import org.apache.streampipes.extensions.api.extractor.IStaticPropertyExtractor;
Expand All @@ -11,50 +29,60 @@
import org.apache.streampipes.sdk.helpers.Alternatives;
import org.apache.streampipes.sdk.helpers.Labels;

import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.*;
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.HOST_PORT;
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_HOST;
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_HOST_OR_URL;
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_SERVER_HOST;
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_SERVER_PORT;
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_SERVER_URL;
import static org.apache.streampipes.extensions.connectors.opcua.utils.OpcUaLabels.OPC_URL;




public class OpcUaAdapterMigrationV2 implements IAdapterMigrator {
@Override
public ModelMigratorConfig config() {
return new ModelMigratorConfig(
"org.apache.streampipes.connect.iiot.adapters.opcua",
SpServiceTagPrefix.ADAPTER,
1,
2);
}

@Override
public MigrationResult<AdapterDescription> migrate(AdapterDescription element, IStaticPropertyExtractor extractor) throws RuntimeException {
var newConfigs = element.getConfig().stream().map(config->{
if (isHostOrUrlConfig(config)){
return modifiedAlternatives();
} else {
return config;
}
}).toList();

element.setConfig(newConfigs);
return MigrationResult.success(element);
}

private StaticProperty modifiedAlternatives() {
return StaticProperties.alternatives(Labels.withId(OPC_HOST_OR_URL),
Alternatives.from(
Labels.withId(OPC_URL),
StaticProperties.stringFreeTextProperty(
Labels.withId(OPC_SERVER_URL), "opc.tcp://localhost:4840"))
,
Alternatives.from(Labels.withId(OPC_HOST),
StaticProperties.group(
Labels.withId(HOST_PORT),
StaticProperties.stringFreeTextProperty(
Labels.withId(OPC_SERVER_HOST)),
StaticProperties.integerFreeTextProperty(
Labels.withId(OPC_SERVER_PORT))
)));
}

private boolean isHostOrUrlConfig(StaticProperty config){
return config.getInternalName().equals(OPC_HOST_OR_URL.name());
}
@Override
public ModelMigratorConfig config() {
return new ModelMigratorConfig(
"org.apache.streampipes.connect.iiot.adapters.opcua",
SpServiceTagPrefix.ADAPTER,
1,
2);
}

@Override
public MigrationResult<AdapterDescription> migrate(AdapterDescription element,
IStaticPropertyExtractor extractor) throws RuntimeException {
var newConfigs = element.getConfig().stream().map(config->{
if (isHostOrUrlConfig(config)){
return modifiedAlternatives();
} else {
return config;
}
}).toList();

element.setConfig(newConfigs);
return MigrationResult.success(element);
}

private StaticProperty modifiedAlternatives() {
return StaticProperties.alternatives(Labels.withId(OPC_HOST_OR_URL),
Alternatives.from(
Labels.withId(OPC_URL),
StaticProperties.stringFreeTextProperty(
Labels.withId(OPC_SERVER_URL), "opc.tcp://localhost:4840"))
,
Alternatives.from(Labels.withId(OPC_HOST),
StaticProperties.group(
Labels.withId(HOST_PORT),
StaticProperties.stringFreeTextProperty(
Labels.withId(OPC_SERVER_HOST)),
StaticProperties.integerFreeTextProperty(
Labels.withId(OPC_SERVER_PORT))
)));
}

private boolean isHostOrUrlConfig(StaticProperty config){
return config.getInternalName().equals(OPC_HOST_OR_URL.name());
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* 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.extensions.connectors.plc.adapter.migration;

import org.apache.streampipes.extensions.api.extractor.IStaticPropertyExtractor;
Expand All @@ -14,35 +32,36 @@
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 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);
@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);
}
return MigrationResult.success(element);
}

private boolean isPortConfig(StaticProperty config) {
return config.getInternalName().equals(PLC_PORT);
}
private boolean isPortConfig(StaticProperty config) {
return config.getInternalName().equals(PLC_PORT);
}
}

0 comments on commit 803af51

Please sign in to comment.