--- a/common/corpus-common-addon/addon/utils/constants.js Thu Feb 25 11:21:09 2016 +0100
+++ b/common/corpus-common-addon/addon/utils/constants.js Thu Feb 25 12:24:30 2016 +0100
@@ -1,4 +1,5 @@
export const LEXVO_BASE_URL = "http://lexvo.org/id/iso639-3/";
+export const VIAF_BASE_URL = "http://viaf.org/viaf/";
export const DEFAULT_STORE_EXP = 3600000;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/common/corpus-common-addon/app/services/viaf-resolver.js Thu Feb 25 12:24:30 2016 +0100
@@ -0,0 +1,51 @@
+import Ember from 'ember';
+import store from 'corpus-common-addon/utils/store';
+import * as constants from 'corpus-common-addon/utils/constants'
+
+export default Ember.Service.extend({
+ env: function() {
+ return Ember.getOwner(this).resolveRegistration('config:environment')
+ },
+ _getStoreKey: function(id) {
+ return 'viaf:'+id;
+ },
+ getName: function(id) {
+ var viafId = id;
+ if(id.startsWith(constants.VIAF_BASE_URL)) {
+ viafId = id.slice(constants.VIAF_BASE_URL.length);
+ }
+ var storeKey = this._getStoreKey(id);
+ var namePromise = null;
+
+ var name = store.get(storeKey);
+ if(!name) {
+ //TODO: handle error !!!
+ namePromise = this.queryName(viafId)
+ .then( function(response) {
+ return store.set(storeKey, response);
+ });
+ }
+ else {
+ namePromise = new Ember.RSVP.Promise(function(resolve/*, reject*/) {
+ resolve(name);
+ });
+ }
+ return namePromise;
+ },
+ // make the query for the name.
+ // return a Promise
+ queryName: function(id) {
+ return new Ember.RSVP.Promise(function(resolve, reject) {
+ Ember.$.ajax({
+ url: this.env().baseURL.replace(/\/$/,"") + "/api/v1/viaf/"+id,
+ success: function(viafDoc) {
+ var names = viafDoc.viafids;
+ resolve((id in names)?names[id]:null);
+ },
+ error: function(req, status, error) {
+ reject(status + ":" + error);
+ }
+ });
+ }.bind(this));
+ }
+});
--- a/server/bo_client/app/services/viaf-resolver.js Thu Feb 25 11:21:09 2016 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,51 +0,0 @@
-import Ember from 'ember';
-import store from 'store';
-import ENV from 'bo-client/config/environment';
-
-// TODO: implement store layer with auto-expiration : c.f. https://github.com/marcuswestin/store.js/#no-sessionstorageauto-expiration
-export default Ember.Service.extend({
- constants: Ember.inject.service(),
- _getStoreKey: function(id) {
- return 'viaf:'+id;
- },
- getName: function(id) {
- var viafId = id;
- if(id.startsWith(this.get('constants').VIAF_BASE_URL)) {
- viafId = id.slice(this.get('constants').VIAF_BASE_URL.length);
- }
- var storeKey = this._getStoreKey(id);
- var namePromise = null;
-
- var name = store.get(storeKey);
- if(!name) {
- //TODO: handle error !!!
- namePromise = this.queryName(viafId)
- .then( function(response) {
- return store.set(storeKey, response);
- });
- }
- else {
- namePromise = new Ember.RSVP.Promise(function(resolve/*, reject*/) {
- resolve(name);
- });
- }
- return namePromise;
- },
- // make the query for the name.
- // return a Promise
- queryName: function(id) {
- return new Ember.RSVP.Promise(function(resolve, reject) {
- Ember.$.ajax({
- //TODO Configuration ?
- url: ENV.baseURL.replace(/\/$/,"") + "/api/v1/viaf/"+id,
- success: function(viafDoc) {
- var names = viafDoc.viafids;
- resolve((id in names)?names[id]:null);
- },
- error: function(req, status, error) {
- reject(status + ":" + error);
- }
- });
- }.bind(this));
- }
-});