mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-05-12 17:04:57 +00:00
[ACS-8695] Getting Agent avatar
This commit is contained in:
parent
92881d063a
commit
3c3961dd82
@ -17,20 +17,21 @@
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { CoreTestingModule } from '@alfresco/adf-core';
|
||||
import { Agent, AgentPaging, AgentsApi, AgentWithAvatar } from '@alfresco/js-api';
|
||||
import { AgentService } from './agent.service';
|
||||
import { AlfrescoApiService } from '../../services/alfresco-api.service';
|
||||
import { Agent, AgentPaging } from '@alfresco/js-api';
|
||||
|
||||
const agent1: Agent = {
|
||||
id: '1',
|
||||
name: 'HR Agent',
|
||||
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.'
|
||||
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.',
|
||||
avatarUrl: ''
|
||||
};
|
||||
|
||||
const agent2: Agent = {
|
||||
id: '2',
|
||||
name: 'Policy Agent',
|
||||
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.'
|
||||
description: 'Your Claims Doc Agent streamlines the extraction, analysis, and management of data from insurance claims documents.',
|
||||
avatarUrl: ''
|
||||
};
|
||||
|
||||
const agentPagingObjectMock: AgentPaging = {
|
||||
@ -46,23 +47,10 @@ const agentPagingObjectMock: AgentPaging = {
|
||||
}
|
||||
};
|
||||
|
||||
const avatarAgentMock = '';
|
||||
|
||||
const agentWithAvatarListMock: AgentWithAvatar[] = [
|
||||
{
|
||||
...agent1,
|
||||
avatar: avatarAgentMock
|
||||
},
|
||||
{
|
||||
...agent2,
|
||||
avatar: avatarAgentMock
|
||||
}
|
||||
];
|
||||
const agentWithAvatarListMock: Agent[] = [agent1, agent2];
|
||||
|
||||
describe('AgentService', () => {
|
||||
let agentService: AgentService;
|
||||
let apiService: AlfrescoApiService;
|
||||
let agentsApi: AgentsApi;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
@ -70,11 +58,6 @@ describe('AgentService', () => {
|
||||
});
|
||||
|
||||
agentService = TestBed.inject(AgentService);
|
||||
apiService = TestBed.inject(AlfrescoApiService);
|
||||
agentsApi = new AgentsApi(apiService.getInstance());
|
||||
|
||||
spyOn(agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock));
|
||||
spyOn(agentService.agentsApi, 'getAgentAvatar').and.returnValue(Promise.resolve(avatarAgentMock));
|
||||
});
|
||||
|
||||
it('should load agents', (done) => {
|
||||
@ -86,12 +69,4 @@ describe('AgentService', () => {
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should get agent avatar', (done) => {
|
||||
agentService.getAgentAvatar('avatarId').subscribe((response) => {
|
||||
expect(response).toEqual(avatarAgentMock);
|
||||
expect(agentService.agentsApi.getAgentAvatar).toHaveBeenCalledWith('avatarId');
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -16,9 +16,9 @@
|
||||
*/
|
||||
|
||||
import { Injectable } from '@angular/core';
|
||||
import { AgentsApi, AgentWithAvatar } from '@alfresco/js-api';
|
||||
import { BehaviorSubject, forkJoin, from, Observable, of } from 'rxjs';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { Agent, AgentsApi } from '@alfresco/js-api';
|
||||
import { BehaviorSubject, from, Observable, of } from 'rxjs';
|
||||
import { map, switchMap } from 'rxjs/operators';
|
||||
import { AlfrescoApiService } from '../../services';
|
||||
|
||||
@Injectable({
|
||||
@ -26,7 +26,7 @@ import { AlfrescoApiService } from '../../services';
|
||||
})
|
||||
export class AgentService {
|
||||
private _agentsApi: AgentsApi;
|
||||
private agents = new BehaviorSubject<AgentWithAvatar[]>([]);
|
||||
private agents = new BehaviorSubject<Agent[]>([]);
|
||||
|
||||
get agentsApi(): AgentsApi {
|
||||
this._agentsApi = this._agentsApi ?? new AgentsApi(this.apiService.getInstance());
|
||||
@ -42,35 +42,20 @@ export class AgentService {
|
||||
*
|
||||
* @returns AgentWithAvatar[] list containing agents.
|
||||
*/
|
||||
getAgents(): Observable<AgentWithAvatar[]> {
|
||||
getAgents(): Observable<Agent[]> {
|
||||
return this.agents$.pipe(
|
||||
switchMap((agentsList) => {
|
||||
if (agentsList.length) {
|
||||
return of(agentsList);
|
||||
}
|
||||
return from(this.agentsApi.getAgents()).pipe(
|
||||
switchMap((paging) => {
|
||||
const agents = paging.list.entries.map((agentEntry) => agentEntry.entry);
|
||||
// TODO: fetch avatars https://hyland.atlassian.net/browse/ACS-8695
|
||||
return forkJoin({ agents: of(agents), avatars: forkJoin(agents.map(() => of(``))) });
|
||||
}),
|
||||
switchMap(({ agents, avatars }) => {
|
||||
const agentsWithAvatar = agents.map((agent, index) => ({ ...agent, avatar: avatars[index] }));
|
||||
this.agents.next(agentsWithAvatar);
|
||||
return of(agentsWithAvatar);
|
||||
map((paging) => {
|
||||
const agentEntries = paging.list.entries.map((agentEntry) => agentEntry.entry);
|
||||
this.agents.next(agentEntries);
|
||||
return agentEntries;
|
||||
})
|
||||
);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets agent avatar by agent id.
|
||||
*
|
||||
* @param agentId agent unique id.
|
||||
* @returns string with an image.
|
||||
*/
|
||||
getAgentAvatar(agentId: string): Observable<string> {
|
||||
return from(this._agentsApi.getAgentAvatar(agentId));
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
| Method | HTTP request | Description |
|
||||
|-----------------------------------|----------------------------------------------|--------------------------|
|
||||
| [getAgents](#getAgents) | **GET** /agents | Gets all agents. |
|
||||
| [getAgentAvatar](#getAgentAvatar) | **GET** /agents/${agentId}/avatars/-default- | Gets agent avatar by id. |
|
||||
|
||||
## getAgents
|
||||
|
||||
@ -47,31 +46,6 @@ agentsApi.getAgents().then((agents) => {
|
||||
|
||||
**Return type**: [AgentPaging](#AgentPaging)
|
||||
|
||||
## getAgentAvatar
|
||||
|
||||
Gets agent avatar by agent id.
|
||||
|
||||
**Parameters**
|
||||
|
||||
| Name | Type |
|
||||
|---------------|----------|
|
||||
| **agentId** | string |
|
||||
|
||||
**Example**
|
||||
|
||||
```javascript
|
||||
import { AlfrescoApi, AgentsApi } from '@alfresco/js-api';
|
||||
|
||||
const alfrescoApi = new AlfrescoApi(/*..*/);
|
||||
const agentsApi = new AgentsApi(alfrescoApi);
|
||||
|
||||
agentsApi.getAgentAvatar('agentId').then((agentAvatarImage) => {
|
||||
console.log('API called successfully. Returned data: ' + agentAvatarImage);
|
||||
});
|
||||
```
|
||||
|
||||
**Return type**: String
|
||||
|
||||
# Models
|
||||
|
||||
## AgentPaging
|
||||
|
@ -19,4 +19,5 @@ export interface Agent {
|
||||
id: string;
|
||||
name: string;
|
||||
description: string;
|
||||
avatarUrl?: string;
|
||||
}
|
||||
|
@ -1,22 +0,0 @@
|
||||
/*!
|
||||
* @license
|
||||
* Copyright © 2005-2024 Hyland Software, Inc. and its affiliates. All rights reserved.
|
||||
*
|
||||
* 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 { Agent } from './agent';
|
||||
|
||||
export interface AgentWithAvatar extends Agent {
|
||||
avatar: string;
|
||||
}
|
@ -28,7 +28,6 @@ export * from './activityEntry';
|
||||
export * from './activityPaging';
|
||||
export * from './activityPagingList';
|
||||
export * from './agent';
|
||||
export * from './agentWithAvatar';
|
||||
export * from './agentEntry';
|
||||
export * from './agentPaging';
|
||||
export * from './agentPagingList';
|
||||
|
Loading…
x
Reference in New Issue
Block a user