mirror of
https://github.com/nasa/openmct.git
synced 2025-06-16 22:28:13 +00:00
[Creation] Use creation capability
...from creationService to initially instantiate a domain object before persisting it.
This commit is contained in:
@ -159,7 +159,7 @@
|
|||||||
"provides": "creationService",
|
"provides": "creationService",
|
||||||
"type": "provider",
|
"type": "provider",
|
||||||
"implementation": "creation/CreationService.js",
|
"implementation": "creation/CreationService.js",
|
||||||
"depends": [ "persistenceService", "now", "$q", "$log" ]
|
"depends": [ "$q", "$log" ]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"runs": [
|
"runs": [
|
||||||
|
@ -42,11 +42,9 @@ define(
|
|||||||
* @memberof platform/commonUI/browse
|
* @memberof platform/commonUI/browse
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
function CreationService(persistenceService, now, $q, $log) {
|
function CreationService($q, $log) {
|
||||||
this.persistenceService = persistenceService;
|
|
||||||
this.$q = $q;
|
this.$q = $q;
|
||||||
this.$log = $log;
|
this.$log = $log;
|
||||||
this.now = now;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -70,19 +68,10 @@ define(
|
|||||||
*/
|
*/
|
||||||
CreationService.prototype.createObject = function (model, parent) {
|
CreationService.prototype.createObject = function (model, parent) {
|
||||||
var persistence = parent.getCapability("persistence"),
|
var persistence = parent.getCapability("persistence"),
|
||||||
|
newObject = parent.useCapability("creation", model),
|
||||||
|
newObjectPersistence = newObject.getCapability("persistence"),
|
||||||
self = this;
|
self = this;
|
||||||
|
|
||||||
// Persist the new domain object's model; it will be fully
|
|
||||||
// constituted as a domain object when loaded back, as all
|
|
||||||
// domain object models are.
|
|
||||||
function doPersist(space, id, model) {
|
|
||||||
return self.persistenceService.createObject(
|
|
||||||
space,
|
|
||||||
id,
|
|
||||||
model
|
|
||||||
).then(function () { return id; });
|
|
||||||
}
|
|
||||||
|
|
||||||
// Add the newly-created object's id to the parent's
|
// Add the newly-created object's id to the parent's
|
||||||
// composition, so that it will subsequently appear
|
// composition, so that it will subsequently appear
|
||||||
// as a child contained by that parent.
|
// as a child contained by that parent.
|
||||||
@ -105,7 +94,7 @@ define(
|
|||||||
|
|
||||||
// We need the parent's persistence capability to determine
|
// We need the parent's persistence capability to determine
|
||||||
// what space to create the new object's model in.
|
// what space to create the new object's model in.
|
||||||
if (!persistence) {
|
if (!persistence || !newObjectPersistence) {
|
||||||
self.$log.warn(NON_PERSISTENT_WARNING);
|
self.$log.warn(NON_PERSISTENT_WARNING);
|
||||||
return self.$q.reject(new Error(NON_PERSISTENT_WARNING));
|
return self.$q.reject(new Error(NON_PERSISTENT_WARNING));
|
||||||
}
|
}
|
||||||
@ -114,10 +103,8 @@ define(
|
|||||||
// 1. Get a new UUID for the object
|
// 1. Get a new UUID for the object
|
||||||
// 2. Create a model with that ID in the persistence space
|
// 2. Create a model with that ID in the persistence space
|
||||||
// 3. Add that ID to
|
// 3. Add that ID to
|
||||||
return self.$q.when(uuid()).then(function (id) {
|
return newObjectPersistence.persist().then(function () {
|
||||||
model.persisted = self.now();
|
var id = newObject.getId();
|
||||||
return doPersist(persistence.getSpace(), id, model);
|
|
||||||
}).then(function (id) {
|
|
||||||
return addToComposition(id, parent, persistence);
|
return addToComposition(id, parent, persistence);
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user