Search in sources :

Example 11 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.

the class SolutionImportHandler method importFile.

@Override
public void importFile(IPlatformImportBundle bundle) throws PlatformImportException, DomainIdNullException, DomainAlreadyExistsException, DomainStorageException, IOException {
    RepositoryFileImportBundle importBundle = (RepositoryFileImportBundle) bundle;
    ZipInputStream zipImportStream = new ZipInputStream(bundle.getInputStream());
    SolutionRepositoryImportSource importSource = new SolutionRepositoryImportSource(zipImportStream);
    LocaleFilesProcessor localeFilesProcessor = new LocaleFilesProcessor();
    setOverwriteFile(bundle.overwriteInRepository());
    // importSession.set(ImportSession.getSession());
    IPlatformImporter importer = PentahoSystem.get(IPlatformImporter.class);
    cachedImports = new HashMap<String, RepositoryFileImportBundle.Builder>();
    // Process Manifest Settings
    ExportManifest manifest = getImportSession().getManifest();
    String manifestVersion = null;
    if (manifest != null) {
        manifestVersion = manifest.getManifestInformation().getManifestVersion();
    }
    // Process Metadata
    if (manifest != null) {
        // import the users
        Map<String, List<String>> roleToUserMap = importUsers(manifest.getUserExports());
        // import the roles
        importRoles(manifest.getRoleExports(), roleToUserMap);
        List<ExportManifestMetadata> metadataList = manifest.getMetadataList();
        for (ExportManifestMetadata exportManifestMetadata : metadataList) {
            String domainId = exportManifestMetadata.getDomainId();
            if (domainId != null && !domainId.endsWith(XMI_EXTENSION)) {
                domainId = domainId + XMI_EXTENSION;
            }
            boolean overWriteInRepository = isOverwriteFile();
            RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().charSet("UTF-8").hidden(RepositoryFile.HIDDEN_BY_DEFAULT).schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT).preserveDsw(bundle.isPreserveDsw()).overwriteFile(overWriteInRepository).mime("text/xmi+xml").withParam("domain-id", domainId);
            cachedImports.put(exportManifestMetadata.getFile(), bundleBuilder);
        }
        // Process Mondrian
        List<ExportManifestMondrian> mondrianList = manifest.getMondrianList();
        for (ExportManifestMondrian exportManifestMondrian : mondrianList) {
            String catName = exportManifestMondrian.getCatalogName();
            Parameters parametersMap = exportManifestMondrian.getParameters();
            StringBuilder parametersStr = new StringBuilder();
            for (String s : parametersMap.keySet()) {
                parametersStr.append(s).append("=").append(parametersMap.get(s)).append(sep);
            }
            RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder().charSet("UTF_8").hidden(RepositoryFile.HIDDEN_BY_DEFAULT).schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT).name(catName).overwriteFile(isOverwriteFile()).mime("application/vnd.pentaho.mondrian+xml").withParam("parameters", parametersStr.toString()).withParam("domain-id", // TODO: this is
            catName);
            // definitely
            // named wrong
            // at the very
            // least.
            // pass as param if not in parameters string
            String xmlaEnabled = "" + exportManifestMondrian.isXmlaEnabled();
            bundleBuilder.withParam("EnableXmla", xmlaEnabled);
            cachedImports.put(exportManifestMondrian.getFile(), bundleBuilder);
            String annotationsFile = exportManifestMondrian.getAnnotationsFile();
            if (annotationsFile != null) {
                RepositoryFileImportBundle.Builder annotationsBundle = new RepositoryFileImportBundle.Builder().path(MondrianCatalogRepositoryHelper.ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catName).name("annotations.xml").charSet("UTF_8").overwriteFile(isOverwriteFile()).mime("text/xml").hidden(RepositoryFile.HIDDEN_BY_DEFAULT).schedulable(RepositoryFile.SCHEDULABLE_BY_DEFAULT).withParam("domain-id", catName);
                cachedImports.put(annotationsFile, annotationsBundle);
            }
        }
    }
    importMetaStore(manifest, bundle.overwriteInRepository());
    for (IRepositoryFileBundle fileBundle : importSource.getFiles()) {
        String fileName = fileBundle.getFile().getName();
        String actualFilePath = fileBundle.getPath();
        if (manifestVersion != null) {
            fileName = ExportFileNameEncoder.decodeZipFileName(fileName);
            actualFilePath = ExportFileNameEncoder.decodeZipFileName(actualFilePath);
        }
        String repositoryFilePath = RepositoryFilenameUtils.concat(PentahoPlatformImporter.computeBundlePath(actualFilePath), fileName);
        if (this.cachedImports.containsKey(repositoryFilePath)) {
            byte[] bytes = IOUtils.toByteArray(fileBundle.getInputStream());
            RepositoryFileImportBundle.Builder builder = cachedImports.get(repositoryFilePath);
            builder.input(new ByteArrayInputStream(bytes));
            importer.importFile(build(builder));
            continue;
        }
        RepositoryFileImportBundle.Builder bundleBuilder = new RepositoryFileImportBundle.Builder();
        InputStream bundleInputStream = null;
        String decodedFilePath = fileBundle.getPath();
        RepositoryFile decodedFile = fileBundle.getFile();
        if (manifestVersion != null) {
            decodedFile = new RepositoryFile.Builder(decodedFile).path(decodedFilePath).name(fileName).title(fileName).build();
            decodedFilePath = ExportFileNameEncoder.decodeZipFileName(fileBundle.getPath());
        }
        if (fileBundle.getFile().isFolder()) {
            bundleBuilder.mime("text/directory");
            bundleBuilder.file(decodedFile);
            fileName = repositoryFilePath;
            repositoryFilePath = importBundle.getPath();
        } else {
            byte[] bytes = IOUtils.toByteArray(fileBundle.getInputStream());
            bundleInputStream = new ByteArrayInputStream(bytes);
            // If is locale file store it for later processing.
            if (localeFilesProcessor.isLocaleFile(fileBundle, importBundle.getPath(), bytes)) {
                log.trace("Skipping [" + repositoryFilePath + "], it is a locale property file");
                continue;
            }
            bundleBuilder.input(bundleInputStream);
            bundleBuilder.mime(solutionHelper.getMime(fileName));
            String filePath = (decodedFilePath.equals("/") || decodedFilePath.equals("\\")) ? "" : decodedFilePath;
            repositoryFilePath = RepositoryFilenameUtils.concat(importBundle.getPath(), filePath);
        }
        bundleBuilder.name(fileName);
        bundleBuilder.path(repositoryFilePath);
        String sourcePath;
        if (fileBundle.getFile().isFolder()) {
            sourcePath = fileName;
        } else {
            sourcePath = RepositoryFilenameUtils.concat(PentahoPlatformImporter.computeBundlePath(actualFilePath), fileName);
        }
        // may not have rights to such as /home or /public
        if (manifest != null && manifest.getExportManifestEntity(sourcePath) == null && fileBundle.getFile().isFolder()) {
            continue;
        }
        getImportSession().setCurrentManifestKey(sourcePath);
        bundleBuilder.charSet(bundle.getCharset());
        bundleBuilder.overwriteFile(bundle.overwriteInRepository());
        bundleBuilder.applyAclSettings(bundle.isApplyAclSettings());
        bundleBuilder.retainOwnership(bundle.isRetainOwnership());
        bundleBuilder.overwriteAclSettings(bundle.isOverwriteAclSettings());
        bundleBuilder.acl(getImportSession().processAclForFile(sourcePath));
        RepositoryFile file = getFile(importBundle, fileBundle);
        ManifestFile manifestFile = getImportSession().getManifestFile(sourcePath, file != null);
        bundleBuilder.hidden(isFileHidden(file, manifestFile, sourcePath));
        boolean isSchedulable = isSchedulable(file, manifestFile);
        if (isSchedulable) {
            bundleBuilder.schedulable(isSchedulable);
        } else {
            bundleBuilder.schedulable(fileIsScheduleInputSource(manifest, sourcePath));
        }
        IPlatformImportBundle platformImportBundle = build(bundleBuilder);
        importer.importFile(platformImportBundle);
        if (bundleInputStream != null) {
            bundleInputStream.close();
            bundleInputStream = null;
        }
    }
    if (manifest != null) {
        importSchedules(manifest.getScheduleList());
        // Add Hitachi Vantara Connections
        List<org.pentaho.database.model.DatabaseConnection> datasourceList = manifest.getDatasourceList();
        if (datasourceList != null) {
            IDatasourceMgmtService datasourceMgmtSvc = PentahoSystem.get(IDatasourceMgmtService.class);
            for (org.pentaho.database.model.DatabaseConnection databaseConnection : datasourceList) {
                if (databaseConnection.getDatabaseType() == null) {
                    // don't try to import the connection if there is no type it will cause an error
                    // However, if this is the DI Server, and the connection is defined in a ktr, it will import automatically
                    log.warn("Can't import connection " + databaseConnection.getName() + " because it doesn't have a databaseType");
                    continue;
                }
                try {
                    IDatabaseConnection existingDBConnection = datasourceMgmtSvc.getDatasourceByName(databaseConnection.getName());
                    if (existingDBConnection != null && existingDBConnection.getName() != null) {
                        if (isOverwriteFile()) {
                            databaseConnection.setId(existingDBConnection.getId());
                            datasourceMgmtSvc.updateDatasourceByName(databaseConnection.getName(), databaseConnection);
                        }
                    } else {
                        datasourceMgmtSvc.createDatasource(databaseConnection);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        }
    }
    // Process locale files.
    localeFilesProcessor.processLocaleFiles(importer);
}
Also used : ExportManifestMetadata(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMetadata) ExportManifest(org.pentaho.platform.plugin.services.importexport.exportManifest.ExportManifest) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) IPlatformImportBundle(org.pentaho.platform.api.repository2.unified.IPlatformImportBundle) List(java.util.List) ArrayList(java.util.ArrayList) ExportManifestMondrian(org.pentaho.platform.plugin.services.importexport.exportManifest.bindings.ExportManifestMondrian) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) IRepositoryFileBundle(org.pentaho.platform.plugin.services.importexport.ImportSource.IRepositoryFileBundle) Parameters(org.pentaho.platform.plugin.services.importexport.exportManifest.Parameters) ByteArrayInputStream(java.io.ByteArrayInputStream) ZipInputStream(java.util.zip.ZipInputStream) InputStream(java.io.InputStream) ManifestFile(org.pentaho.platform.plugin.services.importexport.ImportSession.ManifestFile) AlreadyExistsException(org.pentaho.platform.api.engine.security.userroledao.AlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) ZipInputStream(java.util.zip.ZipInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection)

Example 12 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryContentIT method testLocalePropertiesMap.

@Test
public void testLocalePropertiesMap() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", new String[] { tenantAdminRoleName });
    logout();
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    // Create file
    final String fileName = "locale.sample";
    RepositoryFile file = createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY), fileName, "test", false, 123);
    // Test filename title matches created file name
    assertEquals(fileName, file.getTitle());
    final String DEFAULT_LOCALE = "default";
    final IPentahoLocale SPANISH = new PentahoLocale(new Locale("es"));
    final IPentahoLocale US = new PentahoLocale(Locale.US);
    final String TITLE = "title";
    final String DESCRIPTION = "description";
    final String EN_US_TITLE = "Locale Sample";
    final String EN_US_DESCRIPTION = "This is a test for retrieving localized words";
    final String SP_TITLE = "Muestra de Localizacion";
    final String SP_DESCRIPTION = "Esta es una prueba para buscar palabras localizadas";
    RepositoryFile.Builder builder = new RepositoryFile.Builder(file);
    Map<String, Properties> localeMap = new HashMap<String, Properties>();
    // Set English locale values
    final Properties enProperties = new Properties();
    enProperties.setProperty(TITLE, EN_US_TITLE);
    enProperties.setProperty(DESCRIPTION, EN_US_DESCRIPTION);
    localeMap.put(US.toString(), enProperties);
    // Set Spanish locale values
    final Properties esProperties = new Properties();
    esProperties.setProperty(TITLE, SP_TITLE);
    esProperties.setProperty(DESCRIPTION, SP_DESCRIPTION);
    localeMap.put(SPANISH.toString(), esProperties);
    builder.localePropertiesMap(localeMap);
    // Update file data
    final SampleRepositoryFileData modContent = new SampleRepositoryFileData("blah", false, 123);
    repo.updateFile(builder.build(), modContent, null);
    // Retrieve file - gets full map
    final RepositoryFile updatedFile = repo.getFile(file.getPath(), true);
    // Assert messages are the same
    Properties ep = updatedFile.getLocalePropertiesMap().get(US.toString());
    assertEquals(EN_US_TITLE, ep.getProperty(TITLE));
    assertEquals(EN_US_DESCRIPTION, ep.getProperty(DESCRIPTION));
    Properties sp = updatedFile.getLocalePropertiesMap().get(SPANISH.toString());
    assertEquals(SP_TITLE, sp.getProperty(TITLE));
    assertEquals(SP_DESCRIPTION, sp.getProperty(DESCRIPTION));
    // Assert empty rootLocale
    Properties rootLocale = updatedFile.getLocalePropertiesMap().get(DEFAULT_LOCALE);
    assertNotNull(rootLocale);
    final String NEW_TITLE = "new title";
    final String NEW_DESCRIPTION = "new description";
    // overwrite title
    enProperties.setProperty(TITLE, NEW_TITLE);
    // overwrite title
    enProperties.setProperty(DESCRIPTION, NEW_DESCRIPTION);
    txnTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            // assert available locales
            List<Locale> locales = repositoryFileDao.getAvailableLocalesForFile(updatedFile);
            // includes rootLocale
            assertEquals(3, locales.size());
            // assert correct locale properties
            Properties properties = repositoryFileDao.getLocalePropertiesForFile(updatedFile, "es");
            assertEquals(SP_TITLE, properties.getProperty(TITLE));
            assertEquals(SP_DESCRIPTION, properties.getProperty(DESCRIPTION));
            repositoryFileDao.setLocalePropertiesForFile(updatedFile, Locale.US.getLanguage(), enProperties);
        }
    });
    // Assert updated properties
    RepositoryFile updatedRepoFile = repo.getFile(file.getPath(), true);
    Properties updated_en = updatedRepoFile.getLocalePropertiesMap().get(US.toString());
    assertEquals(NEW_TITLE, updated_en.getProperty(TITLE));
    assertEquals(NEW_DESCRIPTION, updated_en.getProperty(DESCRIPTION));
    // test successful delete locale properties
    final RepositoryFile repoFile1 = updatedRepoFile.clone();
    txnTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            repositoryFileDao.deleteLocalePropertiesForFile(repoFile1, "es");
        }
    });
    // assert deleted locale
    updatedRepoFile = repo.getFile(file.getPath(), true);
    List<Locale> locales = repositoryFileDao.getAvailableLocalesForFile(updatedRepoFile);
    assertEquals(2, locales.size());
    // test successful delete locale properties
    final RepositoryFile repoFile2 = updatedRepoFile.clone();
    txnTemplate.execute(new TransactionCallbackWithoutResult() {

        @Override
        public void doInTransactionWithoutResult(final TransactionStatus status) {
            repositoryFileDao.deleteLocalePropertiesForFile(repoFile2, "xx");
        }
    });
    // locale properties do not exist, no change in available locales
    updatedRepoFile = repo.getFile(file.getPath(), true);
    locales = repositoryFileDao.getAvailableLocalesForFile(updatedRepoFile);
    assertEquals(2, locales.size());
    logout();
}
Also used : Locale(java.util.Locale) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) HashMap(java.util.HashMap) TransactionStatus(org.springframework.transaction.TransactionStatus) Matchers.anyString(org.mockito.Matchers.anyString) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) Properties(java.util.Properties) SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) List(java.util.List) ArrayList(java.util.ArrayList) TransactionCallbackWithoutResult(org.springframework.transaction.support.TransactionCallbackWithoutResult) Test(org.junit.Test)

Example 13 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryContentIT method testLocales.

@Test
public void testLocales() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", new String[] { tenantAdminRoleName });
    logout();
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    // Create file
    final String fileName = "locale.sample";
    RepositoryFile file = createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY), fileName, "test", false, 123);
    // Test filename title matches created file name
    assertEquals(fileName, file.getTitle());
    final IPentahoLocale SPANISH = new PentahoLocale(new Locale("es"));
    final IPentahoLocale US = new PentahoLocale(Locale.US);
    final String EN_US_TITLE = "Locale Sample";
    final String EN_US_DESCRIPTION = "This is a test for retrieving localized words";
    final String SP_TITLE = "Muestra de Localizacion";
    final String SP_DESCRIPTION = "Esta es una prueba para buscar palabras localizadas";
    RepositoryFile.Builder builder = new RepositoryFile.Builder(file);
    // Set English locale values
    builder.title(US.toString(), EN_US_TITLE);
    builder.description(US.toString(), EN_US_DESCRIPTION);
    // Set Spanish locale values
    builder.title(SPANISH.toString(), SP_TITLE);
    builder.description(SPANISH.toString(), SP_DESCRIPTION);
    // Update file data
    final SampleRepositoryFileData modContent = new SampleRepositoryFileData("blah", false, 123);
    repo.updateFile(builder.build(), modContent, null);
    // Retrieve file - gets full map
    RepositoryFile updatedFile = repo.getFile(file.getPath(), true);
    assertNotNull(updatedFile.getLocalePropertiesMap());
    assertEquals(3, updatedFile.getLocalePropertiesMap().size());
    /*
     * Retrieve single result with locale
     */
    // SPANISH
    updatedFile = repo.getFile(file.getPath(), SPANISH);
    assertEquals(SP_TITLE, updatedFile.getTitle());
    assertEquals(SP_DESCRIPTION, updatedFile.getDescription());
    // US ENGLISH
    updatedFile = repo.getFile(file.getPath(), US);
    assertEquals(EN_US_TITLE, updatedFile.getTitle());
    assertEquals(EN_US_DESCRIPTION, updatedFile.getDescription());
    // ROOT Locale
    LocaleHelper.setLocale(US.getLocale());
    updatedFile = repo.getFile(file.getPath(), null);
    assertEquals(EN_US_TITLE, updatedFile.getTitle());
    assertEquals(EN_US_DESCRIPTION, updatedFile.getDescription());
    logout();
}
Also used : Locale(java.util.Locale) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) ITenant(org.pentaho.platform.api.mt.ITenant) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) PentahoLocale(org.pentaho.platform.repository2.locale.PentahoLocale) IPentahoLocale(org.pentaho.platform.api.locale.IPentahoLocale) Test(org.junit.Test)

Example 14 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryContentIT method testGetFileWithLoadedMaps.

@Test
public void testGetFileWithLoadedMaps() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", new String[] { tenantAdminRoleName });
    logout();
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    final String fileName = "helloworld.sample";
    RepositoryFile newFile = createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY), fileName, "blah", false, 123);
    assertEquals(fileName, newFile.getTitle());
    RepositoryFile.Builder builder = new RepositoryFile.Builder(newFile);
    final String EN_US_VALUE = "Hello World Sample";
    builder.title(Locale.getDefault().toString(), EN_US_VALUE);
    final String ROOT_LOCALE_VALUE = "Hello World";
    builder.title(RepositoryFile.DEFAULT_LOCALE, ROOT_LOCALE_VALUE);
    final SampleRepositoryFileData modContent = new SampleRepositoryFileData("blah", false, 123);
    repo.updateFile(builder.build(), modContent, null);
    RepositoryFile updatedFileWithMaps = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY) + RepositoryFile.SEPARATOR + "helloworld.sample", true);
    assertEquals(EN_US_VALUE, updatedFileWithMaps.getLocalePropertiesMap().get(Locale.getDefault().toString()).getProperty(RepositoryFile.FILE_TITLE));
    assertEquals(ROOT_LOCALE_VALUE, updatedFileWithMaps.getLocalePropertiesMap().get(RepositoryFile.DEFAULT_LOCALE).getProperty(RepositoryFile.FILE_TITLE));
    logout();
}
Also used : SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) ITenant(org.pentaho.platform.api.mt.ITenant) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 15 with Builder

use of org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder in project pentaho-platform by pentaho.

the class DefaultUnifiedRepositoryVersioningIT method testGetFileByVersionSummary.

@Test
public void testGetFileByVersionSummary() throws Exception {
    loginAsSysTenantAdmin();
    ITenant tenantAcme = tenantManager.createTenant(systemTenant, TENANT_ID_ACME, tenantAdminRoleName, tenantAuthenticatedRoleName, ANONYMOUS_ROLE_NAME);
    userRoleDao.createUser(tenantAcme, USERNAME_ADMIN, PASSWORD, "", new String[] { tenantAdminRoleName });
    login(USERNAME_ADMIN, tenantAcme, new String[] { tenantAdminRoleName, tenantAuthenticatedRoleName });
    userRoleDao.createUser(tenantAcme, USERNAME_SUZY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
    final String fileName = "helloworld.sample";
    final String origSampleString = "Hello World!";
    final boolean origSampleBoolean = false;
    final int origSampleInteger = 1024;
    RepositoryFile newFile = createSampleFile(parentFolderPath, fileName, origSampleString, origSampleBoolean, origSampleInteger, true);
    final Serializable fileId = newFile.getId();
    final String absolutePath = newFile.getPath();
    final String modSampleString = "Ciao World!";
    final boolean modSampleBoolean = true;
    final int modSampleInteger = 2048;
    final SampleRepositoryFileData modData = new SampleRepositoryFileData(modSampleString, modSampleBoolean, modSampleInteger);
    RepositoryFile.Builder builder = new RepositoryFile.Builder(newFile);
    final String desc = "Hello World description";
    builder.description(RepositoryFile.DEFAULT_LOCALE, desc);
    repo.updateFile(builder.build(), modData, null);
    List<VersionSummary> versionSummaries = repo.getVersionSummaries(newFile.getId());
    RepositoryFile v1 = repo.getFileAtVersion(newFile.getId(), versionSummaries.get(0).getId());
    RepositoryFile v2 = repo.getFileAtVersion(newFile.getId(), versionSummaries.get(1).getId());
    assertEquals(fileName, v1.getName());
    assertEquals(fileName, v2.getName());
    assertEquals(fileId, v1.getId());
    assertEquals(fileId, v2.getId());
    assertEquals("1.0", v1.getVersionId());
    assertEquals("1.1", v2.getVersionId());
    assertEquals(absolutePath, v1.getPath());
    assertEquals(absolutePath, v2.getPath());
    assertNull(v1.getDescription());
    assertEquals(desc, v2.getDescription());
    System.out.println("or: " + newFile);
    System.out.println("v1: " + v1);
    System.out.println("v2: " + v2);
    SampleRepositoryFileData c1 = repo.getDataAtVersionForRead(v1.getId(), v1.getVersionId(), SampleRepositoryFileData.class);
    SampleRepositoryFileData c2 = repo.getDataAtVersionForRead(v2.getId(), v2.getVersionId(), SampleRepositoryFileData.class);
    assertEquals(origSampleString, c1.getSampleString());
    assertEquals(origSampleBoolean, c1.getSampleBoolean());
    assertEquals(origSampleInteger, c1.getSampleInteger());
    assertEquals(modSampleString, c2.getSampleString());
    assertEquals(modSampleBoolean, c2.getSampleBoolean());
    assertEquals(modSampleInteger, c2.getSampleInteger());
}
Also used : SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) Serializable(java.io.Serializable) ITenant(org.pentaho.platform.api.mt.ITenant) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)15 ITenant (org.pentaho.platform.api.mt.ITenant)7 Test (org.junit.Test)5 Matchers.anyString (org.mockito.Matchers.anyString)5 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)5 Builder (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl.Builder)4 SampleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData)4 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 Serializable (java.io.Serializable)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Locale (java.util.Locale)2 Properties (java.util.Properties)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IPentahoLocale (org.pentaho.platform.api.locale.IPentahoLocale)2 PentahoLocale (org.pentaho.platform.repository2.locale.PentahoLocale)2 Authentication (org.springframework.security.core.Authentication)2 TransactionStatus (org.springframework.transaction.TransactionStatus)2