Skip to content

Commit

Permalink
Fix bugs with auto-adding distribution URL
Browse files Browse the repository at this point in the history
Issue #1380
  • Loading branch information
robyngit committed Aug 16, 2023
1 parent b51a7bc commit 7c6c45d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
12 changes: 10 additions & 2 deletions src/js/collections/metadata/eml/EMLDistributions.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ define(["backbone", "models/metadata/eml211/EMLDistribution"], function (
*/
model: EMLDistribution,

/*
* Maps the lower-case EML node names (valid in HTML DOM) to the camel-cased
* EML node names (valid in EML). Used during parse() and serialize().
*/
nodeNameMap: function () {
return EMLDistribution.prototype.nodeNameMap();
},

/**
* Find the distribution that has all of the matching attributes. This
* will return true if the distribution has all of the attributes, even if
Expand Down Expand Up @@ -86,13 +94,13 @@ define(["backbone", "models/metadata/eml211/EMLDistribution"], function (
// Remove any distribution models with the old PID, seriesId, or current
// PID in the URL (only if the URL function is "information")
if (dists.length && oldIDs.length) {
oldIDs.forEach((url) => {
oldIDs.forEach((id) => {
dists.removeByAttributes({ url: id, urlFunction: func }, true);
});
}

// Add a new distribution with the view URL
return dists.add({ url: url, urlFunction: urlFunction });
return dists.add({ url: url, urlFunction: func });
},

/**
Expand Down
20 changes: 14 additions & 6 deletions src/js/models/DataONEObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -1809,10 +1809,18 @@ define(['jquery', 'underscore', 'backbone', 'uuid', 'he', 'collections/AccessPol

/**
* Creates a URL for viewing more information about this object
* @return {string}
* @param {boolean} [absolute=false] - Set to true to return an
* absoloute URL. This will use whatever is configured in the
* AppModel as the base URL.
* @return {string} The URL to view this object
*/
createViewURL: function(){
return MetacatUI.root + "/view/" + encodeURIComponent((this.get("seriesId") || this.get("id")));
createViewURL: function (absolute = false) {
const ID = encodeURIComponent((this.get("seriesId") || this.get("id")));
let viewURL = MetacatUI.root + "/view/" + ID;
if (absolute) {
viewURL = MetacatUI.appModel.get("baseUrl") + viewURL;
}
return viewURL;
},

/**
Expand Down Expand Up @@ -2148,9 +2156,9 @@ define(['jquery', 'underscore', 'backbone', 'uuid', 'he', 'collections/AccessPol
* @returns {boolean} True if it is a DOI
*/
isDOI: function(customString) {
return isDOI(customString) ||
isDOI(this.get("id")) ||
isDOI(this.get("seriesId"));
return MetacatUI.appModel.isDOI(customString) ||
MetacatUI.appModel.isDOI(this.get("id")) ||
MetacatUI.appModel.isDOI(this.get("seriesId"));
},

/**
Expand Down
9 changes: 6 additions & 3 deletions src/js/models/metadata/eml211/EML211.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ define(['jquery', 'underscore', 'backbone', 'uuid',
nodeNameMap: function(){
return _.extend(
this.constructor.__super__.nodeNameMap(),
EMLDistribution.prototype.nodeNameMap(),
EMLDistributions.prototype.nodeNameMap(),
EMLGeoCoverage.prototype.nodeNameMap(),
EMLKeywordSet.prototype.nodeNameMap(),
EMLParty.prototype.nodeNameMap(),
Expand Down Expand Up @@ -1464,9 +1464,12 @@ define(['jquery', 'underscore', 'backbone', 'uuid',
addDatasetDistributionURL: function () {
try {
// Old distribution URLs could exist for any of the old or current
const IDs = [ this.get('oldPid'), this.get('id'), this.get('seriesId')]
let IDs = [this.get('oldPid'), this.get('id'), this.get('seriesId')]
// Append the URL-encoded IDs to the list of IDs
const encodedIDs = IDs.map(id => encodeURIComponent(id));
IDs = IDs.concat(encodedIDs);
// The new distribution URL will be the view URL or DOI URL
const viewURL = this.getCanonicalDOIIRI() || this.createViewURL();
const viewURL = this.getCanonicalDOIIRI() || this.createViewURL(true);
// Add the new distribution URL to the collection
this.getDistributions().addDatasetDistributionURL(viewURL, IDs);
} catch (e) {
Expand Down

0 comments on commit 7c6c45d

Please sign in to comment.