integrate search new javascript api

This commit is contained in:
Eugenio Romano
2016-07-11 16:58:15 +01:00
parent 8c84bc9be5
commit 0e4a401e7f
7 changed files with 17 additions and 15 deletions

View File

@@ -19,6 +19,7 @@ import { Observable } from 'rxjs/Rx';
export interface AbstractAuthentication { export interface AbstractAuthentication {
TYPE: string; TYPE: string;
alfrescoApi: any;
login(username: string, password: string): Observable<any>; login(username: string, password: string): Observable<any>;

View File

@@ -23,6 +23,8 @@ declare let AlfrescoApi: any;
export class AlfrescoAuthenticationBase { export class AlfrescoAuthenticationBase {
alfrescoApi: any;
private _authUrl: string = '/alfresco/api/-default-/public/authentication/versions/1'; private _authUrl: string = '/alfresco/api/-default-/public/authentication/versions/1';
private alfrescoSetting: AlfrescoSettingsService; private alfrescoSetting: AlfrescoSettingsService;
/** /**

View File

@@ -99,7 +99,7 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
} }
/** /**
* The method return tru if the user is logged in * The method return true if the user is logged in
* @returns {boolean} * @returns {boolean}
*/ */
isLoggedIn(type: string = 'ECM'): boolean { isLoggedIn(type: string = 'ECM'): boolean {
@@ -110,6 +110,10 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
return false; return false;
} }
getAlfrescoApi(): any {
return this.findProviderInstance('ECM').alfrescoApi;
}
/** /**
* Return the token stored in the localStorage of the specific provider type * Return the token stored in the localStorage of the specific provider type
* @param token * @param token
@@ -198,7 +202,7 @@ export class AlfrescoAuthenticationService extends AlfrescoAuthenticationBase {
let auth: AbstractAuthentication = null; let auth: AbstractAuthentication = null;
if (this.providersInstance && this.providersInstance.length !== 0) { if (this.providersInstance && this.providersInstance.length !== 0) {
this.providersInstance.forEach((provider) => { this.providersInstance.forEach((provider) => {
if (provider.TYPE === type) { if (provider.TYPE === type.toUpperCase()) {
auth = provider; auth = provider;
} }
}); });

View File

@@ -26,6 +26,8 @@ describe('AlfrescoContentService', () => {
let injector, service: AlfrescoContentService, authService: AlfrescoAuthenticationService; let injector, service: AlfrescoContentService, authService: AlfrescoAuthenticationService;
const nodeId = 'blah'; const nodeId = 'blah';
let DEFAULT_CONTEXT_PATH: string = '/alfresco';
let DEFAULT_BASE_API_PATH: string = '/api/-default-/public/alfresco/versions/1';
beforeEach(() => { beforeEach(() => {
injector = ReflectiveInjector.resolveAndCreate([ injector = ReflectiveInjector.resolveAndCreate([
@@ -47,8 +49,8 @@ describe('AlfrescoContentService', () => {
id: nodeId id: nodeId
} }
})).toBe( })).toBe(
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + AlfrescoSettingsService.DEFAULT_CONTEXT_PATH + AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + DEFAULT_CONTEXT_PATH +
AlfrescoSettingsService.DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/content' + DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/content' +
'?attachment=false&alf_ticket=' + authService.getTicket() '?attachment=false&alf_ticket=' + authService.getTicket()
); );
}); });
@@ -59,8 +61,8 @@ describe('AlfrescoContentService', () => {
id: nodeId id: nodeId
} }
})).toBe( })).toBe(
AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + AlfrescoSettingsService.DEFAULT_CONTEXT_PATH + AlfrescoSettingsService.DEFAULT_HOST_ADDRESS + DEFAULT_CONTEXT_PATH +
AlfrescoSettingsService.DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/renditions/doclib/content' + DEFAULT_BASE_API_PATH + '/nodes/' + nodeId + '/renditions/doclib/content' +
'?attachment=false&alf_ticket=' + authService.getTicket() '?attachment=false&alf_ticket=' + authService.getTicket()
); );
}); });

View File

@@ -37,11 +37,4 @@ describe('AlfrescoSettingsService', () => {
expect(service.host).toBe(address); expect(service.host).toBe(address);
}); });
it('should format api url', () => {
let address = 'http://192.168.0.1';
let expectedUrl =
`${address}${AlfrescoSettingsService.DEFAULT_CONTEXT_PATH}${AlfrescoSettingsService.DEFAULT_BASE_API_PATH}`;
service.host = address;
expect(service.getApiBaseUrl()).toBe(expectedUrl);
});
}); });

View File

@@ -81,7 +81,7 @@ class SearchDemo implements OnInit {
} }
login() { login() {
this.authService.login('admin', 'admin').subscribe( this.authService.login('admin', 'admin', ['ECM']).subscribe(
token => { token => {
console.log(token); console.log(token);
this.token = token; this.token = token;

View File

@@ -40,7 +40,7 @@ export class AlfrescoSearchService {
rootNodeId: nodeId, rootNodeId: nodeId,
nodeType: 'cm:content' nodeType: 'cm:content'
}; };
return this.authService.alfrescoApi.search.liveSearchNodes(term, opts); return this.authService.getAlfrescoApi().search.liveSearchNodes(term, opts);
} }
/** /**