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);
}
}
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);
}
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);
}
}
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;
}
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);
}
Aggregations