-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathODI_SwingBuilder.groovy
228 lines (177 loc) · 8.08 KB
/
ODI_SwingBuilder.groovy
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
import groovy.swing.SwingBuilder
import javax.swing.WindowConstants
import java.awt.FlowLayout as FL
import javax.swing.DefaultComboBoxModel
import javax.swing.BoxLayout as BXL
import groovy.sql.Sql
import java.sql.Driver
import javax.swing.JFrame
import java.awt.BorderLayout
import oracle.odi.domain.project.finder.IOdiProjectFinder;
import oracle.odi.domain.project.OdiProject;
import oracle.odi.domain.project.finder.IOdiFolderFinder;
import oracle.odi.domain.project.OdiFolder;
import oracle.odi.domain.project.finder.IOdiVariableFinder;
import oracle.odi.domain.mapping.Mapping;
import oracle.odi.domain.mapping.component.Dataset;
import oracle.odi.domain.mapping.component.DatastoreComponent;
import oracle.odi.interfaces.interactive.support.InteractiveInterfaceHelperWithActions;
import oracle.odi.interfaces.interactive.IInteractiveInterfaceHelperWithActions;
import oracle.odi.core.persistence.transaction.ITransactionStatus;
import oracle.odi.core.persistence.transaction.support.DefaultTransactionDefinition;
import oracle.odi.domain.mapping.physical.MapPhysicalNode;
import groovy.json.JsonSlurper;
import groovy.beans.Bindable
import oracle.odi.domain.project.StepVariable.DeclareVariable
def swing = new SwingBuilder()
host = "<IP or hostname and Port of your 3rd party server>"
myExtractions=[]
ExtractionList = []
d = new java.awt.Dimension(205,20)
def arrayTextFields = []
def password
def parms = []
label = "label"
// Build list of Extractions
def getExtractionsList (extractioname) {
extractions = []
//read the file with extractions name.
new File('<OS path>/', '<filename>.txt').eachLine { line, nb ->
if(nb == 1)
return
l = line.substring(0,line.indexOf(','))
extractions.add(l)
}
updateParameters(extractioname)
return extractions.find { it == extractioname }
}
def updateParameters(myExtractions) {
def getPar = new URL(host+"<API>"+myExtractions+"/<parameters>").openConnection();
def getRCPar = getPar.getResponseCode();
if(getRCPar.equals(200)) {
a = getPar.getInputStream().getText()
// read file with parameters to be shown in GUI
def myFilePar = new File('<path>','<file_name>.txt')
myFilePar.write(a)
}
}
//Function that opens the connection to oracle database and update the control table
def updateControlTable(parameterValue, extractionName, parameterName) {
def driver = Class.forName('oracle.jdbc.OracleDriver').newInstance() as Driver
def props = new Properties()
props.setProperty("user", "<user>")
props.setProperty("password", "<password>")
def conn = driver.connect("jdbc:oracle:thin:@<host>:<port>/<service_name>", props)
def sql = new Sql(conn)
sql.executeUpdate "update <table_name> set <parameter_column>=$parameterValue WHERE <parameter_name>=$parameterName and <extraction_name>=$extractionName"
sql.close()
}
def frame = swing.frame(id: 'top', size:[500,200], title:'Xtract Server', layout:new BorderLayout()) {
noparent() {
//Open the connection to API and generates a file to read after
getExtractions = {
def get = new URL(host).openConnection();
def getRC = get.getResponseCode();
if(getRC.equals(200)) {
a = get.getInputStream().getText()
def myFile = new File('<OS path>','<file_name>.txt')
myFile.write(a)
}
new File('<OS path>', '<file_name>.txt').eachLine { line, nb ->
if(nb == 1)
return
l = line.substring(0,line.indexOf(','))
ExtractionList.add(l)
}
//Pick the first extraction by default
updateParameters(ExtractionList[0])
}
// When we select the extraction on combobox we click on "Check Parameters" button and this function generates the textboxes and ODI variables
//based on extraction parameters
generateTextField = {
if (parms.size() >0) {
try {
for(parid in parms){
removeLabel = label+parid
swing.target.remove swing."$parid"
swing.target.remove swing."$removeLabel"
swing.doLater { swing.top.validate(); swing.top.repaint() }
}
} catch (e) {println("Expetion Here"+ e) } //do nothing if list is empty
}
def jsonSlurper = new JsonSlurper()
data = jsonSlurper.parse(new File('<OS Path>/<file_name>.txt'))
try{
parameter = data.<tag on json>.name
for
varf= (IOdiVariableFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiVariable.class);
panel(alignmentX:0f) {
flowLayout(alignment:FL.RIGHT)
label(par)
parms << par
swing.target.add swing.label( "$par", id: label+par)
a = swing.target.add swing.textField( "", id: par, columns:10)
(par in parameter){
//use getfinder of ODI to find the variable with that name
def myGlobalExtractionName=varf.findGlobalByName("$par")
arrayTextFields << a
if (myGlobalExtractionName == null){
txnDef = new DefaultTransactionDefinition();
tm = odiInstance.getTransactionManager();
tme = odiInstance.getTransactionalEntityManager()
txnStatus = tm.getTransaction(txnDef);
myVar = new OdiVariable ("$par")
odiInstance.getTransactionalEntityManager().persist(myVar)
tm.commit(txnStatus)
}
swing.doLater { swing.top.validate() }
}
}
}catch (Exception e){
println("Exception "+ e)
}
}
// Function that reads the array with parameters and updates the variables
//In the end updates the control table calling the function updateControlTable
saveParameters = {
for (myVar in arrayTextFields){
txnDef = new DefaultTransactionDefinition();
tm = odiInstance.getTransactionManager();
tme = odiInstance.getTransactionalEntityManager()
txnStatus = tm.getTransaction(txnDef);
varf= (IOdiVariableFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiVariable.class);
name=myVar.name
def myGlobalExtractionName=varf.findGlobalByName("$name")
myGlobalExtractionName.setDefaultValue(swing."$name".text)
tm.commit(txnStatus);
updateControlTable(swing."$name".text, "$myExtractions".toUpperCase(), "$name".toUpperCase())
}
swing.doLater { swing.top.dispose()}
}
}
panel(id:'buttonPane',constraints:BorderLayout.NORTH) {
txnDef = new DefaultTransactionDefinition();
tm = odiInstance.getTransactionManager();
tme = odiInstance.getTransactionalEntityManager()
txnStatus = tm.getTransaction(txnDef);
varf= (IOdiVariableFinder)odiInstance.getTransactionalEntityManager().getFinder(OdiVariable.class);
// Getting all extractions
getExtractions()
myExtractions = ExtractionList[0]
label('Extraction Name:')
comboBox(id:'extractioname',
items:ExtractionList,
preferredSize:d,
itemStateChanged:{event->
myExtractions = getExtractionsList(extractioname.selectedItem) })
button( '<html>OK </html>', actionPerformed: saveParameters)
button( '<html>Check Parameters</html>', actionPerformed: generateTextField)
}
panel(id:'target', constraints:BorderLayout.CENTER, size: [150,150]) {
flowLayout()
label( '')
}
}
swing.doLater {
frame.show()
}