Legacy and new object providers work together (#3461)

* Strip mct namespace from ids when getting models from cache

* Revert PersistenceCapability to use legacy code
Enforce empty namespace for LegacyPersistenceAdapter for new object providers

* Reverts change to caching provider

* CouchObject provider is registered with the mct space.
When saving objects via the persistence capability use the mct space to find the couchdb object provider
This commit is contained in:
Shefali Joshi
2020-10-19 10:17:18 -07:00
committed by GitHub
parent d27f73579b
commit e53399495b
6 changed files with 26 additions and 36 deletions

View File

@ -114,7 +114,12 @@ define(["objectUtils"],
var self = this, var self = this,
domainObject = this.domainObject; 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 return this.openmct.objects
.save(newStyleObject) .save(newStyleObject)
@ -146,6 +151,7 @@ define(["objectUtils"],
return domainObject.useCapability("mutation", function () { return domainObject.useCapability("mutation", function () {
return model; return model;
}, modified); }, modified);
} }
} }
@ -153,11 +159,10 @@ define(["objectUtils"],
return this.$q.when(true); return this.$q.when(true);
} }
return this.openmct.objects.get(domainObject.getId()).then((newStyleObject) => { return this.persistenceService.readObject(
let oldStyleObject = this.openmct.legacyObject(newStyleObject); this.getSpace(),
this.getKey()
return updateModel(oldStyleObject.getModel()); ).then(updateModel);
});
}; };
/** /**

View File

@ -37,7 +37,6 @@ define(
key = "persistence key", key = "persistence key",
id = "object identifier", id = "object identifier",
model, model,
refreshModel,
SPACE = "some space", SPACE = "some space",
persistence, persistence,
mockOpenMCT, mockOpenMCT,
@ -61,7 +60,6 @@ define(
someKey: "some value", someKey: "some value",
name: "domain object" name: "domain object"
}; };
refreshModel = {someOtherKey: "some other value"};
mockPersistenceService = jasmine.createSpyObj( mockPersistenceService = jasmine.createSpyObj(
"persistenceService", "persistenceService",
@ -101,8 +99,8 @@ define(
mockNewStyleDomainObject = Object.assign({}, model); mockNewStyleDomainObject = Object.assign({}, model);
mockNewStyleDomainObject.identifier = { mockNewStyleDomainObject.identifier = {
namespace: "", namespace: SPACE,
key: id key: key
}; };
// Simulate mutation capability // Simulate mutation capability
@ -112,16 +110,8 @@ define(
} }
}); });
mockOpenMCT = { mockOpenMCT = {};
legacyObject: function (object) { mockOpenMCT.objects = jasmine.createSpyObj('Object API', ['save']);
return {
getModel: function () {
return object;
}
};
}
};
mockOpenMCT.objects = jasmine.createSpyObj('Object API', ['save', 'get']);
mockIdentifierService.parse.and.returnValue(mockIdentifier); mockIdentifierService.parse.and.returnValue(mockIdentifier);
mockIdentifier.getSpace.and.returnValue(SPACE); mockIdentifier.getSpace.and.returnValue(SPACE);
@ -141,7 +131,6 @@ define(
describe("successful persistence", function () { describe("successful persistence", function () {
beforeEach(function () { beforeEach(function () {
mockOpenMCT.objects.save.and.returnValue(Promise.resolve(true)); 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 () { it("creates unpersisted objects with the persistence service", function () {
// Verify precondition; no call made during constructor // Verify precondition; no call made during constructor
@ -157,10 +146,11 @@ define(
}); });
it("refreshes the domain object model from persistence", function () { it("refreshes the domain object model from persistence", function () {
var refreshModel = {someOtherKey: "some other value"};
model.persisted = 1; model.persisted = 1;
persistence.refresh().then(() => { mockPersistenceService.readObject.and.returnValue(asPromise(refreshModel));
expect(model).toEqual(refreshModel); persistence.refresh();
}); expect(model).toEqual(refreshModel);
}); });
it("does not trigger error notification on successful" it("does not trigger error notification on successful"

View File

@ -129,13 +129,6 @@ define([
ObjectServiceProvider.prototype.get = function (key) { ObjectServiceProvider.prototype.get = function (key) {
let keyString = utils.makeKeyString(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]) return this.objectService.getObjects([keyString])
.then(function (results) { .then(function (results) {

View File

@ -86,7 +86,10 @@ export default class CouchObjectProvider {
this.objectQueue[key] = new CouchObjectQueue(undefined, response[REV]); 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; return object;
} else { } else {

View File

@ -22,7 +22,7 @@
import CouchObjectProvider from './CouchObjectProvider'; import CouchObjectProvider from './CouchObjectProvider';
const NAMESPACE = ''; const NAMESPACE = '';
const PERSISTENCE_SPACE = ''; const PERSISTENCE_SPACE = 'mct';
export default function CouchPlugin(url) { export default function CouchPlugin(url) {
return function install(openmct) { return function install(openmct) {

View File

@ -31,19 +31,18 @@ describe('the plugin', () => {
let element; let element;
let child; let child;
let provider; let provider;
let testSpace = 'testSpace';
let testPath = '/test/db'; let testPath = '/test/db';
let mockDomainObject; let mockDomainObject;
beforeEach((done) => { beforeEach((done) => {
mockDomainObject = { mockDomainObject = {
identifier: { identifier: {
namespace: '', namespace: 'mct',
key: 'some-value' key: 'some-value'
} }
}; };
openmct = createOpenMct(false); openmct = createOpenMct(false);
openmct.install(new CouchPlugin(testSpace, testPath)); openmct.install(new CouchPlugin(testPath));
element = document.createElement('div'); element = document.createElement('div');
child = document.createElement('div'); child = document.createElement('div');