use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class KettleComponent method executeAction.
/**
* Execute the specified transformation in the chosen repository.
*/
@SuppressWarnings("unchecked")
@Override
public boolean executeAction() {
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_START"));
}
TransMeta transMeta = null;
JobMeta jobMeta = null;
// Build lists of parameters, variables and command line arguments
Map<String, String> argumentMap = new HashMap<String, String>();
Map<String, String> variableMap = new HashMap<String, String>();
Map<String, String> parameterMap = new HashMap<String, String>();
for (Node n : (List<Node>) getComponentDefinition().selectNodes(PARAMETER_MAP_CMD_ARG)) {
argumentMap.put(n.selectSingleNode("name").getText(), // $NON-NLS-1$ //$NON-NLS-2$
applyInputsToFormat(getInputStringValue(n.selectSingleNode("mapping").getText())));
}
for (Node n : (List<Node>) getComponentDefinition().selectNodes(PARAMETER_MAP_VARIABLE)) {
variableMap.put(n.selectSingleNode("name").getText(), // $NON-NLS-1$ //$NON-NLS-2$
applyInputsToFormat(getInputStringValue(n.selectSingleNode("mapping").getText())));
}
for (Node n : (List<Node>) getComponentDefinition().selectNodes(PARAMETER_MAP_PARAMETER)) {
parameterMap.put(n.selectSingleNode("name").getText(), // $NON-NLS-1$ //$NON-NLS-2$
applyInputsToFormat(getInputStringValue(n.selectSingleNode("mapping").getText())));
}
String[] arguments = null;
// arguments (This supports the legacy method)
if (argumentMap.size() <= 0 && variableMap.size() <= 0 && parameterMap.size() <= 0) {
// this use is now considered obsolete, as we prefer the
// action-sequence inputs since they
// now maintain order
boolean running = true;
int index = 1;
ArrayList<String> argumentList = new ArrayList<String>();
while (running) {
if (isDefinedInput("parameter" + index)) {
// $NON-NLS-1$
String value = null;
// $NON-NLS-1$
String inputName = getInputStringValue("parameter" + index);
// see if we have an input with this name
if (isDefinedInput(inputName)) {
value = getInputStringValue(inputName);
}
argumentList.add(value);
} else {
running = false;
}
index++;
}
// this is the preferred way to provide inputs to the
// KetteComponent, the order of inputs is now preserved
Iterator<?> inputNamesIter = getInputNames().iterator();
while (inputNamesIter.hasNext()) {
String name = (String) inputNamesIter.next();
argumentList.add(getInputStringValue(name));
}
arguments = (String[]) argumentList.toArray(new String[argumentList.size()]);
} else {
// Extract arguments from argumentMap (Throw an error if the
// sequential ordering is broken)
arguments = new String[argumentMap.size()];
for (int i = 0; i < argumentMap.size(); i++) {
// Mapping
arguments[i] = argumentMap.get(Integer.toString(i + 1));
// UI
if (arguments[i] == null) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("Kettle.ERROR_0030_INVALID_ARGUMENT_MAPPING"));
}
}
}
// initialize environment variables
try {
KettleSystemListener.environmentInit(getSession());
} catch (KettleException ke) {
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));
// $NON-NLS-1$
jobXmlStr = jobXmlStr.replaceAll("\\$\\{pentaho.solutionpath\\}", solutionPath);
// $NON-NLS-1$
jobXmlStr = jobXmlStr.replaceAll("\\%\\%pentaho.solutionpath\\%\\%", solutionPath);
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), // $NON-NLS-1$
e);
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)) {
// $NON-NLS-1$
String fileAddress = "";
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);
// $NON-NLS-1$
jobXmlStr = jobXmlStr.replaceAll("\\$\\{pentaho.solutionpath\\}", solutionPath);
// $NON-NLS-1$
jobXmlStr = jobXmlStr.replaceAll("\\%\\%pentaho.solutionpath\\%\\%", solutionPath);
org.w3c.dom.Document doc = XmlW3CHelper.getDomFromString(jobXmlStr);
if (doc == null) {
error(Messages.getInstance().getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, // $NON-NLS-1$
fileAddress));
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) {
// $NON-NLS-1$
error(Messages.getInstance().getString("Kettle.ERROR_0023_NO_META"), e);
} finally {
if (repository != null) {
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_DISCONNECTING"));
}
repository.disconnect();
}
}
}
} catch (Exception e) {
error(Messages.getInstance().getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, fileAddress), // $NON-NLS-1$
e);
return false;
}
if (jobMeta == null) {
error(Messages.getInstance().getErrorString("Kettle.ERROR_0015_BAD_RESOURCE", KettleComponent.JOBFILE, // $NON-NLS-1$
fileAddress));
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);
}
}
if (transMeta != null) {
result = executeTransformation(transMeta);
}
if (jobMeta != null) {
result = executeJob(jobMeta, repository);
}
} finally {
if (repository != null) {
if (ComponentBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("Kettle.DEBUG_DISCONNECTING"));
}
try {
repository.disconnect();
} catch (Exception ignored) {
// ignore
}
}
if (transMeta != null) {
try {
cleanLogChannel(transMeta);
transMeta.clear();
} catch (Exception ignored) {
// ignore
}
transMeta = null;
}
if (jobMeta != null) {
try {
cleanLogChannel(jobMeta);
jobMeta.clear();
} catch (Exception ignored) {
// ignored
}
// Can't do anything about an exception here.
jobMeta = null;
}
}
if (isDefinedOutput(EXECUTION_LOG_OUTPUT)) {
setOutputValue(EXECUTION_LOG_OUTPUT, executionLog);
}
if (isDefinedOutput(EXECUTION_STATUS_OUTPUT)) {
setOutputValue(EXECUTION_STATUS_OUTPUT, executionStatus);
}
XMLHandlerCache.getInstance().clear();
return result;
}
use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class OpenFlashChartComponent method executeAction.
protected boolean executeAction() {
// $NON-NLS-1$
log.debug("start to run open flash chart component......");
// input data
IPentahoResultSet data = (IPentahoResultSet) getInputValue(CHART_DATA);
if (!data.isScrollable()) {
// $NON-NLS-1$
getLogger().debug("ResultSet is not scrollable. Copying into memory");
IPentahoResultSet memSet = data.memoryCopy();
data.close();
data = memSet;
}
// chart width
String chartWidth = null;
String inputWidth = getInputStringValue(CHART_WIDTH);
if (inputWidth == null) {
chartWidth = DEFAULT_WIDTH;
} else {
chartWidth = inputWidth;
}
// chart height
String chartHeight = null;
String inputHeight = getInputStringValue(CHART_HEIGHT);
if (null == inputHeight) {
chartHeight = DEFAULT_HEIGHT;
} else {
chartHeight = inputHeight;
}
// swf file location
String ofcURL = getInputStringValue(OFC_URL);
if (ofcURL == null || "".equals(ofcURL)) {
// $NON-NLS-1$
ofcURL = PentahoRequestContextHolder.getRequestContext().getContextPath() + DEFAULT_FLASH_LOC;
}
// swf file name
String ofclibname = getInputStringValue(OFC_LIB_NAME);
if (ofclibname == null || "".equals(ofclibname)) {
// $NON-NLS-1$
ofclibname = DEFAULT_FLASH_SWF;
}
// chart definition
String chartAttributeString = null;
if (getInputNames().contains(CHART_ATTRIBUTES)) {
chartAttributeString = getInputStringValue(CHART_ATTRIBUTES);
} else if (isDefinedResource(CHART_ATTRIBUTES)) {
IActionSequenceResource resource = getResource(CHART_ATTRIBUTES);
chartAttributeString = getResourceAsString(resource);
}
Node chartNode = null;
if (chartAttributeString != null) {
// apply any additional inputs to the chart definition
chartAttributeString = applyInputsToFormat(chartAttributeString);
try {
Document chartDocument = XmlDom4JHelper.getDocFromString(chartAttributeString, new PentahoEntityResolver());
chartNode = chartDocument.selectSingleNode(CHART_NODE_LOC);
if (chartNode == null) {
chartNode = chartDocument.selectSingleNode(CHART_ATTRIBUTES);
}
} catch (XmlParseException e) {
getLogger().error(Messages.getInstance().getErrorString("OpenFlashChartComponent.ERROR_0001_CANT_DOCUMENT_FROM_STRING"), // $NON-NLS-1$
e);
return false;
}
} else {
// see if the chart-attributes node is available in the component definition
chartNode = getComponentDefinition(true).selectSingleNode(CHART_ATTRIBUTES);
}
if (chartNode == null) {
getLogger().error(// $NON-NLS-1$
Messages.getInstance().getErrorString("OpenFlashChartComponent.ERROR_0002_CHART_DEFINITION_NOT_FOUND"));
return false;
}
// Determine if we are going to read the chart data set by row or by column
boolean byRow = false;
if (getInputStringValue(BY_ROW_PROP) != null) {
byRow = Boolean.valueOf(getInputStringValue(BY_ROW_PROP)).booleanValue();
}
String chartJson = generateChartJson(data, chartNode, byRow);
// generate a unique name for the function
// $NON-NLS-1$ //$NON-NLS-2$
String chartId = UUIDUtil.getUUIDAsString().replaceAll("[^\\w]", "");
// populate the flash html template
Properties props = new Properties();
// $NON-NLS-1$
props.setProperty("chartId", chartId);
// $NON-NLS-1$ //$NON-NLS-2$
props.setProperty("dataFunction", "getData" + chartId);
// $NON-NLS-1$
props.setProperty("chart-width", chartWidth);
// $NON-NLS-1$
props.setProperty("chart-height", chartHeight);
// $NON-NLS-1$
props.setProperty("ofc-url", ofcURL);
// $NON-NLS-1$
props.setProperty("ofc-libname", ofclibname);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
props.setProperty("chartJson", chartJson.replaceAll("\"", "\\\\\""));
String flashContent = TemplateUtil.applyTemplate(getFlashFragment(), props, null);
// set output value
// $NON-NLS-1$
log.debug("html_fragment=" + flashContent);
if (this.isDefinedOutput("html_fragment")) {
// $NON-NLS-1$
// $NON-NLS-1$
this.setOutputValue("html_fragment", flashContent);
}
if (this.isDefinedOutput("image-tag")) {
// $NON-NLS-1$
// $NON-NLS-1$
this.setOutputValue("image-tag", flashContent);
}
return true;
}
use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class SolutionURIResolver method resolveEntity.
public InputSource resolveEntity(final String publicId, final String systemId) {
InputStream xslIS = null;
try {
if (systemId.toLowerCase().indexOf(".dtd") >= 0) {
// $NON-NLS-1$
return resolveDTDEntity(publicId, systemId);
}
IActionSequenceResource resource = new // $NON-NLS-1$ //$NON-NLS-2$
ActionSequenceResource(// $NON-NLS-1$ //$NON-NLS-2$
"", // $NON-NLS-1$ //$NON-NLS-2$
IActionSequenceResource.SOLUTION_FILE_RESOURCE, // $NON-NLS-1$ //$NON-NLS-2$
"text/xml", systemId);
xslIS = resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
return new InputSource(xslIS);
} catch (IOException e) {
Logger.error(this, e.getLocalizedMessage());
}
return null;
}
use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class SolutionURIResolver method resolve.
/*
* (non-Javadoc)
*
* @see javax.xml.transform.URIResolver#resolve(java.lang.String, java.lang.String)
*/
public Source resolve(final String href, final String base) {
StreamSource xslSrc = null;
InputStream xslIS = null;
IActionSequenceResource resource = new // $NON-NLS-1$ //$NON-NLS-2$
ActionSequenceResource(// $NON-NLS-1$ //$NON-NLS-2$
"", // $NON-NLS-1$ //$NON-NLS-2$
IActionSequenceResource.SOLUTION_FILE_RESOURCE, // $NON-NLS-1$ //$NON-NLS-2$
"text/xml", href);
xslIS = resource.getInputStream(RepositoryFilePermission.READ, LocaleHelper.getLocale());
xslSrc = new StreamSource(xslIS);
return xslSrc;
}
use of org.pentaho.platform.api.engine.IActionSequenceResource in project pentaho-platform by pentaho.
the class ActionSequenceParameterMgr method getDataSource.
public IPentahoStreamSource getDataSource(final IActionResource actionResource) throws FileNotFoundException {
IPentahoStreamSource dataSrc = null;
IActionSequenceResource resource = runtimeContext.getResourceDefintion(actionResource.getName());
if (resource != null) {
dataSrc = runtimeContext.getResourceDataSource(resource);
}
return dataSrc;
}
Aggregations