mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-31 17:38:48 +00:00
[ADF-1004] The process service definition file in the alfresco-js-api is incomplete (#2488)
* correction after new declaration file for PS * remove unused jasmine * commit ifx initial pipe * fix tasklist test * fix tasklist test * reinsert test
This commit is contained in:
committed by
Denys Vuika
parent
0cc578ba0e
commit
036c63e43d
@@ -0,0 +1,30 @@
|
||||
/*!
|
||||
* @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 let fakeApps = {
|
||||
size: 2, total: 2, start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 1, defaultAppId: null, name: 'Sales-Fakes-App', description: 'desc-fake1', modelId: 22,
|
||||
theme: 'theme-1-fake', icon: 'glyphicon-asterisk', 'deploymentId': '111', 'tenantId': null
|
||||
},
|
||||
{
|
||||
id: 2, defaultAppId: null, name: 'health-care-Fake', description: 'desc-fake2', modelId: 33,
|
||||
theme: 'theme-2-fake', icon: 'glyphicon-asterisk', 'deploymentId': '444', 'tenantId': null
|
||||
}
|
||||
]
|
||||
};
|
@@ -0,0 +1,42 @@
|
||||
/*!
|
||||
* @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 { CommentProcessModel } from '../models/comment-process.model';
|
||||
import { UserProcessModel } from '../models/user-process.model';
|
||||
|
||||
export let fakeUser1 = { id: 1, email: 'fake-email@dom.com', firstName: 'firstName', lastName: 'lastName' };
|
||||
|
||||
export let fakeUser2 = { id: 1001, email: 'some-one@somegroup.com', firstName: 'some', lastName: 'one' };
|
||||
|
||||
export let fakeTasksComment = {
|
||||
size: 2, total: 2, start: 0,
|
||||
data: [
|
||||
{
|
||||
id: 1, message: 'fake-message-1', created: '', createdBy: fakeUser1
|
||||
},
|
||||
{
|
||||
id: 2, message: 'fake-message-2', created: '', createdBy: fakeUser1
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
export let fakeProcessComment = new CommentProcessModel({id: 1, message: 'Test', created: new Date('2016-11-10T03:37:30.010+0000'), createdBy: new UserProcessModel({
|
||||
id: 13,
|
||||
firstName: 'Wilbur',
|
||||
lastName: 'Adams',
|
||||
email: 'wilbur@app.com'
|
||||
}));
|
@@ -22,10 +22,7 @@ import { MaterialModule } from '../../material.module';
|
||||
import { InfoDrawerLayoutComponent } from './info-drawer-layout.component';
|
||||
import { InfoDrawerComponent } from './info-drawer.component';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
describe('InfoDrawerComponent', () => {
|
||||
let componentHandler: any;
|
||||
let debugElement: DebugElement;
|
||||
let element: HTMLElement;
|
||||
let component: InfoDrawerComponent;
|
||||
@@ -48,11 +45,6 @@ describe('InfoDrawerComponent', () => {
|
||||
component = fixture.componentInstance;
|
||||
element = fixture.nativeElement;
|
||||
debugElement = fixture.debugElement;
|
||||
componentHandler = jasmine.createSpyObj('componentHandler', [
|
||||
'upgradeAllRegistered',
|
||||
'upgradeElement'
|
||||
]);
|
||||
window['componentHandler'] = componentHandler;
|
||||
});
|
||||
|
||||
it('should create instance of InfoDrawerComponent', () => {
|
||||
|
@@ -0,0 +1,34 @@
|
||||
/*!
|
||||
* @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 { CommentRepresentation, LightUserRepresentation } from 'alfresco-js-api';
|
||||
|
||||
export class CommentProcessModel implements CommentRepresentation {
|
||||
id: number;
|
||||
message: string;
|
||||
created: Date;
|
||||
createdBy: LightUserRepresentation;
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj) {
|
||||
this.id = obj.id;
|
||||
this.message = obj.message;
|
||||
this.created = obj.created;
|
||||
this.createdBy = obj.createdBy;
|
||||
}
|
||||
}
|
||||
}
|
@@ -19,12 +19,14 @@
|
||||
* This object represent the process service user.*
|
||||
*/
|
||||
|
||||
export class LightUserRepresentation {
|
||||
id: number;
|
||||
email: string;
|
||||
firstName: string;
|
||||
lastName: string;
|
||||
pictureId: number = null;
|
||||
import { LightUserRepresentation } from 'alfresco-js-api';
|
||||
|
||||
export class UserProcessModel implements LightUserRepresentation {
|
||||
id?: number;
|
||||
email?: string;
|
||||
firstName?: string;
|
||||
lastName?: string;
|
||||
pictureId?: number = null;
|
||||
|
||||
constructor(obj?: any) {
|
||||
if (obj) {
|
||||
|
@@ -16,7 +16,7 @@
|
||||
*/
|
||||
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
import { LightUserRepresentation } from '../models/user-process.model';
|
||||
import { UserProcessModel } from '../models/user-process.model';
|
||||
import { InitialUsernamePipe } from './user-initial.pipe';
|
||||
|
||||
class FakeSanitazer extends DomSanitizer {
|
||||
@@ -53,11 +53,11 @@ class FakeSanitazer extends DomSanitizer {
|
||||
describe('UserInitialPipe', () => {
|
||||
|
||||
let pipe: InitialUsernamePipe;
|
||||
let fakeUser: LightUserRepresentation;
|
||||
let fakeUser: UserProcessModel;
|
||||
|
||||
beforeEach(() => {
|
||||
pipe = new InitialUsernamePipe(new FakeSanitazer());
|
||||
fakeUser = new LightUserRepresentation();
|
||||
fakeUser = new UserProcessModel();
|
||||
});
|
||||
|
||||
it('should return a div with the user initials', () => {
|
||||
|
@@ -17,7 +17,7 @@
|
||||
|
||||
import { Pipe, PipeTransform } from '@angular/core';
|
||||
import { DomSanitizer, SafeHtml } from '@angular/platform-browser';
|
||||
import { LightUserRepresentation } from '../models/user-process.model';
|
||||
import { UserProcessModel } from '../models/user-process.model';
|
||||
|
||||
@Pipe({
|
||||
name: 'usernameInitials'
|
||||
@@ -26,7 +26,7 @@ export class InitialUsernamePipe implements PipeTransform {
|
||||
|
||||
constructor(private sanitized: DomSanitizer) {}
|
||||
|
||||
transform(user: LightUserRepresentation, className: string = '', delimiter: string = ''): SafeHtml {
|
||||
transform(user: UserProcessModel, className: string = '', delimiter: string = ''): SafeHtml {
|
||||
let result: SafeHtml = '';
|
||||
if (user) {
|
||||
let initialResult = this.getInitialUserName(user.firstName, user.lastName, delimiter);
|
||||
|
@@ -0,0 +1,113 @@
|
||||
/*!
|
||||
* @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 { TestBed } from '@angular/core/testing';
|
||||
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
|
||||
import { fakeApps } from '../assets/apps-service.mock';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AppConfigService } from './app-config.service';
|
||||
import { AppsProcessService } from './apps-process.service';
|
||||
import { LogService } from './log.service';
|
||||
import { StorageService } from './storage.service';
|
||||
|
||||
declare let jasmine: any;
|
||||
describe('Apps Service', () => {
|
||||
|
||||
let service: AppsProcessService;
|
||||
|
||||
beforeEach((() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
AppsProcessService,
|
||||
AlfrescoApiService,
|
||||
StorageService,
|
||||
LogService,
|
||||
{provide: AppConfigService, useClass: AppConfigServiceMock}
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.get(AppsProcessService);
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should get the deployed apps ', (done) => {
|
||||
service.getDeployedApplications().subscribe(
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(2);
|
||||
expect(res[0].name).toEqual('Sales-Fakes-App');
|
||||
expect(res[0].description).toEqual('desc-fake1');
|
||||
expect(res[0].deploymentId).toEqual('111');
|
||||
expect(res[1].name).toEqual('health-care-Fake');
|
||||
expect(res[1].description).toEqual('desc-fake2');
|
||||
expect(res[1].deploymentId).toEqual('444');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeApps)
|
||||
});
|
||||
});
|
||||
|
||||
it('should get the filter deployed app ', (done) => {
|
||||
service.getDeployedApplicationsByName('health-care-Fake').subscribe(
|
||||
(res: any) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.name).toEqual('health-care-Fake');
|
||||
expect(res.description).toEqual('desc-fake2');
|
||||
expect(res.deploymentId).toEqual('444');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeApps)
|
||||
});
|
||||
});
|
||||
|
||||
it('should get the deployed app details by id ', (done) => {
|
||||
service.getApplicationDetailsById(1).subscribe(
|
||||
(app: any) => {
|
||||
expect(app).toBeDefined();
|
||||
expect(app.name).toEqual('Sales-Fakes-App');
|
||||
expect(app.description).toEqual('desc-fake1');
|
||||
expect(app.deploymentId).toEqual('111');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeApps)
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,60 @@
|
||||
/*!
|
||||
* @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 { Injectable } from '@angular/core';
|
||||
import { AppDefinitionRepresentation } from 'alfresco-js-api';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { LogService } from './log.service';
|
||||
|
||||
@Injectable()
|
||||
export class AppsProcessService {
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private logService: LogService) {
|
||||
}
|
||||
|
||||
getDeployedApplications(): Observable<AppDefinitionRepresentation[]> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().activiti.appsApi.getAppDefinitions())
|
||||
.map((response: any) => {
|
||||
return response.data;
|
||||
})
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
getDeployedApplicationsByName(name: string): Observable<AppDefinitionRepresentation> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().activiti.appsApi.getAppDefinitions())
|
||||
.map((response: any) => {
|
||||
return response.data.find(app => app.name === name);
|
||||
})
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
getApplicationDetailsById(appId: number): Observable<AppDefinitionRepresentation> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().activiti.appsApi.getAppDefinitions())
|
||||
.map((response: any) => {
|
||||
return response.data.find(app => app.id === appId);
|
||||
})
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
this.logService.error(error);
|
||||
return Observable.throw(error || 'Server error');
|
||||
}
|
||||
|
||||
}
|
@@ -0,0 +1,194 @@
|
||||
/*!
|
||||
* @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 { async, TestBed } from '@angular/core/testing';
|
||||
import { CommentProcessModel } from 'ng2-alfresco-core';
|
||||
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
|
||||
import { fakeProcessComment, fakeTasksComment, fakeUser1 } from '../assets/comment-process-service.mock';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AppConfigService } from './app-config.service';
|
||||
import { CommentProcessService } from './comment-process.service';
|
||||
import { LogService } from './log.service';
|
||||
import { StorageService } from './storage.service';
|
||||
|
||||
declare let jasmine: any;
|
||||
describe('Comment ProcessService Service', () => {
|
||||
|
||||
let service: CommentProcessService;
|
||||
let alfrescoApi: any;
|
||||
|
||||
beforeEach((() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
CommentProcessService,
|
||||
AlfrescoApiService,
|
||||
StorageService,
|
||||
LogService,
|
||||
{provide: AppConfigService, useClass: AppConfigServiceMock}
|
||||
]
|
||||
}).compileComponents();
|
||||
}));
|
||||
|
||||
beforeEach(() => {
|
||||
service = TestBed.get(CommentProcessService);
|
||||
alfrescoApi = TestBed.get(AlfrescoApiService).getInstance();
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
jasmine.Ajax.install();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
describe('Process comments', () => {
|
||||
|
||||
const processId = '1001';
|
||||
|
||||
describe('get comments', () => {
|
||||
|
||||
let getProcessInstanceComments: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
getProcessInstanceComments = spyOn(alfrescoApi.activiti.commentsApi, 'getProcessInstanceComments')
|
||||
.and
|
||||
.returnValue(Promise.resolve({data: [fakeProcessComment, fakeProcessComment]}));
|
||||
});
|
||||
|
||||
it('should return the correct number of comments', async(() => {
|
||||
service.getProcessInstanceComments(processId).subscribe((tasks) => {
|
||||
expect(tasks.length).toBe(2);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should return the correct comment data', async(() => {
|
||||
service.getProcessInstanceComments(processId).subscribe((comments) => {
|
||||
let comment: any = comments[0];
|
||||
expect(comment.id).toBe(fakeProcessComment.id);
|
||||
expect(comment.created).toBe(fakeProcessComment.created);
|
||||
expect(comment.message).toBe(fakeProcessComment.message);
|
||||
expect(comment.createdBy.id).toBe(fakeProcessComment.createdBy.id);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should call service to fetch process instance comments', () => {
|
||||
service.getProcessInstanceComments(processId);
|
||||
expect(getProcessInstanceComments).toHaveBeenCalledWith(processId);
|
||||
});
|
||||
|
||||
it('should return a default error if no data is returned by the API', async(() => {
|
||||
getProcessInstanceComments = getProcessInstanceComments.and.returnValue(Promise.reject(null));
|
||||
service.getProcessInstanceComments(processId).subscribe(
|
||||
() => {
|
||||
},
|
||||
(res) => {
|
||||
expect(res).toBe('Server error');
|
||||
}
|
||||
);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
describe('add comment', () => {
|
||||
|
||||
const message = 'Test message';
|
||||
let addProcessInstanceComment: jasmine.Spy;
|
||||
|
||||
beforeEach(() => {
|
||||
addProcessInstanceComment = spyOn(alfrescoApi.activiti.commentsApi, 'addProcessInstanceComment')
|
||||
.and
|
||||
.returnValue(Promise.resolve(fakeProcessComment));
|
||||
});
|
||||
|
||||
it('should call service to add comment', () => {
|
||||
service.addProcessInstanceComment(processId, message);
|
||||
expect(addProcessInstanceComment).toHaveBeenCalledWith({
|
||||
message: message
|
||||
}, processId);
|
||||
});
|
||||
|
||||
it('should return the created comment', async(() => {
|
||||
service.addProcessInstanceComment(processId, message).subscribe((comment) => {
|
||||
expect(comment.id).toBe(fakeProcessComment.id);
|
||||
expect(comment.created).toBe(fakeProcessComment.created);
|
||||
expect(comment.message).toBe(fakeProcessComment.message);
|
||||
expect(comment.createdBy).toBe(fakeProcessComment.createdBy);
|
||||
});
|
||||
}));
|
||||
|
||||
it('should return a default error if no data is returned by the API', async(() => {
|
||||
addProcessInstanceComment = addProcessInstanceComment.and.returnValue(Promise.reject(null));
|
||||
service.addProcessInstanceComment(processId, message).subscribe(
|
||||
() => {
|
||||
},
|
||||
(res) => {
|
||||
expect(res).toBe('Server error');
|
||||
}
|
||||
);
|
||||
}));
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
describe('Task comments', () => {
|
||||
|
||||
it('should add a comment task ', (done) => {
|
||||
service.addTaskComment('999', 'fake-comment-message').subscribe(
|
||||
(res: CommentProcessModel) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.id).not.toEqual('');
|
||||
expect(res.message).toEqual('fake-comment-message');
|
||||
expect(res.created).not.toEqual('');
|
||||
expect(res.createdBy.email).toEqual('fake-email@dom.com');
|
||||
expect(res.createdBy.firstName).toEqual('firstName');
|
||||
expect(res.createdBy.lastName).toEqual('lastName');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify({
|
||||
id: '111', message: 'fake-comment-message',
|
||||
createdBy: fakeUser1,
|
||||
created: '2016-07-15T11:19:17.440+0000'
|
||||
})
|
||||
});
|
||||
});
|
||||
|
||||
it('should return the tasks comments ', (done) => {
|
||||
service.getTaskComments('999').subscribe(
|
||||
(res: CommentProcessModel[]) => {
|
||||
expect(res).toBeDefined();
|
||||
expect(res.length).toEqual(2);
|
||||
expect(res[0].message).toEqual('fake-message-1');
|
||||
expect(res[1].message).toEqual('fake-message-2');
|
||||
done();
|
||||
}
|
||||
);
|
||||
|
||||
jasmine.Ajax.requests.mostRecent().respondWith({
|
||||
'status': 200,
|
||||
contentType: 'application/json',
|
||||
responseText: JSON.stringify(fakeTasksComment)
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
@@ -0,0 +1,82 @@
|
||||
/*!
|
||||
* @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 { Injectable } from '@angular/core';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { CommentProcessModel } from '../models/comment-process.model';
|
||||
import { UserProcessModel } from '../models/user-process.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { LogService } from './log.service';
|
||||
|
||||
@Injectable()
|
||||
export class CommentProcessService {
|
||||
|
||||
constructor(private apiService: AlfrescoApiService,
|
||||
private logService: LogService) {
|
||||
}
|
||||
|
||||
addTaskComment(taskId: string, message: string): Observable<CommentProcessModel> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().activiti.taskApi.addTaskComment({message: message}, taskId))
|
||||
.map(res => res)
|
||||
.map((response: CommentProcessModel) => {
|
||||
return new CommentProcessModel({id: response.id, message: response.message, created: response.created, createdBy: response.createdBy});
|
||||
}).catch(err => this.handleError(err));
|
||||
|
||||
}
|
||||
|
||||
getTaskComments(taskId: string): Observable<CommentProcessModel[]> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().activiti.taskApi.getTaskComments(taskId))
|
||||
.map(res => res)
|
||||
.map((response: any) => {
|
||||
let comments: CommentProcessModel[] = [];
|
||||
response.data.forEach((comment: CommentProcessModel) => {
|
||||
let user = new UserProcessModel(comment.createdBy);
|
||||
comments.push(new CommentProcessModel({id: comment.id, message: comment.message, created: comment.created, createdBy: user}));
|
||||
});
|
||||
return comments;
|
||||
}).catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
getProcessInstanceComments(processInstanceId: string): Observable<CommentProcessModel[]> {
|
||||
return Observable.fromPromise(this.apiService.getInstance().activiti.commentsApi.getProcessInstanceComments(processInstanceId))
|
||||
.map(res => res)
|
||||
.map((response: any) => {
|
||||
let comments: CommentProcessModel[] = [];
|
||||
response.data.forEach((comment: CommentProcessModel) => {
|
||||
let user = new UserProcessModel(comment.createdBy);
|
||||
comments.push(new CommentProcessModel({id: comment.id, message: comment.message, created: comment.created, createdBy: user}));
|
||||
});
|
||||
return comments;
|
||||
}).catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
addProcessInstanceComment(processInstanceId: string, message: string): Observable<CommentProcessModel> {
|
||||
return Observable.fromPromise(
|
||||
this.apiService.getInstance().activiti.commentsApi.addProcessInstanceComment({ message: message }, processInstanceId)
|
||||
)
|
||||
.map((response: CommentProcessModel) => {
|
||||
return new CommentProcessModel({id: response.id, message: response.message, created: response.created, createdBy: response.createdBy});
|
||||
}).catch(err => this.handleError(err));
|
||||
|
||||
}
|
||||
|
||||
private handleError(error: any) {
|
||||
this.logService.error(error);
|
||||
return Observable.throw(error || 'Server error');
|
||||
}
|
||||
|
||||
}
|
@@ -16,8 +16,8 @@
|
||||
*/
|
||||
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { UserProcessModel } from 'ng2-alfresco-core';
|
||||
import { AppConfigServiceMock } from '../assets/app-config.service.mock';
|
||||
import { LightUserRepresentation } from '../models/user-process.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { AppConfigService } from './app-config.service';
|
||||
import { LogService } from './log.service';
|
||||
@@ -26,21 +26,21 @@ import { StorageService } from './storage.service';
|
||||
|
||||
declare let jasmine: any;
|
||||
|
||||
const firstInvolvedUser: LightUserRepresentation = new LightUserRepresentation({
|
||||
const firstInvolvedUser: UserProcessModel = new UserProcessModel({
|
||||
id: '1',
|
||||
email: 'fake-user1@fake.com',
|
||||
firstName: 'fakeName1',
|
||||
lastName: 'fakeLast1'
|
||||
});
|
||||
|
||||
const secondInvolvedUser: LightUserRepresentation = new LightUserRepresentation({
|
||||
const secondInvolvedUser: UserProcessModel = new UserProcessModel({
|
||||
id: '2',
|
||||
email: 'fake-user2@fake.com',
|
||||
firstName: 'fakeName2',
|
||||
lastName: 'fakeLast2'
|
||||
});
|
||||
|
||||
const fakeInvolveUserList: LightUserRepresentation[] = [firstInvolvedUser, secondInvolvedUser];
|
||||
const fakeInvolveUserList: UserProcessModel[] = [firstInvolvedUser, secondInvolvedUser];
|
||||
|
||||
describe('PeopleProcessService', () => {
|
||||
|
||||
@@ -71,7 +71,7 @@ describe('PeopleProcessService', () => {
|
||||
|
||||
it('should be able to retrieve people to involve in the task', (done) => {
|
||||
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(
|
||||
(users: LightUserRepresentation[]) => {
|
||||
(users: UserProcessModel[]) => {
|
||||
expect(users).toBeDefined();
|
||||
expect(users.length).toBe(2);
|
||||
expect(users[0].id).toEqual('1');
|
||||
@@ -89,7 +89,7 @@ describe('PeopleProcessService', () => {
|
||||
|
||||
it('should be able to get people images for people retrieved', (done) => {
|
||||
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(
|
||||
(users: LightUserRepresentation[]) => {
|
||||
(users: UserProcessModel[]) => {
|
||||
expect(users).toBeDefined();
|
||||
expect(users.length).toBe(2);
|
||||
expect(service.getUserImage(users[0])).toContain('/users/' + users[0].id + '/picture');
|
||||
@@ -111,7 +111,7 @@ describe('PeopleProcessService', () => {
|
||||
|
||||
it('should return empty list when there are no users to involve', (done) => {
|
||||
service.getWorkflowUsers('fake-task-id', 'fake-filter').subscribe(
|
||||
(users: LightUserRepresentation[]) => {
|
||||
(users: UserProcessModel[]) => {
|
||||
expect(users).toBeDefined();
|
||||
expect(users.length).toBe(0);
|
||||
done();
|
||||
|
@@ -18,7 +18,7 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Response } from '@angular/http';
|
||||
import { Observable } from 'rxjs/Rx';
|
||||
import { LightUserRepresentation } from '../models/user-process.model';
|
||||
import { UserProcessModel } from '../models/user-process.model';
|
||||
import { AlfrescoApiService } from './alfresco-api.service';
|
||||
import { LogService } from './log.service';
|
||||
|
||||
@@ -29,24 +29,24 @@ export class PeopleProcessService {
|
||||
private logService: LogService) {
|
||||
}
|
||||
|
||||
getWorkflowUsers(taskId?: string, searchWord?: string): Observable<LightUserRepresentation[]> {
|
||||
getWorkflowUsers(taskId?: string, searchWord?: string): Observable<UserProcessModel[]> {
|
||||
let option = { excludeTaskId: taskId, filter: searchWord };
|
||||
return Observable.fromPromise(this.getWorkflowUserApi(option))
|
||||
.map((response: any) => <LightUserRepresentation[]> response.data || [])
|
||||
.map((response: any) => <UserProcessModel[]> response.data || [])
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
getUserImage(user: LightUserRepresentation): string {
|
||||
return this.getUserProfileImageApi(user.id + '');
|
||||
getUserImage(user: UserProcessModel): string {
|
||||
return this.getUserProfileImageApi(user.id);
|
||||
}
|
||||
|
||||
involveUserWithTask(taskId: string, idToInvolve: string): Observable<LightUserRepresentation[]> {
|
||||
involveUserWithTask(taskId: string, idToInvolve: string): Observable<UserProcessModel[]> {
|
||||
let node = {userId: idToInvolve};
|
||||
return Observable.fromPromise(this.involveUserToTaskApi(taskId, node))
|
||||
.catch(err => this.handleError(err));
|
||||
}
|
||||
|
||||
removeInvolvedUser(taskId: string, idToRemove: string): Observable<LightUserRepresentation[]> {
|
||||
removeInvolvedUser(taskId: string, idToRemove: string): Observable<UserProcessModel[]> {
|
||||
let node = {userId: idToRemove};
|
||||
return Observable.fromPromise(this.removeInvolvedUserFromTaskApi(taskId, node))
|
||||
.catch(err => this.handleError(err));
|
||||
@@ -64,7 +64,7 @@ export class PeopleProcessService {
|
||||
return this.alfrescoJsApi.getInstance().activiti.taskActionsApi.removeInvolvedUser(taskId, node);
|
||||
}
|
||||
|
||||
private getUserProfileImageApi(userId: string) {
|
||||
private getUserProfileImageApi(userId: number) {
|
||||
return this.alfrescoJsApi.getInstance().activiti.userApi.getUserProfilePictureUrl(userId);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user