[Persistence] Use identifier service to get key

Retrieve key from identifier service for all persist operations.

Fixes https://github.com/nasa/openmct/issues/1013
This commit is contained in:
Pete Richards 2016-06-14 10:56:54 -07:00
parent 3480809129
commit 2d5824c4ab
2 changed files with 14 additions and 7 deletions

View File

@ -60,11 +60,6 @@ define(
this.$q = $q;
}
function getKey(id) {
var parts = id.split(":");
return parts.length > 1 ? parts.slice(1).join(":") : id;
}
/**
* Checks if the value returned is falsey, and if so returns a
* rejected promise
@ -131,7 +126,7 @@ define(
// ...and persist
return persistenceFn.apply(persistenceService, [
this.getSpace(),
getKey(domainObject.getId()),
this.getKey(),
domainObject.getModel()
]).then(function (result) {
return rejectIfFalsey(result, self.$q);
@ -159,7 +154,7 @@ define(
return this.persistenceService.readObject(
this.getSpace(),
this.domainObject.getId()
this.getKey()
).then(updateModel);
};
@ -178,6 +173,17 @@ define(
return this.identifierService.parse(id).getSpace();
};
/**
* Get the key for this domain object in the given space.
*
* @returns {string} the key of the object in it's space.
*/
PersistenceCapability.prototype.getKey = function () {
var id = this.domainObject.getId();
return this.identifierService.parse(id).getKey();
};
return PersistenceCapability;
}
);

View File

@ -101,6 +101,7 @@ define(
});
mockIdentifierService.parse.andReturn(mockIdentifier);
mockIdentifier.getSpace.andReturn(SPACE);
mockIdentifier.getKey.andReturn(id);
persistence = new PersistenceCapability(
mockCacheService,
mockPersistenceService,