@Override
 public void createContent() throws Exception {
   this.session = PentahoSessionHolder.getSession();
   this.repository = PentahoSystem.get(IUnifiedRepository.class, session);
   final RepositoryFile BIRTfile =
       (RepositoryFile) parameterProviders.get("path").getParameter("file");
   final String ExecBIRTFilePath = "../webapps/birt/" + BIRTfile.getId() + ".rptdocument";
   /*
    * Get BIRT report design from repository
    */
   final File ExecBIRTFile = new File(ExecBIRTFilePath);
   if (!ExecBIRTFile.exists()) {
     final FileOutputStream fos = new FileOutputStream(ExecBIRTFilePath);
     try {
       final SimpleRepositoryFileData data =
           repository.getDataForRead(BIRTfile.getId(), SimpleRepositoryFileData.class);
       final InputStream inputStream = data.getInputStream();
       final byte[] buffer = new byte[0x1000];
       int bytesRead = inputStream.read(buffer);
       while (bytesRead >= 0) {
         fos.write(buffer, 0, bytesRead);
         bytesRead = inputStream.read(buffer);
       }
     } catch (final Exception e) {
       Logger.error(getClass().getName(), e.getMessage());
     } finally {
       fos.close();
     }
   }
   /*
    * Redirect to BIRT Viewer
    */
   try {
     // Get informations about user context
     final IUserRoleListService service = PentahoSystem.get(IUserRoleListService.class);
     String roles = "";
     final ListIterator<String> li =
         service.getRolesForUser(null, session.getName()).listIterator();
     while (li.hasNext()) {
       roles = roles + li.next().toString() + ",";
     }
     // Redirect
     final HttpServletResponse response =
         (HttpServletResponse) this.parameterProviders.get("path").getParameter("httpresponse");
     response.sendRedirect(
         "/birt/frameset?__document="
             + BIRTfile.getId()
             + ".rptdocument&__showtitle=false&username="******"&userroles="
             + roles
             + "&reportname="
             + BIRTfile.getTitle());
   } catch (final Exception e) {
     Logger.error(getClass().getName(), e.getMessage());
   }
 }
  public void shutdown() {

    ICacheManager cacheManager = PentahoSystem.getCacheManager(null);

    Logger.debug(this, "DatasourceSystemListener: Called for shutdown ..."); // $NON-NLS-1$

    cacheManager.removeRegionCache(IDBDatasourceService.JDBC_DATASOURCE);

    Logger.debug(this, "DatasourceSystemListener: Completed shutdown."); // $NON-NLS-1$
  }
Exemplo n.º 3
0
 public void loadAll(File directory, FilenameFilter filenameFilter) {
   File[] files = directory.listFiles(filenameFilter);
   if (files != null) {
     for (File file : files) {
       try {
         Logger.debug(
             this.getClass().getName(),
             this.getClass().getName() + ": importing " + file.getName());
         importer.importFile(createBundle(file));
       } catch (Exception e) {
         Logger.error(this.getClass().getName(), e.getMessage(), e);
       } finally {
         file.renameTo(new File(file.getPath() + DATE_FORMAT.format(loadStamp)));
       }
     }
   }
 }
  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$
    }
  }
Exemplo n.º 5
0
 public String getPassword(String input) {
   if (input.startsWith("ENC:")) {
     try {
       return passwordService.decrypt(input.substring(4));
     } catch (PasswordServiceException e) {
       Logger.error(this, "Exception decrypting password", e);
       throw new RuntimeException(e);
     }
   }
   return input;
 }
 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);
   }
 }
  protected ICacheManager addCacheRegions() {
    ICacheManager cacheManager = PentahoSystem.getCacheManager(null);

    Logger.debug(this, "Adding caching regions ..."); // $NON-NLS-1$

    if (!cacheManager.cacheEnabled(IDBDatasourceService.JDBC_DATASOURCE)) {
      cacheManager.addCacheRegion(IDBDatasourceService.JDBC_DATASOURCE);
    }

    return cacheManager;
  }
  @VisibleForTesting
  protected DataSource setupDataSourceForConnection(IDatabaseConnection databaseConnection) {
    DataSource ds = null;
    try {
      ds = getDataSource(databaseConnection);
    } catch (DBDatasourceServiceException e) {
      Logger.error(this, "Error retrieving DataSource", e);
    }

    return ds;
  }
Exemplo n.º 9
0
  public ActionDefinition(final Node actionRootNode, final ILogger logger) {

    this.actionRootNode = actionRootNode;

    errorCode = ISequenceDefinition.ACTION_SEQUENCE_DEFINITION_OK;
    // this.sequenceData = sequenceData;

    // get the input parameter definitions
    actionInputDefinitions = new ListOrderedMap();
    actionInputMapping = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            actionRootNode,
            logger,
            "action-inputs/*",
            actionInputDefinitions,
            actionInputMapping,
            true); //$NON-NLS-1$

    // get the ouput definitions
    actionOutputDefinitions = new ListOrderedMap();
    actionOutputMapping = new ListOrderedMap();
    errorCode =
        SequenceDefinition.parseParameters(
            actionRootNode,
            logger,
            "action-outputs/*",
            actionOutputDefinitions,
            actionOutputMapping,
            false); //$NON-NLS-1$

    // get the resource definitions
    actionResourceMapping = new ListOrderedMap();
    if (actionRootNode.selectNodes("action-resources/*").size() > 0) { // $NON-NLS-1$
      hasActionResources = true;
      errorCode =
          SequenceDefinition.parseActionResourceDefinitions(
              actionRootNode, logger, "action-resources/*", actionResourceMapping); // $NON-NLS-1$
    }

    componentName = XmlDom4JHelper.getNodeText("component-name", actionRootNode); // $NON-NLS-1$
    String loggingLevelString =
        XmlDom4JHelper.getNodeText("logging-level", actionRootNode); // $NON-NLS-1$
    loggingLevel = Logger.getLogLevel(loggingLevelString);

    // get the component payload
    componentNode = actionRootNode.selectSingleNode("component-definition"); // $NON-NLS-1$
    if (componentNode == null) {
      componentNode = ((Element) actionRootNode).addElement("component-definition"); // $NON-NLS-1$
    }

    // TODO populate preExecuteAuditList and postExecuteAuditList
  }
Exemplo n.º 10
0
  public static String getURLContent(final String uri) {

    try {
      StringBuffer content = new StringBuffer();
      HttpUtil.getURLContent(uri, content);
      return content.toString();
    } catch (Exception e) {
      // TODO: handle this error
      Logger.error(
          "org.pentaho.platform.util.web.HttpUtil",
          Messages.getInstance().getErrorString("HttpUtil.ERROR_0001_URL_ERROR", e.getMessage()),
          e); //$NON-NLS-1$ //$NON-NLS-2$
      return null;
    }
  }
Exemplo n.º 11
0
 protected XulMenupopup getXulPopupMenu(String id, String documentPath, IPentahoSession session) {
   XulDomContainer container = getXulContainer(documentPath, session);
   if (container != null) {
     List<XulComponent> components =
         container.getDocumentRoot().getElementsByTagName("menupopup"); // $NON-NLS-1$
     for (XulComponent component : components) {
       if (component.getId().equals(id) && component instanceof XulMenupopup) {
         return (XulMenupopup) component;
       }
     }
   }
   Logger.error(
       getClass().getName(),
       Messages.getErrorString(
           "BaseMenuProvider.ERROR_0003_COULD_NOT_GET_POPUP_MENU")); //$NON-NLS-1$
   return null;
 }
Exemplo n.º 12
0
  public static Reader getURLReader(final String uri) {

    try {
      URL url = new URL(uri);
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.connect();
      InputStream in = connection.getInputStream();
      return new InputStreamReader(in);
    } catch (Exception e) {
      // TODO: handle this error
      Logger.error(
          HttpUtil.class.getName(),
          Messages.getInstance().getErrorString("HttpUtil.ERROR_0001_URL_ERROR", e.getMessage()),
          e); //$NON-NLS-1$
      return null;
    }
  }
Exemplo n.º 13
0
  public static InputStream getURLInputStream(final String uri) {

    try {
      URL url = new URL(uri);
      HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.connect();
      InputStream in = connection.getInputStream();
      return in;
    } catch (Exception e) {
      // TODO: handle this error
      Logger.error(
          "org.pentaho.platform.util.web.HttpUtil",
          Messages.getInstance().getErrorString("HttpUtil.ERROR_0001_URL_ERROR", e.getMessage()),
          e); //$NON-NLS-1$ //$NON-NLS-2$
      return null;
    }
  }
  /** Load the web services from the list of web service wrappers */
  public void loadServices() {

    List<IServiceConfig> wsDfns = getWebServiceDefinitions();

    for (IServiceConfig wsDef : wsDfns) {
      try {
        loadService(wsDef);
      } catch (Exception e) {
        // Axis cannot handle a typed exception from this method, we must just log the error and
        // continue on
        Logger.error(
            getClass().getName(),
            Messages.getInstance()
                .getErrorString(
                    "AbstractAxisConfigurator.ERROR_0001_COULD_NOT_LOAD_SERVICE", wsDef.getId()),
            e); //$NON-NLS-1$
      }
    }
  }
Exemplo n.º 15
0
  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;
  }
Exemplo n.º 16
0
  protected XulMenubar getXulMenubar(String id, String documentPath, IPentahoSession session) {
    XulDomContainer container = getXulContainer(documentPath, session);
    if (container == null) {
      return null;
    }
    List<XulComponent> components =
        container.getDocumentRoot().getElementsByTagName("menubar"); // $NON-NLS-1$
    for (XulComponent component : components) {
      if (component instanceof XulMenubar && component.getId().equals(id)) {
        XulMenubar menubar = (XulMenubar) component;
        // now get customizations to it
        IPluginManager pluginManager = PentahoSystem.get(IPluginManager.class, session);
        List<?> menuCustomizations = pluginManager.getMenuCustomizations();
        for (Object custom : menuCustomizations) {
          if (custom instanceof IMenuCustomization) {
            IMenuCustomization item = (IMenuCustomization) custom;
            try {
              // apply each customization and log any failures
              MenuUtil.customizeMenu(menubar, item, getXulLoader());
            } catch (Exception e) {
              session.error(
                  Messages.getString(
                      "BaseMenuProvider.ERROR_0004_COULD_NOT_CUSTOMIZE_MENU",
                      item.getId(),
                      item.getLabel()),
                  e); //$NON-NLS-1$
            }
          }
        }

        return menubar;
      }
    }
    Logger.error(
        getClass().getName(),
        Messages.getErrorString(
            "BaseMenuProvider.ERROR_0002_COULD_NOT_GET_MENUBAR")); //$NON-NLS-1$
    return null;
  }
Exemplo n.º 17
0
 public void error(final String message, final Throwable error) {
   if (loggingLevel <= ILogger.ERROR) {
     getLogger().error(message, error);
     Logger.addException(error);
   }
 }
  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;
  }
Exemplo n.º 20
0
 public void debug(final String message, final Throwable error) {
   if (loggingLevel <= ILogger.DEBUG) {
     getLogger().debug(message, error);
     Logger.addException(error);
   }
 }
Exemplo n.º 21
0
 public void trace(final String message, final Throwable error) {
   if (loggingLevel <= ILogger.TRACE) {
     getLogger().trace(message, error);
     Logger.addException(error);
   }
 }
Exemplo n.º 22
0
 public void info(final String message, final Throwable error) {
   if (loggingLevel <= ILogger.INFO) {
     getLogger().info(message, error);
     Logger.addException(error);
   }
 }
Exemplo n.º 23
0
 public void warn(final String message, final Throwable error) {
   if (loggingLevel <= ILogger.WARN) {
     getLogger().warn(message, error);
     Logger.addException(error);
   }
 }
Exemplo n.º 24
0
  protected void init(Util.PropertyList properties) {
    try {
      if (nativeConnection != null) { // Assume we're open
        close();
      }

      // Set a locale for this connection if specified in the platform's mondrian metadata
      // This is required if mondrian.i18n.LocalizingDynamicSchemaProcessor is being used
      if (properties.get(RolapConnectionProperties.Locale.name()) == null) {
        properties.put(
            RolapConnectionProperties.Locale.name(), LocaleHelper.getLocale().toString());
      }

      String dataSourceName = properties.get(RolapConnectionProperties.DataSource.name());

      mapPlatformRolesToMondrianRoles(properties);

      if (dataSourceName != null) {
        IDBDatasourceService datasourceService =
            PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, null);
        DataSource dataSourceImpl = datasourceService.getDataSource(dataSourceName);
        if (dataSourceImpl != null) {
          properties.remove(RolapConnectionProperties.DataSource.name());
          nativeConnection = DriverManager.getConnection(properties, null, dataSourceImpl);
        } else {
          nativeConnection = DriverManager.getConnection(properties, null);
        }
      } else {
        nativeConnection = DriverManager.getConnection(properties, null);
      }

      if (nativeConnection != null) {
        if (role != null) {
          nativeConnection.setRole(role);
        }
      }

      if (nativeConnection == null) {
        logger.error(
            Messages.getInstance()
                .getErrorString(
                    "MDXConnection.ERROR_0002_INVALID_CONNECTION",
                    properties != null
                        ? properties.toString()
                        : "null")); //$NON-NLS-1$ //$NON-NLS-2$
      }
    } catch (Throwable t) {
      if (logger != null) {
        logger.error(
            Messages.getInstance()
                .getErrorString(
                    "MDXConnection.ERROR_0002_INVALID_CONNECTION",
                    properties != null ? properties.toString() : "null"),
            t); //$NON-NLS-1$ //$NON-NLS-2$
      } else {
        Logger.error(
            this.getClass().getName(),
            Messages.getInstance()
                .getErrorString(
                    "MDXConnection.ERROR_0002_INVALID_CONNECTION",
                    properties != null ? properties.toString() : "null"),
            t); //$NON-NLS-1$ //$NON-NLS-2$
      }
    }
  }
Exemplo n.º 25
0
 public void fatal(final String message, final Throwable error) {
   if (loggingLevel <= ILogger.FATAL) {
     getLogger().fatal(message, error);
     Logger.addException(error);
   }
 }