Search in sources :

Example 11 with UnifiedRepositoryException

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

the class DefaultUnifiedRepositoryContentIT method testCreateNodeFile.

@Test
public void testCreateNodeFile() 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 expectedName = "helloworld.doesnotmatter";
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    final String expectedPath = parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
    final String serverPath = ServerRepositoryPaths.getTenantRootFolderPath() + parentFolderPath + RepositoryFile.SEPARATOR + "helloworld2.sample";
    RepositoryFile sampleFile = createSampleFile(parentFolderPath, "helloworld2.sample", "dfdd", true, 83);
    final Date EXP_DATE = new Date();
    DataNode node = new DataNode("kdjd");
    node.setProperty("ddf", "ljsdfkjsdkf");
    DataNode newChild1 = node.addNode("herfkmdx");
    newChild1.setProperty("sdfs", true);
    newChild1.setProperty("ks3", EXP_DATE);
    newChild1.setProperty("ids32", 7.32D);
    newChild1.setProperty("erere3", 9856684583L);
    newChild1.setProperty("tttss4", "843skdfj33ksaljdfj");
    newChild1.setProperty("urei2", new DataNodeRef(sampleFile.getId()));
    DataNode newChild2 = node.addNode(JcrStringHelper.fileNameEncode("pppq/qqs2"));
    newChild2.setProperty(JcrStringHelper.fileNameEncode("ttt*ss4"), "843skdfj33ksaljdfj");
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(expectedName).build(), data, null);
    assertNotNull(newFile.getId());
    RepositoryFile foundFile = repo.getFile(expectedPath);
    assertNotNull(foundFile);
    assertEquals(expectedName, foundFile.getName());
    DataNode foundNode = repo.getDataForRead(foundFile.getId(), NodeRepositoryFileData.class).getNode();
    assertEquals(node.getName(), foundNode.getName());
    assertNotNull(foundNode.getId());
    assertEquals(node.getProperty("ddf"), foundNode.getProperty("ddf"));
    int actualPropCount = 0;
    for (DataProperty prop : foundNode.getProperties()) {
        actualPropCount++;
    }
    assertEquals(1, actualPropCount);
    assertTrue(foundNode.hasNode("herfkmdx"));
    DataNode foundChild1 = foundNode.getNode("herfkmdx");
    assertNotNull(foundChild1.getId());
    assertEquals(newChild1.getName(), foundChild1.getName());
    assertEquals(newChild1.getProperty("sdfs"), foundChild1.getProperty("sdfs"));
    assertEquals(newChild1.getProperty("ks3"), foundChild1.getProperty("ks3"));
    assertEquals(newChild1.getProperty("ids32"), foundChild1.getProperty("ids32"));
    assertEquals(newChild1.getProperty("erere3"), foundChild1.getProperty("erere3"));
    assertEquals(newChild1.getProperty("tttss4"), foundChild1.getProperty("tttss4"));
    assertEquals(newChild1.getProperty("urei2"), foundChild1.getProperty("urei2"));
    try {
        repo.deleteFile(sampleFile.getId(), true, null);
        fail();
    } catch (UnifiedRepositoryException e) {
    // should fail due to referential integrity (newFile payload has reference to sampleFile)
    }
    actualPropCount = 0;
    for (DataProperty prop : newChild1.getProperties()) {
        actualPropCount++;
    }
    assertEquals(6, actualPropCount);
    assertTrue(foundNode.hasNode(JcrStringHelper.fileNameEncode("pppq/qqs2")));
    DataNode foundChild2 = foundNode.getNode(JcrStringHelper.fileNameEncode("pppq/qqs2"));
    assertNotNull(foundChild2.getId());
    assertEquals(newChild2.getName(), foundChild2.getName());
    assertEquals(newChild2.getProperty(JcrStringHelper.fileNameEncode("ttt:ss4")), foundChild2.getProperty(JcrStringHelper.fileNameEncode("ttt:ss4")));
    actualPropCount = 0;
    for (DataProperty prop : foundChild2.getProperties()) {
        actualPropCount++;
    }
    assertEquals(1, actualPropCount);
    // ordering
    int i = 0;
    for (DataNode currentNode : foundNode.getNodes()) {
        if (i++ == 0) {
            assertEquals(newChild1.getName(), currentNode.getName());
        } else {
            assertEquals(newChild2.getName(), currentNode.getName());
        }
    }
}
Also used : DataNodeRef(org.pentaho.platform.api.repository2.unified.data.node.DataNodeRef) ITenant(org.pentaho.platform.api.mt.ITenant) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DataProperty(org.pentaho.platform.api.repository2.unified.data.node.DataProperty) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) Test(org.junit.Test)

Example 12 with UnifiedRepositoryException

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

the class DefaultUnifiedRepositoryContentIT method testUndeleteFile.

@Test
public void testUndeleteFile() throws Exception {
    Date testBegin = new Date();
    Thread.sleep(1000);
    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);
    userRoleDao.createUser(tenantAcme, USERNAME_TIFFANY, PASSWORD, "", null);
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName());
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    final String fileName = "helloworld.sample";
    RepositoryFile newFile = createSampleFile(parentFolderPath, fileName, "dfdfd", true, 3, true);
    List<RepositoryFile> deletedFiles = repo.getDeletedFiles();
    assertEquals(0, deletedFiles.size());
    repo.deleteFile(newFile.getId(), null);
    deletedFiles = repo.getDeletedFiles();
    assertEquals(1, deletedFiles.size());
    deletedFiles = repo.getDeletedFiles(parentFolder.getPath());
    assertEquals(1, deletedFiles.size());
    assertTrue(testBegin.before(deletedFiles.get(0).getDeletedDate()));
    assertEquals(parentFolder.getPath(), deletedFiles.get(0).getOriginalParentFolderPath());
    assertEquals(newFile.getId(), deletedFiles.get(0).getId());
    deletedFiles = repo.getDeletedFiles(parentFolder.getPath(), "*.sample");
    assertEquals(1, deletedFiles.size());
    assertTrue(testBegin.before(deletedFiles.get(0).getDeletedDate()));
    assertEquals(parentFolder.getPath(), deletedFiles.get(0).getOriginalParentFolderPath());
    deletedFiles = repo.getDeletedFiles(parentFolder.getPath(), "*.doesnotexist");
    assertEquals(0, deletedFiles.size());
    deletedFiles = repo.getDeletedFiles();
    assertEquals(1, deletedFiles.size());
    assertEquals(parentFolder.getPath(), deletedFiles.get(0).getOriginalParentFolderPath());
    assertTrue(testBegin.before(deletedFiles.get(0).getDeletedDate()));
    assertEquals(newFile.getId(), deletedFiles.get(0).getId());
    login(USERNAME_TIFFANY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    // tiffany shouldn't see suzy's deleted file
    assertEquals(0, repo.getDeletedFiles().size());
    login(USERNAME_SUZY, tenantAcme, new String[] { tenantAuthenticatedRoleName });
    repo.undeleteFile(newFile.getId(), null);
    assertEquals(0, repo.getDeletedFiles(parentFolder.getPath()).size());
    assertEquals(0, repo.getDeletedFiles().size());
    newFile = repo.getFileById(newFile.getId());
    // next two fields only populated when going through the delete-related API calls
    assertNull(newFile.getDeletedDate());
    assertNull(newFile.getOriginalParentFolderPath());
    repo.deleteFile(newFile.getId(), null);
    // permanent delete
    repo.deleteFile(newFile.getId(), true, null);
    try {
        repo.undeleteFile(newFile.getId(), null);
        fail();
    } catch (UnifiedRepositoryException e) {
    // ignore
    }
    // test preservation of original path even if that path no longer exists
    RepositoryFile publicFolder = repo.getFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()));
    RepositoryFile test1Folder = repo.createFolder(publicFolder.getId(), new RepositoryFile.Builder("test1").folder(true).build(), null);
    newFile = createSampleFile(test1Folder.getPath(), fileName, "dfdfd", true, 3);
    repo.deleteFile(newFile.getId(), null);
    assertNull(repo.getFile("/home/suzy/test1/helloworld.sample"));
    // rename original parent folder
    repo.moveFile(test1Folder.getId(), ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()) + RepositoryFile.SEPARATOR + "test2", null);
    assertNull(repo.getFile(test1Folder.getPath()));
    repo.undeleteFile(newFile.getId(), null);
    assertNotNull(repo.getFile("/home/suzy/test1/helloworld.sample"));
    // repo should create any missing folders
    assertNull(repo.getFile("/home/suzy/test2/helloworld.sample"));
    // on undelete
    assertEquals("/home/suzy/test1/helloworld.sample", repo.getFileById(newFile.getId()).getPath());
    // test versioned parent folder
    RepositoryFile test5Folder = repo.createFolder(publicFolder.getId(), new RepositoryFile.Builder("test5").folder(true).versioned(true).build(), null);
    int versionCountBefore = repo.getVersionSummaries(test5Folder.getId()).size();
    RepositoryFile newFile5 = createSampleFile(test5Folder.getPath(), fileName, "dfdfd", true, 3);
    repo.deleteFile(newFile5.getId(), null);
    assertTrue(repo.getVersionSummaries(test5Folder.getId()).size() > versionCountBefore);
    versionCountBefore = repo.getVersionSummaries(test5Folder.getId()).size();
    repo.undeleteFile(newFile5.getId(), null);
    assertTrue(repo.getVersionSummaries(test5Folder.getId()).size() > versionCountBefore);
    // test permanent delete without undelete
    RepositoryFile newFile6 = createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()), fileName, "dfdfd", true, 3);
    repo.deleteFile(newFile6.getId(), true, null);
    // test undelete where path to restored file already exists
    RepositoryFile newFile7 = createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()), fileName, "dfdfd", true, 3);
    repo.deleteFile(newFile7.getId(), null);
    createSampleFile(ClientRepositoryPaths.getUserHomeFolderPath(PentahoSessionHolder.getSession().getName()), fileName, "dfdfd", true, 3);
    try {
        repo.undeleteFile(newFile7.getId(), null);
        fail();
    } catch (UnifiedRepositoryException e) {
        e.printStackTrace();
    }
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) Test(org.junit.Test)

Example 13 with UnifiedRepositoryException

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

the class DefaultUnifiedRepositoryContentIT method testTransactionRollback.

/**
 * Create a versioned file then update it with invalid data and the checkout that we did before setting the data
 * should be rolled back.
 */
@Test
public void testTransactionRollback() 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 expectedName = "helloworld.sample";
    final String sampleString = "Ciao World!";
    final boolean sampleBoolean = true;
    final int sampleInteger = 99;
    final String parentFolderPath = ClientRepositoryPaths.getUserHomeFolderPath(USERNAME_SUZY);
    final String expectedAbsolutePath = ServerRepositoryPaths.getTenantRootFolderPath() + parentFolderPath + RepositoryFile.SEPARATOR + expectedName;
    RepositoryFile newFile = createSampleFile(parentFolderPath, expectedName, sampleString, sampleBoolean, sampleInteger, true);
    assertNotNull(SimpleJcrTestUtils.getItem(testJcrTemplate, expectedAbsolutePath));
    try {
        repo.updateFile(newFile, new IRepositoryFileData() {

            @Override
            public long getDataSize() {
                return 0;
            }
        }, null);
        fail("expected UnifiedRepositoryException");
    } catch (UnifiedRepositoryException e) {
    // ignore
    }
    assertFalse(SimpleJcrTestUtils.isCheckedOut(testJcrTemplate, expectedAbsolutePath));
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) ITenant(org.pentaho.platform.api.mt.ITenant) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 14 with UnifiedRepositoryException

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

the class DefaultUnifiedRepositoryVersioningIT method testCreateVersionedFile.

@Test
public void testCreateVersionedFile() 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);
    RepositoryFile parentFolder = repo.getFile(parentFolderPath);
    final String dataString = "Hello World!";
    final String encoding = "UTF-8";
    byte[] data = dataString.getBytes(encoding);
    ByteArrayInputStream dataStream = new ByteArrayInputStream(data);
    final String mimeType = "text/plain";
    final String fileName = "helloworld.xaction";
    final SimpleRepositoryFileData content = new SimpleRepositoryFileData(dataStream, encoding, mimeType);
    RepositoryFile newFile = repo.createFile(parentFolder.getId(), new RepositoryFile.Builder(fileName).versioned(true).build(), content, null);
    assertTrue(newFile.isVersioned());
    assertNotNull(newFile.getVersionId());
    final String filePath = ServerRepositoryPaths.getUserHomeFolderPath(tenantAcme, USERNAME_SUZY) + RepositoryFile.SEPARATOR + fileName;
    int versionCount = SimpleJcrTestUtils.getVersionCount(testJcrTemplate, filePath);
    assertTrue(versionCount > 0);
    repo.updateFile(newFile, content, null);
    try {
        repo.updateFile(newFile, content, null);
        fail();
    } catch (UnifiedRepositoryException e) {
    // ignore
    }
    assertTrue(SimpleJcrTestUtils.getVersionCount(testJcrTemplate, filePath) > versionCount);
}
Also used : ITenant(org.pentaho.platform.api.mt.ITenant) ByteArrayInputStream(java.io.ByteArrayInputStream) SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 15 with UnifiedRepositoryException

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

the class JcrBackedDatasourceMgmtService method getDatasourceIds.

public List<String> getDatasourceIds() throws DatasourceMgmtServiceException {
    try {
        List<String> datasourceList = new ArrayList<String>();
        List<RepositoryFile> repositoryFiles = getRepositoryFiles();
        if (repositoryFiles != null) {
            for (RepositoryFile file : repositoryFiles) {
                datasourceList.add(file.getId().toString());
            }
        }
        return datasourceList;
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", ure.getLocalizedMessage()), // $NON-NLS-1$ //$NON-NLS-2$
        ure);
    }
}
Also used : ArrayList(java.util.ArrayList) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Aggregations

UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)31 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)26 Test (org.junit.Test)12 ITenant (org.pentaho.platform.api.mt.ITenant)9 IOException (java.io.IOException)7 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)7 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)7 File (java.io.File)6 FileNotFoundException (java.io.FileNotFoundException)6 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)6 ByteArrayInputStream (java.io.ByteArrayInputStream)5 Matchers.anyString (org.mockito.Matchers.anyString)5 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)5 RepositoryFileSid (org.pentaho.platform.api.repository2.unified.RepositoryFileSid)4 FileOutputStream (java.io.FileOutputStream)3 Serializable (java.io.Serializable)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2