Skip to content

Commit

Permalink
[#1289] Fix AdapterConfigurationBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
tenthe committed Apr 6, 2023
1 parent dcf1357 commit 72abf64
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import org.apache.streampipes.model.connect.guess.AdapterGuessInfo;
import org.apache.streampipes.sdk.StaticProperties;
import org.apache.streampipes.sdk.builder.adapter.AdapterConfigurationBuilder;
import org.apache.streampipes.sdk.builder.adapter.AdapterDescriptionBuilder;
import org.apache.streampipes.sdk.builder.adapter.CsvParser;
import org.apache.streampipes.sdk.builder.adapter.JsonParser;
import org.apache.streampipes.sdk.extractor.AdapterParameterExtractor;
Expand Down Expand Up @@ -59,21 +58,19 @@ public class FileReplayAdapter implements AdapterInterface {

@Override
public AdapterConfiguration declareConfig() {
return AdapterConfigurationBuilder.create().withSupportedParsers(new JsonParser(), new CsvParser())
// TODO write new builder
.withAdapterDescription(
AdapterDescriptionBuilder.create("org.apache.streampipes.connect.iiot.adapters.simulator.machine.v2")
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withLocales(Locales.EN)
.category(AdapterType.Generic)
.requiredFile(Labels.withId(FILE_PATH), Filetypes.CSV, Filetypes.JSON, Filetypes.XML)
.requiredMultiValueSelection(Labels.withId(REPLACE_TIMESTAMP), Options.from(""))
.requiredSingleValueSelection(Labels.withId(REPLAY_ONCE), Options.from("no", "yes"))
.requiredAlternatives(Labels.withId(SPEED),
Alternatives.from(Labels.withId(KEEP_ORIGINAL_TIME), true),
Alternatives.from(Labels.withId(FASTEST)), Alternatives.from(Labels.withId(SPEED_UP_FACTOR),
StaticProperties.group(Labels.withId(SPEED_UP_FACTOR_GROUP),
StaticProperties.doubleFreeTextProperty(Labels.withId(SPEED_UP))))).build())
return AdapterConfigurationBuilder.create("org.apache.streampipes.connect.iiot.adapters.simulator.machine.v2")
.withSupportedParsers(new JsonParser(), new CsvParser())
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withLocales(Locales.EN)
.withCategory(AdapterType.Generic)
.requiredFile(Labels.withId(FILE_PATH), Filetypes.CSV, Filetypes.JSON, Filetypes.XML)
.requiredMultiValueSelection(Labels.withId(REPLACE_TIMESTAMP), Options.from(""))
.requiredSingleValueSelection(Labels.withId(REPLAY_ONCE), Options.from("no", "yes"))
.requiredAlternatives(Labels.withId(SPEED),
Alternatives.from(Labels.withId(KEEP_ORIGINAL_TIME), true),
Alternatives.from(Labels.withId(FASTEST)), Alternatives.from(Labels.withId(SPEED_UP_FACTOR),
StaticProperties.group(Labels.withId(SPEED_UP_FACTOR_GROUP),
StaticProperties.doubleFreeTextProperty(Labels.withId(SPEED_UP)))))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.apache.streampipes.model.connect.adapter.IEventCollector;
import org.apache.streampipes.model.connect.guess.AdapterGuessInfo;
import org.apache.streampipes.sdk.builder.adapter.AdapterConfigurationBuilder;
import org.apache.streampipes.sdk.builder.adapter.AdapterDescriptionBuilder;
import org.apache.streampipes.sdk.extractor.AdapterParameterExtractor;
import org.apache.streampipes.sdk.helpers.Labels;
import org.apache.streampipes.sdk.helpers.Locales;
Expand All @@ -62,19 +61,13 @@ public class NewMachineDataSimulatorAdapter implements AdapterInterface {

@Override
public AdapterConfiguration declareConfig() {
return AdapterConfigurationBuilder.create()

// TODO write new builder
.withAdapterDescription(
AdapterDescriptionBuilder
.create("org.apache.streampipes.connect.iiot.adapters.simulator.machine.v2")
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withLocales(Locales.EN)
.category(AdapterType.Debugging)
.requiredIntegerParameter(Labels.withId(WAIT_TIME_MS), 1000)
.requiredSingleValueSelection(Labels.withId(SELECTED_SIMULATOR_OPTION), Options.from(
"flowrate", "pressure", "waterlevel"))
.build())
return AdapterConfigurationBuilder.create("org.apache.streampipes.connect.iiot.adapters.simulator.machine.v2")
.withAssets(Assets.DOCUMENTATION, Assets.ICON)
.withLocales(Locales.EN)
.withCategory(AdapterType.Debugging)
.requiredIntegerParameter(Labels.withId(WAIT_TIME_MS), 1000)
.requiredSingleValueSelection(Labels.withId(SELECTED_SIMULATOR_OPTION), Options.from(
"flowrate", "pressure", "waterlevel"))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,22 @@

package org.apache.streampipes.sdk.builder.adapter;

import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.AdapterConfiguration;
import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.model.connect.adapter.Parser;
import org.apache.streampipes.sdk.builder.AbstractConfigurablePipelineElementBuilder;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

public class AdapterConfigurationBuilder extends
AbstractConfigurablePipelineElementBuilder<AdapterConfigurationBuilder, AdapterConfiguration> {

private AdapterDescription adapterDescription;
private final AdapterDescription adapterDescription;
private final List<Parser> supportedParsers;

protected AdapterConfigurationBuilder(String appId) {
Expand Down Expand Up @@ -64,9 +67,14 @@ public AdapterConfigurationBuilder withSupportedParsers(Parser... parsers) {
return this;
}


public AdapterConfigurationBuilder withAdapterDescription(AdapterDescription adapterDescription) {
this.adapterDescription = adapterDescription;
return this;
public AdapterConfigurationBuilder withCategory(AdapterType... categories) {
this.adapterDescription
.setCategory(Arrays
.stream(categories)
.map(Enum::name)
.collect(Collectors.toList()));
return me();
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.streampipes.sdk.builder.adapter;


import org.apache.streampipes.model.AdapterType;
import org.apache.streampipes.model.connect.adapter.AdapterDescription;
import org.apache.streampipes.model.connect.adapter.Parser;

Expand All @@ -41,6 +42,7 @@ public void create() {

assertNotNull(adapterConfiguration);
assertEquals(id, adapterConfiguration.getAdapterDescription().getAppId());
assertEquals(new AdapterDescription(), adapterConfiguration.getAdapterDescription());
}

@Test
Expand Down Expand Up @@ -80,15 +82,17 @@ public void withMultipleParserInTwoCall() {
}

@Test
public void withAdapterDescription() {
var expected = new AdapterDescription();

public void withCategory() {
var adapterConfiguration = AdapterConfigurationBuilder
.create(id)
.withAdapterDescription(expected)
.withCategory(AdapterType.Manufacturing)
.build();

assertEquals(expected, adapterConfiguration.getAdapterDescription());
var actual = adapterConfiguration.getAdapterDescription().getCategory();

assertEquals(1, actual.size());
assertEquals(AdapterType.Manufacturing.getCode(), actual.get(0));
}


}

0 comments on commit 72abf64

Please sign in to comment.