Skip to content

Commit

Permalink
[AAE-8929] Get start event form static inputs (#7652)
Browse files Browse the repository at this point in the history
* [AAE-8929] Get start event form static inputs

* [AAE-8929] Fix tests
  • Loading branch information
pmartinezga committed Jun 2, 2022
1 parent 4457aed commit 243803d
Show file tree
Hide file tree
Showing 6 changed files with 99 additions and 4 deletions.
7 changes: 5 additions & 2 deletions angular.json
Expand Up @@ -843,5 +843,8 @@
}
}
},
"defaultProject": "demoshell"
}
"defaultProject": "demoshell",
"cli": {
"analytics": false
}
}
Expand Up @@ -64,7 +64,7 @@
<adf-cloud-form
[appName]="appName"
[appVersion]="processDefinitionCurrent.appVersion"
[data]="values"
[data]="resolvedValues"
[formId]="processDefinitionCurrent.formKey"
[showSaveButton]="false"
[showCompleteButton]="false"
Expand Down
Expand Up @@ -44,7 +44,7 @@ import { TranslateModule } from '@ngx-translate/core';
import { ProcessNameCloudPipe } from '../../../pipes/process-name-cloud.pipe';
import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
import { ESCAPE } from '@angular/cdk/keycodes';
import { ProcessDefinitionCloud } from 'process-services-cloud';
import { ProcessDefinitionCloud, TaskVariableCloud } from 'process-services-cloud';

describe('StartProcessCloudComponent', () => {

Expand All @@ -56,6 +56,7 @@ describe('StartProcessCloudComponent', () => {
let startProcessSpy: jasmine.Spy;
let createProcessSpy: jasmine.Spy;
let formDefinitionSpy: jasmine.Spy;
let getStartEventFormStaticValuesMappingSpy: jasmine.Spy;

const firstChange = new SimpleChange(undefined, 'myApp', true);

Expand Down Expand Up @@ -106,6 +107,7 @@ describe('StartProcessCloudComponent', () => {
spyOn(processService, 'updateProcess').and.returnValue(of());
startProcessSpy = spyOn(processService, 'startCreatedProcess').and.returnValue(of(fakeProcessInstance));
createProcessSpy = spyOn(processService, 'createProcess').and.returnValue(of(fakeCreatedProcessInstance));
getStartEventFormStaticValuesMappingSpy = spyOn(processService, 'getStartEventFormStaticValuesMapping').and.returnValue(of([]));
});

afterEach(() => {
Expand Down Expand Up @@ -202,6 +204,34 @@ describe('StartProcessCloudComponent', () => {
expect(startBtn.disabled).toBe(true);
expect(component.isProcessFormValid()).toBe(false);
});

it('should include the static input mappings in the resolved values', fakeAsync(() => {
const values: TaskVariableCloud[] = [
new TaskVariableCloud({name: 'value1', value: 'value'}),
new TaskVariableCloud({name: 'value2', value: 1}),
new TaskVariableCloud({name: 'value3', value: false})
];
const staticInputs: TaskVariableCloud[] = [
new TaskVariableCloud({name: 'static1', value: 'static value'}),
new TaskVariableCloud({name: 'static2', value: 0}),
new TaskVariableCloud({name: 'static3', value: true})
];
component.name = 'My new process';
component.processDefinitionName = 'processwithoutform2';
component.values = values;
getDefinitionsSpy.and.returnValue(of(fakeSingleProcessDefinitionWithoutForm(component.processDefinitionName)));
getStartEventFormStaticValuesMappingSpy.and.returnValue(of(staticInputs));
fixture.detectChanges();

const change = new SimpleChange(null, 'MyApp', true);
component.ngOnChanges({ appName: change });
fixture.detectChanges();
tick(550);

fixture.whenStable().then(() => {
expect(component.resolvedValues).toEqual(staticInputs.concat(values));
});
}));
});

describe('start a process with start form', () => {
Expand Down
Expand Up @@ -109,6 +109,8 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
formCloud: FormModel;
currentCreatedProcess: ProcessInstanceCloud;
disableStartButton: boolean = true;
staticMappings: TaskVariableCloud[] = [];
resolvedValues: TaskVariableCloud[];

protected onDestroy$ = new Subject<boolean>();
processDefinitionLoaded = false;
Expand Down Expand Up @@ -153,6 +155,10 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
this.loadProcessDefinitions();
}
}

if (changes['values'] && changes['values'].currentValue !== changes['values'].previousValue) {
this.resolvedValues = this.staticMappings.concat(this.values || []);
}
}

@HostListener('keydown', ['$event'])
Expand Down Expand Up @@ -203,6 +209,15 @@ export class StartProcessCloudComponent implements OnChanges, OnInit, OnDestroy
this.processDefinitionCurrent = this.filteredProcesses.find((process: ProcessDefinitionCloud) =>
process.name === selectedProcessDefinitionName || process.key === selectedProcessDefinitionName);

this.startProcessCloudService.getStartEventFormStaticValuesMapping(this.appName, this.processDefinitionCurrent.id)
.subscribe(
staticMappings => {
this.staticMappings = staticMappings;
this.resolvedValues = this.staticMappings.concat(this.values || []);
},
() => this.resolvedValues = this.values
);

this.isFormCloudLoaded = false;
this.processPayloadCloud.processDefinitionKey = this.processDefinitionCurrent.key;
}
Expand Down
Expand Up @@ -156,4 +156,30 @@ describe('StartProcessCloudService', () => {
}
);
});

it('should transform the response into task variables', (done) => {
const appName = 'test-app';
const processDefinitionId = 'processDefinitionId';
const oauth2Auth = jasmine.createSpyObj('oauth2Auth', ['callCustomApi']);
oauth2Auth.callCustomApi.and.returnValue(Promise.resolve({ static1: 'value', static2: 0, static3: true }));
spyOn(alfrescoApiService, 'getInstance').and.returnValue({
oauth2Auth
});

service.getStartEventFormStaticValuesMapping(appName, processDefinitionId).subscribe((result) => {
expect(result.length).toEqual(3);
expect(result[0].name).toEqual('static1');
expect(result[0].id).toEqual('static1');
expect(result[0].value).toEqual('value');
expect(result[1].name).toEqual('static2');
expect(result[1].id).toEqual('static2');
expect(result[1].value).toEqual(0);
expect(result[2].name).toEqual('static3');
expect(result[2].id).toEqual('static3');
expect(result[2].value).toEqual(true);
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[0].endsWith(`${appName}/rb/v1/process-definitions/${processDefinitionId}/static-values`)).toBeTruthy();
expect(oauth2Auth.callCustomApi.calls.mostRecent().args[1]).toBe('GET');
done();
});
});
});
Expand Up @@ -23,6 +23,7 @@ import { ProcessInstanceCloud } from '../models/process-instance-cloud.model';
import { ProcessPayloadCloud } from '../models/process-payload-cloud.model';
import { ProcessDefinitionCloud } from '../../../models/process-definition-cloud.model';
import { BaseCloudService } from '../../../services/base-cloud.service';
import { TaskVariableCloud } from '../../../form/models/task-variable-cloud.model';

@Injectable({
providedIn: 'root'
Expand Down Expand Up @@ -126,4 +127,24 @@ export class StartProcessCloudService extends BaseCloudService {

return this.delete(url);
}

/**
* Gets the static values mapped to the start form of a process definition.
*
* @param appName Name of the app
* @param processDefinitionId ID of the target process definition
* @returns Static mappings for the start event
*/
getStartEventFormStaticValuesMapping(appName: string, processDefinitionId: string): Observable<TaskVariableCloud[]> {
const apiUrl = `${this.getBasePath(appName)}/rb/v1/process-definitions/${processDefinitionId}/static-values`;
return this.get(apiUrl).pipe(
map((res: { [key: string]: any }) => {
const result = [];
if (res) {
Object.keys(res).forEach(mapping => result.push(new TaskVariableCloud({ name: mapping, value: res[mapping] })));
}
return result;
})
);
}
}

0 comments on commit 243803d

Please sign in to comment.