Merge remote-tracking branch 'github-open/open97' into open-master

This commit is contained in:
Pete Richards
2015-09-23 13:44:48 -07:00
18 changed files with 467 additions and 199 deletions

View File

@@ -32,7 +32,8 @@ define(
* @private
*/
/**
* Change the composition of the specified objects.
* Change the composition of the specified objects. Note that this
* should only be invoked after successfully validating.
*
* @param {DomainObject} domainObject the domain object to
* move, copy, or link.
@@ -43,7 +44,8 @@ define(
* @method platform/entanglement.AbstractComposeService#perform
*/
/**
* Check if one object can be composed into another.
* Check if this composition change is valid for these objects.
*
* @param {DomainObject} domainObject the domain object to
* move, copy, or link.
* @param {DomainObject} parent the domain object whose composition

View File

@@ -64,6 +64,12 @@ define(
return self.perform(domainObject, parent);
}
if (!this.validate(domainObject, parent)) {
throw new Error(
"Tried to copy objects without validating first."
);
}
if (domainObject.hasCapability('composition')) {
model.composition = [];
}

View File

@@ -45,6 +45,9 @@ define(
if (parentCandidate.getId() === object.getId()) {
return false;
}
if (!parentCandidate.hasCapability('composition')) {
return false;
}
if (parentCandidate.getModel().composition.indexOf(object.getId()) !== -1) {
return false;
}
@@ -56,26 +59,18 @@ define(
};
LinkService.prototype.perform = function (object, parentObject) {
function findChild(children) {
var i;
for (i = 0; i < children.length; i += 1) {
if (children[i].getId() === object.getId()) {
return children[i];
}
}
if (!this.validate(object, parentObject)) {
throw new Error(
"Tried to link objects without validating first."
);
}
return parentObject.useCapability('mutation', function (model) {
if (model.composition.indexOf(object.getId()) === -1) {
model.composition.push(object.getId());
}
}).then(function () {
return parentObject.getCapability('persistence').persist();
}).then(function getObjectWithNewContext() {
return parentObject
.useCapability('composition')
.then(findChild);
});
return parentObject.getCapability('composition').add(object)
.then(function (objectInNewContext) {
return parentObject.getCapability('persistence')
.persist()
.then(function () { return objectInNewContext; });
});
};
return LinkService;

View File

@@ -82,6 +82,12 @@ define(
}
}
if (!this.validate(object, parentObject)) {
throw new Error(
"Tried to move objects without validating first."
);
}
return this.linkService
.perform(object, parentObject)
.then(relocate)