From 72df464f0ff31bfc20d50f1e2849ce0097551295 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Wed, 10 Feb 2016 13:38:53 -0800 Subject: [PATCH] [Create] Utilize passed-in filter ...when determining which objects should be cloned. --- .../entanglement/src/services/CopyService.js | 19 ++++++++++++++++--- .../entanglement/src/services/CopyTask.js | 15 +++++++++------ 2 files changed, 25 insertions(+), 9 deletions(-) diff --git a/platform/entanglement/src/services/CopyService.js b/platform/entanglement/src/services/CopyService.js index 7cdd769018..0df33de71c 100644 --- a/platform/entanglement/src/services/CopyService.js +++ b/platform/entanglement/src/services/CopyService.js @@ -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." diff --git a/platform/entanglement/src/services/CopyTask.js b/platform/entanglement/src/services/CopyTask.js index 1c4a27c620..15407f6db1 100644 --- a/platform/entanglement/src/services/CopyTask.js +++ b/platform/entanglement/src/services/CopyTask.js @@ -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