/
activity.ts
executable file
·72 lines (62 loc) · 1.96 KB
/
activity.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
* Copyright © 2020. TIBCO Software Inc.
* This file is subject to the license terms contained
* in the license file that is distributed with this file.
*/
import {Observable} from "rxjs/Observable";
import {Injectable, Injector, Inject} from "@angular/core";
import {Http} from "@angular/http";
import {
WiContrib,
WiServiceHandlerContribution,
IValidationResult,
ValidationResult,
IFieldDefinition,
IActivityContribution,
IConnectorContribution,
WiContributionUtils
} from "wi-studio/app/contrib/wi-contrib";
@WiContrib({})
@Injectable()
export class CSVFileWriterContributionHandler extends WiServiceHandlerContribution {
filename: string;
content: string;
constructor(@Inject(Injector) injector, private http: Http) {
super(injector, http);
}
value = (fieldName: string, context: IActivityContribution): Observable<any> | any => {
console.log('[CSVFileWriterContributionHandler::value] fieldName = ' + fieldName);
if (fieldName === "CSVFields") {
var attrJsonSchema = {};
let attrNames: IFieldDefinition = context.getField("CSVFieldnames");
if (attrNames.value) {
let data = JSON.parse(attrNames.value);
for (var i = 0; i < data.length; i++) {
attrJsonSchema[data[i].Name] = populateAttribute(data[i].Type);
}
}
return JSON.stringify(attrJsonSchema);
}
return null;
}
validate = (fieldName: string, context: IActivityContribution): Observable<IValidationResult> | IValidationResult => {
console.log('[CSVFileWriterContributionHandler::validate] fieldName = ' + fieldName);
return null;
}
}
function populateAttribute(attrType) : any {
switch(attrType) {
case "Double" :
return 2.0;
case "Integer":
return 2;
case "Long":
return 2;
case "Boolean":
return true;
case "Date":
return 2;
default:
return "2";
}
}