Skip to content

Commit

Permalink
register multiple repos
Browse files Browse the repository at this point in the history
  • Loading branch information
ck-c8y committed Nov 29, 2023
1 parent 26b98ca commit 148ad35
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 37 deletions.
22 changes: 22 additions & 0 deletions analytics-ui/src/sample/editor/repository.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import { BehaviorSubject, Observable } from "rxjs";
import {
ANALYTICS_REPOSITORIES_TYPE,
REPO_SAMPLES_BLOCKSDK,
REPO_SAMPLES_CONTRIB_BLOCK,
REPO_SAMPLES_CONTRIB_CUMULOCITY,
REPO_SAMPLES_CONTRIB_SIMULATION,
Repository,
uuidCustom,
} from "../../shared/analytics.model";
Expand Down Expand Up @@ -81,6 +84,25 @@ export class RepositoryService {
id: uuidCustom(),
name: "Block SDK Samples",
url: REPO_SAMPLES_BLOCKSDK,
enabled: true
},
{
id: uuidCustom(),
name: "Contrib Samples Block",
url: REPO_SAMPLES_CONTRIB_BLOCK,
enabled: false
},
{
id: uuidCustom(),
name: "Contrib Samples Simulation-Block",
url: REPO_SAMPLES_CONTRIB_SIMULATION,
enabled: false
},
{
id: uuidCustom(),
name: "Contrib Samples Cumulocity-Block",
url: REPO_SAMPLES_CONTRIB_CUMULOCITY,
enabled: false
},
] as Repository[];
this.inventoryService.create(reposMO);
Expand Down
4 changes: 2 additions & 2 deletions analytics-ui/src/sample/list/sample.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export class SampleGridComponent implements OnInit {

async viewMonitor(block: CEP_Block) {
try {
this.source = await this.analyticsService.getBlock_Sample_Content(
block.name
this.source = await this.analyticsService.getCEP_BlockContent(
block.url
);
} catch (error) {
console.log("Something happended:", error);
Expand Down
11 changes: 7 additions & 4 deletions analytics-ui/src/shared/analytics.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,14 @@ export interface CEP_Extension {

export interface CEP_Block {
id: string;
name: string;
producesOutput: string;
description: string;
url: string;
downloadUrl: string;
path: string;
custom: boolean;
extension: string;
name: string;
repositoryName: string;
category: Category;
}
Expand All @@ -86,10 +88,11 @@ export const PATH_CEP_STATUS = `${PATH_CEP_DIAGNOSTICS}/apamaCtrlStatus`;
export const STATUS_MESSAGE_01 = "Recording apama-ctrl safe mode state";

export const GITHUB_BASE = "https://api.github.com";
export const REPO_SAMPLES_NAME = "apama-analytics-builder-block-sdk";
export const REPO_SAMPLES_OWNER = "SoftwareAG";
export const REPO_SAMPLES_PATH = "samples/blocks";
export const REPO_SAMPLES_BLOCKSDK = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/${REPO_SAMPLES_NAME}/contents/${REPO_SAMPLES_PATH}`;
export const REPO_SAMPLES_BLOCKSDK = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/apama-analytics-builder-block-sdk/contents/samples/blocks`;
export const REPO_SAMPLES_CONTRIB_BLOCK = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/analytics-builder-blocks-contrib/contents/blocks`;
export const REPO_SAMPLES_CONTRIB_CUMULOCITY = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/analytics-builder-blocks-contrib/contents/cumulocity-blocks`;
export const REPO_SAMPLES_CONTRIB_SIMULATION = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/analytics-builder-blocks-contrib/contents/simulation-blocks`;

export const BASE_URL = "service/analytics-ext-service";
export const ENDPOINT_EXTENSION = "extension";
Expand Down
46 changes: 15 additions & 31 deletions analytics-ui/src/shared/analytics.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,9 @@ import {
CEP_Block,
CEP_Extension,
CEP_Metadata,
GITHUB_BASE,
PATH_CEP_EN,
PATH_CEP_METADATA_EN,
PATH_CEP_STATUS,
REPO_SAMPLES_OWNER,
REPO_SAMPLES_NAME,
REPO_SAMPLES_PATH,
STATUS_MESSAGE_01,
BASE_URL,
ENDPOINT_EXTENSION,
Expand Down Expand Up @@ -167,18 +163,6 @@ export class AnalyticsService {
return flattened;
});
return result;
// const result = promises.reduce(
// (acc, promise) =>
// acc.then((data) => {
// promise.then((blocks) => {
// data.push(...blocks);
// return data;
// });
// return data;
// }),
// Promise.resolve([]) // as Promise<CEP_Block[]>
// );
// return result;
}

async getCEP_BlockSamplesFromRepository(
Expand All @@ -196,6 +180,14 @@ export class AnalyticsService {
name.forEach((b) => {
b.id = b.sha;
b.repositoryName = rep.name;
b.custom = true;
b.downloadUrl = b.download_url;
delete b.download_url;
delete b.html_url;
delete b.git_url;
delete b._links;
delete b.size;
delete b.sha;
});
return name;
}),
Expand All @@ -217,27 +209,19 @@ export class AnalyticsService {
error.error
);
}
// Return an observable with a user-facing error message.
//return throwError(() => new Error('Something bad happened; please try again later.'));
return EMPTY;
}

async getBlock_Sample_Content(name: string): Promise<string> {
const sampleUrl = `${GITHUB_BASE}/repos/${REPO_SAMPLES_OWNER}/${REPO_SAMPLES_NAME}/contents/${REPO_SAMPLES_PATH}/${name}`;
async getCEP_BlockContent(downloadUrl: string): Promise<string> {
const result: any = this.githubFetchClient
.get(sampleUrl, {
.get(downloadUrl, {
headers: {
// "content-type": "application/json",
"content-type": "application/text",
Accept: "application/vnd.github.raw",
// "content-type": "application/json",
"Content-type": "application/text",
Accept: "application/vnd.github.raw",
},
responseType: "text",
})
// .pipe(
// map((data) => {
// const name = _.values(data);
// return name;
// }),)
.toPromise();
return result;
}
Expand Down Expand Up @@ -270,7 +254,7 @@ export class AnalyticsService {
return data;
}

async getCEPId(): Promise<string> {
async getCEP_Id(): Promise<string> {
if (!this._cepId) {
this._cepId = this.getUncachedCEP_Id();
}
Expand Down Expand Up @@ -309,7 +293,7 @@ export class AnalyticsService {
}

async subscribeMonitoringChannel(): Promise<object> {
const cepId = await this.getCEPId();
const cepId = await this.getCEP_Id();
console.log("Started subscription:", cepId);

const sub = this.realtime.subscribe(
Expand Down

0 comments on commit 148ad35

Please sign in to comment.