Search in sources :

Example 16 with UnifiedRepositoryException

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

the class JcrBackedDatasourceMgmtService method updateDatasource.

private String updateDatasource(RepositoryFile file, IDatabaseConnection databaseConnection) throws NonExistingDatasourceException, DatasourceMgmtServiceException {
    try {
        if (file != null) {
            file = new RepositoryFile.Builder(file).versionId(file.getVersionId()).id(file.getId()).title(RepositoryFile.DEFAULT_LOCALE, databaseConnection.getName()).build();
            file = repository.updateFile(file, new NodeRepositoryFileData(databaseHelper.databaseConnectionToDataNode(databaseConnection)), null);
            renameIfNecessary(databaseConnection, file);
            return file.getId().toString();
        } else {
            throw new NonExistingDatasourceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0006_DATASOURCE_DOES_NOT_EXIST", // $NON-NLS-1$
            databaseConnection.getName()));
        }
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance()
    // .getErrorString("DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0003_UNABLE_TO_UPDATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
}
Also used : NonExistingDatasourceException(org.pentaho.platform.api.repository.datasource.NonExistingDatasourceException) 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) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 17 with UnifiedRepositoryException

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

the class JcrBackedDatasourceMgmtService method deleteDatasourceById.

public void deleteDatasourceById(String id) throws NonExistingDatasourceException, DatasourceMgmtServiceException {
    RepositoryFile fileToDelete = null;
    try {
        fileToDelete = repository.getFileById(id);
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0002_UNABLE_TO_DELETE_DATASOURCE", fileToDelete.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
    deleteDatasource(fileToDelete);
}
Also used : UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 18 with UnifiedRepositoryException

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

the class JcrBackedDatasourceMgmtService method getDatasource.

private IDatabaseConnection getDatasource(RepositoryFile file) throws DatasourceMgmtServiceException {
    try {
        if (file != null) {
            NodeRepositoryFileData data = repository.getDataForRead(file.getId(), NodeRepositoryFileData.class);
            IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection(file.getId(), file.getTitle(), data.getNode());
            // databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword()));
            return databaseConnection;
        } else {
            throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", "", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            ""));
        }
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance()
    // .getErrorString("DatasourceMgmtService.ERROR_0008_UNABLE_TO_DECRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } catch (UnifiedRepositoryException ure) {
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", file.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 19 with UnifiedRepositoryException

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

the class JcrBackedDatasourceMgmtService method getDatabaseParentFolderId.

private Serializable getDatabaseParentFolderId() {
    if (cachedDatabaseParentFolderId == null) {
        try {
            RepositoryFile f = repository.getFile(getDatabaseParentFolderPath());
            cachedDatabaseParentFolderId = f.getId();
        } catch (UnifiedRepositoryException ure) {
            return cachedDatabaseParentFolderId;
        }
    }
    return cachedDatabaseParentFolderId;
}
Also used : UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 20 with UnifiedRepositoryException

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

the class MDXBaseComponentTest method shouldUseUnifiedRepositoryWhenCheckingFileExistence.

@Test
@SuppressWarnings("unchecked")
public void shouldUseUnifiedRepositoryWhenCheckingFileExistence() throws ObjectFactoryException {
    PentahoSystem.registerPrimaryObjectFactory(objFactory);
    PentahoSessionHolder.setSession(session);
    IUnifiedRepository repository = mock(IUnifiedRepository.class);
    when(objFactory.objectDefined("IUnifiedRepository")).thenReturn(true);
    when(objFactory.get(any(Class.class), eq("IUnifiedRepository"), any(IPentahoSession.class))).thenReturn(repository);
    doCallRealMethod().when(mdxBaseComponent).fileExistsInRepository(anyString());
    RepositoryFile file = mock(RepositoryFile.class);
    doReturn(file).when(repository).getFile("fileNameExisting");
    doReturn(null).when(repository).getFile("fileNameNonExisting");
    // checking bad file name for pentaho repository, e.g. windows os file names
    doThrow(new UnifiedRepositoryException()).when(repository).getFile("fileNameBad");
    boolean fileExists = mdxBaseComponent.fileExistsInRepository("fileNameExisting");
    assertTrue(fileExists);
    boolean fileDoesNotExist = mdxBaseComponent.fileExistsInRepository("fileNameNonExisting");
    assertFalse(fileDoesNotExist);
    boolean fileBad = mdxBaseComponent.fileExistsInRepository("fileNameBad");
    assertFalse(fileBad);
}
Also used : IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) Test(org.junit.Test)

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