-
Notifications
You must be signed in to change notification settings - Fork 2
/
activity.ts
executable file
·127 lines (115 loc) · 3.35 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/*
* 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 JSONDataDecouplerContributionHandler 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('fieldName = ' + fieldName);
let model: IFieldDefinition;
let filename: string;
let content: string;
let decoupleTarget: string;
if(fieldName === "JSONObject") {
for (let configuration of context.settings) {
if( configuration.name === "sample") {
let schemaObj: any;
model = configuration
if(configuration.value) {
filename = configuration.value.filename;
content = configuration.value.content;
if(content) {
content = content.substr(content.indexOf(',')+1);
content = atob(content);
}
return JSON.stringify(JSON.parse(content));
}
}
}
return JSON.stringify({});
} else if(fieldName === "Data") {
for (let configuration of context.settings) {
if( configuration.name === "sample") {
let schemaObj: any;
model = configuration
if(configuration.value) {
console.log(context.settings);
filename = configuration.value.filename;
content = configuration.value.content;
if(content) {
content = content.substr(content.indexOf(',')+1);
content = atob(content);
}
let outJsonObject = [{}];
let JsonObject = JSON.parse(content);
let decoupleTarget = context.getField("decoupleTarget").value;
console.log(decoupleTarget);
outJsonObject[0]["originJSONObject"] = JsonObject;
let target = JsonObject;
let decoupleTargetElements = decoupleTarget.split('.')
for (let index in decoupleTargetElements) {
target = target[decoupleTargetElements[index]];
}
outJsonObject[0][decoupleTarget.concat(".Index")] = populateAttribute("Integer");
outJsonObject[0][decoupleTarget.concat(".Element")] = target[0];
outJsonObject[0]["LastElement"] = populateAttribute("Boolean");
return JSON.stringify(outJsonObject);
}
}
}
return JSON.stringify({});
}
return null;
}
validate = (fieldName: string, context: IActivityContribution): Observable<IValidationResult> | IValidationResult => {
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";
}
}
/*
function buildJSON(jsonelement) : any {
switch(typeof jsonelement) {
case object :
return 2.0;
case array :
return 2;
default:
return "2";
}
}
*/