Skip to content

Commit

Permalink
[FOR-58] Adopt persistentUrl of FDP (#46)
Browse files Browse the repository at this point in the history
  • Loading branch information
MarekSuchanek authored Apr 27, 2020
1 parent e042b5d commit 66a3684
Show file tree
Hide file tree
Showing 11 changed files with 44 additions and 29 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<CatalogDTO> catalogDTOs = new ArrayList<>();
for (String catalogURI : fdpMetadataDTO.getChildren()) {
catalogDTOs.add(fdpClient.getCatalogMetadata(catalogURI));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
@Getter
@Setter
public class FDPConfigDTO {
private String instanceUrl;
private String persistentUrl;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -156,13 +156,13 @@ public List<DashboardItemDTO> 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<Statement> statements = parseStatements(conn, actualURI);
projectAudit.reportDebug(EventSource.FDP_CONNECTION, "Parsed and processed repository metadata");
return FDPMetadataTransformerUtils.metadata2DTO(statements, actualURI);
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/module/langs/translation-en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
14 changes: 8 additions & 6 deletions src/main/resources/module/scripts/api-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class MetadataApiClient {

constructor() {
this.fdpUri = null;
this.repositoryUri = null;
this.token = null;
this.fdpConfig = null;
this.fdpInfo = null;
Expand Down Expand Up @@ -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;
Expand All @@ -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) {
Expand All @@ -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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
<dt data-i18n="fdp-info-dialog/baseUri"></dt>
<dd bind="fdpInfoBaseUri"></dd>

<dt data-i18n="fdp-info-dialog/instanceUrl"></dt>
<dd bind="fdpInfoInstanceUrl"></dd>
<dt data-i18n="fdp-info-dialog/persistentUrl"></dt>
<dd bind="fdpInfoPersistentUrl"></dd>
</dl>
</div>
</div>
6 changes: 3 additions & 3 deletions src/main/resources/module/scripts/dialogs/fdp-info-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -143,6 +142,8 @@ class MetadataFormDialog {
formGroupId
);
}

this.fillForm(this.prefill);
}

displayError(errorName, errorMessage) {
Expand Down Expand Up @@ -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();
}
}
10 changes: 6 additions & 4 deletions src/main/resources/module/scripts/dialogs/post-fdp-dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 66a3684

Please sign in to comment.