[Create] Utilize passed-in filter

...when determining which objects should be cloned.
This commit is contained in:
Victor Woeltjen 2016-02-10 13:38:53 -08:00
parent f602aa9247
commit 72df464f0f
2 changed files with 25 additions and 9 deletions

View File

@ -81,10 +81,23 @@ define(
* domainObject when the duplication is successful.
*/
CopyService.prototype.perform = function (domainObject, parent, filter) {
var $q = this.$q,
copyTask = new CopyTask(domainObject, parent, this.policyService, this.$q);
var policyService = this.policyService;
function completeFilter(domainObject) {
return (!filter || filter(domainObject)) &&
policyService.allow(
"creation",
domainObject.getCapability("type")
);
}
if (this.validate(domainObject, parent)) {
return copyTask.perform();
return new CopyTask(
domainObject,
parent,
completeFilter,
this.$q
).perform();
} else {
throw new Error(
"Tried to copy objects without validating first."

View File

@ -31,18 +31,21 @@ define(
* This class encapsulates the process of copying a domain object
* and all of its children.
*
* @param domainObject The object to copy
* @param parent The new location of the cloned object tree
* @param $q
* @param {DomainObject} domainObject The object to copy
* @param {DomainObject} parent The new location of the cloned object tree
* @param {platform/entanglement.CopyService~filter} filter
* a function used to filter out objects from
* the cloning process
* @param $q Angular's $q, for promises
* @constructor
*/
function CopyTask (domainObject, parent, policyService, $q){
function CopyTask (domainObject, parent, filter, $q){
this.domainObject = domainObject;
this.parent = parent;
this.firstClone = undefined;
this.$q = $q;
this.deferred = undefined;
this.policyService = policyService;
this.filter = filter;
this.persisted = 0;
this.clones = [];
this.idMap = {};
@ -198,7 +201,7 @@ define(
//Check if the type of the object being copied allows for
// creation of new instances. If it does not, then a link to the
// original will be created instead.
if (this.policyService.allow("creation", originalObject.getCapability("type"))){
if (this.filter(originalObject)) {
//create a new clone of the original object. Use the
// creation capability of the targetParent to create the
// new clone. This will ensure that the correct persistence