Skip to content

Commit

Permalink
Add missing properties methods in extensions points
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Sep 12, 2024
1 parent bd131de commit 522a88d
Show file tree
Hide file tree
Showing 15 changed files with 77 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
### Added

- ![API] Add confidentiality property to WebSource [#518](https://github.com/nbbrd/sdmx-dl/issues/518)
- ![API] Add missing properties methods in extensions points [#781](https://github.com/nbbrd/sdmx-dl/issues/781)

### Changed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import sdmxdl.ext.FileFormat;
import sdmxdl.ext.Persistence;

import java.util.Collection;
import java.util.Collections;
import java.util.Set;

Expand All @@ -31,4 +32,9 @@ public int getPersistenceRank() {
public @NonNull <T extends HasPersistence> FileFormat<T> getFormat(@NonNull Class<T> type) {
return FileFormat.noOp();
}

@Override
public @NonNull Collection<String> getPersistenceProperties() {
return Collections.emptyList();
}
}
5 changes: 5 additions & 0 deletions sdmx-dl-api/src/main/java/sdmxdl/ext/Persistence.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import nbbrd.service.ServiceSorter;
import sdmxdl.HasPersistence;

import java.util.Collection;
import java.util.Set;

@ServiceDefinition(
Expand All @@ -29,8 +30,12 @@ public interface Persistence {

@NonNull <T extends HasPersistence> FileFormat<T> getFormat(@NonNull Class<T> type);

@NonNull Collection<String> getPersistenceProperties();

int UNKNOWN_PERSISTENCE_RANK = -1;

String PERSISTENCE_PROPERTY_PREFIX = "sdmxdl.persistence";

@StaticFactoryMethod
static @NonNull Persistence noOp() {
return NoOpPersistence.INSTANCE;
Expand Down
5 changes: 5 additions & 0 deletions sdmx-dl-api/src/main/java/sdmxdl/web/spi/Authenticator.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

import java.io.IOException;
import java.net.PasswordAuthentication;
import java.util.Collection;

@ServiceDefinition(
quantifier = Quantifier.MULTIPLE,
Expand All @@ -28,4 +29,8 @@ public interface Authenticator {
@Nullable PasswordAuthentication getPasswordAuthenticationOrNull(@NonNull WebSource source) throws IOException;

void invalidateAuthentication(@NonNull WebSource source) throws IOException;

@NonNull Collection<String> getAuthenticatorProperties();

String AUTHENTICATOR_PROPERTY_PREFIX = "sdmxdl.authenticator";
}
5 changes: 5 additions & 0 deletions sdmx-dl-api/src/main/java/sdmxdl/web/spi/Monitor.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import sdmxdl.web.WebSource;

import java.io.IOException;
import java.util.Collection;

@ServiceDefinition(
quantifier = Quantifier.MULTIPLE,
Expand All @@ -26,4 +27,8 @@ public interface Monitor {
@NonNull WebSource source,
@NonNull WebContext context
) throws IOException, IllegalArgumentException;

@NonNull Collection<String> getMonitorProperties();

String MONITOR_PROPERTY_PREFIX = "sdmxdl.monitor";
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ public class PersistenceAssert {
.idPattern(PersistenceLoader.ID_PATTERN)
.rank(Persistence::getPersistenceRank)
.rankLowerBound(Persistence.UNKNOWN_PERSISTENCE_RANK)
.properties(ignore -> emptyList())
.propertiesPrefix("")
.properties(Persistence::getPersistenceProperties)
.propertiesPrefix(Persistence.PERSISTENCE_PROPERTY_PREFIX)
.build();

public void assertCompliance(Persistence persistence) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ public static class Sample {
.idPattern(AuthenticatorLoader.ID_PATTERN)
.rank(ignore -> -1)
.rankLowerBound(-1)
.properties(ignore -> emptyList())
.propertiesPrefix("")
.properties(Authenticator::getAuthenticatorProperties)
.propertiesPrefix(Authenticator.AUTHENTICATOR_PROPERTY_PREFIX)
.build();

public void assertCompliance(@NonNull Authenticator authenticator, @NonNull Sample sample) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ public static class Sample {
.idPattern(MonitorLoader.ID_PATTERN)
.rank(ignore -> -1)
.rankLowerBound(-1)
.properties(ignore -> emptyList())
.propertiesPrefix("")
.properties(Monitor::getMonitorProperties)
.propertiesPrefix(Monitor.MONITOR_PROPERTY_PREFIX)
.build();

public void assertCompliance(@NonNull Monitor monitor, @NonNull Sample sample) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import java.io.IOError;
import java.io.IOException;
import java.net.PasswordAuthentication;
import java.util.Collection;
import java.util.Collections;
import java.util.concurrent.ConcurrentHashMap;

final class ConsoleAuthenticator implements Authenticator {
Expand Down Expand Up @@ -50,6 +52,11 @@ public void invalidateAuthentication(@NonNull WebSource source) {
cache.remove(source);
}

@Override
public @NonNull Collection<String> getAuthenticatorProperties() {
return Collections.emptyList();
}

private PasswordAuthentication readPasswordAuthentication(WebSource source) throws IOError {
console.format("Enter your credentials for %s\n", source.getId());
String username = console.readLine("Enter username: ");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import sdmxdl.web.spi.Authenticator;

import java.net.PasswordAuthentication;
import java.util.Collection;
import java.util.Collections;

@lombok.AllArgsConstructor
final class ConstantAuthenticator implements Authenticator {
Expand All @@ -30,4 +32,9 @@ public boolean isAuthenticatorAvailable() {
@Override
public void invalidateAuthentication(@NonNull WebSource source) {
}

@Override
public @NonNull Collection<String> getAuthenticatorProperties() {
return Collections.emptyList();
}
}
6 changes: 3 additions & 3 deletions sdmx-dl-cli/src/main/java/sdmxdl/cli/ListPluginsCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ static Plugin of(Driver o) {
}

static Plugin of(Authenticator o) {
return new Plugin("Authenticator", o.getAuthenticatorId(), emptyList());
return new Plugin("Authenticator", o.getAuthenticatorId(), o.getAuthenticatorProperties());
}

static Plugin of(Monitor o) {
return new Plugin("Monitor", o.getMonitorId(), emptyList());
return new Plugin("Monitor", o.getMonitorId(), o.getMonitorProperties());
}

static Plugin of(Persistence o) {
return new Plugin("Persistence", o.getPersistenceId(), emptyList());
return new Plugin("Persistence", o.getPersistenceId(), o.getPersistenceProperties());
}

static Plugin of(Registry o) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import sdmxdl.ext.Persistence;
import sdmxdl.format.design.ServiceSupport;

import java.util.Collection;
import java.util.List;
import java.util.Set;

@ServiceSupport
Expand All @@ -25,6 +27,9 @@ public final class PersistenceSupport implements Persistence {
@lombok.Builder.Default
private final Factory factory = Persistence.noOp()::getFormat;

@lombok.Singular
private final Collection<String> properties;

@Override
public @NonNull String getPersistenceId() {
return id;
Expand All @@ -45,6 +50,11 @@ public int getPersistenceRank() {
return factory.create(type);
}

@Override
public @NonNull Collection<String> getPersistenceProperties() {
return properties;
}

@FunctionalInterface
public interface Factory {
<T extends HasPersistence> @NonNull FileFormat<T> create(@NonNull Class<T> type);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import java.io.IOException;
import java.net.PasswordAuthentication;
import java.util.Collection;
import java.util.Collections;

@DirectImpl
@ServiceProvider
Expand Down Expand Up @@ -40,6 +42,11 @@ public void invalidateAuthentication(@NonNull WebSource source) throws IOExcepti
}
}

@Override
public @NonNull Collection<String> getAuthenticatorProperties() {
return Collections.emptyList();
}

private String getResource(WebSource source) {
return "sdmx-dl:" + source.getEndpoint().getHost();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package sdmxdl.provider.ri.monitors;

import nbbrd.io.http.HttpClient;
import lombok.NonNull;
import nbbrd.design.DirectImpl;
import nbbrd.design.VisibleForTesting;
import nbbrd.io.http.HttpClient;
import nbbrd.io.text.Parser;
import nbbrd.service.ServiceProvider;
import sdmxdl.ext.Cache;
Expand All @@ -20,6 +20,8 @@
import java.text.NumberFormat;
import java.time.Clock;
import java.time.Duration;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;

@DirectImpl
Expand Down Expand Up @@ -59,6 +61,11 @@ public final class UpptimeMonitor implements Monitor {
.orElseThrow(IOException::new);
}

@Override
public @NonNull Collection<String> getMonitorProperties() {
return Collections.emptyList();
}

private MonitorReports createReports(HttpClient client, UpptimeId base, Clock clock) throws IOException {
MonitorReports.Builder result = MonitorReports.builder().uriScheme(getMonitorUriScheme());
for (UpptimeSummary summary : UpptimeSummary.request(client, base.toSummaryURL())) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@
import java.io.Reader;
import java.net.*;
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Collections;

@DirectImpl
@ServiceProvider
Expand Down Expand Up @@ -54,6 +56,11 @@ public final class UptimeRobotMonitor implements Monitor {
return post(url, id.toBody(), parser::parseReader, context, source, getMonitorId());
}

@Override
public @NonNull Collection<String> getMonitorProperties() {
return Collections.emptyList();
}

@lombok.AllArgsConstructor
@lombok.Getter
private enum Status {
Expand Down

0 comments on commit 522a88d

Please sign in to comment.