From 86e5b3f1e5fca6129266b4c699e159b73b6c0af9 Mon Sep 17 00:00:00 2001 From: Vito Albano Date: Mon, 19 Sep 2016 11:53:55 +0100 Subject: [PATCH] Add BPM user logged in --- .../ng2-alfresco-userinfo/demo/src/main.ts | 35 ++--- .../src/models/bpmUser.model.ts | 39 +++++ .../src/services/bpmUser.service.ts | 65 ++++++++ .../src/services/ecmUser.service.ts | 4 +- .../src/userinfo.component.html | 140 +++++++++++++++++- .../src/userinfo.component.ts | 41 +++-- 6 files changed, 288 insertions(+), 36 deletions(-) create mode 100644 ng2-components/ng2-alfresco-userinfo/src/models/bpmUser.model.ts create mode 100644 ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts diff --git a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts index 8801ffcb21..a7c5c03cb1 100644 --- a/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts +++ b/ng2-components/ng2-alfresco-userinfo/demo/src/main.ts @@ -11,7 +11,7 @@ import { @Component({ selector: 'my-app', - template: `

START

`, + template: `

START

`, directives: [ UserInfoComponent ], providers: [AlfrescoAuthenticationService, AlfrescoSettingsService] }) @@ -20,36 +20,31 @@ import { class UserInfoDemo implements OnInit { private authenticated: boolean; - private ticket: string; - // private ecmHost: string; + private token: any; constructor(private authService: AlfrescoAuthenticationService, private settingsService: AlfrescoSettingsService) { - this.settingsService.setProviders('ECM'); + this.settingsService.setProviders('ALL'); } public ngOnInit(): void { this.login(); } - login() { - this.authService.login('test', 'test').subscribe( - ticket => { - console.log(ticket); - this.ticket = this.authService.getTicketEcm(); - this.authenticated = true; - }, - error => { - console.log(error); - this.authenticated = false; - }); - } + login() { + this.authService.login('test', 'test').subscribe( + token => { + console.log(token); + this.token = token; + this.authenticated = true; + }, + error => { + console.log(error); + this.authenticated = false; + }); + } } - - - - bootstrap(UserInfoDemo, [ UserInfoComponent, HTTP_PROVIDERS, diff --git a/ng2-components/ng2-alfresco-userinfo/src/models/bpmUser.model.ts b/ng2-components/ng2-alfresco-userinfo/src/models/bpmUser.model.ts new file mode 100644 index 0000000000..3ee3fd7222 --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/src/models/bpmUser.model.ts @@ -0,0 +1,39 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +export class BpmUserModel { + apps: any; + capabilities: string; + company: string; + created: string; + email: string; + externalId: string; + firstName: string; + lastName: string; + fullname: string; + groups: any; + id: string; + lastUpdate: string; + latestSyncTimeStamp: string; + password: string; + pictureId: string; + status: string; + tenantId: string; + tenantName: string; + tenantPictureId: string; + type: string; +} diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts new file mode 100644 index 0000000000..593079a8cf --- /dev/null +++ b/ng2-components/ng2-alfresco-userinfo/src/services/bpmUser.service.ts @@ -0,0 +1,65 @@ +/*! + * @license + * Copyright 2016 Alfresco Software, Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { AlfrescoAuthenticationService } from 'ng2-alfresco-core'; +import { Injectable } from '@angular/core'; +import { Response } from '@angular/http'; +import { Observable } from 'rxjs/Observable'; +import { BpmUserModel } from '../models/bpmUser.model'; +/** + * + * BPMUserService retrieve all the information of an Ecm user. + * + * @returns {BPMUserService} . + */ +@Injectable() +export class BPMUserService { + + constructor(public authService: AlfrescoAuthenticationService) {} + + /** + * get User Information via ECM + * @param userName - the user name + */ + getCurrentUserInfo(): Observable { + return Observable.fromPromise(this.callApiGetProfile()) + .map( + data => data + ) + .do( + data => console.log('Node data', data) + ) // eyeball results in the console + .catch(this.handleError); + } + + private callApiGetProfile() { + return this.authService.getAlfrescoApi().activiti.profileApi.getProfile(); + } + + /** + * Throw the error + * @param error + * @returns {ErrorObservable} + */ + private handleError(error: Response) { + // in a real world app, we may send the error to some remote logging infrastructure + // instead of just logging it to the console + console.error(error); + return Observable.throw(error || 'Server error'); + } + +} diff --git a/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts b/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts index f6d237ecd6..dbb005892a 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/services/ecmUser.service.ts @@ -37,9 +37,9 @@ export class ECMUserService { */ getUserInfo(userName: string): Observable { return Observable.fromPromise(this.callApiGetPersonInfo(userName)) - .map( data => data ) + .map( data => data['entry']) .do( - data => console.log('Node data', data) + data => console.log('Node data', data['entry']) ) // eyeball results in the console .catch(this.handleError); } diff --git a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html index 116e372f29..4a1c172487 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html +++ b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.html @@ -1 +1,139 @@ -
TEST
+
+
+ +
+ ECM + BPM +
+ + +
+
    +
  • + + person + {{ecmUser.firstName}} {{ecmUser.lastName}} + +
  • +
  • + Id: + +
  • +
  • + Description: + +
  • +
  • + Email: + +
  • +
  • + Skype Id: + +
  • +
  • + Google Id: + +
  • +
  • + Instant Message Id: + +
  • +
  • + Job Title: + +
  • +
  • + Location: + +
  • +
  • + Mobile: + +
  • +
  • + Telephone: + +
  • +
  • + User Status: + +
  • +
  • + Enabled: + +
  • +
  • + Email Notifications: + +
  • +
+
+
+
    +
  • + + person + {{bpmUser.fullname}} + +
  • +
  • + Id: + +
  • +
  • + Email: + +
  • +
  • + Status: + +
  • +
  • + Tenant Name: + +
  • +
  • + Company: + +
  • +
+
+
+
diff --git a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts index ccf3384bac..f29d945b8e 100644 --- a/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts +++ b/ng2-components/ng2-alfresco-userinfo/src/userinfo.component.ts @@ -1,31 +1,46 @@ -import { Component } from '@angular/core'; +import { Component, OnInit, Input } from '@angular/core'; import { ECMUserService } from './services/ecmUser.service'; +import { BPMUserService } from './services/bpmUser.service'; import { EcmUserModel } from './models/ecmUser.model'; +import { BpmUserModel } from './models/bpmUser.model'; +import { AlfrescoContentService } from 'ng2-alfresco-core'; + +declare let __moduleName: string; @Component({ selector: 'ng2-alfresco-userinfo', + moduleId: __moduleName, styles: [`:host h1 { font-size:22px }`], - template: `

Hello World Angular 2 ng2-alfresco-userinfo

`, - providers: [ ECMUserService ] + templateUrl: './userinfo.component.html', + providers: [ ECMUserService, BPMUserService, AlfrescoContentService ] }) +export class UserInfoComponent implements OnInit { -export class UserInfoComponent { + @Input() + userEmail: string; private ecmUser: EcmUserModel; + private bpmUser: BpmUserModel; - constructor(private ecmUserService: ECMUserService) { - console.log('User info component constr'); + constructor(private ecmUserService: ECMUserService, + private bpmUserService: BPMUserService, + private contentService: AlfrescoContentService) { } - doQueryUser() { - this.ecmUserService.getUserInfo('admin') - .subscribe( - res => this.ecmUser = res.entry - ); + ngOnInit() { + this.ecmUserService.getUserInfo(this.userEmail) + .subscribe( + res => this.ecmUser = res + ); + this.bpmUserService.getCurrentUserInfo() + .subscribe( + res => this.bpmUser = res + ); } - - + public getDocumentThumbnailUrl(avatarId: string): string { + return this.contentService.getDocumentThumbnailUrl(document); + } }