From 52ca67b4e33fdc9626886791a7a9d6ce4102aede Mon Sep 17 00:00:00 2001 From: Jens Pelzetter Date: Tue, 4 Aug 2020 16:41:54 +0200 Subject: [PATCH] Entities for RESTful API for managing application instances Former-commit-id: 360afd6bdb0470a778b78bc89ea1b333cae255f7 --- .../typescript/entities/categorization.ts | 37 ++++++++++-- .../src/main/typescript/entities/web.ts | 59 +++++++++++++++++++ 2 files changed, 92 insertions(+), 4 deletions(-) diff --git a/ccm-core-apiclient/src/main/typescript/entities/categorization.ts b/ccm-core-apiclient/src/main/typescript/entities/categorization.ts index 070182f46..7bda4cfb4 100644 --- a/ccm-core-apiclient/src/main/typescript/entities/categorization.ts +++ b/ccm-core-apiclient/src/main/typescript/entities/categorization.ts @@ -8,6 +8,7 @@ import { assertProperties, } from "@libreccm/ccm-apiclient-commons"; import { CcmObjectId } from "./core"; +import { CcmApplicationId } from "./web"; /** * Data required to identify a category. @@ -75,7 +76,7 @@ export interface Category { */ abstractCategory: boolean; /** - * The parent category of the category. Is null if the category is a root + * The parent category of the category. Is null if the category is a root * category. */ parentCategory: AssociatedCategory | null; @@ -120,9 +121,17 @@ export interface Categorization { type: string; } +export interface DomainOwnership { + ownershipId: number; + uuid: string; + context: string; + owner: CcmApplicationId; + ownerOrder: number; +} + /** * Builds a {@link Category} object from a `Record`. - * + * * @param record The record used as datasource. */ export function buildCategoryFromRecord( @@ -160,9 +169,9 @@ export function buildCategoryFromRecord( } /** - * Helper function for building a {@link Categorization} object from + * Helper function for building a {@link Categorization} object from * a record. - * + * * @param record The record to use as datasource. */ export function buildCategorizationFromRecord( @@ -188,3 +197,23 @@ export function buildCategorizationFromRecord( type: record.type as string, }; } + +export function buildDomainOwnershipFromRecord( + record: Record +): DomainOwnership { + assertProperties(record, [ + "ownershipId", + "uuid", + "context", + "owner", + "ownerOrder", + ]); + + return { + ownershipId: record.ownershipId as number, + uuid: record.uuid as string, + context: record.context as string, + owner: record.owner as CcmApplicationId, + ownerOrder: record.ownerOrder as number, + }; +} diff --git a/ccm-core-apiclient/src/main/typescript/entities/web.ts b/ccm-core-apiclient/src/main/typescript/entities/web.ts index 154c946fa..47e157d0e 100644 --- a/ccm-core-apiclient/src/main/typescript/entities/web.ts +++ b/ccm-core-apiclient/src/main/typescript/entities/web.ts @@ -7,12 +7,71 @@ import { LocalizedString, assertProperties, } from "@libreccm/ccm-apiclient-commons"; +import { + DomainOwnership, + buildDomainOwnershipFromRecord, +} from "./categorization"; +import { SiteId } from "./site"; + +export interface CcmApplication { + applicationId: number; + uuid: string; + title: LocalizedString; + description: LocalizedString; + created: string; + applicationClassName: string; + applicationType: string; + primaryUrl: string; + domains: DomainOwnership[]; + siteAware: boolean; + site: SiteId; +} export interface CcmApplicationId { applicationType: string; primaryUrl: string; } +export function buildCcmApplicationFromRecord( + record: Record +): CcmApplication { + assertProperties(record, [ + "applicationId", + "uuid", + "title", + "description", + "created", + "applicationClassName", + "applicationType", + "primaryUrl", + "domains", + "siteAware", + "site", + ]); + + const domainRecords: Record[] = record.domains as Record< + string, + unknown + >[]; + const domains = domainRecords.map((record) => + buildDomainOwnershipFromRecord(record) + ); + + return { + applicationId: record.applicationId as number, + uuid: record.uuid as string, + title: record.title as LocalizedString, + description: record.description as LocalizedString, + created: record.created as string, + applicationClassName: record.applicationClassName as string, + applicationType: record.applicationType as string, + primaryUrl: record.primaryUrl as string, + domains, + siteAware: record.siteAware as boolean, + site: record.site as SiteId, + }; +} + export function buildCcmApplicationIdFromRecord( record: Record ): CcmApplicationId {