refactor: policy requests and remove api policies
Closes:
Closes:
MODIFY
src/app/components/my-apps-summary/my-apps-summary.component.html
src/app/components/my-apps-summary/my-apps-summary.component.html
</div>
</div>
<div class="grid-divider"><div></div></div>
- <div
- *ngIf="
- contract!.policies.length > 0 && contract!.policies[0].probe;
- else noPolicies
- "
- class="policies">
+ <div *ngIf="contract!.policies.length > 0; else noPolicies" class="policies">
<ng-container *ngFor="let policy of contract!.policies">
<app-policy-card-light
[policy]="policy"

MODIFY
src/app/components/my-apps/my-apps.component.ts
src/app/components/my-apps/my-apps.component.ts
@@ -136,28 +136,39 @@ export class MyAppsComponent implements OnInit {
contract.plan.plan.id,
contract.plan.version
),
- this.policyService.getApiPolicies(
- orgId,
- contract.api.api.id,
- contract.api.version
- ),
+
this.backend.getManagedApiEndpoint(
orgId,
contract.api.api.id,
contract.api.version
),
- this.apiService.isApiDocAvailable(contract.api)
+ this.apiService.isApiDocAvailable(contract.api),
+ this.apiService.getApiImage(contract)
]).pipe(
- map(([planPolicies, apiPolicies, endpoint, docsAvailable]) => {
+ map(
+ ([
+ planPolicies,
+ endpoint,
+ docsAvailable,
+ apiSearchResult
+ ]) => {
+ planPolicies.forEach((planPolicy) => {
+ this.policyService.initPolicy(planPolicy);
+ });
+ this.apiImages.set(
+ contract.api.api.name,
+ apiSearchResult.beans[0].image
+ );
return {
...contract,
- policies: planPolicies.concat(apiPolicies),
+ policies: planPolicies,
section: 'summary',
managedEndpoint: endpoint.managedEndpoint,
docsAvailable: docsAvailable,
deletable: this.isDeleteAllowed(contract)
} as IContractExt;
- })
+ }
+ )
);
})
);
@@ -169,7 +180,6 @@ export class MyAppsComponent implements OnInit {
})
)
.subscribe((contracts) => {
- this.getApiImages(contracts);
this.stopMainRequest();
this.extractContracts(contracts);
this.fetchPolicyProbes();
@@ -185,13 +195,11 @@ export class MyAppsComponent implements OnInit {
.pipe(
catchError((err) => {
console.warn(err);
- this.policyService.initPolicy(policy);
return EMPTY;
})
)
.subscribe((probes: IPolicyProbe[]) => {
policy.probe = probes[0];
- this.policyService.initPolicy(policy);
this.policyService.setGaugeDataForPolicy(policy);
});
});
@@ -205,27 +213,6 @@ export class MyAppsComponent implements OnInit {
this.error = setError;
}
- // TODO: include this in to the main request chain. Reminder: ApiVersions do not have api.api.image property
- private getApiImages(contracts: IContractExt[]) {
- contracts.forEach((contract: IContractExt) => {
- const searchCriteria: ISearchCriteria = {
- filters: [
- { name: 'name', value: contract.api.api.name, operator: 'like' }
- ],
- paging: { page: 1, pageSize: 1 }
- };
-
- this.backend
- .searchApis(searchCriteria)
- .subscribe((apiSummaries: ISearchResultsApiSummary) => {
- this.apiImages.set(
- contract.api.api.name,
- apiSummaries.beans[0].image
- );
- });
- });
- }
-
/**
* Contracts will be stored in a map with schema {client.name:contract.version,contract-object}
* @param contracts

MODIFY
src/app/components/plan-card-list/plan-card-list.component.html
src/app/components/plan-card-list/plan-card-list.component.html
</div>
<div class="card-content" [ngSwitch]="plan.planId + ':' + plan.version">
<mat-list>
- <ng-container *ngIf="apiPolicies.length > 0">
- <mat-list-item *ngFor="let policy of apiPolicies">
+ <mat-list-item *ngFor="let policy of plan.planPolicies">
<p>
{{ policy.shortName }}
<span class="right">{{ policy.shortDescription }}</span>
</p>
</mat-list-item>
- <mat-divider></mat-divider>
- </ng-container>
- <ng-container *ngFor="let planPolicies of planPoliciesMap | keyvalue">
- <ng-container *ngSwitchCase="planPolicies.key">
- <mat-list-item *ngFor="let policy of planPolicies.value">
- <p>
- {{ policy.shortName }}
- <span class="right">{{ policy.shortDescription }}</span>
- </p>
- </mat-list-item>
- </ng-container>
- </ng-container>
</mat-list>
</div>
<div class="plan-card-actions">

MODIFY
src/app/components/plan-card-list/plan-card-list.component.ts
src/app/components/plan-card-list/plan-card-list.component.ts
@@ -5,10 +5,9 @@ import { SignUpService } from '../../services/sign-up/sign-up.service';
import { IApiPlanSummary } from '../../interfaces/ICommunication';
import { IPolicyExt } from '../../interfaces/IPolicy';
import { PolicyService } from '../../services/policy/policy.service';
-import { switchMap } from 'rxjs/operators';
-import { forkJoin } from 'rxjs';
-import { flatArray } from '../../shared/utility';
import { IApiVersionExt } from '../../interfaces/IApiVersionExt';
+import { KeycloakService } from 'keycloak-angular';
+import { map } from 'rxjs/operators';
@Component({
selector: 'app-plan-card-list',
@@ -27,7 +26,6 @@ export class PlanCardListComponent implements OnInit {
private router: Router
) {}
- planPoliciesMap = new Map<string, IPolicyExt[]>();
apiPolicies: IPolicyExt[] = [];
orgId = '';
apiId = '';
@@ -39,17 +37,7 @@ export class PlanCardListComponent implements OnInit {
}
onSignUp(plan: IApiPlanSummary): void {
- const policies: IPolicyExt[] = [];
- const planIdVersionMapped = plan.planId + ':' + plan.version;
- const foundPlanPolicies = this.planPoliciesMap.get(planIdVersionMapped);
-
- if (foundPlanPolicies) {
- policies.push(...foundPlanPolicies);
- }
- if (this.apiPolicies.length > 0) {
- policies.concat(this.apiPolicies);
- }
-
+ const policies: IPolicyExt[] = plan.planPolicies;
policies.forEach((policy: IPolicyExt) =>
this.policyService.initPolicy(policy)
);
@@ -67,45 +55,17 @@ export class PlanCardListComponent implements OnInit {
this.planService
.getPlans(this.orgId, this.apiId, this.apiVersion.version)
.pipe(
- switchMap((apiPlanSummaries: IApiPlanSummary[]) => {
- this.plans = apiPlanSummaries;
- return forkJoin(
- apiPlanSummaries.map((apiPlanSummary) => {
- return this.policyService.getPlanPolicies(
- this.orgId,
- apiPlanSummary.planId,
- apiPlanSummary.version
- );
- })
- );
- })
- )
- .subscribe((nestedExtendedPolicies: IPolicyExt[][]) => {
- const extendedPolicies: IPolicyExt[] = flatArray(
- nestedExtendedPolicies
- ) as IPolicyExt[];
- this.extractPolicies(extendedPolicies);
+ map((apiPlanSummaries: IApiPlanSummary[]) => {
+ apiPlanSummaries.forEach((apiPlanSummary) => {
+ apiPlanSummary.planPolicies.forEach((policy: IPolicyExt) => {
+ this.policyService.extendPolicy(policy);
});
- this.policyService
- .getApiPolicies(this.orgId, this.apiId, this.apiVersion.version)
- .subscribe((extendedApiPolicies: IPolicyExt[]) => {
- this.apiPolicies = this.apiPolicies.concat(extendedApiPolicies);
});
- }
-
- private extractPolicies(extendedPolicies: IPolicyExt[]) {
- extendedPolicies.forEach((extendedPolicy) => {
- const planIdVersionMapped =
- extendedPolicy.planId + ':' + extendedPolicy.planVersion;
- const foundPolicies = this.planPoliciesMap.get(planIdVersionMapped);
- if (foundPolicies) {
- this.planPoliciesMap.set(
- planIdVersionMapped,
- foundPolicies.concat(extendedPolicy)
- );
- } else {
- this.planPoliciesMap.set(planIdVersionMapped, [extendedPolicy]);
- }
+ return apiPlanSummaries;
+ })
+ )
+ .subscribe((apiPlanSummaries: IApiPlanSummary[]) => {
+ this.plans = apiPlanSummaries;
});
}
}

MODIFY
src/app/components/policy-card-light/policy-card-light.component.html
src/app/components/policy-card-light/policy-card-light.component.html
</mat-card-header>
<mat-card-content>
<div class="limit-flex">
+ <ng-container *ngIf="!policy.probe; else probe">
+ <div id="spinner" style="display: flex; justify-content: center">
+ <mat-spinner strokeWidth="3" diameter="40"></mat-spinner>
+ </div>
+ </ng-container>
+
+ <ng-template #probe>
<div>
<p
[innerHTML]="
<mat-icon>info</mat-icon>
</button>
</div>
+ </ng-template>
</div>
</mat-card-content>
</mat-card>

MODIFY
src/app/interfaces/ICommunication.ts
src/app/interfaces/ICommunication.ts
+import { IPolicyExt } from './IPolicy';
+
export interface IAction {
type:
| 'publishAPI'
@@ -186,6 +188,7 @@ export interface IApiPlanSummary {
planName: string;
planDescription: string;
version: string;
+ planPolicies: IPolicyExt[];
}
export interface IAuditEntry {

MODIFY
src/app/services/api/api.service.ts
src/app/services/api/api.service.ts
@@ -6,6 +6,7 @@ import {
IApiSummary,
IApiVersion,
IApiVersionSummary,
+ IContract,
ISearchCriteria,
ISearchResultsApiSummary
} from '../../interfaces/ICommunication';
@@ -81,6 +82,19 @@ export class ApiService {
);
}
+ // Reminder: ApiVersions do not have api.api.image property
+ // Therefore we need to use the search endpoint to receive the image
+ getApiImage(contract: IContract): Observable<ISearchResultsApiSummary> {
+ const searchCriteria: ISearchCriteria = {
+ filters: [
+ { name: 'name', value: contract.api.api.name, operator: 'like' }
+ ],
+ paging: { page: 1, pageSize: 1 }
+ };
+
+ return this.backendService.searchApis(searchCriteria);
+ }
+
handleError(error: HttpErrorResponse): Observable<never> {
let errorMessage = '';
if (error.error instanceof ErrorEvent) {

MODIFY
src/app/services/policy/policy.service.ts
src/app/services/policy/policy.service.ts
@@ -142,7 +142,7 @@ export class PolicyService {
);
}
- private extendPolicy(extendedPolicy: IPolicyExt) {
+ public extendPolicy(extendedPolicy: IPolicyExt): void {
const perTranslated = this.translator.instant('COMMON.PER') as string;
const policyConfig = this.getPolicyConfiguration(extendedPolicy);
const periodTranslated = this.getTranslationForPeriod(policyConfig.period);

refactor: policy requests and remove api policies
Closes: #52
Closes: #46