[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); return self.perform(domainObject, parent);
} }
if (!this.validate(domainObject, parent)) {
throw new Error(
"Tried to copy objects without validating first."
);
}
if (domainObject.hasCapability('composition')) { if (domainObject.hasCapability('composition')) {
model.composition = []; model.composition = [];
} }

View File

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