Commit b16711f4 authored by Yogi_Wang's avatar Yogi_Wang
Browse files

change promise to observable


Signed-off-by: default avatarYogi_Wang <yawang@vmware.com>
parent 41e290a1
......@@ -394,11 +394,11 @@ export class MyAccessLogService extends AccessLogService {
*
* @param {(number | string)} projectId
* @param {RequestQueryParams} [queryParams]
* @returns {(Observable<AccessLog[]> | Promise<AccessLog[]> | AccessLog[])}
* @returns {(Observable<AccessLog[]>)}
*
* @memberOf AccessLogService
*/
getAuditLogs(projectId: number | string, queryParams?: RequestQueryParams): Observable<AccessLog[]> | Promise<AccessLog[]> | AccessLog[]{
getAuditLogs(projectId: number | string, queryParams?: RequestQueryParams): Observable<AccessLog[]> {
...
}
......@@ -406,11 +406,11 @@ export class MyAccessLogService extends AccessLogService {
* Get the recent logs.
*
* @param {number} lines : Specify how many lines should be returned.
* @returns {(Observable<AccessLog[]> | Promise<AccessLog[]> | AccessLog[])}
* @returns {(Observable<AccessLog[]>)}
*
* @memberOf AccessLogService
*/
getRecentLogs(lines: number): Observable<AccessLog[]> | Promise<AccessLog[]> | AccessLog[]{
getRecentLogs(lines: number): Observable<AccessLog[]>{
...
}
}
......@@ -437,7 +437,7 @@ export class MyEndpointService extends EndpointService {
*
* @memberOf EndpointService
*/
getEndpoints(endpointName?: string, queryParams?: RequestQueryParams): Observable<Endpoint[]> | Promise<Endpoint[]> | Endpoint[] {
getEndpoints(endpointName?: string, queryParams?: RequestQueryParams): Observable<Endpoint[]> {
...
}
......@@ -449,7 +449,7 @@ export class MyEndpointService extends EndpointService {
*
* @memberOf EndpointService
*/
getEndpoint(endpointId: number | string): Observable<Endpoint> | Promise<Endpoint> | Endpoint {
getEndpoint(endpointId: number | string): Observable<Endpoint>{
...
}
......@@ -461,7 +461,7 @@ export class MyEndpointService extends EndpointService {
*
* @memberOf EndpointService
*/
createEndpoint(endpoint: Endpoint): Observable<any> | Promise<any> | any {
createEndpoint(endpoint: Endpoint): Observable<any> {
...
}
......@@ -474,7 +474,7 @@ export class MyEndpointService extends EndpointService {
*
* @memberOf EndpointService
*/
updateEndpoint(endpointId: number | string, endpoint: Endpoint): Observable<any> | Promise<any> | any {
updateEndpoint(endpointId: number | string, endpoint: Endpoint): Observable<any> {
...
}
......@@ -486,7 +486,7 @@ export class MyEndpointService extends EndpointService {
*
* @memberOf EndpointService
*/
deleteEndpoint(endpointId: number | string): Observable<any> | Promise<any> | any {
deleteEndpoint(endpointId: number | string): Observable<any> {
...
}
......@@ -498,7 +498,7 @@ export class MyEndpointService extends EndpointService {
*
* @memberOf EndpointService
*/
pingEndpoint(endpoint: Endpoint): Observable<any> | Promise<any> | any {
pingEndpoint(endpoint: Endpoint): Observable<any> {
...
}
......@@ -508,7 +508,7 @@ export class MyEndpointService extends EndpointService {
* @param {{number | string}} endpointId
* @returns {{Observable<any> | any}}
*/
getEndpointWithReplicationRules(endpointId: number | string): Observable<any> | Promise<any> | any {
getEndpointWithReplicationRules(endpointId: number | string): Observable<any> {
...
}
}
......@@ -534,11 +534,11 @@ export class MyReplicationService extends ReplicationService {
* @param {(number | string)} [projectId]
* @param {string} [ruleName]
* @param {RequestQueryParams} [queryParams]
* @returns {(Observable<ReplicationRule[]> | Promise<ReplicationRule[]> | ReplicationRule[])}
* @returns {(Observable<ReplicationRule[]>)}
*
* @memberOf ReplicationService
*/
getReplicationRules(projectId?: number | string, ruleName?: string, queryParams?: RequestQueryParams): Observable<ReplicationRule[]> | Promise<ReplicationRule[]> | ReplicationRule[] {
getReplicationRules(projectId?: number | string, ruleName?: string, queryParams?: RequestQueryParams): Observable<ReplicationRule[]> {
...
}
......@@ -546,11 +546,11 @@ export class MyReplicationService extends ReplicationService {
* Get the specified replication rule.
*
* @param {(number | string)} ruleId
* @returns {(Observable<ReplicationRule> | Promise<ReplicationRule> | ReplicationRule)}
* @returns {(Observable<ReplicationRule>)}
*
* @memberOf ReplicationService
*/
getReplicationRule(ruleId: number | string): Observable<ReplicationRule> | Promise<ReplicationRule> | ReplicationRule {
getReplicationRule(ruleId: number | string): Observable<ReplicationRule> {
...
}
......@@ -558,11 +558,11 @@ export class MyReplicationService extends ReplicationService {
* Create new replication rule.
*
* @param {ReplicationRule} replicationRule
* @returns {(Observable<any> | Promise<any> | any)}
* @returns {(Observable<any>)}
*
* @memberOf ReplicationService
*/
createReplicationRule(replicationRule: ReplicationRule): Observable<any> | Promise<any> | any {
createReplicationRule(replicationRule: ReplicationRule): Observable<any> {
...
}
......@@ -570,11 +570,11 @@ export class MyReplicationService extends ReplicationService {
* Update the specified replication rule.
*
* @param {ReplicationRule} replicationRule
* @returns {(Observable<any> | Promise<any> | any)}
* @returns {(Observable<any>)}
*
* @memberOf ReplicationService
*/
updateReplicationRule(replicationRule: ReplicationRule): Observable<any> | Promise<any> | any {
updateReplicationRule(replicationRule: ReplicationRule): Observable<any> {
...
}
......@@ -582,11 +582,11 @@ export class MyReplicationService extends ReplicationService {
* Delete the specified replication rule.
*
* @param {(number | string)} ruleId
* @returns {(Observable<any> | Promise<any> | any)}
* @returns {(Observable<any>)}
*
* @memberOf ReplicationService
*/
deleteReplicationRule(ruleId: number | string): Observable<any> | Promise<any> | any {
deleteReplicationRule(ruleId: number | string): Observable<any> {
...
}
......@@ -594,11 +594,11 @@ export class MyReplicationService extends ReplicationService {
* Enable the specified replication rule.
*
* @param {(number | string)} ruleId
* @returns {(Observable<any> | Promise<any> | any)}
* @returns {(Observable<any>)}
*
* @memberOf ReplicationService
*/
enableReplicationRule(ruleId: number | string, enablement: number): Observable<any> | Promise<any> | any {
enableReplicationRule(ruleId: number | string, enablement: number): Observable<any> {
...
}
......@@ -606,11 +606,11 @@ export class MyReplicationService extends ReplicationService {
* Disable the specified replication rule.
*
* @param {(number | string)} ruleId
* @returns {(Observable<any> | Promise<any> | any)}
* @returns {(Observable<any>)}
*
* @memberOf ReplicationService
*/
disableReplicationRule(ruleId: number | string): Observable<any> | Promise<any> | any {
disableReplicationRule(ruleId: number | string): Observable<any> {
...
}
......@@ -625,11 +625,11 @@ export class MyReplicationService extends ReplicationService {
*
* @param {(number | string)} ruleId
* @param {RequestQueryParams} [queryParams]
* @returns {(Observable<ReplicationJob> | Promise<ReplicationJob[]> | ReplicationJob)}
* @returns {(Observable<ReplicationJob>)}
*
* @memberOf ReplicationService
*/
getJobs(ruleId: number | string, queryParams?: RequestQueryParams): Observable<ReplicationJob[]> | Promise<ReplicationJob[]> | ReplicationJob[] {
getJobs(ruleId: number | string, queryParams?: RequestQueryParams): Observable<ReplicationJob[]> {
...
}
}
......@@ -656,11 +656,11 @@ export class MyRepositoryService extends RepositoryService {
* @param {(number | string)} projectId
* @param {string} repositoryName
* @param {RequestQueryParams} [queryParams]
* @returns {(Observable<Repository[]> | Promise<Repository[]> | Repository[])}
* @returns {(Observable<Repository[]>)}
*
* @memberOf RepositoryService
*/
getRepositories(projectId: number | string, repositoryName?: string, queryParams?: RequestQueryParams): Observable<Repository[]> | Promise<Repository[]> | Repository[] {
getRepositories(projectId: number | string, repositoryName?: string, queryParams?: RequestQueryParams): Observable<Repository[]> {
...
}
......@@ -668,11 +668,11 @@ export class MyRepositoryService extends RepositoryService {
* DELETE the specified repository.
*
* @param {string} repositoryName
* @returns {(Observable<any> | Promise<any> | any)}
* @returns {(Observable<any>)}
*
* @memberOf RepositoryService
*/
deleteRepository(repositoryName: string): Observable<any> | Promise<any> | any {
deleteRepository(repositoryName: string): Observable<any> {
...
}
}
......@@ -694,11 +694,11 @@ export class MyTagService extends TagService {
*
* @param {string} repositoryName
* @param {RequestQueryParams} [queryParams]
* @returns {(Observable<Tag[]> | Promise<Tag[]> | Tag[])}
* @returns {(Observable<Tag[]>)}
*
* @memberOf TagService
*/
getTags(repositoryName: string, queryParams?: RequestQueryParams): Observable<Tag[]> | Promise<Tag[]> | Tag[] {
getTags(repositoryName: string, queryParams?: RequestQueryParams): Observable<Tag[]> {
...
}
......@@ -711,7 +711,7 @@ export class MyTagService extends TagService {
*
* @memberOf TagService
*/
deleteTag(repositoryName: string, tag: string): Observable<any> | Promise<Tag> | any {
deleteTag(repositoryName: string, tag: string): Observable<any> {
...
}
}
......@@ -738,11 +738,11 @@ export class MyScanningResultService extends ScanningResultService {
* Get the summary of vulnerability scanning result.
*
* @param {string} tagId
* @returns {(Observable<VulnerabilitySummary> | Promise<VulnerabilitySummary> | VulnerabilitySummary)}
* @returns {(Observable<VulnerabilitySummary>)}
*
* @memberOf ScanningResultService
*/
getVulnerabilityScanningSummary(repoName: string, tagId: string, queryParams?: RequestQueryParams): Observable<VulnerabilitySummary> | Promise<VulnerabilitySummary> | VulnerabilitySummary{
getVulnerabilityScanningSummary(repoName: string, tagId: string, queryParams?: RequestQueryParams): Observable<VulnerabilitySummary> {
...
}
......@@ -750,11 +750,11 @@ export class MyScanningResultService extends ScanningResultService {
* Get the detailed vulnerabilities scanning results.
*
* @param {string} tagId
* @returns {(Observable<VulnerabilityItem[]> | Promise<VulnerabilityItem[]> | VulnerabilityItem[])}
* @returns {(Observable<VulnerabilityItem[]>)}
*
* @memberOf ScanningResultService
*/
getVulnerabilityScanningResults(repoName: string, tagId: string, queryParams?: RequestQueryParams): Observable<VulnerabilityItem[]> | Promise<VulnerabilityItem[]> | VulnerabilityItem[]{
getVulnerabilityScanningResults(repoName: string, tagId: string, queryParams?: RequestQueryParams): Observable<VulnerabilityItem[]> {
...
}
......@@ -764,11 +764,11 @@ export class MyScanningResultService extends ScanningResultService {
*
* @param {string} repoName
* @param {string} tagId
* @returns {(Observable<any> | Promise<any> | any)}
* @returns {(Observable<any>)}
*
* @memberOf ScanningResultService
*/
startVulnerabilityScanning(repoName: string, tagId: string): Observable<any> | Promise<any> | any {
startVulnerabilityScanning(repoName: string, tagId: string): Observable<any> {
...
}
}
......@@ -792,7 +792,7 @@ export class MySystemInfoService extends SystemInfoService {
* Get global system information.
* @returns
*/
getSystemInfo(): Observable<SystemInfo> | Promise<SystemInfo> | SystemInfo {
getSystemInfo(): Observable<SystemInfo> {
...
}
}
......@@ -820,11 +820,11 @@ export class MyConfigurationService extends ConfigurationService{
* Get configurations.
*
* @returns {(Observable<Configuration> | Promise<Configuration> | Configuration)}
* @returns {(Observable<Configuration>)}
*
* @memberOf ConfigurationService
*/
getConfigurations(): Observable<Configuration> | Promise<Configuration> | Configuration{
getConfigurations(): Observable<Configuration> {
...
}
......@@ -832,11 +832,11 @@ export class MyConfigurationService extends ConfigurationService{
* Save configurations.
*
* @returns {(Observable<Configuration> | Promise<Configuration> | Configuration)}
* @returns {(Observable<Configuration>)}
*
* @memberOf ConfigurationService
*/
saveConfigurations(changedConfigs: any | { [key: string]: any | any[] }): Observable<any> | Promise<any> | any{
saveConfigurations(changedConfigs: any | { [key: string]: any | any[] }): Observable<any> {
...
}
}
......
......@@ -21,6 +21,7 @@ import {
SystemInfo
} from '../service/index';
import { Configuration } from './config';
import { of } from 'rxjs';
describe('RegistryConfigComponent (inline template)', () => {
......@@ -84,8 +85,8 @@ describe('RegistryConfigComponent (inline template)', () => {
cfgService = fixture.debugElement.injector.get(ConfigurationService);
systemInfoService = fixture.debugElement.injector.get(SystemInfoService);
spy = spyOn(cfgService, 'getConfigurations').and.returnValue(Promise.resolve(mockConfig));
spySystemInfo = spyOn(systemInfoService, 'getSystemInfo').and.returnValue(Promise.resolve(mockSystemInfo));
spy = spyOn(cfgService, 'getConfigurations').and.returnValue(of(mockConfig));
spySystemInfo = spyOn(systemInfoService, 'getSystemInfo').and.returnValue(of(mockSystemInfo));
fixture.detectChanges();
});
......@@ -100,7 +101,7 @@ describe('RegistryConfigComponent (inline template)', () => {
let el: HTMLInputElement = fixture.nativeElement.querySelector('input[type="text"]');
expect(el).not.toBeFalsy();
expect(el.value).toEqual('30');
expect(el.value).toEqual('90');
fixture.detectChanges();
......
......@@ -7,7 +7,6 @@ import { ConfirmationMessage } from '../confirmation-dialog/confirmation-message
import { ConfirmationAcknowledgement } from '../confirmation-dialog/confirmation-state-message';
import { ConfigurationService, SystemInfoService, SystemInfo } from '../service/index';
import {
toPromise,
compareValue,
isEmptyObject,
clone
......@@ -15,6 +14,7 @@ import {
import { ErrorHandler } from '../error-handler/index';
import { SystemSettingsComponent, VulnerabilityConfigComponent, GcComponent} from './index';
import { Configuration } from './config';
import { map, catchError } from "rxjs/operators";
@Component({
selector: 'hbr-registry-config',
......@@ -75,21 +75,21 @@ export class RegistryConfigComponent implements OnInit {
// Get system info
loadSystemInfo(): void {
toPromise<SystemInfo>(this.systemInfoService.getSystemInfo())
.then((info: SystemInfo) => this.systemInfo = info)
.catch(error => this.errorHandler.error(error));
this.systemInfoService.getSystemInfo()
.subscribe((info: SystemInfo) => {
this.systemInfo = info;
}, error => this.errorHandler.error(error));
}
// Load configurations
load(): void {
this.onGoing = true;
toPromise<Configuration>(this.configService.getConfigurations())
.then((config: Configuration) => {
this.configService.getConfigurations()
.subscribe((config: Configuration) => {
this.configCopy = clone(config);
this.config = config;
this.onGoing = false;
})
.catch(error => {
}, error => {
this.errorHandler.error(error);
this.onGoing = false;
});
......@@ -105,8 +105,8 @@ export class RegistryConfigComponent implements OnInit {
}
this.onGoing = true;
toPromise<any>(this.configService.saveConfigurations(changes))
.then(() => {
this.configService.saveConfigurations(changes)
.subscribe(() => {
this.onGoing = false;
this.translate.get("CONFIG.SAVE_SUCCESS").subscribe((res: string) => {
......@@ -116,8 +116,8 @@ export class RegistryConfigComponent implements OnInit {
this.load();
// Reload all system info
// this.loadSystemInfo();
})
.catch(error => {
}
, error => {
this.onGoing = false;
this.errorHandler.error(error);
});
......
......@@ -2,7 +2,7 @@ import { Component, Input, OnInit, Output, EventEmitter, ViewChild, Inject, OnCh
import { NgForm } from '@angular/forms';
import { Configuration, StringValueItem } from '../config';
import { SERVICE_CONFIG, IServiceConfig } from '../../service.config';
import { clone, isEmpty, getChanges, toPromise } from '../../utils';
import { clone, isEmpty, getChanges } from '../../utils';
import { ErrorHandler } from '../../error-handler/index';
import { ConfirmationMessage } from '../../confirmation-dialog/confirmation-message';
import { ConfirmationDialogComponent } from '../../confirmation-dialog/confirmation-dialog.component';
......@@ -115,7 +115,7 @@ export class SystemSettingsComponent implements OnChanges, OnInit {
if (!isEmpty(changes)) {
this.onGoing = true;
this.configService.saveConfigurations(changes)
.then(response => {
.subscribe(response => {
this.onGoing = false;
// API should return the updated configurations here
// Unfortunately API does not do that
......@@ -129,8 +129,8 @@ export class SystemSettingsComponent implements OnChanges, OnInit {
this.reloadSystemConfig.emit();
this.errorHandler.info('CONFIG.SAVE_SUCCESS');
})
.catch(error => {
}
, error => {
this.onGoing = false;
this.errorHandler.error(error);
});
......@@ -142,7 +142,7 @@ export class SystemSettingsComponent implements OnChanges, OnInit {
retrieveConfig(): void {
this.onGoing = true;
from(toPromise(this.configService.getConfigurations()))
this.configService.getConfigurations()
.subscribe((configurations: Configuration) => {
this.onGoing = false;
// Add two password fields
......
import { Component, Input, Output, EventEmitter, ViewChild, OnInit } from '@angular/core';
import { NgForm } from '@angular/forms';
import { map, catchError } from "rxjs/operators";
import { Observable, throwError as observableThrowError, of } from "rxjs";
import { Configuration } from '../config';
import {
ScanningResultService,
......@@ -9,7 +10,7 @@ import {
ConfigurationService
} from '../../service/index';
import { ErrorHandler } from '../../error-handler/index';
import { toPromise, isEmptyObject, clone} from '../../utils';
import { isEmptyObject, clone} from '../../utils';
import { TranslateService } from '@ngx-translate/core';
import { ClairDetail } from '../../service/interface';
const ONE_HOUR_SECONDS: number = 3600;
......@@ -241,12 +242,11 @@ export class VulnerabilityConfigComponent implements OnInit {
}
getConfigurations(): void {
toPromise<Configuration>(this.configService.getConfigurations())
.then((config: Configuration) => {
this.configService.getConfigurations()
.subscribe((config: Configuration) => {
this.configCopy = clone(config);
this.config = config;
})
.catch(error => {
}, error => {
this.errorHandler.error(error);
});
}
......@@ -272,20 +272,20 @@ export class VulnerabilityConfigComponent implements OnInit {
}
this.onSubmitting = true;
toPromise<any>(this.scanningService.startScanningAll())
.then(() => {
this.scanningService.startScanningAll()
.subscribe(() => {
this.translate.get("CONFIG.SCANNING.TRIGGER_SCAN_ALL_SUCCESS").subscribe((res: string) => {
this.errorHandler.info(res);
});
// Update system info
this.getSystemInfo().then(() => {
this.getSystemInfo().subscribe(() => {
this.onSubmitting = false;
}).catch(() => {
}, error => {
this.onSubmitting = false;
});
})
.catch(error => {
}
, error => {
if (error && error.status && error.status === 412) {
this.translate.get("CONFIG.SCANNING.TRIGGER_SCAN_ALL_FAIL", { error: '' + error }).subscribe((res: string) => {
this.errorHandler.error(res);
......@@ -297,10 +297,13 @@ export class VulnerabilityConfigComponent implements OnInit {
});
}
getSystemInfo(): Promise<void | SystemInfo> {
return toPromise<SystemInfo>(this.systemInfoService.getSystemInfo())
.then((info: SystemInfo) => this.systemInfo = info)
.catch(error => this.errorHandler.error(error));
getSystemInfo(): Observable<void | SystemInfo> {
return this.systemInfoService.getSystemInfo()
.pipe(map((info: SystemInfo) => this.systemInfo = info)
, catchError(error => {
this.errorHandler.error(error);
return of();
}));
}
save(): void {
......@@ -311,17 +314,14 @@ export class VulnerabilityConfigComponent implements OnInit {
return;
}
toPromise<any>(this.configService.saveConfigurations(changes))
.then(() => {
this.configService.saveConfigurations(changes)
.subscribe(() => {
this.translate.get("CONFIG.SAVE_SUCCESS").subscribe((res: string) => {
this.errorHandler.info(res);
});
this.getConfigurations();
this.isEditMode = false;
}, () => {
this.reset();
})
.catch(error => {
}, error => {
this.errorHandler.error(error);
this.reset();
});
......
......@@ -18,6 +18,7 @@ import {
EndpointDefaultService
} from "../service/endpoint.service";
import { IServiceConfig, SERVICE_CONFIG } from "../service.config";
import { of } from "rxjs";
describe("CreateEditEndpointComponent (inline template)", () => {
let mockData: Endpoint = {
id: 1,
......@@ -62,7 +63,7 @@ describe("CreateEditEndpointComponent (inline template)", () => {
endpointService = fixture.debugElement.injector.get(EndpointService);
spy = spyOn(endpointService, "getEndpoint").and.returnValue(
Promise.resolve(mockData)
of(mockData)
);
fixture.detectChanges();
......
......@@ -28,7 +28,7 @@ import { EndpointService } from "../service/endpoint.service";
import { ErrorHandler } from "../error-handler/index";
import { InlineAlertComponent } from "../inline-alert/inline-alert.component";
import { Endpoint } from "../service/interface";
import { toPromise, clone, compareValue, isEmptyObject } from "../utils";
import { clone, compareValue, isEmptyObject } from "../utils";
const FAKE_PASSWORD = "rjGcfuRu";
......@@ -153,8 +153,8 @@ export class CreateEditEndpointComponent
this.translateService
.get("DESTINATION.TITLE_EDIT")
.subscribe(res => (this.modalTitle = res));
toPromise<Endpoint>(this.endpointService.getEndpoint(targetId))
.then(target => {
this.endpointService.getEndpoint(targetId)
.subscribe(target => {
this.target = target;
// Keep data cache
this.initVal = clone(target);
......@@ -164,8 +164,7 @@ export class CreateEditEndpointComponent
// Open the modal now
this.open();
this.forceRefreshView(2000);
})
.catch(error => this.errorHandler.error(error));
}, error => this.errorHandler.error(error));
} else {
this.endpointId = "";
this.translateService
......@@ -198,15 +197,14 @@ export class CreateEditEndpointComponent
}
this.testOngoing = true;
toPromise<Endpoint>(this.endpointService.pingEndpoint(payload))
.then(response => {
this.endpointService.pingEndpoint(payload)
.subscribe(response => {
this.inlineAlert.showInlineSuccess({
message: "DESTINATION.TEST_CONNECTION_SUCCESS"
});
this.forceRefreshView(2000);
this.testOngoing = false;
})