Search in sources :

Example 6 with SampleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData in project pentaho-platform by pentaho.

the class JcrRepositoryFileDaoIT method testUpdateFile1.

@Test
public // Running within defined date
void testUpdateFile1() throws Exception {
    RepositoryFile newFile = createFile("JcrRepositoryFileDaoTest1.test");
    IRepositoryFileData dataMock = new SampleRepositoryFileData("", true, 0);
    Date startDate = new Date();
    newFile = new RepositoryFile.Builder(newFile).createdDate(startDate).build();
    repo.updateFile(newFile, dataMock, "edition #2");
    List<VersionSummary> summaries = repo.getVersionSummaries(newFile.getId());
    Date lastVersionDate = summaries.get(summaries.size() - 1).getDate();
    assertEquals("incorrect version date", lastVersionDate, startDate);
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) SampleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData) VersionSummary(org.pentaho.platform.api.repository2.unified.VersionSummary) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Date(java.util.Date) Test(org.junit.Test)

Example 7 with SampleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData 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 8 with SampleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData 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 9 with SampleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData 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 10 with SampleRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData 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

SampleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.sample.SampleRepositoryFileData)14 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)13 Test (org.junit.Test)12 Matchers.anyString (org.mockito.Matchers.anyString)10 ITenant (org.pentaho.platform.api.mt.ITenant)10 VersionSummary (org.pentaho.platform.api.repository2.unified.VersionSummary)4 Date (java.util.Date)3 Locale (java.util.Locale)2 IPentahoLocale (org.pentaho.platform.api.locale.IPentahoLocale)2 IRepositoryFileData (org.pentaho.platform.api.repository2.unified.IRepositoryFileData)2 PentahoLocale (org.pentaho.platform.repository2.locale.PentahoLocale)2 Serializable (java.io.Serializable)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Properties (java.util.Properties)1 Node (javax.jcr.Node)1 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)1 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)1 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)1