Skip to content

Commit

Permalink
Merge pull request #1629 from adsabs/revert-1624-orcid-ms-table
Browse files Browse the repository at this point in the history
Revert "Changes for new ORCID microservice table, part 2"
  • Loading branch information
marblestation authored Nov 6, 2018
2 parents 4f34dd5 + 89141be commit dfa5956
Show file tree
Hide file tree
Showing 19 changed files with 393 additions and 154 deletions.
1 change: 0 additions & 1 deletion src/js/components/api_targets.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ function (

// store ADS information connected with ORCID here
ORCID_PREFERENCES: 'orcid/preferences',
ORCID_NAME: 'orcid/orcid-name',

// library endpoints
// can get info about all libraries, or list of bibcodes associated w/specific lib (libraries/id)
Expand Down
2 changes: 1 addition & 1 deletion src/js/mixins/papers_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ function (
data.shortAbstract = data.abstract ? this.shortenAbstract(data.abstract) : undefined;
data.details = data.details || { 'shortAbstract': data.shortAbstract, 'pub': data.pub, 'abstract': data.abstract };
data.num_citations = data['[citations]'] ? data['[citations]'].num_citations : undefined;
data.identifier = data.bibcode ? data.bibcode : data.identifier;
data.identifier = data.bibcode;

// make sure undefined doesn't become "undefined"
data.encodedIdentifier = _.isUndefined(data.identifier)
Expand Down
44 changes: 0 additions & 44 deletions src/js/modules/orcid/bio.js

This file was deleted.

37 changes: 30 additions & 7 deletions src/js/modules/orcid/extension.js
Original file line number Diff line number Diff line change
Expand Up @@ -201,23 +201,41 @@ function (

// make sure the doc has any information we gained
if (_.isUndefined(work.identifier)) {
work.identifier = work._work.getIdentifier();
if (_.isString(info.bibcode)) {
work.identifier = info.bibcode;
} else if (_.isArray(info.doi)) {
work.identifier = info.doi[0];
} else if (_.isPlainObject(work._work)) {
var type = work._work.getExternalIdType();
type = _.isArray(type) ? type[0] : type;
if (_.isString(type)) {
work.identifier = work._work.getExternalIds()[type];
}
}
}

var model = _.find(self.hiddenCollection.models, function (m) {
// do our best to find the match
return (_.isPlainObject(work._work) && work._work === m.get('_work'))
|| (_.isString(work.bibcode) && work.bibcode === m.get('bibcode'))
|| (_.isArray(work.doi) && work.doi === m.get('doi'))
|| (!_.isUndefined(work.identifier) && work.identifier === m.get('identifier'));
});

// found the model, update it
if (model) {
var sources;
var orcidPath;

// grab the array of sources, if it exists
if (_.isPlainObject(work._work)) {
sources = work._work.getSources();
var host = work._work.getSourceOrcidIdHost();
var path = work._work.getPath();

if (_.isString(host) && _.isString(path)) {
orcidPath = '//' + host + '/' + path;
}
}

if (_.isUndefined(model.get('identifier')) && self.orcidWidget) {
Expand All @@ -226,7 +244,8 @@ function (

model.set({
orcid: actions,
source_name: _.isArray(sources) ? sources.join('; ') : model.get('source_name')
source_name: _.isArray(sources) ? sources.join('; ') : model.get('source_name'),
orcidWorkPath: orcidPath
});
} else if (count < 60) {
_.delay(_.bind(onSuccess, self, [work], count + 1), 500);
Expand Down Expand Up @@ -312,7 +331,7 @@ function (
*/
WidgetClass.prototype._updateModelsWithOrcid = function (models, tries) {
var modelsToUpdate = _.filter(models || this.hiddenCollection.models, function (m) {
return !m.has('_work') && (m.has('bibcode') || m.has('doi') || m.has('identifier'));
return !m.has('_work') && (m.has('bibcode') || m.has('doi'));
});

if (_.isEmpty(modelsToUpdate)) {
Expand All @@ -329,7 +348,7 @@ function (
_.forEach(modelsToUpdate, function (m) {
var exIds = _.flatten(_.values(_.pick(m.attributes, ['bibcode', 'doi', 'identifier'])));
_.forEach(works, function (w) {
var wIds = _.flatten(_.values(w.getIdentifier()));
var wIds = _.flatten(_.values(w.getExternalIds()));
var idMatch = _.intersection(exIds, wIds).length > 0;

if (idMatch) {
Expand Down Expand Up @@ -362,7 +381,7 @@ function (
if (pagination.numFound !== result.length) {
_.extend(pagination, this.getPaginationInfo(apiResponse, docs));
}
_.delay(_.bind(this._updateModelsWithOrcid, this, 0), 1000);
_.delay(_.bind(this._updateModelsWithOrcid, this), 1000);
return result;
}
return docs;
Expand Down Expand Up @@ -425,7 +444,11 @@ function (
* @param {Work} fullOrcidWork - the full orcid work record
*/
var onRecieveFullOrcidWork = function (fullOrcidWork) {
var identifier = model.get('identifier');
var identifier = model.get('identifier')
|| fullOrcidWork.pickIdentifier(['bibcode', 'doi']);
if (!identifier) {
throw Error('Unable to determine suitable identifier');
}

var q = new ApiQuery({
q: 'identifier:' + queryUpdater.quoteIfNecessary(identifier),
Expand Down Expand Up @@ -485,7 +508,7 @@ function (
var success = function (profile) {
var works = profile.getWorks();
var matchedWork = _.find(works, function (w) {
var wIds = w.getIdentifier();
var wIds = w.getExternalIds();
var doi = _.any(exIds.doi, wIds.doi);

return exIds.bibcode === wIds.bibcode || doi;
Expand Down
Loading

0 comments on commit dfa5956

Please sign in to comment.