[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; 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 * Checks if the value returned is falsey, and if so returns a
* rejected promise * rejected promise
@ -131,7 +126,7 @@ define(
// ...and persist // ...and persist
return persistenceFn.apply(persistenceService, [ return persistenceFn.apply(persistenceService, [
this.getSpace(), this.getSpace(),
getKey(domainObject.getId()), this.getKey(),
domainObject.getModel() domainObject.getModel()
]).then(function (result) { ]).then(function (result) {
return rejectIfFalsey(result, self.$q); return rejectIfFalsey(result, self.$q);
@ -159,7 +154,7 @@ define(
return this.persistenceService.readObject( return this.persistenceService.readObject(
this.getSpace(), this.getSpace(),
this.domainObject.getId() this.getKey()
).then(updateModel); ).then(updateModel);
}; };
@ -178,6 +173,17 @@ define(
return this.identifierService.parse(id).getSpace(); 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; return PersistenceCapability;
} }
); );

View File

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