@Test
  public void testDoNewTenant() throws Exception {
    loginAsRepositoryAdmin();
    ITenant systemTenant =
        tenantManager.createTenant(
            null,
            ServerRepositoryPaths.getPentahoRootFolderName(),
            adminAuthorityName,
            tenantAuthenticatedAuthorityName,
            "Anonymous");
    userRoleDao.createUser(
        systemTenant, sysAdminUserName, "password", "", new String[] {adminAuthorityName});
    ITenant mainTenant_1 =
        tenantManager.createTenant(
            systemTenant,
            MAIN_TENANT_1,
            adminAuthorityName,
            tenantAuthenticatedAuthorityName,
            "Anonymous");
    userRoleDao.createUser(
        mainTenant_1,
        "admin",
        "password",
        "",
        new String[] {adminAuthorityName, tenantAuthenticatedAuthorityName});
    login(
        "admin", mainTenant_1, new String[] {adminAuthorityName, tenantAuthenticatedAuthorityName});
    JcrRepositoryDumpToFile dumpToFile =
        new JcrRepositoryDumpToFile(
            testJcrTemplate,
            jcrTransactionTemplate,
            repositoryAdminUsername,
            "c:/build/testrepo_3",
            Mode.CUSTOM);
    dumpToFile.execute();
    metadataRepositoryLifecycleManager.newTenant(mainTenant_1);
    String metadataPath = ClientRepositoryPaths.getEtcFolderPath() + "/metadata";
    RepositoryFile metadataRepositoryPath = repo.getFile(metadataPath);
    assertTrue(metadataRepositoryPath.getPath() != null);

    // Nothing should change if we run it again
    metadataRepositoryLifecycleManager.newTenant(mainTenant_1);
    metadataPath = ClientRepositoryPaths.getEtcFolderPath() + "/metadata";
    metadataRepositoryPath = repo.getFile(metadataPath);
    assertTrue(metadataRepositoryPath.getPath() != null);
    cleanupUserAndRoles(mainTenant_1);
    cleanupUserAndRoles(systemTenant);
  }
  public static MasterReport createReport(final Serializable fileId)
      throws ResourceException, IOException {
    final ResourceManager resourceManager = new ResourceManager();
    resourceManager.registerDefaults();
    final HashMap helperObjects = new HashMap();
    // add the runtime context so that PentahoResourceData class can get access
    // to the solution repo

    ResourceKey key = null;

    IUnifiedRepository unifiedRepository =
        PentahoSystem.get(IUnifiedRepository.class, PentahoSessionHolder.getSession());
    RepositoryFile repositoryFile = unifiedRepository.getFileById(fileId);
    if (repositoryFile != null) {
      key =
          resourceManager.createKey(
              RepositoryResourceLoader.SOLUTION_SCHEMA_NAME
                  + RepositoryResourceLoader.SCHEMA_SEPARATOR
                  + repositoryFile.getPath(),
              helperObjects);
    } else {
      key =
          resourceManager.createKey(
              RepositoryResourceLoader.SOLUTION_SCHEMA_NAME
                  + RepositoryResourceLoader.SCHEMA_SEPARATOR
                  + fileId,
              helperObjects);
    }

    final Resource resource = resourceManager.create(key, null, MasterReport.class);
    return (MasterReport) resource.getResource();
  }
 /**
  * @param repositoryDir
  * @param outputStream
  */
 @Override
 public void exportDirectory(
     RepositoryFile repositoryDir, OutputStream outputStream, String filePath)
     throws ExportException, IOException {
   addToManifest(repositoryDir);
   List<RepositoryFile> children =
       this.unifiedRepository.getChildren(
           new RepositoryRequest(String.valueOf(repositoryDir.getId()), true, 1, null));
   for (RepositoryFile repositoryFile : children) {
     // exclude 'etc' folder - datasources and etc.
     if (!ClientRepositoryPaths.getEtcFolderPath().equals(repositoryFile.getPath())) {
       if (repositoryFile.isFolder()) {
         if (outputStream.getClass().isAssignableFrom(ZipOutputStream.class)) {
           ZipOutputStream zos = (ZipOutputStream) outputStream;
           ZipEntry entry = new ZipEntry(getZipEntryName(repositoryFile, filePath));
           zos.putNextEntry(entry);
         }
         exportDirectory(repositoryFile, outputStream, filePath);
       } else {
         exportFile(repositoryFile, outputStream, filePath);
       }
     }
   }
   createLocales(repositoryDir, filePath, repositoryDir.isFolder(), outputStream);
 }
Пример #4
0
  @SuppressWarnings("rawtypes")
  protected static IRuntimeContext executeInternal(
      RepositoryFile file,
      IParameterProvider requestParams,
      HttpServletRequest httpServletRequest,
      IOutputHandler outputHandler,
      Map<String, IParameterProvider> parameterProviders,
      IPentahoSession userSession,
      boolean forcePrompt,
      List messages)
      throws Exception {
    String processId = XactionUtil.class.getName();
    String instanceId = httpServletRequest.getParameter("instance-id"); // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory(""); // $NON-NLS-1$
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, userSession);
    ISystemSettings systemSettings = PentahoSystem.getSystemSettings();

    if (solutionEngine == null) {
      throw new ObjectFactoryException("No Solution Engine");
    }

    boolean instanceEnds =
        "true"
            .equalsIgnoreCase(
                requestParams.getStringParameter(
                    "instanceends", "true")); // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    String parameterXsl =
        systemSettings.getSystemSetting(
            "default-parameter-xsl", "DefaultParameterForm.xsl"); // $NON-NLS-1$ //$NON-NLS-2$

    solutionEngine.setLoggingLevel(2);
    solutionEngine.init(userSession);
    solutionEngine.setForcePrompt(forcePrompt);
    if (parameterXsl != null) {
      solutionEngine.setParameterXsl(parameterXsl);
    }
    return solutionEngine.execute(
        file.getPath(),
        processId,
        false,
        instanceEnds,
        instanceId,
        false,
        parameterProviders,
        outputHandler,
        null,
        urlFactory,
        messages);
  }
  @Test
  public void testGetFolder() throws Exception {
    final MockUnifiedRepository repository =
        new MockUnifiedRepository(new SpringSecurityCurrentUserProvider());
    final RepositoryUtils repositoryUtils = new RepositoryUtils(repository);

    RepositoryFile test = repositoryUtils.getFolder("/public/one/two/three", true, true, null);
    assertNotNull(test);
    assertEquals("The folder name is invalid", "three", test.getName());
    assertEquals("The path is invalid", "/public/one/two/three", test.getPath());
    assertTrue("The folder should be defined as a folder", test.isFolder());

    // Make sure it created the parents
    RepositoryFile one = repositoryUtils.getFolder("/public/one", false, false, null);
    assertNotNull(one);
    RepositoryFile two = repositoryUtils.getFolder("/public/one/two", false, false, null);
    assertNotNull(two);
  }
Пример #6
0
  @SuppressWarnings("rawtypes")
  public static void createOutputFileName(RepositoryFile file, IOutputHandler outputHandler) {
    IPentahoSession userSession = PentahoSessionHolder.getSession();
    ActionSequenceJCRHelper actionHelper = new ActionSequenceJCRHelper(userSession);
    IActionSequence actionSequence =
        actionHelper.getActionSequence(
            file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);

    String fileName = "content"; // $NON-NLS-1$
    if (actionSequence != null) {
      String title = actionSequence.getTitle();
      if ((title != null) && (title.length() > 0)) {
        fileName = title;
      } else {
        String sequenceName = actionSequence.getSequenceName();

        if ((sequenceName != null) && (sequenceName.length() > 0)) {
          fileName = sequenceName;
        } else {
          List actionDefinitionsList = actionSequence.getActionDefinitionsAndSequences();
          int i = 0;
          boolean done = false;

          while ((actionDefinitionsList.size() > i) && (!done)) {
            IActionDefinition actionDefinition = (IActionDefinition) actionDefinitionsList.get(i);
            String componentName = actionDefinition.getComponentName();
            if ((componentName != null) && (componentName.length() > 0)) {
              fileName = componentName;
              done = true;
            } else {
              ++i;
            }
          }
        }
      }
    }
    IMimeTypeListener mimeTypeListener = outputHandler.getMimeTypeListener();
    if (mimeTypeListener != null) {
      mimeTypeListener.setName(fileName);
    }
  }
  /**
   * Take repository file path and local file path and return computed zip entry path
   *
   * @param repositoryFile
   * @param filePath
   * @return
   */
  private String getZipEntryName(RepositoryFile repositoryFile, String filePath) {
    String result = "";

    // if we are at the root, get substring differently
    int filePathLength = 0;

    if (filePath.equals("/")) {
      filePathLength = filePath.length();
    } else {
      filePathLength = filePath.length() + 1;
    }

    result = repositoryFile.getPath().substring(filePathLength);

    // add trailing slash for folders
    if (repositoryFile.isFolder()) {
      result += "/";
    }

    return result;
  }
  @Test
  public void testGetFile() throws Exception {
    final MockUnifiedRepository repository =
        new MockUnifiedRepository(new SpringSecurityCurrentUserProvider());
    final RepositoryUtils repositoryUtils = new RepositoryUtils(repository);

    final SimpleRepositoryFileData data =
        new SimpleRepositoryFileData(
            new ByteArrayInputStream("Test".getBytes()), "UTF-8", "text/plain");
    RepositoryFile test =
        repositoryUtils.getFile("/public/one/two/three.prpt", data, true, true, null);
    assertNotNull(test);
    assertEquals("The filename is invalid", "three.prpt", test.getName());
    assertEquals("The path is invalid", "/public/one/two/three.prpt", test.getPath());
    assertFalse("The file should not be defined as a folder", test.isFolder());

    // Make sure it created the parents
    RepositoryFile one = repositoryUtils.getFolder("/public/one", false, false, null);
    assertNotNull(one);
    RepositoryFile two = repositoryUtils.getFolder("/public/one/two", false, false, null);
    assertNotNull(two);
  }
Пример #9
0
  @SuppressWarnings({"unchecked", "rawtypes"})
  public static String doParameter(
      final RepositoryFile file,
      IParameterProvider parameterProvider,
      final IPentahoSession userSession)
      throws IOException {
    ActionSequenceJCRHelper helper = new ActionSequenceJCRHelper();
    final IActionSequence actionSequence =
        helper.getActionSequence(
            file.getPath(), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
    final Document document = DocumentHelper.createDocument();
    try {
      final Element parametersElement = document.addElement("parameters");

      // noinspection unchecked
      final Map<String, IActionParameter> params =
          actionSequence.getInputDefinitionsForParameterProvider(IParameterProvider.SCOPE_REQUEST);
      for (final Map.Entry<String, IActionParameter> entry : params.entrySet()) {
        final String paramName = entry.getKey();
        final IActionParameter paramDef = entry.getValue();
        final String value = paramDef.getStringValue();
        final Class type;
        // yes, the actual type-code uses equals-ignore-case and thus allows the user
        // to specify type information in a random case. sTrInG is equal to STRING is equal to the
        // value
        // defined as constant (string)
        if (IActionParameter.TYPE_LIST.equalsIgnoreCase(paramDef.getType())) {
          type = String[].class;
        } else {
          type = String.class;
        }
        final String label = paramDef.getSelectionDisplayName();

        final String[] values;
        if (StringUtils.isEmpty(value)) {
          values = new String[0];
        } else {
          values = new String[] {value};
        }

        createParameterElement(
            parametersElement, paramName, type, label, "user", "parameters", values);
      }

      createParameterElement(
          parametersElement,
          "path",
          String.class,
          null,
          "system",
          "system",
          new String[] {file.getPath()});
      createParameterElement(
          parametersElement,
          "prompt",
          String.class,
          null,
          "system",
          "system",
          new String[] {"yes", "no"});
      createParameterElement(
          parametersElement,
          "instance-id",
          String.class,
          null,
          "system",
          "system",
          new String[] {parameterProvider.getStringParameter("instance-id", null)});
      // no close, as far as I know tomcat does not like it that much ..
      OutputFormat format = OutputFormat.createCompactFormat();
      format.setSuppressDeclaration(true);
      format.setEncoding("utf-8"); // $NON-NLS-1$
      ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
      XMLWriter writer = new XMLWriter(outputStream, format);
      writer.write(document);
      writer.flush();
      return outputStream.toString("utf-8");
    } catch (Exception e) {
      logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e);
      return null;
    }
  }
  /**
   * Performs the export process, returns a zip File object
   *
   * @throws ExportException indicates an error in import processing
   */
  public File performExport(RepositoryFile exportRepositoryFile)
      throws ExportException, IOException {
    File exportFile = null;

    // create temp file
    exportFile = File.createTempFile(EXPORT_TEMP_FILENAME_PREFIX, EXPORT_TEMP_FILENAME_EXT);
    exportFile.deleteOnExit();

    // get the file path
    String filePath = new File(this.path).getParent();
    if (filePath == null) {
      filePath = "/";
    }

    // send a response right away if not found
    if (exportRepositoryFile == null) {
      // todo: add to messages.properties
      throw new FileNotFoundException("JCR file not found: " + this.path);
    }

    ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(exportFile));

    if (exportRepositoryFile.isFolder()) { // Handle recursive export
      exportManifest
          .getManifestInformation()
          .setRootFolder(path.substring(0, path.lastIndexOf("/") + 1));

      // don't zip root folder without name
      if (!ClientRepositoryPaths.getRootFolderPath().equals(exportRepositoryFile.getPath())) {
        zos.putNextEntry(new ZipEntry(getZipEntryName(exportRepositoryFile, filePath)));
      }
      exportDirectory(exportRepositoryFile, zos, filePath);

    } else {
      exportManifest
          .getManifestInformation()
          .setRootFolder(path.substring(0, path.lastIndexOf("/") + 1));
      exportFile(exportRepositoryFile, zos, filePath);
    }

    if (this.withManifest) {
      // write manifest to zip output stream
      ZipEntry entry = new ZipEntry(EXPORT_MANIFEST_FILENAME);
      zos.putNextEntry(entry);

      // pass output stream to manifest class for writing
      try {
        exportManifest.toXml(zos);
      } catch (Exception e) {
        // todo: add to messages.properties
        log.error("Error generating export XML");
      }

      zos.closeEntry();
    }

    zos.close();

    // clean up
    exportManifest = null;
    zos = null;

    return exportFile;
  }