-
Notifications
You must be signed in to change notification settings - Fork 3.4k
/
AppendMeta.java
228 lines (197 loc) · 8.85 KB
/
AppendMeta.java
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
/*! ******************************************************************************
*
* Pentaho Data Integration
*
* Copyright (C) 2002-2017 by Pentaho : http://www.pentaho.com
*
*******************************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
******************************************************************************/
package org.pentaho.di.trans.steps.append;
import java.util.List;
import org.pentaho.di.core.CheckResult;
import org.pentaho.di.core.CheckResultInterface;
import org.pentaho.di.core.annotations.Step;
import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.exception.KettleException;
import org.pentaho.di.core.exception.KettleStepException;
import org.pentaho.di.core.exception.KettleXMLException;
import org.pentaho.di.core.injection.Injection;
import org.pentaho.di.core.injection.InjectionSupported;
import org.pentaho.di.core.row.RowMetaInterface;
import org.pentaho.di.core.variables.VariableSpace;
import org.pentaho.di.core.xml.XMLHandler;
import org.pentaho.di.i18n.BaseMessages;
import org.pentaho.di.repository.ObjectId;
import org.pentaho.di.repository.Repository;
import org.pentaho.di.trans.Trans;
import org.pentaho.di.trans.TransMeta;
import org.pentaho.di.trans.TransMeta.TransformationType;
import org.pentaho.di.trans.step.BaseStepMeta;
import org.pentaho.di.trans.step.StepDataInterface;
import org.pentaho.di.trans.step.StepIOMeta;
import org.pentaho.di.trans.step.StepIOMetaInterface;
import org.pentaho.di.trans.step.StepInterface;
import org.pentaho.di.trans.step.StepMeta;
import org.pentaho.di.trans.step.StepMetaInterface;
import org.pentaho.di.trans.step.errorhandling.Stream;
import org.pentaho.di.trans.step.errorhandling.StreamIcon;
import org.pentaho.di.trans.step.errorhandling.StreamInterface;
import org.pentaho.di.trans.step.errorhandling.StreamInterface.StreamType;
import org.pentaho.metastore.api.IMetaStore;
import org.w3c.dom.Node;
/**
* @author Sven Boden
* @since 3-june-2007
*/
@Step( id = "Append", image = "APP.svg", i18nPackageName = "org.pentaho.di.trans.steps.append",
name = "Append.Name", description = "Append.Description",
documentationUrl = "http://wiki.pentaho.com/display/EAI/Append+streams",
categoryDescription = "i18n:org.pentaho.di.trans.step:BaseStep.Category.Flow" )
@InjectionSupported( localizationPrefix = "AppendMeta.Injection." )
public class AppendMeta extends BaseStepMeta implements StepMetaInterface {
private static Class<?> PKG = Append.class; // for i18n purposes, needed by Translator2!!
@Injection( name = "HEAD_STEP" )
public String headStepname;
@Injection( name = "TAIL_STEP" )
public String tailStepname;
public AppendMeta() {
super(); // allocate BaseStepMeta
}
public void loadXML( Node stepnode, List<DatabaseMeta> databases, IMetaStore metaStore ) throws KettleXMLException {
readData( stepnode );
}
public Object clone() {
AppendMeta retval = (AppendMeta) super.clone();
return retval;
}
public String getXML() {
StringBuilder retval = new StringBuilder();
List<StreamInterface> infoStreams = getStepIOMeta().getInfoStreams();
retval.append( XMLHandler.addTagValue( "head_name", infoStreams.get( 0 ).getStepname() ) );
retval.append( XMLHandler.addTagValue( "tail_name", infoStreams.get( 1 ).getStepname() ) );
return retval.toString();
}
private void readData( Node stepnode ) throws KettleXMLException {
try {
List<StreamInterface> infoStreams = getStepIOMeta().getInfoStreams();
StreamInterface headStream = infoStreams.get( 0 );
StreamInterface tailStream = infoStreams.get( 1 );
headStream.setSubject( XMLHandler.getTagValue( stepnode, "head_name" ) );
tailStream.setSubject( XMLHandler.getTagValue( stepnode, "tail_name" ) );
} catch ( Exception e ) {
throw new KettleXMLException( BaseMessages.getString( PKG, "AppendMeta.Exception.UnableToLoadStepInfo" ), e );
}
}
public void setDefault() {
}
public void readRep( Repository rep, IMetaStore metaStore, ObjectId id_step, List<DatabaseMeta> databases ) throws KettleException {
try {
List<StreamInterface> infoStreams = getStepIOMeta().getInfoStreams();
StreamInterface headStream = infoStreams.get( 0 );
StreamInterface tailStream = infoStreams.get( 1 );
headStream.setSubject( rep.getStepAttributeString( id_step, "head_name" ) );
tailStream.setSubject( rep.getStepAttributeString( id_step, "tail_name" ) );
} catch ( Exception e ) {
throw new KettleException( BaseMessages.getString(
PKG, "AppendMeta.Exception.UnexpectedErrorReadingStepInfo" ), e );
}
}
public void saveRep( Repository rep, IMetaStore metaStore, ObjectId id_transformation, ObjectId id_step ) throws KettleException {
try {
List<StreamInterface> infoStreams = getStepIOMeta().getInfoStreams();
StreamInterface headStream = infoStreams.get( 0 );
StreamInterface tailStream = infoStreams.get( 1 );
rep.saveStepAttribute( id_transformation, id_step, "head_name", headStream.getStepname() );
rep.saveStepAttribute( id_transformation, id_step, "tail_name", tailStream.getStepname() );
} catch ( Exception e ) {
throw new KettleException( BaseMessages.getString( PKG, "AppendMeta.Exception.UnableToSaveStepInfo" )
+ id_step, e );
}
}
@Override
public void searchInfoAndTargetSteps( List<StepMeta> steps ) {
for ( StreamInterface stream : getStepIOMeta().getInfoStreams() ) {
stream.setStepMeta( StepMeta.findStep( steps, (String) stream.getSubject() ) );
}
}
public boolean chosesTargetSteps() {
return false;
}
public String[] getTargetSteps() {
return null;
}
public void getFields( RowMetaInterface r, String name, RowMetaInterface[] info, StepMeta nextStep,
VariableSpace space, Repository repository, IMetaStore metaStore ) throws KettleStepException {
// We don't have any input fields here in "r" as they are all info fields.
// So we just take the info fields.
//
if ( info != null ) {
if ( info.length > 0 && info[0] != null ) {
r.mergeRowMeta( info[0] );
}
}
}
public void check( List<CheckResultInterface> remarks, TransMeta transMeta, StepMeta stepMeta,
RowMetaInterface prev, String[] input, String[] output, RowMetaInterface info, VariableSpace space,
Repository repository, IMetaStore metaStore ) {
CheckResult cr;
List<StreamInterface> infoStreams = getStepIOMeta().getInfoStreams();
StreamInterface headStream = infoStreams.get( 0 );
StreamInterface tailStream = infoStreams.get( 1 );
if ( headStream.getStepname() != null && tailStream.getStepname() != null ) {
cr =
new CheckResult( CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(
PKG, "AppendMeta.CheckResult.SourceStepsOK" ), stepMeta );
remarks.add( cr );
} else if ( headStream.getStepname() == null && tailStream.getStepname() == null ) {
cr =
new CheckResult( CheckResultInterface.TYPE_RESULT_ERROR, BaseMessages.getString(
PKG, "AppendMeta.CheckResult.SourceStepsMissing" ), stepMeta );
remarks.add( cr );
} else {
cr =
new CheckResult( CheckResultInterface.TYPE_RESULT_OK, BaseMessages.getString(
PKG, "AppendMeta.CheckResult.OneSourceStepMissing" ), stepMeta );
remarks.add( cr );
}
}
public StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int cnr, TransMeta tr,
Trans trans ) {
return new Append( stepMeta, stepDataInterface, cnr, tr, trans );
}
public StepDataInterface getStepData() {
return new AppendData();
}
/**
* Returns the Input/Output metadata for this step.
*/
public StepIOMetaInterface getStepIOMeta() {
if ( ioMeta == null ) {
ioMeta = new StepIOMeta( true, true, false, false, false, false );
ioMeta.addStream( new Stream( StreamType.INFO, null, BaseMessages.getString(
PKG, "AppendMeta.InfoStream.FirstStream.Description" ), StreamIcon.INFO, null ) );
ioMeta.addStream( new Stream( StreamType.INFO, null, BaseMessages.getString(
PKG, "AppendMeta.InfoStream.SecondStream.Description" ), StreamIcon.INFO, null ) );
}
return ioMeta;
}
@Override
public void resetStepIoMeta() {
}
public TransformationType[] getSupportedTransformationTypes() {
return new TransformationType[] { TransformationType.Normal, };
}
}