common/corpus-common-addon/app/services/viaf-resolver.js
changeset 182 1bcc373adabb
parent 132 d97eda8bc8ec
child 305 ff6cf3fc5f40
--- a/common/corpus-common-addon/app/services/viaf-resolver.js	Wed Jun 08 21:40:22 2016 +0200
+++ b/common/corpus-common-addon/app/services/viaf-resolver.js	Thu Jun 09 17:11:14 2016 +0200
@@ -1,51 +1,26 @@
-import Ember from 'ember';
-import store from 'corpus-common-addon/utils/store';
-import * as constants from 'corpus-common-addon/utils/constants'
+import * as constants from 'corpus-common-addon/utils/constants';
+
+import ResolverService from 'corpus-common-addon/services/resolver-service';
 
-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;
+export default ResolverService.extend({
+
+    storeKeyBase: 'viaf',
+    apiPath:  '/api/v1/viaf/',
+    resDocRoot: 'viafids',
 
-    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);
+    init() {
+        this._super(...arguments);
+        console.log("VIAF", this);
+    },
+
+    processId: function(id) {
+        var viafId = id;
+        if(id.startsWith(constants.VIAF_BASE_URL)) {
+            viafId = id.slice(constants.VIAF_BASE_URL.length);
         }
-      });
-    }.bind(this));
-  }
+        return viafId;
+    },
+
+    getReturnDictKey: function(id) { return id; }
+
 });