Search in sources :

Example 41 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtService method getDatasources.

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()), // $NON-NLS-1$ //$NON-NLS-2$
        ure);
    }
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) ArrayList(java.util.ArrayList) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 42 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.

the class JcrBackedDatasourceMgmtService method createDatasource.

public String createDatasource(IDatabaseConnection databaseConnection) throws DuplicateDatasourceException, DatasourceMgmtServiceException {
    try {
        // IPasswordService passwordService = PentahoSystem.get(IPasswordService.class,
        // PentahoSessionHolder.getSession());
        // databaseMeta.setPassword(passwordService.encrypt(databaseMeta.getPassword()));
        RepositoryFile file = new RepositoryFile.Builder(RepositoryFilenameUtils.escape(databaseConnection.getName() + RepositoryObjectType.DATABASE.getExtension(), cachedReservedChars)).title(RepositoryFile.DEFAULT_LOCALE, databaseConnection.getName()).versioned(true).build();
        file = repository.createFile(getDatabaseParentFolderId(), file, new NodeRepositoryFileData(databaseHelper.databaseConnectionToDataNode(databaseConnection)), null);
        if (file != null && file.getId() != null) {
            return file.getId().toString();
        } else {
            return null;
        }
    // } catch(PasswordServiceException pse) {
    // throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString(
    // "DatasourceMgmtService.ERROR_0007_UNABLE_TO_ENCRYPT_PASSWORD"), pse ); //$NON-NLS-1$
    } catch (UnifiedRepositoryException ure) {
        if (ure.getCause().toString().contains("ItemExistsException")) {
            throw new DuplicateDatasourceException();
        }
        throw new DatasourceMgmtServiceException(Messages.getInstance().getErrorString("DatasourceMgmtService.ERROR_0001_UNABLE_TO_CREATE_DATASOURCE", databaseConnection.getName(), ure.getLocalizedMessage()), // $NON-NLS-1$
        ure);
    }
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DuplicateDatasourceException(org.pentaho.platform.api.repository.datasource.DuplicateDatasourceException) 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 43 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.

the class FileSystemRepositoryFileDao method updateFile.

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());
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IOException(java.io.IOException) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 44 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.

the class FileSystemRepositoryFileDao method createFile.

public RepositoryFile createFile(Serializable parentFolderId, RepositoryFile file, IRepositoryFileData data, RepositoryFileAcl acl, String versionMessage) {
    String fileNameWithPath = RepositoryFilenameUtils.concat(parentFolderId.toString(), file.getName());
    FileOutputStream fos = null;
    File f = new File(fileNameWithPath);
    try {
        f.createNewFile();
        fos = new FileOutputStream(f);
        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("Error writing file [" + fileNameWithPath + "]", e);
    } catch (IOException e) {
        throw new UnifiedRepositoryException("Error writing file [" + fileNameWithPath + "]", e);
    } finally {
        IOUtils.closeQuietly(fos);
    }
    return internalGetFile(f);
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) IOException(java.io.IOException) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 45 with NodeRepositoryFileData

use of org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData in project pentaho-platform by pentaho.

the class UnifiedRepositoryTestUtils method stubGetData.

/**
 * Stubs a {@code getDataForRead} call. The pairs specified will be used to construct a
 * {@code NodeRepositoryFileData} .
 */
public static void stubGetData(final IUnifiedRepository repo, final String path, final String rootNodeName, final PathPropertyPair... pairs) {
    final String prefix = RepositoryFile.SEPARATOR + rootNodeName;
    DataNode rootNode = new DataNode(rootNodeName);
    for (PathPropertyPair pair : pairs) {
        if (!pair.getPath().startsWith(prefix)) {
            throw new IllegalArgumentException("all paths must have a common prefix");
        }
        String[] pathSegments = pair.getPath().substring(prefix.length() + 1).split("/");
        addChild(rootNode, pair.getProperty(), pathSegments, 0);
    }
    doReturn(new NodeRepositoryFileData(rootNode)).when(repo).getDataForRead(makeIdObject(path), NodeRepositoryFileData.class);
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)

Aggregations

NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)46 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)36 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)22 KettleException (org.pentaho.di.core.exception.KettleException)14 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)11 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)11 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)10 KettleFileException (org.pentaho.di.core.exception.KettleFileException)10 KettleSecurityException (org.pentaho.di.core.exception.KettleSecurityException)10 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)10 UnifiedRepositoryCreateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryCreateFileException)10 UnifiedRepositoryUpdateFileException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryUpdateFileException)10 Test (org.junit.Test)9 Matchers.anyString (org.mockito.Matchers.anyString)7 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)7 ITenant (org.pentaho.platform.api.mt.ITenant)6 StringObjectId (org.pentaho.di.repository.StringObjectId)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ArrayList (java.util.ArrayList)4 Date (java.util.Date)4