All test cases passing + added test cases for copy
This commit is contained in:
@@ -35,11 +35,12 @@ define(
|
||||
* @memberof platform/entanglement
|
||||
* @implements {platform/entanglement.AbstractComposeService}
|
||||
*/
|
||||
function CopyService($q, creationService, policyService, persistenceService) {
|
||||
function CopyService($q, creationService, policyService, persistenceService, now) {
|
||||
this.$q = $q;
|
||||
this.creationService = creationService;
|
||||
this.policyService = policyService;
|
||||
this.persistenceService = persistenceService;
|
||||
this.now = now;
|
||||
}
|
||||
|
||||
CopyService.prototype.validate = function (object, parentCandidate) {
|
||||
@@ -95,16 +96,15 @@ define(
|
||||
}
|
||||
delete modelClone.model.composition;
|
||||
delete modelClone.model.location;
|
||||
delete modelClone.model.persisted;
|
||||
delete modelClone.model.modified;
|
||||
return $q.when(originalObject.useCapability('composition')).then(function(composees){
|
||||
console.log("composees: " + composees);
|
||||
return (composees || []).reduce(function(promise, composee){
|
||||
console.log("inside reduce");
|
||||
//If the object is composed of other
|
||||
// objects, chain a promise..
|
||||
return promise.then(function(){
|
||||
// ...to recursively copy it (and its children)
|
||||
return copy(composee, originalObject).then(function(composeeClone){
|
||||
console.log("Composing clone");
|
||||
//Once copied, associate each cloned
|
||||
// composee with its parent clone
|
||||
composeeClone.model.location = modelClone.id;
|
||||
@@ -113,7 +113,6 @@ define(
|
||||
});
|
||||
});}, $q.when(undefined)
|
||||
).then(function (){
|
||||
console.log("Adding clone to list");
|
||||
//Add the clone to the list of clones that will
|
||||
//be returned by this function
|
||||
clones.push(modelClone);
|
||||
@@ -122,7 +121,6 @@ define(
|
||||
});
|
||||
};
|
||||
return copy(domainObject, parent).then(function(){
|
||||
console.log("Done cloning, returning");
|
||||
return clones;
|
||||
});
|
||||
}
|
||||
@@ -140,13 +138,13 @@ define(
|
||||
var persisted = 0,
|
||||
self = this;
|
||||
return function(objectClones) {
|
||||
console.log("Persisting " + objectClones.length + " clones");
|
||||
return self.$q.all(objectClones.map(function(clone, index){
|
||||
clone.model.persisted = self.now();
|
||||
return self.persistenceService.createObject(clone.persistenceSpace, clone.id, clone.model)
|
||||
.then(function(){
|
||||
progress && progress("copying", objectClones.length, ++persisted);
|
||||
});
|
||||
})).then(function(qall){
|
||||
})).then(function(){
|
||||
return objectClones
|
||||
});
|
||||
}
|
||||
@@ -170,8 +168,10 @@ define(
|
||||
|
||||
return self.persistenceService
|
||||
.updateObject(parentClone.persistenceSpace, parentClone.id, parentClone.model)
|
||||
.then(function(){return parent.getCapability('composition').add(parentClone.id)})
|
||||
.then(function(){return parent.getCapability("persistence").persist()});
|
||||
.then(function(){return parent.getCapability("composition").add(parentClone.id)})
|
||||
.then(function(){return parent.getCapability("persistence").persist()})
|
||||
.then(function(){return parentClone});
|
||||
// Ensure the clone of the original domainObject is returned
|
||||
}
|
||||
}
|
||||
|
||||
@@ -181,8 +181,8 @@ define(
|
||||
* @param domainObject
|
||||
* @param parent
|
||||
* @param progress
|
||||
* @returns a promise that will be completed when the duplication is
|
||||
* successful, otherwise an error is thrown.
|
||||
* @returns a promise that will be completed with the clone of
|
||||
* domainObject when the duplication is successful.
|
||||
*/
|
||||
CopyService.prototype.perform = function (domainObject, parent, progress) {
|
||||
var $q = this.$q;
|
||||
|
||||
Reference in New Issue
Block a user