Skip to content

Commit

Permalink
Rename field SdmxWebSource#name as SdmxWebSource#id
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Feb 3, 2023
1 parent 911242d commit 9d720f8
Show file tree
Hide file tree
Showing 58 changed files with 252 additions and 198 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- ![API] Rename field `Dimension#label` as `Dimension#name`
- ![API] Rename field `Attribute#label` as `Attribute#name`
- ![API] Rename field `DataStructure#label` as `DataStructure#name`
- ![API] Rename field `SdmxWebSource#name` as `SdmxWebSource#id`
- ![API] Set field `Dataflow#description` as optional
- ![FORMAT] Improve parsing of time formats
- ![FORMAT] Rename module `sdmx-dl-format-util ` as `smdx-dl-format-base`
Expand Down
4 changes: 2 additions & 2 deletions sdmx-dl-api/src/main/java/sdmxdl/web/SdmxWebManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,14 +199,14 @@ private static List<SdmxWebSource> initDefaultSources(List<WebDriver> drivers) {
return drivers
.stream()
.flatMap(driver -> driver.getDefaultSources().stream())
.filter(distinctByKey(SdmxWebSource::getName))
.filter(distinctByKey(SdmxWebSource::getId))
.collect(Collectors.toList());
}

private static SortedMap<String, SdmxWebSource> initSourceMap(List<SdmxWebSource> customSources, List<SdmxWebSource> defaultSources) {
return Stream.concat(customSources.stream(), defaultSources.stream())
.flatMap(SdmxWebManager::expandAliases)
.collect(Collectors.groupingBy(SdmxWebSource::getName, TreeMap::new, reducingByFirst()));
.collect(Collectors.groupingBy(SdmxWebSource::getId, TreeMap::new, reducingByFirst()));
}

private static Stream<SdmxWebSource> expandAliases(SdmxWebSource source) {
Expand Down
16 changes: 6 additions & 10 deletions sdmx-dl-api/src/main/java/sdmxdl/web/SdmxWebSource.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
public class SdmxWebSource extends SdmxSource {

@lombok.NonNull
String name;
String id;

@lombok.Singular
Map<String, String> descriptions;
Expand Down Expand Up @@ -68,19 +68,15 @@ public class SdmxWebSource extends SdmxSource {
URL monitorWebsite = null;

@NonNull
public SdmxWebSource alias(@NonNull String name) throws IllegalArgumentException {
if (!aliases.contains(name)) {
throw new IllegalArgumentException(name);
public SdmxWebSource alias(@NonNull String id) throws IllegalArgumentException {
if (!aliases.contains(id)) {
throw new IllegalArgumentException(id);
}
return toBuilder().name(name).build();
return toBuilder().id(id).build();
}

public boolean isAlias() {
return aliases.contains(name);
}

public @NonNull String getId() {
return getDriver() + ":" + getName();
return aliases.contains(id);
}

public @Nullable String getDescription(@NonNull LanguagePriorityList langs) {
Expand Down
2 changes: 1 addition & 1 deletion sdmx-dl-api/src/test/java/_test/sdmxdl/TestDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -138,5 +138,5 @@ public boolean isAvailable() {
}
};

public static final SdmxWebSource SOURCE = SdmxWebSource.builder().name("123").driver("456").dialect(SDMX21_DIALECT).endpointOf("http://localhost").build();
public static final SdmxWebSource SOURCE = SdmxWebSource.builder().id("123").driver("456").dialect(SDMX21_DIALECT).endpointOf("http://localhost").build();
}
34 changes: 17 additions & 17 deletions sdmx-dl-api/src/test/java/sdmxdl/web/SdmxWebManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,9 @@ public void testFactories() {

@Test
public void testGetSources() {
SdmxWebSource nbb = SdmxWebSource.builder().name("nbb").alias("bnb").driver("sdmx21").endpointOf("http://nbb").build();
SdmxWebSource ecb = SdmxWebSource.builder().name("ecb").driver("sdmx21").endpointOf("http://ecb").build();
SdmxWebSource abs = SdmxWebSource.builder().name("abs").driver("sdmx21").endpointOf("http://abs").build();
SdmxWebSource nbb = SdmxWebSource.builder().id("nbb").alias("bnb").driver("sdmx21").endpointOf("http://nbb").build();
SdmxWebSource ecb = SdmxWebSource.builder().id("ecb").driver("sdmx21").endpointOf("http://ecb").build();
SdmxWebSource abs = SdmxWebSource.builder().id("abs").driver("sdmx21").endpointOf("http://abs").build();

SdmxWebSource nbbAlias = nbb.alias("bnb");
SdmxWebSource nbbDialect = nbb.toBuilder().dialect("custom").clearAliases().build();
Expand Down Expand Up @@ -172,12 +172,12 @@ public void testGetSources() {

@Test
public void testGetDefaultSources() {
SdmxWebSource source1a = SdmxWebSource.builder().name("s1").driver("dX").endpointOf("http://abc").build();
SdmxWebSource source2 = SdmxWebSource.builder().name("s2").driver("dX").endpointOf("http://abc").build();
SdmxWebSource source1a = SdmxWebSource.builder().id("s1").driver("dX").endpointOf("http://abc").build();
SdmxWebSource source2 = SdmxWebSource.builder().id("s2").driver("dX").endpointOf("http://abc").build();
WebDriver driverX = MockedDriver.builder().name("dX").rank(WRAPPED_RANK).available(true).customSource(source1a).customSource(source2).build();

SdmxWebSource source1b = SdmxWebSource.builder().name("s1").driver("dY").endpointOf("http://xyz").build();
SdmxWebSource source3 = SdmxWebSource.builder().name("s3").driver("dY").endpointOf("http://xyz").build();
SdmxWebSource source1b = SdmxWebSource.builder().id("s1").driver("dY").endpointOf("http://xyz").build();
SdmxWebSource source3 = SdmxWebSource.builder().id("s3").driver("dY").endpointOf("http://xyz").build();
WebDriver driverY = MockedDriver.builder().name("dY").rank(NATIVE_RANK).available(true).customSource(source1b).customSource(source3).build();

assertThat(SdmxWebManager.builder().driver(driverX).driver(driverY).build().getDefaultSources())
Expand All @@ -198,15 +198,15 @@ public void testGetConnection() throws IOException {
.isThrownBy(() -> manager.getConnection("ko"))
.as("Invalid source name");

assertThatCode(() -> manager.getConnection(sampleSource.getName()).close()).doesNotThrowAnyException();
assertThatCode(() -> manager.getConnection(sampleSource.getId()).close()).doesNotThrowAnyException();

WebDriver driver1 = MockedDriver
.builder()
.name("d1")
.rank(WRAPPED_RANK)
.available(true)
.repo(sample, EnumSet.allOf(Feature.class))
.customSource(SdmxWebSource.builder().name("source").driver("d1").dialect("azerty").endpointOf(sample.getName()).build())
.customSource(SdmxWebSource.builder().id("source").driver("d1").dialect("azerty").endpointOf(sample.getName()).build())
.build();

WebDriver driver2 = MockedDriver
Expand All @@ -215,7 +215,7 @@ public void testGetConnection() throws IOException {
.rank(NATIVE_RANK)
.available(true)
.repo(sample, EnumSet.allOf(Feature.class))
.customSource(SdmxWebSource.builder().name("source").driver("d2").dialect("azerty").endpointOf(sample.getName()).build())
.customSource(SdmxWebSource.builder().id("source").driver("d2").dialect("azerty").endpointOf(sample.getName()).build())
.build();

try (Connection c = SdmxWebManager.builder().driver(driver2).driver(driver1).build().getConnection("source")) {
Expand All @@ -240,7 +240,7 @@ public void testGetConnectionOfSource() {
.as("Invalid source driver");

assertThatCode(() -> manager.getConnection(sampleSource).close()).doesNotThrowAnyException();
assertThatCode(() -> manager.getConnection(sampleSource.toBuilder().name("other").build()).close()).doesNotThrowAnyException();
assertThatCode(() -> manager.getConnection(sampleSource.toBuilder().id("other").build()).close()).doesNotThrowAnyException();
}

@SuppressWarnings("EmptyTryBlock")
Expand All @@ -251,31 +251,31 @@ public void testInvalidSourceProperties() throws IOException {
SdmxWebManager manager = SdmxWebManager
.builder()
.driver(sampleDriver)
.eventListener((source, event) -> events.add(source.getName() + ":" + event))
.eventListener((source, event) -> events.add(source.getId() + ":" + event))
.build();

SdmxWebSource noProp = sampleSource.toBuilder().name("noProp").clearProperties().build();
SdmxWebSource noProp = sampleSource.toBuilder().id("noProp").clearProperties().build();
try (Connection ignored = manager.getConnection(noProp)) {
}
assertThat(events).isEmpty();

SdmxWebSource validProp = sampleSource.toBuilder().name("validProp").build();
SdmxWebSource validProp = sampleSource.toBuilder().id("validProp").build();
try (Connection ignored = manager.getConnection(validProp)) {
}
assertThat(events).isEmpty();

SdmxWebSource invalidProp = sampleSource.toBuilder().name("invalidProp").property("boom", "123").build();
SdmxWebSource invalidProp = sampleSource.toBuilder().id("invalidProp").property("boom", "123").build();
try (Connection ignored = manager.getConnection(invalidProp)) {
}
assertThat(events).singleElement(as(STRING))
.contains(invalidProp.getName())
.contains(invalidProp.getId())
.contains("boom");
}

private final DataRepository sample = DataRepository.builder().name("repo").build();
private final SdmxWebSource sampleSource = SdmxWebSource
.builder()
.name("repoSource")
.id("repoSource")
.driver("repoDriver")
.dialect("azerty")
.endpointOf(sample.getName())
Expand Down
16 changes: 8 additions & 8 deletions sdmx-dl-api/src/test/java/sdmxdl/web/SdmxWebSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,13 @@ public void testBuilderEndpointOf() throws MalformedURLException {
assertThatIllegalArgumentException()
.isThrownBy(() -> SdmxWebSource.builder().endpointOf("h ttp://localhost"));

assertThat(SdmxWebSource.builder().endpointOf("http://localhost").name("").driver("").build().getEndpoint())
assertThat(SdmxWebSource.builder().endpointOf("http://localhost").id("").driver("").build().getEndpoint())
.isEqualTo(URI.create("http://localhost"));
}

@Test
public void testBuilderDescription() {
SdmxWebSource base = SdmxWebSource.builder().endpointOf("http://localhost").name("").driver("").build();
SdmxWebSource base = SdmxWebSource.builder().endpointOf("http://localhost").id("").driver("").build();

assertThat(
base
Expand Down Expand Up @@ -77,16 +77,16 @@ public void testBuilderPropertyOf() {
assertThatNullPointerException()
.isThrownBy(() -> SdmxWebSource.builder().propertyOf("", null));

assertThat(SdmxWebSource.builder().propertyOf("hello", "world").endpointOf("http://localhost").name("").driver("").build().getProperties())
assertThat(SdmxWebSource.builder().propertyOf("hello", "world").endpointOf("http://localhost").id("").driver("").build().getProperties())
.containsEntry("hello", "world");
}

@Test
public void testAlias() {
SdmxWebSource estat = SdmxWebSource.builder().name("ESTAT").alias("EUROSTAT").driver("").endpointOf("http://localhost").build();
SdmxWebSource estat = SdmxWebSource.builder().id("ESTAT").alias("EUROSTAT").driver("").endpointOf("http://localhost").build();

assertThat(estat.alias("EUROSTAT"))
.isEqualTo(estat.toBuilder().name("EUROSTAT").build());
.isEqualTo(estat.toBuilder().id("EUROSTAT").build());

assertThatNullPointerException()
.isThrownBy(() -> estat.alias(null));
Expand All @@ -97,15 +97,15 @@ public void testAlias() {

@Test
public void testIsAlias() {
SdmxWebSource base = SdmxWebSource.builder().name("ESTAT").driver("").endpointOf("http://localhost").build();
SdmxWebSource base = SdmxWebSource.builder().id("ESTAT").driver("").endpointOf("http://localhost").build();
assertThat(base.isAlias()).isFalse();
assertThat(base.toBuilder().alias("EUROSTAT").build().isAlias()).isFalse();
assertThat(base.toBuilder().name("EUROSTAT").alias("EUROSTAT").build().isAlias()).isTrue();
assertThat(base.toBuilder().id("EUROSTAT").alias("EUROSTAT").build().isAlias()).isTrue();
}

@Test
public void testWebsite() {
SdmxWebSource base = SdmxWebSource.builder().name("ESTAT").driver("").endpointOf("http://localhost").build();
SdmxWebSource base = SdmxWebSource.builder().id("ESTAT").driver("").endpointOf("http://localhost").build();
assertThat(base.getWebsite()).isNull();
assertThat(base.toBuilder().websiteOf("http://somewhere").build().getWebsite())
.asString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private Stream<SdmxWebSource> generateSources() {
public static SdmxWebSource sourceOf(String name, String driverName, DataRepository repo) {
return SdmxWebSource
.builder()
.name(name)
.id(name)
.driver(driverName)
.endpointOf(repo.getName())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public WebContext noOpWebContext() {
public void assertCompliance(WebDriver d) {
SdmxWebSource validSource = SdmxWebSource
.builder()
.name("valid")
.id("valid")
.driver(d.getName())
.dialect("azerty")
.endpointOf("http://localhost")
Expand All @@ -40,7 +40,7 @@ public void assertCompliance(WebDriver d) {
}

private void checkSource(SdmxWebSource o, WebDriver d) {
assertThat(o.getName()).isNotBlank();
assertThat(o.getId()).isNotBlank();
assertThat(o.getProperties()).isNotNull();
assertThat(o.getDriver()).isEqualTo(d.getName());
assertThat(o.getProperties().keySet()).isSubsetOf(d.getSupportedProperties());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void invalidate(SdmxWebSource source) {
}

private PasswordAuthentication readPasswordAuthentication(SdmxWebSource source) throws IOError {
console.format("Enter your credentials for %s\n", source.getName());
console.format("Enter your credentials for %s\n", source.getId());
String username = console.readLine("Enter username: ");
char[] password = console.readPassword("Enter password: ");
return new PasswordAuthentication(username, password);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public void onSourceEvent(SdmxWebSource source, String message) {
main.accept(source, message);
}
if (verboseOptions.isVerbose()) {
verboseOptions.reportToErrorStream("WEB", source.getName() + ": " + message);
verboseOptions.reportToErrorStream("WEB", source.getId() + ": " + message);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public Void call() throws Exception {
private CsvTable<SdmxWebSource> getTable() {
return CsvTable
.builderOf(SdmxWebSource.class)
.columnOf("Name", SdmxWebSource::getName, Formatter.onString())
.columnOf("Name", SdmxWebSource::getId, Formatter.onString())
.columnOf("Description", this::getDescription, Formatter.onString())
.columnOf("Aliases", SdmxWebSource::getAliases, CsvUtil.fromIterable(Formatter.onString(), ','))
.columnOf("Driver", SdmxWebSource::getDriver, Formatter.onString())
Expand Down
2 changes: 1 addition & 1 deletion sdmx-dl-cli/src/test/java/_test/FileSample.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public static File create(Path temp) throws IOException {
private static SdmxWebSource sourceOf(String name, File data, File struct) throws MalformedURLException {
return SdmxWebSource
.builder()
.name(name)
.id(name)
.driver("ri:file")
.endpoint(data.toURI())
.property("structureURL", struct.toURI().toURL().toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private File newInvalidFile(Path temp) throws IOException {

private File newValidFile(Path temp) throws IOException {
File result = Files.createFile(temp.resolve("validFile")).toFile();
SdmxWebSource source = SdmxWebSource.builder().name("xyz").driver("dummy").endpointOf("http://localhost").build();
SdmxWebSource source = SdmxWebSource.builder().id("xyz").driver("dummy").endpointOf("http://localhost").build();
XmlWebSource.getFormatter().formatFile(singletonList(source), result);
return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public AutoCompletionSource getSource() {
.builder(this::load)
.behavior(SYNC)
.postProcessor(this::filterAndSort)
.valueToString(SdmxWebSource::getName)
.valueToString(SdmxWebSource::getId)
.build();
}

Expand All @@ -144,7 +144,7 @@ public ListCellRenderer getRenderer() {
return new CustomListCellRenderer<SdmxWebSource>() {
@Override
protected String getValueAsString(SdmxWebSource value) {
return value.getName() + ": " + manager.getLanguages().select(value.getDescriptions());
return value.getId() + ": " + manager.getLanguages().select(value.getDescriptions());
}

@Override
Expand All @@ -171,7 +171,7 @@ private Predicate<SdmxWebSource> getFilter(String term) {
Predicate<String> filter = ExtAutoCompletionSource.basicFilter(term);
LanguagePriorityList langs = manager.getLanguages();
return value -> filter.test(langs.select(value.getDescriptions()))
|| filter.test(value.getName())
|| filter.test(value.getId())
|| value.getAliases().stream().anyMatch(filter);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,8 @@ public void actionPerformed(ActionEvent e) {
main.putClientProperty(FlatClientProperties.TABBED_PANE_TAB_TYPE, FlatClientProperties.TABBED_PANE_TAB_TYPE_CARD);

sourcesList.setCellRenderer(JLists.cellRendererOf((label, value) -> {
label.setText(nameDescription(value.getName(), value.getDescription(LanguagePriorityList.ANY)).render());
label.setIcon(getDataSourceIcon(value.getName(), 24, sourcesList::repaint));
label.setText(nameDescription(value.getId(), value.getDescription(LanguagePriorityList.ANY)).render());
label.setIcon(getDataSourceIcon(value.getId(), 24, sourcesList::repaint));
label.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ private static List<SdmxWebSource> parseXml(XMLStreamReader reader) throws XMLSt
item = SdmxWebSource.builder();
break;
case NAME_TAG:
item.name(reader.getElementText());
item.id(reader.getElementText());
break;
case DESCRIPTION_TAG:
String lang = reader.getAttributeValue(null, LANG_ATTR);
Expand Down Expand Up @@ -122,7 +122,7 @@ private static void formatXml(List<SdmxWebSource> list, XMLStreamWriter writer,
writer.writeStartElement(SOURCES_TAG);
for (SdmxWebSource source : list) {
writer.writeStartElement(SOURCE_TAG);
writeTextElement(writer, NAME_TAG, source.getName());
writeTextElement(writer, NAME_TAG, source.getId());
for (Map.Entry<String, String> description : source.getDescriptions().entrySet()) {
writeDescription(writer, description);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public class XmlWebSourceTest {
private final List<SdmxWebSource> sample = Arrays.asList(
SdmxWebSource
.builder()
.name("ECB")
.id("ECB")
.description("en", "European Central Bank")
.driver("ri:sdmx21")
.dialect(SDMX21_DIALECT)
Expand All @@ -48,7 +48,7 @@ public class XmlWebSourceTest {
.build(),
SdmxWebSource
.builder()
.name("other")
.id("other")
.descriptionOf("some description")
.driver("dummy")
.endpointOf("http://localhost")
Expand Down
Loading

0 comments on commit 9d720f8

Please sign in to comment.