From 66a368448d5f654c5c0881f1a0306585ed66f618 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Such=C3=A1nek?= Date: Mon, 27 Apr 2020 14:06:34 +0200 Subject: [PATCH] [FOR-58] Adopt persistentUrl of FDP (#46) --- CHANGELOG.md | 5 +++++ .../metadata/commands/CatalogsMetadataCommand.java | 6 ++++-- .../metadata/commands/FDPMetadataCommand.java | 6 ++++-- .../metadata/dto/config/FDPConfigDTO.java | 2 +- .../metadata/fdp/FairDataPointClient.java | 6 +++--- .../resources/module/langs/translation-en.json | 3 ++- src/main/resources/module/scripts/api-client.js | 14 ++++++++------ .../module/scripts/dialogs/fdp-info-dialog.html | 4 ++-- .../module/scripts/dialogs/fdp-info-dialog.js | 6 +++--- .../module/scripts/dialogs/metadata-form-dialog.js | 11 ++++++----- .../module/scripts/dialogs/post-fdp-dialog.js | 10 ++++++---- 11 files changed, 44 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b1535d..8d79cc5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Changed - Prepared getting and passing SHACL specs from FDP to OpenRefine frontend +- Updated for compatibility with newer FAIR Data Point 1.3.0 + +### Fixed + +- Persisting information about stored metadata ## [1.2.0] diff --git a/src/main/java/solutions/fairdata/openrefine/metadata/commands/CatalogsMetadataCommand.java b/src/main/java/solutions/fairdata/openrefine/metadata/commands/CatalogsMetadataCommand.java index 95dd2d6..c17e563 100644 --- a/src/main/java/solutions/fairdata/openrefine/metadata/commands/CatalogsMetadataCommand.java +++ b/src/main/java/solutions/fairdata/openrefine/metadata/commands/CatalogsMetadataCommand.java @@ -51,13 +51,15 @@ public class CatalogsMetadataCommand extends Command { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String fdpUri = request.getParameter("fdpUri"); + String repositoryUri = request.getParameter("repositoryUri"); + String token = request.getParameter("token"); Writer w = CommandUtils.prepareWriter(response); ProjectAudit pa = new ProjectAudit(getProject(request)); - FairDataPointClient fdpClient = new FairDataPointClient(fdpUri, pa); + FairDataPointClient fdpClient = new FairDataPointClient(fdpUri, token, pa); pa.reportInfo(EventSource.FDP_METADATA, "Retrieving catalogs from FDP URI: " + fdpUri); try { - FDPMetadataDTO fdpMetadataDTO = fdpClient.getFairDataPointMetadata(); + FDPMetadataDTO fdpMetadataDTO = fdpClient.getFairDataPointMetadata(repositoryUri); ArrayList catalogDTOs = new ArrayList<>(); for (String catalogURI : fdpMetadataDTO.getChildren()) { catalogDTOs.add(fdpClient.getCatalogMetadata(catalogURI)); diff --git a/src/main/java/solutions/fairdata/openrefine/metadata/commands/FDPMetadataCommand.java b/src/main/java/solutions/fairdata/openrefine/metadata/commands/FDPMetadataCommand.java index e04102c..800fb2d 100644 --- a/src/main/java/solutions/fairdata/openrefine/metadata/commands/FDPMetadataCommand.java +++ b/src/main/java/solutions/fairdata/openrefine/metadata/commands/FDPMetadataCommand.java @@ -47,13 +47,15 @@ public class FDPMetadataCommand extends Command { @Override public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { String fdpUri = request.getParameter("fdpUri"); + String repositoryUri = request.getParameter("repositoryUri"); + String token = request.getParameter("token"); Writer w = CommandUtils.prepareWriter(response); ProjectAudit pa = new ProjectAudit(getProject(request)); - FairDataPointClient fdpClient = new FairDataPointClient(fdpUri, pa); + FairDataPointClient fdpClient = new FairDataPointClient(fdpUri, token, pa); pa.reportInfo(EventSource.FDP_METADATA, "Retrieving FAIR Data Point (repository) metadata from URI: " + fdpUri); try { - FDPMetadataDTO fdpMetadataDTO = fdpClient.getFairDataPointMetadata(); + FDPMetadataDTO fdpMetadataDTO = fdpClient.getFairDataPointMetadata(repositoryUri); pa.reportInfo(EventSource.FDP_METADATA, "FAIR Data Point (repository) metadata retrieved from: " + fdpUri); CommandUtils.objectMapper.writeValue(w, new FDPMetadataResponse("connect-fdp-command/success", fdpMetadataDTO)); } catch (Exception e) { diff --git a/src/main/java/solutions/fairdata/openrefine/metadata/dto/config/FDPConfigDTO.java b/src/main/java/solutions/fairdata/openrefine/metadata/dto/config/FDPConfigDTO.java index e44363d..c4d1425 100644 --- a/src/main/java/solutions/fairdata/openrefine/metadata/dto/config/FDPConfigDTO.java +++ b/src/main/java/solutions/fairdata/openrefine/metadata/dto/config/FDPConfigDTO.java @@ -32,5 +32,5 @@ @Getter @Setter public class FDPConfigDTO { - private String instanceUrl; + private String persistentUrl; } diff --git a/src/main/java/solutions/fairdata/openrefine/metadata/fdp/FairDataPointClient.java b/src/main/java/solutions/fairdata/openrefine/metadata/fdp/FairDataPointClient.java index 66cf301..c9f298b 100644 --- a/src/main/java/solutions/fairdata/openrefine/metadata/fdp/FairDataPointClient.java +++ b/src/main/java/solutions/fairdata/openrefine/metadata/fdp/FairDataPointClient.java @@ -74,7 +74,7 @@ public class FairDataPointClient { )); private static final String INFO_PART = "actuator/info"; - private static final String CONFIG_PART = "configuration"; + private static final String CONFIG_PART = "configs/bootstrap"; private static final String CATALOG_PART = "catalog"; private static final String DATASET_PART = "dataset"; private static final String DISTRIBUTION_PART = "distribution"; @@ -156,13 +156,13 @@ public List getDashboard() throws IOException, FairDataPointEx * @throws IOException in case of a communication error * @throws FairDataPointException in case that FDP responds with an unexpected code */ - public FDPMetadataDTO getFairDataPointMetadata() throws IOException, FairDataPointException { + public FDPMetadataDTO getFairDataPointMetadata(String repositoryUri) throws IOException, FairDataPointException { HttpURLConnection conn = request(fdpBaseURI, "GET", MEDIA_TYPE_TURTLE, true); projectAudit.reportDebug(EventSource.FDP_CONNECTION, "Sending GET repository metadata request to FDP"); if(conn.getResponseCode() == HttpURLConnection.HTTP_OK) { projectAudit.reportDebug(EventSource.FDP_CONNECTION, "Received repository metadata"); - String actualURI = conn.getURL().toString(); + String actualURI = repositoryUri != null ? repositoryUri : conn.getURL().toString(); ArrayList statements = parseStatements(conn, actualURI); projectAudit.reportDebug(EventSource.FDP_CONNECTION, "Parsed and processed repository metadata"); return FDPMetadataTransformerUtils.metadata2DTO(statements, actualURI); diff --git a/src/main/resources/module/langs/translation-en.json b/src/main/resources/module/langs/translation-en.json index 5d633c8..e6f8527 100644 --- a/src/main/resources/module/langs/translation-en.json +++ b/src/main/resources/module/langs/translation-en.json @@ -164,7 +164,7 @@ "fdp-info-dialog/version": "Version", "fdp-info-dialog/builtAt": "Built at", "fdp-info-dialog/baseUri": "Base URI", - "fdp-info-dialog/instanceUrl": "Instance URI", + "fdp-info-dialog/persistentUrl": "Persistent URL", "fdp-info-dialog/unknown": "(unknown)", "audit/title": "Audit log (metadata extension)", "audit/entries": "entries", @@ -177,6 +177,7 @@ "audit/type/WARNING": "WARNING", "audit/type/INFO": "INFO", "audit/type/DEBUG": "DEBUG", + "audit/type/TRACE": "TRACE", "audit/source/ANY": "any", "audit/source/FDP_CONNECTION": "FDP connection", "audit/source/FDP_METADATA": "FDP metadata", diff --git a/src/main/resources/module/scripts/api-client.js b/src/main/resources/module/scripts/api-client.js index 97ff5e2..e9f05ca 100644 --- a/src/main/resources/module/scripts/api-client.js +++ b/src/main/resources/module/scripts/api-client.js @@ -4,6 +4,7 @@ class MetadataApiClient { constructor() { this.fdpUri = null; + this.repositoryUri = null; this.token = null; this.fdpConfig = null; this.fdpInfo = null; @@ -31,6 +32,7 @@ class MetadataApiClient { }), [(result) => { this.fdpUri = result.fdpUri; + this.repositoryUri = result.fdpConfig.persistentUrl; this.token = result.token; this.fdpConfig = result.fdpConfig; this.fdpInfo = result.fdpInfo; @@ -49,8 +51,8 @@ class MetadataApiClient { } postSettings(projectData, callbacks) { - const settingsPostRequest = JSON.stringify({ projectData }); - this._ajaxGeneric("settings","POST", settingsPostRequest, callbacks, [], true); + const settingsPostRequest = JSON.stringify(projectData); + this._ajaxGeneric("settings", "POST", settingsPostRequest, callbacks, [], true); } getAuditLog(callbacks) { @@ -72,22 +74,22 @@ class MetadataApiClient { } getFDPMetadata(callbacks, errorCallbacks) { - const params = { fdpUri: this.fdpUri }; + const params = { fdpUri: this.fdpUri, repositoryUri: this.repositoryUri, token: this.token }; this._ajaxGeneric("fdp-metadata", "GET", params, callbacks, errorCallbacks); } getCatalogs(callbacks, errorCallbacks) { - const params = { fdpUri: this.fdpUri }; + const params = { fdpUri: this.fdpUri, repositoryUri: this.repositoryUri, token: this.token }; this._ajaxGeneric("catalogs-metadata", "GET", params, callbacks, errorCallbacks); } getDatasets(catalogUri, callbacks, errorCallbacks) { - const params = { fdpUri: this.fdpUri, catalogUri }; + const params = { fdpUri: this.fdpUri, repositoryUri: this.repositoryUri, token: this.token, catalogUri }; this._ajaxGeneric("datasets-metadata", "GET", params, callbacks, errorCallbacks); } getDistributions(datasetUri, callbacks, errorCallbacks) { - const params = { fdpUri: this.fdpUri, datasetUri }; + const params = { fdpUri: this.fdpUri, repositoryUri: this.repositoryUri, token: this.token, datasetUri }; this._ajaxGeneric("distributions-metadata", "GET", params, callbacks, errorCallbacks); } diff --git a/src/main/resources/module/scripts/dialogs/fdp-info-dialog.html b/src/main/resources/module/scripts/dialogs/fdp-info-dialog.html index 271a828..b8222a2 100644 --- a/src/main/resources/module/scripts/dialogs/fdp-info-dialog.html +++ b/src/main/resources/module/scripts/dialogs/fdp-info-dialog.html @@ -17,8 +17,8 @@
-
-
+
+
diff --git a/src/main/resources/module/scripts/dialogs/fdp-info-dialog.js b/src/main/resources/module/scripts/dialogs/fdp-info-dialog.js index a7a60c3..5e3c84e 100644 --- a/src/main/resources/module/scripts/dialogs/fdp-info-dialog.js +++ b/src/main/resources/module/scripts/dialogs/fdp-info-dialog.js @@ -13,14 +13,14 @@ class FDPInfoDialog { let fdpName = null; let fdpVersion = null; let fdpBuiltAt = null; - let fdpInstanceUrl = null; + let fdpPersistentUrl = null; if (apiClient.fdpInfo !== null) { fdpName = apiClient.fdpInfo.name; fdpVersion = apiClient.fdpInfo.version; fdpBuiltAt = apiClient.fdpInfo.builtAt; } if (apiClient.fdpConfig !== null) { - fdpInstanceUrl = apiClient.fdpConfig.instanceUrl; + fdpPersistentUrl = apiClient.fdpConfig.persistentUrl; } const handleNull = (text) => { @@ -32,7 +32,7 @@ class FDPInfoDialog { this.elements.fdpInfoVersion.text(handleNull(fdpVersion)); this.elements.fdpInfoBuiltAt.text(handleNull(fdpBuiltAt)); this.elements.fdpInfoBaseUri.text(handleNull(fdpUri)); - this.elements.fdpInfoInstanceUrl.text(handleNull(fdpInstanceUrl)); + this.elements.fdpInfoPersistentUrl.text(handleNull(fdpPersistentUrl)); } launch() { diff --git a/src/main/resources/module/scripts/dialogs/metadata-form-dialog.js b/src/main/resources/module/scripts/dialogs/metadata-form-dialog.js index e171067..9664a0e 100644 --- a/src/main/resources/module/scripts/dialogs/metadata-form-dialog.js +++ b/src/main/resources/module/scripts/dialogs/metadata-form-dialog.js @@ -14,12 +14,11 @@ class MetadataFormDialog { this.datalists = new Set(); - const prefillMap = prefill || new Map(); + this.prefill = prefill || new Map(); this.initBasicTexts(); - this.fillForm(prefillMap); - this.bindActions(); this.getSpec(); + this.bindActions(); } launch() { @@ -143,6 +142,8 @@ class MetadataFormDialog { formGroupId ); } + + this.fillForm(this.prefill); } displayError(errorName, errorMessage) { @@ -439,8 +440,8 @@ class MetadataFormDialog { } // launcher - static createAndLaunch(specs, callbackFn, prefill) { - const dialog = new MetadataFormDialog(specs, callbackFn, prefill); + static createAndLaunch(apiClient, specs, callbackFn, prefill) { + const dialog = new MetadataFormDialog(apiClient, specs, callbackFn, prefill); dialog.launch(); } } diff --git a/src/main/resources/module/scripts/dialogs/post-fdp-dialog.js b/src/main/resources/module/scripts/dialogs/post-fdp-dialog.js index 87444c1..3196883 100644 --- a/src/main/resources/module/scripts/dialogs/post-fdp-dialog.js +++ b/src/main/resources/module/scripts/dialogs/post-fdp-dialog.js @@ -65,10 +65,12 @@ class PostFdpDialog { } persistProjectData() { - const settings = { projectData: { + const settings = { + projectData: { lastCatalog: Object.fromEntries(this.projectData.lastCatalog.entries()), - projectData: Object.fromEntries(this.projectData.lastDataset.entries()) - }}; + lastDataset: Object.fromEntries(this.projectData.lastDataset.entries()) + } + }; this.apiClient.postSettings(settings, [ (result) => { this.loadProjectData(result.projectData); @@ -186,7 +188,7 @@ class PostFdpDialog { elmts.catalogAddButton.click(() => { let prefill = new Map(this.prefill); - prefill.set("parent", self.apiClient.fdpUri); + prefill.set("parent", self.apiClient.repositoryUri); MetadataFormDialog.createAndLaunch(this.apiClient, MetadataSpecs.catalog, (catalog, formDialog) => { this.apiClient.postCatalog(