use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryTransDelegate method saveTransformation.
/**
* Saves the transformation to a repository.
*
* @param transMeta
* the transformation metadata to store
* @param monitor
* the way we report progress to the user, can be null if no UI is present
* @param overwrite
* Overwrite existing object(s)?
* @throws KettleException
* if an error occurs.
*/
public void saveTransformation(TransMeta transMeta, String versionComment, ProgressMonitorListener monitor, boolean overwriteAssociated) throws KettleException {
try {
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.LockingRepository"));
}
repository.insertLogEntry("save transformation '" + transMeta.getName() + "'");
// Clear attribute id cache
// force repository lookup.
repository.connectionDelegate.clearNextIDCounters();
// Do we have a valid directory?
if (transMeta.getRepositoryDirectory().getObjectId() == null) {
throw new KettleException(BaseMessages.getString(PKG, "TransMeta.Exception.PlsSelectAValidDirectoryBeforeSavingTheTransformation"));
}
int nrWorks = 2 + transMeta.nrDatabases() + transMeta.nrNotes() + transMeta.nrSteps() + transMeta.nrTransHops();
if (monitor != null) {
monitor.beginTask(BaseMessages.getString(PKG, "TransMeta.Monitor.SavingTransformationTask.Title") + transMeta.getPathAndName(), nrWorks);
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingOfTransformationStarted"));
}
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException();
}
//
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.HandlingOldVersionTransformationTask.Title"));
// transMeta.setObjectId(getTransformationID(transMeta.getName(),
// transMeta.getRepositoryDirectory().getObjectId()));
}
// If no valid id is available in the database, assign one...
if (transMeta.getObjectId() == null) {
transMeta.setObjectId(repository.connectionDelegate.getNextTransformationID());
} else {
// of the database for this id_transformation, before we put it back in...
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.DeletingOldVersionTransformationTask.Title"));
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.DeletingOldVersionTransformation"));
}
repository.deleteTransformation(transMeta.getObjectId());
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.OldVersionOfTransformationRemoved"));
}
}
if (monitor != null) {
monitor.worked(1);
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingNotes"));
}
for (int i = 0; i < transMeta.nrNotes(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.SavingNoteTask.Title") +
// (i + 1) + "/" + transMeta.nrNotes());
NotePadMeta ni = transMeta.getNote(i);
repository.saveNotePadMeta(ni, transMeta.getObjectId());
if (ni.getObjectId() != null) {
repository.insertTransNote(transMeta.getObjectId(), ni.getObjectId());
}
if (monitor != null) {
monitor.worked(1);
}
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingDatabaseConnections"));
}
for (int i = 0; i < transMeta.nrDatabases(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG,
// "TransMeta.Monitor.SavingDatabaseTask.Title") + (i + 1) + "/" + transMeta.nrDatabases());
DatabaseMeta databaseMeta = transMeta.getDatabase(i);
// repository)
if (overwriteAssociated || databaseMeta.hasChanged() || databaseMeta.getObjectId() == null) {
repository.save(databaseMeta, versionComment, monitor, overwriteAssociated);
}
if (monitor != null) {
monitor.worked(1);
}
}
// It is possible that we received another step through a plugin.
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.CheckingStepTypes"));
}
repository.updateStepTypes();
repository.updateDatabaseTypes();
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingSteps"));
}
for (int i = 0; i < transMeta.nrSteps(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.SavingStepTask.Title") +
// (i + 1) + "/" + transMeta.nrSteps());
StepMeta stepMeta = transMeta.getStep(i);
repository.stepDelegate.saveStepMeta(stepMeta, transMeta.getObjectId());
if (monitor != null) {
monitor.worked(1);
}
}
repository.connectionDelegate.closeStepAttributeInsertPreparedStatement();
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingHops"));
}
for (int i = 0; i < transMeta.nrTransHops(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.SavingHopTask.Title") +
// (i + 1) + "/" + transMeta.nrTransHops());
TransHopMeta hi = transMeta.getTransHop(i);
saveTransHopMeta(hi, transMeta.getObjectId());
if (monitor != null) {
monitor.worked(1);
}
}
// if (monitor != null) monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.FinishingTask.Title"));
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingTransformationInfo"));
}
// save the top level information for the transformation
insertTransformation(transMeta);
saveTransParameters(transMeta);
repository.connectionDelegate.closeTransAttributeInsertPreparedStatement();
//
for (int i = 0; i < transMeta.getPartitionSchemas().size(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
PartitionSchema partitionSchema = transMeta.getPartitionSchemas().get(i);
// See if this transformation really is a consumer of this object
// It might be simply loaded as a shared object from the repository
//
boolean isUsedByTransformation = transMeta.isUsingPartitionSchema(partitionSchema);
repository.save(partitionSchema, versionComment, null, transMeta.getObjectId(), isUsedByTransformation, overwriteAssociated);
}
//
for (int i = 0; i < transMeta.getSlaveServers().size(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
SlaveServer slaveServer = transMeta.getSlaveServers().get(i);
boolean isUsedByTransformation = transMeta.isUsingSlaveServer(slaveServer);
repository.save(slaveServer, versionComment, null, transMeta.getObjectId(), isUsedByTransformation, overwriteAssociated);
}
// Save the clustering schemas
for (int i = 0; i < transMeta.getClusterSchemas().size(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
ClusterSchema clusterSchema = transMeta.getClusterSchemas().get(i);
boolean isUsedByTransformation = transMeta.isUsingClusterSchema(clusterSchema);
repository.save(clusterSchema, versionComment, null, transMeta.getObjectId(), isUsedByTransformation, overwriteAssociated);
}
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingDependencies"));
}
for (int i = 0; i < transMeta.nrDependencies(); i++) {
if (monitor != null && monitor.isCanceled()) {
throw new KettleDatabaseException(BaseMessages.getString(PKG, "TransMeta.Log.UserCancelledTransSave"));
}
TransDependency td = transMeta.getDependency(i);
saveTransDependency(td, transMeta.getObjectId());
}
saveTransAttributesMap(transMeta.getObjectId(), transMeta.getAttributesMap());
// Save the step error handling information as well!
for (int i = 0; i < transMeta.nrSteps(); i++) {
StepMeta stepMeta = transMeta.getStep(i);
StepErrorMeta stepErrorMeta = stepMeta.getStepErrorMeta();
if (stepErrorMeta != null) {
repository.stepDelegate.saveStepErrorMeta(stepErrorMeta, transMeta.getObjectId(), stepMeta.getObjectId());
}
}
repository.connectionDelegate.closeStepAttributeInsertPreparedStatement();
if (log.isDebug()) {
log.logDebug(BaseMessages.getString(PKG, "TransMeta.Log.SavingFinished"));
}
if (monitor != null) {
monitor.subTask(BaseMessages.getString(PKG, "TransMeta.Monitor.UnlockingRepository"));
}
repository.unlockRepository();
// Perform a commit!
repository.commit();
transMeta.clearChanged();
if (monitor != null) {
monitor.worked(1);
}
if (monitor != null) {
monitor.done();
}
} catch (KettleDatabaseException dbe) {
// Oops, roll back!
repository.rollback();
log.logError(BaseMessages.getString(PKG, "TransMeta.Log.ErrorSavingTransformationToRepository") + Const.CR + dbe.getMessage());
throw new KettleException(BaseMessages.getString(PKG, "TransMeta.Log.ErrorSavingTransformationToRepository"), dbe);
}
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class KettleDatabaseRepositoryTransDelegate method loadTransHopMeta.
public TransHopMeta loadTransHopMeta(ObjectId id_trans_hop, List<StepMeta> steps) throws KettleException {
TransHopMeta hopTransMeta = new TransHopMeta();
try {
hopTransMeta.setObjectId(id_trans_hop);
RowMetaAndData r = getTransHop(id_trans_hop);
hopTransMeta.setEnabled(r.getBoolean("ENABLED", false));
long id_step_from = r.getInteger("ID_STEP_FROM", 0);
long id_step_to = r.getInteger("ID_STEP_TO", 0);
StepMeta fromStep = StepMeta.findStep(steps, new LongObjectId(id_step_from));
//
if (fromStep == null && id_step_from > 0) {
// Simply load this, we only want the name, we don't care about the
// rest...
//
StepMeta stepMeta = repository.stepDelegate.loadStepMeta(new LongObjectId(id_step_from), new ArrayList<DatabaseMeta>(), new ArrayList<PartitionSchema>());
fromStep = StepMeta.findStep(steps, stepMeta.getName());
}
if (fromStep == null) {
log.logError("Unable to determine source step of transformation hop with ID: " + id_trans_hop);
// Invalid hop, simply ignore. See: PDI-2446
return null;
}
hopTransMeta.setFromStep(fromStep);
hopTransMeta.getFromStep().setDraw(true);
hopTransMeta.setToStep(StepMeta.findStep(steps, new LongObjectId(id_step_to)));
//
if (hopTransMeta.getToStep() == null && id_step_to > 0) {
// Simply load this, we only want the name, we don't care about
// the rest...
StepMeta stepMeta = repository.stepDelegate.loadStepMeta(new LongObjectId(id_step_to), new ArrayList<DatabaseMeta>(), new ArrayList<PartitionSchema>());
hopTransMeta.setToStep(StepMeta.findStep(steps, stepMeta.getName()));
}
if (hopTransMeta.getFromStep() == null || hopTransMeta.getFromStep() == null) {
//
return null;
}
hopTransMeta.getToStep().setDraw(true);
return hopTransMeta;
} catch (KettleDatabaseException dbe) {
throw new KettleException(BaseMessages.getString(PKG, "TransHopMeta.Exception.LoadTransformationHopInfo") + id_trans_hop, dbe);
}
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class GetXMLDataTest method testInit.
public void testInit() throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("getxmldata1");
PluginRegistry registry = PluginRegistry.getInstance();
//
// create an injector step...
//
String injectorStepname = "injector step";
InjectorMeta im = new InjectorMeta();
// Set the information of the injector.
String injectorPid = registry.getPluginId(StepPluginType.class, im);
StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
transMeta.addStep(injectorStep);
//
// Create a Get XML Data step
//
String getXMLDataName = "get xml data step";
GetXMLDataMeta gxdm = new GetXMLDataMeta();
String getXMLDataPid = registry.getPluginId(StepPluginType.class, gxdm);
StepMeta getXMLDataStep = new StepMeta(getXMLDataPid, getXMLDataName, gxdm);
transMeta.addStep(getXMLDataStep);
GetXMLDataField[] fields = new GetXMLDataField[5];
for (int idx = 0; idx < fields.length; idx++) {
fields[idx] = new GetXMLDataField();
}
fields[0].setName("objectid");
fields[0].setXPath("${xml_path}");
fields[0].setElementType(GetXMLDataField.ELEMENT_TYPE_NODE);
fields[0].setType(ValueMetaInterface.TYPE_STRING);
fields[0].setFormat("");
fields[0].setLength(-1);
fields[0].setPrecision(-1);
fields[0].setCurrencySymbol("");
fields[0].setDecimalSymbol("");
fields[0].setGroupSymbol("");
fields[0].setTrimType(GetXMLDataField.TYPE_TRIM_NONE);
gxdm.setEncoding("UTF-8");
gxdm.setIsAFile(false);
gxdm.setInFields(true);
gxdm.setLoopXPath("Level1/Level2/Props");
gxdm.setXMLField("field1");
gxdm.setInputFields(fields);
TransHopMeta hi = new TransHopMeta(injectorStep, getXMLDataStep);
transMeta.addTransHop(hi);
//
// Create a dummy step 1
//
String dummyStepname1 = "dummy step 1";
DummyTransMeta dm1 = new DummyTransMeta();
String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
transMeta.addStep(dummyStep1);
TransHopMeta hi1 = new TransHopMeta(getXMLDataStep, dummyStep1);
transMeta.addTransHop(hi1);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(dummyStepname1, 0);
RowStepCollector dummyRc1 = new RowStepCollector();
si.addRowListener(dummyRc1);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createData();
Iterator<RowMetaAndData> it = inputList.iterator();
while (it.hasNext()) {
RowMetaAndData rm = it.next();
rp.putRow(rm.getRowMeta(), rm.getData());
}
rp.finished();
trans.waitUntilFinished();
// Compare the results
List<RowMetaAndData> resultRows = dummyRc1.getRowsWritten();
List<RowMetaAndData> goldenImageRows = createResultData1();
GetXMLDataData getXMLDataData = new GetXMLDataData();
GetXMLData getXmlData = new GetXMLData(dummyStep1, getXMLDataData, 0, transMeta, trans);
getXmlData.setVariable("xml_path", "data/owner");
getXmlData.init(gxdm, getXMLDataData);
assertEquals(gxdm.getInputFields()[0].getXPath(), "${xml_path}");
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class XsltTest method runTestWithParams.
public void runTestWithParams(String xmlFieldname, String resultFieldname, boolean xslInField, boolean xslFileInField, String xslFileField, String xslFilename, String xslFactory) throws Exception {
KettleEnvironment.init();
//
// Create a new transformation...
//
TransMeta transMeta = new TransMeta();
transMeta.setName("xslt");
PluginRegistry registry = PluginRegistry.getInstance();
//
// create an injector step...
//
String injectorStepname = "injector step";
InjectorMeta im = new InjectorMeta();
// Set the information of the injector.
String injectorPid = registry.getPluginId(StepPluginType.class, im);
StepMeta injectorStep = new StepMeta(injectorPid, injectorStepname, im);
transMeta.addStep(injectorStep);
//
// Create a XSLT step
//
String xsltName = "xslt step";
XsltMeta xm = new XsltMeta();
String xsltPid = registry.getPluginId(StepPluginType.class, xm);
StepMeta xsltStep = new StepMeta(xsltPid, xsltName, xm);
transMeta.addStep(xsltStep);
TextFileInputField[] fields = new TextFileInputField[3];
for (int idx = 0; idx < fields.length; idx++) {
fields[idx] = new TextFileInputField();
}
fields[0].setName("XML");
fields[0].setType(ValueMetaInterface.TYPE_STRING);
fields[0].setFormat("");
fields[0].setLength(-1);
fields[0].setPrecision(-1);
fields[0].setCurrencySymbol("");
fields[0].setDecimalSymbol("");
fields[0].setGroupSymbol("");
fields[0].setTrimType(ValueMetaInterface.TRIM_TYPE_NONE);
fields[1].setName("XSL");
fields[1].setType(ValueMetaInterface.TYPE_STRING);
fields[1].setFormat("");
fields[1].setLength(-1);
fields[1].setPrecision(-1);
fields[1].setCurrencySymbol("");
fields[1].setDecimalSymbol("");
fields[1].setGroupSymbol("");
fields[1].setTrimType(ValueMetaInterface.TRIM_TYPE_NONE);
fields[2].setName("filename");
fields[2].setType(ValueMetaInterface.TYPE_STRING);
fields[2].setFormat("");
fields[2].setLength(-1);
fields[2].setPrecision(-1);
fields[2].setCurrencySymbol("");
fields[2].setDecimalSymbol("");
fields[2].setGroupSymbol("");
fields[2].setTrimType(ValueMetaInterface.TRIM_TYPE_NONE);
xm.setFieldname(xmlFieldname);
xm.setResultfieldname(resultFieldname);
xm.setXSLField(xslInField);
xm.setXSLFileField(xslFileField);
xm.setXSLFieldIsAFile(xslFileInField);
xm.setXslFilename(xslFilename);
xm.setXSLFactory(xslFactory);
TransHopMeta hi = new TransHopMeta(injectorStep, xsltStep);
transMeta.addTransHop(hi);
//
// Create a dummy step 1
//
String dummyStepname1 = "dummy step 1";
DummyTransMeta dm1 = new DummyTransMeta();
String dummyPid1 = registry.getPluginId(StepPluginType.class, dm1);
StepMeta dummyStep1 = new StepMeta(dummyPid1, dummyStepname1, dm1);
transMeta.addStep(dummyStep1);
TransHopMeta hi1 = new TransHopMeta(xsltStep, dummyStep1);
transMeta.addTransHop(hi1);
// Now execute the transformation...
Trans trans = new Trans(transMeta);
trans.prepareExecution(null);
StepInterface si = trans.getStepInterface(dummyStepname1, 0);
RowStepCollector dummyRc1 = new RowStepCollector();
si.addRowListener(dummyRc1);
RowProducer rp = trans.addRowProducer(injectorStepname, 0);
trans.startThreads();
// add rows
List<RowMetaAndData> inputList = createData(xslFilename);
Iterator<RowMetaAndData> it = inputList.iterator();
while (it.hasNext()) {
RowMetaAndData rm = it.next();
rp.putRow(rm.getRowMeta(), rm.getData());
}
rp.finished();
trans.waitUntilFinished();
// Compare the results
List<RowMetaAndData> resultRows = dummyRc1.getRowsWritten();
List<RowMetaAndData> goldenImageRows = createResultData1();
checkRows(goldenImageRows, resultRows, 2);
}
use of org.pentaho.di.trans.TransHopMeta in project pentaho-kettle by pentaho.
the class TransformationHasNoDisabledHopsImportRule method verifyRule.
@Override
public List<ImportValidationFeedback> verifyRule(Object subject) {
List<ImportValidationFeedback> feedback = new ArrayList<ImportValidationFeedback>();
if (!isEnabled()) {
return feedback;
}
if (!(subject instanceof TransMeta)) {
return feedback;
}
TransMeta transMeta = (TransMeta) subject;
for (int i = 0; i < transMeta.nrTransHops(); i++) {
TransHopMeta hop = transMeta.getTransHop(i);
if (!hop.isEnabled()) {
feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.ERROR, "There is a disabled hop in the transformation."));
}
}
if (feedback.isEmpty()) {
feedback.add(new ImportValidationFeedback(this, ImportValidationResultType.APPROVAL, "All hops are enabled in this transformation."));
}
return feedback;
}
Aggregations