Search in sources :

Example 46 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 47 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 48 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)

Example 49 with NodeRepositoryFileData

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

the class JcrBackedDatasourceMgmtServiceTest method testgetDatasourceById.

private void testgetDatasourceById(boolean throwException) throws Exception {
    final String dotKdb = ".kdb";
    IUnifiedRepository repo = mock(IUnifiedRepository.class);
    NodeRepositoryFileData nodeRep = mock(NodeRepositoryFileData.class);
    DataNode dataNode = mock(DataNode.class);
    // stub out get parent folder
    doReturn(new RepositoryFile.Builder("123", "databases").folder(true).build()).when(repo).getFileById(EXP_FILE_ID);
    doReturn(reservedChars).when(repo).getReservedChars();
    // stub out get file to delete
    doReturn(new RepositoryFile.Builder(EXP_FILE_ID, EXP_DBMETA_NAME + dotKdb).build()).when(repo).getFileById(EXP_FILE_ID);
    doReturn(nodeRep).when(repo).getDataForRead(any(), any());
    doReturn(dataNode).when(nodeRep).getNode();
    IDatasourceMgmtService datasourceMgmtService = new JcrBackedDatasourceMgmtService(repo, new DatabaseDialectService());
    if (throwException) {
        getDatasourceWithIdThrowException(repo);
    }
    assertNotNull(datasourceMgmtService.getDatasourceById(EXP_FILE_ID));
}
Also used : NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) DatabaseDialectService(org.pentaho.database.service.DatabaseDialectService) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) IUnifiedRepository(org.pentaho.platform.api.repository2.unified.IUnifiedRepository) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)

Example 50 with NodeRepositoryFileData

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

the class MondrianCatalogRepositoryHelper method addOlap4jServer.

public void addOlap4jServer(String name, String className, String URL, String user, String password, Properties props) {
    final RepositoryFile etcOlapServers = repository.getFile(ETC_OLAP_SERVERS_JCR_FOLDER);
    RepositoryFile entry = repository.getFile(ETC_OLAP_SERVERS_JCR_FOLDER + RepositoryFile.SEPARATOR + name);
    if (entry == null) {
        entry = repository.createFolder(etcOlapServers.getId(), new RepositoryFile.Builder(name).folder(true).build(), "Creating entry for olap server: " + name + " into folder " + ETC_OLAP_SERVERS_JCR_FOLDER);
    }
    final String path = ETC_OLAP_SERVERS_JCR_FOLDER + RepositoryFile.SEPARATOR + name + RepositoryFile.SEPARATOR + "metadata";
    // Convert the properties to a serializable XML format.
    final String xmlProperties;
    final ByteArrayOutputStream os = new ByteArrayOutputStream();
    try {
        props.storeToXML(os, "Connection properties for server: " + name, "UTF-8");
        xmlProperties = os.toString("UTF-8");
    } catch (IOException e) {
        // Very bad. Just throw.
        throw new RuntimeException(e);
    } finally {
        try {
            os.close();
        } catch (IOException e) {
        // Don't care. Just cleaning up.
        }
    }
    final DataNode node = new DataNode("server");
    node.setProperty("name", name);
    node.setProperty("className", className);
    node.setProperty("URL", URL);
    node.setProperty("user", user);
    node.setProperty("password", password);
    node.setProperty("properties", xmlProperties);
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    final RepositoryFile metadata = repository.getFile(path);
    if (metadata == null) {
        repository.createFile(entry.getId(), new RepositoryFile.Builder("metadata").build(), data, "Creating olap-server metadata for server " + name);
    } else {
        repository.updateFile(metadata, data, "Updating olap-server metadata for server " + name);
    }
}
Also used : DataNode(org.pentaho.platform.api.repository2.unified.data.node.DataNode) NodeRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException)

Aggregations

NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)48 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)38 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)24 KettleException (org.pentaho.di.core.exception.KettleException)14 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)11 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)11 URISyntaxException (java.net.URISyntaxException)10 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 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Date (java.util.Date)5