1
|
|
|
package br.ufrj.ppgi.greco.kettle; |
2
|
|
|
|
3
|
|
|
import java.util.List; |
4
|
|
|
import java.util.Map; |
5
|
|
|
|
6
|
|
|
import org.pentaho.di.core.CheckResult; |
7
|
|
|
import org.pentaho.di.core.CheckResultInterface; |
8
|
|
|
import org.pentaho.di.core.Counter; |
9
|
|
|
import org.pentaho.di.core.database.DatabaseMeta; |
10
|
|
|
import org.pentaho.di.core.exception.KettleException; |
11
|
|
|
import org.pentaho.di.core.exception.KettleStepException; |
12
|
|
|
import org.pentaho.di.core.exception.KettleXMLException; |
13
|
|
|
import org.pentaho.di.core.row.RowMetaInterface; |
14
|
|
|
import org.pentaho.di.core.row.ValueMetaInterface; |
15
|
|
|
import org.pentaho.di.core.row.value.ValueMetaBoolean; |
16
|
|
|
import org.pentaho.di.core.row.value.ValueMetaInteger; |
17
|
|
|
import org.pentaho.di.core.row.value.ValueMetaString; |
18
|
|
|
import org.pentaho.di.core.variables.VariableSpace; |
19
|
|
|
import org.pentaho.di.core.xml.XMLHandler; |
20
|
|
|
import org.pentaho.di.repository.ObjectId; |
21
|
|
|
import org.pentaho.di.repository.Repository; |
22
|
|
|
import org.pentaho.di.trans.Trans; |
23
|
|
|
import org.pentaho.di.trans.TransMeta; |
24
|
|
|
import org.pentaho.di.trans.step.BaseStepMeta; |
25
|
|
|
import org.pentaho.di.trans.step.StepDataInterface; |
26
|
|
|
import org.pentaho.di.trans.step.StepInterface; |
27
|
|
|
import org.pentaho.di.trans.step.StepMeta; |
28
|
|
|
import org.pentaho.di.trans.step.StepMetaInterface; |
29
|
|
|
import org.w3c.dom.Node; |
30
|
|
|
|
31
|
|
|
public class SparqlUpdateInsertStepMeta extends BaseStepMeta implements StepMetaInterface { |
32
|
|
|
|
33
|
|
|
// Fields for serialization |
34
|
|
|
public enum Field { |
35
|
|
|
RDF_CONTENT, GRAPH_URI, CLEAR_GRAPH, PROTOCOL, HOSTNAME, PORT, PATH, USERNAME, PASSWORD, ENDPOINT_URL, OUT_CODE, OUT_MESSAGE |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
// Values - tipo refere-se ao tipo destas variaveis |
39
|
|
|
private String rdfContentFieldName; |
40
|
|
|
private String graphUriValue; |
41
|
|
|
private Boolean clearGraph; |
42
|
|
|
private String endpointUrl; |
43
|
|
|
private String username; |
44
|
|
|
private String password; |
45
|
|
|
// Output - ATENCAO: tipo refere-se ao tipo dos campos cujos nomes sao |
46
|
|
|
// especificados por estas variaveis |
47
|
|
|
private String resultCodeFieldName; |
48
|
|
|
private String resultMessageFieldName; |
49
|
|
|
|
50
|
|
|
public SparqlUpdateInsertStepMeta() { |
51
|
|
|
setDefault(); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
// TODO Validar todos os campos para dar feedback ao usuario! |
55
|
|
|
@Override |
56
|
|
|
public void check(List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta, RowMetaInterface prev, |
57
|
|
|
String[] input, String[] output, RowMetaInterface info) { |
58
|
|
|
|
59
|
|
|
// if (Const.isEmpty(fieldName)) { |
60
|
|
|
// CheckResultInterface error = new CheckResult( |
61
|
|
|
// CheckResult.TYPE_RESULT_ERROR, |
62
|
|
|
// "error rorororroroo", |
63
|
|
|
// stepMeta); |
64
|
|
|
// remarks.add(error); |
65
|
|
|
// } |
66
|
|
|
// else { |
67
|
|
|
CheckResultInterface ok = new CheckResult(CheckResult.TYPE_RESULT_OK, "", stepMeta); |
68
|
|
|
remarks.add(ok); |
69
|
|
|
// } |
70
|
|
|
|
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
public StepInterface getStep(StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, |
74
|
|
|
TransMeta transMeta, Trans trans) { |
75
|
|
|
return new SparqlUpdateInsertStep(stepMeta, stepDataInterface, copyNr, transMeta, trans); |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
public StepDataInterface getStepData() { |
79
|
|
|
return new SparqlUpdateInsertStepData(); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
@Override |
83
|
|
|
public String getDialogClassName() { |
84
|
|
|
return SparqlUpdateInsertStepDialog.class.getName(); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
@Override |
88
|
|
|
public void loadXML(Node stepDomNode, List<DatabaseMeta> databases, Map<String, Counter> sequenceCounters) |
89
|
|
|
throws KettleXMLException { |
90
|
|
|
|
91
|
|
|
rdfContentFieldName = XMLHandler.getTagValue(stepDomNode, Field.RDF_CONTENT.name()); |
92
|
|
|
graphUriValue = XMLHandler.getTagValue(stepDomNode, Field.GRAPH_URI.name()); |
93
|
|
|
clearGraph = "Y".equals(XMLHandler.getTagValue(stepDomNode, Field.CLEAR_GRAPH.name())); |
94
|
|
|
endpointUrl = XMLHandler.getTagValue(stepDomNode, Field.ENDPOINT_URL.name()); |
95
|
|
|
username = XMLHandler.getTagValue(stepDomNode, Field.USERNAME.name()); |
96
|
|
|
password = XMLHandler.getTagValue(stepDomNode, Field.PASSWORD.name()); |
97
|
|
|
resultCodeFieldName = XMLHandler.getTagValue(stepDomNode, Field.OUT_CODE.name()); |
98
|
|
|
resultMessageFieldName = XMLHandler.getTagValue(stepDomNode, Field.OUT_MESSAGE.name()); |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
@Override |
102
|
|
|
public String getXML() throws KettleException { |
103
|
|
|
StringBuilder xml = new StringBuilder(); |
104
|
|
|
xml.append(XMLHandler.addTagValue(Field.RDF_CONTENT.name(), rdfContentFieldName)); |
105
|
|
|
xml.append(XMLHandler.addTagValue(Field.GRAPH_URI.name(), graphUriValue)); |
106
|
|
|
xml.append(XMLHandler.addTagValue(Field.CLEAR_GRAPH.name(), clearGraph)); |
107
|
|
|
xml.append(XMLHandler.addTagValue(Field.ENDPOINT_URL.name(), endpointUrl)); |
108
|
|
|
xml.append(XMLHandler.addTagValue(Field.USERNAME.name(), username)); |
109
|
|
|
xml.append(XMLHandler.addTagValue(Field.PASSWORD.name(), password)); |
110
|
|
|
xml.append(XMLHandler.addTagValue(Field.OUT_CODE.name(), resultCodeFieldName)); |
111
|
|
|
xml.append(XMLHandler.addTagValue(Field.OUT_MESSAGE.name(), resultMessageFieldName)); |
112
|
|
|
return xml.toString(); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
@Override |
116
|
|
|
public void readRep(Repository repository, ObjectId stepIdInRepository, List<DatabaseMeta> databases, |
117
|
|
|
Map<String, Counter> sequenceCounters) throws KettleException { |
118
|
|
|
|
119
|
|
|
rdfContentFieldName = repository.getStepAttributeString(stepIdInRepository, Field.RDF_CONTENT.name()); |
120
|
|
|
graphUriValue = repository.getStepAttributeString(stepIdInRepository, Field.GRAPH_URI.name()); |
121
|
|
|
clearGraph = repository.getStepAttributeBoolean(stepIdInRepository, Field.CLEAR_GRAPH.name()); |
122
|
|
|
endpointUrl = repository.getStepAttributeString(stepIdInRepository, Field.ENDPOINT_URL.name()); |
123
|
|
|
username = repository.getStepAttributeString(stepIdInRepository, Field.USERNAME.name()); |
124
|
|
|
password = repository.getStepAttributeString(stepIdInRepository, Field.PASSWORD.name()); |
125
|
|
|
resultCodeFieldName = repository.getStepAttributeString(stepIdInRepository, Field.OUT_CODE.name()); |
126
|
|
|
resultMessageFieldName = repository.getStepAttributeString(stepIdInRepository, Field.OUT_MESSAGE.name()); |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
@Override |
130
|
|
|
public void saveRep(Repository repository, ObjectId idOfTransformation, ObjectId idOfStep) throws KettleException { |
131
|
|
|
|
132
|
|
|
repository.saveStepAttribute(idOfTransformation, idOfStep, Field.RDF_CONTENT.name(), rdfContentFieldName); |
133
|
|
|
repository.saveStepAttribute(idOfTransformation, idOfStep, Field.GRAPH_URI.name(), graphUriValue); |
134
|
|
|
repository.saveStepAttribute(idOfTransformation, idOfStep, Field.CLEAR_GRAPH.name(), clearGraph); |
135
|
|
|
repository.saveStepAttribute(idOfTransformation, idOfStep, Field.ENDPOINT_URL.name(), endpointUrl); |
136
|
|
|
repository.saveStepAttribute(idOfTransformation, idOfStep, Field.USERNAME.name(), username); |
137
|
|
|
repository.saveStepAttribute(idOfTransformation, idOfStep, Field.PASSWORD.name(), password); |
138
|
|
|
repository.saveStepAttribute(idOfTransformation, idOfStep, Field.OUT_CODE.name(), resultCodeFieldName); |
139
|
|
|
repository.saveStepAttribute(idOfTransformation, idOfStep, Field.OUT_MESSAGE.name(), resultMessageFieldName); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
public void setDefault() { |
143
|
|
|
graphUriValue = ""; |
144
|
|
|
rdfContentFieldName = ""; |
145
|
|
|
clearGraph = true; |
146
|
|
|
|
147
|
|
|
endpointUrl = "http://example.com:80/sparql-auth"; |
148
|
|
|
username = "username"; |
149
|
|
|
password = ""; |
150
|
|
|
|
151
|
|
|
resultCodeFieldName = "status_code"; |
152
|
|
|
resultMessageFieldName = "status_message"; |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
// Para os campos Field.OUT_*, refere-se ao tipo dos campos cujos nomes sao |
156
|
|
|
// especificados pelas estas variaveis desta classe Meta |
157
|
|
|
public int getFieldType(Field field) { |
158
|
|
|
if (field == Field.PORT) |
159
|
|
|
return ValueMetaInterface.TYPE_INTEGER; |
160
|
|
|
if (field == Field.OUT_CODE) |
161
|
|
|
return ValueMetaInterface.TYPE_INTEGER; |
162
|
|
|
else if (field == Field.CLEAR_GRAPH) |
163
|
|
|
return ValueMetaInterface.TYPE_BOOLEAN; |
164
|
|
|
else |
165
|
|
|
return ValueMetaInterface.TYPE_STRING; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
public ValueMetaInterface getValueMeta(String name, Field field) { |
169
|
|
|
if (field == Field.PORT) |
170
|
|
|
return new ValueMetaInteger(name); |
171
|
|
|
if (field == Field.OUT_CODE) |
172
|
|
|
return new ValueMetaInteger(name); |
173
|
|
|
else if (field == Field.CLEAR_GRAPH) |
174
|
|
|
return new ValueMetaBoolean(name); |
175
|
|
|
else |
176
|
|
|
return new ValueMetaString(name); |
177
|
|
|
} |
178
|
|
|
|
179
|
|
|
/** |
180
|
|
|
* it describes what each output row is going to look like |
181
|
|
|
*/ |
182
|
|
|
@Override |
183
|
|
|
public void getFields(RowMetaInterface inputRowMeta, String name, RowMetaInterface[] info, StepMeta nextStep, |
184
|
|
|
VariableSpace space) throws KettleStepException { |
185
|
|
|
|
186
|
|
|
ValueMetaInterface field = null; |
187
|
|
|
|
188
|
|
|
field = getValueMeta(resultCodeFieldName, Field.OUT_CODE); |
189
|
|
|
field.setOrigin(name); |
190
|
|
|
inputRowMeta.addValueMeta(field); |
191
|
|
|
|
192
|
|
|
field = getValueMeta(resultMessageFieldName, Field.OUT_MESSAGE); |
193
|
|
|
field.setOrigin(name); |
194
|
|
|
inputRowMeta.addValueMeta(field); |
195
|
|
|
} |
196
|
|
|
|
197
|
|
|
// Getters & Setters |
198
|
|
|
|
199
|
|
|
public String getRdfContentFieldName() { |
200
|
|
|
return rdfContentFieldName; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
public void setRdfContentFieldName(String value) { |
204
|
|
|
rdfContentFieldName = value; |
205
|
|
|
} |
206
|
|
|
|
207
|
|
|
public String getGraphUriValue() { |
208
|
|
|
return graphUriValue; |
209
|
|
|
} |
210
|
|
|
|
211
|
|
|
public void setGraphUriValue(String graphUriValue) { |
212
|
|
|
this.graphUriValue = graphUriValue; |
213
|
|
|
} |
214
|
|
|
|
215
|
|
|
public Boolean getClearGraph() { |
216
|
|
|
return clearGraph; |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
public void setClearGraph(Boolean clearGraph) { |
220
|
|
|
this.clearGraph = clearGraph; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
public String getEndpointUrl() { |
224
|
|
|
return endpointUrl; |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
public void setEndpointUrl(String endpointUrl) { |
228
|
|
|
this.endpointUrl = endpointUrl; |
229
|
|
|
} |
230
|
|
|
|
231
|
|
|
public String getUsername() { |
232
|
|
|
return username; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
public void setUsername(String username) { |
236
|
|
|
this.username = username; |
237
|
|
|
} |
238
|
|
|
|
239
|
|
|
public String getPassword() { |
240
|
|
|
return password; |
241
|
|
|
} |
242
|
|
|
|
243
|
|
|
public void setPassword(String password) { |
244
|
|
|
this.password = password; |
245
|
|
|
} |
246
|
|
|
|
247
|
|
|
public String getResultCodeFieldName() { |
248
|
|
|
return resultCodeFieldName; |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
public void setResultCodeFieldName(String resultCodeFieldName) { |
252
|
|
|
this.resultCodeFieldName = resultCodeFieldName; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
public String getResultMessageFieldName() { |
256
|
|
|
return resultMessageFieldName; |
257
|
|
|
} |
258
|
|
|
|
259
|
|
|
public void setResultMessageFieldName(String resultMessageFieldName) { |
260
|
|
|
this.resultMessageFieldName = resultMessageFieldName; |
261
|
|
|
} |
262
|
|
|
} |
263
|
|
|
|