-
Notifications
You must be signed in to change notification settings - Fork 2
/
activity.ts
executable file
·186 lines (172 loc) · 6.32 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* 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 JSONParserContributionHandler extends WiServiceHandlerContribution {
constructor(@Inject(Injector) injector, private http: Http) {
super(injector, http);
}
value = (fieldName: string, context: IActivityContribution): Observable<any> | any => {
console.log('value ?????????? fieldName = ' + fieldName);
let serveGraphData: IFieldDefinition = context.getField("ServeGraphData")
let attrNames: IFieldDefinition = context.getField("OutputFieldnames");
let graphModel: IFieldDefinition = context.getField("GraphModel");
let data = [];
if(attrNames.value) {
data = JSON.parse(attrNames.value)
}
if (serveGraphData.value) {
let previousConnector = context.getField("PreviousConnector").value
let selectedConnector : string;
let allowedConnectors = context.getField("GraphModel").allowed;
let selectedConnectorId = context.getField("GraphModel").value;
for(let allowedConnector of allowedConnectors) {
if(allowedConnector["unique_id"] === selectedConnectorId) {
selectedConnector = allowedConnector["name"]
}
}
if (fieldName === "GraphModel") {
return Observable.create(observer => {
//Connector Type must match with the category defined in connector.json
WiContributionUtils.getConnections(this.http, "GraphBuilder").subscribe((data: IConnectorContribution[]) => {
let connectionRefs = [];
data.forEach(connection => {
for (let setting of connection.settings) {
if(setting.name === "name") {
connectionRefs.push({
"unique_id": WiContributionUtils.getUniqueId(connection),
"name": setting.value
});
}
}
});
observer.next(connectionRefs);
observer.complete();
});
});
} else if (fieldName === "OutputFieldnames") {
//[{"parameterName":"","type":"string","repeating":"false","required":"false","isEditable":true,"AttributeName":"aa","JSONPath":"aa","Default":"a","Type":"String","Optional":"yes"}]
return buildData(this.http, selectedConnector, (content : string) => {
console.log('in value >>>>>>>> selectedConnector = ' + selectedConnector + ', previousConnector = ' + previousConnector);
if(content && (0===data.length||selectedConnector!=previousConnector)) {
data = [];
let graphModel = JSON.parse(content);
buildAttributeDataForEntity("node", data, graphModel["nodes"])
buildAttributeDataForEntity("edge", data, graphModel["edges"])
}
return data;
});
} else if (fieldName === "PreviousConnector"){
return selectedConnector;
}
}
if (fieldName === "Data") {
var attrJsonSchema = [{}];
let attrNames: IFieldDefinition = context.getField("OutputFieldnames");
if (attrNames.value) {
let data = JSON.parse(attrNames.value);
for (var i = 0; i < data.length; i++) {
attrJsonSchema[0][data[i].AttributeName] = populateAttribute(data[i].Type);
}
attrJsonSchema[0]["LastElement"] = populateAttribute("Boolean");
}
return JSON.stringify(attrJsonSchema);
}
return null;
}
validate = (fieldName: string, context: IActivityContribution): Observable<IValidationResult> | IValidationResult => {
console.log('validate >>>>>>>> fieldName = ' + fieldName);
if (fieldName === "GraphModel") {
let serveGraphData: IFieldDefinition = context.getField("ServeGraphData")
console.log(serveGraphData)
if (serveGraphData.value) {
return ValidationResult.newValidationResult().setVisible(true);
} else {
return ValidationResult.newValidationResult().setVisible(false);
}
} else if (fieldName === "PreviousConnector") {
return ValidationResult.newValidationResult().setVisible(false);
}
return null;
}
}
function buildData(http, selectedConnector, builder) : Observable<any> {
return Observable.create(observer => {
WiContributionUtils.getConnections(http, "GraphBuilder").subscribe((data: IConnectorContribution[]) => {
let content : string;
data.forEach(connection => {
var currentConnector;
for (let setting of connection.settings) {
if(setting.name === "name") {
currentConnector = setting.value
}else if (setting.name === "metadata"&&
selectedConnector === currentConnector) {
content = setting.value;
}
}
});
console.log("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO")
console.log(content)
console.log("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO")
console.log(builder(content))
console.log("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO")
observer.next(JSON.stringify(builder(content)));
observer.complete();
});
});
}
function buildAttributeDataForEntity(entityType, data, entities) {
for(let entity of entities) {
let entityName = entity["name"];
if(!entity["attributes"]) {
continue;
}
for(let attr of entity["attributes"]) {
let attrName = attr["name"];
data.push({
"parameterName":"",
"type":"string",
"repeating":"false",
"required":"false",
"isEditable":true,
"AttributeName":entityType+"_"+entityName+"_"+attrName,
"JSONPath":"",
"Default":"",
"Type":attr["type"],
"Optional":"yes"
});
}
}
}
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";
}
}