mirror of
https://github.com/nasa/openmct.git
synced 2025-05-21 09:47:38 +00:00
Incremental commit of duplication
This commit is contained in:
parent
fa3821b50f
commit
2a1388772a
@ -22,7 +22,7 @@
|
|||||||
"platform/features/events",
|
"platform/features/events",
|
||||||
"platform/forms",
|
"platform/forms",
|
||||||
"platform/identity",
|
"platform/identity",
|
||||||
"platform/persistence/local",
|
"platform/persistence/elastic",
|
||||||
"platform/persistence/queue",
|
"platform/persistence/queue",
|
||||||
"platform/policy",
|
"platform/policy",
|
||||||
"platform/entanglement",
|
"platform/entanglement",
|
||||||
|
@ -75,7 +75,8 @@
|
|||||||
"name": "Copy Service",
|
"name": "Copy Service",
|
||||||
"description": "Provides a service for copying objects",
|
"description": "Provides a service for copying objects",
|
||||||
"implementation": "services/CopyService.js",
|
"implementation": "services/CopyService.js",
|
||||||
"depends": ["$q", "creationService", "policyService"]
|
"depends": ["$q", "creationService", "policyService",
|
||||||
|
"persistenceService"]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"key": "locationService",
|
"key": "locationService",
|
||||||
|
@ -35,10 +35,11 @@ define(
|
|||||||
* @memberof platform/entanglement
|
* @memberof platform/entanglement
|
||||||
* @implements {platform/entanglement.AbstractComposeService}
|
* @implements {platform/entanglement.AbstractComposeService}
|
||||||
*/
|
*/
|
||||||
function CopyService($q, creationService, policyService) {
|
function CopyService($q, creationService, policyService, persistenceService) {
|
||||||
this.$q = $q;
|
this.$q = $q;
|
||||||
this.creationService = creationService;
|
this.creationService = creationService;
|
||||||
this.policyService = policyService;
|
this.policyService = policyService;
|
||||||
|
this.persistenceService = persistenceService;
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyService.prototype.validate = function (object, parentCandidate) {
|
CopyService.prototype.validate = function (object, parentCandidate) {
|
||||||
@ -61,15 +62,18 @@ define(
|
|||||||
* @param domainObject
|
* @param domainObject
|
||||||
*/
|
*/
|
||||||
function buildCopyGraph(domainObject, parent) {
|
function buildCopyGraph(domainObject, parent) {
|
||||||
var clonedModels = [];
|
var clones = [],
|
||||||
|
$q = this.$q;
|
||||||
|
|
||||||
function clone(object) {
|
function clone(object) {
|
||||||
return JSON.parse(JSON.stringify(object));
|
return JSON.parse(JSON.stringify(object));
|
||||||
}
|
}
|
||||||
|
|
||||||
function copy(object, parent) {
|
function copy(object, parent) {
|
||||||
|
var self = this;
|
||||||
var modelClone = clone(object.getModel());
|
var modelClone = clone(object.getModel());
|
||||||
modelClone.composition = [];
|
modelClone.composition = [];
|
||||||
|
|
||||||
if (domainObject.hasCapability('composition')) {
|
if (domainObject.hasCapability('composition')) {
|
||||||
return domainObject.useCapability('composition').then(function(composees){
|
return domainObject.useCapability('composition').then(function(composees){
|
||||||
return composees.reduce(function(promise, composee){
|
return composees.reduce(function(promise, composee){
|
||||||
@ -83,27 +87,37 @@ define(
|
|||||||
});
|
});
|
||||||
}, $q.when(undefined)).then(function (){
|
}, $q.when(undefined)).then(function (){
|
||||||
modelClone.id = uuid();
|
modelClone.id = uuid();
|
||||||
clonedModels.push(modelClone);
|
clones.push({persistence: parent.getCapability('persistence'), model: modelClone});
|
||||||
return modelClone;
|
return modelClone;
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
return Q.when(modelClone);
|
return $q.when(modelClone);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return copy(domainObject, parent).then(function(){
|
return copy(domainObject, parent).then(function(){
|
||||||
return clonedModels;
|
return clones;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function newPerform (domainObject, parent) {
|
function newPerform (domainObject, parent) {
|
||||||
return buildCopyGraph.then(function(clonedModels){
|
var $q = this.$q;
|
||||||
return clonedModels.reduce(function(promise, clonedModel){
|
if (this.validate(domainObject, parent)) {
|
||||||
|
return buildCopyGraph(domainObject, parent).then(function(clones){
|
||||||
|
return clones.reduce(function(promise, clone){
|
||||||
/*
|
/*
|
||||||
TODO: Persist the clone. We need to bypass the creation service on this because it wants to create the composition along the way, which we want to avoid. The composition has already been done directly in the model.
|
TODO: Persist the clone. We need to bypass the creation service on this because it wants to create the composition along the way, which we want to avoid. The composition has already been done directly in the model.
|
||||||
*/
|
*/
|
||||||
}, this.q.when(undefined));
|
promise.then(function(){
|
||||||
|
return this.persistenceService.createObject(clone.persistence.getSpace(), clone.model.id, clone.model);
|
||||||
|
});
|
||||||
|
}, $q.when(undefined));
|
||||||
})
|
})
|
||||||
|
} else {
|
||||||
|
throw new Error(
|
||||||
|
"Tried to copy objects without validating first."
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CopyService.prototype.perform = oldPerform;
|
CopyService.prototype.perform = oldPerform;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user