Skip to content

Commit

Permalink
Support nameIdentifier. #158
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fenner committed Mar 12, 2019
1 parent 914dfaa commit d1fdf10
Show file tree
Hide file tree
Showing 6 changed files with 119 additions and 3 deletions.
26 changes: 26 additions & 0 deletions app/adapters/person.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import DS from 'ember-data';
import DataAdapterMixin from 'ember-simple-auth/mixins/data-adapter-mixin';
import ENV from 'bracco/config/environment';

const { JSONAPIAdapter } = DS;

export default JSONAPIAdapter.extend(DataAdapterMixin, {
host: ENV.ORCID_API_URL,

init() {
this._super(...arguments);

this.set('headers', {
'Content-Type': 'application/json',
'Accept': 'application/json'
});
},

pathForType() {
return 'v2.1';
},

authorize() {

}
});
2 changes: 1 addition & 1 deletion app/components/client-show.js
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export default Component.extend({
console.log(reason);
});
},
searchRepository(query) {
searchy(query) {
this.set('repositories', this.store.query('repository', { 'query': query, 'page[size]': 25 }));
},
selectRepository(repository) {
Expand Down
63 changes: 61 additions & 2 deletions app/components/doi-name-identifier.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
import Component from '@ember/component';
import { inject as service } from '@ember/service';
import { validator, buildValidations } from 'ember-cp-validations';
import { computed } from '@ember/object';

const Validations = buildValidations({
'fragment.nameIdentifier': [
validator('format', {
regex: /(http|https|ftp):\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_+.~#?&//=]*)/,
allowBlank: true,
message: 'Please enter a name identifier in URL format.'
}),
validator('presence', {
presence: true,
isWarning: computed('model.state', 'model.prefix', function () {
return (this.get('model.state') === 'draft' || this.get('model.prefix') === '10.5072');
})
})
],
});

const nameIdentifierSchemeList = [
'ISNI',
Expand All @@ -16,9 +35,26 @@ const schemeUriList = {
ror: 'https://ror.org'
};

export default Component.extend({
export default Component.extend(Validations, {
store: service(),

nameIdentifierSchemeList,
nameIdentifierSchemes: nameIdentifierSchemeList,
errorMessage: computed('validations.messages', function () {
if (this.get('validations.messages').length > 0) {
return this.get('validations.messages').get('firstObject');
} else {
return null;
}
}),

validateOrcidIdentifier(id) {
let self = this;
this.store.findRecord('person', id).then(function(person) {
console.log(person)
return person;
});
},

actions: {
searchNameIdentifierScheme(query) {
Expand All @@ -33,7 +69,30 @@ export default Component.extend({
this.set('nameIdentifierSchemes', nameIdentifierSchemeList);
},
updateNameIdentifier(value) {
this.fragment.set('nameIdentifier', value);
if (value.startsWith('https://orcid.org') || value.startsWith('http://orcid.org')) {
let id = value.substr(value.indexOf('0'));
this.fragment.set('schemeUri', 'https://orcid.org');
this.fragment.set('nameIdentifierScheme', 'ORCID');
this.fragment.set('nameIdentifier', 'https://orcid.org/' + id);

// this.validateOrcidIdentifier(id);

} else if (value.startsWith('http://isni.org')) {
let id = value.substr(value.indexOf('0'));

this.fragment.set('schemeUri', 'http://isni.org');
this.fragment.set('nameIdentifierScheme', 'ISNI');
this.fragment.set('nameIdentifier', id);
} else if (value.startsWith('https://ror.org')) {
let id = value.substr(value.indexOf('0'));

this.fragment.set('schemeUri', 'https://ror.org');
this.fragment.set('nameIdentifierScheme', 'ROR');
this.fragment.set('nameIdentifier', id);
} else {
this.fragment.set('nameIdentifierScheme', 'Other');
this.fragment.set('nameIdentifier', value);
}
this.setIsValidating(false);
this.setHasErrors(false);
},
Expand Down
10 changes: 10 additions & 0 deletions app/models/person.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import DS from 'ember-data';

export default DS.Model.extend({
meta: DS.attr(),

identifier: DS.attr('string'),
creditName: DS.attr('string'),
givenNames: DS.attr('string', { defaultValue: null }),
familyName: DS.attr('string', { defaultValue: null })
});
20 changes: 20 additions & 0 deletions app/serializers/person.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { underscore } from '@ember/string';
// import { assign } from '@ember/polyfills';
import DS from 'ember-data';

export default DS.JSONSerializer.extend({
normalizeSingleResponse(store, primaryModelClass, payload, id, requestType) {
// strip "https://" from id
console.log(payload)
payload.id = payload.id.substr(8);
return this._super(store, primaryModelClass, payload, id, requestType);
},
// normalizeFindRecordResponse(store, primaryModelClass, payload) {
// payload.data.attributes.meta = payload.meta || {};

// return this._super(store, primaryModelClass, payload);
// },
keyForAttribute(attr) {
return underscore(attr);
}
});
1 change: 1 addition & 0 deletions config/environment.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ module.exports = function(environment) {
API_URL: process.env.API_URL || "https://api.test.datacite.org",
RE3DATA_API_URL: process.env.RE3DATA_API_URL || "https://api.test.datacite.org",
ROR_API_URL: process.env.ROR_API_URL || "https://api.ror.org",
ORCID_API_URL: process.env.ORCID_API_URL || "https://pub.orcid.org",
EVENTDATA_URL: process.env.EVENTDATA_URL || "https://api.test.datacite.org",
CDN_URL: process.env.CDN_URL || "https://assets.test.datacite.org",
JWT_PUBLIC_KEY: process.env.JWT_PUBLIC_KEY || null,
Expand Down

0 comments on commit d1fdf10

Please sign in to comment.