@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());
   }
 }
  @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.º 3
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;
 }
Exemplo n.º 4
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;
    }
  }
 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.º 6
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)));
       }
     }
   }
 }
Exemplo n.º 7
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.º 8
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.º 10
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.º 11
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.º 12
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$
      }
    }
  }
  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;
    }
  }