observer on setting change

This commit is contained in:
Eugenio Romano
2016-08-18 13:16:23 +01:00
parent 124b6971ac
commit 984f6d5822
5 changed files with 83 additions and 16 deletions

View File

@@ -30,7 +30,6 @@ export class ActivitiTaskListService {
constructor(public authService: AlfrescoAuthenticationService) {
}
/**
* Retrive all the Deployed app
* @returns {Observable<any>}
@@ -55,7 +54,7 @@ export class ActivitiTaskListService {
filters.push(filterModel);
});
return filters;
});
}).catch(this.handleError);
}
/**
@@ -67,7 +66,7 @@ export class ActivitiTaskListService {
return Observable.fromPromise(this.callApiTasksFiltered(filter.filter))
.map((res: any) => {
return res;
});
}).catch(this.handleError);
}
/**
@@ -80,7 +79,7 @@ export class ActivitiTaskListService {
.map(res => res)
.map((details: any) => {
return new TaskDetailsModel(details);
});
}).catch(this.handleError);
}
/**
@@ -99,7 +98,7 @@ export class ActivitiTaskListService {
comments.push(new Comment(comment.id, comment.message, comment.created, user));
});
return comments;
});
}).catch(this.handleError);
}
/**
@@ -116,7 +115,7 @@ export class ActivitiTaskListService {
checklists.push(new TaskDetailsModel(checklist));
});
return checklists;
});
}).catch(this.handleError);
}
/**
@@ -129,7 +128,7 @@ export class ActivitiTaskListService {
.map(res => res)
.map((response: TaskDetailsModel) => {
return new TaskDetailsModel(response);
});
}).catch(this.handleError);
}
/**
@@ -143,7 +142,8 @@ export class ActivitiTaskListService {
.map(res => res)
.map((response: Comment) => {
return new Comment(response.id, response.message, response.created, response.createdBy);
});
}).catch(this.handleError);
}
/**
@@ -192,4 +192,8 @@ export class ActivitiTaskListService {
return this.authService.getAlfrescoApi().activiti.taskApi.completeTask(id);
}
private handleError(error: any) {
console.error(error);
return Observable.throw(error || 'Server error');
}
}

View File

@@ -87,6 +87,7 @@ describe('AlfrescoAuthentication', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.alfrescoSetting.setProviders('ECM');
});
it('should return an ECM ticket after the login done', (done) => {
@@ -157,7 +158,7 @@ describe('AlfrescoAuthentication', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.providers = 'BPM';
authService.alfrescoSetting.setProviders('BPM');
});
@@ -214,6 +215,44 @@ describe('AlfrescoAuthentication', () => {
});
});
describe('Setting service change should reflect in the api', () => {
beforeEach(() => {
authService = injector.get(AlfrescoAuthenticationService);
authService.alfrescoSetting.setProviders('ALL');
spyOn(AlfrescoAuthenticationService.prototype, 'callApiLogin').and.returnValue(fakePromiseBPMECM);
});
it('should host ecm url change be reflected in the api configuration', (done) => {
authService.alfrescoSetting.ecmHost = '127.99.99.99';
authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.getAlfrescoApi().config.host).toBe('127.99.99.99');
done();
});
});
it('should host bpm url change be reflected in the api configuration', (done) => {
authService.alfrescoSetting.bpmHost = '127.99.99.99';
authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.getAlfrescoApi().config.hostActiviti).toBe('127.99.99.99');
done();
});
});
it('should host bpm provider change be reflected in the api configuration', (done) => {
authService.alfrescoSetting.setProviders('ECM');
authService.login('fake-username', 'fake-password').subscribe(() => {
expect(authService.getAlfrescoApi().config.provider).toBe('ECM');
done();
});
});
});
describe('when the setting is both ECM and BPM ', () => {
beforeEach(() => {

View File

@@ -36,10 +36,22 @@ export class AlfrescoAuthenticationService {
constructor(public alfrescoSetting: AlfrescoSettingsService) {
this.alfrescoApi = new AlfrescoApi({
provider: this.alfrescoSetting.getProviders(),
ticket: this.isLoggedIn() ? this.getTicket() : null,
ticket: this.isLoggedIn() ? this.getTicket().split(',')[0] : null,
host: this.alfrescoSetting.ecmHost,
hostActiviti: this.alfrescoSetting.bpmHost
});
alfrescoSetting.bpmHostSubject.subscribe((value) => {
this.alfrescoApi.config.hostActiviti = value;
});
alfrescoSetting.ecmHostSubject.subscribe((value) => {
this.alfrescoApi.config.host = value;
});
alfrescoSetting.providerSubject.subscribe((value) => {
this.alfrescoApi.config.provider = value;
});
}
/**
@@ -80,7 +92,6 @@ export class AlfrescoAuthenticationService {
* @returns {*|Observable<any>}
*/
private callApiLogin(username: string, password: string) {
this.alfrescoApi.config.provider = this.alfrescoSetting.getProviders();
return this.alfrescoApi.login(username, password);
}

View File

@@ -16,6 +16,7 @@
*/
import { Injectable } from '@angular/core';
import { Subject } from 'rxjs/Subject';
@Injectable()
export class AlfrescoSettingsService {
@@ -32,20 +33,26 @@ export class AlfrescoSettingsService {
private providers: string = 'ALL'; // ECM, BPM , ALL
bpmHostSubject: Subject<string> = new Subject<string>();
ecmHostSubject: Subject<string> = new Subject<string>();
providerSubject: Subject<string> = new Subject<string>();
public get ecmHost(): string {
return this._ecmHost;
}
public set ecmHost(value: string) {
this._ecmHost = value;
public set ecmHost(ecmHostUrl: string) {
this.ecmHostSubject.next(ecmHostUrl);
this._ecmHost = ecmHostUrl;
}
public get bpmHost(): string {
return this._bpmHost;
}
public set bpmHost(value: string) {
this._bpmHost = value;
public set bpmHost(bpmHostUrl: string) {
this.bpmHostSubject.next(bpmHostUrl);
this._bpmHost = bpmHostUrl;
}
public getBPMApiBaseUrl(): string {
@@ -57,7 +64,7 @@ export class AlfrescoSettingsService {
}
public setProviders(providers: string) {
this.providerSubject.next(providers);
this.providers = providers;
}
}

View File

@@ -41,4 +41,10 @@ in the demo shell:
./start-linked.sh
```
* If you want to build all your local component:
```sh
./npm-buid-alll.sh
```
For development environment configuration please refer to [project docs](demo-shell-ng2/README.md).