[Entanglement] Throw errors if validation is skipped

...per feedback from nasa/openmctweb#98
This commit is contained in:
Victor Woeltjen 2015-09-22 14:39:15 -07:00
parent ff24f06475
commit 119403e71c
3 changed files with 23 additions and 8 deletions

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

@ -53,15 +53,18 @@ define(
};
LinkService.prototype.perform = function (object, parentObject) {
// It is assumed here that validate has been called, and therefore
// that parentObject.hasCapability('composition').
var composition = parentObject.getCapability('composition');
if (!this.validate(object, parentObject)) {
throw new Error(
"Tried to link objects without validating first."
);
}
return composition.add(object).then(function (objectInNewContext) {
return parentObject.getCapability('persistence')
.persist()
.then(function () { return objectInNewContext; });
});
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)