@SuppressWarnings( "unchecked" ) public <T extends IRepositoryFileData> T getData( Serializable fileId, Serializable versionId, Class<T> dataClass ) { File f = new File( fileId.toString() ); T data = null; try { if ( SimpleRepositoryFileData.class.getName().equals( dataClass.getName() ) ) { data = (T) new SimpleRepositoryFileData( new FileInputStream( f ), "UTF-8", "text/plain" ); } else if ( NodeRepositoryFileData.class.getName().equals( dataClass.getName() ) ) { throw new UnsupportedOperationException( "This operation is not support by this repository" ); } } catch ( FileNotFoundException e ) { throw new UnifiedRepositoryException( e ); } return data; }
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() ), ure ); //$NON-NLS-1$ //$NON-NLS-2$ } }
@Override public String getMessage() { return PREFIX + ": " + super.getMessage(); }
if ( ure.getCause().toString().contains( "ItemExistsException" ) ) { throw new DuplicateDatasourceException(); .getInstance() .getErrorString( "DatasourceMgmtService.ERROR_0001_UNABLE_TO_CREATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage() ), ure ); //$NON-NLS-1$
public RepositoryFile createFolder( Serializable parentFolderId, RepositoryFile file, RepositoryFileAcl acl, String versionMessage ) { try { String folderNameWithPath = parentFolderId + "/" + file.getName(); File newFolder = new File( folderNameWithPath ); newFolder.mkdir(); final RepositoryFile repositoryFolder = internalGetFile( newFolder ); return repositoryFolder; } catch ( Throwable th ) { throw new UnifiedRepositoryException(); } }
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 != null ? fileToDelete.getName() : id, ure.getLocalizedMessage() ), ure ); //$NON-NLS-1$ } deleteDatasource( fileToDelete ); }
@Override public String getMessage() { return PREFIX + ": " + super.getMessage(); }
fos.write( data.toString().getBytes() ); } catch ( FileNotFoundException e ) { throw new UnifiedRepositoryException( "Error writing file metadata [" + fileId + "]", e ); } catch ( IOException e ) { throw new UnifiedRepositoryException( "Error writing file metadata [" + fileId + "]", e ); } finally { IOUtils.closeQuietly( fos );
public IDatabaseConnection getDatasourceByName( String name ) throws DatasourceMgmtServiceException { RepositoryFile file = null; try { file = repository.getFile( getPath( name ) ); } catch ( UnifiedRepositoryException ure ) { throw new DatasourceMgmtServiceException( Messages.getInstance().getErrorString( "DatasourceMgmtService.ERROR_0004_UNABLE_TO_RETRIEVE_DATASOURCE", name, ure.getLocalizedMessage() ), ure ); //$NON-NLS-1$ } if ( file != null ) { return getDatasource( file ); } return null; }
public FileRecord getFileById( final Serializable fileId ) { FileRecord r = idMap.get( fileId ); if ( r == null ) { throw new UnifiedRepositoryException( String.format( "file id [%s] does not exist", fileId ) ); } return r; }
public String updateDatasourceById( String id, IDatabaseConnection databaseConnection ) throws NonExistingDatasourceException, DatasourceMgmtServiceException { RepositoryFile file = null; try { file = repository.getFileById( id ); } catch ( UnifiedRepositoryException ure ) { throw new DatasourceMgmtServiceException( Messages .getInstance() .getErrorString( "DatasourceMgmtService.ERROR_0003_UNABLE_TO_UPDATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage() ), ure ); //$NON-NLS-1$ } return updateDatasource( file, databaseConnection ); }
public Map<String, Serializable> getFileMetadata( final Serializable fileId ) { final String metadataFilename = FilenameUtils.concat( FilenameUtils.concat( FilenameUtils.getFullPathNoEndSeparator( fileId.toString() ), ".metadata" ), FilenameUtils.getName( fileId.toString() ) ); final Map<String, Serializable> metadata = new HashMap<String, Serializable>(); BufferedReader reader = null; try { reader = new BufferedReader( new FileReader( metadataFilename ) ); String data = reader.readLine(); while ( data != null ) { final int pos = data.indexOf( '=' ); if ( pos > 0 ) { final String key = data.substring( 0, pos ); final String value = ( data.length() > pos ? data.substring( pos + 1 ) : null ); metadata.put( key, value ); } data = reader.readLine(); } } catch ( FileNotFoundException e ) { // Do nothing ... metadata empty } catch ( IOException e ) { throw new UnifiedRepositoryException( "Error reading metadata [" + fileId + "]", e ); } finally { IOUtils.closeQuietly( reader ); } return metadata; }
public void deleteDatasourceByName( String name ) throws NonExistingDatasourceException, DatasourceMgmtServiceException { RepositoryFile fileToDelete = null; try { fileToDelete = repository.getFile( getPath( name ) ); } catch ( UnifiedRepositoryException ure ) { throw new DatasourceMgmtServiceException( Messages .getInstance() .getErrorString( "DatasourceMgmtService.ERROR_0002_UNABLE_TO_DELETE_DATASOURCE", fileToDelete != null ? fileToDelete.getName() : name, ure.getLocalizedMessage() ), ure ); //$NON-NLS-1$ } deleteDatasource( fileToDelete ); }
public FrozenFileRecord getLatestVersion( final Serializable fileId ) { List<FrozenFileRecord> history = versionMap.get( fileId ); if ( history == null ) { throw new UnifiedRepositoryException( String.format( "version history for [%s] does not exist", fileId ) ); } return history.get( history.size() - 1 ); }
public List<IDatabaseConnection> getDatasources() throws DatasourceMgmtServiceException { try { List<IDatabaseConnection> datasourceList = new ArrayList<IDatabaseConnection>(); List<RepositoryFile> repositoryFiles = getRepositoryFiles(); if ( repositoryFiles != null ) { for ( RepositoryFile file : repositoryFiles ) { NodeRepositoryFileData data = repository.getDataForRead( file.getId(), NodeRepositoryFileData.class ); IDatabaseConnection databaseConnection = databaseHelper.dataNodeToDatabaseConnection( file.getId(), file.getTitle(), data.getNode() ); // IPasswordService passwordService = PentahoSystem.get(IPasswordService.class, // PentahoSessionHolder.getSession()); // databaseMeta.setPassword(passwordService.decrypt(databaseMeta.getPassword())); datasourceList.add( databaseConnection ); } } return datasourceList; // } 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", "", ure.getLocalizedMessage() ), ure ); //$NON-NLS-1$ //$NON-NLS-2$ } }
public FrozenFileRecord getFileAtVersion( final Serializable fileId, final Serializable versionId ) { List<FrozenFileRecord> history = versionMap.get( fileId ); if ( history == null ) { throw new UnifiedRepositoryException( String.format( "version history for [%s] does not exist", fileId ) ); } Integer versionNumber = versionNumber( versionId ); FrozenFileRecord r = history.get( versionNumber ); if ( r == null ) { throw new UnifiedRepositoryException( String.format( "version [%s] does not exist", versionId ) ); } return r; }
private void deleteDatasource( RepositoryFile file ) throws DatasourceMgmtServiceException { try { if ( file != null ) { // Permanently Deletes the File repository.deleteFile( file.getId(), true, null ); } else { throw new DatasourceMgmtServiceException( Messages.getInstance().getErrorString( "DatasourceMgmtService.ERROR_0002_UNABLE_TO_DELETE_DATASOURCE", "", "" ) ); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } catch ( UnifiedRepositoryException ure ) { throw new DatasourceMgmtServiceException( Messages .getInstance() .getErrorString( "DatasourceMgmtService.ERROR_0002_UNABLE_TO_DELETE_DATASOURCE", file.getName(), ure.getLocalizedMessage() ), ure ); //$NON-NLS-1$ } }
public RepositoryFile updateFile( RepositoryFile file, IRepositoryFileData data, String versionMessage ) { File f = new File( file.getId().toString() ); FileOutputStream fos = null; try { fos = new FileOutputStream( f, false ); if ( data instanceof SimpleRepositoryFileData ) { fos.write( inputStreamToBytes( ( (SimpleRepositoryFileData) data ).getInputStream() ) ); } else if ( data instanceof NodeRepositoryFileData ) { fos.write( inputStreamToBytes( new ByteArrayInputStream( ( (NodeRepositoryFileData) data ).getNode().toString() .getBytes() ) ) ); } } catch ( FileNotFoundException e ) { throw new UnifiedRepositoryException( e ); } catch ( IOException e ) { throw new UnifiedRepositoryException( e ); } finally { IOUtils.closeQuietly( fos ); } return getFile( file.getPath() ); }
public String updateDatasourceByName( String name, IDatabaseConnection databaseConnection ) throws NonExistingDatasourceException, DatasourceMgmtServiceException { RepositoryFile file = null; try { if ( databaseConnection.getId() != null ) { file = repository.getFileById( databaseConnection.getId() ); } else { file = repository.getFile( getPath( name ) ); } } catch ( UnifiedRepositoryException ure ) { throw new DatasourceMgmtServiceException( Messages .getInstance() .getErrorString( "DatasourceMgmtService.ERROR_0003_UNABLE_TO_UPDATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage() ), ure ); //$NON-NLS-1$ } return updateDatasource( file, databaseConnection ); }
public List<FrozenFileRecord> getVersions( final Serializable fileId ) { List<FrozenFileRecord> history = versionMap.get( fileId ); if ( history == null ) { throw new UnifiedRepositoryException( String.format( "version history for [%s] does not exist", fileId ) ); } List<FrozenFileRecord> cleanedHistory = new ArrayList<FrozenFileRecord>( history ); for ( Iterator<FrozenFileRecord> iter = cleanedHistory.iterator(); iter.hasNext(); ) { FrozenFileRecord r = iter.next(); if ( r == null ) { iter.remove(); } } return cleanedHistory; }