Skip to content

Commit a719d60

Browse files
TA-3725: Add list command options to filter by variable value and type. (#196)
Co-authored-by: Laberion Ajvazi <93651741+LaberionAjvazi@users.noreply.github.com>
1 parent 2f8ac9a commit a719d60

6 files changed

Lines changed: 85 additions & 8 deletions

File tree

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@celonis/content-cli",
3-
"version": "0.13.4",
3+
"version": "0.13.5",
44
"description": "CLI Tool to help manage content in Celonis EMS",
55
"main": "content-cli.js",
66
"bin": {

src/api/batch-import-export-api.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ class BatchImportExportApi {
2121
});
2222
}
2323

24+
public findActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string): Promise<PackageExportTransport[]> {
25+
const queryParams = new URLSearchParams();
26+
27+
queryParams.set("variableValue", variableValue);
28+
if (variableType) {
29+
queryParams.set("variableType", variableType);
30+
}
31+
flavors.forEach(flavor => queryParams.append("flavors", flavor))
32+
33+
return httpClientV2.get(`/package-manager/api/core/packages/export/list-by-variable-value?${queryParams.toString()}`).catch(e => {
34+
throw new FatalError(`Problem getting active packages by variable value: ${e}`);
35+
});
36+
}
37+
2438
public findActivePackagesByKeys(packageKeys: string[], withDependencies: boolean = false): Promise<PackageExportTransport[]> {
2539
const queryParams = new URLSearchParams();
2640

src/commands/config.command.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ import {diffService} from "../services/package-manager/diff-service";
44

55
export class ConfigCommand {
66

7-
public async listActivePackages(jsonResponse: boolean, flavors: string[], withDependencies: boolean, packageKeys:string[]): Promise<void> {
7+
public async listActivePackages(jsonResponse: boolean, flavors: string[], withDependencies: boolean, packageKeys: string[], variableValue: string, variableType: string): Promise<void> {
8+
if (variableValue) {
9+
await this.listPackagesByVariableValue(jsonResponse, flavors, variableValue, variableType);
10+
return;
11+
}
12+
813
if (jsonResponse) {
914
await batchImportExportService.findAndExportListOfActivePackages(flavors ?? [], packageKeys ?? [], withDependencies)
1015
} else {
@@ -31,4 +36,12 @@ export class ConfigCommand {
3136
public diffPackages(file: string, hasChanges: boolean, jsonResponse: boolean): Promise<void> {
3237
return diffService.diffPackages(file, hasChanges, jsonResponse);
3338
}
39+
40+
private async listPackagesByVariableValue(jsonResponse: boolean, flavors: string[], variableValue: string, variableType: string): Promise<void> {
41+
if (jsonResponse) {
42+
await batchImportExportService.findAndExportListOfActivePackagesByVariableValue(flavors ?? [], variableValue, variableType )
43+
} else {
44+
await batchImportExportService.listActivePackagesByVariableValue(flavors ?? [], variableValue, variableType);
45+
}
46+
}
3447
}

src/content-cli-config.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ export class Config {
1414
.option("--flavors <flavors...>", "Lists only active packages of the given flavors")
1515
.option("--withDependencies", "Include dependencies", "")
1616
.option("--packageKeys <packageKeys...>", "Lists only given package keys")
17+
.option("--variableValue <variableValue>", "Variable value for filtering packages by.")
18+
.option("--variableType <variableType>", "Variable type for filtering packages by.")
1719
.action(async cmd => {
18-
await new ConfigCommand().listActivePackages(cmd.json, cmd.flavors, cmd.withDependencies, cmd.packageKeys);
20+
await new ConfigCommand().listActivePackages(cmd.json, cmd.flavors, cmd.withDependencies, cmd.packageKeys, cmd.variableValue, cmd.variableType);
1921
process.exit();
2022
});
2123

src/services/package-manager/batch-import-export-service.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,21 @@ class BatchImportExportService {
9595
logger.info("Config import report file: " + reportFileName);
9696
}
9797

98+
public async findAndExportListOfActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string): Promise<void> {
99+
let packagesToExport = await batchImportExportApi.findActivePackagesByVariableValue(flavors, variableValue, variableType);
100+
101+
packagesToExport = await studioService.getExportPackagesWithStudioData(packagesToExport, false);
102+
103+
this.exportListOfPackages(packagesToExport);
104+
}
105+
106+
public async listActivePackagesByVariableValue(flavors: string[], variableValue: string, variableType: string) : Promise<void> {
107+
const packagesByVariableValue = await batchImportExportApi.findActivePackagesByVariableValue(flavors, variableValue, variableType);
108+
packagesByVariableValue.forEach(pkg => {
109+
logger.info(`${pkg.name} - Key: "${pkg.key}"`)
110+
});
111+
}
112+
98113
private exportListOfPackages(packages: PackageExportTransport[]): void {
99114
const filename = uuidv4() + ".json";
100115
fileService.writeToFileWithGivenName(JSON.stringify(packages), filename);

tests/config/config-list.spec.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("Config list", () => {
3030

3131
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list?" + urlParams.toString(), [firstPackage, secondPackage]);
3232

33-
await new ConfigCommand().listActivePackages(false, flavorsArray, false, []);
33+
await new ConfigCommand().listActivePackages(false, flavorsArray, false, [], null, null);
3434

3535
expect(testTransport.logMessages.length).toBe(2);
3636
expect(testTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
@@ -47,7 +47,7 @@ describe("Config list", () => {
4747
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list?withDependencies=false", [{...firstPackage}, {...secondPackage}]);
4848
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", [studioPackage]);
4949

50-
await new ConfigCommand().listActivePackages(true, [], false, []);
50+
await new ConfigCommand().listActivePackages(true, [], false, [], null, null);
5151

5252
const expectedFileName = testTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];
5353

@@ -93,7 +93,7 @@ describe("Config list", () => {
9393
};
9494
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/compute-pools/data-models/details", [dataModelDetailResponse]);
9595

96-
await new ConfigCommand().listActivePackages(true, [], true, []);
96+
await new ConfigCommand().listActivePackages(true, [], true, [], null, null);
9797

9898
const expectedFileName = testTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];
9999

@@ -118,7 +118,7 @@ describe("Config list", () => {
118118
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-keys?packageKeys=key-1&packageKeys=key-2&withDependencies=false", [{...firstPackage}, {...secondPackage}]);
119119
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", [studioPackage]);
120120

121-
await new ConfigCommand().listActivePackages(true, [], false, [firstPackage.key, secondPackage.key]);
121+
await new ConfigCommand().listActivePackages(true, [], false, [firstPackage.key, secondPackage.key], null, null);
122122

123123
const expectedFileName = testTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];
124124

@@ -164,7 +164,7 @@ describe("Config list", () => {
164164
};
165165
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/compute-pools/data-models/details", [dataModelDetailResponse]);
166166

167-
await new ConfigCommand().listActivePackages(true, [], true, [firstPackage.key, secondPackage.key]);
167+
await new ConfigCommand().listActivePackages(true, [], true, [firstPackage.key, secondPackage.key], null, null);
168168

169169
const expectedFileName = testTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];
170170

@@ -179,4 +179,37 @@ describe("Config list", () => {
179179
expect(exportedSecondPackage).toEqual(secondPackage);
180180
expect(exportedFirstPackage).toEqual({...firstPackage, datamodels: [{...dataModelDetailResponse}]});
181181
})
182+
183+
it("Should list all packages filtered by variable value", async () => {
184+
const firstPackage = PackageManagerApiUtils.buildPackageExportTransport("key-1", "name-1");
185+
const secondPackage = PackageManagerApiUtils.buildPackageExportTransport("key-2", "name-2");
186+
187+
188+
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-variable-value?variableValue=1", [{...firstPackage}, {...secondPackage}]);
189+
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", []);
190+
191+
await new ConfigCommand().listActivePackages(false, [], false, [], "1", null);
192+
193+
expect(testTransport.logMessages.length).toBe(2);
194+
expect(testTransport.logMessages[0].message).toContain(`${firstPackage.name} - Key: "${firstPackage.key}"`);
195+
expect(testTransport.logMessages[1].message).toContain(`${secondPackage.name} - Key: "${secondPackage.key}"`);
196+
})
197+
198+
it("Should export all packages for json response filtered by variable value", async () => {
199+
const firstPackage = PackageManagerApiUtils.buildPackageExportTransport("key-1", "name-1");
200+
const secondPackage = PackageManagerApiUtils.buildPackageExportTransport("key-2", "name-2");
201+
202+
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/core/packages/export/list-by-variable-value?variableValue=1", [{...firstPackage}, {...secondPackage}]);
203+
mockAxiosGet("https://myTeam.celonis.cloud/package-manager/api/packages/with-variable-assignments?type=DATA_MODEL", []);
204+
205+
await new ConfigCommand().listActivePackages(true, [], false, [], "1", null);
206+
207+
const expectedFileName = testTransport.logMessages[0].message.split(FileService.fileDownloadedMessage)[1];
208+
209+
expect(mockWriteFileSync).toHaveBeenCalledWith(path.resolve(process.cwd(), expectedFileName), expect.any(String), {encoding: "utf-8"});
210+
211+
const exportedTransports = JSON.parse(mockWriteFileSync.mock.calls[0][1]) as PackageExportTransport[];
212+
expect(exportedTransports.length).toBe(2);
213+
})
214+
182215
})

0 commit comments

Comments
 (0)