mirror of
https://github.com/nasa/openmct.git
synced 2025-01-18 02:39:56 +00:00
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:
parent
d27f73579b
commit
e53399495b
@ -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);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -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"
|
||||
|
@ -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) {
|
||||
|
@ -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 {
|
||||
|
@ -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) {
|
||||
|
@ -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');
|
||||
|
Loading…
Reference in New Issue
Block a user