From 620c0415cf161a182fbf0e444b127e166b9effb0 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Fri, 28 Aug 2015 10:46:18 -0700 Subject: [PATCH] [Persistence] Use create from persistence capability ...when an object hasn't been previously persisted. This allows for compatibility with persistence services which disallow updates for nonexistent objects (which is not abnomal behavior.) nasa/openmctweb#92 --- .../core/src/capabilities/PersistenceCapability.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/platform/core/src/capabilities/PersistenceCapability.js b/platform/core/src/capabilities/PersistenceCapability.js index 8c7e08e17d..74a6bc52e7 100644 --- a/platform/core/src/capabilities/PersistenceCapability.js +++ b/platform/core/src/capabilities/PersistenceCapability.js @@ -72,7 +72,12 @@ define( */ PersistenceCapability.prototype.persist = function () { var domainObject = this.domainObject, - modified = domainObject.getModel().modified; + model = domainObject.getModel(), + modified = model.modified, + persistenceService = this.persistenceService, + persistenceFn = model.persisted !== undefined ? + this.persistenceService.updateObject : + this.persistenceService.createObject; // Update persistence timestamp... domainObject.useCapability("mutation", function (model) { @@ -80,11 +85,11 @@ define( }, modified); // ...and persist - return this.persistenceService.updateObject( + return persistenceFn.apply(persistenceService, [ this.getSpace(), domainObject.getId(), domainObject.getModel() - ); + ]); }; /**