diff --git a/platform/core/src/capabilities/PersistenceCapability.js b/platform/core/src/capabilities/PersistenceCapability.js index f67b8145e6..7c32608a99 100644 --- a/platform/core/src/capabilities/PersistenceCapability.js +++ b/platform/core/src/capabilities/PersistenceCapability.js @@ -114,7 +114,12 @@ define(["objectUtils"], var self = this, domainObject = this.domainObject; - let newStyleObject = objectUtils.toNewFormat(domainObject.getModel(), domainObject.getId()); + const identifier = { + namespace: this.getSpace(), + key: this.getKey() + }; + + let newStyleObject = objectUtils.toNewFormat(domainObject.getModel(), identifier); return this.openmct.objects .save(newStyleObject) @@ -146,6 +151,7 @@ define(["objectUtils"], return domainObject.useCapability("mutation", function () { return model; }, modified); + } } @@ -153,11 +159,10 @@ define(["objectUtils"], return this.$q.when(true); } - return this.openmct.objects.get(domainObject.getId()).then((newStyleObject) => { - let oldStyleObject = this.openmct.legacyObject(newStyleObject); - - return updateModel(oldStyleObject.getModel()); - }); + return this.persistenceService.readObject( + this.getSpace(), + this.getKey() + ).then(updateModel); }; /** diff --git a/platform/core/test/capabilities/PersistenceCapabilitySpec.js b/platform/core/test/capabilities/PersistenceCapabilitySpec.js index 07733be3d2..ae5ef99689 100644 --- a/platform/core/test/capabilities/PersistenceCapabilitySpec.js +++ b/platform/core/test/capabilities/PersistenceCapabilitySpec.js @@ -37,7 +37,6 @@ define( key = "persistence key", id = "object identifier", model, - refreshModel, SPACE = "some space", persistence, mockOpenMCT, @@ -61,7 +60,6 @@ define( someKey: "some value", name: "domain object" }; - refreshModel = {someOtherKey: "some other value"}; mockPersistenceService = jasmine.createSpyObj( "persistenceService", @@ -101,8 +99,8 @@ define( mockNewStyleDomainObject = Object.assign({}, model); mockNewStyleDomainObject.identifier = { - namespace: "", - key: id + namespace: SPACE, + key: key }; // Simulate mutation capability @@ -112,16 +110,8 @@ define( } }); - mockOpenMCT = { - legacyObject: function (object) { - return { - getModel: function () { - return object; - } - }; - } - }; - mockOpenMCT.objects = jasmine.createSpyObj('Object API', ['save', 'get']); + mockOpenMCT = {}; + mockOpenMCT.objects = jasmine.createSpyObj('Object API', ['save']); mockIdentifierService.parse.and.returnValue(mockIdentifier); mockIdentifier.getSpace.and.returnValue(SPACE); @@ -141,7 +131,6 @@ define( describe("successful persistence", function () { beforeEach(function () { mockOpenMCT.objects.save.and.returnValue(Promise.resolve(true)); - mockOpenMCT.objects.get.and.returnValue(Promise.resolve(refreshModel)); }); it("creates unpersisted objects with the persistence service", function () { // Verify precondition; no call made during constructor @@ -157,10 +146,11 @@ define( }); it("refreshes the domain object model from persistence", function () { + var refreshModel = {someOtherKey: "some other value"}; model.persisted = 1; - persistence.refresh().then(() => { - expect(model).toEqual(refreshModel); - }); + mockPersistenceService.readObject.and.returnValue(asPromise(refreshModel)); + persistence.refresh(); + expect(model).toEqual(refreshModel); }); it("does not trigger error notification on successful" diff --git a/src/adapter/services/LegacyObjectAPIInterceptor.js b/src/adapter/services/LegacyObjectAPIInterceptor.js index 79b1315ffb..af9545078a 100644 --- a/src/adapter/services/LegacyObjectAPIInterceptor.js +++ b/src/adapter/services/LegacyObjectAPIInterceptor.js @@ -129,13 +129,6 @@ define([ ObjectServiceProvider.prototype.get = function (key) { let keyString = utils.makeKeyString(key); - const space = this.getSpace(keyString); - - let identifier = utils.parseKeyString(keyString); - // We assign to the space for legacy persistence providers since they register themselves using a defaultSpace. - // This is the way to make everyone happy. - identifier.namespace = space; - keyString = utils.makeKeyString(identifier); return this.objectService.getObjects([keyString]) .then(function (results) { diff --git a/src/plugins/persistence/couch/CouchObjectProvider.js b/src/plugins/persistence/couch/CouchObjectProvider.js index 64dfe88c7e..1df673eb7b 100644 --- a/src/plugins/persistence/couch/CouchObjectProvider.js +++ b/src/plugins/persistence/couch/CouchObjectProvider.js @@ -86,7 +86,10 @@ export default class CouchObjectProvider { this.objectQueue[key] = new CouchObjectQueue(undefined, response[REV]); } - this.objectQueue[key].updateRevision(response[REV]); + //Sometimes CouchDB returns the old rev which fetching the object if there is a document update in progress + if (!this.objectQueue[key].pending) { + this.objectQueue[key].updateRevision(response[REV]); + } return object; } else { diff --git a/src/plugins/persistence/couch/plugin.js b/src/plugins/persistence/couch/plugin.js index 4b3d160739..0851972e15 100644 --- a/src/plugins/persistence/couch/plugin.js +++ b/src/plugins/persistence/couch/plugin.js @@ -22,7 +22,7 @@ import CouchObjectProvider from './CouchObjectProvider'; const NAMESPACE = ''; -const PERSISTENCE_SPACE = ''; +const PERSISTENCE_SPACE = 'mct'; export default function CouchPlugin(url) { return function install(openmct) { diff --git a/src/plugins/persistence/couch/pluginSpec.js b/src/plugins/persistence/couch/pluginSpec.js index e2fd2b6437..364da70cef 100644 --- a/src/plugins/persistence/couch/pluginSpec.js +++ b/src/plugins/persistence/couch/pluginSpec.js @@ -31,19 +31,18 @@ describe('the plugin', () => { let element; let child; let provider; - let testSpace = 'testSpace'; let testPath = '/test/db'; let mockDomainObject; beforeEach((done) => { mockDomainObject = { identifier: { - namespace: '', + namespace: 'mct', key: 'some-value' } }; openmct = createOpenMct(false); - openmct.install(new CouchPlugin(testSpace, testPath)); + openmct.install(new CouchPlugin(testPath)); element = document.createElement('div'); child = document.createElement('div');