[Creation] Use creation capability

...from creationService to initially instantiate a domain object
before persisting it.
This commit is contained in:
Victor Woeltjen 2015-11-05 15:13:33 -08:00
parent 474afdf8ef
commit 331b4e9259
2 changed files with 7 additions and 20 deletions

View File

@ -159,7 +159,7 @@
"provides": "creationService",
"type": "provider",
"implementation": "creation/CreationService.js",
"depends": [ "persistenceService", "now", "$q", "$log" ]
"depends": [ "$q", "$log" ]
}
],
"runs": [

View File

@ -42,11 +42,9 @@ define(
* @memberof platform/commonUI/browse
* @constructor
*/
function CreationService(persistenceService, now, $q, $log) {
this.persistenceService = persistenceService;
function CreationService($q, $log) {
this.$q = $q;
this.$log = $log;
this.now = now;
}
/**
@ -70,19 +68,10 @@ define(
*/
CreationService.prototype.createObject = function (model, parent) {
var persistence = parent.getCapability("persistence"),
newObject = parent.useCapability("creation", model),
newObjectPersistence = newObject.getCapability("persistence"),
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
// composition, so that it will subsequently appear
// as a child contained by that parent.
@ -105,7 +94,7 @@ define(
// We need the parent's persistence capability to determine
// what space to create the new object's model in.
if (!persistence) {
if (!persistence || !newObjectPersistence) {
self.$log.warn(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
// 2. Create a model with that ID in the persistence space
// 3. Add that ID to
return self.$q.when(uuid()).then(function (id) {
model.persisted = self.now();
return doPersist(persistence.getSpace(), id, model);
}).then(function (id) {
return newObjectPersistence.persist().then(function () {
var id = newObject.getId();
return addToComposition(id, parent, persistence);
});
};