-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to ORCiD 2.0 #1269
Upgrade to ORCiD 2.0 #1269
Conversation
* Major rewrite of logic for api * Updated to work with ORCiD 2.0 api * Offloaded all logic dealing with parsing/formatting to new Work and Profile classes
* Adds helper classes that deal with the parsing and formatting of ORCiD works * Hopefully easier to maintain, since all entries are now xpath-based
* Converts the extension over to the new api * Rewrite of handlers for orcid actions * Alters some of the logic dealing with updating the ui
*Work In Progress* * Some tests disabled/commented while they are being converted * Most tests are working * Added simple tests for new classes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i really like your PR, great work!
i've found few issues (of little significance); the only important one would be to udpate the unittests - orcid is quite tricky and before we can merge it should be well tested (for example, the api limits of 5000 characters - it used to be orcid throwing error; maybe it is not the case any more - but stuff like that is important)
|
||
get(0, 'update').click(); | ||
get(1, 'delete').click(); | ||
get(2, 'add').click(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
github shows me not enough context; but it seems like you concentrated 3 actions into one spot; the idea was to click 'update' and verify, then click 'delete' and verify....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah those need to be written out better, the three button clicks are different actions, but right after that it checks to see how many times the merge records method was called (should be once). There is a lot more that needs to be checked here though, I'd like to test for fails as well.
|
||
describe('Instantiation', function () { | ||
it('instantiates correctly', function () { | ||
expect(new Profile() instanceof Profile).to.equal(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this suite should be extended
|
||
describe('Instantiation', function () { | ||
it('instantiates correctly', function () { | ||
expect(new Work({}) instanceof Work).to.equal(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
dtto - but i guess that's your plan
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, I will add in these tests.
src/js/modules/orcid/orcid_api.js
Outdated
} | ||
}); | ||
return ret.promise(); | ||
checkAccessOrcidApiAccess: function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one significan tchange i see here is that authData is missing; i don't recall - whether it was ever needed (to pass a different token), but i'm assuming it was there for a reason (could be wrong)
src/js/modules/orcid/orcid_api.js
Outdated
} | ||
return false; | ||
return !!(this.authData); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pls double check authData always has '.expires'
src/js/modules/orcid/orcid_api.js
Outdated
} | ||
|
||
var url = this.getUrl('works', putcode); | ||
return this.createRequest(url, { method: 'PUT' }, work); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it is better to remove promises (universally) for any methods that do add/update/delete work; here you are returning the request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying that the api shouldn't return anything on these requests? or should I be return more generic replies? like this:
var promise = $.Deferred();
request(...).done(function (status) {
if (status === 201) {
promise.resolve();
} else {
promise.reject();
}
}).fail(function (status) {
promise.reject();
});
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
im sorry! i wanted to write: "better to return promises" universally
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ohh! okay yeah that makes sense. Actually in this case it does do that. createRequest
is just a convenience wrapper around the call to sendData
--> https://github.com/adsabs/bumblebee/pull/1269/files#diff-b88a44bee5c5ab37fb8be1b927cde460R332
There may be a cleaner way of doing it though, I think it makes sense to fail here for status codes that don't make sense than to force the caller to handle the response.
src/js/modules/orcid/orcid_api.js
Outdated
this.getWorks() | ||
.done(function (orcidWorks) { | ||
_.forEach(works, function (w) { | ||
var entry = self.addCache.pop(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
question: is it guaranteed that the cache will have the same size/order or elements as the response from orcid? can multiple requests/user actions cause multiple requests?
src/js/modules/orcid/orcid_api.js
Outdated
_buildQuery: function (query) { | ||
var formatString = function (values, field) { | ||
if (values.length === 0) { | ||
return ''; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that would be empty query -> syntax error; better not even send it to the api
src/js/modules/orcid/orcid_api.js
Outdated
_.forEach(works, function addIdsToDatabase(w, i) { | ||
var key; | ||
var ids = w.getExternalIds(); | ||
if (ids.bibcode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
solr now has a field called 'identifier' - it will search across multiple identifiers; so a query
bibcode:foo OR alternate_bibcode:foo OR doi:foo
can be replaced with:
identifier:foo
not sure why the old api didn't do that (maybe the identifier was not populated properly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okay yeah that confused me a bit, I'll make that change it should make things a little easier
src/js/modules/orcid/extension.js
Outdated
var works = profile.getWorks(); | ||
var matchedWork = _.find(works, function (w) { | ||
var wIds = w.getExternalIds(); | ||
return exIds.bibcode === wIds.bibcode || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bibcode can be only one; but doi and alternate_bibcodes are multivalued - so why check only the first element? ;)
* Add check for expires on authdata to ensure that it is present * Check access for orcid, now will also check if authdata is up to date * Add checks for empty query string to not send useless queries to solr * Remove use of `bibcode:xxx OR alternate_bibcode:xxx` queries for the `identifier:xxx` kind
* Better descriptions, jsdoc cleanup * Moved debounce calls into activation to help with testing
e4cde0c
to
208b14a
Compare
208b14a
to
79da3f8
Compare
@romanchyla this guy is ready for you to check out again. I fixed, or altered the areas you mentioned. Some of the tests I've updated. Also, I was able to figure out a good way to keep track of the right entries in the cache. I am passing along a unique id that rides the request, then I'm able to compare it afterwards to make sure it resolves the appropriate deferred. I wasn't able to figure out a good way to gracefully fail after a bad addWorks request, yet... right now if you were to pass in say 300 at once, it would make 3 total requests, if request 2 failed then jquery short-circuits and calls the fail block right away. But if 1 and 2 succeeded we wouldn't know. Probably should refactor to handle that case, especially if the plan is to allow adding in bulk. Thanks! |
d8955d9
to
79da3f8
Compare
global variables are usually bad and most likely my ignorance of sinon framework made me use one for the tests. i'm glad it's gone :) for addWorks failures; if some simple solution is not applicable - such as .done() and chaining of promises, then you could consider using sentinel values; maybe like adding an entry into the cache and removing it after the request finished; if you find some entry there, then you would know the batch failed |
Work in progress
Functionally complete, at least afaik, I need testers to check things out and make sure that everything is working like it did in prod, and whether there are areas to improve.
This is a big update, most of the changes are in Orcid_api and Extension
The orcid api actions portion was completely rewritten
extension
Work/Profile
Thoughts
source_name
part for now, until I can find a use case for the changes.