From a7d058fd2e2252bc15788e6d3f69e7c07c3ed608 Mon Sep 17 00:00:00 2001 From: Maurizio Vitale Date: Fri, 1 Mar 2019 16:19:41 +0000 Subject: [PATCH] Process Service Cloud - Add the identity user service (#4374) * Add the identity service to cloud * Expose the service --- .../src/lib/services/identity-user.service.ts | 60 +++++++++++++++++++ .../src/lib/services/public-api.ts | 18 ++++++ lib/process-services-cloud/src/public-api.ts | 1 + 3 files changed, 79 insertions(+) create mode 100644 lib/process-services-cloud/src/lib/services/identity-user.service.ts create mode 100644 lib/process-services-cloud/src/lib/services/public-api.ts diff --git a/lib/process-services-cloud/src/lib/services/identity-user.service.ts b/lib/process-services-cloud/src/lib/services/identity-user.service.ts new file mode 100644 index 0000000000..2fad48b9e9 --- /dev/null +++ b/lib/process-services-cloud/src/lib/services/identity-user.service.ts @@ -0,0 +1,60 @@ +/*! + * @license + * Copyright 2019 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 { Injectable } from '@angular/core'; +import { throwError as observableThrowError, Observable, from } from 'rxjs'; +import { catchError } from 'rxjs/operators'; + +import { AppConfigService, LogService, AlfrescoApiService } from '@alfresco/adf-core'; + +@Injectable() +export class IdentityUserService { + + constructor( + private apiService: AlfrescoApiService, + private appConfigService: AppConfigService, + private logService: LogService + ) { } + + /** + * Finds groups filtered by username. + * @param username Object containing the name filter string + * @returns List of users information + */ + findUsersByUsername(username: string): Observable { + const url = this.getUserApi(); + const httpMethod = 'GET', pathParams = {}, queryParams = { search: username }, bodyParam = {}, headerParams = {}, + formParams = {}, contentTypes = ['application/json'], accepts = ['application/json']; + + return (from(this.apiService.getInstance().oauth2Auth.callCustomApi( + url, httpMethod, pathParams, queryParams, + headerParams, formParams, bodyParam, + contentTypes, accepts, Object, null, null) + )).pipe( + catchError((err) => this.handleError(err)) + ); + } + + private getUserApi() { + return `${this.appConfigService.get('identityHost')}/users`; + } + + private handleError(error: any) { + this.logService.error(error); + return observableThrowError(error || 'Server error'); + } +} diff --git a/lib/process-services-cloud/src/lib/services/public-api.ts b/lib/process-services-cloud/src/lib/services/public-api.ts new file mode 100644 index 0000000000..a1ee695bf0 --- /dev/null +++ b/lib/process-services-cloud/src/lib/services/public-api.ts @@ -0,0 +1,18 @@ +/*! + * @license + * Copyright 2019 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 * from './identity-user.service'; diff --git a/lib/process-services-cloud/src/public-api.ts b/lib/process-services-cloud/src/public-api.ts index 187f0cbcae..37fd3dd798 100644 --- a/lib/process-services-cloud/src/public-api.ts +++ b/lib/process-services-cloud/src/public-api.ts @@ -21,3 +21,4 @@ export * from './lib/app/public-api'; export * from './lib/process/public-api'; export * from './lib/task/public-api'; export * from './lib/group/public-api'; +export * from './lib/services/public-api';