From b9b1525dcd79b5a74839309b9b16d6c2fcf2f382 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 11 Apr 2024 16:37:54 +0200 Subject: [PATCH 01/46] EW-793 Add loggable exceptions --- .../common-cartridge-element-factory.spec.ts | 6 +-- .../common-cartridge-element-factory.ts | 5 +- .../common-cartridge-element-factory.spec.ts | 6 +-- .../common-cartridge-element-factory.ts | 4 +- .../common-cartridge-element-factory.spec.ts | 6 +-- .../common-cartridge-element-factory.ts | 4 +- ...e-not-supported.loggable-exception.spec.ts | 23 +++++++++ ...t-type-not-supported.loggable-exception.ts | 24 ++++++++++ .../export/error/error.enum.ts | 5 ++ .../common-cartridge/export/error/index.ts | 3 ++ ...e-not-supported.loggable-exception.spec.ts | 23 +++++++++ ...e-type-not-supported.loggable-exception.ts | 24 ++++++++++ ...n-not-supported.loggable-exception.spec.ts | 23 +++++++++ ...ersion-not-supported.loggable-exception.ts | 24 ++++++++++ .../common-cartridge-element.interface.ts | 4 +- .../common-cartridge-resource-factory.spec.ts | 6 +-- .../common-cartridge-resource-factory.ts | 5 +- .../common-cartridge-resource-factory.spec.ts | 6 +-- .../common-cartridge-resource-factory.ts | 4 +- .../common-cartridge-resource-factory.spec.ts | 6 +-- .../common-cartridge-resource-factory.ts | 4 +- .../common-cartridge/export/utils.spec.ts | 48 +------------------ .../modules/common-cartridge/export/utils.ts | 14 ------ 23 files changed, 184 insertions(+), 93 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.ts create mode 100644 apps/server/src/modules/common-cartridge/export/error/error.enum.ts create mode 100644 apps/server/src/modules/common-cartridge/export/error/index.ts create mode 100644 apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.ts create mode 100644 apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.ts diff --git a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts index b891d1aa49a..e8049ad7de3 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts @@ -1,9 +1,9 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeMetadataElementPropsV110, createCommonCartridgeMetadataElementPropsV130, } from '../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { VersionNotSupportedLoggableException } from '../error'; import { CommonCartridgeElementFactory } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementPropsV110, CommonCartridgeMetadataElementV110 } from './v1.1.0'; import { CommonCartridgeMetadataElementV130 } from './v1.3.0'; @@ -36,14 +36,14 @@ describe('CommonCartridgeElementFactory', () => { CommonCartridgeVersion.V_1_4_0, ]; - it('should throw InternalServerErrorException', () => { + it('should throw VersionNotSupportedLoggableException', () => { notSupportedVersions.forEach((version) => { expect(() => CommonCartridgeElementFactory.createElement({ version, type: CommonCartridgeElementType.METADATA, } as CommonCartridgeMetadataElementPropsV110) - ).toThrow(InternalServerErrorException); + ).toThrow(VersionNotSupportedLoggableException); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts index 046f7033fde..15464eb898e 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts @@ -1,6 +1,7 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { VersionNotSupportedLoggableException } from '../error'; import { CommonCartridgeElement } from '../interfaces'; -import { OmitVersionAndFolder, createVersionNotSupportedError } from '../utils'; +import { OmitVersionAndFolder } from '../utils'; import { CommonCartridgeElementFactoryV110, CommonCartridgeMetadataElementPropsV110, @@ -46,7 +47,7 @@ export class CommonCartridgeElementFactory { case CommonCartridgeVersion.V_1_3_0: return CommonCartridgeElementFactoryV130.createElement(props); default: - throw createVersionNotSupportedError(version); + throw new VersionNotSupportedLoggableException(version); } } } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts index 3c43cf3a830..6794ecd0ae8 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -1,4 +1,3 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeMetadataElementPropsV110, createCommonCartridgeOrganizationElementPropsV110, @@ -6,6 +5,7 @@ import { createCommonCartridgeResourcesWrapperElementPropsV110, } from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../error'; import { CommonCartridgeElementFactoryV110 } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; import { CommonCartridgeOrganizationElementV110 } from './common-cartridge-organization-element'; @@ -53,9 +53,9 @@ describe('CommonCartridgeElementFactoryV110', () => { notSupportedProps.type = 'not-supported' as CommonCartridgeElementType.METADATA; - it('should throw error', () => { + it('should throw ElementTypeNotSupportedLoggableException', () => { expect(() => CommonCartridgeElementFactoryV110.createElement(notSupportedProps)).toThrow( - InternalServerErrorException + ElementTypeNotSupportedLoggableException ); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts index 88095cf218a..b62881093b0 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts @@ -1,6 +1,6 @@ import { CommonCartridgeElementType } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../error'; import { CommonCartridgeElement } from '../../interfaces'; -import { createElementTypeNotSupportedError } from '../../utils'; import { CommonCartridgeMetadataElementPropsV110, CommonCartridgeMetadataElementV110, @@ -39,7 +39,7 @@ export class CommonCartridgeElementFactoryV110 { case CommonCartridgeElementType.RESOURCES_WRAPPER: return new CommonCartridgeResourcesWrapperElementV110(props); default: - throw createElementTypeNotSupportedError(type); + throw new ElementTypeNotSupportedLoggableException(type); } } } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts index 7fe5e1f0cf5..4dd6ef98bae 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -1,4 +1,3 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeMetadataElementPropsV130, createCommonCartridgeOrganizationElementPropsV130, @@ -6,6 +5,7 @@ import { createCommonCartridgeResourcesWrapperElementPropsV130, } from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../error'; import { CommonCartridgeElementFactoryV130 } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; import { CommonCartridgeOrganizationElementV130 } from './common-cartridge-organization-element'; @@ -52,9 +52,9 @@ describe('CommonCartridgeElementFactoryV130', () => { const notSupportedProps = createCommonCartridgeOrganizationsWrapperElementPropsV130(); notSupportedProps.type = 'not-supported' as CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; - it('should throw error', () => { + it('should throw ElementTypeNotSupportedLoggableException', () => { expect(() => CommonCartridgeElementFactoryV130.createElement(notSupportedProps)).toThrow( - InternalServerErrorException + ElementTypeNotSupportedLoggableException ); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts index 6a1216e405a..054b2a42a2f 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts @@ -1,6 +1,6 @@ import { CommonCartridgeElementType } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../error'; import { CommonCartridgeElement } from '../../interfaces'; -import { createElementTypeNotSupportedError } from '../../utils'; import { CommonCartridgeMetadataElementPropsV130, CommonCartridgeMetadataElementV130, @@ -39,7 +39,7 @@ export class CommonCartridgeElementFactoryV130 { case CommonCartridgeElementType.RESOURCES_WRAPPER: return new CommonCartridgeResourcesWrapperElementV130(props); default: - throw createElementTypeNotSupportedError(type); + throw new ElementTypeNotSupportedLoggableException(type); } } } diff --git a/apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.spec.ts new file mode 100644 index 00000000000..9c27761a872 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.spec.ts @@ -0,0 +1,23 @@ +import { ElementTypeNotSupportedLoggableException } from './element-type-not-supported.loggable-exception'; +import { CommonCartridgeErrorEnum } from './error.enum'; + +describe('ElementTypeNotSupportedLoggableException', () => { + describe('getLogMessage', () => { + describe('when getting log message', () => { + const exception = new ElementTypeNotSupportedLoggableException('notSupportedType'); + + it('should return log message', () => { + const result = exception.getLogMessage(); + + expect(result).toStrictEqual({ + type: CommonCartridgeErrorEnum.ELEMENT_TYPE_NOT_SUPPORTED, + stack: exception.stack, + data: { + type: 'notSupportedType', + message: 'Common Cartridge element type notSupportedType is not supported', + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.ts new file mode 100644 index 00000000000..ab1148fcfdf --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.ts @@ -0,0 +1,24 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { ErrorLogMessage, Loggable } from '@src/core/logger'; +import { CommonCartridgeErrorEnum } from './error.enum'; + +export class ElementTypeNotSupportedLoggableException extends InternalServerErrorException implements Loggable { + constructor(private readonly type: string) { + super({ + type: CommonCartridgeErrorEnum.ELEMENT_TYPE_NOT_SUPPORTED, + }); + } + + getLogMessage(): ErrorLogMessage { + const message: ErrorLogMessage = { + type: CommonCartridgeErrorEnum.ELEMENT_TYPE_NOT_SUPPORTED, + stack: this.stack, + data: { + type: this.type, + message: `Common Cartridge element type ${this.type} is not supported`, + }, + }; + + return message; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/error/error.enum.ts b/apps/server/src/modules/common-cartridge/export/error/error.enum.ts new file mode 100644 index 00000000000..ba6b1d926b5 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/error/error.enum.ts @@ -0,0 +1,5 @@ +export enum CommonCartridgeErrorEnum { + VERSION_NOT_SUPPORTED = 'VERSION_NOT_SUPPORTED', + RESOURCE_TYPE_NOT_SUPPORTED = 'RESOURCE_TYPE_NOT_SUPPORTED', + ELEMENT_TYPE_NOT_SUPPORTED = 'ELEMENT_TYPE_NOT_SUPPORTED', +} diff --git a/apps/server/src/modules/common-cartridge/export/error/index.ts b/apps/server/src/modules/common-cartridge/export/error/index.ts new file mode 100644 index 00000000000..5c5a946c510 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/error/index.ts @@ -0,0 +1,3 @@ +export { ElementTypeNotSupportedLoggableException } from './element-type-not-supported.loggable-exception'; +export { ResourceTypeNotSupportedLoggableException } from './resource-type-not-supported.loggable-exception'; +export { VersionNotSupportedLoggableException } from './version-not-supported.loggable-exception'; diff --git a/apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.spec.ts new file mode 100644 index 00000000000..cc9936c200f --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.spec.ts @@ -0,0 +1,23 @@ +import { CommonCartridgeErrorEnum } from './error.enum'; +import { ResourceTypeNotSupportedLoggableException } from './resource-type-not-supported.loggable-exception'; + +describe('ResourceTypeNotSupportedLoggableException', () => { + describe('getLogMessage', () => { + describe('when getting log message', () => { + const exception = new ResourceTypeNotSupportedLoggableException('notSupportedType'); + + it('should return log message', () => { + const result = exception.getLogMessage(); + + expect(result).toStrictEqual({ + type: CommonCartridgeErrorEnum.RESOURCE_TYPE_NOT_SUPPORTED, + stack: exception.stack, + data: { + type: 'notSupportedType', + message: 'Common Cartridge resource type notSupportedType is not supported', + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.ts new file mode 100644 index 00000000000..a6467474083 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.ts @@ -0,0 +1,24 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { ErrorLogMessage, Loggable } from '@src/core/logger'; +import { CommonCartridgeErrorEnum } from './error.enum'; + +export class ResourceTypeNotSupportedLoggableException extends InternalServerErrorException implements Loggable { + constructor(private readonly type: string) { + super({ + type: CommonCartridgeErrorEnum.RESOURCE_TYPE_NOT_SUPPORTED, + }); + } + + getLogMessage(): ErrorLogMessage { + const message: ErrorLogMessage = { + type: CommonCartridgeErrorEnum.RESOURCE_TYPE_NOT_SUPPORTED, + stack: this.stack, + data: { + type: this.type, + message: `Common Cartridge resource type ${this.type} is not supported`, + }, + }; + + return message; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.spec.ts new file mode 100644 index 00000000000..e2d57e79178 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.spec.ts @@ -0,0 +1,23 @@ +import { CommonCartridgeErrorEnum } from './error.enum'; +import { VersionNotSupportedLoggableException } from './version-not-supported.loggable-exception'; + +describe('VersionNotSupportedLoggableException', () => { + describe('getLogMessage', () => { + describe('when getting log message', () => { + const exception = new VersionNotSupportedLoggableException('notSupportedVersion'); + + it('should return log message', () => { + const result = exception.getLogMessage(); + + expect(result).toStrictEqual({ + type: CommonCartridgeErrorEnum.VERSION_NOT_SUPPORTED, + stack: exception.stack, + data: { + version: 'notSupportedVersion', + message: 'Common Cartridge version notSupportedVersion is not supported', + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.ts new file mode 100644 index 00000000000..5c691ff1e6f --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.ts @@ -0,0 +1,24 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { ErrorLogMessage, Loggable } from '@src/core/logger'; +import { CommonCartridgeErrorEnum } from './error.enum'; + +export class VersionNotSupportedLoggableException extends InternalServerErrorException implements Loggable { + constructor(private readonly version: string) { + super({ + type: CommonCartridgeErrorEnum.VERSION_NOT_SUPPORTED, + }); + } + + getLogMessage(): ErrorLogMessage { + const message: ErrorLogMessage = { + type: CommonCartridgeErrorEnum.VERSION_NOT_SUPPORTED, + stack: this.stack, + data: { + version: this.version, + message: `Common Cartridge version ${this.version} is not supported`, + }, + }; + + return message; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts index 869aa6f576f..e830376ed24 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts @@ -1,5 +1,5 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { createVersionNotSupportedError } from '../utils'; +import { VersionNotSupportedLoggableException } from '../error'; type CommonCartridgeElementProps = { version: CommonCartridgeVersion; @@ -37,7 +37,7 @@ export abstract class CommonCartridgeElement { private checkVersion(target: CommonCartridgeVersion): void { if (this.getSupportedVersion() !== target) { - throw createVersionNotSupportedError(target); + throw new VersionNotSupportedLoggableException(target); } } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts index 9bd274d4810..0dfb6f11702 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts @@ -1,9 +1,9 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeWebContentResourcePropsV110, createCommonCartridgeWebContentResourcePropsV130, } from '../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { VersionNotSupportedLoggableException } from '../error'; import { CommonCartridgeResourceFactory } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourcePropsV110, CommonCartridgeWebContentResourceV110 } from './v1.1.0'; import { CommonCartridgeWebContentResourceV130 } from './v1.3.0'; @@ -35,14 +35,14 @@ describe('CommonCartridgeResourceVersion', () => { CommonCartridgeVersion.V_1_4_0, ]; - it('should throw InternalServerErrorException', () => { + it('should throw VersionNotSupportedLoggableException', () => { notSupportedVersions.forEach((version) => { expect(() => CommonCartridgeResourceFactory.createResource({ version, type: CommonCartridgeResourceType.WEB_CONTENT, } as CommonCartridgeWebContentResourcePropsV110) - ).toThrow(InternalServerErrorException); + ).toThrow(VersionNotSupportedLoggableException); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts index 673672c129e..bca6e246ffa 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts @@ -1,6 +1,7 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { VersionNotSupportedLoggableException } from '../error'; import { CommonCartridgeResource } from '../interfaces'; -import { OmitVersionAndFolder, createVersionNotSupportedError } from '../utils'; +import { OmitVersionAndFolder } from '../utils'; import { CommonCartridgeManifestResourcePropsV110, CommonCartridgeResourceFactoryV110, @@ -38,7 +39,7 @@ export class CommonCartridgeResourceFactory { case CommonCartridgeVersion.V_1_3_0: return CommonCartridgeResourceFactoryV130.createResource(props); default: - throw createVersionNotSupportedError(version); + throw new VersionNotSupportedLoggableException(version); } } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index fd93be44d2d..68cf3ef5533 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -1,9 +1,9 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeManifestResourcePropsV110, createCommonCartridgeWebContentResourcePropsV110, createCommonCartridgeWeblinkResourcePropsV110, } from '../../../testing/common-cartridge-resource-props.factory'; +import { ResourceTypeNotSupportedLoggableException } from '../../error'; import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; @@ -41,10 +41,10 @@ describe('CommonCartridgeResourceFactoryV110', () => { }); describe('when resource type is not supported', () => { - it('should throw error', () => { + it('should throw ResourceTypeNotSupportedLoggableException', () => { expect(() => CommonCartridgeResourceFactoryV110.createResource({} as CommonCartridgeWebLinkResourcePropsV110) - ).toThrow(InternalServerErrorException); + ).toThrow(ResourceTypeNotSupportedLoggableException); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts index 4e13ec77587..1436c4d766c 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -1,6 +1,6 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; +import { ResourceTypeNotSupportedLoggableException } from '../../error'; import { CommonCartridgeResource } from '../../interfaces'; -import { createResourceTypeNotSupportedError } from '../../utils'; import { CommonCartridgeManifestResourcePropsV110, CommonCartridgeManifestResourceV110, @@ -31,7 +31,7 @@ export class CommonCartridgeResourceFactoryV110 { case CommonCartridgeResourceType.WEB_LINK: return new CommonCartridgeWebLinkResourceV110(props); default: - throw createResourceTypeNotSupportedError(type); + throw new ResourceTypeNotSupportedLoggableException(type); } } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index ad630ea25d8..2e93b564dd5 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -1,9 +1,9 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeManifestResourcePropsV130, createCommonCartridgeWebContentResourcePropsV130, createCommonCartridgeWeblinkResourcePropsV130, } from '../../../testing/common-cartridge-resource-props.factory'; +import { ResourceTypeNotSupportedLoggableException } from '../../error'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; @@ -41,10 +41,10 @@ describe('CommonCartridgeResourceFactoryV130', () => { }); describe('when resource type is not supported', () => { - it('should throw error', () => { + it('should throw ResourceTypeNotSupportedLoggableException', () => { expect(() => CommonCartridgeResourceFactoryV130.createResource({} as CommonCartridgeWebLinkResourcePropsV130) - ).toThrow(InternalServerErrorException); + ).toThrow(ResourceTypeNotSupportedLoggableException); }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts index 9be5fad11c1..8e3223724ab 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -1,6 +1,6 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; +import { ResourceTypeNotSupportedLoggableException } from '../../error'; import { CommonCartridgeResource } from '../../interfaces'; -import { createResourceTypeNotSupportedError } from '../../utils'; import { CommonCartridgeManifestResourcePropsV130, CommonCartridgeManifestResourceV130, @@ -31,7 +31,7 @@ export class CommonCartridgeResourceFactoryV130 { case CommonCartridgeResourceType.WEB_LINK: return new CommonCartridgeWebLinkResourceV130(props); default: - throw createResourceTypeNotSupportedError(type); + throw new ResourceTypeNotSupportedLoggableException(type); } } } diff --git a/apps/server/src/modules/common-cartridge/export/utils.spec.ts b/apps/server/src/modules/common-cartridge/export/utils.spec.ts index 3dae9ffa1c8..0f86cada2cf 100644 --- a/apps/server/src/modules/common-cartridge/export/utils.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/utils.spec.ts @@ -1,14 +1,5 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { ObjectId } from 'bson'; -import { CommonCartridgeVersion } from './common-cartridge.enums'; -import { - buildXmlString, - checkIntendedUse, - createElementTypeNotSupportedError, - createIdentifier, - createResourceTypeNotSupportedError, - createVersionNotSupportedError, -} from './utils'; +import { buildXmlString, checkIntendedUse, createIdentifier } from './utils'; describe('CommonCartridgeUtils', () => { describe('buildXmlString', () => { @@ -19,17 +10,6 @@ describe('CommonCartridgeUtils', () => { }); }); - describe('createVersionNotSupportedError', () => { - describe('when creating error', () => { - it('should return error with message', () => { - const error = createVersionNotSupportedError(CommonCartridgeVersion.V_1_0_0); - - expect(error).toBeInstanceOf(InternalServerErrorException); - expect(error.message).toBe('Common Cartridge version 1.0.0 is not supported'); - }); - }); - }); - describe('createIdentifier', () => { describe('when creating identifier', () => { it('should return identifier with prefix', () => { @@ -44,32 +24,6 @@ describe('CommonCartridgeUtils', () => { }); }); - describe('createResourceTypeNotSupportedError', () => { - describe('when creating error', () => { - it('should return error with message', () => { - const resourceType = 'unsupported'; - - const error = createResourceTypeNotSupportedError(resourceType); - - expect(error).toBeInstanceOf(InternalServerErrorException); - expect(error.message).toBe(`Common Cartridge resource type ${resourceType} is not supported`); - }); - }); - }); - - describe('createElementTypeNotSupportedError', () => { - describe('when creating error', () => { - it('should return error with message', () => { - const elementType = 'unsupported'; - - const error = createElementTypeNotSupportedError(elementType); - - expect(error).toBeInstanceOf(InternalServerErrorException); - expect(error.message).toBe(`Common Cartridge element type ${elementType} is not supported`); - }); - }); - }); - describe('checkIntendedUse', () => { describe('when intended use is not supported', () => { it('should throw error', () => { diff --git a/apps/server/src/modules/common-cartridge/export/utils.ts b/apps/server/src/modules/common-cartridge/export/utils.ts index 0b110f783c5..f097c9be944 100644 --- a/apps/server/src/modules/common-cartridge/export/utils.ts +++ b/apps/server/src/modules/common-cartridge/export/utils.ts @@ -1,4 +1,3 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { ObjectId } from 'bson'; import { Builder } from 'xml2js'; @@ -17,19 +16,6 @@ export function buildXmlString(obj: unknown): string { return xmlBuilder.buildObject(obj); } -export function createVersionNotSupportedError(version: string): Error { - return new InternalServerErrorException(`Common Cartridge version ${version} is not supported`); -} - -export function createResourceTypeNotSupportedError(type: string): Error { - return new InternalServerErrorException(`Common Cartridge resource type ${type} is not supported`); -} - -export function createElementTypeNotSupportedError(type: string): Error { - // AI next 1 line - return new InternalServerErrorException(`Common Cartridge element type ${type} is not supported`); -} - export function createIdentifier(identifier?: string | ObjectId): string { if (!identifier) { return `i${new ObjectId().toString()}`; From 711cd09825ad31416de2e106c2bc330d14272d34 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 12 Apr 2024 11:33:12 +0200 Subject: [PATCH 02/46] EW-793 Rename folder and adjust regarding imports --- .../export/elements/common-cartridge-element-factory.spec.ts | 2 +- .../export/elements/common-cartridge-element-factory.ts | 2 +- .../elements/v1.1.0/common-cartridge-element-factory.spec.ts | 2 +- .../export/elements/v1.1.0/common-cartridge-element-factory.ts | 2 +- .../elements/v1.3.0/common-cartridge-element-factory.spec.ts | 2 +- .../export/elements/v1.3.0/common-cartridge-element-factory.ts | 2 +- .../element-type-not-supported.loggable-exception.spec.ts | 0 .../element-type-not-supported.loggable-exception.ts | 0 .../common-cartridge/export/{error => errors}/error.enum.ts | 0 .../modules/common-cartridge/export/{error => errors}/index.ts | 0 .../resource-type-not-supported.loggable-exception.spec.ts | 0 .../resource-type-not-supported.loggable-exception.ts | 0 .../version-not-supported.loggable-exception.spec.ts | 0 .../version-not-supported.loggable-exception.ts | 0 .../export/interfaces/common-cartridge-element.interface.ts | 2 +- .../export/resources/common-cartridge-resource-factory.spec.ts | 2 +- .../export/resources/common-cartridge-resource-factory.ts | 2 +- .../resources/v1.1.0/common-cartridge-resource-factory.spec.ts | 2 +- .../resources/v1.1.0/common-cartridge-resource-factory.ts | 2 +- .../resources/v1.3.0/common-cartridge-resource-factory.spec.ts | 2 +- .../resources/v1.3.0/common-cartridge-resource-factory.ts | 2 +- 21 files changed, 13 insertions(+), 13 deletions(-) rename apps/server/src/modules/common-cartridge/export/{error => errors}/element-type-not-supported.loggable-exception.spec.ts (100%) rename apps/server/src/modules/common-cartridge/export/{error => errors}/element-type-not-supported.loggable-exception.ts (100%) rename apps/server/src/modules/common-cartridge/export/{error => errors}/error.enum.ts (100%) rename apps/server/src/modules/common-cartridge/export/{error => errors}/index.ts (100%) rename apps/server/src/modules/common-cartridge/export/{error => errors}/resource-type-not-supported.loggable-exception.spec.ts (100%) rename apps/server/src/modules/common-cartridge/export/{error => errors}/resource-type-not-supported.loggable-exception.ts (100%) rename apps/server/src/modules/common-cartridge/export/{error => errors}/version-not-supported.loggable-exception.spec.ts (100%) rename apps/server/src/modules/common-cartridge/export/{error => errors}/version-not-supported.loggable-exception.ts (100%) diff --git a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts index e8049ad7de3..2aad5899e57 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.spec.ts @@ -3,7 +3,7 @@ import { createCommonCartridgeMetadataElementPropsV130, } from '../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { VersionNotSupportedLoggableException } from '../error'; +import { VersionNotSupportedLoggableException } from '../errors'; import { CommonCartridgeElementFactory } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementPropsV110, CommonCartridgeMetadataElementV110 } from './v1.1.0'; import { CommonCartridgeMetadataElementV130 } from './v1.3.0'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts index 15464eb898e..7765e79d7ac 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/common-cartridge-element-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { VersionNotSupportedLoggableException } from '../error'; +import { VersionNotSupportedLoggableException } from '../errors'; import { CommonCartridgeElement } from '../interfaces'; import { OmitVersionAndFolder } from '../utils'; import { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts index 6794ecd0ae8..3c4fceabe83 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.spec.ts @@ -5,7 +5,7 @@ import { createCommonCartridgeResourcesWrapperElementPropsV110, } from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType } from '../../common-cartridge.enums'; -import { ElementTypeNotSupportedLoggableException } from '../../error'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeElementFactoryV110 } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; import { CommonCartridgeOrganizationElementV110 } from './common-cartridge-organization-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts index b62881093b0..b623cd277f8 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-element-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType } from '../../common-cartridge.enums'; -import { ElementTypeNotSupportedLoggableException } from '../../error'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeElement } from '../../interfaces'; import { CommonCartridgeMetadataElementPropsV110, diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts index 4dd6ef98bae..7a5cdae2204 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.spec.ts @@ -5,7 +5,7 @@ import { createCommonCartridgeResourcesWrapperElementPropsV130, } from '../../../testing/common-cartridge-element-props.factory'; import { CommonCartridgeElementType } from '../../common-cartridge.enums'; -import { ElementTypeNotSupportedLoggableException } from '../../error'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeElementFactoryV130 } from './common-cartridge-element-factory'; import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; import { CommonCartridgeOrganizationElementV130 } from './common-cartridge-organization-element'; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts index 054b2a42a2f..adade3178cb 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-element-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType } from '../../common-cartridge.enums'; -import { ElementTypeNotSupportedLoggableException } from '../../error'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeElement } from '../../interfaces'; import { CommonCartridgeMetadataElementPropsV130, diff --git a/apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.spec.ts rename to apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.spec.ts diff --git a/apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/export/error/element-type-not-supported.loggable-exception.ts rename to apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts diff --git a/apps/server/src/modules/common-cartridge/export/error/error.enum.ts b/apps/server/src/modules/common-cartridge/export/errors/error.enum.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/export/error/error.enum.ts rename to apps/server/src/modules/common-cartridge/export/errors/error.enum.ts diff --git a/apps/server/src/modules/common-cartridge/export/error/index.ts b/apps/server/src/modules/common-cartridge/export/errors/index.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/export/error/index.ts rename to apps/server/src/modules/common-cartridge/export/errors/index.ts diff --git a/apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.spec.ts rename to apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.spec.ts diff --git a/apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/export/error/resource-type-not-supported.loggable-exception.ts rename to apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts diff --git a/apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.spec.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.spec.ts rename to apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.spec.ts diff --git a/apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts similarity index 100% rename from apps/server/src/modules/common-cartridge/export/error/version-not-supported.loggable-exception.ts rename to apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts index e830376ed24..4580562aff3 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts @@ -1,5 +1,5 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { VersionNotSupportedLoggableException } from '../error'; +import { VersionNotSupportedLoggableException } from '../errors'; type CommonCartridgeElementProps = { version: CommonCartridgeVersion; diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts index 0dfb6f11702..d1d6ab6ae76 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.spec.ts @@ -3,7 +3,7 @@ import { createCommonCartridgeWebContentResourcePropsV130, } from '../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { VersionNotSupportedLoggableException } from '../error'; +import { VersionNotSupportedLoggableException } from '../errors'; import { CommonCartridgeResourceFactory } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourcePropsV110, CommonCartridgeWebContentResourceV110 } from './v1.1.0'; import { CommonCartridgeWebContentResourceV130 } from './v1.3.0'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts index bca6e246ffa..21050539eaa 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { VersionNotSupportedLoggableException } from '../error'; +import { VersionNotSupportedLoggableException } from '../errors'; import { CommonCartridgeResource } from '../interfaces'; import { OmitVersionAndFolder } from '../utils'; import { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts index 68cf3ef5533..3e214a828ee 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.spec.ts @@ -3,7 +3,7 @@ import { createCommonCartridgeWebContentResourcePropsV110, createCommonCartridgeWeblinkResourcePropsV110, } from '../../../testing/common-cartridge-resource-props.factory'; -import { ResourceTypeNotSupportedLoggableException } from '../../error'; +import { ResourceTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV110 } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts index 1436c4d766c..ffb94273dce 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-resource-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; -import { ResourceTypeNotSupportedLoggableException } from '../../error'; +import { ResourceTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeResource } from '../../interfaces'; import { CommonCartridgeManifestResourcePropsV110, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index 2e93b564dd5..799e435ee00 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -3,7 +3,7 @@ import { createCommonCartridgeWebContentResourcePropsV130, createCommonCartridgeWeblinkResourcePropsV130, } from '../../../testing/common-cartridge-resource-props.factory'; -import { ResourceTypeNotSupportedLoggableException } from '../../error'; +import { ResourceTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts index 8e3223724ab..a842c1a4a98 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.ts @@ -1,5 +1,5 @@ import { CommonCartridgeResourceType } from '../../common-cartridge.enums'; -import { ResourceTypeNotSupportedLoggableException } from '../../error'; +import { ResourceTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeResource } from '../../interfaces'; import { CommonCartridgeManifestResourcePropsV130, From a56b9183e0e3afc58e793277447aeacb3ee43369 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 12 Apr 2024 13:53:30 +0200 Subject: [PATCH 03/46] EW-793 Add common cartridge guard for intended use --- .../export/common-cartridge.guard.spec.ts | 29 +++++++++++++++++++ .../export/common-cartridge.guard.ts | 9 ++++++ .../export/errors/error.enum.ts | 1 + .../common-cartridge/export/errors/index.ts | 1 + ...e-not-supported.loggable-exception.spec.ts | 23 +++++++++++++++ ...ed-use-not-supported.loggable-exception.ts | 24 +++++++++++++++ .../common-cartridge-web-content-resource.ts | 7 +++-- .../common-cartridge-web-content-resource.ts | 7 +++-- .../common-cartridge/export/utils.spec.ts | 14 +-------- .../modules/common-cartridge/export/utils.ts | 6 ---- 10 files changed, 98 insertions(+), 23 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts create mode 100644 apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts diff --git a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts new file mode 100644 index 00000000000..0739b6307b3 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts @@ -0,0 +1,29 @@ +import { CommonCartridgeGuard } from './common-cartridge.guard'; + +describe('CommonCartridgeGuard', () => { + describe('checkIntendedUse', () => { + describe('when intended use is supported', () => { + const supportedIntendedUses = ['use1', 'use2', 'use3']; + + it('should not throw an exception', () => { + const intendedUse = 'use1'; + + expect(() => { + CommonCartridgeGuard.checkIntendedUse(intendedUse, supportedIntendedUses); + }).not.toThrow(); + }); + }); + + describe('when intended use is not supported', () => { + const supportedIntendedUses = ['use1', 'use2', 'use3']; + + it('should throw an exception', () => { + const intendedUse = 'use4'; + + expect(() => { + CommonCartridgeGuard.checkIntendedUse(intendedUse, supportedIntendedUses); + }).toThrow(); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts new file mode 100644 index 00000000000..af850466912 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts @@ -0,0 +1,9 @@ +import { IntendedUseNotSupportedLoggableException } from './errors'; + +export class CommonCartridgeGuard { + static checkIntendedUse(intendedUse: string, supportedIntendedUses: string[]): void | never { + if (!supportedIntendedUses.includes(intendedUse)) { + throw new IntendedUseNotSupportedLoggableException(intendedUse); + } + } +} diff --git a/apps/server/src/modules/common-cartridge/export/errors/error.enum.ts b/apps/server/src/modules/common-cartridge/export/errors/error.enum.ts index ba6b1d926b5..c236c2f2006 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/error.enum.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/error.enum.ts @@ -2,4 +2,5 @@ export enum CommonCartridgeErrorEnum { VERSION_NOT_SUPPORTED = 'VERSION_NOT_SUPPORTED', RESOURCE_TYPE_NOT_SUPPORTED = 'RESOURCE_TYPE_NOT_SUPPORTED', ELEMENT_TYPE_NOT_SUPPORTED = 'ELEMENT_TYPE_NOT_SUPPORTED', + INTENDED_USE_NOT_SUPPORTED = 'INTENDED_USE_NOT_SUPPORTED', } diff --git a/apps/server/src/modules/common-cartridge/export/errors/index.ts b/apps/server/src/modules/common-cartridge/export/errors/index.ts index 5c5a946c510..93e281f3c63 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/index.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/index.ts @@ -1,3 +1,4 @@ export { ElementTypeNotSupportedLoggableException } from './element-type-not-supported.loggable-exception'; +export { IntendedUseNotSupportedLoggableException } from './intended-use-not-supported.loggable-exception'; export { ResourceTypeNotSupportedLoggableException } from './resource-type-not-supported.loggable-exception'; export { VersionNotSupportedLoggableException } from './version-not-supported.loggable-exception'; diff --git a/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.spec.ts new file mode 100644 index 00000000000..4646ef8259a --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.spec.ts @@ -0,0 +1,23 @@ +import { CommonCartridgeErrorEnum } from './error.enum'; +import { IntendedUseNotSupportedLoggableException } from './intended-use-not-supported.loggable-exception'; + +describe('IntendedUseNotSupportedLoggableException', () => { + describe('getLogMessage', () => { + describe('when getting log message', () => { + const exception = new IntendedUseNotSupportedLoggableException('notSupportedIntendedUse'); + + it('should return log message', () => { + const result = exception.getLogMessage(); + + expect(result).toStrictEqual({ + type: CommonCartridgeErrorEnum.INTENDED_USE_NOT_SUPPORTED, + stack: exception.stack, + data: { + intendedUse: 'notSupportedIntendedUse', + message: 'Common Cartridge intended use notSupportedIntendedUse is not supported', + }, + }); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts new file mode 100644 index 00000000000..56f93702cf6 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts @@ -0,0 +1,24 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { ErrorLogMessage, Loggable } from '@src/core/logger'; +import { CommonCartridgeErrorEnum } from './error.enum'; + +export class IntendedUseNotSupportedLoggableException extends InternalServerErrorException implements Loggable { + constructor(private readonly intendedUse: string) { + super({ + type: CommonCartridgeErrorEnum.INTENDED_USE_NOT_SUPPORTED, + }); + } + + getLogMessage(): ErrorLogMessage { + const message: ErrorLogMessage = { + type: CommonCartridgeErrorEnum.INTENDED_USE_NOT_SUPPORTED, + stack: this.stack, + data: { + intendedUse: this.intendedUse, + message: `Common Cartridge intended use ${this.intendedUse} is not supported`, + }, + }; + + return message; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts index f684709e246..31e4f2d4f17 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -3,8 +3,8 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; +import { CommonCartridgeGuard } from '../../common-cartridge.guard'; import { CommonCartridgeResource } from '../../interfaces'; -import { checkIntendedUse } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV110 = { type: CommonCartridgeResourceType.WEB_CONTENT; @@ -25,7 +25,10 @@ export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResour constructor(private readonly props: CommonCartridgeWebContentResourcePropsV110) { super(props); - checkIntendedUse(props.intendedUse, CommonCartridgeWebContentResourceV110.SUPPORTED_INTENDED_USES); + CommonCartridgeGuard.checkIntendedUse( + props.intendedUse, + CommonCartridgeWebContentResourceV110.SUPPORTED_INTENDED_USES + ); } public canInline(): boolean { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts index eb168087a52..175d2da468c 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -3,8 +3,8 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; +import { CommonCartridgeGuard } from '../../common-cartridge.guard'; import { CommonCartridgeResource } from '../../interfaces'; -import { checkIntendedUse } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV130 = { type: CommonCartridgeResourceType.WEB_CONTENT; @@ -26,7 +26,10 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResour constructor(private readonly props: CommonCartridgeWebContentResourcePropsV130) { super(props); - checkIntendedUse(props.intendedUse, CommonCartridgeWebContentResourceV130.SUPPORTED_INTENDED_USES); + CommonCartridgeGuard.checkIntendedUse( + props.intendedUse, + CommonCartridgeWebContentResourceV130.SUPPORTED_INTENDED_USES + ); } public canInline(): boolean { diff --git a/apps/server/src/modules/common-cartridge/export/utils.spec.ts b/apps/server/src/modules/common-cartridge/export/utils.spec.ts index 0f86cada2cf..2a5b5b7de60 100644 --- a/apps/server/src/modules/common-cartridge/export/utils.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/utils.spec.ts @@ -1,5 +1,5 @@ import { ObjectId } from 'bson'; -import { buildXmlString, checkIntendedUse, createIdentifier } from './utils'; +import { buildXmlString, createIdentifier } from './utils'; describe('CommonCartridgeUtils', () => { describe('buildXmlString', () => { @@ -23,16 +23,4 @@ describe('CommonCartridgeUtils', () => { }); }); }); - - describe('checkIntendedUse', () => { - describe('when intended use is not supported', () => { - it('should throw error', () => { - const supportedIntendedUses = ['use1', 'use2']; - - expect(() => checkIntendedUse('use3', supportedIntendedUses)).toThrowError( - 'Intended use use3 is not supported' - ); - }); - }); - }); }); diff --git a/apps/server/src/modules/common-cartridge/export/utils.ts b/apps/server/src/modules/common-cartridge/export/utils.ts index f097c9be944..0e22175216e 100644 --- a/apps/server/src/modules/common-cartridge/export/utils.ts +++ b/apps/server/src/modules/common-cartridge/export/utils.ts @@ -23,9 +23,3 @@ export function createIdentifier(identifier?: string | ObjectId): string { return `i${identifier.toString()}`; } - -export function checkIntendedUse(intendedUse: string, supportedIntendedUses: string[]): void | never { - if (!supportedIntendedUses.includes(intendedUse)) { - throw new Error(`Intended use ${intendedUse} is not supported`); - } -} From 6ca75beb67e832cfd1b2209f6613427dfe843233 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 16 Apr 2024 16:18:39 +0200 Subject: [PATCH 04/46] EW-793 Work in progress --- .../builders/common-cartridge-file-builder.ts | 193 +++++++++++++++++- ...n-cartridge-resource-collection-builder.ts | 16 ++ .../common-cartridge-resource-factory.ts | 2 +- 3 files changed, 203 insertions(+), 8 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts index 0f605b5561d..0fde56360cd 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts @@ -1,16 +1,19 @@ import AdmZip from 'adm-zip'; -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../common-cartridge.enums'; import { CommonCartridgeElementFactory, CommonCartridgeElementProps, } from '../elements/common-cartridge-element-factory'; import { CommonCartridgeElement, CommonCartridgeResource } from '../interfaces'; -import { CommonCartridgeResourceFactory } from '../resources/common-cartridge-resource-factory'; -import { OmitVersion } from '../utils'; import { - CommonCartridgeOrganizationBuilder, - CommonCartridgeOrganizationBuilderOptions, -} from './common-cartridge-organization-builder'; + CommonCartridgeResourceFactory, + CommonCartridgeResourcePropsInternal, +} from '../resources/common-cartridge-resource-factory'; +import { CommonCartridgeOrganizationBuilder } from './common-cartridge-organization-builder'; export type CommonCartridgeFileBuilderProps = { version: CommonCartridgeVersion; @@ -37,7 +40,16 @@ export class CommonCartridgeFileBuilder { return this; } - public addOrganization( + public addOrganization(organizationBuilder: CommonCartridgeOrganizationBuilder): void { + const builder = new CommonCartridgeOrganizationBuilder( + { ...props, version: this.props.version }, + (resource: CommonCartridgeResource) => this.resources.push(resource) + ); + + this.organizationBuilders.push(organizationBuilder); + } + + /* public addOrganization( props: OmitVersion ): CommonCartridgeOrganizationBuilder { const builder = new CommonCartridgeOrganizationBuilder( @@ -49,6 +61,7 @@ export class CommonCartridgeFileBuilder { return builder; } +*/ public async build(): Promise { if (!this.metadata) { @@ -78,3 +91,169 @@ export class CommonCartridgeFileBuilder { return buffer; } } + +type CCFileBuilderOptions = { + version: CommonCartridgeVersion; + identifier: string; +}; + +interface CCMetadataBuilder { + setTitle(title: string): CCMetadataBuilder; + + setCreationDate(date: Date): CCMetadataBuilder; + + setCopyrightOwners(copyrightOwners: string[]): CCMetadataBuilder; // addCopyrightOwner Methode hinzufügen +} + +class CCMetadataBuilderImpl implements CCMetadataBuilder { + private title = ''; + + private creationDate: Date = new Date(); + + private copyrightOwners: string[] = []; + + constructor(private readonly props: CCFileBuilderOptions) {} + + public setTitle(title: string): CCMetadataBuilder { + this.title = title; + + return this; + } + + public setCreationDate(date: Date): CCMetadataBuilder { + this.creationDate = date; + + return this; + } + + public setCopyrightOwners(copyrightOwners: string[]): CCMetadataBuilder { + this.copyrightOwners = copyrightOwners; + + return this; + } + + public build(): CommonCartridgeElement { + const metadataElement = CommonCartridgeElementFactory.createElement({ + type: CommonCartridgeElementType.METADATA, + version: this.props.version, + title: this.title, + creationDate: this.creationDate, + copyrightOwners: this.copyrightOwners, + }); + + return metadataElement; + } +} + +type CCOrganizationBuilderOptions = { + version: CommonCartridgeVersion; + identifier: string; + title: string; +} & CCFileBuilderOptions; + +class CCOrganizationBuilderImpl { + private identifier = ''; + + private title = ''; + + private items = new Array(); + + constructor( + private readonly resourceBuilder: CCResourceBuilder, + private readonly props: CCOrganizationBuilderOptions + ) {} + + public addOrganization(props: CCOrganizationBuilderOptions): CCOrganizationBuilderImpl { + const subOrganizationBuilder = new CCOrganizationBuilderImpl(this.resourceBuilder, props); + + this.items.push(subOrganizationBuilder); + + return this; + } + + public build(): CommonCartridgeElement { + throw new Error('Method not implemented.'); + } +} + +class CCResourceBuilder { + private readonly resources = new Array(); + + constructor(private readonly props: CCFileBuilderOptions) {} + + public addResource(resource: CommonCartridgeResourcePropsInternal): CCResourceBuilder { + this.resources.push(resource); + + return this; + } + + public build(): CommonCartridgeResource[] { + const result = this.resources.map((resource) => + CommonCartridgeResourceFactory.createResource({ + ...resource, + version: this.props.version, + }) + ); + + return result; + } +} + +export class CCFileBuilder { + private readonly metadataBuilder: CCMetadataBuilderImpl; + + private readonly organizationBuilder: CCOrganizationBuilderImpl; + + private readonly resourceBuilder: CCResourceBuilder; + + constructor(private readonly props: CCFileBuilderOptions) { + this.resourceBuilder = new CCResourceBuilder(props); + this.metadataBuilder = new CCMetadataBuilderImpl(props); + this.organizationBuilder = new CCOrganizationBuilderImpl(this.resourceBuilder, props); + } + + public get metadata(): CCMetadataBuilder { + return this.metadataBuilder; + } + + public get organizations(): CCOrganizationBuilder { + return this.organizationBuilder; + } + + public build(): Buffer { + const archive = new AdmZip(); + const organization = this.organizationBuilder.build(); + const resources = this.resourceBuilder.build(); + const manifest = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.MANIFEST, + version: this.props.version, + identifier: this.props.identifier, + metadata: this.metadataBuilder.build(), + organization, + resources, + }); + + archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); + + for (const resource of resources.filter((res) => !res.canInline())) { + archive.addFile(resource.getFilePath(), Buffer.from(resource.getFileContent())); + } + + return archive.toBuffer(); + } +} + +const fileBuilder = new CCFileBuilder({ + version: CommonCartridgeVersion.V_1_1_0, + identifier: 'test', +}); + +fileBuilder.metadata.setTitle('Test').setCreationDate(new Date()).setCopyrightOwners(['Simone', 'Patrick']); + +const orga1 = fileBuilder.organizations.setIdentifier('org1').setTitle('Organization 1').addOrganization(); + +const sub1 = orga1.addOrganization().setIdentifier('sub1').setTitle('Suborganization 1'); +const sub2 = orga1.addOrganization().setIdentifier('sub2').setTitle('Suborganization 2'); +const subSub1 = sub1.addOrganization().setIdentifier('subsub1').setTitle('Subsuborganization 1'); + +console.log(fileBuilder.build()); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts new file mode 100644 index 00000000000..31d4f76a672 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts @@ -0,0 +1,16 @@ +import { CommonCartridgeResource } from '../interfaces'; +import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; + +export class CommonCartridgeResourceCollectionBuilder { + private readonly resources = new Array(); + + constructor(private readonly props: CommonCartridgeResourceProps) {} + + public addResource(resource: CommonCartridgeResource): void { + this.resources.push(resource); + } + + public getResources(): CommonCartridgeResource[] { + return this.resources; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts index 21050539eaa..1ef3cc1428d 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/common-cartridge-resource-factory.ts @@ -21,7 +21,7 @@ export type CommonCartridgeResourceProps = | OmitVersionAndFolder | OmitVersionAndFolder; -type CommonCartridgeResourcePropsInternal = +export type CommonCartridgeResourcePropsInternal = | CommonCartridgeManifestResourcePropsV110 | CommonCartridgeWebContentResourcePropsV110 | CommonCartridgeWebLinkResourcePropsV110 From 2ee5a6302fc207f0163151aa0f96813c643edae8 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Tue, 16 Apr 2024 16:43:25 +0200 Subject: [PATCH 05/46] EW-793 Working in progress --- .../common-cartridge/export/builders/tree.ts | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 apps/server/src/modules/common-cartridge/export/builders/tree.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/tree.ts b/apps/server/src/modules/common-cartridge/export/builders/tree.ts new file mode 100644 index 00000000000..b8842c16d4c --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/tree.ts @@ -0,0 +1,53 @@ +export class TNode { + private readonly _value: T; + + private readonly _parent: TNode | null = null; + + private readonly _children: TNode[] = []; + + constructor(value: T, parent: TNode | null, children?: TNode[]) { + this._value = value; + this._parent = parent; + this._children = children || []; + + if (this._parent) { + this._parent.addChild(this); + } + } + + public get value(): T { + return this._value; + } + + public get parent(): TNode | null { + return this._parent; + } + + public get children(): TNode[] { + return this._children; + } + + public addChild(child: TNode): void { + this._children.push(child); + } +} + +export class NTree { + private readonly _root: TNode[]; + + constructor(rootValue: T[]) { + this._root = rootValue.map((value) => new TNode(value, null)); + } + + public get root(): TNode { + return this._root; + } + + public addNode(value: T, parent: TNode): TNode { + return new TNode(value, parent); + } + + public traverse(): Record { + return this._root.map((node) => this.traverseNode(node)); + } +} From 9a6d51a441ed972ee497ddd1eb13d76a36ec0578 Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Wed, 17 Apr 2024 15:58:36 +0200 Subject: [PATCH 06/46] EW-793 work in progress Co-authored-by: Simone Radtke --- .../common-cartridge-export.factory.ts | 152 +++++++ .../builders/common-cartridge-file-builder.ts | 396 +++++++++--------- ...n-cartridge-resource-collection-builder.ts | 16 - .../common-cartridge-resources-builder.ts | 31 ++ .../common-cartridge/export/builders/tree.ts | 53 --- .../src/modules/common-cartridge/index.ts | 8 +- .../mapper/common-cartridge.mapper.ts | 7 +- .../common-cartridge-export.service.ts | 220 +++++----- 8 files changed, 513 insertions(+), 370 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts delete mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts create mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts delete mode 100644 apps/server/src/modules/common-cartridge/export/builders/tree.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts new file mode 100644 index 00000000000..a81c1f9e2ac --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts @@ -0,0 +1,152 @@ +import AdmZip from 'adm-zip'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../common-cartridge.enums'; +import { + CommonCartridgeElementFactory, + CommonCartridgeElementProps, +} from '../elements/common-cartridge-element-factory'; +import { CommonCartridgeOrganizationElementPropsV110 } from '../elements/v1.1.0'; +import { CommonCartridgeOrganizationElementPropsV130 } from '../elements/v1.3.0'; +import { CommonCartridgeElement, CommonCartridgeResource } from '../interfaces'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourceProps, +} from '../resources/common-cartridge-resource-factory'; +import { CommonCartridgeResourcesBuilder } from './common-cartridge-resources-builder'; + +class CommonCartridgeResourceNode { + private readonly parent: CommonCartridgeOrganizationNode; + + constructor( + private readonly props: CommonCartridgeResourceProps & { version: CommonCartridgeVersion }, + parent: CommonCartridgeOrganizationNode + ) { + this.parent = parent; + } + + public get folder(): string { + return this.parent ? `${this.parent.folder}/${this.props.identifier}` : this.props.identifier; + } + + public build(): CommonCartridgeResource { + const resource = CommonCartridgeResourceFactory.createResource({ ...this.props, folder: this.parent.folder }); + + return resource; + } +} + +type CommonCartridgeOrganizationNodeProps = Omit< + CommonCartridgeOrganizationElementPropsV110 | CommonCartridgeOrganizationElementPropsV130, + 'items' +>; + +export class CommonCartridgeOrganizationNode { + private readonly parent: CommonCartridgeOrganizationNode | null = null; + + private readonly children: (CommonCartridgeOrganizationNode | CommonCartridgeResourceNode)[] = []; + + constructor( + private readonly props: CommonCartridgeOrganizationNodeProps, + parent: CommonCartridgeOrganizationNode | null + ) { + this.parent = parent; + + if (parent) { + parent.addChild(this); + } + } + + public get folder(): string { + return this.parent ? `${this.parent.folder}/${this.props.identifier}` : this.props.identifier; + } + + public addChild(organization: CommonCartridgeOrganizationNode | CommonCartridgeResourceNode): void { + this.children.push(organization); + } + + public build(): CommonCartridgeElement { + const organization = CommonCartridgeElementFactory.createElement({ + ...this.props, + version: this.props.version, + items: this.children.map((child) => child.build()), + }); + + return organization; + } +} + +type CommonCartridgeExportFactoryProps = { + version: CommonCartridgeVersion; + identifier: string; +}; + +export class CommonCartridgeExportFactory { + private readonly resourcesBuilder: CommonCartridgeResourcesBuilder; + + private readonly organizationsRoot: CommonCartridgeOrganizationNode[] = []; + + private metadataElement: CommonCartridgeElement | null = null; + + constructor(private readonly props: CommonCartridgeExportFactoryProps) { + this.resourcesBuilder = new CommonCartridgeResourcesBuilder({ version: props.version }); + } + + public addMetadata(props: CommonCartridgeElementProps): void { + this.metadataElement = CommonCartridgeElementFactory.createElement({ + version: this.props.version, + ...props, + }); + } + + public addOrganization( + props: Omit, + parent: CommonCartridgeOrganizationNode | null + ): CommonCartridgeOrganizationNode { + const organization = new CommonCartridgeOrganizationNode( + { ...props, version: this.props.version, type: CommonCartridgeElementType.ORGANIZATION }, + parent + ); + + if (!parent) { + this.organizationsRoot.push(organization); + } + + return organization; + } + + public addResource(resource: CommonCartridgeResourceProps, parent: CommonCartridgeOrganizationNode): void { + parent.addChild(new CommonCartridgeResourceNode({ ...resource, version: this.props.version }, parent)); + + this.resourcesBuilder.addResource(resource); + } + + public build(): Buffer { + if (!this.metadataElement) { + throw new Error('Metadata is required'); + } + + const archive = new AdmZip(); + const organizations = this.organizationsRoot.map((organization) => organization.build()); + const resources = this.resourcesBuilder.build(); + const manifest = CommonCartridgeResourceFactory.createResource({ + type: CommonCartridgeResourceType.MANIFEST, + version: this.props.version, + identifier: this.props.identifier, + metadata: this.metadataElement, + organizations, + resources, + }); + + archive.addFile('imsmanifest.xml', Buffer.from(manifest.getFileContent())); + + this.resourcesBuilder + .build() + .filter((resource) => !resource.canInline) + .forEach((resource) => archive.addFile(resource.getFilePath(), Buffer.from(resource.getFileContent()))); + + return archive.toBuffer(); + } +} diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts index 0fde56360cd..913cafde643 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts @@ -1,259 +1,259 @@ -import AdmZip from 'adm-zip'; -import { - CommonCartridgeElementType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../common-cartridge.enums'; -import { - CommonCartridgeElementFactory, - CommonCartridgeElementProps, -} from '../elements/common-cartridge-element-factory'; -import { CommonCartridgeElement, CommonCartridgeResource } from '../interfaces'; -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourcePropsInternal, -} from '../resources/common-cartridge-resource-factory'; -import { CommonCartridgeOrganizationBuilder } from './common-cartridge-organization-builder'; - -export type CommonCartridgeFileBuilderProps = { - version: CommonCartridgeVersion; - identifier: string; -}; +// import AdmZip from 'adm-zip'; +// import { +// CommonCartridgeElementType, +// CommonCartridgeResourceType, +// CommonCartridgeVersion, +// } from '../common-cartridge.enums'; +// import { +// CommonCartridgeElementFactory, +// CommonCartridgeElementProps, +// } from '../elements/common-cartridge-element-factory'; +// import { CommonCartridgeElement, CommonCartridgeResource } from '../interfaces'; +// import { +// CommonCartridgeResourceFactory, +// CommonCartridgeResourcePropsInternal, +// } from '../resources/common-cartridge-resource-factory'; +// import { CommonCartridgeOrganizationBuilder } from './common-cartridge-organization-builder'; + +// export type CommonCartridgeFileBuilderProps = { +// version: CommonCartridgeVersion; +// identifier: string; +// }; -export class CommonCartridgeFileBuilder { - private readonly archive: AdmZip = new AdmZip(); +// export class CommonCartridgeFileBuilder { +// private readonly archive: AdmZip = new AdmZip(); - private readonly organizationBuilders = new Array(); +// private readonly organizationBuilders = new Array(); - private readonly resources = new Array(); +// private readonly resources = new Array(); - private metadata?: CommonCartridgeElement; +// private metadata?: CommonCartridgeElement; - constructor(private readonly props: CommonCartridgeFileBuilderProps) {} +// constructor(private readonly props: CommonCartridgeFileBuilderProps) {} - public addMetadata(props: CommonCartridgeElementProps): CommonCartridgeFileBuilder { - this.metadata = CommonCartridgeElementFactory.createElement({ - version: this.props.version, - ...props, - }); +// public addMetadata(props: CommonCartridgeElementProps): CommonCartridgeFileBuilder { +// this.metadata = CommonCartridgeElementFactory.createElement({ +// version: this.props.version, +// ...props, +// }); - return this; - } - - public addOrganization(organizationBuilder: CommonCartridgeOrganizationBuilder): void { - const builder = new CommonCartridgeOrganizationBuilder( - { ...props, version: this.props.version }, - (resource: CommonCartridgeResource) => this.resources.push(resource) - ); - - this.organizationBuilders.push(organizationBuilder); - } - - /* public addOrganization( - props: OmitVersion - ): CommonCartridgeOrganizationBuilder { - const builder = new CommonCartridgeOrganizationBuilder( - { ...props, version: this.props.version }, - (resource: CommonCartridgeResource) => this.resources.push(resource) - ); +// return this; +// } + +// public addOrganization(organizationBuilder: CommonCartridgeOrganizationBuilder): void { +// const builder = new CommonCartridgeOrganizationBuilder( +// { ...props, version: this.props.version }, +// (resource: CommonCartridgeResource) => this.resources.push(resource) +// ); + +// this.organizationBuilders.push(organizationBuilder); +// } + +// /* public addOrganization( +// props: OmitVersion +// ): CommonCartridgeOrganizationBuilder { +// const builder = new CommonCartridgeOrganizationBuilder( +// { ...props, version: this.props.version }, +// (resource: CommonCartridgeResource) => this.resources.push(resource) +// ); - this.organizationBuilders.push(builder); +// this.organizationBuilders.push(builder); - return builder; - } -*/ +// return builder; +// } +// */ - public async build(): Promise { - if (!this.metadata) { - throw new Error('Metadata is not defined'); - } +// public async build(): Promise { +// if (!this.metadata) { +// throw new Error('Metadata is not defined'); +// } - const organizations = this.organizationBuilders.map((builder) => builder.build()); - const manifest = CommonCartridgeResourceFactory.createResource({ - type: CommonCartridgeResourceType.MANIFEST, - version: this.props.version, - identifier: this.props.identifier, - metadata: this.metadata, - organizations, - resources: this.resources, - }); +// const organizations = this.organizationBuilders.map((builder) => builder.build()); +// const manifest = CommonCartridgeResourceFactory.createResource({ +// type: CommonCartridgeResourceType.MANIFEST, +// version: this.props.version, +// identifier: this.props.identifier, +// metadata: this.metadata, +// organizations, +// resources: this.resources, +// }); - for (const resources of this.resources) { - if (!resources.canInline()) { - this.archive.addFile(resources.getFilePath(), Buffer.from(resources.getFileContent())); - } - } +// for (const resources of this.resources) { +// if (!resources.canInline()) { +// this.archive.addFile(resources.getFilePath(), Buffer.from(resources.getFileContent())); +// } +// } - this.archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); +// this.archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); - const buffer = await this.archive.toBufferPromise(); +// const buffer = await this.archive.toBufferPromise(); - return buffer; - } -} +// return buffer; +// } +// } -type CCFileBuilderOptions = { - version: CommonCartridgeVersion; - identifier: string; -}; +// type CCFileBuilderOptions = { +// version: CommonCartridgeVersion; +// identifier: string; +// }; -interface CCMetadataBuilder { - setTitle(title: string): CCMetadataBuilder; +// interface CCMetadataBuilder { +// setTitle(title: string): CCMetadataBuilder; - setCreationDate(date: Date): CCMetadataBuilder; +// setCreationDate(date: Date): CCMetadataBuilder; - setCopyrightOwners(copyrightOwners: string[]): CCMetadataBuilder; // addCopyrightOwner Methode hinzufügen -} +// setCopyrightOwners(copyrightOwners: string[]): CCMetadataBuilder; // addCopyrightOwner Methode hinzufügen +// } -class CCMetadataBuilderImpl implements CCMetadataBuilder { - private title = ''; +// class CCMetadataBuilderImpl implements CCMetadataBuilder { +// private title = ''; - private creationDate: Date = new Date(); +// private creationDate: Date = new Date(); - private copyrightOwners: string[] = []; +// private copyrightOwners: string[] = []; - constructor(private readonly props: CCFileBuilderOptions) {} +// constructor(private readonly props: CCFileBuilderOptions) {} - public setTitle(title: string): CCMetadataBuilder { - this.title = title; +// public setTitle(title: string): CCMetadataBuilder { +// this.title = title; - return this; - } +// return this; +// } - public setCreationDate(date: Date): CCMetadataBuilder { - this.creationDate = date; +// public setCreationDate(date: Date): CCMetadataBuilder { +// this.creationDate = date; - return this; - } +// return this; +// } - public setCopyrightOwners(copyrightOwners: string[]): CCMetadataBuilder { - this.copyrightOwners = copyrightOwners; +// public setCopyrightOwners(copyrightOwners: string[]): CCMetadataBuilder { +// this.copyrightOwners = copyrightOwners; - return this; - } +// return this; +// } - public build(): CommonCartridgeElement { - const metadataElement = CommonCartridgeElementFactory.createElement({ - type: CommonCartridgeElementType.METADATA, - version: this.props.version, - title: this.title, - creationDate: this.creationDate, - copyrightOwners: this.copyrightOwners, - }); +// public build(): CommonCartridgeElement { +// const metadataElement = CommonCartridgeElementFactory.createElement({ +// type: CommonCartridgeElementType.METADATA, +// version: this.props.version, +// title: this.title, +// creationDate: this.creationDate, +// copyrightOwners: this.copyrightOwners, +// }); - return metadataElement; - } -} +// return metadataElement; +// } +// } -type CCOrganizationBuilderOptions = { - version: CommonCartridgeVersion; - identifier: string; - title: string; -} & CCFileBuilderOptions; +// type CCOrganizationBuilderOptions = { +// version: CommonCartridgeVersion; +// identifier: string; +// title: string; +// } & CCFileBuilderOptions; -class CCOrganizationBuilderImpl { - private identifier = ''; +// class CCOrganizationBuilderImpl { +// private identifier = ''; - private title = ''; +// private title = ''; - private items = new Array(); +// private items = new Array(); - constructor( - private readonly resourceBuilder: CCResourceBuilder, - private readonly props: CCOrganizationBuilderOptions - ) {} +// constructor( +// private readonly resourceBuilder: CCResourceBuilder, +// private readonly props: CCOrganizationBuilderOptions +// ) {} - public addOrganization(props: CCOrganizationBuilderOptions): CCOrganizationBuilderImpl { - const subOrganizationBuilder = new CCOrganizationBuilderImpl(this.resourceBuilder, props); +// public addOrganization(props: CCOrganizationBuilderOptions): CCOrganizationBuilderImpl { +// const subOrganizationBuilder = new CCOrganizationBuilderImpl(this.resourceBuilder, props); - this.items.push(subOrganizationBuilder); +// this.items.push(subOrganizationBuilder); - return this; - } +// return this; +// } - public build(): CommonCartridgeElement { - throw new Error('Method not implemented.'); - } -} +// public build(): CommonCartridgeElement { +// throw new Error('Method not implemented.'); +// } +// } -class CCResourceBuilder { - private readonly resources = new Array(); +// class CCResourceBuilder { +// private readonly resources = new Array(); - constructor(private readonly props: CCFileBuilderOptions) {} +// constructor(private readonly props: CCFileBuilderOptions) {} - public addResource(resource: CommonCartridgeResourcePropsInternal): CCResourceBuilder { - this.resources.push(resource); +// public addResource(resource: CommonCartridgeResourcePropsInternal): CCResourceBuilder { +// this.resources.push(resource); - return this; - } +// return this; +// } - public build(): CommonCartridgeResource[] { - const result = this.resources.map((resource) => - CommonCartridgeResourceFactory.createResource({ - ...resource, - version: this.props.version, - }) - ); +// public build(): CommonCartridgeResource[] { +// const result = this.resources.map((resource) => +// CommonCartridgeResourceFactory.createResource({ +// ...resource, +// version: this.props.version, +// }) +// ); - return result; - } -} +// return result; +// } +// } -export class CCFileBuilder { - private readonly metadataBuilder: CCMetadataBuilderImpl; +// export class CCFileBuilder { +// private readonly metadataBuilder: CCMetadataBuilderImpl; - private readonly organizationBuilder: CCOrganizationBuilderImpl; +// private readonly organizationBuilder: CCOrganizationBuilderImpl; - private readonly resourceBuilder: CCResourceBuilder; +// private readonly resourceBuilder: CCResourceBuilder; - constructor(private readonly props: CCFileBuilderOptions) { - this.resourceBuilder = new CCResourceBuilder(props); - this.metadataBuilder = new CCMetadataBuilderImpl(props); - this.organizationBuilder = new CCOrganizationBuilderImpl(this.resourceBuilder, props); - } +// constructor(private readonly props: CCFileBuilderOptions) { +// this.resourceBuilder = new CCResourceBuilder(props); +// this.metadataBuilder = new CCMetadataBuilderImpl(props); +// this.organizationBuilder = new CCOrganizationBuilderImpl(this.resourceBuilder, props); +// } - public get metadata(): CCMetadataBuilder { - return this.metadataBuilder; - } +// public get metadata(): CCMetadataBuilder { +// return this.metadataBuilder; +// } - public get organizations(): CCOrganizationBuilder { - return this.organizationBuilder; - } +// public get organizations(): CCOrganizationBuilder { +// return this.organizationBuilder; +// } - public build(): Buffer { - const archive = new AdmZip(); - const organization = this.organizationBuilder.build(); - const resources = this.resourceBuilder.build(); - const manifest = CommonCartridgeResourceFactory.createResource({ - type: CommonCartridgeResourceType.MANIFEST, - version: this.props.version, - identifier: this.props.identifier, - metadata: this.metadataBuilder.build(), - organization, - resources, - }); +// public build(): Buffer { +// const archive = new AdmZip(); +// const organization = this.organizationBuilder.build(); +// const resources = this.resourceBuilder.build(); +// const manifest = CommonCartridgeResourceFactory.createResource({ +// type: CommonCartridgeResourceType.MANIFEST, +// version: this.props.version, +// identifier: this.props.identifier, +// metadata: this.metadataBuilder.build(), +// organization, +// resources, +// }); - archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); +// archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); - for (const resource of resources.filter((res) => !res.canInline())) { - archive.addFile(resource.getFilePath(), Buffer.from(resource.getFileContent())); - } +// for (const resource of resources.filter((res) => !res.canInline())) { +// archive.addFile(resource.getFilePath(), Buffer.from(resource.getFileContent())); +// } - return archive.toBuffer(); - } -} +// return archive.toBuffer(); +// } +// } -const fileBuilder = new CCFileBuilder({ - version: CommonCartridgeVersion.V_1_1_0, - identifier: 'test', -}); +// const fileBuilder = new CCFileBuilder({ +// version: CommonCartridgeVersion.V_1_1_0, +// identifier: 'test', +// }); -fileBuilder.metadata.setTitle('Test').setCreationDate(new Date()).setCopyrightOwners(['Simone', 'Patrick']); +// fileBuilder.metadata.setTitle('Test').setCreationDate(new Date()).setCopyrightOwners(['Simone', 'Patrick']); -const orga1 = fileBuilder.organizations.setIdentifier('org1').setTitle('Organization 1').addOrganization(); +// const orga1 = fileBuilder.organizations.setIdentifier('org1').setTitle('Organization 1').addOrganization(); -const sub1 = orga1.addOrganization().setIdentifier('sub1').setTitle('Suborganization 1'); -const sub2 = orga1.addOrganization().setIdentifier('sub2').setTitle('Suborganization 2'); -const subSub1 = sub1.addOrganization().setIdentifier('subsub1').setTitle('Subsuborganization 1'); +// const sub1 = orga1.addOrganization().setIdentifier('sub1').setTitle('Suborganization 1'); +// const sub2 = orga1.addOrganization().setIdentifier('sub2').setTitle('Suborganization 2'); +// const subSub1 = sub1.addOrganization().setIdentifier('subsub1').setTitle('Subsuborganization 1'); -console.log(fileBuilder.build()); +// console.log(fileBuilder.build()); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts deleted file mode 100644 index 31d4f76a672..00000000000 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { CommonCartridgeResource } from '../interfaces'; -import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; - -export class CommonCartridgeResourceCollectionBuilder { - private readonly resources = new Array(); - - constructor(private readonly props: CommonCartridgeResourceProps) {} - - public addResource(resource: CommonCartridgeResource): void { - this.resources.push(resource); - } - - public getResources(): CommonCartridgeResource[] { - return this.resources; - } -} diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts new file mode 100644 index 00000000000..9cd33b43d98 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts @@ -0,0 +1,31 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResource } from '../interfaces'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourceProps, + CommonCartridgeResourcePropsInternal, +} from '../resources/common-cartridge-resource-factory'; + +type CommonCartridgeResourcesBuilderProps = { + version: CommonCartridgeVersion; +}; + +export class CommonCartridgeResourcesBuilder { + private readonly resources: CommonCartridgeResourceProps[] = []; + + constructor(private readonly props: CommonCartridgeResourcesBuilderProps) {} + + addResource(resource: CommonCartridgeResourceProps): void { + this.resources.push(resource); + } + + build(): CommonCartridgeResource[] { + return this.resources.map((resource) => + CommonCartridgeResourceFactory.createResource({ + // TODO: Fix this cast + version: this.props.version, + ...resource, + } as CommonCartridgeResourcePropsInternal) + ); + } +} diff --git a/apps/server/src/modules/common-cartridge/export/builders/tree.ts b/apps/server/src/modules/common-cartridge/export/builders/tree.ts deleted file mode 100644 index b8842c16d4c..00000000000 --- a/apps/server/src/modules/common-cartridge/export/builders/tree.ts +++ /dev/null @@ -1,53 +0,0 @@ -export class TNode { - private readonly _value: T; - - private readonly _parent: TNode | null = null; - - private readonly _children: TNode[] = []; - - constructor(value: T, parent: TNode | null, children?: TNode[]) { - this._value = value; - this._parent = parent; - this._children = children || []; - - if (this._parent) { - this._parent.addChild(this); - } - } - - public get value(): T { - return this._value; - } - - public get parent(): TNode | null { - return this._parent; - } - - public get children(): TNode[] { - return this._children; - } - - public addChild(child: TNode): void { - this._children.push(child); - } -} - -export class NTree { - private readonly _root: TNode[]; - - constructor(rootValue: T[]) { - this._root = rootValue.map((value) => new TNode(value, null)); - } - - public get root(): TNode { - return this._root; - } - - public addNode(value: T, parent: TNode): TNode { - return new TNode(value, parent); - } - - public traverse(): Record { - return this._root.map((node) => this.traverseNode(node)); - } -} diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts index 4c6746ee1e2..7748da22999 100644 --- a/apps/server/src/modules/common-cartridge/index.ts +++ b/apps/server/src/modules/common-cartridge/index.ts @@ -1,7 +1,7 @@ -export { - CommonCartridgeFileBuilder, - CommonCartridgeFileBuilderProps, -} from './export/builders/common-cartridge-file-builder'; +// export { +// CommonCartridgeFileBuilder, +// CommonCartridgeFileBuilderProps, +// } from './export/builders/common-cartridge-file-builder'; export { CommonCartridgeOrganizationBuilder, CommonCartridgeOrganizationBuilderOptions, diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index b5e89980278..68d4435d80b 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -1,7 +1,7 @@ import { CommonCartridgeElementProps, CommonCartridgeElementType, - CommonCartridgeFileBuilderProps, + // CommonCartridgeFileBuilderProps, CommonCartridgeIntendedUseType, CommonCartridgeOrganizationBuilderOptions, CommonCartridgeResourceProps, @@ -111,7 +111,10 @@ export class CommonCartridgeMapper { } } - public mapCourseToManifest(version: CommonCartridgeVersion, course: Course): CommonCartridgeFileBuilderProps { + public mapCourseToManifest( + version: CommonCartridgeVersion, + course: Course + ): { version: CommonCartridgeVersion; identifier: string } { return { version, identifier: createIdentifier(course.id), diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 2c82d7e1a3e..2c7320df2b9 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -1,15 +1,14 @@ -import { - CommonCartridgeFileBuilder, - CommonCartridgeOrganizationBuilder, - CommonCartridgeVersion, -} from '@modules/common-cartridge'; +import { CommonCartridgeVersion } from '@modules/common-cartridge'; import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { Injectable } from '@nestjs/common'; -import { BoardExternalReferenceType, Column, Card } from '@shared/domain/domainobject'; -import { ComponentProperties } from '@shared/domain/entity'; +import { BoardExternalReferenceType, Card, Column } from '@shared/domain/domainobject'; import { EntityId } from '@shared/domain/types'; import { ColumnBoardService } from '@src/modules/board'; +import { + CommonCartridgeExportFactory, + CommonCartridgeOrganizationNode as CommonCartridgeOrganizationBuilder, +} from '@src/modules/common-cartridge/export/builders/common-cartridge-export.factory'; import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; import { CourseService } from './course.service'; @@ -28,74 +27,84 @@ export class CommonCartridgeExportService { courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion, + // eslint-disable-next-line @typescript-eslint/no-unused-vars exportedTopics: string[], + // eslint-disable-next-line @typescript-eslint/no-unused-vars exportedTasks: string[] ): Promise { const course = await this.courseService.findById(courseId); - const builder = new CommonCartridgeFileBuilder(this.commonCartridgeMapper.mapCourseToManifest(version, course)); + const builder = new CommonCartridgeExportFactory(this.commonCartridgeMapper.mapCourseToManifest(version, course)); builder.addMetadata(this.commonCartridgeMapper.mapCourseToMetadata(course)); - await this.addLessons(builder, courseId, version, exportedTopics); - await this.addTasks(builder, courseId, userId, version, exportedTasks); + // await this.addLessons(builder, courseId, version, exportedTopics); + // await this.addTasks(builder, courseId, userId, version, exportedTasks); await this.addColumnBoards(builder, courseId); return builder.build(); } - private async addLessons( - builder: CommonCartridgeFileBuilder, - courseId: EntityId, - version: CommonCartridgeVersion, - topics: string[] - ): Promise { - const [lessons] = await this.lessonService.findByCourseIds([courseId]); - - lessons.forEach((lesson) => { - if (!topics.includes(lesson.id)) { - return; - } - - const organizationBuilder = builder.addOrganization(this.commonCartridgeMapper.mapLessonToOrganization(lesson)); - - lesson.contents.forEach((content) => { - this.addComponentToOrganization(organizationBuilder, content); - }); - - lesson.getLessonLinkedTasks().forEach((task) => { - organizationBuilder.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); - }); - }); - } - - private async addTasks( - builder: CommonCartridgeFileBuilder, - courseId: EntityId, - userId: EntityId, - version: CommonCartridgeVersion, - exportedTasks: string[] - ): Promise { - const [tasks] = await this.taskService.findBySingleParent(userId, courseId); - - if (tasks.length === 0) { - return; - } - - const organization = builder.addOrganization({ - title: '', - identifier: createIdentifier(), - }); - - tasks.forEach((task) => { - if (!exportedTasks.includes(task.id)) { - return; - } - - organization.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); - }); - } - - private async addColumnBoards(builder: CommonCartridgeFileBuilder, courseId: EntityId): Promise { + // private async addLessons( + // builder: CommonCartridgeExportFactory, + // courseId: EntityId, + // version: CommonCartridgeVersion, + // topics: string[] + // ): Promise { + // const [lessons] = await this.lessonService.findByCourseIds([courseId]); + + // lessons.forEach((lesson) => { + // if (!topics.includes(lesson.id)) { + // return; + // } + + // const organizationBuilder = builder.addOrganization( + // { + // type: CommonCartridgeElementType.ORGANIZATION, + // identifier: createIdentifier(lesson.id), + // title: lesson.name, + // items: [], + // }, + // null + // ); + + // lesson.contents.forEach((content) => { + // this.addComponentToOrganization(organizationBuilder, content); + // }); + + // lesson.getLessonLinkedTasks().forEach((task) => { + // organizationBuilder.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); + // }); + // }); + // } + + // private async addTasks( + // builder: CommonCartridgeExportFactory, + // courseId: EntityId, + // userId: EntityId, + // version: CommonCartridgeVersion, + // exportedTasks: string[] + // ): Promise { + // const [tasks] = await this.taskService.findBySingleParent(userId, courseId); + + // if (tasks.length === 0) { + // return; + // } + + // const organization = builder.addOrganization({ + // title: '', + // identifier: createIdentifier(), + // }); + + // tasks.forEach((task) => { + // if (!exportedTasks.includes(task.id)) { + // return; + // } + + // organization.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); + // }); + // } + + private async addColumnBoards(builder: CommonCartridgeExportFactory, courseId: EntityId): Promise { const columnBoardIds = await this.columnBoardService.findIdsByExternalReference({ type: BoardExternalReferenceType.Course, id: courseId, @@ -104,53 +113,70 @@ export class CommonCartridgeExportService { for await (const columnBoardId of columnBoardIds) { const columnBoard = await this.columnBoardService.findById(columnBoardId); - const organization = builder.addOrganization({ - title: columnBoard.title, - identifier: createIdentifier(columnBoard.id), - }); + const organization = builder.addOrganization( + { + title: columnBoard.title, + identifier: createIdentifier(columnBoard.id), + }, + null + ); columnBoard.children .filter((child) => child instanceof Column) - .forEach((column) => this.addColumnToOrganization(column as Column, organization)); + .forEach((column) => this.addColumnToOrganization(column as Column, builder, organization)); } } - private addColumnToOrganization(column: Column, organizationBuilder: CommonCartridgeOrganizationBuilder): void { + private addColumnToOrganization( + column: Column, + builder: CommonCartridgeExportFactory, + organizationBuilder: CommonCartridgeOrganizationBuilder + ): void { const { id } = column; - const columnOrganization = organizationBuilder.addSubOrganization({ - title: column.title, - identifier: createIdentifier(id), - }); + const columnOrganization = builder.addOrganization( + { + title: column.title, + identifier: createIdentifier(id), + }, + organizationBuilder + ); column.children .filter((child) => child instanceof Card) - .forEach((card) => this.addCardToOrganization(card as Card, columnOrganization)); + .forEach((card) => this.addCardToOrganization(card as Card, builder, columnOrganization)); } - private addCardToOrganization(card: Card, organizationBuilder: CommonCartridgeOrganizationBuilder): void { + private addCardToOrganization( + card: Card, + builder: CommonCartridgeExportFactory, + organizationBuilder: CommonCartridgeOrganizationBuilder + ): void { const { id } = card; - organizationBuilder.addSubOrganization({ - title: card.title, - identifier: createIdentifier(id), - }); + builder.addOrganization( + { + title: card.title, + identifier: createIdentifier(id), + }, + organizationBuilder + ); } - private addComponentToOrganization( - organizationBuilder: CommonCartridgeOrganizationBuilder, - component: ComponentProperties - ): void { - const resources = this.commonCartridgeMapper.mapContentToResources(component); - - if (Array.isArray(resources)) { - const subOrganizationBuilder = organizationBuilder.addSubOrganization( - this.commonCartridgeMapper.mapContentToOrganization(component) - ); - - resources.forEach((resource) => { - subOrganizationBuilder.addResource(resource); - }); - } else { - organizationBuilder.addResource(resources); - } - } + // private addComponentToOrganization( + // organizationBuilder: CommonCartridgeOrganizationBuilder, + // component: ComponentProperties + // ): void { + // const resources = this.commonCartridgeMapper.mapContentToResources(component); + + // if (Array.isArray(resources)) { + // const subOrganizationBuilder = organizationBuilder.addSubOrganization( + // this.commonCartridgeMapper.mapContentToOrganization(component) + // ); + + // resources.forEach((resource) => { + // subOrganizationBuilder.addResource(resource); + // }); + // } else { + // organizationBuilder.addResource(resources); + // } + // } } From 2315fc10ba71db99f47b64987514a384354e2add Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:04:38 +0200 Subject: [PATCH 07/46] EW-793 restructuring export mechanism Co-authored-by: Simone Radtke --- .../common-cartridge-export.factory.ts | 111 ++-------- .../common-cartridge-organization-node.ts | 71 ++++++ .../common-cartridge-resource-node.ts | 23 ++ .../common-cartridge-resources-builder.ts | 29 +-- .../export/interfaces/index.ts | 2 + .../common-cartridge-export.service.ts | 203 ++++++++---------- 6 files changed, 214 insertions(+), 225 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.ts create mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts index a81c1f9e2ac..2473ba16d86 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts @@ -8,91 +8,29 @@ import { CommonCartridgeElementFactory, CommonCartridgeElementProps, } from '../elements/common-cartridge-element-factory'; -import { CommonCartridgeOrganizationElementPropsV110 } from '../elements/v1.1.0'; -import { CommonCartridgeOrganizationElementPropsV130 } from '../elements/v1.3.0'; -import { CommonCartridgeElement, CommonCartridgeResource } from '../interfaces'; +import { CommonCartridgeElement } from '../interfaces'; +import { CommonCartridgeResourceFactory } from '../resources/common-cartridge-resource-factory'; import { - CommonCartridgeResourceFactory, - CommonCartridgeResourceProps, -} from '../resources/common-cartridge-resource-factory'; + CommonCartridgeOrganizationNode, + CommonCartridgeOrganizationNodeProps, +} from './common-cartridge-organization-node'; import { CommonCartridgeResourcesBuilder } from './common-cartridge-resources-builder'; -class CommonCartridgeResourceNode { - private readonly parent: CommonCartridgeOrganizationNode; - - constructor( - private readonly props: CommonCartridgeResourceProps & { version: CommonCartridgeVersion }, - parent: CommonCartridgeOrganizationNode - ) { - this.parent = parent; - } - - public get folder(): string { - return this.parent ? `${this.parent.folder}/${this.props.identifier}` : this.props.identifier; - } - - public build(): CommonCartridgeResource { - const resource = CommonCartridgeResourceFactory.createResource({ ...this.props, folder: this.parent.folder }); - - return resource; - } -} - -type CommonCartridgeOrganizationNodeProps = Omit< - CommonCartridgeOrganizationElementPropsV110 | CommonCartridgeOrganizationElementPropsV130, - 'items' ->; - -export class CommonCartridgeOrganizationNode { - private readonly parent: CommonCartridgeOrganizationNode | null = null; - - private readonly children: (CommonCartridgeOrganizationNode | CommonCartridgeResourceNode)[] = []; - - constructor( - private readonly props: CommonCartridgeOrganizationNodeProps, - parent: CommonCartridgeOrganizationNode | null - ) { - this.parent = parent; - - if (parent) { - parent.addChild(this); - } - } - - public get folder(): string { - return this.parent ? `${this.parent.folder}/${this.props.identifier}` : this.props.identifier; - } - - public addChild(organization: CommonCartridgeOrganizationNode | CommonCartridgeResourceNode): void { - this.children.push(organization); - } - - public build(): CommonCartridgeElement { - const organization = CommonCartridgeElementFactory.createElement({ - ...this.props, - version: this.props.version, - items: this.children.map((child) => child.build()), - }); - - return organization; - } -} - -type CommonCartridgeExportFactoryProps = { +export type CommonCartridgeExportFactoryProps = { version: CommonCartridgeVersion; identifier: string; }; +export type CommonCartridgeOrganizationProps = Omit; + export class CommonCartridgeExportFactory { - private readonly resourcesBuilder: CommonCartridgeResourcesBuilder; + private readonly resourcesBuilder: CommonCartridgeResourcesBuilder = new CommonCartridgeResourcesBuilder(); private readonly organizationsRoot: CommonCartridgeOrganizationNode[] = []; private metadataElement: CommonCartridgeElement | null = null; - constructor(private readonly props: CommonCartridgeExportFactoryProps) { - this.resourcesBuilder = new CommonCartridgeResourcesBuilder({ version: props.version }); - } + constructor(private readonly props: CommonCartridgeExportFactoryProps) {} public addMetadata(props: CommonCartridgeElementProps): void { this.metadataElement = CommonCartridgeElementFactory.createElement({ @@ -101,28 +39,18 @@ export class CommonCartridgeExportFactory { }); } - public addOrganization( - props: Omit, - parent: CommonCartridgeOrganizationNode | null - ): CommonCartridgeOrganizationNode { + public createOrganization(organizationProps: CommonCartridgeOrganizationProps): CommonCartridgeOrganizationNode { const organization = new CommonCartridgeOrganizationNode( - { ...props, version: this.props.version, type: CommonCartridgeElementType.ORGANIZATION }, - parent + { ...organizationProps, version: this.props.version, type: CommonCartridgeElementType.ORGANIZATION }, + this.resourcesBuilder, + null ); - if (!parent) { - this.organizationsRoot.push(organization); - } + this.organizationsRoot.push(organization); return organization; } - public addResource(resource: CommonCartridgeResourceProps, parent: CommonCartridgeOrganizationNode): void { - parent.addChild(new CommonCartridgeResourceNode({ ...resource, version: this.props.version }, parent)); - - this.resourcesBuilder.addResource(resource); - } - public build(): Buffer { if (!this.metadataElement) { throw new Error('Metadata is required'); @@ -142,10 +70,11 @@ export class CommonCartridgeExportFactory { archive.addFile('imsmanifest.xml', Buffer.from(manifest.getFileContent())); - this.resourcesBuilder - .build() - .filter((resource) => !resource.canInline) - .forEach((resource) => archive.addFile(resource.getFilePath(), Buffer.from(resource.getFileContent()))); + resources + .filter((resource) => !resource.canInline()) + .forEach((resource) => { + archive.addFile(resource.getFilePath(), Buffer.from(resource.getFileContent())); + }); return archive.toBuffer(); } diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.ts new file mode 100644 index 00000000000..8f98a1b649a --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.ts @@ -0,0 +1,71 @@ +import { CommonCartridgeElementType } from '../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from '../elements/common-cartridge-element-factory'; +import { CommonCartridgeOrganizationElementPropsV110 } from '../elements/v1.1.0'; +import { CommonCartridgeOrganizationElementPropsV130 } from '../elements/v1.3.0'; +import { CommonCartridgeElement } from '../interfaces'; +import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; +import type { CommonCartridgeOrganizationProps } from './common-cartridge-export.factory'; +import { CommonCartridgeResourceNode } from './common-cartridge-resource-node'; +import { CommonCartridgeResourcesBuilder } from './common-cartridge-resources-builder'; + +export type CommonCartridgeOrganizationNodeProps = Omit< + CommonCartridgeOrganizationElementPropsV110 | CommonCartridgeOrganizationElementPropsV130, + 'items' +>; + +export class CommonCartridgeOrganizationNode { + private readonly parent: CommonCartridgeOrganizationNode | null = null; + + private readonly children: (CommonCartridgeOrganizationNode | CommonCartridgeResourceNode)[] = []; + + constructor( + private readonly props: CommonCartridgeOrganizationNodeProps, + private readonly resourcesBuilder: CommonCartridgeResourcesBuilder, + parent: CommonCartridgeOrganizationNode | null + ) { + this.parent = parent; + } + + public get folder(): string { + return this.parent ? `${this.parent.folder}/${this.props.identifier}` : this.props.identifier; + } + + public createChild(childProps: CommonCartridgeOrganizationProps): CommonCartridgeOrganizationNode { + const organization = new CommonCartridgeOrganizationNode( + { + ...childProps, + version: this.props.version, + type: CommonCartridgeElementType.ORGANIZATION, + }, + this.resourcesBuilder, + this + ); + + this.children.push(organization); + + return organization; + } + + public addResource(resourceProps: CommonCartridgeResourceProps): void { + const resource = new CommonCartridgeResourceNode( + { + ...resourceProps, + version: this.props.version, + }, + this + ); + + this.children.push(resource); + this.resourcesBuilder.addResource(resource); + } + + public build(): CommonCartridgeElement { + const organization = CommonCartridgeElementFactory.createElement({ + ...this.props, + version: this.props.version, + items: this.children.map((child) => child.build()), + }); + + return organization; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.ts new file mode 100644 index 00000000000..912c969a59a --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.ts @@ -0,0 +1,23 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResource } from '../interfaces'; +import { + CommonCartridgeResourceFactory, + CommonCartridgeResourceProps, +} from '../resources/common-cartridge-resource-factory'; +import type { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node'; + +export type CommonCartridgeResourceNodeProps = CommonCartridgeResourceProps & { version: CommonCartridgeVersion }; + +export class CommonCartridgeResourceNode { + private readonly parent: CommonCartridgeOrganizationNode; + + constructor(private readonly props: CommonCartridgeResourceNodeProps, parent: CommonCartridgeOrganizationNode) { + this.parent = parent; + } + + public build(): CommonCartridgeResource { + const resource = CommonCartridgeResourceFactory.createResource({ ...this.props, folder: this.parent.folder }); + + return resource; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts index 9cd33b43d98..6c765c8cfa7 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts @@ -1,31 +1,16 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeResource } from '../interfaces'; -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourceProps, - CommonCartridgeResourcePropsInternal, -} from '../resources/common-cartridge-resource-factory'; - -type CommonCartridgeResourcesBuilderProps = { - version: CommonCartridgeVersion; -}; +import { CommonCartridgeResourceNode } from './common-cartridge-resource-node'; export class CommonCartridgeResourcesBuilder { - private readonly resources: CommonCartridgeResourceProps[] = []; - - constructor(private readonly props: CommonCartridgeResourcesBuilderProps) {} + private readonly resourceNodes: CommonCartridgeResourceNode[] = []; - addResource(resource: CommonCartridgeResourceProps): void { - this.resources.push(resource); + addResource(resourceNode: CommonCartridgeResourceNode): void { + this.resourceNodes.push(resourceNode); } build(): CommonCartridgeResource[] { - return this.resources.map((resource) => - CommonCartridgeResourceFactory.createResource({ - // TODO: Fix this cast - version: this.props.version, - ...resource, - } as CommonCartridgeResourcePropsInternal) - ); + const resources = this.resourceNodes.map((resource) => resource.build()); + + return resources; } } diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts index aaefb39018c..1eef5293ea0 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts @@ -1,2 +1,4 @@ export { CommonCartridgeElement } from './common-cartridge-element.interface'; export { CommonCartridgeResource } from './common-cartridge-resource.interface'; + +export type XmlStructure = Record; diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 2c7320df2b9..9beb51e8223 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -3,12 +3,11 @@ import { LessonService } from '@modules/lesson'; import { TaskService } from '@modules/task'; import { Injectable } from '@nestjs/common'; import { BoardExternalReferenceType, Card, Column } from '@shared/domain/domainobject'; +import { ComponentProperties } from '@shared/domain/entity'; import { EntityId } from '@shared/domain/types'; import { ColumnBoardService } from '@src/modules/board'; -import { - CommonCartridgeExportFactory, - CommonCartridgeOrganizationNode as CommonCartridgeOrganizationBuilder, -} from '@src/modules/common-cartridge/export/builders/common-cartridge-export.factory'; +import { CommonCartridgeExportFactory } from '@src/modules/common-cartridge/export/builders/common-cartridge-export.factory'; +import { CommonCartridgeOrganizationNode as CommonCartridgeOrganizationBuilder } from '@src/modules/common-cartridge/export/builders/common-cartridge-organization-node'; import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; import { CourseService } from './course.service'; @@ -27,9 +26,7 @@ export class CommonCartridgeExportService { courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion, - // eslint-disable-next-line @typescript-eslint/no-unused-vars exportedTopics: string[], - // eslint-disable-next-line @typescript-eslint/no-unused-vars exportedTasks: string[] ): Promise { const course = await this.courseService.findById(courseId); @@ -37,72 +34,67 @@ export class CommonCartridgeExportService { builder.addMetadata(this.commonCartridgeMapper.mapCourseToMetadata(course)); - // await this.addLessons(builder, courseId, version, exportedTopics); - // await this.addTasks(builder, courseId, userId, version, exportedTasks); + await this.addLessons(builder, courseId, version, exportedTopics); + await this.addTasks(builder, courseId, userId, version, exportedTasks); await this.addColumnBoards(builder, courseId); return builder.build(); } - // private async addLessons( - // builder: CommonCartridgeExportFactory, - // courseId: EntityId, - // version: CommonCartridgeVersion, - // topics: string[] - // ): Promise { - // const [lessons] = await this.lessonService.findByCourseIds([courseId]); - - // lessons.forEach((lesson) => { - // if (!topics.includes(lesson.id)) { - // return; - // } - - // const organizationBuilder = builder.addOrganization( - // { - // type: CommonCartridgeElementType.ORGANIZATION, - // identifier: createIdentifier(lesson.id), - // title: lesson.name, - // items: [], - // }, - // null - // ); - - // lesson.contents.forEach((content) => { - // this.addComponentToOrganization(organizationBuilder, content); - // }); - - // lesson.getLessonLinkedTasks().forEach((task) => { - // organizationBuilder.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); - // }); - // }); - // } - - // private async addTasks( - // builder: CommonCartridgeExportFactory, - // courseId: EntityId, - // userId: EntityId, - // version: CommonCartridgeVersion, - // exportedTasks: string[] - // ): Promise { - // const [tasks] = await this.taskService.findBySingleParent(userId, courseId); - - // if (tasks.length === 0) { - // return; - // } - - // const organization = builder.addOrganization({ - // title: '', - // identifier: createIdentifier(), - // }); - - // tasks.forEach((task) => { - // if (!exportedTasks.includes(task.id)) { - // return; - // } - - // organization.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); - // }); - // } + private async addLessons( + builder: CommonCartridgeExportFactory, + courseId: EntityId, + version: CommonCartridgeVersion, + topics: string[] + ): Promise { + const [lessons] = await this.lessonService.findByCourseIds([courseId]); + + lessons.forEach((lesson) => { + if (!topics.includes(lesson.id)) { + return; + } + + const lessonOrganization = builder.createOrganization({ + identifier: createIdentifier(lesson.id), + title: lesson.name, + }); + + lesson.contents.forEach((content) => { + this.addComponentToOrganization(lessonOrganization, content); + }); + + lesson.getLessonLinkedTasks().forEach((task) => { + lessonOrganization.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); + }); + }); + } + + private async addTasks( + builder: CommonCartridgeExportFactory, + courseId: EntityId, + userId: EntityId, + version: CommonCartridgeVersion, + exportedTasks: string[] + ): Promise { + const [tasks] = await this.taskService.findBySingleParent(userId, courseId); + + if (tasks.length === 0) { + return; + } + + const tasksOrganization = builder.createOrganization({ + title: 'Aufgaben', + identifier: createIdentifier(), + }); + + tasks.forEach((task) => { + if (!exportedTasks.includes(task.id)) { + return; + } + + tasksOrganization.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); + }); + } private async addColumnBoards(builder: CommonCartridgeExportFactory, courseId: EntityId): Promise { const columnBoardIds = await this.columnBoardService.findIdsByExternalReference({ @@ -113,13 +105,10 @@ export class CommonCartridgeExportService { for await (const columnBoardId of columnBoardIds) { const columnBoard = await this.columnBoardService.findById(columnBoardId); - const organization = builder.addOrganization( - { - title: columnBoard.title, - identifier: createIdentifier(columnBoard.id), - }, - null - ); + const organization = builder.createOrganization({ + title: columnBoard.title, + identifier: createIdentifier(columnBoard.id), + }); columnBoard.children .filter((child) => child instanceof Column) @@ -133,50 +122,40 @@ export class CommonCartridgeExportService { organizationBuilder: CommonCartridgeOrganizationBuilder ): void { const { id } = column; - const columnOrganization = builder.addOrganization( - { - title: column.title, - identifier: createIdentifier(id), - }, - organizationBuilder - ); + const columnOrganization = organizationBuilder.createChild({ + title: column.title, + identifier: createIdentifier(id), + }); column.children .filter((child) => child instanceof Card) - .forEach((card) => this.addCardToOrganization(card as Card, builder, columnOrganization)); + .forEach((card) => this.addCardToOrganization(card as Card, columnOrganization)); } - private addCardToOrganization( - card: Card, - builder: CommonCartridgeExportFactory, - organizationBuilder: CommonCartridgeOrganizationBuilder - ): void { + private addCardToOrganization(card: Card, cardOrganization: CommonCartridgeOrganizationBuilder): void { const { id } = card; - builder.addOrganization( - { - title: card.title, - identifier: createIdentifier(id), - }, - organizationBuilder - ); + cardOrganization.createChild({ + title: card.title, + identifier: createIdentifier(id), + }); } - // private addComponentToOrganization( - // organizationBuilder: CommonCartridgeOrganizationBuilder, - // component: ComponentProperties - // ): void { - // const resources = this.commonCartridgeMapper.mapContentToResources(component); - - // if (Array.isArray(resources)) { - // const subOrganizationBuilder = organizationBuilder.addSubOrganization( - // this.commonCartridgeMapper.mapContentToOrganization(component) - // ); - - // resources.forEach((resource) => { - // subOrganizationBuilder.addResource(resource); - // }); - // } else { - // organizationBuilder.addResource(resources); - // } - // } + private addComponentToOrganization( + lessonOrganization: CommonCartridgeOrganizationBuilder, + component: ComponentProperties + ): void { + const resources = this.commonCartridgeMapper.mapContentToResources(component); + + if (Array.isArray(resources)) { + const componentOrganization = lessonOrganization.createChild( + this.commonCartridgeMapper.mapContentToOrganization(component) + ); + + resources.forEach((resource) => { + componentOrganization.addResource(resource); + }); + } else { + lessonOrganization.addResource(resources); + } + } } From cb75216e0a7d93d2126c5061cad5fc1011c4cbaf Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Thu, 18 Apr 2024 15:35:39 +0200 Subject: [PATCH 08/46] EW-793 removing unused code Co-authored-by: Simone Radtke --- .../common-cartridge-file-builder.spec.ts | 110 -------- .../builders/common-cartridge-file-builder.ts | 259 ------------------ ...mon-cartridge-organization-builder.spec.ts | 87 ------ .../common-cartridge-organization-builder.ts | 82 ------ .../common-cartridge-export.service.ts | 20 +- 5 files changed, 8 insertions(+), 550 deletions(-) delete mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts delete mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts delete mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts delete mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts deleted file mode 100644 index 5c5db130cf5..00000000000 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts +++ /dev/null @@ -1,110 +0,0 @@ -import { faker } from '@faker-js/faker'; -import AdmZip from 'adm-zip'; -import { - CommonCartridgeElementType, - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../common-cartridge.enums'; -import { CommonCartridgeElementProps } from '../elements/common-cartridge-element-factory'; -import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; -import { CommonCartridgeFileBuilder } from './common-cartridge-file-builder'; -import { CommonCartridgeOrganizationBuilderOptions } from './common-cartridge-organization-builder'; - -describe('CommonCartridgeFileBuilder', () => { - const getFileContentAsString = (zip: AdmZip, path: string): string | undefined => - zip.getEntry(path)?.getData().toString(); - - describe('build', () => { - describe('when a common cartridge archive has been created', () => { - const setup = async () => { - const metadataProps: CommonCartridgeElementProps = { - type: CommonCartridgeElementType.METADATA, - title: faker.lorem.words(), - creationDate: new Date(), - copyrightOwners: ['John Doe', 'Jane Doe'], - }; - const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { - identifier: faker.string.uuid(), - title: faker.lorem.words(), - }; - const resourceProps: CommonCartridgeResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - html: faker.lorem.paragraphs(), - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, - }; - const builder = new CommonCartridgeFileBuilder({ - version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - }); - - builder - .addMetadata(metadataProps) - .addOrganization(organizationOptions) - .addResource(resourceProps) - .addSubOrganization(organizationOptions) - .addResource(resourceProps) - .addSubOrganization(organizationOptions) - .addResource(resourceProps); - - const archive = new AdmZip(await builder.build()); - - return { archive, metadataProps, organizationOptions, resourceProps }; - }; - - it('should have a imsmanifest.xml in archive root', async () => { - const { archive } = await setup(); - - const manifest = getFileContentAsString(archive, 'imsmanifest.xml'); - - expect(manifest).toBeDefined(); - }); - - it('should have included the resource in organization folder', async () => { - const { archive, organizationOptions, resourceProps } = await setup(); - - const resource = getFileContentAsString( - archive, - `${organizationOptions.identifier}/${resourceProps.identifier}.html` - ); - - expect(resource).toBeDefined(); - }); - - it('should have included the resource in sub-organization folder', async () => { - const { archive, organizationOptions, resourceProps } = await setup(); - - const resource = getFileContentAsString( - archive, - `${organizationOptions.identifier}/${organizationOptions.identifier}/${resourceProps.identifier}.html` - ); - - expect(resource).toBeDefined(); - }); - - it('should have included the resource in sub-sub-organization folder', async () => { - const { archive, organizationOptions, resourceProps } = await setup(); - - const resource = getFileContentAsString( - archive, - `${organizationOptions.identifier}/${organizationOptions.identifier}/${organizationOptions.identifier}/${resourceProps.identifier}.html` - ); - - expect(resource).toBeDefined(); - }); - }); - - describe('when metadata has not been provide', () => { - const sut = new CommonCartridgeFileBuilder({ - version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - }); - - it('should throw an error', async () => { - await expect(sut.build()).rejects.toThrow('Metadata is not defined'); - }); - }); - }); -}); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts deleted file mode 100644 index 913cafde643..00000000000 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts +++ /dev/null @@ -1,259 +0,0 @@ -// import AdmZip from 'adm-zip'; -// import { -// CommonCartridgeElementType, -// CommonCartridgeResourceType, -// CommonCartridgeVersion, -// } from '../common-cartridge.enums'; -// import { -// CommonCartridgeElementFactory, -// CommonCartridgeElementProps, -// } from '../elements/common-cartridge-element-factory'; -// import { CommonCartridgeElement, CommonCartridgeResource } from '../interfaces'; -// import { -// CommonCartridgeResourceFactory, -// CommonCartridgeResourcePropsInternal, -// } from '../resources/common-cartridge-resource-factory'; -// import { CommonCartridgeOrganizationBuilder } from './common-cartridge-organization-builder'; - -// export type CommonCartridgeFileBuilderProps = { -// version: CommonCartridgeVersion; -// identifier: string; -// }; - -// export class CommonCartridgeFileBuilder { -// private readonly archive: AdmZip = new AdmZip(); - -// private readonly organizationBuilders = new Array(); - -// private readonly resources = new Array(); - -// private metadata?: CommonCartridgeElement; - -// constructor(private readonly props: CommonCartridgeFileBuilderProps) {} - -// public addMetadata(props: CommonCartridgeElementProps): CommonCartridgeFileBuilder { -// this.metadata = CommonCartridgeElementFactory.createElement({ -// version: this.props.version, -// ...props, -// }); - -// return this; -// } - -// public addOrganization(organizationBuilder: CommonCartridgeOrganizationBuilder): void { -// const builder = new CommonCartridgeOrganizationBuilder( -// { ...props, version: this.props.version }, -// (resource: CommonCartridgeResource) => this.resources.push(resource) -// ); - -// this.organizationBuilders.push(organizationBuilder); -// } - -// /* public addOrganization( -// props: OmitVersion -// ): CommonCartridgeOrganizationBuilder { -// const builder = new CommonCartridgeOrganizationBuilder( -// { ...props, version: this.props.version }, -// (resource: CommonCartridgeResource) => this.resources.push(resource) -// ); - -// this.organizationBuilders.push(builder); - -// return builder; -// } -// */ - -// public async build(): Promise { -// if (!this.metadata) { -// throw new Error('Metadata is not defined'); -// } - -// const organizations = this.organizationBuilders.map((builder) => builder.build()); -// const manifest = CommonCartridgeResourceFactory.createResource({ -// type: CommonCartridgeResourceType.MANIFEST, -// version: this.props.version, -// identifier: this.props.identifier, -// metadata: this.metadata, -// organizations, -// resources: this.resources, -// }); - -// for (const resources of this.resources) { -// if (!resources.canInline()) { -// this.archive.addFile(resources.getFilePath(), Buffer.from(resources.getFileContent())); -// } -// } - -// this.archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); - -// const buffer = await this.archive.toBufferPromise(); - -// return buffer; -// } -// } - -// type CCFileBuilderOptions = { -// version: CommonCartridgeVersion; -// identifier: string; -// }; - -// interface CCMetadataBuilder { -// setTitle(title: string): CCMetadataBuilder; - -// setCreationDate(date: Date): CCMetadataBuilder; - -// setCopyrightOwners(copyrightOwners: string[]): CCMetadataBuilder; // addCopyrightOwner Methode hinzufügen -// } - -// class CCMetadataBuilderImpl implements CCMetadataBuilder { -// private title = ''; - -// private creationDate: Date = new Date(); - -// private copyrightOwners: string[] = []; - -// constructor(private readonly props: CCFileBuilderOptions) {} - -// public setTitle(title: string): CCMetadataBuilder { -// this.title = title; - -// return this; -// } - -// public setCreationDate(date: Date): CCMetadataBuilder { -// this.creationDate = date; - -// return this; -// } - -// public setCopyrightOwners(copyrightOwners: string[]): CCMetadataBuilder { -// this.copyrightOwners = copyrightOwners; - -// return this; -// } - -// public build(): CommonCartridgeElement { -// const metadataElement = CommonCartridgeElementFactory.createElement({ -// type: CommonCartridgeElementType.METADATA, -// version: this.props.version, -// title: this.title, -// creationDate: this.creationDate, -// copyrightOwners: this.copyrightOwners, -// }); - -// return metadataElement; -// } -// } - -// type CCOrganizationBuilderOptions = { -// version: CommonCartridgeVersion; -// identifier: string; -// title: string; -// } & CCFileBuilderOptions; - -// class CCOrganizationBuilderImpl { -// private identifier = ''; - -// private title = ''; - -// private items = new Array(); - -// constructor( -// private readonly resourceBuilder: CCResourceBuilder, -// private readonly props: CCOrganizationBuilderOptions -// ) {} - -// public addOrganization(props: CCOrganizationBuilderOptions): CCOrganizationBuilderImpl { -// const subOrganizationBuilder = new CCOrganizationBuilderImpl(this.resourceBuilder, props); - -// this.items.push(subOrganizationBuilder); - -// return this; -// } - -// public build(): CommonCartridgeElement { -// throw new Error('Method not implemented.'); -// } -// } - -// class CCResourceBuilder { -// private readonly resources = new Array(); - -// constructor(private readonly props: CCFileBuilderOptions) {} - -// public addResource(resource: CommonCartridgeResourcePropsInternal): CCResourceBuilder { -// this.resources.push(resource); - -// return this; -// } - -// public build(): CommonCartridgeResource[] { -// const result = this.resources.map((resource) => -// CommonCartridgeResourceFactory.createResource({ -// ...resource, -// version: this.props.version, -// }) -// ); - -// return result; -// } -// } - -// export class CCFileBuilder { -// private readonly metadataBuilder: CCMetadataBuilderImpl; - -// private readonly organizationBuilder: CCOrganizationBuilderImpl; - -// private readonly resourceBuilder: CCResourceBuilder; - -// constructor(private readonly props: CCFileBuilderOptions) { -// this.resourceBuilder = new CCResourceBuilder(props); -// this.metadataBuilder = new CCMetadataBuilderImpl(props); -// this.organizationBuilder = new CCOrganizationBuilderImpl(this.resourceBuilder, props); -// } - -// public get metadata(): CCMetadataBuilder { -// return this.metadataBuilder; -// } - -// public get organizations(): CCOrganizationBuilder { -// return this.organizationBuilder; -// } - -// public build(): Buffer { -// const archive = new AdmZip(); -// const organization = this.organizationBuilder.build(); -// const resources = this.resourceBuilder.build(); -// const manifest = CommonCartridgeResourceFactory.createResource({ -// type: CommonCartridgeResourceType.MANIFEST, -// version: this.props.version, -// identifier: this.props.identifier, -// metadata: this.metadataBuilder.build(), -// organization, -// resources, -// }); - -// archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); - -// for (const resource of resources.filter((res) => !res.canInline())) { -// archive.addFile(resource.getFilePath(), Buffer.from(resource.getFileContent())); -// } - -// return archive.toBuffer(); -// } -// } - -// const fileBuilder = new CCFileBuilder({ -// version: CommonCartridgeVersion.V_1_1_0, -// identifier: 'test', -// }); - -// fileBuilder.metadata.setTitle('Test').setCreationDate(new Date()).setCopyrightOwners(['Simone', 'Patrick']); - -// const orga1 = fileBuilder.organizations.setIdentifier('org1').setTitle('Organization 1').addOrganization(); - -// const sub1 = orga1.addOrganization().setIdentifier('sub1').setTitle('Suborganization 1'); -// const sub2 = orga1.addOrganization().setIdentifier('sub2').setTitle('Suborganization 2'); -// const subSub1 = sub1.addOrganization().setIdentifier('subsub1').setTitle('Subsuborganization 1'); - -// console.log(fileBuilder.build()); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts deleted file mode 100644 index ba9a36001ae..00000000000 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.spec.ts +++ /dev/null @@ -1,87 +0,0 @@ -import { faker } from '@faker-js/faker/locale/af_ZA'; -import { createCommonCartridgeWebContentResourcePropsV110 } from '../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElement, CommonCartridgeResource } from '../interfaces'; -import { - CommonCartridgeOrganizationBuilder, - CommonCartridgeOrganizationBuilderOptions, -} from './common-cartridge-organization-builder'; - -describe('CommonCartridgeOrganizationBuilder', () => { - describe('build', () => { - describe('when building a Common Cartridge organization with resources', () => { - const setup = () => { - const resources = new Array(); - - const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { - identifier: faker.string.uuid(), - title: faker.lorem.words(), - }; - - const resourceProps = createCommonCartridgeWebContentResourcePropsV110(); - - const sut = new CommonCartridgeOrganizationBuilder( - { - ...organizationOptions, - version: CommonCartridgeVersion.V_1_1_0, - }, - (resource) => resources.push(resource) - ) - .addResource(resourceProps) - .addSubOrganization(organizationOptions) - .addResource(resourceProps) - .addSubOrganization(organizationOptions) - .addResource(resourceProps); - - return { sut, resources }; - }; - - it('should return a common cartridge element', () => { - const { sut, resources } = setup(); - - const element = sut.build(); - - expect(element).toBeInstanceOf(CommonCartridgeElement); - expect(resources.length).toBe(3); - }); - }); - - describe('when building a Common Cartridge organization with items', () => { - const setup = () => { - const resources = new Array(); - - const organizationOptions: CommonCartridgeOrganizationBuilderOptions = { - identifier: faker.string.uuid(), - title: faker.lorem.words(), - }; - - const resourceProps = createCommonCartridgeWebContentResourcePropsV110(); - - const sut = new CommonCartridgeOrganizationBuilder( - { - ...organizationOptions, - version: CommonCartridgeVersion.V_1_1_0, - }, - (resource) => resources.push(resource) - ) - .addResource(resourceProps) - .addSubOrganization(organizationOptions) - .addResource(resourceProps) - .addSubOrganization(organizationOptions) - .addResource(resourceProps) - .addResource(resourceProps); - - return { sut, resources }; - }; - - it('should return a common cartridge element', () => { - const { sut, resources } = setup(); - - const element = sut.build(); - - expect(element).toBeInstanceOf(CommonCartridgeElement); - expect(resources.length).toBe(4); - }); - }); - }); -}); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts deleted file mode 100644 index 20ff6d3e528..00000000000 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-builder.ts +++ /dev/null @@ -1,82 +0,0 @@ -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; -import { CommonCartridgeElementFactory } from '../elements/common-cartridge-element-factory'; -import { CommonCartridgeElement } from '../interfaces/common-cartridge-element.interface'; -import { CommonCartridgeResource } from '../interfaces/common-cartridge-resource.interface'; -import { - CommonCartridgeResourceFactory, - CommonCartridgeResourceProps, -} from '../resources/common-cartridge-resource-factory'; -import { OmitVersionAndFolder } from '../utils'; - -export type CommonCartridgeOrganizationBuilderOptions = - OmitVersionAndFolder; - -type CommonCartridgeOrganizationBuilderOptionsInternal = { - version: CommonCartridgeVersion; - identifier: string; - title: string; - folder?: string; -}; - -export class CommonCartridgeOrganizationBuilder { - private readonly resources: CommonCartridgeResource[] = []; - - private readonly subOrganizations: CommonCartridgeOrganizationBuilder[] = []; - - constructor( - protected readonly options: CommonCartridgeOrganizationBuilderOptionsInternal, - private readonly addResourceToFileBuilder: (resource: CommonCartridgeResource) => void - ) {} - - private get folder(): string { - return this.options.folder ? `${this.options.folder}/${this.options.identifier}` : this.options.identifier; - } - - public addSubOrganization( - options: OmitVersionAndFolder - ): CommonCartridgeOrganizationBuilder { - const subOrganization = new CommonCartridgeOrganizationBuilder( - { ...options, version: this.options.version, folder: this.folder }, - (resource: CommonCartridgeResource) => this.addResourceToFileBuilder(resource) - ); - - this.subOrganizations.push(subOrganization); - - return subOrganization; - } - - public addResource(props: CommonCartridgeResourceProps): CommonCartridgeOrganizationBuilder { - const resource = CommonCartridgeResourceFactory.createResource({ - version: this.options.version, - folder: this.folder, - ...props, - }); - - this.resources.push(resource); - this.addResourceToFileBuilder(resource); - - return this; - } - - public build(): CommonCartridgeElement { - const organizationElement = CommonCartridgeElementFactory.createElement({ - type: CommonCartridgeElementType.ORGANIZATION, - version: this.options.version, - identifier: this.options.identifier, - title: this.options.title, - items: this.buildItems(), - }); - - return organizationElement; - } - - private buildItems(): (CommonCartridgeElement | CommonCartridgeResource)[] { - if (this.resources.length === 1 && this.subOrganizations.length === 0) { - return [...this.resources]; - } - - const items = [...this.resources, ...this.subOrganizations.map((subOrganization) => subOrganization.build())]; - - return items; - } -} diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 9beb51e8223..14d89eadd62 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -7,7 +7,7 @@ import { ComponentProperties } from '@shared/domain/entity'; import { EntityId } from '@shared/domain/types'; import { ColumnBoardService } from '@src/modules/board'; import { CommonCartridgeExportFactory } from '@src/modules/common-cartridge/export/builders/common-cartridge-export.factory'; -import { CommonCartridgeOrganizationNode as CommonCartridgeOrganizationBuilder } from '@src/modules/common-cartridge/export/builders/common-cartridge-organization-node'; +import { CommonCartridgeOrganizationNode } from '@src/modules/common-cartridge/export/builders/common-cartridge-organization-node'; import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; import { CourseService } from './course.service'; @@ -105,24 +105,20 @@ export class CommonCartridgeExportService { for await (const columnBoardId of columnBoardIds) { const columnBoard = await this.columnBoardService.findById(columnBoardId); - const organization = builder.createOrganization({ + const columnBoardOrganization = builder.createOrganization({ title: columnBoard.title, identifier: createIdentifier(columnBoard.id), }); columnBoard.children .filter((child) => child instanceof Column) - .forEach((column) => this.addColumnToOrganization(column as Column, builder, organization)); + .forEach((column) => this.addColumnToOrganization(column as Column, columnBoardOrganization)); } } - private addColumnToOrganization( - column: Column, - builder: CommonCartridgeExportFactory, - organizationBuilder: CommonCartridgeOrganizationBuilder - ): void { + private addColumnToOrganization(column: Column, columnBoardOrganization: CommonCartridgeOrganizationNode): void { const { id } = column; - const columnOrganization = organizationBuilder.createChild({ + const columnOrganization = columnBoardOrganization.createChild({ title: column.title, identifier: createIdentifier(id), }); @@ -132,16 +128,16 @@ export class CommonCartridgeExportService { .forEach((card) => this.addCardToOrganization(card as Card, columnOrganization)); } - private addCardToOrganization(card: Card, cardOrganization: CommonCartridgeOrganizationBuilder): void { + private addCardToOrganization(card: Card, columnOrganization: CommonCartridgeOrganizationNode): void { const { id } = card; - cardOrganization.createChild({ + columnOrganization.createChild({ title: card.title, identifier: createIdentifier(id), }); } private addComponentToOrganization( - lessonOrganization: CommonCartridgeOrganizationBuilder, + lessonOrganization: CommonCartridgeOrganizationNode, component: ComponentProperties ): void { const resources = this.commonCartridgeMapper.mapContentToResources(component); From 17655051f0325f95a42da0440ec89698e9899acd Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Thu, 18 Apr 2024 16:09:19 +0200 Subject: [PATCH 09/46] EW-793 removing compilation errors --- .../modules/common-cartridge/export/interfaces/index.ts | 2 -- apps/server/src/modules/common-cartridge/index.ts | 8 -------- .../modules/learnroom/mapper/common-cartridge.mapper.ts | 9 ++++----- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts index 1eef5293ea0..aaefb39018c 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts @@ -1,4 +1,2 @@ export { CommonCartridgeElement } from './common-cartridge-element.interface'; export { CommonCartridgeResource } from './common-cartridge-resource.interface'; - -export type XmlStructure = Record; diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts index 7748da22999..bbdd1fe6d0d 100644 --- a/apps/server/src/modules/common-cartridge/index.ts +++ b/apps/server/src/modules/common-cartridge/index.ts @@ -1,11 +1,3 @@ -// export { -// CommonCartridgeFileBuilder, -// CommonCartridgeFileBuilderProps, -// } from './export/builders/common-cartridge-file-builder'; -export { - CommonCartridgeOrganizationBuilder, - CommonCartridgeOrganizationBuilderOptions, -} from './export/builders/common-cartridge-organization-builder'; export { CommonCartridgeElementType, CommonCartridgeIntendedUseType, diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 6fee9bbcfa1..43954b1c3f0 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -1,9 +1,7 @@ import { CommonCartridgeElementProps, CommonCartridgeElementType, - // CommonCartridgeFileBuilderProps, CommonCartridgeIntendedUseType, - CommonCartridgeOrganizationBuilderOptions, CommonCartridgeResourceProps, CommonCartridgeResourceType, CommonCartridgeVersion, @@ -13,6 +11,7 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { LinkElement, RichTextElement } from '@shared/domain/domainobject'; import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; +import { CommonCartridgeOrganizationProps } from '@src/modules/common-cartridge/export/builders/common-cartridge-export.factory'; import { LearnroomConfig } from '../learnroom.config'; @Injectable() @@ -28,21 +27,21 @@ export class CommonCartridgeMapper { }; } - public mapLessonToOrganization(lesson: LessonEntity): CommonCartridgeOrganizationBuilderOptions { + public mapLessonToOrganization(lesson: LessonEntity): CommonCartridgeOrganizationProps { return { identifier: createIdentifier(lesson.id), title: lesson.name, }; } - public mapContentToOrganization(content: ComponentProperties): CommonCartridgeOrganizationBuilderOptions { + public mapContentToOrganization(content: ComponentProperties): CommonCartridgeOrganizationProps { return { identifier: createIdentifier(content._id), title: content.title, }; } - public mapTaskToOrganization(task: Task): CommonCartridgeOrganizationBuilderOptions { + public mapTaskToOrganization(task: Task): CommonCartridgeOrganizationProps { return { identifier: createIdentifier(), title: task.name, From 7c47e0dcdf92353d774d573c10745cb9e87fc5ff Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 19 Apr 2024 11:17:46 +0200 Subject: [PATCH 10/46] EW-793 Renaming functions, classes and variables Co-authored-by: Patrick Sachmann --- ...ry.ts => common-cartridge-file-builder.ts} | 17 ++++---- .../common-cartridge-organization-node.ts | 6 +-- ...-cartridge-resource-collection-builder.ts} | 2 +- .../src/modules/learnroom/learnroom.module.ts | 4 +- .../mapper/common-cartridge.mapper.spec.ts | 8 ++-- .../mapper/common-cartridge.mapper.ts | 4 +- .../common-cartridge-export.service.spec.ts | 4 +- .../common-cartridge-export.service.ts | 41 ++++++++----------- 8 files changed, 41 insertions(+), 45 deletions(-) rename apps/server/src/modules/common-cartridge/export/builders/{common-cartridge-export.factory.ts => common-cartridge-file-builder.ts} (79%) rename apps/server/src/modules/common-cartridge/export/builders/{common-cartridge-resources-builder.ts => common-cartridge-resource-collection-builder.ts} (89%) diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts similarity index 79% rename from apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts rename to apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts index 2473ba16d86..c428a328266 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-export.factory.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts @@ -14,28 +14,29 @@ import { CommonCartridgeOrganizationNode, CommonCartridgeOrganizationNodeProps, } from './common-cartridge-organization-node'; -import { CommonCartridgeResourcesBuilder } from './common-cartridge-resources-builder'; +import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder'; -export type CommonCartridgeExportFactoryProps = { +export type CommonCartridgeFileBuilderProps = { version: CommonCartridgeVersion; identifier: string; }; export type CommonCartridgeOrganizationProps = Omit; -export class CommonCartridgeExportFactory { - private readonly resourcesBuilder: CommonCartridgeResourcesBuilder = new CommonCartridgeResourcesBuilder(); +export class CommonCartridgeFileBuilder { + private readonly resourcesBuilder: CommonCartridgeResourceCollectionBuilder = + new CommonCartridgeResourceCollectionBuilder(); private readonly organizationsRoot: CommonCartridgeOrganizationNode[] = []; private metadataElement: CommonCartridgeElement | null = null; - constructor(private readonly props: CommonCartridgeExportFactoryProps) {} + constructor(private readonly props: CommonCartridgeFileBuilderProps) {} - public addMetadata(props: CommonCartridgeElementProps): void { + public addMetadata(metadataProps: CommonCartridgeElementProps): void { this.metadataElement = CommonCartridgeElementFactory.createElement({ version: this.props.version, - ...props, + ...metadataProps, }); } @@ -53,7 +54,7 @@ export class CommonCartridgeExportFactory { public build(): Buffer { if (!this.metadataElement) { - throw new Error('Metadata is required'); + throw new Error('Metadata is required'); // TODO add loggable } const archive = new AdmZip(); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.ts index 8f98a1b649a..9185d9db589 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.ts @@ -4,9 +4,9 @@ import { CommonCartridgeOrganizationElementPropsV110 } from '../elements/v1.1.0' import { CommonCartridgeOrganizationElementPropsV130 } from '../elements/v1.3.0'; import { CommonCartridgeElement } from '../interfaces'; import { CommonCartridgeResourceProps } from '../resources/common-cartridge-resource-factory'; -import type { CommonCartridgeOrganizationProps } from './common-cartridge-export.factory'; +import type { CommonCartridgeOrganizationProps } from './common-cartridge-file-builder'; +import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder'; import { CommonCartridgeResourceNode } from './common-cartridge-resource-node'; -import { CommonCartridgeResourcesBuilder } from './common-cartridge-resources-builder'; export type CommonCartridgeOrganizationNodeProps = Omit< CommonCartridgeOrganizationElementPropsV110 | CommonCartridgeOrganizationElementPropsV130, @@ -20,7 +20,7 @@ export class CommonCartridgeOrganizationNode { constructor( private readonly props: CommonCartridgeOrganizationNodeProps, - private readonly resourcesBuilder: CommonCartridgeResourcesBuilder, + private readonly resourcesBuilder: CommonCartridgeResourceCollectionBuilder, parent: CommonCartridgeOrganizationNode | null ) { this.parent = parent; diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts similarity index 89% rename from apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts rename to apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts index 6c765c8cfa7..089e720685f 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resources-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts @@ -1,7 +1,7 @@ import { CommonCartridgeResource } from '../interfaces'; import { CommonCartridgeResourceNode } from './common-cartridge-resource-node'; -export class CommonCartridgeResourcesBuilder { +export class CommonCartridgeResourceCollectionBuilder { private readonly resourceNodes: CommonCartridgeResourceNode[] = []; addResource(resourceNode: CommonCartridgeResourceNode): void { diff --git a/apps/server/src/modules/learnroom/learnroom.module.ts b/apps/server/src/modules/learnroom/learnroom.module.ts index b1f53af3da8..337fc910458 100644 --- a/apps/server/src/modules/learnroom/learnroom.module.ts +++ b/apps/server/src/modules/learnroom/learnroom.module.ts @@ -19,7 +19,7 @@ import { LoggerModule } from '@src/core/logger'; import { BoardNodeRepo } from '../board/repo'; import { COURSE_REPO } from './domain'; import { CommonCartridgeImportMapper } from './mapper/common-cartridge-import.mapper'; -import { CommonCartridgeMapper } from './mapper/common-cartridge.mapper'; +import { CommonCartridgeExportMapper } from './mapper/common-cartridge.mapper'; import { CourseMikroOrmRepo } from './repo/mikro-orm/course.repo'; import { BoardCopyService, @@ -56,7 +56,7 @@ import { CommonCartridgeFileValidatorPipe } from './utils'; CommonCartridgeExportService, CommonCartridgeFileValidatorPipe, CommonCartridgeImportService, - CommonCartridgeMapper, + CommonCartridgeExportMapper, CommonCartridgeImportMapper, CourseCopyService, CourseGroupRepo, diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts index 526ad859a29..e1ee2fbf28e 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts @@ -25,25 +25,25 @@ import { userFactory, } from '@shared/testing'; import { LearnroomConfig } from '../learnroom.config'; -import { CommonCartridgeMapper } from './common-cartridge.mapper'; +import { CommonCartridgeExportMapper } from './common-cartridge.mapper'; describe('CommonCartridgeMapper', () => { let module: TestingModule; - let sut: CommonCartridgeMapper; + let sut: CommonCartridgeExportMapper; let configServiceMock: DeepMocked>; beforeAll(async () => { await setupEntities(); module = await Test.createTestingModule({ providers: [ - CommonCartridgeMapper, + CommonCartridgeExportMapper, { provide: ConfigService, useValue: createMock>(), }, ], }).compile(); - sut = module.get(CommonCartridgeMapper); + sut = module.get(CommonCartridgeExportMapper); configServiceMock = module.get(ConfigService); }); diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts index 43954b1c3f0..a5e70990d1a 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts @@ -11,11 +11,11 @@ import { Injectable } from '@nestjs/common'; import { ConfigService } from '@nestjs/config'; import { LinkElement, RichTextElement } from '@shared/domain/domainobject'; import { ComponentProperties, ComponentType, Course, LessonEntity, Task } from '@shared/domain/entity'; -import { CommonCartridgeOrganizationProps } from '@src/modules/common-cartridge/export/builders/common-cartridge-export.factory'; +import { CommonCartridgeOrganizationProps } from '@src/modules/common-cartridge/export/builders/common-cartridge-file-builder'; import { LearnroomConfig } from '../learnroom.config'; @Injectable() -export class CommonCartridgeMapper { +export class CommonCartridgeExportMapper { constructor(private readonly configService: ConfigService) {} public mapCourseToMetadata(course: Course): CommonCartridgeElementProps { diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index d131e9c4774..5ac0e15874e 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -20,7 +20,7 @@ import { } from '@shared/testing'; import { ColumnBoardService } from '@src/modules/board'; import AdmZip from 'adm-zip'; -import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; +import { CommonCartridgeExportMapper } from '../mapper/common-cartridge.mapper'; describe('CommonCartridgeExportService', () => { let module: TestingModule; @@ -104,7 +104,7 @@ describe('CommonCartridgeExportService', () => { module = await Test.createTestingModule({ providers: [ CommonCartridgeExportService, - CommonCartridgeMapper, + CommonCartridgeExportMapper, { provide: CourseService, useValue: createMock(), diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 8eee41a6d98..92d83540a97 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -15,10 +15,10 @@ import { import { ComponentProperties } from '@shared/domain/entity'; import { EntityId } from '@shared/domain/types'; import { ColumnBoardService } from '@src/modules/board'; -import { CommonCartridgeExportFactory } from '@src/modules/common-cartridge/export/builders/common-cartridge-export.factory'; +import { CommonCartridgeFileBuilder } from '@src/modules/common-cartridge/export/builders/common-cartridge-file-builder'; import { CommonCartridgeOrganizationNode } from '@src/modules/common-cartridge/export/builders/common-cartridge-organization-node'; import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; -import { CommonCartridgeMapper } from '../mapper/common-cartridge.mapper'; +import { CommonCartridgeExportMapper } from '../mapper/common-cartridge.mapper'; import { CourseService } from './course.service'; @Injectable() @@ -28,7 +28,7 @@ export class CommonCartridgeExportService { private readonly lessonService: LessonService, private readonly taskService: TaskService, private readonly columnBoardService: ColumnBoardService, - private readonly commonCartridgeMapper: CommonCartridgeMapper + private readonly mapper: CommonCartridgeExportMapper ) {} public async exportCourse( @@ -39,9 +39,9 @@ export class CommonCartridgeExportService { exportedTasks: string[] ): Promise { const course = await this.courseService.findById(courseId); - const builder = new CommonCartridgeExportFactory(this.commonCartridgeMapper.mapCourseToManifest(version, course)); + const builder = new CommonCartridgeFileBuilder(this.mapper.mapCourseToManifest(version, course)); - builder.addMetadata(this.commonCartridgeMapper.mapCourseToMetadata(course)); + builder.addMetadata(this.mapper.mapCourseToMetadata(course)); await this.addLessons(builder, courseId, version, exportedTopics); await this.addTasks(builder, courseId, userId, version, exportedTasks); @@ -51,7 +51,7 @@ export class CommonCartridgeExportService { } private async addLessons( - builder: CommonCartridgeExportFactory, + builder: CommonCartridgeFileBuilder, courseId: EntityId, version: CommonCartridgeVersion, topics: string[] @@ -63,23 +63,20 @@ export class CommonCartridgeExportService { return; } - const lessonOrganization = builder.createOrganization({ - identifier: createIdentifier(lesson.id), - title: lesson.name, - }); + const lessonOrganization = builder.createOrganization(this.mapper.mapLessonToOrganization(lesson)); lesson.contents.forEach((content) => { - this.addComponentToOrganization(lessonOrganization, content); + this.addComponentToOrganization(content, lessonOrganization); }); lesson.getLessonLinkedTasks().forEach((task) => { - lessonOrganization.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); + lessonOrganization.addResource(this.mapper.mapTaskToResource(task, version)); }); }); } private async addTasks( - builder: CommonCartridgeExportFactory, + builder: CommonCartridgeFileBuilder, courseId: EntityId, userId: EntityId, version: CommonCartridgeVersion, @@ -101,11 +98,11 @@ export class CommonCartridgeExportService { return; } - tasksOrganization.addResource(this.commonCartridgeMapper.mapTaskToResource(task, version)); + tasksOrganization.addResource(this.mapper.mapTaskToResource(task, version)); }); } - private async addColumnBoards(builder: CommonCartridgeExportFactory, courseId: EntityId): Promise { + private async addColumnBoards(builder: CommonCartridgeFileBuilder, courseId: EntityId): Promise { const columnBoardIds = await this.columnBoardService.findIdsByExternalReference({ type: BoardExternalReferenceType.Course, id: courseId, @@ -148,28 +145,26 @@ export class CommonCartridgeExportService { private addCardElementToOrganization(element: AnyBoardDo, cardOrganization: CommonCartridgeOrganizationNode): void { if (isRichTextElement(element)) { - const resource = this.commonCartridgeMapper.mapRichTextElementToResource(element); + const resource = this.mapper.mapRichTextElementToResource(element); cardOrganization.addResource(resource); } if (isLinkElement(element)) { - const resource = this.commonCartridgeMapper.mapLinkElementToResource(element); + const resource = this.mapper.mapLinkElementToResource(element); cardOrganization.addResource(resource); } } private addComponentToOrganization( - lessonOrganization: CommonCartridgeOrganizationNode, - component: ComponentProperties + component: ComponentProperties, + lessonOrganization: CommonCartridgeOrganizationNode ): void { - const resources = this.commonCartridgeMapper.mapContentToResources(component); + const resources = this.mapper.mapContentToResources(component); if (Array.isArray(resources)) { - const componentOrganization = lessonOrganization.createChild( - this.commonCartridgeMapper.mapContentToOrganization(component) - ); + const componentOrganization = lessonOrganization.createChild(this.mapper.mapContentToOrganization(component)); resources.forEach((resource) => { componentOrganization.addResource(resource); From 34b058a8ca8d23b015b49ee236839a44f00adf73 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 19 Apr 2024 13:18:53 +0200 Subject: [PATCH 11/46] EW-793 Renaming --- apps/server/src/modules/learnroom/learnroom.module.ts | 2 +- ....mapper.spec.ts => common-cartridge-export.mapper.spec.ts} | 4 ++-- ...-cartridge.mapper.ts => common-cartridge-export.mapper.ts} | 0 .../learnroom/service/common-cartridge-export.service.spec.ts | 2 +- .../learnroom/service/common-cartridge-export.service.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) rename apps/server/src/modules/learnroom/mapper/{common-cartridge.mapper.spec.ts => common-cartridge-export.mapper.spec.ts} (99%) rename apps/server/src/modules/learnroom/mapper/{common-cartridge.mapper.ts => common-cartridge-export.mapper.ts} (100%) diff --git a/apps/server/src/modules/learnroom/learnroom.module.ts b/apps/server/src/modules/learnroom/learnroom.module.ts index 337fc910458..bd2a147eea3 100644 --- a/apps/server/src/modules/learnroom/learnroom.module.ts +++ b/apps/server/src/modules/learnroom/learnroom.module.ts @@ -18,8 +18,8 @@ import { import { LoggerModule } from '@src/core/logger'; import { BoardNodeRepo } from '../board/repo'; import { COURSE_REPO } from './domain'; +import { CommonCartridgeExportMapper } from './mapper/common-cartridge-export.mapper'; import { CommonCartridgeImportMapper } from './mapper/common-cartridge-import.mapper'; -import { CommonCartridgeExportMapper } from './mapper/common-cartridge.mapper'; import { CourseMikroOrmRepo } from './repo/mikro-orm/course.repo'; import { BoardCopyService, diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.spec.ts similarity index 99% rename from apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts rename to apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.spec.ts index e1ee2fbf28e..d229f6da63e 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.spec.ts @@ -25,9 +25,9 @@ import { userFactory, } from '@shared/testing'; import { LearnroomConfig } from '../learnroom.config'; -import { CommonCartridgeExportMapper } from './common-cartridge.mapper'; +import { CommonCartridgeExportMapper } from './common-cartridge-export.mapper'; -describe('CommonCartridgeMapper', () => { +describe('CommonCartridgeExportMapper', () => { let module: TestingModule; let sut: CommonCartridgeExportMapper; let configServiceMock: DeepMocked>; diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts similarity index 100% rename from apps/server/src/modules/learnroom/mapper/common-cartridge.mapper.ts rename to apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts index 5ac0e15874e..6fcb7e830dc 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.spec.ts @@ -20,7 +20,7 @@ import { } from '@shared/testing'; import { ColumnBoardService } from '@src/modules/board'; import AdmZip from 'adm-zip'; -import { CommonCartridgeExportMapper } from '../mapper/common-cartridge.mapper'; +import { CommonCartridgeExportMapper } from '../mapper/common-cartridge-export.mapper'; describe('CommonCartridgeExportService', () => { let module: TestingModule; diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts index 92d83540a97..1d7f9af7837 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-export.service.ts @@ -18,7 +18,7 @@ import { ColumnBoardService } from '@src/modules/board'; import { CommonCartridgeFileBuilder } from '@src/modules/common-cartridge/export/builders/common-cartridge-file-builder'; import { CommonCartridgeOrganizationNode } from '@src/modules/common-cartridge/export/builders/common-cartridge-organization-node'; import { createIdentifier } from '@src/modules/common-cartridge/export/utils'; -import { CommonCartridgeExportMapper } from '../mapper/common-cartridge.mapper'; +import { CommonCartridgeExportMapper } from '../mapper/common-cartridge-export.mapper'; import { CourseService } from './course.service'; @Injectable() From be48244735f961d76c1b843767a18d0c8d09ebef Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 22 Apr 2024 09:27:48 +0200 Subject: [PATCH 12/46] EW-793 Add loggable exception for missing metadata and rename folder --- .../builders/common-cartridge-file-builder.ts | 3 ++- ...e-not-supported.loggable-exception.spec.ts | 2 +- ...t-type-not-supported.loggable-exception.ts | 2 +- .../errors/{error.enum.ts => error.enums.ts} | 1 + .../common-cartridge/export/errors/index.ts | 1 + ...e-not-supported.loggable-exception.spec.ts | 2 +- ...ed-use-not-supported.loggable-exception.ts | 2 +- .../missing-metadata.loggable-exception.ts | 23 +++++++++++++++++++ ...e-not-supported.loggable-exception.spec.ts | 2 +- ...e-type-not-supported.loggable-exception.ts | 2 +- ...n-not-supported.loggable-exception.spec.ts | 2 +- ...ersion-not-supported.loggable-exception.ts | 2 +- 12 files changed, 35 insertions(+), 9 deletions(-) rename apps/server/src/modules/common-cartridge/export/errors/{error.enum.ts => error.enums.ts} (87%) create mode 100644 apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts index c428a328266..e2b84b5a053 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts @@ -8,6 +8,7 @@ import { CommonCartridgeElementFactory, CommonCartridgeElementProps, } from '../elements/common-cartridge-element-factory'; +import { MissingMetadataLoggableException } from '../errors'; import { CommonCartridgeElement } from '../interfaces'; import { CommonCartridgeResourceFactory } from '../resources/common-cartridge-resource-factory'; import { @@ -54,7 +55,7 @@ export class CommonCartridgeFileBuilder { public build(): Buffer { if (!this.metadataElement) { - throw new Error('Metadata is required'); // TODO add loggable + throw new MissingMetadataLoggableException(); } const archive = new AdmZip(); diff --git a/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.spec.ts index 9c27761a872..65cd0f664d9 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.spec.ts @@ -1,5 +1,5 @@ import { ElementTypeNotSupportedLoggableException } from './element-type-not-supported.loggable-exception'; -import { CommonCartridgeErrorEnum } from './error.enum'; +import { CommonCartridgeErrorEnum } from './error.enums'; describe('ElementTypeNotSupportedLoggableException', () => { describe('getLogMessage', () => { diff --git a/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts index ab1148fcfdf..b1f3ad751b8 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; import { ErrorLogMessage, Loggable } from '@src/core/logger'; -import { CommonCartridgeErrorEnum } from './error.enum'; +import { CommonCartridgeErrorEnum } from './error.enums'; export class ElementTypeNotSupportedLoggableException extends InternalServerErrorException implements Loggable { constructor(private readonly type: string) { diff --git a/apps/server/src/modules/common-cartridge/export/errors/error.enum.ts b/apps/server/src/modules/common-cartridge/export/errors/error.enums.ts similarity index 87% rename from apps/server/src/modules/common-cartridge/export/errors/error.enum.ts rename to apps/server/src/modules/common-cartridge/export/errors/error.enums.ts index c236c2f2006..0f5081717c9 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/error.enum.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/error.enums.ts @@ -3,4 +3,5 @@ export enum CommonCartridgeErrorEnum { RESOURCE_TYPE_NOT_SUPPORTED = 'RESOURCE_TYPE_NOT_SUPPORTED', ELEMENT_TYPE_NOT_SUPPORTED = 'ELEMENT_TYPE_NOT_SUPPORTED', INTENDED_USE_NOT_SUPPORTED = 'INTENDED_USE_NOT_SUPPORTED', + MISSING_METADATA = 'MISSING_METADATA', } diff --git a/apps/server/src/modules/common-cartridge/export/errors/index.ts b/apps/server/src/modules/common-cartridge/export/errors/index.ts index 93e281f3c63..a3f364f2793 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/index.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/index.ts @@ -1,4 +1,5 @@ export { ElementTypeNotSupportedLoggableException } from './element-type-not-supported.loggable-exception'; export { IntendedUseNotSupportedLoggableException } from './intended-use-not-supported.loggable-exception'; +export { MissingMetadataLoggableException } from './missing-metadata.loggable-exception'; export { ResourceTypeNotSupportedLoggableException } from './resource-type-not-supported.loggable-exception'; export { VersionNotSupportedLoggableException } from './version-not-supported.loggable-exception'; diff --git a/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.spec.ts index 4646ef8259a..3bc2353cdae 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.spec.ts @@ -1,4 +1,4 @@ -import { CommonCartridgeErrorEnum } from './error.enum'; +import { CommonCartridgeErrorEnum } from './error.enums'; import { IntendedUseNotSupportedLoggableException } from './intended-use-not-supported.loggable-exception'; describe('IntendedUseNotSupportedLoggableException', () => { diff --git a/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts index 56f93702cf6..fc516d1a633 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; import { ErrorLogMessage, Loggable } from '@src/core/logger'; -import { CommonCartridgeErrorEnum } from './error.enum'; +import { CommonCartridgeErrorEnum } from './error.enums'; export class IntendedUseNotSupportedLoggableException extends InternalServerErrorException implements Loggable { constructor(private readonly intendedUse: string) { diff --git a/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.ts new file mode 100644 index 00000000000..7463173dfa1 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.ts @@ -0,0 +1,23 @@ +import { InternalServerErrorException } from '@nestjs/common'; +import { ErrorLogMessage, Loggable } from '@src/core/logger'; +import { CommonCartridgeErrorEnum } from './error.enums'; + +export class MissingMetadataLoggableException extends InternalServerErrorException implements Loggable { + constructor() { + super({ + type: CommonCartridgeErrorEnum.MISSING_METADATA, + }); + } + + getLogMessage(): ErrorLogMessage { + const message: ErrorLogMessage = { + type: CommonCartridgeErrorEnum.MISSING_METADATA, + stack: this.stack, + data: { + message: 'Metadata is required', + }, + }; + + return message; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.spec.ts index cc9936c200f..b51cb43cd0b 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.spec.ts @@ -1,4 +1,4 @@ -import { CommonCartridgeErrorEnum } from './error.enum'; +import { CommonCartridgeErrorEnum } from './error.enums'; import { ResourceTypeNotSupportedLoggableException } from './resource-type-not-supported.loggable-exception'; describe('ResourceTypeNotSupportedLoggableException', () => { diff --git a/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts index a6467474083..5f2f088fe6e 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; import { ErrorLogMessage, Loggable } from '@src/core/logger'; -import { CommonCartridgeErrorEnum } from './error.enum'; +import { CommonCartridgeErrorEnum } from './error.enums'; export class ResourceTypeNotSupportedLoggableException extends InternalServerErrorException implements Loggable { constructor(private readonly type: string) { diff --git a/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.spec.ts index e2d57e79178..5ec29c55fdb 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.spec.ts @@ -1,4 +1,4 @@ -import { CommonCartridgeErrorEnum } from './error.enum'; +import { CommonCartridgeErrorEnum } from './error.enums'; import { VersionNotSupportedLoggableException } from './version-not-supported.loggable-exception'; describe('VersionNotSupportedLoggableException', () => { diff --git a/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts index 5c691ff1e6f..9d254ae0076 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts @@ -1,6 +1,6 @@ import { InternalServerErrorException } from '@nestjs/common'; import { ErrorLogMessage, Loggable } from '@src/core/logger'; -import { CommonCartridgeErrorEnum } from './error.enum'; +import { CommonCartridgeErrorEnum } from './error.enums'; export class VersionNotSupportedLoggableException extends InternalServerErrorException implements Loggable { constructor(private readonly version: string) { From d4458ecb49285f31d1dc8299d79193b5d2a6dbfe Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 22 Apr 2024 09:29:30 +0200 Subject: [PATCH 13/46] EW-793 Adjust mapper test and index file --- apps/server/src/modules/common-cartridge/index.ts | 4 ++++ .../mapper/common-cartridge-export.mapper.spec.ts | 8 ++++---- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts index bbdd1fe6d0d..d19e2d0c6a8 100644 --- a/apps/server/src/modules/common-cartridge/index.ts +++ b/apps/server/src/modules/common-cartridge/index.ts @@ -1,3 +1,7 @@ +export { + CommonCartridgeFileBuilderProps, + CommonCartridgeOrganizationProps, +} from './export/builders/common-cartridge-file-builder'; export { CommonCartridgeElementType, CommonCartridgeIntendedUseType, diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.spec.ts index d229f6da63e..08ee713b63f 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.spec.ts @@ -5,7 +5,7 @@ import { CommonCartridgeElementType, CommonCartridgeFileBuilderProps, CommonCartridgeIntendedUseType, - CommonCartridgeOrganizationBuilderOptions, + CommonCartridgeOrganizationProps, CommonCartridgeResourceProps, CommonCartridgeResourceType, CommonCartridgeVersion, @@ -95,7 +95,7 @@ describe('CommonCartridgeExportMapper', () => { const { lesson } = setup(); const organizationProps = sut.mapLessonToOrganization(lesson); - expect(organizationProps).toStrictEqual>({ + expect(organizationProps).toStrictEqual>({ identifier: createIdentifier(lesson.id), title: lesson.name, }); @@ -124,7 +124,7 @@ describe('CommonCartridgeExportMapper', () => { const { componentProps } = setup(); const organizationProps = sut.mapContentToOrganization(componentProps); - expect(organizationProps).toStrictEqual>({ + expect(organizationProps).toStrictEqual>({ identifier: expect.any(String), title: componentProps.title, }); @@ -195,7 +195,7 @@ describe('CommonCartridgeExportMapper', () => { const { task } = setup(); const organizationProps = sut.mapTaskToOrganization(task); - expect(organizationProps).toStrictEqual>({ + expect(organizationProps).toStrictEqual>({ identifier: expect.any(String), title: task.name, }); From 63c3dfb7e82671408f38dc7bae4fbc1ddbf3f3f3 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Apr 2024 08:24:47 +0200 Subject: [PATCH 14/46] EW-793 Add tests for new builders and expand test factories Co-authored-by: Patrick Sachmann --- .../common-cartridge-file-builder.spec.ts | 96 ++++++++++ ...common-cartridge-organization-node.spec.ts | 166 ++++++++++++++++++ ...tridge-resource-collection-builder.spec.ts | 90 ++++++++++ ...n-cartridge-resource-collection-builder.ts | 4 +- .../common-cartridge-resource-node.spec.ts | 54 ++++++ .../src/modules/common-cartridge/index.ts | 2 +- .../common-cartridge-element-props.factory.ts | 23 ++- ...common-cartridge-resource-props.factory.ts | 10 ++ 8 files changed, 441 insertions(+), 4 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts create mode 100644 apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts new file mode 100644 index 00000000000..308f05b2ff8 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts @@ -0,0 +1,96 @@ +import { faker } from '@faker-js/faker'; +import { + createCommonCartridgeMetadataElementProps, + createCommonCartridgeOrganizationProps, +} from '../../testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWebLinkResourceProps } from '../../testing/common-cartridge-resource-props.factory'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElementFactory } from '../elements/common-cartridge-element-factory'; +import { MissingMetadataLoggableException } from '../errors'; +import { CommonCartridgeFileBuilder, CommonCartridgeFileBuilderProps } from './common-cartridge-file-builder'; +import { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node'; + +describe('CommonCartridgeFileBuilder', () => { + let sut: CommonCartridgeFileBuilder; + + const builderProps: CommonCartridgeFileBuilderProps = { + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + }; + + beforeEach(() => { + sut = new CommonCartridgeFileBuilder(builderProps); + jest.clearAllMocks(); + }); + + describe('addMetadata', () => { + describe('when metadata is added to the CommonCartridgeFileBuilder', () => { + const setup = () => { + const createElementSpy = jest.spyOn(CommonCartridgeElementFactory, 'createElement'); + const metadataProps = createCommonCartridgeMetadataElementProps(); + + return { metadataProps, createElementSpy }; + }; + + it('should set the metadata element', () => { + const { metadataProps, createElementSpy } = setup(); + + sut.addMetadata(metadataProps); + + expect(createElementSpy).toHaveBeenCalledWith({ ...metadataProps, version: builderProps.version }); + }); + }); + }); + + describe('createOrganization', () => { + describe('when an organization is created in the CommonCartridgeFileBuilder', () => { + const setup = () => { + const organizationProps = createCommonCartridgeOrganizationProps(); + + return { organizationProps }; + }; + + it('should create and return an organization node', () => { + const { organizationProps } = setup(); + + const organizationNode = sut.createOrganization(organizationProps); + + expect(organizationNode).toBeInstanceOf(CommonCartridgeOrganizationNode); + }); + }); + }); + + describe('build', () => { + describe('when metadata has not been provided', () => { + it('should throw MissingMetadataLoggableException', () => { + expect(() => { + sut.build(); + }).toThrow(MissingMetadataLoggableException); + }); + }); + + describe('when metadata has been provided', () => { + const setup = () => { + const metadataProps = createCommonCartridgeMetadataElementProps(); + const organizationProps = createCommonCartridgeOrganizationProps(); + const resourceProps = createCommonCartridgeWebLinkResourceProps(); + + return { metadataProps, organizationProps, resourceProps }; + }; + + it('should build the common cartridge file', () => { + const { metadataProps, organizationProps, resourceProps } = setup(); + + sut.addMetadata(metadataProps); + + const org = sut.createOrganization(organizationProps); + + org.addResource(resourceProps); + + const result = sut.build(); + + expect(result).toBeDefined(); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts new file mode 100644 index 00000000000..ffdaaecdcbc --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts @@ -0,0 +1,166 @@ +import { faker } from '@faker-js/faker'; +import { createMock } from '@golevelup/ts-jest'; +import { createCommonCartridgeWebLinkResourceProps } from '../../testing/common-cartridge-resource-props.factory'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeElement } from '../interfaces'; +import { + CommonCartridgeOrganizationNode, + CommonCartridgeOrganizationNodeProps, +} from './common-cartridge-organization-node'; +import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder'; + +describe('CommonCartridgeOrganizationNode', () => { + const setupOrganizationNodeProps = () => { + const props: CommonCartridgeOrganizationNodeProps = { + type: CommonCartridgeElementType.ORGANIZATION, + version: CommonCartridgeVersion.V_1_1_0, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + }; + + return props; + }; + const setupResourcesMock = () => { + const mock = createMock(); + + return mock; + }; + const setupResourceProps = () => { + const resourceProps = createCommonCartridgeWebLinkResourceProps(); + + return resourceProps; + }; + + beforeEach(() => { + jest.clearAllMocks(); + }); + + describe('folder', () => { + describe('when organization node has no parent', () => { + const setup = () => { + const resourcesMock = setupResourcesMock(); + const props = setupOrganizationNodeProps(); + const sut = new CommonCartridgeOrganizationNode(props, resourcesMock, null); + + return { sut, props }; + }; + + it('should return its own id as folder', () => { + const { sut, props } = setup(); + + const result = sut.folder; + + expect(result).toBe(props.identifier); + }); + }); + + describe('when organization node has parent', () => { + // AI next 15 lines + const setup = () => { + const resourcesMock = setupResourcesMock(); + const props = setupOrganizationNodeProps(); + const parentProps = setupOrganizationNodeProps(); + const parent = new CommonCartridgeOrganizationNode(parentProps, resourcesMock, null); + const sut = new CommonCartridgeOrganizationNode(props, resourcesMock, parent); + + return { sut, props, parentProps }; + }; + + it('should construct folder path from parent and own identifier', () => { + const { sut, props, parentProps } = setup(); + + const result = sut.folder; + + expect(result).toBe(`${parentProps.identifier}/${props.identifier}`); + }); + }); + }); + + describe('createChild', () => { + describe('when creating a child organization node', () => { + const setup = () => { + const resourcesMock = setupResourcesMock(); + const childrenMock = createMock(); + const props = setupOrganizationNodeProps(); + const childProps = setupOrganizationNodeProps(); + const sut = new CommonCartridgeOrganizationNode(props, resourcesMock, null); + + Reflect.set(sut, 'children', childrenMock); + + return { sut, childProps, childrenMock }; + }; + + it('should return a new organization node', () => { + const { sut, childProps } = setup(); + + const result = sut.createChild(childProps); + + expect(result).toBeInstanceOf(CommonCartridgeOrganizationNode); + expect(result).not.toBe(sut); + }); + + it('should add new organization node to children', () => { + const { sut, childProps, childrenMock } = setup(); + + const result = sut.createChild(childProps); + + expect(result).toBeDefined(); + expect(childrenMock.push).toHaveBeenCalledTimes(1); + }); + }); + }); + + describe('addResource', () => { + describe('when adding a resource to an organization node', () => { + const setup = () => { + const resourcesMock = setupResourcesMock(); + const childrenMock = createMock(); + const props = setupOrganizationNodeProps(); + const resourceProps = setupResourceProps(); + const sut = new CommonCartridgeOrganizationNode(props, resourcesMock, null); + + return { sut, resourceProps, childrenMock, resourcesMock }; + }; + + it('should call addResource on resource collection builder', () => { + const { sut, resourceProps, resourcesMock } = setup(); + + sut.addResource(resourceProps); + + expect(resourcesMock.addResource).toHaveBeenCalledTimes(1); + }); + }); + }); + + describe('build', () => { + describe('when building an organization node', () => { + const setup = () => { + const resourcesMock = setupResourcesMock(); + const props = setupOrganizationNodeProps(); + const sut = new CommonCartridgeOrganizationNode(props, resourcesMock, null); + const childProps = setupOrganizationNodeProps(); + const childNode = sut.createChild(childProps); + const childNodeBuildSpy = jest.spyOn(childNode, 'build'); + + return { sut, childNodeBuildSpy }; + }; + + it('should return an common cartridge element', () => { + const { sut } = setup(); + + const result = sut.build(); + + expect(result).toBeInstanceOf(CommonCartridgeElement); + }); + + it('should build all children', () => { + const { sut, childNodeBuildSpy } = setup(); + + const result = sut.build(); + + expect(result).toBeDefined(); + expect(childNodeBuildSpy).toHaveBeenCalledTimes(1); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts new file mode 100644 index 00000000000..b54ed6e0b30 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts @@ -0,0 +1,90 @@ +import { faker } from '@faker-js/faker'; +import { createMock } from '@golevelup/ts-jest'; +import { + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../common-cartridge.enums'; +import { + CommonCartridgeOrganizationNode, + CommonCartridgeOrganizationNodeProps, +} from './common-cartridge-organization-node'; +import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder'; +import { CommonCartridgeResourceNode, CommonCartridgeResourceNodeProps } from './common-cartridge-resource-node'; + +describe('CommonCartridgeResourceCollectionBuilder', () => { + let sut: CommonCartridgeResourceCollectionBuilder; + + const setupResourceNode = () => { + const resourceNodeProps: CommonCartridgeResourceNodeProps = { + type: CommonCartridgeResourceType.WEB_CONTENT, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + html: faker.lorem.paragraph(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + version: CommonCartridgeVersion.V_1_1_0, + }; + const organizationNodeProps: CommonCartridgeOrganizationNodeProps = { + identifier: faker.string.uuid(), + title: faker.lorem.words(), + version: CommonCartridgeVersion.V_1_1_0, + type: CommonCartridgeElementType.ORGANIZATION, + }; + const organizationNode = new CommonCartridgeOrganizationNode(organizationNodeProps, sut, null); + const resourceNode = new CommonCartridgeResourceNode(resourceNodeProps, organizationNode); + + return resourceNode; + }; + + beforeEach(() => { + sut = new CommonCartridgeResourceCollectionBuilder(); + jest.clearAllMocks(); + }); + + describe('addResource', () => { + describe('when a resource is added to the CommonCartridgeResourceCollectionBuilder', () => { + const setup = () => { + const resourceNode = setupResourceNode(); + const resourceNodesMock = createMock(); + + Reflect.set(sut, 'resourceNodes', resourceNodesMock); + + return { resourceNode, resourceNodesMock }; + }; + + it('should add the resource node to the collection', () => { + const { resourceNode, resourceNodesMock } = setup(); + + sut.addResource(resourceNode); + + expect(resourceNodesMock.push).toHaveBeenCalledTimes(1); + expect(resourceNodesMock.push).toHaveBeenCalledWith(resourceNode); + }); + }); + }); + + describe('build', () => { + describe('when build method is called', () => { + const setup = () => { + const resourceNode1 = setupResourceNode(); + const resourceNode2 = setupResourceNode(); + + return { resourceNode1, resourceNode2 }; + }; + + it('should return the resource collection', () => { + const { resourceNode1, resourceNode2 } = setup(); + + sut.addResource(resourceNode1); + sut.addResource(resourceNode2); + + const resources = sut.build(); + + expect(resources).toHaveLength(2); + expect(resources).toContainEqual(resourceNode1.build()); + expect(resources).toContainEqual(resourceNode2.build()); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts index 089e720685f..62b4b082480 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.ts @@ -4,11 +4,11 @@ import { CommonCartridgeResourceNode } from './common-cartridge-resource-node'; export class CommonCartridgeResourceCollectionBuilder { private readonly resourceNodes: CommonCartridgeResourceNode[] = []; - addResource(resourceNode: CommonCartridgeResourceNode): void { + public addResource(resourceNode: CommonCartridgeResourceNode): void { this.resourceNodes.push(resourceNode); } - build(): CommonCartridgeResource[] { + public build(): CommonCartridgeResource[] { const resources = this.resourceNodes.map((resource) => resource.build()); return resources; diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts new file mode 100644 index 00000000000..5678583c6af --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts @@ -0,0 +1,54 @@ +import { faker } from '@faker-js/faker'; +import { createCommonCartridgeWebLinkResourceProps } from '../../testing/common-cartridge-resource-props.factory'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeResource } from '../interfaces'; +import { + CommonCartridgeOrganizationNode, + CommonCartridgeOrganizationNodeProps, +} from './common-cartridge-organization-node'; +import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder'; +import { CommonCartridgeResourceNode, CommonCartridgeResourceNodeProps } from './common-cartridge-resource-node'; + +describe('CommonCartridgeResourceNode', () => { + let sut: CommonCartridgeResourceNode; + + describe('build', () => { + describe('when build is called', () => { + const setup = () => { + const resourceNodeProps: CommonCartridgeResourceNodeProps = { + ...createCommonCartridgeWebLinkResourceProps(), + version: CommonCartridgeVersion.V_1_1_0, + }; + + const organizationNodeProps: CommonCartridgeOrganizationNodeProps = { + identifier: faker.string.uuid(), + title: faker.lorem.words(), + version: CommonCartridgeVersion.V_1_1_0, + type: CommonCartridgeElementType.ORGANIZATION, + }; + + const resourceCollectionBuilder: CommonCartridgeResourceCollectionBuilder = + new CommonCartridgeResourceCollectionBuilder(); + + const organizationNode = new CommonCartridgeOrganizationNode( + organizationNodeProps, + resourceCollectionBuilder, + null + ); + + return { resourceNodeProps, organizationNode }; + }; + + it('should return a CommonCartridgeResource', () => { + const { resourceNodeProps, organizationNode } = setup(); + + sut = new CommonCartridgeResourceNode(resourceNodeProps, organizationNode); + + const result = sut.build(); + + expect(result).toBeDefined(); + expect(result).toBeInstanceOf(CommonCartridgeResource); + }); + }); + }); +}); diff --git a/apps/server/src/modules/common-cartridge/index.ts b/apps/server/src/modules/common-cartridge/index.ts index 3ad32b8ce48..5a29fd1c900 100644 --- a/apps/server/src/modules/common-cartridge/index.ts +++ b/apps/server/src/modules/common-cartridge/index.ts @@ -15,8 +15,8 @@ export { CommonCartridgeFileParser } from './import/common-cartridge-file-parser export { CommonCartridgeResourceTypeV1P1 } from './import/common-cartridge-import.enums'; export { CommonCartridgeFileParserOptions, + CommonCartridgeOrganizationProps as CommonCartridgeImportOrganizationProps, CommonCartridgeResourceProps as CommonCartridgeImportResourceProps, - CommonCartridgeOrganizationProps, DEFAULT_FILE_PARSER_OPTIONS, } from './import/common-cartridge-import.types'; export { CommonCartridgeImportUtils } from './import/utils/common-cartridge-import-utils'; diff --git a/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts index 000ad586840..c6b69a6a469 100644 --- a/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts @@ -1,5 +1,10 @@ import { faker } from '@faker-js/faker'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '@modules/common-cartridge'; +import { + CommonCartridgeElementProps, + CommonCartridgeElementType, + CommonCartridgeOrganizationProps, + CommonCartridgeVersion, +} from '@modules/common-cartridge'; import { CommonCartridgeMetadataElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-metadata-element'; import { CommonCartridgeOrganizationElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-organization-element'; import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-organizations-wrapper-element'; @@ -94,3 +99,19 @@ export function createCommonCartridgeResourcesWrapperElementPropsV130( items: items || [], }; } + +export function createCommonCartridgeMetadataElementProps(): CommonCartridgeElementProps { + return { + type: CommonCartridgeElementType.METADATA, + title: faker.lorem.words(), + creationDate: new Date(), + copyrightOwners: ['John Doe', 'Jane Doe'], + }; +} + +export function createCommonCartridgeOrganizationProps(): CommonCartridgeOrganizationProps { + return { + title: faker.lorem.words(), + identifier: faker.string.uuid(), + }; +} diff --git a/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts index cbe4f31f0c6..8aece02d9c0 100644 --- a/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts @@ -1,6 +1,7 @@ import { faker } from '@faker-js/faker'; import { CommonCartridgeIntendedUseType, + CommonCartridgeResourceProps, CommonCartridgeResourceType, CommonCartridgeVersion, } from '@modules/common-cartridge'; @@ -79,3 +80,12 @@ export function createCommonCartridgeManifestResourcePropsV130(): CommonCartridg resources: [], }; } + +export function createCommonCartridgeWebLinkResourceProps(): CommonCartridgeResourceProps { + return { + type: CommonCartridgeResourceType.WEB_LINK, + title: faker.lorem.words(), + identifier: faker.string.uuid(), + url: faker.internet.url(), + }; +} From 5580ea5c9153180b8e5e6009ddb2377fb4e9270e Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Apr 2024 09:30:53 +0200 Subject: [PATCH 15/46] EW-793 Adjust import --- .../learnroom/service/common-cartridge-import.service.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/service/common-cartridge-import.service.ts b/apps/server/src/modules/learnroom/service/common-cartridge-import.service.ts index c53f98bb0d1..4f18b370eea 100644 --- a/apps/server/src/modules/learnroom/service/common-cartridge-import.service.ts +++ b/apps/server/src/modules/learnroom/service/common-cartridge-import.service.ts @@ -4,7 +4,7 @@ import { Course, User } from '@shared/domain/entity'; import { CardService, ColumnBoardService, ColumnService, ContentElementService } from '@src/modules/board'; import { CommonCartridgeFileParser, - CommonCartridgeOrganizationProps, + CommonCartridgeImportOrganizationProps, DEFAULT_FILE_PARSER_OPTIONS, } from '@src/modules/common-cartridge'; import { CommonCartridgeImportMapper } from '../mapper/common-cartridge-import.mapper'; @@ -57,8 +57,8 @@ export class CommonCartridgeImportService { private async createColumn( parser: CommonCartridgeFileParser, columnBoard: ColumnBoard, - columnProps: CommonCartridgeOrganizationProps, - organizations: CommonCartridgeOrganizationProps[] + columnProps: CommonCartridgeImportOrganizationProps, + organizations: CommonCartridgeImportOrganizationProps[] ): Promise { const column = await this.columnService.create(columnBoard, this.mapper.mapOrganizationToColumn(columnProps)); const cards = organizations.filter( @@ -74,7 +74,7 @@ export class CommonCartridgeImportService { private async createCard( parser: CommonCartridgeFileParser, column: Column, - cardProps: CommonCartridgeOrganizationProps + cardProps: CommonCartridgeImportOrganizationProps ): Promise { const card = await this.cardService.create(column, undefined, this.mapper.mapOrganizationToCard(cardProps)); const resource = parser.getResource(cardProps); From d9157855071c5f8e67324b9c5c4c89b323cbeaad Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Apr 2024 10:03:21 +0200 Subject: [PATCH 16/46] EW-793 Adjust import for CommonCartridgeImportOrganizationProps --- .../learnroom/mapper/common-cartridge-import.mapper.spec.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge-import.mapper.spec.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge-import.mapper.spec.ts index 9aa415f5f60..590b05c86a2 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge-import.mapper.spec.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge-import.mapper.spec.ts @@ -1,13 +1,13 @@ import { faker } from '@faker-js/faker'; import { Test, TestingModule } from '@nestjs/testing'; import { CardInitProps, ColumnInitProps, ContentElementType } from '@shared/domain/domainobject'; +import { InputFormat } from '@shared/domain/types'; import { LinkContentBody, RichTextContentBody } from '@src/modules/board/controller/dto'; import { + CommonCartridgeImportOrganizationProps, CommonCartridgeImportResourceProps, - CommonCartridgeOrganizationProps, CommonCartridgeResourceTypeV1P1, } from '@src/modules/common-cartridge'; -import { InputFormat } from '@shared/domain/types'; import { CommonCartridgeImportMapper } from './common-cartridge-import.mapper'; describe('CommonCartridgeImportMapper', () => { @@ -15,7 +15,7 @@ describe('CommonCartridgeImportMapper', () => { let sut: CommonCartridgeImportMapper; const setupOrganization = () => { - const organization: CommonCartridgeOrganizationProps = { + const organization: CommonCartridgeImportOrganizationProps = { path: faker.string.uuid(), pathDepth: faker.number.int({ min: 0, max: 3 }), identifier: faker.string.uuid(), From 7fc8fab8d4bba0535a4fd1a3c6b5a8ba9e64ae18 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Apr 2024 10:23:23 +0200 Subject: [PATCH 17/46] EW-793 Add test for new loggable exception --- ...issing-metadata.loggable-exception.spec.ts | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.spec.ts diff --git a/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.spec.ts b/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.spec.ts new file mode 100644 index 00000000000..3d0b32d87d9 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.spec.ts @@ -0,0 +1,22 @@ +import { CommonCartridgeErrorEnum } from './error.enums'; +import { MissingMetadataLoggableException } from './missing-metadata.loggable-exception'; + +describe('MissingMetadataLoggableException', () => { + describe('getLogMessage', () => { + describe('when getting log message', () => { + const exception = new MissingMetadataLoggableException(); + + it('should return log message', () => { + const result = exception.getLogMessage(); + + expect(result).toStrictEqual({ + type: CommonCartridgeErrorEnum.MISSING_METADATA, + stack: exception.stack, + data: { + message: 'Metadata is required', + }, + }); + }); + }); + }); +}); From 9b4d7a637c31453224950b7e43c0c2c48cb47957 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Apr 2024 11:09:20 +0200 Subject: [PATCH 18/46] EW-793 Add xml object interface Co-authored-by: Patrick Sachmann --- .../elements/v1.1.0/common-cartridge-metadata-element.ts | 4 ++-- .../elements/v1.1.0/common-cartridge-organization-element.ts | 4 ++-- .../v1.1.0/common-cartridge-organizations-wrapper-element.ts | 4 ++-- .../v1.1.0/common-cartridge-resources-wrapper-element.ts | 4 ++-- .../elements/v1.3.0/common-cartridge-metadata-element.ts | 4 ++-- .../elements/v1.3.0/common-cartridge-organization-element.ts | 4 ++-- .../v1.3.0/common-cartridge-organizations-wrapper-element.ts | 4 ++-- .../v1.3.0/common-cartridge-resources-wrapper-element.ts | 4 ++-- .../export/interfaces/common-cartridge-element.interface.ts | 3 ++- .../src/modules/common-cartridge/export/interfaces/index.ts | 1 + .../export/interfaces/xml-object.interface.ts | 1 + .../resources/v1.1.0/common-cartridge-manifest-resource.ts | 4 ++-- .../resources/v1.1.0/common-cartridge-web-content-resource.ts | 4 ++-- .../resources/v1.1.0/common-cartridge-web-link-resource.ts | 4 ++-- .../resources/v1.3.0/common-cartridge-manifest-resource.ts | 4 ++-- .../resources/v1.3.0/common-cartridge-web-content-resource.ts | 4 ++-- .../resources/v1.3.0/common-cartridge-web-link-resource.ts | 4 ++-- 17 files changed, 32 insertions(+), 29 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/interfaces/xml-object.interface.ts diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts index c70cbd2c892..217eb9639ab 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeMetadataElementPropsV110 = { type: CommonCartridgeElementType.METADATA; @@ -18,7 +18,7 @@ export class CommonCartridgeMetadataElementV110 extends CommonCartridgeElement { return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { schema: 'IMS Common Cartridge', schemaversion: '1.1.0', diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts index ff304d6ea08..0d9bd34a223 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement, CommonCartridgeResource } from '../../interfaces'; +import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; import { createIdentifier } from '../../utils'; export type CommonCartridgeOrganizationElementPropsV110 = { @@ -19,7 +19,7 @@ export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeEleme return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { if (this.props.items instanceof CommonCartridgeResource) { return { $: { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts index 9d1c44ec85d..d82d19f69f0 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationsWrapperElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; @@ -16,7 +16,7 @@ export class CommonCartridgeOrganizationsWrapperElementV110 extends CommonCartri return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { organization: [ { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts index 4048787732a..0917e906839 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeResourcesWrapperElementPropsV110 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; @@ -16,7 +16,7 @@ export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeE return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { resources: [ { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts index a6477783e57..7ede15ab102 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeMetadataElementPropsV130 = { type: CommonCartridgeElementType.METADATA; @@ -18,7 +18,7 @@ export class CommonCartridgeMetadataElementV130 extends CommonCartridgeElement { return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { schema: 'IMS Common Cartridge', schemaversion: '1.3.0', diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts index 14696edfd95..f3d9f0b3106 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement, CommonCartridgeResource } from '../../interfaces'; +import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; import { createIdentifier } from '../../utils'; export type CommonCartridgeOrganizationElementPropsV130 = { @@ -19,7 +19,7 @@ export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeEleme return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { if (this.props.items instanceof CommonCartridgeResource) { return { $: { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts index 3c00f4844d2..bba69960e5c 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationsWrapperElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; @@ -16,7 +16,7 @@ export class CommonCartridgeOrganizationsWrapperElementV130 extends CommonCartri return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { organization: [ { diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts index aa11d0f457a..c3f3875a952 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement } from '../../interfaces'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeResourcesWrapperElementPropsV130 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; @@ -16,7 +16,7 @@ export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeE return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { resources: [ { diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts index 4580562aff3..48f0ee0ad7d 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts @@ -1,5 +1,6 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { VersionNotSupportedLoggableException } from '../errors'; +import { XmlObject } from './xml-object.interface'; type CommonCartridgeElementProps = { version: CommonCartridgeVersion; @@ -33,7 +34,7 @@ export abstract class CommonCartridgeElement { * This method is used to build the imsmanifest.xml file. * @returns The XML object representation for the imsmanifest.xml file. */ - abstract getManifestXmlObject(): Record; + abstract getManifestXmlObject(): XmlObject; private checkVersion(target: CommonCartridgeVersion): void { if (this.getSupportedVersion() !== target) { diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts index aaefb39018c..1b49948d3f7 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts @@ -1,2 +1,3 @@ export { CommonCartridgeElement } from './common-cartridge-element.interface'; export { CommonCartridgeResource } from './common-cartridge-resource.interface'; +export { XmlObject } from './xml-object.interface'; diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/xml-object.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/xml-object.interface.ts new file mode 100644 index 00000000000..583e52d208e --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/interfaces/xml-object.interface.ts @@ -0,0 +1 @@ +export interface XmlObject extends Record {} diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts index ae578c34e4a..ddab40b3bb3 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -4,7 +4,7 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; -import { CommonCartridgeElement, CommonCartridgeResource } from '../../interfaces'; +import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV110 = { @@ -37,7 +37,7 @@ export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { manifest: { $: { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts index 31e4f2d4f17..59a4e74737e 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -4,7 +4,7 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeGuard } from '../../common-cartridge.guard'; -import { CommonCartridgeResource } from '../../interfaces'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; export type CommonCartridgeWebContentResourcePropsV110 = { type: CommonCartridgeResourceType.WEB_CONTENT; @@ -47,7 +47,7 @@ export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResour return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts index 4da6c641215..4d6b31c7e84 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -1,5 +1,5 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV110 = { @@ -51,7 +51,7 @@ export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts index 3da27cb30b8..9913108595c 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -7,7 +7,7 @@ import { CommonCartridgeOrganizationsWrapperElementV130, CommonCartridgeResourcesWrapperElementV130, } from '../../elements/v1.3.0'; -import { CommonCartridgeElement, CommonCartridgeResource } from '../../interfaces'; +import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV130 = { @@ -40,7 +40,7 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { manifest: { $: { diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts index 175d2da468c..dd23ef6926c 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -4,7 +4,7 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeGuard } from '../../common-cartridge.guard'; -import { CommonCartridgeResource } from '../../interfaces'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; export type CommonCartridgeWebContentResourcePropsV130 = { type: CommonCartridgeResourceType.WEB_CONTENT; @@ -48,7 +48,7 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResour return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { $: { identifier: this.props.identifier, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts index 1cfd8a3df5b..36dd32e77a3 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -1,5 +1,5 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeResource } from '../../interfaces'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV130 = { @@ -51,7 +51,7 @@ export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): Record { + public getManifestXmlObject(): XmlObject { return { $: { identifier: this.props.identifier, From e5563f2091cd2784d597a5bf8c0829525f2307e1 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Apr 2024 11:16:48 +0200 Subject: [PATCH 19/46] EW-793 Add public keyword to loggable methods --- .../errors/element-type-not-supported.loggable-exception.ts | 2 +- .../errors/intended-use-not-supported.loggable-exception.ts | 2 +- .../export/errors/missing-metadata.loggable-exception.ts | 2 +- .../errors/resource-type-not-supported.loggable-exception.ts | 2 +- .../export/errors/version-not-supported.loggable-exception.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts index b1f3ad751b8..19dd0ff941d 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/element-type-not-supported.loggable-exception.ts @@ -9,7 +9,7 @@ export class ElementTypeNotSupportedLoggableException extends InternalServerErro }); } - getLogMessage(): ErrorLogMessage { + public getLogMessage(): ErrorLogMessage { const message: ErrorLogMessage = { type: CommonCartridgeErrorEnum.ELEMENT_TYPE_NOT_SUPPORTED, stack: this.stack, diff --git a/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts index fc516d1a633..5259bd517f1 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/intended-use-not-supported.loggable-exception.ts @@ -9,7 +9,7 @@ export class IntendedUseNotSupportedLoggableException extends InternalServerErro }); } - getLogMessage(): ErrorLogMessage { + public getLogMessage(): ErrorLogMessage { const message: ErrorLogMessage = { type: CommonCartridgeErrorEnum.INTENDED_USE_NOT_SUPPORTED, stack: this.stack, diff --git a/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.ts index 7463173dfa1..9ee3d6bcff0 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/missing-metadata.loggable-exception.ts @@ -9,7 +9,7 @@ export class MissingMetadataLoggableException extends InternalServerErrorExcepti }); } - getLogMessage(): ErrorLogMessage { + public getLogMessage(): ErrorLogMessage { const message: ErrorLogMessage = { type: CommonCartridgeErrorEnum.MISSING_METADATA, stack: this.stack, diff --git a/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts index 5f2f088fe6e..4d9d9d8a8e1 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/resource-type-not-supported.loggable-exception.ts @@ -9,7 +9,7 @@ export class ResourceTypeNotSupportedLoggableException extends InternalServerErr }); } - getLogMessage(): ErrorLogMessage { + public getLogMessage(): ErrorLogMessage { const message: ErrorLogMessage = { type: CommonCartridgeErrorEnum.RESOURCE_TYPE_NOT_SUPPORTED, stack: this.stack, diff --git a/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts b/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts index 9d254ae0076..bb22519217e 100644 --- a/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts +++ b/apps/server/src/modules/common-cartridge/export/errors/version-not-supported.loggable-exception.ts @@ -9,7 +9,7 @@ export class VersionNotSupportedLoggableException extends InternalServerErrorExc }); } - getLogMessage(): ErrorLogMessage { + public getLogMessage(): ErrorLogMessage { const message: ErrorLogMessage = { type: CommonCartridgeErrorEnum.VERSION_NOT_SUPPORTED, stack: this.stack, From 9ba35fa6596b318006a501ef16f28c8a654d3222 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Apr 2024 11:40:21 +0200 Subject: [PATCH 20/46] EW-793 Add new guard to org element --- .../export/common-cartridge.guard.spec.ts | 40 ++++++++++++++ .../export/common-cartridge.guard.ts | 11 +++- .../common-cartridge-organization-element.ts | 52 ++++++++++--------- 3 files changed, 77 insertions(+), 26 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts index 0739b6307b3..559470b9b1f 100644 --- a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts @@ -1,4 +1,8 @@ +import { createCommonCartridgeMetadataElementPropsV110 } from '../testing/common-cartridge-element-props.factory'; +import { createCommonCartridgeWeblinkResourcePropsV110 } from '../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeGuard } from './common-cartridge.guard'; +import { CommonCartridgeElementFactory } from './elements/common-cartridge-element-factory'; +import { CommonCartridgeResourceFactory } from './resources/common-cartridge-resource-factory'; describe('CommonCartridgeGuard', () => { describe('checkIntendedUse', () => { @@ -26,4 +30,40 @@ describe('CommonCartridgeGuard', () => { }); }); }); + + describe('isResource', () => { + describe('when element is a resource', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV110(); + const element = CommonCartridgeResourceFactory.createResource(props); + + return { element }; + }; + + it('should return true', () => { + const { element } = setup(); + + const result = CommonCartridgeGuard.isResource(element); + + expect(result).toBe(true); + }); + }); + + describe('when element is not a resource', () => { + const setup = () => { + const props = createCommonCartridgeMetadataElementPropsV110(); + const element = CommonCartridgeElementFactory.createElement(props); + + return { element }; + }; + + it('should return false', () => { + const { element } = setup(); + + const result = CommonCartridgeGuard.isResource(element); + + expect(result).toBe(false); + }); + }); + }); }); diff --git a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts index af850466912..20c2a501053 100644 --- a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts +++ b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts @@ -1,9 +1,18 @@ import { IntendedUseNotSupportedLoggableException } from './errors'; +import { CommonCartridgeElement, CommonCartridgeResource } from './interfaces'; export class CommonCartridgeGuard { - static checkIntendedUse(intendedUse: string, supportedIntendedUses: string[]): void | never { + public static checkIntendedUse(intendedUse: string, supportedIntendedUses: string[]): void { if (!supportedIntendedUses.includes(intendedUse)) { throw new IntendedUseNotSupportedLoggableException(intendedUse); } } + + public static isResource( + element: CommonCartridgeElement | (CommonCartridgeElement | CommonCartridgeResource)[] + ): element is CommonCartridgeResource { + const result = element instanceof CommonCartridgeResource; + + return result; + } } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts index 0d9bd34a223..d68b0c9afab 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts @@ -1,6 +1,6 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeGuard } from '../../common-cartridge.guard'; import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; -import { createIdentifier } from '../../utils'; export type CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION; @@ -20,34 +20,36 @@ export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeEleme } public getManifestXmlObject(): XmlObject { - if (this.props.items instanceof CommonCartridgeResource) { - return { - $: { - identifier: this.identifier, - identifierref: this.props.items.identifier, - }, - title: this.title, - }; - } - - return { + const xmlObject = CommonCartridgeGuard.isResource(this.props.items) + ? this.getManifestXmlObjectForResource(this.props.items) + : this.getManifestXmlObjectForResourceCollection(this.props.items); + + return xmlObject; + } + + private getManifestXmlObjectForResource(item: CommonCartridgeResource): XmlObject { + const xmlObject = { + $: { + identifier: this.identifier, + identifierref: item.identifier, + }, + title: this.title, + }; + + return xmlObject; + } + + private getManifestXmlObjectForResourceCollection( + items: (CommonCartridgeElement | CommonCartridgeResource)[] + ): XmlObject { + const xmlObject = { $: { identifier: this.identifier, }, title: this.title, - item: this.props.items.map((item) => { - if (item instanceof CommonCartridgeResource) { - return { - $: { - identifier: createIdentifier(), - identifierref: item.identifier, - }, - title: item.title, - }; - } - - return item.getManifestXmlObject(); - }), + item: items.map((item) => item.getManifestXmlObject()), }; + + return xmlObject; } } From 8827adb95b258f9dbede9935c8c11087ac12c37a Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 26 Apr 2024 11:52:05 +0200 Subject: [PATCH 21/46] EW-793 Work in progress --- .../elements/v1.1.0/common-cartridge-organization-element.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts index d68b0c9afab..862144f4c0f 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts @@ -7,7 +7,7 @@ export type CommonCartridgeOrganizationElementPropsV110 = { version: CommonCartridgeVersion; identifier: string; title: string; - items: CommonCartridgeResource | Array; + items: CommonCartridgeResource | Array; }; export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeElement { From b4e7cdd7d11c207c0630fbcc58f71e4d24ee57bf Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 29 Apr 2024 11:20:40 +0200 Subject: [PATCH 22/46] EW.793 Work in progress Co-authored-by: Patrick Sachmann --- .../common-cartridge-organization-element.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts index 862144f4c0f..bf12a1e95a9 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts @@ -1,6 +1,7 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeGuard } from '../../common-cartridge.guard'; import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { createIdentifier } from '../../utils'; export type CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION; @@ -47,7 +48,19 @@ export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeEleme identifier: this.identifier, }, title: this.title, - item: items.map((item) => item.getManifestXmlObject()), + item: items.map((item) => { + if (CommonCartridgeGuard.isResource(item)) { + return { + $: { + identifier: createIdentifier(), + identifierref: item.identifier, + }, + title: item.title, + }; + } + + return item.getManifestXmlObject(); + }), }; return xmlObject; From db411ea07751c925a7bac4f831d0708b866b6413 Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Tue, 14 May 2024 14:52:18 +0200 Subject: [PATCH 23/46] EW-793 introducing some interfaces --- .../export/common-cartridge.guard.ts | 6 +-- .../common-cartridge-base.interface.ts | 47 +++++++++++++++++ .../common-cartridge-element.interface.ts | 36 +------------ ...common-cartridge-organization.interface.ts | 9 ++++ .../common-cartridge-resource.interface.ts | 10 ++-- .../export/interfaces/index.ts | 2 + .../common-cartridge-manifest-resource.ts | 7 ++- .../common-cartridge-web-content-resource.ts | 48 +++++++++++------ .../common-cartridge-web-link-resource.ts | 51 ++++++++++++------- .../common-cartridge-manifest-resource.ts | 7 ++- .../common-cartridge-web-content-resource.ts | 48 +++++++++++------ .../common-cartridge-web-link-resource.ts | 51 ++++++++++++------- 12 files changed, 210 insertions(+), 112 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts create mode 100644 apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-organization.interface.ts diff --git a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts index 20c2a501053..1a3ad075cb3 100644 --- a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts +++ b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts @@ -1,5 +1,5 @@ import { IntendedUseNotSupportedLoggableException } from './errors'; -import { CommonCartridgeElement, CommonCartridgeResource } from './interfaces'; +import { CommonCartridgeResource } from './interfaces'; export class CommonCartridgeGuard { public static checkIntendedUse(intendedUse: string, supportedIntendedUses: string[]): void { @@ -8,9 +8,7 @@ export class CommonCartridgeGuard { } } - public static isResource( - element: CommonCartridgeElement | (CommonCartridgeElement | CommonCartridgeResource)[] - ): element is CommonCartridgeResource { + public static isResource(element: unknown): element is CommonCartridgeResource { const result = element instanceof CommonCartridgeResource; return result; diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts new file mode 100644 index 00000000000..63b01026467 --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts @@ -0,0 +1,47 @@ +import { CommonCartridgeVersion } from '../common-cartridge.enums'; + +type CCBaseProps = { + version: CommonCartridgeVersion; + identifier?: string; + title?: string; +}; + +export abstract class CommonCartridgeBase { + protected constructor(public readonly baseProps: CCBaseProps) { + this.checkVersion(baseProps.version); + } + + public get identifier(): string | undefined { + return this.baseProps.identifier; + } + + public get title(): string | undefined { + return this.baseProps.title; + } + + abstract getSupportedVersion(): CommonCartridgeVersion; + + private checkVersion(target: CommonCartridgeVersion): void { + if (this.getSupportedVersion() !== target) { + throw new Error(`Version ${target} is not supported.`); + } + } +} + +// export abstract class CCElement extends CCBase { +// abstract getManifestXmlObject(): XmlObject; +// } + +// export abstract class CCOrganization extends CCBase { +// abstract getManifestOrganizationXmlObject(): XmlObject; +// } + +// export abstract class CCResource extends CCOrganization { +// abstract getManifestResourceXmlObject(): XmlObject; + +// abstract canInline(): boolean; + +// abstract getFilePath(): string; + +// abstract getFileContent(): string; +// } diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts index 48f0ee0ad7d..28ed473f305 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts @@ -1,44 +1,12 @@ -import { CommonCartridgeVersion } from '../common-cartridge.enums'; -import { VersionNotSupportedLoggableException } from '../errors'; import { XmlObject } from './xml-object.interface'; -type CommonCartridgeElementProps = { - version: CommonCartridgeVersion; - identifier?: string; - title?: string; -}; - /** * Every element which should be listed in the Common Cartridge manifest must implement this interface. */ -export abstract class CommonCartridgeElement { - protected constructor(private readonly baseProps: CommonCartridgeElementProps) { - this.checkVersion(baseProps.version); - } - - public get identifier(): string | undefined { - return this.baseProps.identifier; - } - - public get title(): string | undefined { - return this.baseProps.title; - } - - /** - * Every element must know which versions it supports. - * @returns The supported versions for this element. - */ - abstract getSupportedVersion(): CommonCartridgeVersion; - +export interface CommonCartridgeElement { /** * This method is used to build the imsmanifest.xml file. * @returns The XML object representation for the imsmanifest.xml file. */ - abstract getManifestXmlObject(): XmlObject; - - private checkVersion(target: CommonCartridgeVersion): void { - if (this.getSupportedVersion() !== target) { - throw new VersionNotSupportedLoggableException(target); - } - } + getManifestXmlObject(): XmlObject; } diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-organization.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-organization.interface.ts new file mode 100644 index 00000000000..f21f921f38b --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-organization.interface.ts @@ -0,0 +1,9 @@ +import { XmlObject } from './xml-object.interface'; + +export interface CommonCartridgeOrganization { + isResource(): boolean; + + getManifestOrganizationXmlObject(): XmlObject; + + getManifestResourceXmlObject(): XmlObject; +} diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts index dfa3adbc8b4..2df03fcb71e 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts @@ -1,24 +1,22 @@ -import { CommonCartridgeElement } from './common-cartridge-element.interface'; - /** * Every resource which should be added to the Common Cartridge archive must implement this interface. */ -export abstract class CommonCartridgeResource extends CommonCartridgeElement { +export interface CommonCartridgeResource { /** * In later Common Cartridge versions, resources can be inlined in the imsmanifest.xml file. * @returns true if the resource can be inlined, otherwise false. */ - abstract canInline(): boolean; + canInline(): boolean; /** * This method is used to determine the path of the resource in the Common Cartridge archive. * @returns The path of the resource in the Common Cartridge archive. */ - abstract getFilePath(): string; + getFilePath(): string; /** * This method is used to get the content of the resource. * @returns The content of the resource. */ - abstract getFileContent(): string; + getFileContent(): string; } diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts index 1b49948d3f7..32785be421e 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts @@ -1,3 +1,5 @@ +export { CommonCartridgeBase } from './common-cartridge-base.interface'; export { CommonCartridgeElement } from './common-cartridge-element.interface'; +export { CommonCartridgeOrganization } from './common-cartridge-organization.interface'; export { CommonCartridgeResource } from './common-cartridge-resource.interface'; export { XmlObject } from './xml-object.interface'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts index ddab40b3bb3..48ae687ea16 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -4,7 +4,7 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; -import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV110 = { @@ -16,7 +16,10 @@ export type CommonCartridgeManifestResourcePropsV110 = { resources: CommonCartridgeElement[]; }; -export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource { +export class CommonCartridgeManifestResourceV110 + extends CommonCartridgeBase + implements CommonCartridgeElement, CommonCartridgeResource +{ constructor(private readonly props: CommonCartridgeManifestResourcePropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts index 59a4e74737e..162c8230d37 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -4,7 +4,8 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeGuard } from '../../common-cartridge.guard'; -import { CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { createIdentifier } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV110 = { type: CommonCartridgeResourceType.WEB_CONTENT; @@ -16,7 +17,10 @@ export type CommonCartridgeWebContentResourcePropsV110 = { intendedUse: CommonCartridgeIntendedUseType; }; -export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResource { +export class CommonCartridgeWebContentResourceV110 + extends CommonCartridgeBase + implements CommonCartridgeOrganization, CommonCartridgeResource +{ private static readonly SUPPORTED_INTENDED_USES = [ CommonCartridgeIntendedUseType.LESSON_PLAN, CommonCartridgeIntendedUseType.SYLLABUS, @@ -31,23 +35,21 @@ export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResour ); } - public canInline(): boolean { - return false; - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.html`; - } - - public getFileContent(): string { - return this.props.html; + public isResource(): boolean { + return true; } - public getSupportedVersion(): CommonCartridgeVersion { - return CommonCartridgeVersion.V_1_1_0; + public getManifestOrganizationXmlObject(): XmlObject { + return { + $: { + identifier: createIdentifier(), + identifierref: this.props.identifier, + }, + title: this.props.title, + }; } - public getManifestXmlObject(): XmlObject { + public getManifestResourceXmlObject(): XmlObject { return { $: { identifier: this.props.identifier, @@ -61,4 +63,20 @@ export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResour }, }; } + + public canInline(): boolean { + return false; + } + + public getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.html`; + } + + public getFileContent(): string { + return this.props.html; + } + + public getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts index 4d6b31c7e84..4c438e6558a 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -1,6 +1,6 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeResource, XmlObject } from '../../interfaces'; -import { buildXmlString } from '../../utils'; +import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { buildXmlString, createIdentifier } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV110 = { type: CommonCartridgeResourceType.WEB_LINK; @@ -13,11 +13,42 @@ export type CommonCartridgeWebLinkResourcePropsV110 = { windowFeatures?: string; }; -export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource { +export class CommonCartridgeWebLinkResourceV110 + extends CommonCartridgeBase + implements CommonCartridgeOrganization, CommonCartridgeResource +{ constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV110) { super(props); } + public isResource(): boolean { + return true; + } + + public getManifestOrganizationXmlObject(): XmlObject { + return { + $: { + identifier: createIdentifier(), + identifierref: this.props.identifier, + }, + title: this.props.title, + }; + } + + public getManifestResourceXmlObject(): XmlObject { + return { + $: { + identifier: this.props.identifier, + type: 'imswl_xmlv1p1', + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } + public canInline(): boolean { return false; } @@ -50,18 +81,4 @@ export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - - public getManifestXmlObject(): XmlObject { - return { - $: { - identifier: this.props.identifier, - type: 'imswl_xmlv1p1', - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts index 9913108595c..0e68762b60e 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -7,7 +7,7 @@ import { CommonCartridgeOrganizationsWrapperElementV130, CommonCartridgeResourcesWrapperElementV130, } from '../../elements/v1.3.0'; -import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV130 = { @@ -19,7 +19,10 @@ export type CommonCartridgeManifestResourcePropsV130 = { resources: CommonCartridgeElement[]; }; -export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource { +export class CommonCartridgeManifestResourceV130 + extends CommonCartridgeBase + implements CommonCartridgeElement, CommonCartridgeResource +{ constructor(private readonly props: CommonCartridgeManifestResourcePropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts index dd23ef6926c..00d9d5cfeed 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -4,7 +4,8 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeGuard } from '../../common-cartridge.guard'; -import { CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { createIdentifier } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV130 = { type: CommonCartridgeResourceType.WEB_CONTENT; @@ -16,7 +17,10 @@ export type CommonCartridgeWebContentResourcePropsV130 = { intendedUse: CommonCartridgeIntendedUseType; }; -export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResource { +export class CommonCartridgeWebContentResourceV130 + extends CommonCartridgeBase + implements CommonCartridgeOrganization, CommonCartridgeResource +{ private static readonly SUPPORTED_INTENDED_USES = [ CommonCartridgeIntendedUseType.ASSIGNMENT, CommonCartridgeIntendedUseType.LESSON_PLAN, @@ -32,23 +36,21 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResour ); } - public canInline(): boolean { - return false; - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.html`; - } - - public getFileContent(): string { - return this.props.html; + public isResource(): boolean { + return true; } - public getSupportedVersion(): CommonCartridgeVersion { - return CommonCartridgeVersion.V_1_3_0; + public getManifestOrganizationXmlObject(): XmlObject { + return { + $: { + identifier: createIdentifier(), + identifierref: this.props.identifier, + }, + title: this.props.title, + }; } - public getManifestXmlObject(): XmlObject { + public getManifestResourceXmlObject(): XmlObject { return { $: { identifier: this.props.identifier, @@ -62,4 +64,20 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResour }, }; } + + public canInline(): boolean { + return false; + } + + public getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.html`; + } + + public getFileContent(): string { + return this.props.html; + } + + public getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts index 36dd32e77a3..cd2f561650a 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -1,6 +1,6 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeResource, XmlObject } from '../../interfaces'; -import { buildXmlString } from '../../utils'; +import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { buildXmlString, createIdentifier } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV130 = { type: CommonCartridgeResourceType.WEB_LINK; @@ -13,11 +13,42 @@ export type CommonCartridgeWebLinkResourcePropsV130 = { windowFeatures?: string; }; -export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource { +export class CommonCartridgeWebLinkResourceV130 + extends CommonCartridgeBase + implements CommonCartridgeOrganization, CommonCartridgeResource +{ constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV130) { super(props); } + public isResource(): boolean { + return true; + } + + public getManifestOrganizationXmlObject(): XmlObject { + return { + $: { + identifier: createIdentifier(), + identifierref: this.props.identifier, + }, + title: this.props.title, + }; + } + + public getManifestResourceXmlObject(): XmlObject { + return { + $: { + identifier: this.props.identifier, + type: 'imswl_xmlv1p3', + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } + public canInline(): boolean { return false; } @@ -50,18 +81,4 @@ export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - - public getManifestXmlObject(): XmlObject { - return { - $: { - identifier: this.props.identifier, - type: 'imswl_xmlv1p3', - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } } From 910754b5907f2de6295199132a2ffcf506f22217 Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Tue, 14 May 2024 15:46:54 +0200 Subject: [PATCH 24/46] EW-793 working on --- .../export/common-cartridge.guard.ts | 10 ++-- .../common-cartridge-metadata-element.ts | 4 +- .../common-cartridge-organization-element.ts | 52 ++++++------------ ...cartridge-organizations-wrapper-element.ts | 7 ++- ...mon-cartridge-resources-wrapper-element.ts | 4 +- .../common-cartridge-metadata-element.ts | 4 +- .../common-cartridge-organization-element.ts | 55 +++++++++---------- ...cartridge-organizations-wrapper-element.ts | 7 ++- ...mon-cartridge-resources-wrapper-element.ts | 4 +- .../common-cartridge-base.interface.ts | 18 ------ 10 files changed, 67 insertions(+), 98 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts index 1a3ad075cb3..593cec3a515 100644 --- a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts +++ b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts @@ -1,5 +1,5 @@ import { IntendedUseNotSupportedLoggableException } from './errors'; -import { CommonCartridgeResource } from './interfaces'; +import { CommonCartridgeOrganization, CommonCartridgeResource } from './interfaces'; export class CommonCartridgeGuard { public static checkIntendedUse(intendedUse: string, supportedIntendedUses: string[]): void { @@ -8,9 +8,11 @@ export class CommonCartridgeGuard { } } - public static isResource(element: unknown): element is CommonCartridgeResource { - const result = element instanceof CommonCartridgeResource; + public static isResource(element: object): element is CommonCartridgeResource { + throw new Error('Method not implemented.'); + } - return result; + public static isOrganization(element: object): element is CommonCartridgeOrganization { + throw new Error('Method not implemented.'); } } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts index 217eb9639ab..106cfbad275 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeMetadataElementPropsV110 = { type: CommonCartridgeElementType.METADATA; @@ -9,7 +9,7 @@ export type CommonCartridgeMetadataElementPropsV110 = { copyrightOwners: string[]; }; -export class CommonCartridgeMetadataElementV110 extends CommonCartridgeElement { +export class CommonCartridgeMetadataElementV110 extends CommonCartridgeBase implements CommonCartridgeElement { constructor(private readonly props: CommonCartridgeMetadataElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts index bf12a1e95a9..89eb8f2b191 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts @@ -1,66 +1,48 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeGuard } from '../../common-cartridge.guard'; -import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; -import { createIdentifier } from '../../utils'; +import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION; version: CommonCartridgeVersion; identifier: string; title: string; - items: CommonCartridgeResource | Array; + items: + | (CommonCartridgeBase & CommonCartridgeOrganization & CommonCartridgeResource) + | Array; }; -export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeElement { +export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeBase implements CommonCartridgeOrganization { constructor(protected readonly props: CommonCartridgeOrganizationElementPropsV110) { super(props); } + public isResource(): boolean { + return false; + } + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): XmlObject { - const xmlObject = CommonCartridgeGuard.isResource(this.props.items) - ? this.getManifestXmlObjectForResource(this.props.items) - : this.getManifestXmlObjectForResourceCollection(this.props.items); + public getManifestOrganizationXmlObject(): XmlObject { + const xmlObject = Array.isArray(this.props.items) + ? this.getManifestXmlObjectForMany(this.props.items) + : this.props.items.getManifestOrganizationXmlObject(); return xmlObject; } - private getManifestXmlObjectForResource(item: CommonCartridgeResource): XmlObject { - const xmlObject = { - $: { - identifier: this.identifier, - identifierref: item.identifier, - }, - title: this.title, - }; - - return xmlObject; + public getManifestResourceXmlObject(): XmlObject { + throw new Error('CommonCartridgeOrganizationElementV110 does not support getManifestResourceXmlObject'); } - private getManifestXmlObjectForResourceCollection( - items: (CommonCartridgeElement | CommonCartridgeResource)[] - ): XmlObject { + private getManifestXmlObjectForMany(items: Array): XmlObject { const xmlObject = { $: { identifier: this.identifier, }, title: this.title, - item: items.map((item) => { - if (CommonCartridgeGuard.isResource(item)) { - return { - $: { - identifier: createIdentifier(), - identifierref: item.identifier, - }, - title: item.title, - }; - } - - return item.getManifestXmlObject(); - }), + item: items.map((item) => item.getManifestOrganizationXmlObject()), }; return xmlObject; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts index d82d19f69f0..b8b7bc0c5cc 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationsWrapperElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; @@ -7,7 +7,10 @@ export type CommonCartridgeOrganizationsWrapperElementPropsV110 = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeOrganizationsWrapperElementV110 extends CommonCartridgeElement { +export class CommonCartridgeOrganizationsWrapperElementV110 + extends CommonCartridgeBase + implements CommonCartridgeElement +{ constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts index 0917e906839..789304804f8 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeResourcesWrapperElementPropsV110 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; @@ -7,7 +7,7 @@ export type CommonCartridgeResourcesWrapperElementPropsV110 = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeElement { +export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeBase implements CommonCartridgeElement { constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV110) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts index 7ede15ab102..60058eb7acf 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeMetadataElementPropsV130 = { type: CommonCartridgeElementType.METADATA; @@ -9,7 +9,7 @@ export type CommonCartridgeMetadataElementPropsV130 = { copyrightOwners: string[]; }; -export class CommonCartridgeMetadataElementV130 extends CommonCartridgeElement { +export class CommonCartridgeMetadataElementV130 extends CommonCartridgeBase implements CommonCartridgeElement { constructor(private readonly props: CommonCartridgeMetadataElementPropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts index f3d9f0b3106..83e3cb5a1eb 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts @@ -1,53 +1,50 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; -import { createIdentifier } from '../../utils'; +import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATION; version: CommonCartridgeVersion; identifier: string; title: string; - items: CommonCartridgeResource | Array; + items: + | (CommonCartridgeBase & CommonCartridgeOrganization & CommonCartridgeResource) + | Array; }; -export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeElement { +export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeBase implements CommonCartridgeOrganization { constructor(private readonly props: CommonCartridgeOrganizationElementPropsV130) { super(props); } + public isResource(): boolean { + return false; + } + public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): XmlObject { - if (this.props.items instanceof CommonCartridgeResource) { - return { - $: { - identifier: this.identifier, - identifierref: this.props.items.identifier, - }, - title: this.title, - }; - } - - return { + public getManifestOrganizationXmlObject(): XmlObject { + const xmlObject = Array.isArray(this.props.items) + ? this.getManifestXmlObjectForMany(this.props.items) + : this.props.items.getManifestOrganizationXmlObject(); + + return xmlObject; + } + + public getManifestResourceXmlObject(): XmlObject { + throw new Error('CommonCartridgeOrganizationElementV130 does not support getManifestResourceXmlObject'); + } + + private getManifestXmlObjectForMany(items: Array): XmlObject { + const xmlObject = { $: { identifier: this.identifier, }, title: this.title, - item: this.props.items.map((item) => { - if (item instanceof CommonCartridgeResource) { - return { - $: { - identifier: createIdentifier(), - identifierref: item.identifier, - }, - title: item.title, - }; - } - - return item.getManifestXmlObject(); - }), + item: items.map((item) => item.getManifestOrganizationXmlObject()), }; + + return xmlObject; } } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts index bba69960e5c..edaf5f674f7 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationsWrapperElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; @@ -7,7 +7,10 @@ export type CommonCartridgeOrganizationsWrapperElementPropsV130 = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeOrganizationsWrapperElementV130 extends CommonCartridgeElement { +export class CommonCartridgeOrganizationsWrapperElementV130 + extends CommonCartridgeBase + implements CommonCartridgeElement +{ constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts index c3f3875a952..8d6b9484691 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -1,5 +1,5 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeResourcesWrapperElementPropsV130 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; @@ -7,7 +7,7 @@ export type CommonCartridgeResourcesWrapperElementPropsV130 = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeElement { +export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeBase implements CommonCartridgeElement { constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV130) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts index 63b01026467..0d9b3a21bab 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts @@ -27,21 +27,3 @@ export abstract class CommonCartridgeBase { } } } - -// export abstract class CCElement extends CCBase { -// abstract getManifestXmlObject(): XmlObject; -// } - -// export abstract class CCOrganization extends CCBase { -// abstract getManifestOrganizationXmlObject(): XmlObject; -// } - -// export abstract class CCResource extends CCOrganization { -// abstract getManifestResourceXmlObject(): XmlObject; - -// abstract canInline(): boolean; - -// abstract getFilePath(): string; - -// abstract getFileContent(): string; -// } From 87c3ae7fe20f45c9568270a4867ae8cafc936c3b Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Wed, 15 May 2024 14:44:08 +0200 Subject: [PATCH 25/46] EW-793 changing interfaces and make them more consistent --- .../builders/common-cartridge-file-builder.ts | 10 +-- .../export/common-cartridge.enums.ts | 6 +- .../export/common-cartridge.guard.ts | 9 --- .../common-cartridge-metadata-element.ts | 16 +++- .../common-cartridge-organization-element.ts | 34 ++++---- ...cartridge-organizations-wrapper-element.ts | 23 ++++-- ...mon-cartridge-resources-wrapper-element.ts | 18 ++++- .../common-cartridge-metadata-element.ts | 16 +++- .../common-cartridge-organization-element.ts | 36 ++++----- ...cartridge-organizations-wrapper-element.ts | 23 ++++-- ...mon-cartridge-resources-wrapper-element.ts | 18 ++++- .../common-cartridge-base.interface.ts | 4 +- .../common-cartridge-element.interface.ts | 6 +- ...common-cartridge-organization.interface.ts | 9 --- .../common-cartridge-resource.interface.ts | 14 ++-- .../export/interfaces/index.ts | 1 - .../common-cartridge-manifest-resource.ts | 35 +++++---- .../common-cartridge-web-content-resource.ts | 52 +++++++------ .../common-cartridge-web-link-resource.ts | 77 ++++++++++--------- .../common-cartridge-manifest-resource.ts | 17 ++-- .../common-cartridge-web-content-resource.ts | 52 +++++++------ .../common-cartridge-web-link-resource.ts | 77 ++++++++++--------- 22 files changed, 300 insertions(+), 253 deletions(-) delete mode 100644 apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-organization.interface.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts index e2b84b5a053..35e84aa7115 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.ts @@ -70,13 +70,11 @@ export class CommonCartridgeFileBuilder { resources, }); - archive.addFile('imsmanifest.xml', Buffer.from(manifest.getFileContent())); + archive.addFile(manifest.getFilePath(), Buffer.from(manifest.getFileContent())); - resources - .filter((resource) => !resource.canInline()) - .forEach((resource) => { - archive.addFile(resource.getFilePath(), Buffer.from(resource.getFileContent())); - }); + resources.forEach((resource) => { + archive.addFile(resource.getFilePath(), Buffer.from(resource.getFileContent())); + }); return archive.toBuffer(); } diff --git a/apps/server/src/modules/common-cartridge/export/common-cartridge.enums.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.enums.ts index 8e474d7c3df..183cc0f31d4 100644 --- a/apps/server/src/modules/common-cartridge/export/common-cartridge.enums.ts +++ b/apps/server/src/modules/common-cartridge/export/common-cartridge.enums.ts @@ -21,8 +21,10 @@ export enum CommonCartridgeIntendedUseType { } export enum CommonCartridgeElementType { + MANIFEST = 'manifest', METADATA = 'metadata', ORGANIZATION = 'organization', - RESOURCES_WRAPPER = 'resourceswrapper', - ORGANIZATIONS_WRAPPER = 'organizationswrapper', + ORGANIZATIONS_WRAPPER = 'organizations-wrapper', + RESOURCES_WRAPPER = 'resources-wrapper', + RESOURCE = 'resource', } diff --git a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts index 593cec3a515..2b0a012cef6 100644 --- a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts +++ b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.ts @@ -1,5 +1,4 @@ import { IntendedUseNotSupportedLoggableException } from './errors'; -import { CommonCartridgeOrganization, CommonCartridgeResource } from './interfaces'; export class CommonCartridgeGuard { public static checkIntendedUse(intendedUse: string, supportedIntendedUses: string[]): void { @@ -7,12 +6,4 @@ export class CommonCartridgeGuard { throw new IntendedUseNotSupportedLoggableException(intendedUse); } } - - public static isResource(element: object): element is CommonCartridgeResource { - throw new Error('Method not implemented.'); - } - - public static isOrganization(element: object): element is CommonCartridgeOrganization { - throw new Error('Method not implemented.'); - } } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts index 106cfbad275..f51b842e011 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.ts @@ -1,5 +1,6 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeMetadataElementPropsV110 = { type: CommonCartridgeElementType.METADATA; @@ -9,7 +10,7 @@ export type CommonCartridgeMetadataElementPropsV110 = { copyrightOwners: string[]; }; -export class CommonCartridgeMetadataElementV110 extends CommonCartridgeBase implements CommonCartridgeElement { +export class CommonCartridgeMetadataElementV110 extends CommonCartridgeElement { constructor(private readonly props: CommonCartridgeMetadataElementPropsV110) { super(props); } @@ -18,7 +19,16 @@ export class CommonCartridgeMetadataElementV110 extends CommonCartridgeBase impl return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): XmlObject { + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.METADATA: + return this.getManifestMetadataXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + private getManifestMetadataXmlObjectInternal() { return { schema: 'IMS Common Cartridge', schemaversion: '1.1.0', diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts index 89eb8f2b191..215f68d7a38 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.ts @@ -1,48 +1,48 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATION; version: CommonCartridgeVersion; identifier: string; title: string; - items: - | (CommonCartridgeBase & CommonCartridgeOrganization & CommonCartridgeResource) - | Array; + items: CommonCartridgeResource | Array; }; -export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeBase implements CommonCartridgeOrganization { +export class CommonCartridgeOrganizationElementV110 extends CommonCartridgeElement { constructor(protected readonly props: CommonCartridgeOrganizationElementPropsV110) { super(props); } - public isResource(): boolean { - return false; - } - public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - public getManifestOrganizationXmlObject(): XmlObject { + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.ORGANIZATION: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + private getManifestXmlObjectInternal(): XmlObject { const xmlObject = Array.isArray(this.props.items) ? this.getManifestXmlObjectForMany(this.props.items) - : this.props.items.getManifestOrganizationXmlObject(); + : this.props.items.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION); return xmlObject; } - public getManifestResourceXmlObject(): XmlObject { - throw new Error('CommonCartridgeOrganizationElementV110 does not support getManifestResourceXmlObject'); - } - - private getManifestXmlObjectForMany(items: Array): XmlObject { + private getManifestXmlObjectForMany(items: Array): XmlObject { const xmlObject = { $: { identifier: this.identifier, }, title: this.title, - item: items.map((item) => item.getManifestOrganizationXmlObject()), + item: items.map((item) => item.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION)), }; return xmlObject; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts index b8b7bc0c5cc..6262025ec4e 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts @@ -1,5 +1,6 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationsWrapperElementPropsV110 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; @@ -7,10 +8,7 @@ export type CommonCartridgeOrganizationsWrapperElementPropsV110 = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeOrganizationsWrapperElementV110 - extends CommonCartridgeBase - implements CommonCartridgeElement -{ +export class CommonCartridgeOrganizationsWrapperElementV110 extends CommonCartridgeElement { constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV110) { super(props); } @@ -19,7 +17,16 @@ export class CommonCartridgeOrganizationsWrapperElementV110 return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): XmlObject { + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.ORGANIZATIONS_WRAPPER: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + private getManifestXmlObjectInternal(): XmlObject { return { organization: [ { @@ -32,7 +39,9 @@ export class CommonCartridgeOrganizationsWrapperElementV110 $: { identifier: 'LearningModules', }, - item: this.props.items.map((items) => items.getManifestXmlObject()), + item: this.props.items.map((items) => + items.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION) + ), }, ], }, diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts index 789304804f8..d5f4939ff8b 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -1,5 +1,6 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeResourcesWrapperElementPropsV110 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; @@ -7,7 +8,7 @@ export type CommonCartridgeResourcesWrapperElementPropsV110 = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeBase implements CommonCartridgeElement { +export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeElement { constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV110) { super(props); } @@ -16,11 +17,20 @@ export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeB return CommonCartridgeVersion.V_1_1_0; } - public getManifestXmlObject(): XmlObject { + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCES_WRAPPER: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + private getManifestXmlObjectInternal(): XmlObject { return { resources: [ { - resource: this.props.items.map((items) => items.getManifestXmlObject()), + resource: this.props.items.map((items) => items.getManifestXmlObject(CommonCartridgeElementType.RESOURCE)), }, ], }; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts index 60058eb7acf..f7503c779dc 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.ts @@ -1,5 +1,6 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeMetadataElementPropsV130 = { type: CommonCartridgeElementType.METADATA; @@ -9,7 +10,7 @@ export type CommonCartridgeMetadataElementPropsV130 = { copyrightOwners: string[]; }; -export class CommonCartridgeMetadataElementV130 extends CommonCartridgeBase implements CommonCartridgeElement { +export class CommonCartridgeMetadataElementV130 extends CommonCartridgeElement { constructor(private readonly props: CommonCartridgeMetadataElementPropsV130) { super(props); } @@ -18,7 +19,16 @@ export class CommonCartridgeMetadataElementV130 extends CommonCartridgeBase impl return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): XmlObject { + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.METADATA: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + private getManifestXmlObjectInternal(): XmlObject { return { schema: 'IMS Common Cartridge', schemaversion: '1.3.0', diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts index 83e3cb5a1eb..9c71e8b3e29 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.ts @@ -1,48 +1,48 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATION; version: CommonCartridgeVersion; identifier: string; title: string; - items: - | (CommonCartridgeBase & CommonCartridgeOrganization & CommonCartridgeResource) - | Array; + items: CommonCartridgeResource | Array; }; -export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeBase implements CommonCartridgeOrganization { +export class CommonCartridgeOrganizationElementV130 extends CommonCartridgeElement { constructor(private readonly props: CommonCartridgeOrganizationElementPropsV130) { super(props); } - public isResource(): boolean { - return false; - } - public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - public getManifestOrganizationXmlObject(): XmlObject { + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.ORGANIZATION: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + public getManifestXmlObjectInternal(): XmlObject { const xmlObject = Array.isArray(this.props.items) - ? this.getManifestXmlObjectForMany(this.props.items) - : this.props.items.getManifestOrganizationXmlObject(); + ? this.getManifestXmlObjectForCollection(this.props.items) + : this.props.items.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION); return xmlObject; } - public getManifestResourceXmlObject(): XmlObject { - throw new Error('CommonCartridgeOrganizationElementV130 does not support getManifestResourceXmlObject'); - } - - private getManifestXmlObjectForMany(items: Array): XmlObject { + private getManifestXmlObjectForCollection(items: Array): XmlObject { const xmlObject = { $: { identifier: this.identifier, }, title: this.title, - item: items.map((item) => item.getManifestOrganizationXmlObject()), + item: items.map((item) => item.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION)), }; return xmlObject; diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts index edaf5f674f7..20146198b18 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts @@ -1,5 +1,6 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeOrganizationsWrapperElementPropsV130 = { type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; @@ -7,10 +8,7 @@ export type CommonCartridgeOrganizationsWrapperElementPropsV130 = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeOrganizationsWrapperElementV130 - extends CommonCartridgeBase - implements CommonCartridgeElement -{ +export class CommonCartridgeOrganizationsWrapperElementV130 extends CommonCartridgeElement { constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV130) { super(props); } @@ -19,7 +17,16 @@ export class CommonCartridgeOrganizationsWrapperElementV130 return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): XmlObject { + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.ORGANIZATIONS_WRAPPER: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + private getManifestXmlObjectInternal(): XmlObject { return { organization: [ { @@ -32,7 +39,9 @@ export class CommonCartridgeOrganizationsWrapperElementV130 $: { identifier: 'LearningModules', }, - item: this.props.items.map((items) => items.getManifestXmlObject()), + item: this.props.items.map((items) => + items.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION) + ), }, ], }, diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts index 8d6b9484691..98826911e2b 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -1,5 +1,6 @@ import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; export type CommonCartridgeResourcesWrapperElementPropsV130 = { type: CommonCartridgeElementType.RESOURCES_WRAPPER; @@ -7,7 +8,7 @@ export type CommonCartridgeResourcesWrapperElementPropsV130 = { items: CommonCartridgeElement[]; }; -export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeBase implements CommonCartridgeElement { +export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeElement { constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV130) { super(props); } @@ -16,11 +17,20 @@ export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeB return CommonCartridgeVersion.V_1_3_0; } - public getManifestXmlObject(): XmlObject { + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCES_WRAPPER: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + private getManifestXmlObjectInternal(): XmlObject { return { resources: [ { - resource: this.props.items.map((items) => items.getManifestXmlObject()), + resource: this.props.items.map((items) => items.getManifestXmlObject(CommonCartridgeElementType.RESOURCE)), }, ], }; diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts index 0d9b3a21bab..33c438b835f 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts @@ -1,13 +1,13 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; -type CCBaseProps = { +type CommonCartridgeBaseProps = { version: CommonCartridgeVersion; identifier?: string; title?: string; }; export abstract class CommonCartridgeBase { - protected constructor(public readonly baseProps: CCBaseProps) { + protected constructor(public readonly baseProps: CommonCartridgeBaseProps) { this.checkVersion(baseProps.version); } diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts index 28ed473f305..dae8a1ecf78 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-element.interface.ts @@ -1,12 +1,14 @@ +import { CommonCartridgeElementType } from '../common-cartridge.enums'; +import { CommonCartridgeBase } from './common-cartridge-base.interface'; import { XmlObject } from './xml-object.interface'; /** * Every element which should be listed in the Common Cartridge manifest must implement this interface. */ -export interface CommonCartridgeElement { +export abstract class CommonCartridgeElement extends CommonCartridgeBase { /** * This method is used to build the imsmanifest.xml file. * @returns The XML object representation for the imsmanifest.xml file. */ - getManifestXmlObject(): XmlObject; + abstract getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject; } diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-organization.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-organization.interface.ts deleted file mode 100644 index f21f921f38b..00000000000 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-organization.interface.ts +++ /dev/null @@ -1,9 +0,0 @@ -import { XmlObject } from './xml-object.interface'; - -export interface CommonCartridgeOrganization { - isResource(): boolean; - - getManifestOrganizationXmlObject(): XmlObject; - - getManifestResourceXmlObject(): XmlObject; -} diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts index 2df03fcb71e..b75b3524d06 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-resource.interface.ts @@ -1,22 +1,18 @@ +import { CommonCartridgeElement } from './common-cartridge-element.interface'; + /** * Every resource which should be added to the Common Cartridge archive must implement this interface. */ -export interface CommonCartridgeResource { - /** - * In later Common Cartridge versions, resources can be inlined in the imsmanifest.xml file. - * @returns true if the resource can be inlined, otherwise false. - */ - canInline(): boolean; - +export abstract class CommonCartridgeResource extends CommonCartridgeElement { /** * This method is used to determine the path of the resource in the Common Cartridge archive. * @returns The path of the resource in the Common Cartridge archive. */ - getFilePath(): string; + abstract getFilePath(): string; /** * This method is used to get the content of the resource. * @returns The content of the resource. */ - getFileContent(): string; + abstract getFileContent(): string; } diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts index 32785be421e..1f5d4394c4d 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/index.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/index.ts @@ -1,5 +1,4 @@ export { CommonCartridgeBase } from './common-cartridge-base.interface'; export { CommonCartridgeElement } from './common-cartridge-element.interface'; -export { CommonCartridgeOrganization } from './common-cartridge-organization.interface'; export { CommonCartridgeResource } from './common-cartridge-resource.interface'; export { XmlObject } from './xml-object.interface'; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts index 48ae687ea16..1f597492d03 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.ts @@ -4,7 +4,8 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; -import { CommonCartridgeBase, CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV110 = { @@ -16,16 +17,22 @@ export type CommonCartridgeManifestResourcePropsV110 = { resources: CommonCartridgeElement[]; }; -export class CommonCartridgeManifestResourceV110 - extends CommonCartridgeBase - implements CommonCartridgeElement, CommonCartridgeResource -{ +export class CommonCartridgeManifestResourceV110 extends CommonCartridgeResource { constructor(private readonly props: CommonCartridgeManifestResourcePropsV110) { super(props); } - public canInline(): boolean { - return false; + public getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.MANIFEST: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } } public getFilePath(): string { @@ -33,14 +40,10 @@ export class CommonCartridgeManifestResourceV110 } public getFileContent(): string { - return buildXmlString(this.getManifestXmlObject()); - } - - public getSupportedVersion(): CommonCartridgeVersion { - return CommonCartridgeVersion.V_1_1_0; + return buildXmlString(this.getManifestXmlObjectInternal()); } - public getManifestXmlObject(): XmlObject { + private getManifestXmlObjectInternal(): XmlObject { return { manifest: { $: { @@ -54,17 +57,17 @@ export class CommonCartridgeManifestResourceV110 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/manifest https://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lommanifest_v1p0.xsd ' + 'http://ltsc.ieee.org/xsd/imsccv1p1/LOM/resource https://www.imsglobal.org/profile/cc/ccv1p1/LOM/ccv1p1_lomresource_v1p0.xsd', }, - metadata: this.props.metadata.getManifestXmlObject(), + metadata: this.props.metadata.getManifestXmlObject(CommonCartridgeElementType.METADATA), organizations: CommonCartridgeElementFactory.createElement({ type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: this.props.version, items: this.props.organizations, - }).getManifestXmlObject(), + }).getManifestXmlObject(CommonCartridgeElementType.ORGANIZATIONS_WRAPPER), ...CommonCartridgeElementFactory.createElement({ type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: this.props.version, items: this.props.resources, - }).getManifestXmlObject(), + }).getManifestXmlObject(CommonCartridgeElementType.RESOURCES_WRAPPER), }, }; } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts index 162c8230d37..e097a707960 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -1,10 +1,12 @@ import { + CommonCartridgeElementType, CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeGuard } from '../../common-cartridge.guard'; -import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; import { createIdentifier } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV110 = { @@ -17,10 +19,7 @@ export type CommonCartridgeWebContentResourcePropsV110 = { intendedUse: CommonCartridgeIntendedUseType; }; -export class CommonCartridgeWebContentResourceV110 - extends CommonCartridgeBase - implements CommonCartridgeOrganization, CommonCartridgeResource -{ +export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResource { private static readonly SUPPORTED_INTENDED_USES = [ CommonCartridgeIntendedUseType.LESSON_PLAN, CommonCartridgeIntendedUseType.SYLLABUS, @@ -35,11 +34,30 @@ export class CommonCartridgeWebContentResourceV110 ); } - public isResource(): boolean { - return true; + public getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; + } + + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCE: + return this.getManifestResourceXmlObject(); + case CommonCartridgeElementType.ORGANIZATION: + return this.getManifestOrganizationXmlObject(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } } - public getManifestOrganizationXmlObject(): XmlObject { + public getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.html`; + } + + public getFileContent(): string { + return this.props.html; + } + + private getManifestOrganizationXmlObject(): XmlObject { return { $: { identifier: createIdentifier(), @@ -49,7 +67,7 @@ export class CommonCartridgeWebContentResourceV110 }; } - public getManifestResourceXmlObject(): XmlObject { + private getManifestResourceXmlObject(): XmlObject { return { $: { identifier: this.props.identifier, @@ -63,20 +81,4 @@ export class CommonCartridgeWebContentResourceV110 }, }; } - - public canInline(): boolean { - return false; - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.html`; - } - - public getFileContent(): string { - return this.props.html; - } - - public getSupportedVersion(): CommonCartridgeVersion { - return CommonCartridgeVersion.V_1_1_0; - } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts index 4c438e6558a..b6fd594de7d 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.ts @@ -1,5 +1,10 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString, createIdentifier } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV110 = { @@ -13,44 +18,24 @@ export type CommonCartridgeWebLinkResourcePropsV110 = { windowFeatures?: string; }; -export class CommonCartridgeWebLinkResourceV110 - extends CommonCartridgeBase - implements CommonCartridgeOrganization, CommonCartridgeResource -{ +export class CommonCartridgeWebLinkResourceV110 extends CommonCartridgeResource { constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV110) { super(props); } - public isResource(): boolean { - return true; - } - - public getManifestOrganizationXmlObject(): XmlObject { - return { - $: { - identifier: createIdentifier(), - identifierref: this.props.identifier, - }, - title: this.props.title, - }; - } - - public getManifestResourceXmlObject(): XmlObject { - return { - $: { - identifier: this.props.identifier, - type: 'imswl_xmlv1p1', - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; + public getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_1_0; } - public canInline(): boolean { - return false; + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCE: + return this.getManifestResourceXmlObject(); + case CommonCartridgeElementType.ORGANIZATION: + return this.getManifestOrganizationXmlObject(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } } public getFilePath(): string { @@ -78,7 +63,27 @@ export class CommonCartridgeWebLinkResourceV110 }); } - public getSupportedVersion(): CommonCartridgeVersion { - return CommonCartridgeVersion.V_1_1_0; + private getManifestOrganizationXmlObject(): XmlObject { + return { + $: { + identifier: createIdentifier(), + identifierref: this.identifier, + }, + title: this.title, + }; + } + + private getManifestResourceXmlObject(): XmlObject { + return { + $: { + identifier: this.identifier, + type: 'imswl_xmlv1p1', + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts index 0e68762b60e..74795a670a4 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -7,7 +7,7 @@ import { CommonCartridgeOrganizationsWrapperElementV130, CommonCartridgeResourcesWrapperElementV130, } from '../../elements/v1.3.0'; -import { CommonCartridgeBase, CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString } from '../../utils'; export type CommonCartridgeManifestResourcePropsV130 = { @@ -19,18 +19,11 @@ export type CommonCartridgeManifestResourcePropsV130 = { resources: CommonCartridgeElement[]; }; -export class CommonCartridgeManifestResourceV130 - extends CommonCartridgeBase - implements CommonCartridgeElement, CommonCartridgeResource -{ +export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource { constructor(private readonly props: CommonCartridgeManifestResourcePropsV130) { super(props); } - public canInline(): boolean { - return false; - } - public getFilePath(): string { return 'imsmanifest.xml'; } @@ -57,17 +50,17 @@ export class CommonCartridgeManifestResourceV130 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/manifest https://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lommanifest_v1p0.xsd ' + 'http://ltsc.ieee.org/xsd/imsccv1p3/LOM/resource https://www.imsglobal.org/profile/cc/ccv1p3/LOM/ccv1p3_lomresource_v1p0.xsd', }, - metadata: this.props.metadata.getManifestXmlObject(), + metadata: this.props.metadata.getManifestXmlObject(CommonCartridgeElementType.METADATA), organizations: new CommonCartridgeOrganizationsWrapperElementV130({ type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER, version: this.props.version, items: this.props.organizations, - }).getManifestXmlObject(), + }).getManifestXmlObject(CommonCartridgeElementType.ORGANIZATIONS_WRAPPER), ...new CommonCartridgeResourcesWrapperElementV130({ type: CommonCartridgeElementType.RESOURCES_WRAPPER, version: this.props.version, items: this.props.resources, - }).getManifestXmlObject(), + }).getManifestXmlObject(CommonCartridgeElementType.RESOURCES_WRAPPER), }, }; } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts index 00d9d5cfeed..21aa09a0a2d 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -1,10 +1,12 @@ import { + CommonCartridgeElementType, CommonCartridgeIntendedUseType, CommonCartridgeResourceType, CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeGuard } from '../../common-cartridge.guard'; -import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; import { createIdentifier } from '../../utils'; export type CommonCartridgeWebContentResourcePropsV130 = { @@ -17,10 +19,7 @@ export type CommonCartridgeWebContentResourcePropsV130 = { intendedUse: CommonCartridgeIntendedUseType; }; -export class CommonCartridgeWebContentResourceV130 - extends CommonCartridgeBase - implements CommonCartridgeOrganization, CommonCartridgeResource -{ +export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResource { private static readonly SUPPORTED_INTENDED_USES = [ CommonCartridgeIntendedUseType.ASSIGNMENT, CommonCartridgeIntendedUseType.LESSON_PLAN, @@ -36,11 +35,30 @@ export class CommonCartridgeWebContentResourceV130 ); } - public isResource(): boolean { - return true; + public getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; + } + + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCE: + return this.getManifestResourceXmlObject(); + case CommonCartridgeElementType.ORGANIZATION: + return this.getManifestOrganizationXmlObject(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } } - public getManifestOrganizationXmlObject(): XmlObject { + public getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.html`; + } + + public getFileContent(): string { + return this.props.html; + } + + private getManifestOrganizationXmlObject(): XmlObject { return { $: { identifier: createIdentifier(), @@ -50,7 +68,7 @@ export class CommonCartridgeWebContentResourceV130 }; } - public getManifestResourceXmlObject(): XmlObject { + private getManifestResourceXmlObject(): XmlObject { return { $: { identifier: this.props.identifier, @@ -64,20 +82,4 @@ export class CommonCartridgeWebContentResourceV130 }, }; } - - public canInline(): boolean { - return false; - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.html`; - } - - public getFileContent(): string { - return this.props.html; - } - - public getSupportedVersion(): CommonCartridgeVersion { - return CommonCartridgeVersion.V_1_3_0; - } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts index cd2f561650a..eb5d66ad8eb 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.ts @@ -1,5 +1,10 @@ -import { CommonCartridgeResourceType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeBase, CommonCartridgeOrganization, CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { + CommonCartridgeElementType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString, createIdentifier } from '../../utils'; export type CommonCartridgeWebLinkResourcePropsV130 = { @@ -13,44 +18,24 @@ export type CommonCartridgeWebLinkResourcePropsV130 = { windowFeatures?: string; }; -export class CommonCartridgeWebLinkResourceV130 - extends CommonCartridgeBase - implements CommonCartridgeOrganization, CommonCartridgeResource -{ +export class CommonCartridgeWebLinkResourceV130 extends CommonCartridgeResource { constructor(private readonly props: CommonCartridgeWebLinkResourcePropsV130) { super(props); } - public isResource(): boolean { - return true; - } - - public getManifestOrganizationXmlObject(): XmlObject { - return { - $: { - identifier: createIdentifier(), - identifierref: this.props.identifier, - }, - title: this.props.title, - }; - } - - public getManifestResourceXmlObject(): XmlObject { - return { - $: { - identifier: this.props.identifier, - type: 'imswl_xmlv1p3', - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; + public getSupportedVersion(): CommonCartridgeVersion { + return CommonCartridgeVersion.V_1_3_0; } - public canInline(): boolean { - return false; + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCE: + return this.getManifestResourceXmlObject(); + case CommonCartridgeElementType.ORGANIZATION: + return this.getManifestOrganizationXmlObject(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } } public getFilePath(): string { @@ -78,7 +63,27 @@ export class CommonCartridgeWebLinkResourceV130 }); } - public getSupportedVersion(): CommonCartridgeVersion { - return CommonCartridgeVersion.V_1_3_0; + private getManifestOrganizationXmlObject(): XmlObject { + return { + $: { + identifier: createIdentifier(), + identifierref: this.props.identifier, + }, + title: this.props.title, + }; + } + + private getManifestResourceXmlObject(): XmlObject { + return { + $: { + identifier: this.props.identifier, + type: 'imswl_xmlv1p3', + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; } } From 9f5b932ea1f184e42641ae49ff8c9740bf0029e1 Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Thu, 16 May 2024 14:02:18 +0200 Subject: [PATCH 26/46] EW-793 updating tests --- .../export/common-cartridge.guard.spec.ts | 40 ----------- .../common-cartridge-metadata-element.spec.ts | 30 ++++++-- ...mon-cartridge-organization-element.spec.ts | 39 ++++++---- ...idge-organizations-wrapper-element.spec.ts | 30 ++++++-- ...artridge-resources-wrapper-element.spec.ts | 28 ++++++-- .../common-cartridge-metadata-element.spec.ts | 31 ++++++-- ...mon-cartridge-organization-element.spec.ts | 37 ++++++---- ...idge-organizations-wrapper-element.spec.ts | 28 ++++++-- ...artridge-resources-wrapper-element.spec.ts | 28 ++++++-- .../common-cartridge-base.interface.ts | 3 +- ...common-cartridge-manifest-resource.spec.ts | 25 +++---- ...mon-cartridge-web-content-resource.spec.ts | 70 +++++++++++------- ...common-cartridge-web-link-resource.spec.ts | 67 +++++++++++------ ...common-cartridge-manifest-resource.spec.ts | 25 +++---- ...mon-cartridge-web-content-resource.spec.ts | 70 +++++++++++------- ...common-cartridge-web-link-resource.spec.ts | 72 ++++++++++++------- 16 files changed, 388 insertions(+), 235 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts index 559470b9b1f..0739b6307b3 100644 --- a/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/common-cartridge.guard.spec.ts @@ -1,8 +1,4 @@ -import { createCommonCartridgeMetadataElementPropsV110 } from '../testing/common-cartridge-element-props.factory'; -import { createCommonCartridgeWeblinkResourcePropsV110 } from '../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeGuard } from './common-cartridge.guard'; -import { CommonCartridgeElementFactory } from './elements/common-cartridge-element-factory'; -import { CommonCartridgeResourceFactory } from './resources/common-cartridge-resource-factory'; describe('CommonCartridgeGuard', () => { describe('checkIntendedUse', () => { @@ -30,40 +26,4 @@ describe('CommonCartridgeGuard', () => { }); }); }); - - describe('isResource', () => { - describe('when element is a resource', () => { - const setup = () => { - const props = createCommonCartridgeWeblinkResourcePropsV110(); - const element = CommonCartridgeResourceFactory.createResource(props); - - return { element }; - }; - - it('should return true', () => { - const { element } = setup(); - - const result = CommonCartridgeGuard.isResource(element); - - expect(result).toBe(true); - }); - }); - - describe('when element is not a resource', () => { - const setup = () => { - const props = createCommonCartridgeMetadataElementPropsV110(); - const element = CommonCartridgeElementFactory.createElement(props); - - return { element }; - }; - - it('should return false', () => { - const { element } = setup(); - - const result = CommonCartridgeGuard.isResource(element); - - expect(result).toBe(false); - }); - }); - }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts index cd12efa1590..1ab4e0421c4 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-metadata-element.spec.ts @@ -1,6 +1,6 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeMetadataElementPropsV110 } from '../../../testing/common-cartridge-element-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeMetadataElementV110 } from './common-cartridge-metadata-element'; describe('CommonCartridgeMetadataElementV110', () => { @@ -27,13 +27,15 @@ describe('CommonCartridgeMetadataElementV110', () => { notSupportedProps.version = CommonCartridgeVersion.V_1_3_0; it('should throw error', () => { - expect(() => new CommonCartridgeMetadataElementV110(notSupportedProps)).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeMetadataElementV110(notSupportedProps)).toThrow( + VersionNotSupportedLoggableException + ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using Common Cartridge version 1.1', () => { + describe('when creating metadata xml object', () => { const setup = () => { const props = createCommonCartridgeMetadataElementPropsV110(); const sut = new CommonCartridgeMetadataElementV110(props); @@ -41,10 +43,10 @@ describe('CommonCartridgeMetadataElementV110', () => { return { sut, props }; }; - it('should return correct manifest xml object', () => { + it('should return metadata manifest fragment', () => { const { sut, props } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.METADATA); expect(result).toStrictEqual({ schema: 'IMS Common Cartridge', @@ -67,5 +69,21 @@ describe('CommonCartridgeMetadataElementV110', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeMetadataElementPropsV110(); + const sut = new CommonCartridgeMetadataElementV110(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts index 8e1be0c920f..f42cc140d5d 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organization-element.spec.ts @@ -1,7 +1,7 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeOrganizationElementPropsV110 } from '../../../testing/common-cartridge-element-props.factory'; import { createCommonCartridgeWeblinkResourcePropsV110 } from '../../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationElementV110 } from './common-cartridge-organization-element'; @@ -31,25 +31,20 @@ describe('CommonCartridgeOrganizationElementV110', () => { it('should throw error', () => { expect(() => new CommonCartridgeOrganizationElementV110(notSupportedProps)).toThrowError( - InternalServerErrorException + VersionNotSupportedLoggableException ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using Common Cartridge version 1.1.0', () => { + describe('when creating organization xml object', () => { const setup = () => { const resourceProps = createCommonCartridgeWeblinkResourcePropsV110(); - - const subOrganization1Props = createCommonCartridgeOrganizationElementPropsV110( - CommonCartridgeResourceFactory.createResource(resourceProps) - ); - + const subOrganization1Props = createCommonCartridgeOrganizationElementPropsV110(); const subOrganization2Props = createCommonCartridgeOrganizationElementPropsV110([ CommonCartridgeResourceFactory.createResource(resourceProps), ]); - const organizationProps = createCommonCartridgeOrganizationElementPropsV110([ CommonCartridgeElementFactory.createElement(subOrganization1Props), CommonCartridgeElementFactory.createElement(subOrganization2Props), @@ -60,10 +55,10 @@ describe('CommonCartridgeOrganizationElementV110', () => { return { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps }; }; - it('should return correct manifest xml object', () => { + it('should return organization manifest fragment', () => { const { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION); expect(result).toStrictEqual({ $: { @@ -74,9 +69,9 @@ describe('CommonCartridgeOrganizationElementV110', () => { { $: { identifier: subOrganization1Props.identifier, - identifierref: resourceProps.identifier, }, title: subOrganization1Props.title, + item: [], }, { $: { @@ -97,5 +92,23 @@ describe('CommonCartridgeOrganizationElementV110', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeOrganizationElementPropsV110(); + const sut = new CommonCartridgeOrganizationElementV110(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrowError( + ElementTypeNotSupportedLoggableException + ); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts index fb5ae465a28..2efc3000a3c 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -1,9 +1,9 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeOrganizationElementPropsV110, createCommonCartridgeOrganizationsWrapperElementPropsV110, } from '../../../testing/common-cartridge-element-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationsWrapperElementV110 } from './common-cartridge-organizations-wrapper-element'; @@ -31,15 +31,15 @@ describe('CommonCartridgeOrganizationsWrapperElementV110', () => { notSupportedProps.version = CommonCartridgeVersion.V_1_3_0; it('should throw error', () => { - expect(() => new CommonCartridgeOrganizationsWrapperElementV110(notSupportedProps)).toThrowError( - InternalServerErrorException + expect(() => new CommonCartridgeOrganizationsWrapperElementV110(notSupportedProps)).toThrow( + VersionNotSupportedLoggableException ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using Common Cartridge version 1.1.0', () => { + describe('when creating organization wrapper xml object', () => { const setup = () => { const organizationProps = createCommonCartridgeOrganizationElementPropsV110(); const props = createCommonCartridgeOrganizationsWrapperElementPropsV110([ @@ -50,10 +50,10 @@ describe('CommonCartridgeOrganizationsWrapperElementV110', () => { return { sut, organizationProps }; }; - it('should return correct manifest xml object', () => { + it('should return organization wrapper manifest fragment', () => { const { sut, organizationProps } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATIONS_WRAPPER); expect(result).toStrictEqual({ organization: [ @@ -83,5 +83,21 @@ describe('CommonCartridgeOrganizationsWrapperElementV110', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeOrganizationsWrapperElementPropsV110(); + const sut = new CommonCartridgeOrganizationsWrapperElementV110(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts index 0106eefbee5..ed54df3df8e 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,7 +1,7 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeResourcesWrapperElementPropsV110 } from '../../../testing/common-cartridge-element-props.factory'; import { createCommonCartridgeWeblinkResourcePropsV110 } from '../../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeResourcesWrapperElementV110 } from './common-cartridge-resources-wrapper-element'; @@ -30,14 +30,14 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { it('should throw error', () => { expect(() => new CommonCartridgeResourcesWrapperElementV110(notSupportedProps)).toThrow( - InternalServerErrorException + VersionNotSupportedLoggableException ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using common cartridge version 1.1.0', () => { + describe('when creating resources wrapper xml object', () => { const setup = () => { const resourceProps = createCommonCartridgeWeblinkResourcePropsV110(); const props = createCommonCartridgeResourcesWrapperElementPropsV110([ @@ -48,10 +48,10 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { return { sut, resourceProps }; }; - it('should return correct manifest xml object', () => { + it('should return resources wrapper manifest fragment', () => { const { sut, resourceProps } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.RESOURCES_WRAPPER); expect(result).toStrictEqual({ resources: [ @@ -74,5 +74,21 @@ describe('CommonCartridgeResourcesWrapperElementV110', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeResourcesWrapperElementPropsV110(); + const sut = new CommonCartridgeResourcesWrapperElementV110(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts index 698b3efea04..e672a08d3d2 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-metadata-element.spec.ts @@ -1,6 +1,6 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeMetadataElementPropsV130 } from '../../../testing/common-cartridge-element-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeMetadataElementV130 } from './common-cartridge-metadata-element'; describe('CommonCartridgeMetadataElementV130', () => { @@ -27,13 +27,15 @@ describe('CommonCartridgeMetadataElementV130', () => { notSupportedProps.version = CommonCartridgeVersion.V_1_1_0; it('should throw error', () => { - expect(() => new CommonCartridgeMetadataElementV130(notSupportedProps)).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeMetadataElementV130(notSupportedProps)).toThrow( + VersionNotSupportedLoggableException + ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using common cartridge version 1.3', () => { + describe('when creating metadata xml object', () => { const setup = () => { const props = createCommonCartridgeMetadataElementPropsV130(); const sut = new CommonCartridgeMetadataElementV130(props); @@ -41,10 +43,10 @@ describe('CommonCartridgeMetadataElementV130', () => { return { sut, props }; }; - it('should return correct manifest xml object', () => { + it('should return metadata manifest fragment', () => { const { sut, props } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.METADATA); expect(result).toStrictEqual({ schema: 'IMS Common Cartridge', @@ -67,5 +69,22 @@ describe('CommonCartridgeMetadataElementV130', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const props = createCommonCartridgeMetadataElementPropsV130(); + const sut = new CommonCartridgeMetadataElementV130(props); + + return { sut, props }; + }; + + it('should throw error', () => { + const { sut } = setup(); + + expect(() => sut.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION)).toThrow( + ElementTypeNotSupportedLoggableException + ); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts index 73cb9b1af5a..6ada585495b 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organization-element.spec.ts @@ -1,7 +1,7 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeOrganizationElementPropsV130 } from '../../../testing/common-cartridge-element-props.factory'; import { createCommonCartridgeWeblinkResourcePropsV130 } from '../../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationElementV130 } from './common-cartridge-organization-element'; @@ -31,25 +31,20 @@ describe('CommonCartridgeOrganizationElementV130', () => { it('should throw error', () => { expect(() => new CommonCartridgeOrganizationElementV130(notSupportedProps)).toThrow( - InternalServerErrorException + VersionNotSupportedLoggableException ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using common cartridge version 1.3.0', () => { + describe('when creating organization xml object', () => { const setup = () => { const resourceProps = createCommonCartridgeWeblinkResourcePropsV130(); - - const subOrganization1Props = createCommonCartridgeOrganizationElementPropsV130( - CommonCartridgeResourceFactory.createResource(resourceProps) - ); - + const subOrganization1Props = createCommonCartridgeOrganizationElementPropsV130(); const subOrganization2Props = createCommonCartridgeOrganizationElementPropsV130([ CommonCartridgeResourceFactory.createResource(resourceProps), ]); - const organizationProps = createCommonCartridgeOrganizationElementPropsV130([ CommonCartridgeElementFactory.createElement(subOrganization1Props), CommonCartridgeElementFactory.createElement(subOrganization2Props), @@ -60,10 +55,10 @@ describe('CommonCartridgeOrganizationElementV130', () => { return { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps }; }; - it('should return correct manifest xml object', () => { + it('should return organization manifest fragment', () => { const { sut, organizationProps, subOrganization1Props, subOrganization2Props, resourceProps } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION); expect(result).toStrictEqual({ $: { @@ -74,9 +69,9 @@ describe('CommonCartridgeOrganizationElementV130', () => { { $: { identifier: subOrganization1Props.identifier, - identifierref: resourceProps.identifier, }, title: subOrganization1Props.title, + item: [], }, { $: { @@ -97,5 +92,21 @@ describe('CommonCartridgeOrganizationElementV130', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeOrganizationElementPropsV130(); + const sut = new CommonCartridgeOrganizationElementV130(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts index 47c68046764..09cccd60b72 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.spec.ts @@ -1,9 +1,9 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeOrganizationElementPropsV130, createCommonCartridgeOrganizationsWrapperElementPropsV130, } from '../../../testing/common-cartridge-element-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeElementFactory } from '../common-cartridge-element-factory'; import { CommonCartridgeOrganizationsWrapperElementV130 } from './common-cartridge-organizations-wrapper-element'; @@ -32,14 +32,14 @@ describe('CommonCartridgeOrganizationsWrapperElementV130', () => { it('should throw error', () => { expect(() => new CommonCartridgeOrganizationsWrapperElementV130(notSupportedProps)).toThrow( - InternalServerErrorException + VersionNotSupportedLoggableException ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using common cartridge version 1.3.0', () => { + describe('when creating organizations wrapper xml object', () => { const setup = () => { const organizationProps = createCommonCartridgeOrganizationElementPropsV130(); const props = createCommonCartridgeOrganizationsWrapperElementPropsV130([ @@ -50,10 +50,10 @@ describe('CommonCartridgeOrganizationsWrapperElementV130', () => { return { sut, organizationProps }; }; - it('should return correct manifest xml object', () => { + it('should return organizations wrapper manifest fragment', () => { const { sut, organizationProps } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATIONS_WRAPPER); expect(result).toStrictEqual({ organization: [ @@ -83,5 +83,21 @@ describe('CommonCartridgeOrganizationsWrapperElementV130', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeOrganizationsWrapperElementPropsV130(); + const sut = new CommonCartridgeOrganizationsWrapperElementV130(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts index 2d71adcc144..17cdf2bac31 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.spec.ts @@ -1,7 +1,7 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeResourcesWrapperElementPropsV130 } from '../../../testing/common-cartridge-element-props.factory'; import { createCommonCartridgeWeblinkResourcePropsV130 } from '../../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeResourceFactory } from '../../resources/common-cartridge-resource-factory'; import { CommonCartridgeResourcesWrapperElementV130 } from './common-cartridge-resources-wrapper-element'; @@ -30,14 +30,14 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { it('should throw error', () => { expect(() => new CommonCartridgeResourcesWrapperElementV130(notSupportedProps)).toThrowError( - InternalServerErrorException + VersionNotSupportedLoggableException ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using common cartridge version 1.3.0', () => { + describe('when creating resources wrapper xml object', () => { const setup = () => { const weblinkResourceProps = createCommonCartridgeWeblinkResourcePropsV130(); const props = createCommonCartridgeResourcesWrapperElementPropsV130([ @@ -51,7 +51,7 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { it('should return correct manifest xml object', () => { const { sut, weblinkResourceProps } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.RESOURCES_WRAPPER); expect(result).toStrictEqual({ resources: [ @@ -74,5 +74,23 @@ describe('CommonCartridgeResourcesWrapperElementV130', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeResourcesWrapperElementPropsV130(); + const sut = new CommonCartridgeResourcesWrapperElementV130(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrowError( + ElementTypeNotSupportedLoggableException + ); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts index 33c438b835f..0b768edfbc7 100644 --- a/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts +++ b/apps/server/src/modules/common-cartridge/export/interfaces/common-cartridge-base.interface.ts @@ -1,4 +1,5 @@ import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { VersionNotSupportedLoggableException } from '../errors'; type CommonCartridgeBaseProps = { version: CommonCartridgeVersion; @@ -23,7 +24,7 @@ export abstract class CommonCartridgeBase { private checkVersion(target: CommonCartridgeVersion): void { if (this.getSupportedVersion() !== target) { - throw new Error(`Version ${target} is not supported.`); + throw new VersionNotSupportedLoggableException(target); } } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index aa63bb9237f..a1aa8e728b8 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -8,27 +8,13 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; +import * as utils from '../../utils'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; describe('CommonCartridgeManifestResourceV110', () => { - describe('canInline', () => { - describe('when using Common Cartridge version 1.1.0', () => { - const setup = () => { - const props = createCommonCartridgeManifestResourcePropsV110(); - const sut = new CommonCartridgeManifestResourceV110(props); - - return { sut }; - }; - - it('should return false', () => { - const { sut } = setup(); - - const result = sut.canInline(); - - expect(result).toBe(false); - }); - }); + beforeEach(() => { + jest.clearAllMocks(); }); describe('getFilePath', () => { @@ -100,6 +86,11 @@ describe('CommonCartridgeManifestResourceV110', () => { resources: [resource1, resource2], }); + // we need this, otherwise the identifier will be random and we have to updated + // the manifest.xml file which we will compare with the expected content in the test + const mockValues = ['o1', 'o2']; + jest.spyOn(utils, 'createIdentifier').mockImplementation(() => mockValues.shift() ?? ''); + return { sut }; }; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts index 169986b451e..40ae8a4f2e1 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.spec.ts @@ -1,28 +1,9 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeWebContentResourcePropsV110 } from '../../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeWebContentResourceV110 } from './common-cartridge-web-content-resource'; describe('CommonCartridgeWebContentResourceV110', () => { - describe('canInline', () => { - describe('when using Common Cartridge version 1.1.0', () => { - const setup = () => { - const props = createCommonCartridgeWebContentResourcePropsV110(); - const sut = new CommonCartridgeWebContentResourceV110(props); - - return { sut }; - }; - - it('should return false', () => { - const { sut } = setup(); - - const result = sut.canInline(); - - expect(result).toBe(false); - }); - }); - }); - describe('getFilePath', () => { describe('when using Common Cartridge version 1.1.0', () => { const setup = () => { @@ -85,14 +66,37 @@ describe('CommonCartridgeWebContentResourceV110', () => { it('should throw error', () => { expect(() => new CommonCartridgeWebContentResourceV110(notSupportedProps)).toThrow( - InternalServerErrorException + VersionNotSupportedLoggableException ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using Common Cartridge version 1.1.0', () => { + describe('when creating organization xml object', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV110(); + const sut = new CommonCartridgeWebContentResourceV110(props); + + return { sut, props }; + }; + + it('should return organization manifest fragment', () => { + const { sut, props } = setup(); + + const result = sut.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION); + + expect(result).toEqual({ + $: { + identifier: expect.any(String), + identifierref: props.identifier, + }, + title: props.title, + }); + }); + }); + + describe('when creating resource xml object', () => { const setup = () => { const props = createCommonCartridgeWebContentResourcePropsV110(); const sut = new CommonCartridgeWebContentResourceV110(props); @@ -100,10 +104,10 @@ describe('CommonCartridgeWebContentResourceV110', () => { return { sut, props }; }; - it('should return the correct XML object', () => { + it('should return resource manifest fragment', () => { const { sut, props } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.RESOURCE); expect(result).toEqual({ $: { @@ -119,5 +123,21 @@ describe('CommonCartridgeWebContentResourceV110', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeWebContentResourcePropsV110(); + const sut = new CommonCartridgeWebContentResourceV110(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts index 79881d285f4..b697a51f871 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-link-resource.spec.ts @@ -1,29 +1,11 @@ import { InternalServerErrorException } from '@nestjs/common'; import { readFile } from 'fs/promises'; import { createCommonCartridgeWeblinkResourcePropsV110 } from '../../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeWebLinkResourceV110 } from './common-cartridge-web-link-resource'; describe('CommonCartridgeWebLinkResourceV110', () => { - describe('canInline', () => { - describe('when using Common Cartridge version 1.3.0', () => { - const setup = () => { - const props = createCommonCartridgeWeblinkResourcePropsV110(); - const sut = new CommonCartridgeWebLinkResourceV110(props); - - return { sut }; - }; - - it('should return false', () => { - const { sut } = setup(); - - const result = sut.canInline(); - - expect(result).toBe(false); - }); - }); - }); - describe('getFilePath', () => { describe('when using Common Cartridge version 1.1.0', () => { const setup = () => { @@ -99,7 +81,7 @@ describe('CommonCartridgeWebLinkResourceV110', () => { }); describe('getManifestXmlObject', () => { - describe('when using Common Cartridge version 1.1.0', () => { + describe('when creating organization xml object', () => { const setup = () => { const props = createCommonCartridgeWeblinkResourcePropsV110(); const sut = new CommonCartridgeWebLinkResourceV110(props); @@ -107,10 +89,33 @@ describe('CommonCartridgeWebLinkResourceV110', () => { return { sut, props }; }; - it('should return the manifest XML object', () => { + it('should return resource manifest fragment', () => { const { sut, props } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION); + + expect(result).toEqual({ + $: { + identifier: expect.any(String), + identifierref: props.identifier, + }, + title: props.title, + }); + }); + }); + + describe('when creating resource xml object', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV110(); + const sut = new CommonCartridgeWebLinkResourceV110(props); + + return { sut, props }; + }; + + it('should return resource manifest fragment', () => { + const { sut, props } = setup(); + + const result = sut.getManifestXmlObject(CommonCartridgeElementType.RESOURCE); expect(result).toEqual({ $: { @@ -125,5 +130,21 @@ describe('CommonCartridgeWebLinkResourceV110', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeWeblinkResourcePropsV110(); + const sut = new CommonCartridgeWebLinkResourceV110(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index f49caa016c9..1c6263de9e1 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -9,27 +9,13 @@ import { } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; import { CommonCartridgeElementFactoryV130 } from '../../elements/v1.3.0'; +import * as utils from '../../utils'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; describe('CommonCartridgeManifestResourceV130', () => { - describe('canInline', () => { - describe('when using Common Cartridge version 1.3.0', () => { - const setup = () => { - const props = createCommonCartridgeManifestResourcePropsV130(); - const sut = new CommonCartridgeManifestResourceV130(props); - - return { sut }; - }; - - it('should return false', () => { - const { sut } = setup(); - - const result = sut.canInline(); - - expect(result).toBe(false); - }); - }); + beforeEach(() => { + jest.clearAllMocks(); }); describe('getFilePath', () => { @@ -101,6 +87,11 @@ describe('CommonCartridgeManifestResourceV130', () => { resources: [resource1, resource2], }); + // we need this, otherwise the identifier will be random and we have to updated + // the manifest.xml file which we will compare with the expected content in the test + const mockValues = ['o1', 'o2']; + jest.spyOn(utils, 'createIdentifier').mockImplementation(() => mockValues.shift() ?? ''); + return { sut }; }; diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts index e1b3334fd7d..44ab6b65002 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.spec.ts @@ -1,28 +1,9 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { createCommonCartridgeWebContentResourcePropsV130 } from '../../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; describe('CommonCartridgeWebContentResourceV130', () => { - describe('canInline', () => { - describe('when using Common Cartridge version 1.3.0', () => { - const setup = () => { - const props = createCommonCartridgeWebContentResourcePropsV130(); - const sut = new CommonCartridgeWebContentResourceV130(props); - - return { sut }; - }; - - it('should return false', () => { - const { sut } = setup(); - - const result = sut.canInline(); - - expect(result).toBe(false); - }); - }); - }); - describe('getFilePath', () => { describe('when using Common Cartridge version 1.3.0', () => { const setup = () => { @@ -85,14 +66,37 @@ describe('CommonCartridgeWebContentResourceV130', () => { it('should throw error', () => { expect(() => new CommonCartridgeWebContentResourceV130(notSupportedProps)).toThrow( - InternalServerErrorException + VersionNotSupportedLoggableException ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using Common Cartridge version 1.3.0', () => { + describe('when creating organization xml object', () => { + const setup = () => { + const props = createCommonCartridgeWebContentResourcePropsV130(); + const sut = new CommonCartridgeWebContentResourceV130(props); + + return { sut, props }; + }; + + it('should return organization manifest fragment', () => { + const { sut, props } = setup(); + + const result = sut.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION); + + expect(result).toEqual({ + $: { + identifier: expect.any(String), + identifierref: props.identifier, + }, + title: props.title, + }); + }); + }); + + describe('when creating resource xml object', () => { const setup = () => { const props = createCommonCartridgeWebContentResourcePropsV130(); const sut = new CommonCartridgeWebContentResourceV130(props); @@ -100,10 +104,10 @@ describe('CommonCartridgeWebContentResourceV130', () => { return { sut, props }; }; - it('should return the manifest XML object', () => { + it('should return resource manifest fragment', () => { const { sut, props } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.RESOURCE); expect(result).toEqual({ $: { @@ -119,5 +123,21 @@ describe('CommonCartridgeWebContentResourceV130', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeWebContentResourcePropsV130(); + const sut = new CommonCartridgeWebContentResourceV130(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); }); }); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts index d6aee5e394f..83985e8f717 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-link-resource.spec.ts @@ -1,29 +1,10 @@ -import { InternalServerErrorException } from '@nestjs/common'; import { readFile } from 'node:fs/promises'; import { createCommonCartridgeWeblinkResourcePropsV130 } from '../../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException, VersionNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeWebLinkResourceV130 } from './common-cartridge-web-link-resource'; describe('CommonCartridgeWebLinkResourceV130', () => { - describe('canInline', () => { - describe('when using Common Cartridge version 1.3.0', () => { - const setup = () => { - const props = createCommonCartridgeWeblinkResourcePropsV130(); - const sut = new CommonCartridgeWebLinkResourceV130(props); - - return { sut }; - }; - - it('should return false', () => { - const { sut } = setup(); - - const result = sut.canInline(); - - expect(result).toBe(false); - }); - }); - }); - describe('getFilePath', () => { describe('when using Common Cartridge version 1.3.0', () => { const setup = () => { @@ -94,13 +75,38 @@ describe('CommonCartridgeWebLinkResourceV130', () => { notSupportedProps.version = CommonCartridgeVersion.V_1_1_0; it('should throw error', () => { - expect(() => new CommonCartridgeWebLinkResourceV130(notSupportedProps)).toThrow(InternalServerErrorException); + expect(() => new CommonCartridgeWebLinkResourceV130(notSupportedProps)).toThrow( + VersionNotSupportedLoggableException + ); }); }); }); describe('getManifestXmlObject', () => { - describe('when using Common Cartridge version 1.3.0', () => { + describe('when creating organization xml object', () => { + const setup = () => { + const props = createCommonCartridgeWeblinkResourcePropsV130(); + const sut = new CommonCartridgeWebLinkResourceV130(props); + + return { sut, props }; + }; + + it('should return organization manifest fragment', () => { + const { sut, props } = setup(); + + const result = sut.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION); + + expect(result).toEqual({ + $: { + identifier: expect.any(String), + identifierref: props.identifier, + }, + title: props.title, + }); + }); + }); + + describe('when creating resource xml object', () => { const setup = () => { const props = createCommonCartridgeWeblinkResourcePropsV130(); const sut = new CommonCartridgeWebLinkResourceV130(props); @@ -108,10 +114,10 @@ describe('CommonCartridgeWebLinkResourceV130', () => { return { sut, props }; }; - it('should return the manifest XML object', () => { + it('should return resource manifest fragment', () => { const { sut, props } = setup(); - const result = sut.getManifestXmlObject(); + const result = sut.getManifestXmlObject(CommonCartridgeElementType.RESOURCE); expect(result).toEqual({ $: { @@ -127,4 +133,20 @@ describe('CommonCartridgeWebLinkResourceV130', () => { }); }); }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeWeblinkResourcePropsV130(); + const sut = new CommonCartridgeWebLinkResourceV130(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); }); From 19dfea36dce053b79011ec505c127b6fe96fd3ea Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Thu, 16 May 2024 15:30:28 +0200 Subject: [PATCH 27/46] EW-793 working on tests --- ...common-cartridge-manifest-resource.spec.ts | 43 +++++++++++++++++++ .../common-cartridge-manifest-resource.ts | 1 + ...common-cartridge-resource-props.factory.ts | 4 +- 3 files changed, 47 insertions(+), 1 deletion(-) diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index a1aa8e728b8..b2addc34eb4 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -8,6 +8,7 @@ import { CommonCartridgeVersion, } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; import * as utils from '../../utils'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; import { CommonCartridgeManifestResourceV110 } from './common-cartridge-manifest-resource'; @@ -135,4 +136,46 @@ describe('CommonCartridgeManifestResourceV110', () => { }); }); }); + + describe('getManifestXmlObject', () => { + describe('when creating manifest xml object', () => { + const setup = () => { + const props = createCommonCartridgeManifestResourcePropsV110(); + const sut = new CommonCartridgeManifestResourceV110(props); + + return { sut }; + }; + + it('should return manifest xml object', () => { + const { sut } = setup(); + + const result = sut.getManifestXmlObject(CommonCartridgeElementType.MANIFEST); + + expect(result).toStrictEqual({ + manifest: { + $: expect.any(Object), + metadata: expect.any(Object), + organizations: expect.any(Object), + resources: expect.any(Object), + }, + }); + }); + }); + + describe('when using unsupported element type', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeManifestResourcePropsV110(); + const sut = new CommonCartridgeManifestResourceV110(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); + }); }); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts index 74795a670a4..2103232764d 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -36,6 +36,7 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource return CommonCartridgeVersion.V_1_3_0; } + // TODO: Implement this method correctly with arguments public getManifestXmlObject(): XmlObject { return { manifest: { diff --git a/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts index 8aece02d9c0..c905cd3a5a7 100644 --- a/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts @@ -5,6 +5,7 @@ import { CommonCartridgeResourceType, CommonCartridgeVersion, } from '@modules/common-cartridge'; +import { CommonCartridgeElementFactory } from '../export/elements/common-cartridge-element-factory'; import { CommonCartridgeElement } from '../export/interfaces/common-cartridge-element.interface'; import { CommonCartridgeManifestResourcePropsV110 } from '../export/resources/v1.1.0/common-cartridge-manifest-resource'; import { CommonCartridgeWebContentResourcePropsV110 } from '../export/resources/v1.1.0/common-cartridge-web-content-resource'; @@ -12,6 +13,7 @@ import { CommonCartridgeWebLinkResourcePropsV110 } from '../export/resources/v1. import { CommonCartridgeManifestResourcePropsV130 } from '../export/resources/v1.3.0/common-cartridge-manifest-resource'; import { CommonCartridgeWebContentResourcePropsV130 } from '../export/resources/v1.3.0/common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV130 } from '../export/resources/v1.3.0/common-cartridge-web-link-resource'; +import { createCommonCartridgeMetadataElementPropsV110 } from './common-cartridge-element-props.factory'; export function createCommonCartridgeWeblinkResourcePropsV110(): CommonCartridgeWebLinkResourcePropsV110 { return { @@ -64,7 +66,7 @@ export function createCommonCartridgeManifestResourcePropsV110(): CommonCartridg type: CommonCartridgeResourceType.MANIFEST, version: CommonCartridgeVersion.V_1_1_0, identifier: faker.string.uuid(), - metadata: {} as CommonCartridgeElement, + metadata: CommonCartridgeElementFactory.createElement(createCommonCartridgeMetadataElementPropsV110()), organizations: [], resources: [], }; From 73f179e1e52d25222e0763b580fe515995e5f6dc Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Fri, 17 May 2024 09:48:52 +0200 Subject: [PATCH 28/46] EW-793 adding unit tests --- ...common-cartridge-manifest-resource.spec.ts | 43 +++++++++++++++++++ .../common-cartridge-manifest-resource.ts | 15 +++++-- ...common-cartridge-resource-props.factory.ts | 8 ++-- 3 files changed, 60 insertions(+), 6 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index 1c6263de9e1..781f714899c 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -9,6 +9,7 @@ import { } from '../../common-cartridge.enums'; import { CommonCartridgeElementFactory } from '../../elements/common-cartridge-element-factory'; import { CommonCartridgeElementFactoryV130 } from '../../elements/v1.3.0'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; import * as utils from '../../utils'; import { CommonCartridgeResourceFactory } from '../common-cartridge-resource-factory'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; @@ -136,4 +137,46 @@ describe('CommonCartridgeManifestResourceV130', () => { }); }); }); + + describe('getManifestXmlObject', () => { + describe('when creating manifest xml object', () => { + const setup = () => { + const props = createCommonCartridgeManifestResourcePropsV130(); + const sut = new CommonCartridgeManifestResourceV130(props); + + return { sut }; + }; + + it('should return manifest xml object', () => { + const { sut } = setup(); + + const result = sut.getManifestXmlObject(CommonCartridgeElementType.MANIFEST); + + expect(result).toStrictEqual({ + manifest: { + $: expect.any(Object), + metadata: expect.any(Object), + organizations: expect.any(Object), + resources: expect.any(Object), + }, + }); + }); + }); + + describe('when element type is not supported', () => { + const setup = () => { + const unknownElementType = 'unknown' as CommonCartridgeElementType; + const props = createCommonCartridgeManifestResourcePropsV130(); + const sut = new CommonCartridgeManifestResourceV130(props); + + return { sut, unknownElementType }; + }; + + it('should throw error', () => { + const { sut, unknownElementType } = setup(); + + expect(() => sut.getManifestXmlObject(unknownElementType)).toThrow(ElementTypeNotSupportedLoggableException); + }); + }); + }); }); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts index 2103232764d..63f543baf07 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.ts @@ -7,6 +7,7 @@ import { CommonCartridgeOrganizationsWrapperElementV130, CommonCartridgeResourcesWrapperElementV130, } from '../../elements/v1.3.0'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeElement, CommonCartridgeResource, XmlObject } from '../../interfaces'; import { buildXmlString } from '../../utils'; @@ -29,15 +30,23 @@ export class CommonCartridgeManifestResourceV130 extends CommonCartridgeResource } public getFileContent(): string { - return buildXmlString(this.getManifestXmlObject()); + return buildXmlString(this.getManifestXmlObject(CommonCartridgeElementType.MANIFEST)); } public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - // TODO: Implement this method correctly with arguments - public getManifestXmlObject(): XmlObject { + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.MANIFEST: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + public getManifestXmlObjectInternal(): XmlObject { return { manifest: { $: { diff --git a/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts index c905cd3a5a7..af838cb5b5a 100644 --- a/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts @@ -6,14 +6,16 @@ import { CommonCartridgeVersion, } from '@modules/common-cartridge'; import { CommonCartridgeElementFactory } from '../export/elements/common-cartridge-element-factory'; -import { CommonCartridgeElement } from '../export/interfaces/common-cartridge-element.interface'; import { CommonCartridgeManifestResourcePropsV110 } from '../export/resources/v1.1.0/common-cartridge-manifest-resource'; import { CommonCartridgeWebContentResourcePropsV110 } from '../export/resources/v1.1.0/common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV110 } from '../export/resources/v1.1.0/common-cartridge-web-link-resource'; import { CommonCartridgeManifestResourcePropsV130 } from '../export/resources/v1.3.0/common-cartridge-manifest-resource'; import { CommonCartridgeWebContentResourcePropsV130 } from '../export/resources/v1.3.0/common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV130 } from '../export/resources/v1.3.0/common-cartridge-web-link-resource'; -import { createCommonCartridgeMetadataElementPropsV110 } from './common-cartridge-element-props.factory'; +import { + createCommonCartridgeMetadataElementPropsV110, + createCommonCartridgeMetadataElementPropsV130, +} from './common-cartridge-element-props.factory'; export function createCommonCartridgeWeblinkResourcePropsV110(): CommonCartridgeWebLinkResourcePropsV110 { return { @@ -77,7 +79,7 @@ export function createCommonCartridgeManifestResourcePropsV130(): CommonCartridg type: CommonCartridgeResourceType.MANIFEST, version: CommonCartridgeVersion.V_1_3_0, identifier: faker.string.uuid(), - metadata: {} as CommonCartridgeElement, + metadata: CommonCartridgeElementFactory.createElement(createCommonCartridgeMetadataElementPropsV130()), organizations: [], resources: [], }; From a193bb2a3afabb2053ed061cc2645ec46be6b7ca Mon Sep 17 00:00:00 2001 From: Patrick Sachmann <20001160+psachmann@users.noreply.github.com> Date: Fri, 17 May 2024 10:51:17 +0200 Subject: [PATCH 29/46] EW-793 fixing linter warnings --- .../v1.1.0/common-cartridge-manifest-resource.spec.ts | 8 ++++---- .../v1.3.0/common-cartridge-manifest-resource.spec.ts | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts index b2addc34eb4..129738f323f 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-manifest-resource.spec.ts @@ -153,10 +153,10 @@ describe('CommonCartridgeManifestResourceV110', () => { expect(result).toStrictEqual({ manifest: { - $: expect.any(Object), - metadata: expect.any(Object), - organizations: expect.any(Object), - resources: expect.any(Object), + $: expect.any(Object) as unknown, + metadata: expect.any(Object) as unknown, + organizations: expect.any(Object) as unknown, + resources: expect.any(Object) as unknown, }, }); }); diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts index 781f714899c..eb0bd8e5696 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-manifest-resource.spec.ts @@ -154,10 +154,10 @@ describe('CommonCartridgeManifestResourceV130', () => { expect(result).toStrictEqual({ manifest: { - $: expect.any(Object), - metadata: expect.any(Object), - organizations: expect.any(Object), - resources: expect.any(Object), + $: expect.any(Object) as unknown, + metadata: expect.any(Object) as unknown, + organizations: expect.any(Object) as unknown, + resources: expect.any(Object) as unknown, }, }); }); From ba0d2b094bfae993f0e4b57881d1936a31426430 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 24 May 2024 10:35:05 +0200 Subject: [PATCH 30/46] EW-793 Try to reduce code duplications --- .../common-cartridge-file-builder.spec.ts | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts index 308f05b2ff8..4adafc76b30 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts @@ -18,6 +18,14 @@ describe('CommonCartridgeFileBuilder', () => { identifier: faker.string.uuid(), }; + const setupProps = () => { + const metadataProps = createCommonCartridgeMetadataElementProps(); + const organizationProps = createCommonCartridgeOrganizationProps(); + const resourceProps = createCommonCartridgeWebLinkResourceProps(); + + return { metadataProps, organizationProps, resourceProps }; + }; + beforeEach(() => { sut = new CommonCartridgeFileBuilder(builderProps); jest.clearAllMocks(); @@ -44,14 +52,14 @@ describe('CommonCartridgeFileBuilder', () => { describe('createOrganization', () => { describe('when an organization is created in the CommonCartridgeFileBuilder', () => { - const setup = () => { + /* const setup = () => { const organizationProps = createCommonCartridgeOrganizationProps(); return { organizationProps }; - }; + }; */ it('should create and return an organization node', () => { - const { organizationProps } = setup(); + const { organizationProps } = setupProps(); const organizationNode = sut.createOrganization(organizationProps); @@ -70,16 +78,16 @@ describe('CommonCartridgeFileBuilder', () => { }); describe('when metadata has been provided', () => { - const setup = () => { + /* const setup = () => { const metadataProps = createCommonCartridgeMetadataElementProps(); const organizationProps = createCommonCartridgeOrganizationProps(); const resourceProps = createCommonCartridgeWebLinkResourceProps(); return { metadataProps, organizationProps, resourceProps }; }; - + */ it('should build the common cartridge file', () => { - const { metadataProps, organizationProps, resourceProps } = setup(); + const { metadataProps, organizationProps, resourceProps } = setupProps(); sut.addMetadata(metadataProps); From 1ff4491a7161ed62a0f46284c1dac6af73cc837e Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Fri, 24 May 2024 11:33:06 +0200 Subject: [PATCH 31/46] EW-793 Revert try --- .../common-cartridge-file-builder.spec.ts | 20 ++++++------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts index 4adafc76b30..308f05b2ff8 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-file-builder.spec.ts @@ -18,14 +18,6 @@ describe('CommonCartridgeFileBuilder', () => { identifier: faker.string.uuid(), }; - const setupProps = () => { - const metadataProps = createCommonCartridgeMetadataElementProps(); - const organizationProps = createCommonCartridgeOrganizationProps(); - const resourceProps = createCommonCartridgeWebLinkResourceProps(); - - return { metadataProps, organizationProps, resourceProps }; - }; - beforeEach(() => { sut = new CommonCartridgeFileBuilder(builderProps); jest.clearAllMocks(); @@ -52,14 +44,14 @@ describe('CommonCartridgeFileBuilder', () => { describe('createOrganization', () => { describe('when an organization is created in the CommonCartridgeFileBuilder', () => { - /* const setup = () => { + const setup = () => { const organizationProps = createCommonCartridgeOrganizationProps(); return { organizationProps }; - }; */ + }; it('should create and return an organization node', () => { - const { organizationProps } = setupProps(); + const { organizationProps } = setup(); const organizationNode = sut.createOrganization(organizationProps); @@ -78,16 +70,16 @@ describe('CommonCartridgeFileBuilder', () => { }); describe('when metadata has been provided', () => { - /* const setup = () => { + const setup = () => { const metadataProps = createCommonCartridgeMetadataElementProps(); const organizationProps = createCommonCartridgeOrganizationProps(); const resourceProps = createCommonCartridgeWebLinkResourceProps(); return { metadataProps, organizationProps, resourceProps }; }; - */ + it('should build the common cartridge file', () => { - const { metadataProps, organizationProps, resourceProps } = setupProps(); + const { metadataProps, organizationProps, resourceProps } = setup(); sut.addMetadata(metadataProps); From eedfeec888ee395a8c1be51833ad7592c9384795 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 27 May 2024 10:26:46 +0200 Subject: [PATCH 32/46] EW-793 Extend test factories to reduce code duplications --- ...common-cartridge-organization-node.spec.ts | 15 ++-------- ...tridge-resource-collection-builder.spec.ts | 28 ++++--------------- .../common-cartridge-resource-node.spec.ts | 16 +++-------- .../common-cartridge-node-props.factory.ts | 12 ++++++++ ...common-cartridge-resource-props.factory.ts | 10 +++++++ 5 files changed, 35 insertions(+), 46 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/testing/common-cartridge-node-props.factory.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts index ffdaaecdcbc..b4d8fd22581 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts @@ -1,22 +1,13 @@ -import { faker } from '@faker-js/faker'; import { createMock } from '@golevelup/ts-jest'; +import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-node-props.factory'; import { createCommonCartridgeWebLinkResourceProps } from '../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeElement } from '../interfaces'; -import { - CommonCartridgeOrganizationNode, - CommonCartridgeOrganizationNodeProps, -} from './common-cartridge-organization-node'; +import { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node'; import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder'; describe('CommonCartridgeOrganizationNode', () => { const setupOrganizationNodeProps = () => { - const props: CommonCartridgeOrganizationNodeProps = { - type: CommonCartridgeElementType.ORGANIZATION, - version: CommonCartridgeVersion.V_1_1_0, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - }; + const props = createCommonCartridgeOrganizationNodeProps(); return props; }; diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts index b54ed6e0b30..dd8c547876f 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts @@ -1,15 +1,8 @@ -import { faker } from '@faker-js/faker'; import { createMock } from '@golevelup/ts-jest'; -import { - CommonCartridgeElementType, - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../common-cartridge.enums'; -import { - CommonCartridgeOrganizationNode, - CommonCartridgeOrganizationNodeProps, -} from './common-cartridge-organization-node'; +import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-node-props.factory'; +import { createCommonCartridgeWebContentResourceProps } from '../../testing/common-cartridge-resource-props.factory'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node'; import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder'; import { CommonCartridgeResourceNode, CommonCartridgeResourceNodeProps } from './common-cartridge-resource-node'; @@ -18,19 +11,10 @@ describe('CommonCartridgeResourceCollectionBuilder', () => { const setupResourceNode = () => { const resourceNodeProps: CommonCartridgeResourceNodeProps = { - type: CommonCartridgeResourceType.WEB_CONTENT, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - html: faker.lorem.paragraph(), - intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + ...createCommonCartridgeWebContentResourceProps(), version: CommonCartridgeVersion.V_1_1_0, }; - const organizationNodeProps: CommonCartridgeOrganizationNodeProps = { - identifier: faker.string.uuid(), - title: faker.lorem.words(), - version: CommonCartridgeVersion.V_1_1_0, - type: CommonCartridgeElementType.ORGANIZATION, - }; + const organizationNodeProps = createCommonCartridgeOrganizationNodeProps(); const organizationNode = new CommonCartridgeOrganizationNode(organizationNodeProps, sut, null); const resourceNode = new CommonCartridgeResourceNode(resourceNodeProps, organizationNode); diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts index 5678583c6af..8fc409b48fd 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts @@ -1,11 +1,8 @@ -import { faker } from '@faker-js/faker'; +import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-node-props.factory'; import { createCommonCartridgeWebLinkResourceProps } from '../../testing/common-cartridge-resource-props.factory'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../common-cartridge.enums'; +import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeResource } from '../interfaces'; -import { - CommonCartridgeOrganizationNode, - CommonCartridgeOrganizationNodeProps, -} from './common-cartridge-organization-node'; +import { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node'; import { CommonCartridgeResourceCollectionBuilder } from './common-cartridge-resource-collection-builder'; import { CommonCartridgeResourceNode, CommonCartridgeResourceNodeProps } from './common-cartridge-resource-node'; @@ -20,12 +17,7 @@ describe('CommonCartridgeResourceNode', () => { version: CommonCartridgeVersion.V_1_1_0, }; - const organizationNodeProps: CommonCartridgeOrganizationNodeProps = { - identifier: faker.string.uuid(), - title: faker.lorem.words(), - version: CommonCartridgeVersion.V_1_1_0, - type: CommonCartridgeElementType.ORGANIZATION, - }; + const organizationNodeProps = createCommonCartridgeOrganizationNodeProps(); const resourceCollectionBuilder: CommonCartridgeResourceCollectionBuilder = new CommonCartridgeResourceCollectionBuilder(); diff --git a/apps/server/src/modules/common-cartridge/testing/common-cartridge-node-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-node-props.factory.ts new file mode 100644 index 00000000000..bffe84b1f7c --- /dev/null +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-node-props.factory.ts @@ -0,0 +1,12 @@ +import { faker } from '@faker-js/faker'; +import { CommonCartridgeOrganizationNodeProps } from '../export/builders/common-cartridge-organization-node'; +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../export/common-cartridge.enums'; + +export function createCommonCartridgeOrganizationNodeProps(): CommonCartridgeOrganizationNodeProps { + return { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + version: CommonCartridgeVersion.V_1_1_0, + }; +} diff --git a/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts index af838cb5b5a..136f0e8ac6f 100644 --- a/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-resource-props.factory.ts @@ -93,3 +93,13 @@ export function createCommonCartridgeWebLinkResourceProps(): CommonCartridgeReso url: faker.internet.url(), }; } + +export function createCommonCartridgeWebContentResourceProps(): CommonCartridgeResourceProps { + return { + type: CommonCartridgeResourceType.WEB_CONTENT, + title: faker.lorem.words(), + identifier: faker.string.uuid(), + html: faker.lorem.paragraph(), + intendedUse: CommonCartridgeIntendedUseType.UNSPECIFIED, + }; +} From 23bbc0a6917752943f7b3bd93e0b590cb8fd4bef Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 29 May 2024 10:09:30 +0200 Subject: [PATCH 33/46] EW-793 Delete node-props-factory and move method to another factory --- .../common-cartridge-organization-node.spec.ts | 2 +- ...mon-cartridge-resource-collection-builder.spec.ts | 2 +- .../builders/common-cartridge-resource-node.spec.ts | 2 +- .../common-cartridge-element-props.factory.ts | 10 ++++++++++ .../testing/common-cartridge-node-props.factory.ts | 12 ------------ 5 files changed, 13 insertions(+), 15 deletions(-) delete mode 100644 apps/server/src/modules/common-cartridge/testing/common-cartridge-node-props.factory.ts diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts index b4d8fd22581..204ae5d1685 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-organization-node.spec.ts @@ -1,5 +1,5 @@ import { createMock } from '@golevelup/ts-jest'; -import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-node-props.factory'; +import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-element-props.factory'; import { createCommonCartridgeWebLinkResourceProps } from '../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeElement } from '../interfaces'; import { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node'; diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts index dd8c547876f..c7c6d1e8020 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-collection-builder.spec.ts @@ -1,5 +1,5 @@ import { createMock } from '@golevelup/ts-jest'; -import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-node-props.factory'; +import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-element-props.factory'; import { createCommonCartridgeWebContentResourceProps } from '../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeOrganizationNode } from './common-cartridge-organization-node'; diff --git a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts index 8fc409b48fd..4cf86f6bb60 100644 --- a/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/builders/common-cartridge-resource-node.spec.ts @@ -1,4 +1,4 @@ -import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-node-props.factory'; +import { createCommonCartridgeOrganizationNodeProps } from '../../testing/common-cartridge-element-props.factory'; import { createCommonCartridgeWebLinkResourceProps } from '../../testing/common-cartridge-resource-props.factory'; import { CommonCartridgeVersion } from '../common-cartridge.enums'; import { CommonCartridgeResource } from '../interfaces'; diff --git a/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts index c6b69a6a469..f6d05b9710b 100644 --- a/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts +++ b/apps/server/src/modules/common-cartridge/testing/common-cartridge-element-props.factory.ts @@ -5,6 +5,7 @@ import { CommonCartridgeOrganizationProps, CommonCartridgeVersion, } from '@modules/common-cartridge'; +import { CommonCartridgeOrganizationNodeProps } from '../export/builders/common-cartridge-organization-node'; import { CommonCartridgeMetadataElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-metadata-element'; import { CommonCartridgeOrganizationElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-organization-element'; import { CommonCartridgeOrganizationsWrapperElementPropsV110 } from '../export/elements/v1.1.0/common-cartridge-organizations-wrapper-element'; @@ -115,3 +116,12 @@ export function createCommonCartridgeOrganizationProps(): CommonCartridgeOrganiz identifier: faker.string.uuid(), }; } + +export function createCommonCartridgeOrganizationNodeProps(): CommonCartridgeOrganizationNodeProps { + return { + type: CommonCartridgeElementType.ORGANIZATION, + identifier: faker.string.uuid(), + title: faker.lorem.words(), + version: CommonCartridgeVersion.V_1_1_0, + }; +} diff --git a/apps/server/src/modules/common-cartridge/testing/common-cartridge-node-props.factory.ts b/apps/server/src/modules/common-cartridge/testing/common-cartridge-node-props.factory.ts deleted file mode 100644 index bffe84b1f7c..00000000000 --- a/apps/server/src/modules/common-cartridge/testing/common-cartridge-node-props.factory.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { faker } from '@faker-js/faker'; -import { CommonCartridgeOrganizationNodeProps } from '../export/builders/common-cartridge-organization-node'; -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../export/common-cartridge.enums'; - -export function createCommonCartridgeOrganizationNodeProps(): CommonCartridgeOrganizationNodeProps { - return { - type: CommonCartridgeElementType.ORGANIZATION, - identifier: faker.string.uuid(), - title: faker.lorem.words(), - version: CommonCartridgeVersion.V_1_1_0, - }; -} From cd83ed2ec5d8b8e7bf621b78d2468eb4bd11bfbf Mon Sep 17 00:00:00 2001 From: Alexander Weber Date: Fri, 31 May 2024 17:12:32 +0200 Subject: [PATCH 34/46] fix code duplication --- ...cartridge-organizations-wrapper-element.ts | 50 +++++++++++++ ...cartridge-organizations-wrapper-element.ts | 52 ++------------ ...cartridge-organizations-wrapper-element.ts | 52 ++------------ .../common-cartridge-web-content-resource.ts | 71 ++++++++++++++++++ .../common-cartridge-web-content-resource.ts | 72 +++---------------- .../common-cartridge-resource-factory.spec.ts | 4 +- .../common-cartridge-web-content-resource.ts | 72 +++---------------- .../export/resources/v1.3.0/index.ts | 2 +- 8 files changed, 155 insertions(+), 220 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts create mode 100644 apps/server/src/modules/common-cartridge/export/resources/abstract/common-cartridge-web-content-resource.ts diff --git a/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts new file mode 100644 index 00000000000..ff56a19123d --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts @@ -0,0 +1,50 @@ +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; + +export type CommonCartridgeOrganizationsWrapperElementProps = { + type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; + version: CommonCartridgeVersion; + items: CommonCartridgeElement[]; +}; + +export abstract class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { + + constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementProps) { + super(props); + } + + abstract getSupportedVersion(): CommonCartridgeVersion; + + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.ORGANIZATIONS_WRAPPER: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + private getManifestXmlObjectInternal(): XmlObject { + return { + organization: [ + { + $: { + identifier: 'org-1', + structure: 'rooted-hierarchy', + }, + item: [ + { + $: { + identifier: 'LearningModules', + }, + item: this.props.items.map((items) => + items.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION) + ), + }, + ], + }, + ], + }; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts index 6262025ec4e..564d010b79c 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-organizations-wrapper-element.ts @@ -1,51 +1,13 @@ -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { ElementTypeNotSupportedLoggableException } from '../../errors'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { + CommonCartridgeOrganizationsWrapperElement, + CommonCartridgeOrganizationsWrapperElementProps, +} from '../abstract/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; -export type CommonCartridgeOrganizationsWrapperElementPropsV110 = { - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; - version: CommonCartridgeVersion; - items: CommonCartridgeElement[]; -}; - -export class CommonCartridgeOrganizationsWrapperElementV110 extends CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV110) { - super(props); - } +export type CommonCartridgeOrganizationsWrapperElementPropsV110 = CommonCartridgeOrganizationsWrapperElementProps; +export class CommonCartridgeOrganizationsWrapperElementV110 extends CommonCartridgeOrganizationsWrapperElement { public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - - public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { - switch (elementType) { - case CommonCartridgeElementType.ORGANIZATIONS_WRAPPER: - return this.getManifestXmlObjectInternal(); - default: - throw new ElementTypeNotSupportedLoggableException(elementType); - } - } - - private getManifestXmlObjectInternal(): XmlObject { - return { - organization: [ - { - $: { - identifier: 'org-1', - structure: 'rooted-hierarchy', - }, - item: [ - { - $: { - identifier: 'LearningModules', - }, - item: this.props.items.map((items) => - items.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION) - ), - }, - ], - }, - ], - }; - } } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts index 20146198b18..0bf03cd9efc 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-organizations-wrapper-element.ts @@ -1,51 +1,13 @@ -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { ElementTypeNotSupportedLoggableException } from '../../errors'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { + CommonCartridgeOrganizationsWrapperElement, + CommonCartridgeOrganizationsWrapperElementProps, +} from '../abstract/common-cartridge-organizations-wrapper-element'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; -export type CommonCartridgeOrganizationsWrapperElementPropsV130 = { - type: CommonCartridgeElementType.ORGANIZATIONS_WRAPPER; - version: CommonCartridgeVersion; - items: CommonCartridgeElement[]; -}; - -export class CommonCartridgeOrganizationsWrapperElementV130 extends CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementPropsV130) { - super(props); - } +export type CommonCartridgeOrganizationsWrapperElementPropsV130 = CommonCartridgeOrganizationsWrapperElementProps; +export class CommonCartridgeOrganizationsWrapperElementV130 extends CommonCartridgeOrganizationsWrapperElement { public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - - public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { - switch (elementType) { - case CommonCartridgeElementType.ORGANIZATIONS_WRAPPER: - return this.getManifestXmlObjectInternal(); - default: - throw new ElementTypeNotSupportedLoggableException(elementType); - } - } - - private getManifestXmlObjectInternal(): XmlObject { - return { - organization: [ - { - $: { - identifier: 'org-1', - structure: 'rooted-hierarchy', - }, - item: [ - { - $: { - identifier: 'LearningModules', - }, - item: this.props.items.map((items) => - items.getManifestXmlObject(CommonCartridgeElementType.ORGANIZATION) - ), - }, - ], - }, - ], - }; - } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/abstract/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/abstract/common-cartridge-web-content-resource.ts new file mode 100644 index 00000000000..06a4efd415f --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/resources/abstract/common-cartridge-web-content-resource.ts @@ -0,0 +1,71 @@ +import { + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { createIdentifier } from '../../utils'; + +export type CommonCartridgeWebContentResourceProps = { + type: CommonCartridgeResourceType.WEB_CONTENT; + version: CommonCartridgeVersion; + identifier: string; + folder: string; + title: string; + html: string; + intendedUse: CommonCartridgeIntendedUseType; +}; + +export abstract class CommonCartridgeWebContentResource extends CommonCartridgeResource { + constructor(readonly props: CommonCartridgeWebContentResourceProps) { + super(props); + } + + abstract getSupportedVersion(): CommonCartridgeVersion; + + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCE: + return this.getManifestResourceXmlObject(); + case CommonCartridgeElementType.ORGANIZATION: + return this.getManifestOrganizationXmlObject(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + public getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.html`; + } + + public getFileContent(): string { + return this.props.html; + } + + private getManifestOrganizationXmlObject(): XmlObject { + return { + $: { + identifier: createIdentifier(), + identifierref: this.props.identifier, + }, + title: this.props.title, + }; + } + + private getManifestResourceXmlObject(): XmlObject { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + intendeduse: this.props.intendedUse, + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts index e097a707960..71ea9e056d3 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -1,32 +1,20 @@ -import { - CommonCartridgeElementType, - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; +import { CommonCartridgeIntendedUseType, CommonCartridgeVersion } from '../../common-cartridge.enums'; import { CommonCartridgeGuard } from '../../common-cartridge.guard'; -import { ElementTypeNotSupportedLoggableException } from '../../errors'; -import { CommonCartridgeResource, XmlObject } from '../../interfaces'; -import { createIdentifier } from '../../utils'; +import { + CommonCartridgeWebContentResource, + CommonCartridgeWebContentResourceProps, +} from '../abstract/common-cartridge-web-content-resource'; -export type CommonCartridgeWebContentResourcePropsV110 = { - type: CommonCartridgeResourceType.WEB_CONTENT; - version: CommonCartridgeVersion; - identifier: string; - folder: string; - title: string; - html: string; - intendedUse: CommonCartridgeIntendedUseType; -}; +export type CommonCartridgeWebContentResourcePropsV110 = CommonCartridgeWebContentResourceProps; -export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResource { +export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeWebContentResource { private static readonly SUPPORTED_INTENDED_USES = [ CommonCartridgeIntendedUseType.LESSON_PLAN, CommonCartridgeIntendedUseType.SYLLABUS, CommonCartridgeIntendedUseType.UNSPECIFIED, ]; - constructor(private readonly props: CommonCartridgeWebContentResourcePropsV110) { + constructor(readonly props: CommonCartridgeWebContentResourcePropsV110) { super(props); CommonCartridgeGuard.checkIntendedUse( props.intendedUse, @@ -37,48 +25,4 @@ export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResour public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - - public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { - switch (elementType) { - case CommonCartridgeElementType.RESOURCE: - return this.getManifestResourceXmlObject(); - case CommonCartridgeElementType.ORGANIZATION: - return this.getManifestOrganizationXmlObject(); - default: - throw new ElementTypeNotSupportedLoggableException(elementType); - } - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.html`; - } - - public getFileContent(): string { - return this.props.html; - } - - private getManifestOrganizationXmlObject(): XmlObject { - return { - $: { - identifier: createIdentifier(), - identifierref: this.props.identifier, - }, - title: this.props.title, - }; - } - - private getManifestResourceXmlObject(): XmlObject { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - intendeduse: this.props.intendedUse, - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index 799e435ee00..f678f5d5431 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -1,3 +1,6 @@ +import { + CommonCartridgeWebContentResourceV130 +} from "@modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource"; import { createCommonCartridgeManifestResourcePropsV130, createCommonCartridgeWebContentResourcePropsV130, @@ -6,7 +9,6 @@ import { import { ResourceTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; -import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV130, CommonCartridgeWebLinkResourceV130, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts index 21aa09a0a2d..3b6b5a48cd7 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -1,25 +1,13 @@ -import { - CommonCartridgeElementType, - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; +import { CommonCartridgeIntendedUseType, CommonCartridgeVersion } from '@modules/common-cartridge'; import { CommonCartridgeGuard } from '../../common-cartridge.guard'; -import { ElementTypeNotSupportedLoggableException } from '../../errors'; -import { CommonCartridgeResource, XmlObject } from '../../interfaces'; -import { createIdentifier } from '../../utils'; +import { + CommonCartridgeWebContentResource, + CommonCartridgeWebContentResourceProps, +} from '../abstract/common-cartridge-web-content-resource'; -export type CommonCartridgeWebContentResourcePropsV130 = { - type: CommonCartridgeResourceType.WEB_CONTENT; - version: CommonCartridgeVersion; - identifier: string; - folder: string; - title: string; - html: string; - intendedUse: CommonCartridgeIntendedUseType; -}; +export type CommonCartridgeWebContentResourcePropsV130 = CommonCartridgeWebContentResourceProps; -export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResource { +export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeWebContentResource { private static readonly SUPPORTED_INTENDED_USES = [ CommonCartridgeIntendedUseType.ASSIGNMENT, CommonCartridgeIntendedUseType.LESSON_PLAN, @@ -27,7 +15,7 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResour CommonCartridgeIntendedUseType.UNSPECIFIED, ]; - constructor(private readonly props: CommonCartridgeWebContentResourcePropsV130) { + constructor(readonly props: CommonCartridgeWebContentResourcePropsV130) { super(props); CommonCartridgeGuard.checkIntendedUse( props.intendedUse, @@ -38,48 +26,4 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResour public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - - public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { - switch (elementType) { - case CommonCartridgeElementType.RESOURCE: - return this.getManifestResourceXmlObject(); - case CommonCartridgeElementType.ORGANIZATION: - return this.getManifestOrganizationXmlObject(); - default: - throw new ElementTypeNotSupportedLoggableException(elementType); - } - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.html`; - } - - public getFileContent(): string { - return this.props.html; - } - - private getManifestOrganizationXmlObject(): XmlObject { - return { - $: { - identifier: createIdentifier(), - identifierref: this.props.identifier, - }, - title: this.props.title, - }; - } - - private getManifestResourceXmlObject(): XmlObject { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - intendeduse: this.props.intendedUse, - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/index.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/index.ts index dca0baca323..90e0b5121ea 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/index.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/index.ts @@ -1,7 +1,7 @@ export { CommonCartridgeManifestResourcePropsV130 } from './common-cartridge-manifest-resource'; export { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; export { - CommonCartridgeWebContentResourcePropsV130, CommonCartridgeWebContentResourceV130, + CommonCartridgeWebContentResourcePropsV130, } from './common-cartridge-web-content-resource'; export { CommonCartridgeWebLinkResourcePropsV130 } from './common-cartridge-web-link-resource'; From 7190c3df87eb33aeebd6e38820fea4f14465ba5e Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 3 Jun 2024 15:51:43 +0200 Subject: [PATCH 35/46] EW-793 Add abstract class for resources wrapper and revert changes in web content --- ...cartridge-organizations-wrapper-element.ts | 1 - ...mon-cartridge-resources-wrapper-element.ts | 36 ++++++++++ ...mon-cartridge-resources-wrapper-element.ts | 39 ++-------- ...mon-cartridge-resources-wrapper-element.ts | 39 ++-------- .../common-cartridge-web-content-resource.ts | 71 ------------------ .../common-cartridge-web-content-resource.ts | 72 ++++++++++++++++--- .../common-cartridge-resource-factory.spec.ts | 4 +- .../common-cartridge-web-content-resource.ts | 72 ++++++++++++++++--- 8 files changed, 179 insertions(+), 155 deletions(-) create mode 100644 apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-resources-wrapper-element.ts delete mode 100644 apps/server/src/modules/common-cartridge/export/resources/abstract/common-cartridge-web-content-resource.ts diff --git a/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts index ff56a19123d..37562ca9ecf 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts @@ -9,7 +9,6 @@ export type CommonCartridgeOrganizationsWrapperElementProps = { }; export abstract class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementProps) { super(props); } diff --git a/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-resources-wrapper-element.ts new file mode 100644 index 00000000000..c04b5e506da --- /dev/null +++ b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-resources-wrapper-element.ts @@ -0,0 +1,36 @@ +import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeElement, XmlObject } from '../../interfaces'; + +export type CommonCartridgeResourcesWrapperElementProps = { + type: CommonCartridgeElementType.RESOURCES_WRAPPER; + version: CommonCartridgeVersion; + items: CommonCartridgeElement[]; +}; + +export abstract class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { + constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { + super(props); + } + + abstract getSupportedVersion(): CommonCartridgeVersion; + + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCES_WRAPPER: + return this.getManifestXmlObjectInternal(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + private getManifestXmlObjectInternal(): XmlObject { + return { + resources: [ + { + resource: this.props.items.map((items) => items.getManifestXmlObject(CommonCartridgeElementType.RESOURCE)), + }, + ], + }; + } +} diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts index d5f4939ff8b..e179834e99e 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.1.0/common-cartridge-resources-wrapper-element.ts @@ -1,38 +1,13 @@ -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { ElementTypeNotSupportedLoggableException } from '../../errors'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { + CommonCartridgeResourcesWrapperElement, + CommonCartridgeResourcesWrapperElementProps, +} from '../abstract/common-cartridge-resources-wrapper-element'; -export type CommonCartridgeResourcesWrapperElementPropsV110 = { - type: CommonCartridgeElementType.RESOURCES_WRAPPER; - version: CommonCartridgeVersion; - items: CommonCartridgeElement[]; -}; - -export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV110) { - super(props); - } +export type CommonCartridgeResourcesWrapperElementPropsV110 = CommonCartridgeResourcesWrapperElementProps; +export class CommonCartridgeResourcesWrapperElementV110 extends CommonCartridgeResourcesWrapperElement { public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } - - public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { - switch (elementType) { - case CommonCartridgeElementType.RESOURCES_WRAPPER: - return this.getManifestXmlObjectInternal(); - default: - throw new ElementTypeNotSupportedLoggableException(elementType); - } - } - - private getManifestXmlObjectInternal(): XmlObject { - return { - resources: [ - { - resource: this.props.items.map((items) => items.getManifestXmlObject(CommonCartridgeElementType.RESOURCE)), - }, - ], - }; - } } diff --git a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts index 98826911e2b..b9726dd3c63 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/v1.3.0/common-cartridge-resources-wrapper-element.ts @@ -1,38 +1,13 @@ -import { CommonCartridgeElementType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { ElementTypeNotSupportedLoggableException } from '../../errors'; -import { CommonCartridgeElement, XmlObject } from '../../interfaces'; +import { CommonCartridgeVersion } from '../../common-cartridge.enums'; +import { + CommonCartridgeResourcesWrapperElement, + CommonCartridgeResourcesWrapperElementProps, +} from '../abstract/common-cartridge-resources-wrapper-element'; -export type CommonCartridgeResourcesWrapperElementPropsV130 = { - type: CommonCartridgeElementType.RESOURCES_WRAPPER; - version: CommonCartridgeVersion; - items: CommonCartridgeElement[]; -}; - -export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeElement { - constructor(private readonly props: CommonCartridgeResourcesWrapperElementPropsV130) { - super(props); - } +export type CommonCartridgeResourcesWrapperElementPropsV130 = CommonCartridgeResourcesWrapperElementProps; +export class CommonCartridgeResourcesWrapperElementV130 extends CommonCartridgeResourcesWrapperElement { public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } - - public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { - switch (elementType) { - case CommonCartridgeElementType.RESOURCES_WRAPPER: - return this.getManifestXmlObjectInternal(); - default: - throw new ElementTypeNotSupportedLoggableException(elementType); - } - } - - private getManifestXmlObjectInternal(): XmlObject { - return { - resources: [ - { - resource: this.props.items.map((items) => items.getManifestXmlObject(CommonCartridgeElementType.RESOURCE)), - }, - ], - }; - } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/abstract/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/abstract/common-cartridge-web-content-resource.ts deleted file mode 100644 index 06a4efd415f..00000000000 --- a/apps/server/src/modules/common-cartridge/export/resources/abstract/common-cartridge-web-content-resource.ts +++ /dev/null @@ -1,71 +0,0 @@ -import { - CommonCartridgeElementType, - CommonCartridgeIntendedUseType, - CommonCartridgeResourceType, - CommonCartridgeVersion, -} from '../../common-cartridge.enums'; -import { ElementTypeNotSupportedLoggableException } from '../../errors'; -import { CommonCartridgeResource, XmlObject } from '../../interfaces'; -import { createIdentifier } from '../../utils'; - -export type CommonCartridgeWebContentResourceProps = { - type: CommonCartridgeResourceType.WEB_CONTENT; - version: CommonCartridgeVersion; - identifier: string; - folder: string; - title: string; - html: string; - intendedUse: CommonCartridgeIntendedUseType; -}; - -export abstract class CommonCartridgeWebContentResource extends CommonCartridgeResource { - constructor(readonly props: CommonCartridgeWebContentResourceProps) { - super(props); - } - - abstract getSupportedVersion(): CommonCartridgeVersion; - - public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { - switch (elementType) { - case CommonCartridgeElementType.RESOURCE: - return this.getManifestResourceXmlObject(); - case CommonCartridgeElementType.ORGANIZATION: - return this.getManifestOrganizationXmlObject(); - default: - throw new ElementTypeNotSupportedLoggableException(elementType); - } - } - - public getFilePath(): string { - return `${this.props.folder}/${this.props.identifier}.html`; - } - - public getFileContent(): string { - return this.props.html; - } - - private getManifestOrganizationXmlObject(): XmlObject { - return { - $: { - identifier: createIdentifier(), - identifierref: this.props.identifier, - }, - title: this.props.title, - }; - } - - private getManifestResourceXmlObject(): XmlObject { - return { - $: { - identifier: this.props.identifier, - type: this.props.type, - intendeduse: this.props.intendedUse, - }, - file: { - $: { - href: this.getFilePath(), - }, - }, - }; - } -} diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts index 71ea9e056d3..e097a707960 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.1.0/common-cartridge-web-content-resource.ts @@ -1,20 +1,32 @@ -import { CommonCartridgeIntendedUseType, CommonCartridgeVersion } from '../../common-cartridge.enums'; -import { CommonCartridgeGuard } from '../../common-cartridge.guard'; import { - CommonCartridgeWebContentResource, - CommonCartridgeWebContentResourceProps, -} from '../abstract/common-cartridge-web-content-resource'; + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeGuard } from '../../common-cartridge.guard'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { createIdentifier } from '../../utils'; -export type CommonCartridgeWebContentResourcePropsV110 = CommonCartridgeWebContentResourceProps; +export type CommonCartridgeWebContentResourcePropsV110 = { + type: CommonCartridgeResourceType.WEB_CONTENT; + version: CommonCartridgeVersion; + identifier: string; + folder: string; + title: string; + html: string; + intendedUse: CommonCartridgeIntendedUseType; +}; -export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeWebContentResource { +export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeResource { private static readonly SUPPORTED_INTENDED_USES = [ CommonCartridgeIntendedUseType.LESSON_PLAN, CommonCartridgeIntendedUseType.SYLLABUS, CommonCartridgeIntendedUseType.UNSPECIFIED, ]; - constructor(readonly props: CommonCartridgeWebContentResourcePropsV110) { + constructor(private readonly props: CommonCartridgeWebContentResourcePropsV110) { super(props); CommonCartridgeGuard.checkIntendedUse( props.intendedUse, @@ -25,4 +37,48 @@ export class CommonCartridgeWebContentResourceV110 extends CommonCartridgeWebCon public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_1_0; } + + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCE: + return this.getManifestResourceXmlObject(); + case CommonCartridgeElementType.ORGANIZATION: + return this.getManifestOrganizationXmlObject(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + public getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.html`; + } + + public getFileContent(): string { + return this.props.html; + } + + private getManifestOrganizationXmlObject(): XmlObject { + return { + $: { + identifier: createIdentifier(), + identifierref: this.props.identifier, + }, + title: this.props.title, + }; + } + + private getManifestResourceXmlObject(): XmlObject { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + intendeduse: this.props.intendedUse, + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } } diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts index f678f5d5431..799e435ee00 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-resource-factory.spec.ts @@ -1,6 +1,3 @@ -import { - CommonCartridgeWebContentResourceV130 -} from "@modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource"; import { createCommonCartridgeManifestResourcePropsV130, createCommonCartridgeWebContentResourcePropsV130, @@ -9,6 +6,7 @@ import { import { ResourceTypeNotSupportedLoggableException } from '../../errors'; import { CommonCartridgeManifestResourceV130 } from './common-cartridge-manifest-resource'; import { CommonCartridgeResourceFactoryV130 } from './common-cartridge-resource-factory'; +import { CommonCartridgeWebContentResourceV130 } from './common-cartridge-web-content-resource'; import { CommonCartridgeWebLinkResourcePropsV130, CommonCartridgeWebLinkResourceV130, diff --git a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts index 3b6b5a48cd7..21aa09a0a2d 100644 --- a/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts +++ b/apps/server/src/modules/common-cartridge/export/resources/v1.3.0/common-cartridge-web-content-resource.ts @@ -1,13 +1,25 @@ -import { CommonCartridgeIntendedUseType, CommonCartridgeVersion } from '@modules/common-cartridge'; -import { CommonCartridgeGuard } from '../../common-cartridge.guard'; import { - CommonCartridgeWebContentResource, - CommonCartridgeWebContentResourceProps, -} from '../abstract/common-cartridge-web-content-resource'; + CommonCartridgeElementType, + CommonCartridgeIntendedUseType, + CommonCartridgeResourceType, + CommonCartridgeVersion, +} from '../../common-cartridge.enums'; +import { CommonCartridgeGuard } from '../../common-cartridge.guard'; +import { ElementTypeNotSupportedLoggableException } from '../../errors'; +import { CommonCartridgeResource, XmlObject } from '../../interfaces'; +import { createIdentifier } from '../../utils'; -export type CommonCartridgeWebContentResourcePropsV130 = CommonCartridgeWebContentResourceProps; +export type CommonCartridgeWebContentResourcePropsV130 = { + type: CommonCartridgeResourceType.WEB_CONTENT; + version: CommonCartridgeVersion; + identifier: string; + folder: string; + title: string; + html: string; + intendedUse: CommonCartridgeIntendedUseType; +}; -export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeWebContentResource { +export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeResource { private static readonly SUPPORTED_INTENDED_USES = [ CommonCartridgeIntendedUseType.ASSIGNMENT, CommonCartridgeIntendedUseType.LESSON_PLAN, @@ -15,7 +27,7 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeWebCon CommonCartridgeIntendedUseType.UNSPECIFIED, ]; - constructor(readonly props: CommonCartridgeWebContentResourcePropsV130) { + constructor(private readonly props: CommonCartridgeWebContentResourcePropsV130) { super(props); CommonCartridgeGuard.checkIntendedUse( props.intendedUse, @@ -26,4 +38,48 @@ export class CommonCartridgeWebContentResourceV130 extends CommonCartridgeWebCon public getSupportedVersion(): CommonCartridgeVersion { return CommonCartridgeVersion.V_1_3_0; } + + public getManifestXmlObject(elementType: CommonCartridgeElementType): XmlObject { + switch (elementType) { + case CommonCartridgeElementType.RESOURCE: + return this.getManifestResourceXmlObject(); + case CommonCartridgeElementType.ORGANIZATION: + return this.getManifestOrganizationXmlObject(); + default: + throw new ElementTypeNotSupportedLoggableException(elementType); + } + } + + public getFilePath(): string { + return `${this.props.folder}/${this.props.identifier}.html`; + } + + public getFileContent(): string { + return this.props.html; + } + + private getManifestOrganizationXmlObject(): XmlObject { + return { + $: { + identifier: createIdentifier(), + identifierref: this.props.identifier, + }, + title: this.props.title, + }; + } + + private getManifestResourceXmlObject(): XmlObject { + return { + $: { + identifier: this.props.identifier, + type: this.props.type, + intendeduse: this.props.intendedUse, + }, + file: { + $: { + href: this.getFilePath(), + }, + }, + }; + } } From c3e4826563e512267e2f267d8fa7904b20dda96a Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Mon, 3 Jun 2024 17:15:49 +0200 Subject: [PATCH 36/46] EW-793 Add comments to abstract classes --- .../common-cartridge-organizations-wrapper-element.ts | 4 ++++ .../abstract/common-cartridge-resources-wrapper-element.ts | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts index 37562ca9ecf..e30c80e0d87 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-organizations-wrapper-element.ts @@ -8,6 +8,10 @@ export type CommonCartridgeOrganizationsWrapperElementProps = { items: CommonCartridgeElement[]; }; +/** + * This abstract class was created to reduce code duplication and + * keep the SonarCloud code duplication rate below 3%. + */ export abstract class CommonCartridgeOrganizationsWrapperElement extends CommonCartridgeElement { constructor(private readonly props: CommonCartridgeOrganizationsWrapperElementProps) { super(props); diff --git a/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-resources-wrapper-element.ts b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-resources-wrapper-element.ts index c04b5e506da..06059be68ea 100644 --- a/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-resources-wrapper-element.ts +++ b/apps/server/src/modules/common-cartridge/export/elements/abstract/common-cartridge-resources-wrapper-element.ts @@ -8,6 +8,10 @@ export type CommonCartridgeResourcesWrapperElementProps = { items: CommonCartridgeElement[]; }; +/** + * This abstract class was created to reduce code duplication and + * keep the SonarCloud code duplication rate below 3%. + */ export abstract class CommonCartridgeResourcesWrapperElement extends CommonCartridgeElement { constructor(private readonly props: CommonCartridgeResourcesWrapperElementProps) { super(props); From 02bffc43ef338c083cc2b87d56d06a44721d29d3 Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Wed, 5 Jun 2024 15:59:32 +0200 Subject: [PATCH 37/46] EW-793 Change three dots in card title --- .../learnroom/mapper/common-cartridge-export.mapper.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts index a5e70990d1a..bc52a85d17f 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts @@ -141,10 +141,10 @@ export class CommonCartridgeExportMapper { } private getTextTitle(text: string): string { - const title = text - .slice(0, 50) - .replace(/<[^>]*>?/gm, '') - .concat('...'); + let title = text.slice(0, 50).replace(/<[^>]*>?/gm, ''); + if (text.length > 50) { + title = title.concat('...'); + } return title; } } From 985a88f300db5de86ca96817e8d22a81dfb1978a Mon Sep 17 00:00:00 2001 From: Simone Radtke Date: Thu, 6 Jun 2024 13:34:04 +0200 Subject: [PATCH 38/46] EW-793 Prevent script injection --- .../modules/learnroom/mapper/common-cartridge-export.mapper.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts b/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts index bc52a85d17f..9d4a63771af 100644 --- a/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts +++ b/apps/server/src/modules/learnroom/mapper/common-cartridge-export.mapper.ts @@ -142,6 +142,7 @@ export class CommonCartridgeExportMapper { private getTextTitle(text: string): string { let title = text.slice(0, 50).replace(/<[^>]*>?/gm, ''); + title = title.replace(/