server/bo_client/app/services/viaf-resolver.js
changeset 132 d97eda8bc8ec
parent 131 31a5c314d575
child 133 821253d361d1
--- 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));
-  }
-});