mirror of
https://github.com/nasa/openmct.git
synced 2025-06-22 09:08:43 +00:00
Allow tags files to define namespace to save annotations (#6274)
* allow tags files to define namespace to save annotations * add tests * typo in test name * lint * change param to objects object and remove debug
This commit is contained in:
@ -84,6 +84,7 @@ export default class AnnotationAPI extends EventEmitter {
|
||||
super();
|
||||
this.openmct = openmct;
|
||||
this.availableTags = {};
|
||||
this.namespaceToSaveAnnotations = '';
|
||||
|
||||
this.ANNOTATION_TYPES = ANNOTATION_TYPES;
|
||||
this.ANNOTATION_TYPE = ANNOTATION_TYPE;
|
||||
@ -139,7 +140,7 @@ export default class AnnotationAPI extends EventEmitter {
|
||||
const domainObjectKeyString = this.openmct.objects.makeKeyString(domainObject.identifier);
|
||||
const originalPathObjects = await this.openmct.objects.getOriginalPath(domainObjectKeyString);
|
||||
const originalContextPath = this.openmct.objects.getRelativePath(originalPathObjects);
|
||||
const namespace = domainObject.identifier.namespace;
|
||||
const namespace = this.namespaceToSaveAnnotations;
|
||||
const type = 'annotation';
|
||||
const typeDefinition = this.openmct.types.get(type);
|
||||
const definition = typeDefinition.definition;
|
||||
@ -198,6 +199,14 @@ export default class AnnotationAPI extends EventEmitter {
|
||||
this.availableTags[tagKey] = tagsDefinition;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method setNamespaceToSaveAnnotations
|
||||
* @param {String} namespace the namespace to save new annotations to
|
||||
*/
|
||||
setNamespaceToSaveAnnotations(namespace) {
|
||||
this.namespaceToSaveAnnotations = namespace;
|
||||
}
|
||||
|
||||
/**
|
||||
* @method isAnnotation
|
||||
* @param {DomainObject} domainObject the domainObject in question
|
||||
|
@ -26,6 +26,7 @@ import ExampleTagsPlugin from "../../../example/exampleTags/plugin";
|
||||
describe("The Annotation API", () => {
|
||||
let openmct;
|
||||
let mockObjectProvider;
|
||||
let mockImmutableObjectProvider;
|
||||
let mockDomainObject;
|
||||
let mockFolderObject;
|
||||
let mockAnnotationObject;
|
||||
@ -89,6 +90,23 @@ describe("The Annotation API", () => {
|
||||
mockObjectProvider.create.and.returnValue(Promise.resolve(true));
|
||||
mockObjectProvider.update.and.returnValue(Promise.resolve(true));
|
||||
|
||||
mockImmutableObjectProvider = jasmine.createSpyObj("mock immutable provider", [
|
||||
"get"
|
||||
]);
|
||||
// eslint-disable-next-line require-await
|
||||
mockImmutableObjectProvider.get = async (identifier) => {
|
||||
if (identifier.key === mockDomainObject.identifier.key) {
|
||||
return mockDomainObject;
|
||||
} else if (identifier.key === mockAnnotationObject.identifier.key) {
|
||||
return mockAnnotationObject;
|
||||
} else if (identifier.key === mockFolderObject.identifier.key) {
|
||||
return mockFolderObject;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
openmct.objects.addProvider('immutableProvider', mockImmutableObjectProvider);
|
||||
openmct.objects.addProvider('fooNameSpace', mockObjectProvider);
|
||||
openmct.on('start', done);
|
||||
openmct.startHeadless();
|
||||
@ -115,6 +133,22 @@ describe("The Annotation API", () => {
|
||||
expect(annotationObject).toBeDefined();
|
||||
expect(annotationObject.type).toEqual('annotation');
|
||||
});
|
||||
it("can create annotations if domain object is immutable", async () => {
|
||||
mockDomainObject.identifier.namespace = 'immutableProvider';
|
||||
const annotationCreationArguments = {
|
||||
name: 'Test Annotation',
|
||||
domainObject: mockDomainObject,
|
||||
annotationType: openmct.annotation.ANNOTATION_TYPES.NOTEBOOK,
|
||||
tags: ['sometag'],
|
||||
contentText: "fooContext",
|
||||
targetDomainObjects: [mockDomainObject],
|
||||
targets: {'fooTarget': {}}
|
||||
};
|
||||
openmct.annotation.setNamespaceToSaveAnnotations('fooNameSpace');
|
||||
const annotationObject = await openmct.annotation.create(annotationCreationArguments);
|
||||
expect(annotationObject).toBeDefined();
|
||||
expect(annotationObject.type).toEqual('annotation');
|
||||
});
|
||||
it("fails if annotation is an unknown type", async () => {
|
||||
try {
|
||||
await openmct.annotation.create('Garbage Annotation', mockDomainObject, 'garbageAnnotation', ['sometag'], "fooContext", {'fooTarget': {}});
|
||||
@ -122,6 +156,40 @@ describe("The Annotation API", () => {
|
||||
expect(error).toBeDefined();
|
||||
}
|
||||
});
|
||||
it("fails if annotation if given an immutable namespace to save to", async () => {
|
||||
try {
|
||||
const annotationCreationArguments = {
|
||||
name: 'Test Annotation',
|
||||
domainObject: mockDomainObject,
|
||||
annotationType: openmct.annotation.ANNOTATION_TYPES.NOTEBOOK,
|
||||
tags: ['sometag'],
|
||||
contentText: "fooContext",
|
||||
targetDomainObjects: [mockDomainObject],
|
||||
targets: {'fooTarget': {}}
|
||||
};
|
||||
openmct.annotation.setNamespaceToSaveAnnotations('nameespaceThatDoesNotExist');
|
||||
await openmct.annotation.create(annotationCreationArguments);
|
||||
} catch (error) {
|
||||
expect(error).toBeDefined();
|
||||
}
|
||||
});
|
||||
it("fails if annotation if given an undefined namespace to save to", async () => {
|
||||
try {
|
||||
const annotationCreationArguments = {
|
||||
name: 'Test Annotation',
|
||||
domainObject: mockDomainObject,
|
||||
annotationType: openmct.annotation.ANNOTATION_TYPES.NOTEBOOK,
|
||||
tags: ['sometag'],
|
||||
contentText: "fooContext",
|
||||
targetDomainObjects: [mockDomainObject],
|
||||
targets: {'fooTarget': {}}
|
||||
};
|
||||
openmct.annotation.setNamespaceToSaveAnnotations('immutableProvider');
|
||||
await openmct.annotation.create(annotationCreationArguments);
|
||||
} catch (error) {
|
||||
expect(error).toBeDefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("Tagging", () => {
|
||||
|
Reference in New Issue
Block a user