Skip to content
This repository was archived by the owner on Jun 11, 2025. It is now read-only.

Commit 44ce95f

Browse files
SilviuCPopaeromano
authored andcommitted
[ADF-4075] TaskFormsApi - change getRestFieldValues return format (#392)
* change getRestFieldValues reponse type * change deserialize return type if response it is array type * fix unit test
1 parent 59ae415 commit 44ce95f

File tree

7 files changed

+46
-16
lines changed

7 files changed

+46
-16
lines changed

src/alfrescoApi.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ export class AlfrescoApi {
248248

249249
oauth2AuthPromise.then((accessToken) => {
250250
this.config.accessToken = accessToken;
251-
}, () => {
251+
}, () => {
252252
console.log('login OAUTH error');
253253
});
254254

@@ -261,7 +261,7 @@ export class AlfrescoApi {
261261

262262
processPromise.then((ticketBpm) => {
263263
this.config.ticketBpm = ticketBpm;
264-
}, () => {
264+
}, () => {
265265
console.log('login BPM error');
266266
});
267267

@@ -273,7 +273,7 @@ export class AlfrescoApi {
273273
this.setAuthenticationClientECMBPM(this.contentAuth.getAuthentication(), null);
274274

275275
this.config.ticketEcm = ticketEcm;
276-
}, () => {
276+
}, () => {
277277
console.log('login ECM error');
278278
});
279279

@@ -366,7 +366,7 @@ export class AlfrescoApi {
366366
let contentPromise = this.contentAuth.logout();
367367
contentPromise.then(() => {
368368
this.config.ticket = undefined;
369-
}, () => {
369+
}, () => {
370370
});
371371

372372
return contentPromise;

src/alfrescoApiClient.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,13 @@ export class AlfrescoApiClient {
282282
}
283283

284284
if (returnType) {
285-
data = new returnType(data);
285+
if (Array.isArray(data)) {
286+
data = data.map( (element) => {
287+
return new returnType(element);
288+
});
289+
} else {
290+
data = new returnType(data);
291+
}
286292
}
287293

288294
return data;

src/api-legacy/activiti-rest-api/src/api/ProcessApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,11 +83,11 @@ export class ProcessApi {
8383
return this.processInstancesApi.getProcessAuditPdf(processInstanceId);
8484
}
8585

86-
getRestFieldValues(processDefinitionId: string, field: string): Promise<FormValueRepresentation> {
86+
getRestFieldValues(processDefinitionId: string, field: string): Promise<FormValueRepresentation []> {
8787
return this.processDefinitionsApi.getRestFieldValues(processDefinitionId, field);
8888
}
8989

90-
getRestTableFieldValues(processDefinitionId: string, field: string, column: string): Promise<FormValueRepresentation> {
90+
getRestTableFieldValues(processDefinitionId: string, field: string, column: string): Promise<FormValueRepresentation []> {
9191
return this.processDefinitionsApi.getRestTableFieldValues(processDefinitionId, field, column);
9292
}
9393

src/api-legacy/activiti-rest-api/src/api/ProcessDefinitionsFormApi.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ export class ProcessDefinitionsFormApi {
3535
return this.processDefinitionsApi.getProcessDefinitionStartForm(processDefinitionId);
3636
}
3737

38-
getRestFieldValues(processDefinitionId: string, field: string): Promise<FormValueRepresentation> {
38+
getRestFieldValues(processDefinitionId: string, field: string): Promise<FormValueRepresentation []> {
3939
return this.processDefinitionsApi.getRestFieldValues(processDefinitionId, field);
4040
}
4141

42-
getRestTableFieldValues(processDefinitionId: string, field: string, column: string): Promise<FormValueRepresentation> {
42+
getRestTableFieldValues(processDefinitionId: string, field: string, column: string): Promise<FormValueRepresentation []> {
4343
return this.processDefinitionsApi.getRestTableFieldValues(processDefinitionId, field, column);
4444
}
4545
}

src/api/activiti-rest-api/api/processDefinitions.api.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -365,9 +365,9 @@ export class ProcessDefinitionsApi extends BaseApi {
365365
*
366366
* @param processDefinitionId processDefinitionId
367367
*
368-
* @return Promise<FormValueRepresentation>
368+
* @return Promise<FormValueRepresentation[]>
369369
*/
370-
getRestFieldValues(processDefinitionId: string, field: string): Promise<FormValueRepresentation> {
370+
getRestFieldValues(processDefinitionId: string, field: string): Promise<FormValueRepresentation []> {
371371

372372
let postBody = null;
373373

@@ -395,9 +395,9 @@ export class ProcessDefinitionsApi extends BaseApi {
395395
*
396396
* @param processDefinitionId processDefinitionId
397397
*
398-
* @return Promise<FormValueRepresentation>
398+
* @return Promise<FormValueRepresentation []>
399399
*/
400-
getRestTableFieldValues(processDefinitionId: string, field: string, column: string): Promise<FormValueRepresentation> {
400+
getRestTableFieldValues(processDefinitionId: string, field: string, column: string): Promise<FormValueRepresentation []> {
401401

402402
let postBody = null;
403403

src/api/activiti-rest-api/api/taskForms.api.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,9 @@ export class TaskFormsApi extends BaseApi {
161161
*
162162
* @param taskId taskId
163163
* @param field field
164-
* @return Promise<FormValueRepresentation>
164+
* @return Promise<FormValueRepresentation []>
165165
*/
166-
getRestFieldValues(taskId: string, field: string): Promise<FormValueRepresentation> {
166+
getRestFieldValues(taskId: string, field: string): Promise<FormValueRepresentation []> {
167167

168168
let postBody = null;
169169

test/alfrescoApiClient.spec.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*global describe, it */
22

3-
import { AlfrescoApiClient } from '../index';
3+
import { AlfrescoApiClient, FormValueRepresentation } from '../index';
44
import { DateAlfresco } from '../index';
55
let chai = require('chai');
66

@@ -77,4 +77,28 @@ describe('Alfresco Core API Client', function () {
7777

7878
});
7979

80+
describe('Deserializes', function () {
81+
82+
it('should the deserializer return an array of object when the response is an array', function() {
83+
const client = new AlfrescoApiClient();
84+
const data = {
85+
body: [
86+
{
87+
id: "1",
88+
name: "test1"
89+
},
90+
{
91+
id: "2",
92+
name: "test2"
93+
}
94+
]
95+
};
96+
const result = client.deserialize(data, FormValueRepresentation);
97+
const isArray = Array.isArray(result);
98+
const isObject = (result[0] instanceof (FormValueRepresentation));
99+
expect(isArray).to.equal(true);
100+
expect(isObject).to.equal(true);
101+
})
102+
});
103+
80104
});

0 commit comments

Comments
 (0)