error( ke.getMessage(), ke );
}
String solutionPath = "solution:";
Repository repository = connectToRepository();
boolean result = false;
try {
if ( isDefinedInput( KettleComponent.DIRECTORY ) ) {
String directoryName = getInputStringValue( KettleComponent.DIRECTORY );
if ( repository == null ) {
return false;
}
if ( isDefinedInput( KettleComponent.TRANSFORMATION ) ) {
String transformationName = getInputStringValue( KettleComponent.TRANSFORMATION );
transMeta = loadTransformFromRepository( directoryName, transformationName, repository );
if ( transMeta != null ) {
try {
for ( String key : parameterMap.keySet() ) {
transMeta.setParameterValue( key, parameterMap.get( key ) );
}
for ( String key : variableMap.keySet() ) {
transMeta.setVariable( key, variableMap.get( key ) );
}
} catch ( UnknownParamException e ) {
error( e.getMessage() );
}
transMeta.setArguments( arguments );
} else {
return false;
}
} else if ( isDefinedInput( KettleComponent.JOB ) ) {
String jobName = getInputStringValue( KettleComponent.JOB );
jobMeta = loadJobFromRepository( directoryName, jobName, repository );
if ( jobMeta != null ) {
try {
for ( String key : parameterMap.keySet() ) {
jobMeta.setParameterValue( key, parameterMap.get( key ) );
}
for ( String key : variableMap.keySet() ) {
jobMeta.setVariable( key, variableMap.get( key ) );
}
} catch ( UnknownParamException e ) {
error( e.getMessage() );
}
jobMeta.setArguments( arguments );
} else {
return false;
}
}
} else if ( isDefinedResource( KettleComponent.TRANSFORMFILE ) ) {
IActionSequenceResource transformResource = getResource( KettleComponent.TRANSFORMFILE );
String fileAddress = getActualFileName( transformResource );
try {
if ( fileAddress != null ) { // We have an actual loadable
// filesystem and file
transMeta = new TransMeta( fileAddress, repository, true );
transMeta.setFilename( fileAddress );
} else if ( repository != null && repository.isConnected() ) {
fileAddress = transformResource.getAddress();
// load transformation resource from kettle/settings.xml configured repository
transMeta = loadTransformFromRepository( FilenameUtils.getPathNoEndSeparator( fileAddress ), FilenameUtils.getBaseName( fileAddress ), repository );
} else {
String jobXmlStr = getResourceAsString( getResource( KettleComponent.TRANSFORMFILE ) );
jobXmlStr = jobXmlStr.replaceAll( "\\$\\{pentaho.solutionpath\\}", solutionPath ); //$NON-NLS-1$
jobXmlStr = jobXmlStr.replaceAll( "\\%\\%pentaho.solutionpath\\%\\%", solutionPath ); //$NON-NLS-1$
org.w3c.dom.Document doc = XmlW3CHelper.getDomFromString( jobXmlStr );
// create a tranformation from the document
transMeta = new TransMeta( doc.getFirstChild(), repository );
}
} catch ( Exception e ) {
error( Messages.getInstance().getErrorString(
"Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.TRANSFORMFILE, fileAddress ), e ); //$NON-NLS-1$
return false;
}
/*
* Unreachable code below... if (transMeta == null) {
* error(Messages.getInstance().getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.TRANSFORMFILE,
* fileAddress)); //$NON-NLS-1$ debug(getKettleLog(true)); return false; }
*/
// Don't forget to set the parameters here as well...
try {
for ( String key : parameterMap.keySet() ) {
transMeta.setParameterValue( key, parameterMap.get( key ) );
}
for ( String key : variableMap.keySet() ) {
transMeta.setVariable( key, variableMap.get( key ) );
}
} catch ( UnknownParamException e ) {
error( e.getMessage() );
}
transMeta.setArguments( arguments );
/*
* We do not need to concatenate the solutionPath info as the fileAddress has the complete location of the file
* from start to end. This is to resolve BISERVER-502.
*/
transMeta.setFilename( fileAddress );
} else if ( isDefinedResource( KettleComponent.JOBFILE ) ) {
String fileAddress = ""; //$NON-NLS-1$
try {
fileAddress = getResource( KettleComponent.JOBFILE ).getAddress();
if ( repository != null && repository.isConnected() ) {
solutionPath = StringUtils.EMPTY;
// load job resource from kettle/settings.xml configured repository
jobMeta = loadJobFromRepository( FilenameUtils.getPathNoEndSeparator( fileAddress ), FilenameUtils.getBaseName( fileAddress ), repository );
} else {
String jobXmlStr = getResourceAsString( getResource( KettleComponent.JOBFILE ) );
// String jobXmlStr =
// XmlW3CHelper.getContentFromSolutionResource(fileAddress);
jobXmlStr = jobXmlStr.replaceAll( "\\$\\{pentaho.solutionpath\\}", solutionPath ); //$NON-NLS-1$
jobXmlStr = jobXmlStr.replaceAll( "\\%\\%pentaho.solutionpath\\%\\%", solutionPath ); //$NON-NLS-1$
org.w3c.dom.Document doc = XmlW3CHelper.getDomFromString( jobXmlStr );
if ( doc == null ) {
error( Messages.getInstance().getErrorString(
"Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, fileAddress ) ); //$NON-NLS-1$
debug( getKettleLog( true ) );
return false;
}
// create a job from the document
try {
repository = connectToRepository();
// if we get a valid repository its great, if not try it
// without
jobMeta = new JobMeta( solutionPath + fileAddress, repository );
} catch ( Exception e ) {
error( Messages.getInstance().getString( "Kettle.ERROR_0023_NO_META" ), e ); //$NON-NLS-1$
} finally {
if ( repository != null ) {
if ( ComponentBase.debug ) {
debug( Messages.getInstance().getString( "Kettle.DEBUG_DISCONNECTING" ) ); //$NON-NLS-1$
}
repository.disconnect();
}
}
}
} catch ( Exception e ) {
error( Messages.getInstance().getErrorString(
"Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, fileAddress ), e ); //$NON-NLS-1$
return false;
}
if ( jobMeta == null ) {
error( Messages.getInstance().getErrorString(
"Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, fileAddress ) ); //$NON-NLS-1$
debug( getKettleLog( true ) );
return false;
} else {
try {
for ( String key : parameterMap.keySet() ) {
jobMeta.setParameterValue( key, parameterMap.get( key ) );
}
for ( String key : variableMap.keySet() ) {
jobMeta.setVariable( key, variableMap.get( key ) );
}
} catch ( UnknownParamException e ) {
error( e.getMessage() );
}
jobMeta.setArguments( arguments );
jobMeta.setFilename( solutionPath + fileAddress );
}
}
// OK, we have the information, let's load and execute the
// transformation or job
if ( transMeta != null ) {
result = executeTransformation( transMeta );
}
if ( jobMeta != null ) {
result = executeJob( jobMeta, repository );
}
} finally {
if ( repository != null ) {
if ( ComponentBase.debug ) {
debug( Messages.getInstance().getString( "Kettle.DEBUG_DISCONNECTING" ) ); //$NON-NLS-1$
}
try {
repository.disconnect();
} catch ( Exception ignored ) {
//ignore
}
}