-
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.
- Loading branch information
Showing
11 changed files
with
262 additions
and
129 deletions.
There are no files selected for viewing
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
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
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
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,79 @@ | ||
package internal.sdmxdl.cli; | ||
|
||
import lombok.NonNull; | ||
import sdmxdl.ext.Persistence; | ||
import sdmxdl.file.spi.FileCaching; | ||
import sdmxdl.web.SdmxWebManager; | ||
import sdmxdl.web.spi.*; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.List; | ||
|
||
@lombok.Value | ||
public class Plugin { | ||
|
||
public enum Type { | ||
DRIVER, | ||
AUTHENTICATOR, | ||
MONITOR, | ||
PERSISTENCE, | ||
REGISTRY, | ||
WEB_CACHING, | ||
FILE_CACHING, | ||
NETWORKING | ||
} | ||
|
||
public static List<Plugin> allOf(SdmxWebManager manager) { | ||
List<Plugin> result = new ArrayList<>(); | ||
manager.getDrivers().stream().map(Plugin::of).forEach(result::add); | ||
manager.getAuthenticators().stream().map(Plugin::of).forEach(result::add); | ||
manager.getMonitors().stream().map(Plugin::of).forEach(result::add); | ||
manager.getPersistences().stream().map(Plugin::of).forEach(result::add); | ||
result.add(Plugin.of(manager.getRegistry())); | ||
result.add(Plugin.of(manager.getCaching())); | ||
result.add(Plugin.of(manager.getNetworking())); | ||
return result; | ||
} | ||
|
||
static Plugin of(Driver o) { | ||
return new Plugin(Type.DRIVER, o.getDriverId(), o.getDriverProperties()); | ||
} | ||
|
||
static Plugin of(Authenticator o) { | ||
return new Plugin(Type.AUTHENTICATOR, o.getAuthenticatorId(), o.getAuthenticatorProperties()); | ||
} | ||
|
||
static Plugin of(Monitor o) { | ||
return new Plugin(Type.MONITOR, o.getMonitorId(), o.getMonitorProperties()); | ||
} | ||
|
||
static Plugin of(Persistence o) { | ||
return new Plugin(Type.PERSISTENCE, o.getPersistenceId(), o.getPersistenceProperties()); | ||
} | ||
|
||
static Plugin of(Registry o) { | ||
return new Plugin(Type.REGISTRY, o.getRegistryId(), o.getRegistryProperties()); | ||
} | ||
|
||
static Plugin of(WebCaching o) { | ||
return new Plugin(Type.WEB_CACHING, o.getWebCachingId(), o.getWebCachingProperties()); | ||
} | ||
|
||
static Plugin of(FileCaching o) { | ||
return new Plugin(Type.FILE_CACHING, o.getFileCachingId(), o.getFileCachingProperties()); | ||
} | ||
|
||
static Plugin of(Networking o) { | ||
return new Plugin(Type.NETWORKING, o.getNetworkingId(), o.getNetworkingProperties()); | ||
} | ||
|
||
@NonNull | ||
Type type; | ||
|
||
@NonNull | ||
String id; | ||
|
||
@NonNull | ||
Collection<String> Properties; | ||
} |
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
96 changes: 96 additions & 0 deletions
96
sdmx-dl-cli/src/main/java/sdmxdl/cli/CheckSourcesCommand.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,96 @@ | ||
/* | ||
* Copyright 2018 National Bank of Belgium | ||
* | ||
* Licensed under the EUPL, Version 1.1 or - as soon they will be approved | ||
* by the European Commission - subsequent versions of the EUPL (the "Licence"); | ||
* You may not use this work except in compliance with the Licence. | ||
* You may obtain a copy of the Licence at: | ||
* | ||
* http://ec.europa.eu/idabc/eupl | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the Licence is distributed on an "AS IS" basis, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the Licence for the specific language governing permissions and | ||
* limitations under the Licence. | ||
*/ | ||
package sdmxdl.cli; | ||
|
||
import internal.sdmxdl.cli.Plugin; | ||
import internal.sdmxdl.cli.WebSourcesOptions; | ||
import internal.sdmxdl.cli.ext.CsvTable; | ||
import internal.sdmxdl.cli.ext.RFC4180OutputOptions; | ||
import picocli.CommandLine; | ||
import sdmxdl.web.SdmxWebManager; | ||
import sdmxdl.web.WebSource; | ||
import sdmxdl.web.spi.Driver; | ||
|
||
import java.io.IOException; | ||
import java.util.Collection; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.concurrent.Callable; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
import static java.util.stream.Collectors.toList; | ||
|
||
/** | ||
* @author Philippe Charles | ||
*/ | ||
@CommandLine.Command(name = "sources") | ||
@SuppressWarnings("FieldMayBeFinal") | ||
public final class CheckSourcesCommand implements Callable<Void> { | ||
|
||
@CommandLine.Mixin | ||
private WebSourcesOptions web; | ||
|
||
@CommandLine.Mixin | ||
private final RFC4180OutputOptions csv = new RFC4180OutputOptions(); | ||
|
||
@Override | ||
public Void call() throws Exception { | ||
getTable().write(csv, getRows()); | ||
return null; | ||
} | ||
|
||
private CsvTable<SourceIssue> getTable() { | ||
return CsvTable | ||
.builderOf(SourceIssue.class) | ||
.columnOf("ID", SourceIssue::getId) | ||
.columnOf("Issue", SourceIssue::getIssue) | ||
.build(); | ||
} | ||
|
||
private Stream<SourceIssue> getRows() throws IOException { | ||
SdmxWebManager manager = web.loadManager(); | ||
Stream<String> sources = web.isAllSources() ? WebSourcesOptions.getAllSourceNames(manager) : web.getSources().stream(); | ||
List<Plugin> plugins = Plugin.allOf(manager); | ||
return web.applyParallel(sources).map(source -> check(source, manager, plugins)); | ||
} | ||
|
||
private SourceIssue check(String sourceID, SdmxWebManager manager, List<Plugin> plugins) { | ||
WebSource webSource = manager.getSources().get(sourceID); | ||
if (webSource == null) { | ||
return new SourceIssue(sourceID, "Source not found"); | ||
} | ||
Optional<Driver> driver = manager.getDrivers().stream().filter(o -> o.getDriverId().equals(webSource.getDriver())).findFirst(); | ||
if (!driver.isPresent()) { | ||
return new SourceIssue(sourceID, "Driver not found"); | ||
} | ||
Collection<String> expected = plugins.stream() | ||
.filter(plugin -> !plugin.getType().equals(Plugin.Type.DRIVER) || plugin.getId().equals(driver.get().getDriverId())) | ||
.map(Plugin::getProperties) | ||
.flatMap(Collection::stream) | ||
.collect(toList()); | ||
Collection<String> found = webSource.getProperties().keySet(); | ||
String result = found.stream().filter(item -> !expected.contains(item)).sorted().collect(Collectors.joining(",")); | ||
return new SourceIssue(sourceID, result.isEmpty() ? "No problem" : ("Unknown properties: " + result)); | ||
} | ||
|
||
@lombok.Value | ||
private static class SourceIssue { | ||
String id; | ||
String issue; | ||
} | ||
} |
Oops, something went wrong.