diff --git a/src/commands/action-flows/skill/skill-command.service.ts b/src/commands/action-flows/skill/skill-command.service.ts index 7a3a4c88..29b9fcf7 100644 --- a/src/commands/action-flows/skill/skill-command.service.ts +++ b/src/commands/action-flows/skill/skill-command.service.ts @@ -1,9 +1,7 @@ -import { ContentService } from "../../../core/http/http-shared/content.service"; import { Context } from "../../../core/command/cli-context"; import { SkillManagerFactory } from "./skill.manager-factory"; export class SkillCommandService { - private contentService = new ContentService(); private skillManagerFactory: SkillManagerFactory; constructor(context: Context) { @@ -11,10 +9,10 @@ export class SkillCommandService { } public async pullSkill(profile: string, projectId: string, skillId: string): Promise { - await this.contentService.pull(this.skillManagerFactory.createManager(projectId, skillId, null)); + await this.skillManagerFactory.createManager(projectId, skillId, null).pull(); } public async pushSkill(profile: string, projectId: string, filename: string): Promise { - await this.contentService.push(this.skillManagerFactory.createManager(projectId, null, filename)); + await this.skillManagerFactory.createManager(projectId, null, filename).push(); } } diff --git a/src/commands/analysis/analysis-bookmarks-command.service.ts b/src/commands/analysis/analysis-bookmarks-command.service.ts index 374e27ea..c121aa24 100644 --- a/src/commands/analysis/analysis-bookmarks-command.service.ts +++ b/src/commands/analysis/analysis-bookmarks-command.service.ts @@ -1,9 +1,7 @@ -import { ContentService } from "../../core/http/http-shared/content.service"; import { AnalysisBookmarksManagerFactory } from "./analysis-bookmarks.manager-factory"; import { Context } from "../../core/command/cli-context"; export class AnalysisBookmarksCommandService { - private contentService = new ContentService(); private analysisBookmarksManagerFactory: AnalysisBookmarksManagerFactory; constructor(context: Context) { @@ -11,10 +9,10 @@ export class AnalysisBookmarksCommandService { } public async pullAnalysisBookmarks(analysisId: string, type: string): Promise { - await this.contentService.pull(this.analysisBookmarksManagerFactory.createAnalysisBookmarksManager(null, analysisId, type)); + await this.analysisBookmarksManagerFactory.createAnalysisBookmarksManager(null, analysisId, type).pull(); } public async pushAnalysisBookmarks(analysisId: string, filename: string): Promise { - await this.contentService.push(this.analysisBookmarksManagerFactory.createAnalysisBookmarksManager(filename, analysisId)); + await this.analysisBookmarksManagerFactory.createAnalysisBookmarksManager(filename, analysisId).push(); } } diff --git a/src/commands/cpm4/ctp-command.service.ts b/src/commands/cpm4/ctp-command.service.ts index 5a5fa69f..6def57e8 100644 --- a/src/commands/cpm4/ctp-command.service.ts +++ b/src/commands/cpm4/ctp-command.service.ts @@ -1,10 +1,8 @@ import { Context } from "../../core/command/cli-context"; -import { ContentService } from "../../core/http/http-shared/content.service"; import { FatalError, logger } from "../../core/utils/logger"; import { CTPManagerFactory } from "./ctp.manager-factory"; export class CTPCommandService { - private contentService = new ContentService(); private ctpManagerFactory: CTPManagerFactory; constructor(context: Context) { @@ -21,12 +19,12 @@ export class CTPCommandService { spaceKey: string ): Promise { if (pushAnalysis) { - await this.contentService.push(this.ctpManagerFactory.createCtpAnalysisManager(filename, password, spaceKey)); + await this.ctpManagerFactory.createCtpAnalysisManager(filename, password, spaceKey).push(); } if (pushDataModels) { this.validateParamsForDataModelPush(existingPoolId, globalPoolName); - await this.contentService.push(this.ctpManagerFactory.createCtpDataModelManager(filename, password, existingPoolId, globalPoolName)); + await this.ctpManagerFactory.createCtpDataModelManager(filename, password, existingPoolId, globalPoolName).push(); } } diff --git a/src/commands/data-pipeline/data-pool/data-pool-command.service.ts b/src/commands/data-pipeline/data-pool/data-pool-command.service.ts index 722eff8e..8fb4a698 100644 --- a/src/commands/data-pipeline/data-pool/data-pool-command.service.ts +++ b/src/commands/data-pipeline/data-pool/data-pool-command.service.ts @@ -1,10 +1,10 @@ -import { ContentService } from "../../../core/http/http-shared/content.service"; import { DataPoolManagerFactory } from "./data-pool-manager.factory"; import { Context } from "../../../core/command/cli-context"; import { DataPoolService } from "./data-pool-service"; +import { BaseManagerHelper } from "../../../core/http/http-shared/base.manager.helper"; export class DataPoolCommandService { - private contentService = new ContentService(); + private baseManagerHelper = new BaseManagerHelper(); private dataPoolManagerFactory: DataPoolManagerFactory; private dataPoolService: DataPoolService; @@ -14,11 +14,11 @@ export class DataPoolCommandService { } public async pullDataPool(id: string): Promise { - await this.contentService.pull(this.dataPoolManagerFactory.createManager(id, null)); + await this.dataPoolManagerFactory.createManager(id, null).pull(); } public async pushDataPool(filename: string): Promise { - await this.contentService.push(this.dataPoolManagerFactory.createManager(null, filename)); + await this.dataPoolManagerFactory.createManager(null, filename).push(); } public async exportDataPool(poolId: string, outputToJsonFile: boolean): Promise { @@ -26,7 +26,8 @@ export class DataPoolCommandService { } public async pushDataPools(): Promise { - await this.contentService.batchPush(this.dataPoolManagerFactory.createManagers()); + const dataPoolManagers = this.dataPoolManagerFactory.createManagers(); + await this.baseManagerHelper.batchPush(dataPoolManagers); } public async batchImportDataPools(requestFile: string, outputToJsonFile: boolean): Promise { @@ -34,7 +35,7 @@ export class DataPoolCommandService { } public async updateDataPool(id: string, filename: string): Promise { - await this.contentService.update(this.dataPoolManagerFactory.createManager(id, filename)); + await this.dataPoolManagerFactory.createManager(id, filename).update(); } public async listDataPools(jsonResponse: boolean): Promise { diff --git a/src/commands/studio/command-service/asset-command.service.ts b/src/commands/studio/command-service/asset-command.service.ts index ff560e3c..88e20f16 100644 --- a/src/commands/studio/command-service/asset-command.service.ts +++ b/src/commands/studio/command-service/asset-command.service.ts @@ -1,10 +1,10 @@ -import { ContentService } from "../../../core/http/http-shared/content.service"; import { Context } from "../../../core/command/cli-context"; import { AssetManagerFactory } from "../manager/asset.manager-factory"; import { AssetService } from "../service/asset-service"; +import { BaseManagerHelper } from "../../../core/http/http-shared/base.manager.helper"; export class AssetCommandService { - private contentService = new ContentService(); + private baseManagerHelper = new BaseManagerHelper(); private assetManagerFactory: AssetManagerFactory; private assetService: AssetService; @@ -15,15 +15,16 @@ export class AssetCommandService { } public async pullAsset(key: string): Promise { - await this.contentService.pull(this.assetManagerFactory.createManager(key)); + await this.assetManagerFactory.createManager(key).pull(); } public async pushAsset(fileName: string, packageKey: string): Promise { - await this.contentService.push(this.assetManagerFactory.createManager(null, fileName, packageKey)); + await this.assetManagerFactory.createManager(null, fileName, packageKey).push(); } public async pushAssets(packageKey: string): Promise { - await this.contentService.batchPush(this.assetManagerFactory.createManagers(packageKey)); + const assetManagers = this.assetManagerFactory.createManagers(packageKey); + await this.baseManagerHelper.batchPush(assetManagers); } public async listAssets(jsonResponse: boolean, assetType: string): Promise { diff --git a/src/commands/studio/command-service/package-command.service.ts b/src/commands/studio/command-service/package-command.service.ts index e3b92ef7..c8a9535f 100644 --- a/src/commands/studio/command-service/package-command.service.ts +++ b/src/commands/studio/command-service/package-command.service.ts @@ -1,10 +1,10 @@ -import { ContentService } from "../../../core/http/http-shared/content.service"; import { Context } from "../../../core/command/cli-context"; import { PackageManagerFactory } from "../manager/package.manager-factory"; import { PackageService } from "../service/package.service"; +import { BaseManagerHelper } from "../../../core/http/http-shared/base.manager.helper"; export class PackageCommandService { - private contentService = new ContentService(); + private baseManagerHelper = new BaseManagerHelper(); private packageManagerFactory: PackageManagerFactory; private packageService: PackageService; @@ -20,9 +20,7 @@ export class PackageCommandService { newKey: string, draft: boolean ): Promise { - await this.contentService.pullFile( - this.packageManagerFactory.createPullManager(key, store, newKey, draft) - ); + await this.packageManagerFactory.createPullManager(key, store, newKey, draft).pullFile(); } public async pushPackage( @@ -31,13 +29,12 @@ export class PackageCommandService { newKey: string, overwrite: boolean ): Promise { - await this.contentService.push( - this.packageManagerFactory.createPushManager(spaceKey, fileName, newKey, overwrite) - ); + await this.packageManagerFactory.createPushManager(spaceKey, fileName, newKey, overwrite).push(); } public async pushPackages(spaceKey: string): Promise { - await this.contentService.batchPush(this.packageManagerFactory.createPushManagers(spaceKey)); + const packageManagers = this.packageManagerFactory.createPushManagers(spaceKey); + await this.baseManagerHelper.batchPush(packageManagers); } public async listPackages(jsonResponse: boolean, includeDependencies: boolean, packageKeys: string[]): Promise { diff --git a/src/commands/studio/command-service/space-command.service.ts b/src/commands/studio/command-service/space-command.service.ts index b12c85f1..87a9d34c 100644 --- a/src/commands/studio/command-service/space-command.service.ts +++ b/src/commands/studio/command-service/space-command.service.ts @@ -1,9 +1,7 @@ -import { ContentService } from "../../../core/http/http-shared/content.service"; import { SpaceManagerFactory } from "../manager/space.manager-factory"; import { Context } from "../../../core/command/cli-context"; export class SpaceCommandService { - private contentService = new ContentService(); private spaceManagerFactory: SpaceManagerFactory; constructor(context: Context) { @@ -11,6 +9,6 @@ export class SpaceCommandService { } public async listSpaces(jsonResponse: boolean): Promise { - await this.contentService.findAll(this.spaceManagerFactory.createListManager(jsonResponse)); + await this.spaceManagerFactory.createListManager(jsonResponse).findAll(); } } diff --git a/src/commands/studio/command-service/widget.command.ts b/src/commands/studio/command-service/widget.command.ts index cc483507..add8316d 100644 --- a/src/commands/studio/command-service/widget.command.ts +++ b/src/commands/studio/command-service/widget.command.ts @@ -2,12 +2,10 @@ import { execSync } from "child_process"; import { GracefulError, logger } from "../../../core/utils/logger"; import * as fs from "fs"; import * as path from "path"; -import { ContentService } from "../../../core/http/http-shared/content.service"; import { Context } from "../../../core/command/cli-context"; import { WidgetManagerFactory } from "../manager/widget.manager-factory"; export class WidgetCommand { - private contentService = new ContentService(); private widgetManagerFactory: WidgetManagerFactory; constructor(context: Context) { @@ -15,7 +13,7 @@ export class WidgetCommand { } public async pushWidget(tenantIndependent: boolean, userSpecific: boolean): Promise { - await this.contentService.push(this.widgetManagerFactory.createManager(tenantIndependent, userSpecific)); + await this.widgetManagerFactory.createManager(tenantIndependent, userSpecific).push(); await this.pushToAwsIfAuthorized(); } diff --git a/src/core/http/http-shared/base.manager.helper.ts b/src/core/http/http-shared/base.manager.helper.ts new file mode 100644 index 00000000..e216138c --- /dev/null +++ b/src/core/http/http-shared/base.manager.helper.ts @@ -0,0 +1,8 @@ +import { BaseManager } from "./base.manager"; + +export class BaseManagerHelper { + + public async batchPush(baseManagers: BaseManager[]): Promise { + return Promise.all(baseManagers.map(baseManager => baseManager.push())) + } +} diff --git a/src/core/http/http-shared/content.service.ts b/src/core/http/http-shared/content.service.ts deleted file mode 100644 index 6c2a3d15..00000000 --- a/src/core/http/http-shared/content.service.ts +++ /dev/null @@ -1,64 +0,0 @@ -import { BaseManager } from "./base.manager"; - -export class ContentService { - - public async pull(baseManager: BaseManager): Promise { - return new Promise((resolve, reject) => { - baseManager.pull().then( - () => resolve(), - () => reject() - ); - }); - } - - public async pullFile(baseManager: BaseManager): Promise { - return new Promise((resolve, reject) => { - baseManager.pullFile().then( - () => resolve(), - () => reject() - ); - }); - } - - public async push(baseManager: BaseManager): Promise { - return new Promise((resolve, reject) => { - baseManager.push().then( - () => resolve(), - () => reject() - ); - }); - } - - public async batchPush(baseManagers: BaseManager[]): Promise { - return new Promise((resolve, reject) => { - const promises: Array> = []; - - baseManagers.forEach(baseManager => { - promises.push(baseManager.push()); - }); - - Promise.all(promises).then( - () => resolve(), - () => reject() - ); - }); - } - - public async update(baseManager: BaseManager): Promise { - return new Promise((resolve, reject) => { - baseManager.update().then( - () => resolve(), - () => reject() - ); - }); - } - - public async findAll(baseManager: BaseManager): Promise { - return new Promise((resolve, reject) => { - baseManager.findAll().then( - () => resolve(), - () => reject() - ); - }); - } -}