private SequenceDefinition( final Node sequenceRootNode, final String solutionPath, final ILogger logger, final IApplicationContext applicationContext) { // initialize this object from the contents of the xml this.xactionPath = solutionPath; this.applicationContext = applicationContext; // get the descriptive entries version = XmlDom4JHelper.getNodeText("version", sequenceRootNode); // $NON-NLS-1$ title = XmlDom4JHelper.getNodeText("title", sequenceRootNode); // $NON-NLS-1$ isWebService = "true" .equals( XmlDom4JHelper.getNodeText( "web-service", sequenceRootNode)); // $NON-NLS-1$ //$NON-NLS-2$ loggingLevel = Logger.getLogLevel( XmlDom4JHelper.getNodeText("logging-level", sequenceRootNode)); // $NON-NLS-1$ description = XmlDom4JHelper.getNodeText("documentation/description", sequenceRootNode); // $NON-NLS-1$ help = XmlDom4JHelper.getNodeText("documentation/help", sequenceRootNode); // $NON-NLS-1$ author = XmlDom4JHelper.getNodeText("documentation/author", sequenceRootNode); // $NON-NLS-1$ resultType = XmlDom4JHelper.getNodeText("documentation/result-type", sequenceRootNode); // $NON-NLS-1$ iconPath = XmlDom4JHelper.getNodeText("documentation/icon", sequenceRootNode); // $NON-NLS-1$ // get the input parameter definitions inputDefinitions = new ListOrderedMap(); errorCode = SequenceDefinition.parseParameters( sequenceRootNode, logger, "inputs/*", inputDefinitions, null, true); // $NON-NLS-1$ // get the ouput definitions outputDefinitions = new ListOrderedMap(); errorCode = SequenceDefinition.parseParameters( sequenceRootNode, logger, "outputs/*", outputDefinitions, null, false); // $NON-NLS-1$ if (errorCode != ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK) { logger.info( Messages.getInstance() .getString( "SequenceDefinition.INFO_OUTPUT_PARAMETERS_NOT_DEFINED")); //$NON-NLS-1$ } // get the resource definitions errorCode = parseResourceDefinitions(sequenceRootNode, logger); if (errorCode != ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK) { logger.info( Messages.getInstance() .getString( "SequenceDefinition.INFO_RESOURCES_PARAMETERS_NOT_DEFINED")); //$NON-NLS-1$ } }
@Override public String publish(final IPentahoSession session) { // TODO put any code in here to validate the solution return Messages.getInstance() .getString("SolutionPublisher.USER_SOLUTION_REPOSITORY_UPDATED"); // $NON-NLS-1$ }
/** * sbarkdull: method appears to never be used anywhere * * @param actionRootNode * @param logger * @param nodePath * @param mapTo * @return */ static int parseActionResourceDefinitions( final Node actionRootNode, final ILogger logger, final String nodePath, final Map mapTo) { try { List resources = actionRootNode.selectNodes(nodePath); // TODO create objects to represent the types // TODO need source variable list Iterator resourcesIterator = resources.iterator(); Node resourceNode; String resourceName; while (resourcesIterator.hasNext()) { resourceNode = (Node) resourcesIterator.next(); resourceName = resourceNode.getName(); if (mapTo != null) { mapTo.put( resourceName, XmlDom4JHelper.getNodeText("@mapping", resourceNode, resourceName)); // $NON-NLS-1$ } } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; } catch (Exception e) { logger.error( Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"), e); //$NON-NLS-1$ } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC; }
public static IActionSequence ActionSequenceFactory( final Document document, final String solutionPath, final ILogger logger, final IApplicationContext applicationContext, final int loggingLevel) { // Check for a sequence document Node sequenceDefinitionNode = document.selectSingleNode("//action-sequence"); // $NON-NLS-1$ if (sequenceDefinitionNode == null) { logger.error( Messages.getInstance() .getErrorString( "SequenceDefinition.ERROR_0002_NO_ACTION_SEQUENCE_NODE", "", solutionPath, "")); //$NON-NLS-1$ return null; } ISequenceDefinition seqDef = new SequenceDefinition(sequenceDefinitionNode, solutionPath, logger, applicationContext); Node actionNode = sequenceDefinitionNode.selectSingleNode("actions"); // $NON-NLS-1$ return (SequenceDefinition.getNextLoopGroup( seqDef, actionNode, solutionPath, logger, loggingLevel)); }
static { try { DriverManager.registerDriver(new PentahoSystemDriver()); } catch (SQLException e) { org.pentaho.platform.util.logging.Logger.warn( PentahoSystemDriver.class.getName(), Messages.getInstance() .getErrorString("PentahoSystemDriver.ERROR_0001_COULD_NOT_REGISTER_DRIVER"), e); } }
static IConditionalExecution parseConditionalExecution( final Node actionRootNode, final ILogger logger, final String nodePath) { try { Node condition = actionRootNode.selectSingleNode(nodePath); if (condition == null) { return null; } String script = condition.getText(); IConditionalExecution ce = PentahoSystem.get(IConditionalExecution.class, null); ce.setScript(script); return ce; } catch (Exception ex) { logger.error( Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0005_PARSING_PARAMETERS"), ex); //$NON-NLS-1$ } return null; }
public IRuntimeContext handleActionRequest(final int timeout, final int timeoutType) { // Get the solution engine ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session); solutionEngine.setCreateFeedbackParameterCallback(createFeedbackParameterCallback); if (solutionEngine == null) { Logger.error( this, Messages.getInstance() .getErrorString("BaseRequestHandler.ERROR_0001_NO_SOLUTION_ENGINE")); // $NON-NLS-1$ return null; } solutionEngine.setLoggingLevel(ILogger.DEBUG); solutionEngine.init(session); solutionEngine.setForcePrompt(forcePrompt); if (parameterXsl != null) { solutionEngine.setParameterXsl(parameterXsl); } dispose(); runtime = solutionEngine.execute( actionPath, processId, false, instanceEnds, instanceId, true, parameterProviders, outputHandler, this, urlFactory, messages); // need to wait until this is complete // TODO // if this times out check the timeoutType before cancelling or // returning and leaving the component running return runtime; }
/** * This method is called when TemplateUtil.applyTemplate() encounters a parameter. * * @param template the source string * @param parameter the parameter value * @param parameterMatcher the regex parameter matcher * @param copyStart the start of the copy * @param results the output result * @return the next copystart */ public int resolveParameter( final String template, final String parameter, final Matcher parameterMatcher, int copyStart, final StringBuffer results) { StringTokenizer tokenizer = new StringTokenizer(parameter, ":"); // $NON-NLS-1$ if (tokenizer.countTokens() == 2) { // Currently, the component only handles one bit of metadata String parameterPrefix = tokenizer.nextToken(); String inputName = tokenizer.nextToken(); if (parameterPrefix.equals(prefix)) { // We know this parameter is for us. // First, is this a special input Object parameterValue = TemplateUtil.getSystemInput(inputName, runtimecontext); if ((parameterValue == null) && lookupMap.containsKey(inputName)) { parameterValue = lookupMap.get(inputName); } if (parameterValue != null) { // We have a parameter value - now, it's time to create a parameter and build up the // parameter string int start = parameterMatcher.start(); int end = parameterMatcher.end(); // We now have a valid start and end. It's time to see whether we're dealing // with an array, a result set, or a scalar. StringBuffer parameterBuffer = new StringBuffer(); // find and remove the next placeholder, to be replaced by the new value if (parameterValue instanceof String) { parameterBuffer.append( ((String) parameterValue).replaceAll("'", "\\'")); // $NON-NLS-1$ //$NON-NLS-2$ } else if (parameterValue instanceof Object[]) { Object[] pObj = (Object[]) parameterValue; for (Object element : pObj) { // TODO: escape quotes! parameterBuffer.append( (parameterBuffer.length() == 0) ? "'" + element + "'" : ",'" + element + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } else if (parameterValue instanceof IPentahoResultSet) { IPentahoResultSet rs = (IPentahoResultSet) parameterValue; // See if we can find a column in the metadata with the same // name as the input IPentahoMetaData md = rs.getMetaData(); int columnIdx = -1; if (md.getColumnCount() == 1) { columnIdx = 0; } else { columnIdx = md.getColumnIndex(new String[] {parameter}); } if (columnIdx < 0) { error( Messages.getErrorString( "Template.ERROR_0005_COULD_NOT_DETERMINE_COLUMN")); //$NON-NLS-1$ return -1; } int rowCount = rs.getRowCount(); Object valueCell = null; // TODO support non-string columns for (int i = 0; i < rowCount; i++) { valueCell = rs.getValueAt(i, columnIdx); // TODO: escape quotes! parameterBuffer.append( (parameterBuffer.length() == 0) ? "'" + valueCell + "'" : ",'" + valueCell + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } else if (parameterValue instanceof List) { List pObj = (List) parameterValue; for (int i = 0; i < pObj.size(); i++) { parameterBuffer.append( (parameterBuffer.length() == 0) ? "'" + pObj.get(i) + "'" : ",'" + pObj.get(i) + "'"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } } else { // If we're here, we know parameterValue is not null and not a string parameterBuffer.append( parameterValue.toString().replaceAll("'", "\\'")); // $NON-NLS-1$ //$NON-NLS-2$ } // OK - We have a parameterBuffer and have filled out the preparedParameters // list. It's time to change the SQL to insert our parameter marker and tell // the caller we've done our job. results.append(template.substring(copyStart, start)); copyStart = end; results.append(parameterBuffer); return copyStart; } } } return -1; // Nothing here for us - let default behavior through }
private static Element createSoapFaultElement(List messages) { Element faultElement = new DefaultElement("SOAP-ENV:Fault"); // TODO mlowery begin hack: copied in getFirstError code from MessageFormatter // to avoid needing an IPentahoSession String message = null; String errorStart = PentahoMessenger.getUserString("ERROR"); // $NON-NLS-1$ int pos = errorStart.indexOf('{'); if (pos != -1) { errorStart = errorStart.substring(0, pos); } Iterator msgIterator = messages.iterator(); while (msgIterator.hasNext()) { String msg = (String) msgIterator.next(); if (msg.indexOf(errorStart) == 0) { message = msg; } } // TODO mlowery end hack if (message == null) { message = Messages.getInstance() .getErrorString("SoapHelper.ERROR_0001_UNKNOWN_ERROR"); // $NON-NLS-1$ } // Envelope envelope = new Envelope(); // Fault fault = new Fault( ); // TODO: Generate the following message using the envelope and fault objects // TODO determine if this is a reciever or a sender problem by examining // the error code boolean senderFault = (message.indexOf("SolutionEngine.ERROR_0002") != -1) || //$NON-NLS-1$ // solution not specifed (message.indexOf("SolutionEngine.ERROR_0003") != -1) || //$NON-NLS-1$ // Path not specifeid (message.indexOf("SolutionEngine.ERROR_0004") != -1) || //$NON-NLS-1$ // Action not specified (message.indexOf("SolutionEngine.ERROR_0005") != -1); // $NON-NLS-1$ // Action not found // send the error code // TODO parse out the error code faultElement .addElement("SOAP-ENV:Fault") .addElement("SOAP-ENV:Subcode") .addElement("SOAP-ENV:Value") .addCDATA(message); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ if (senderFault) { faultElement .addElement("SOAP-ENV:faultactor") .setText("SOAP-ENV:Client"); // $NON-NLS-1$ //$NON-NLS-2$ } else { faultElement .addElement("SOAP-ENV:faultactor") .setText("SOAP-ENV:Server"); // $NON-NLS-1$ //$NON-NLS-2$ } Element faultTextElement = faultElement.addElement("SOAP-ENV:faultstring").addElement("SOAP-ENV:Text"); faultTextElement.addAttribute("xml:lang", LocaleHelper.getDefaultLocale().toString()); faultTextElement.addCDATA(message); Element detailElement = faultElement.addElement("SOAP-ENV:Detail"); Iterator messageIterator = messages.iterator(); while (messageIterator.hasNext()) { detailElement .addElement("message") .addAttribute("name", "trace") .addCDATA((String) messageIterator.next()); } return faultElement; }
public boolean startup(final IPentahoSession session) { try { Logger.debug(this, "DatasourceSystemListener: called for startup ..."); // $NON-NLS-1$ ICacheManager cacheManager = addCacheRegions(); List<IDatabaseConnection> databaseConnections = getListOfDatabaseConnections(session); String dsName = ""; DataSource ds = null; for (IDatabaseConnection databaseConnection : databaseConnections) { if (databaseConnection != null) { Logger.debug(this, " Setting up datasource - " + databaseConnection); // $NON-NLS-1$ // isPortUsedByServer should NOT be called on a JNDI data source // http://jira.pentaho.com/browse/BISERVER-12244 if (!databaseConnection.getAccessType().equals(DatabaseAccessType.JNDI)) { // if connection's port used by server there is no sense to get DataSource for this ds = isPortUsedByServer(databaseConnection) ? null : setupDataSourceForConnection(databaseConnection); } else { Logger.debug( this, "(Datasource \"" + IDBDatasourceService.JDBC_DATASOURCE // $NON-NLS-1$ + dsName + "\" not cached)"); //$NON-NLS-1$ continue; } dsName = databaseConnection.getName(); cacheManager.putInRegionCache(IDBDatasourceService.JDBC_DATASOURCE, dsName, ds); Logger.debug( this, "(Storing datasource under key \"" + IDBDatasourceService.JDBC_DATASOURCE // $NON-NLS-1$ + dsName + "\")"); //$NON-NLS-1$ } } Logger.debug(this, "DatasourceSystemListener: Completed startup."); // $NON-NLS-1$ return true; } catch (ObjectFactoryException objface) { Logger.error( this, Messages.getInstance() .getErrorString("DatasourceSystemListener.ERROR_0001_UNABLE_TO_INSTANTIATE_OBJECT"), objface); //$NON-NLS-1$ return false; } catch (DatasourceMgmtServiceException dmse) { Logger.error( this, Messages.getInstance() .getErrorString("DatasourceSystemListener.ERROR_0002_UNABLE_TO_GET_DATASOURCE"), dmse); //$NON-NLS-1$ return false; } }
@VisibleForTesting protected boolean isPortUsedByServer(IDatabaseConnection databaseConnection) { // get connection IP address String connectionHostName = databaseConnection.getHostname(); InetAddress connectionAddress = null; try { connectionAddress = getAdressFromString(connectionHostName); } catch (UnknownHostException e) { Logger.warn( this, Messages.getInstance() .getErrorString( "DatasourceSystemListener.WARN_0001_UNABLE_TO_GET_CONNECTION_ADDRESS"), e); //$NON-NLS-1$ return false; } // get connection port String stringConnectionPort = databaseConnection.getDatabasePort(); // get server URL String fullyQualifiedServerURL = PentahoSystem.getApplicationContext().getFullyQualifiedServerURL(); URL url = null; try { url = new URL(fullyQualifiedServerURL); } catch (MalformedURLException e) { Logger.warn( this, Messages.getInstance() .getErrorString("DatasourceSystemListener.WARN_0002_UNABLE_TO_PARSE_SERVER_URL"), e); //$NON-NLS-1$ return false; } // get server IP address String hostNameUsedByServer = url.getHost(); InetAddress serverAddress = null; try { serverAddress = getAdressFromString(hostNameUsedByServer); } catch (UnknownHostException e) { Logger.warn( this, Messages.getInstance() .getErrorString("DatasourceSystemListener.WARN_0003_UNABLE_TO_GET_SERVER_ADDRESS"), e); //$NON-NLS-1$ return false; } // get server port int portUsedByServer = url.getPort(); boolean isAddressesEquals = connectionAddress.equals(serverAddress); boolean isPortsEquals = false; try { Integer connectionPort = Integer.valueOf(stringConnectionPort); isPortsEquals = connectionPort.equals(portUsedByServer); } catch (NumberFormatException e) { Logger.warn( this, Messages.getInstance() .getErrorString("DatasourceSystemListener.WARN_0004_UNABLE_TO_GET_PORT_NUMBER"), e); //$NON-NLS-1$ return false; } return isAddressesEquals && isPortsEquals; }
public String getDescription() { return Messages.getInstance() .getString("SolutionRepository.USER_PUBLISH_DESCRIPTION"); // $NON-NLS-1$ }
public String getName() { return Messages.getInstance().getString("SolutionRepository.USER_PUBLISH_TITLE"); // $NON-NLS-1$ }
private int parseResourceDefinitions(final Node actionRootNode, final ILogger logger) { resourceDefinitions = new ListOrderedMap(); try { List resources = actionRootNode.selectNodes("resources/*"); // $NON-NLS-1$ // TODO create objects to represent the types // TODO need source variable list Iterator resourcesIterator = resources.iterator(); Node resourceNode; String resourceName; String resourceTypeName; String resourceMimeType; int resourceType; ActionResource resource; Node typeNode, mimeNode; while (resourcesIterator.hasNext()) { resourceNode = (Node) resourcesIterator.next(); typeNode = resourceNode.selectSingleNode("./*"); // $NON-NLS-1$ if (typeNode != null) { resourceName = resourceNode.getName(); resourceTypeName = typeNode.getName(); resourceType = ActionResource.getResourceType(resourceTypeName); String resourceLocation = XmlDom4JHelper.getNodeText("location", typeNode); // $NON-NLS-1$ if (resourceType == IActionSequenceResource.SOLUTION_FILE_RESOURCE) { if (resourceLocation == null) { logger.error( Messages.getInstance() .getErrorString( "SequenceDefinition.ERROR_0008_RESOURCE_NO_LOCATION", resourceName)); //$NON-NLS-1$ continue; } } else if (resourceType == IActionSequenceResource.STRING) { resourceLocation = XmlDom4JHelper.getNodeText("string", resourceNode); // $NON-NLS-1$ } else if (resourceType == IActionSequenceResource.XML) { // resourceLocation = XmlHelper.getNodeText("xml", resourceNode); //$NON-NLS-1$ Node xmlNode = typeNode.selectSingleNode("./location/*"); // $NON-NLS-1$ // Danger, we have now lost the character encoding of the XML in this node // see BISERVER-895 resourceLocation = (xmlNode == null) ? "" : xmlNode.asXML(); // $NON-NLS-1$ } mimeNode = typeNode.selectSingleNode("mime-type"); // $NON-NLS-1$ if (mimeNode != null) { resourceMimeType = mimeNode.getText(); resource = new ActionResource( resourceName, resourceType, resourceMimeType, solutionName, solutionPath, resourceLocation); resourceDefinitions.put(resourceName, resource); } else { logger.error( Messages.getInstance() .getErrorString( "SequenceDefinition.ERROR_0007_RESOURCE_NO_MIME_TYPE", resourceName)); //$NON-NLS-1$ } } // input = new ActionParameter( resourceName, resourceType, null // ); // resourceDefinitions.put( inputName, input ); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; } catch (Exception e) { logger.error( Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0006_PARSING_RESOURCE"), e); //$NON-NLS-1$ } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC; }
static int parseParameters( final Node actionRootNode, final ILogger logger, final String nodePath, final Map parameterMap, final Map mapTo, final boolean inputVar) { try { List parameters = actionRootNode.selectNodes(nodePath); // TODO create objects to represent the types // TODO need source variable list Iterator parametersIterator = parameters.iterator(); Node parameterNode; String parameterName; String parameterType; ActionParameter parameter; List variableNodes; List variables; Node variableNode; Iterator variablesIterator; String variableSource; String variableName; int variableIdx; Object defaultValue = null; while (parametersIterator.hasNext()) { parameterNode = (Node) parametersIterator.next(); parameterName = parameterNode.getName(); parameterType = XmlDom4JHelper.getNodeText("@type", parameterNode); // $NON-NLS-1$ if (mapTo != null) { mapTo.put( parameterName, XmlDom4JHelper.getNodeText("@mapping", parameterNode, parameterName)); // $NON-NLS-1$ } defaultValue = SequenceDefinition.getDefaultValue(parameterNode); // get the list of sources for this parameter variableNodes = parameterNode.selectNodes( (inputVar) ? "sources/*" : "destinations/*"); // $NON-NLS-1$ //$NON-NLS-2$ variablesIterator = variableNodes.iterator(); variableIdx = 1; variables = new ArrayList(); while (variablesIterator.hasNext()) { variableNode = (Node) variablesIterator.next(); // try to resolve the parameter value for this try { variableSource = variableNode.getName(); variableName = variableNode.getText(); ActionParameterSource variable = new ActionParameterSource(variableSource, variableName); if (SequenceDefinition.debug) { logger.debug( Messages.getInstance() .getString( "SequenceDefinition.DEBUG_ADDING_SOURCE_FOR_PARAMETER", variableSource, parameterName)); //$NON-NLS-1$ } variables.add(variable); } catch (Exception e) { logger.error( Messages.getInstance() .getErrorString( "SequenceDefinition.ERROR_0004_VARIABLE_SOURCE_NOT_VALID", Integer.toString(variableIdx), parameterName), e); //$NON-NLS-1$ } variableIdx++; } if (defaultValue != null) { if (SequenceDefinition.debug) { logger.debug( Messages.getInstance() .getString( "SequenceDefinition.DEBUG_USING_DEFAULT_VALUE", defaultValue.toString(), parameterName)); //$NON-NLS-1$ } } parameter = new ActionParameter(parameterName, parameterType, null, variables, defaultValue); parameterMap.put(parameterName, parameter); } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK; } catch (Exception e) { logger.error( Messages.getInstance().getErrorString("SequenceDefinition.ERROR_0005_PARSING_PARAMETERS"), e); //$NON-NLS-1$ } return ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_INVALID_ACTION_DOC; }