Search in sources :

Example 86 with RepositoryFile

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

the class MondrianCatalogRepositoryHelper method getOlap4jServers.

/**
 * Provides a list of the catalog names which are not hosted on this server.
 * (generic olap4j connections)
 */
public List<String> getOlap4jServers() {
    final RepositoryFile hostedFolder = repository.getFile(ETC_OLAP_SERVERS_JCR_FOLDER);
    if (hostedFolder == null) {
        // The folder gets created in addOlap4jServer
        return Collections.emptyList();
    }
    final List<String> names = new ArrayList<String>();
    for (RepositoryFile repoFile : repository.getChildren(hostedFolder.getId())) {
        names.add(repoFile.getName());
    }
    return names;
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 87 with RepositoryFile

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

the class MondrianCatalogRepositoryHelper method addHostedCatalog.

public void addHostedCatalog(InputStream mondrianFile, String catalogName, String datasourceInfo) throws Exception {
    RepositoryFile catalog = createCatalog(catalogName, datasourceInfo);
    File tempFile = File.createTempFile("tempFile", null);
    tempFile.deleteOnExit();
    FileOutputStream outputStream = new FileOutputStream(tempFile);
    IOUtils.copy(mondrianFile, outputStream);
    RepositoryFile repoFile = new RepositoryFile.Builder("schema.xml").build();
    org.pentaho.platform.plugin.services.importexport.RepositoryFileBundle repoFileBundle = new org.pentaho.platform.plugin.services.importexport.RepositoryFileBundle(repoFile, null, ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName + RepositoryFile.SEPARATOR, tempFile, "UTF-8", "text/xml");
    RepositoryFile schema = repository.getFile(ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName + RepositoryFile.SEPARATOR + "schema.xml");
    IRepositoryFileData data = new StreamConverter().convert(repoFileBundle.getInputStream(), repoFileBundle.getCharset(), repoFileBundle.getMimeType());
    if (schema == null) {
        RepositoryFile schemaFile = repository.createFile(catalog.getId(), repoFileBundle.getFile(), data, null);
        if (schemaFile != null) {
            // make sure the folder is not set to hidden if the schema is not hidden
            RepositoryFile catalogFolder = repository.getFile(ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName);
            if (catalogFolder.isHidden() != schemaFile.isHidden()) {
                RepositoryFile unhiddenFolder = (new RepositoryFile.Builder(catalogFolder)).hidden(schemaFile.isHidden()).build();
                repository.updateFolder(unhiddenFolder, "");
            }
        }
    } else {
        repository.updateFile(schema, data, null);
    }
}
Also used : IRepositoryFileData(org.pentaho.platform.api.repository2.unified.IRepositoryFileData) FileOutputStream(java.io.FileOutputStream) StreamConverter(org.pentaho.platform.plugin.services.importexport.StreamConverter) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 88 with RepositoryFile

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

the class MondrianCatalogRepositoryHelper method getModrianSchemaFiles.

public Map<String, InputStream> getModrianSchemaFiles(String catalogName) {
    Map<String, InputStream> values = new HashMap<String, InputStream>();
    RepositoryFile catalogFolder = repository.getFile(ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalogName);
    if (catalogFolder == null) {
        logger.warn("Catalog " + catalogName + " not found");
        throw new RepositoryException("Catalog " + catalogName + " not found");
    }
    for (RepositoryFile repoFile : repository.getChildren(catalogFolder.getId())) {
        RepositoryFileInputStream is;
        if (repoFile.getName().equals("metadata")) {
            continue;
        }
        try {
            is = new RepositoryFileInputStream(repoFile, repository);
        } catch (FileNotFoundException e) {
            throw new RepositoryException(e);
        }
        values.put(repoFile.getName(), is);
    }
    if (values.containsKey(ANNOTATIONS_XML) && values.containsKey(SCHEMA_XML)) {
        return includeAnnotatedSchema(values);
    }
    return values;
}
Also used : HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) RepositoryException(org.pentaho.platform.api.repository.RepositoryException) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream)

Example 89 with RepositoryFile

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

the class MondrianCatalogRepositoryHelper method getHostedCatalogs.

/**
 * Provides a list of the catalog names hosted locally on this server.
 */
public List<String> getHostedCatalogs() {
    final List<String> names = new ArrayList<String>();
    final RepositoryFile serversFolder = repository.getFile(ETC_MONDRIAN_JCR_FOLDER);
    if (serversFolder != null) {
        for (RepositoryFile repoFile : repository.getChildren(serversFolder.getId())) {
            names.add(repoFile.getName());
        }
    }
    return names;
}
Also used : ArrayList(java.util.ArrayList) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile)

Example 90 with RepositoryFile

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

the class MondrianCatalogRepositoryHelper method createDatasourceMetadata.

/*
   * Creates "/etc/mondrian/<catalog>/metadata" and the connection nodes
   */
private void createDatasourceMetadata(RepositoryFile catalog, String datasourceInfo) {
    final String path = ETC_MONDRIAN_JCR_FOLDER + RepositoryFile.SEPARATOR + catalog.getName() + RepositoryFile.SEPARATOR + "metadata";
    RepositoryFile metadata = repository.getFile(path);
    String definition = "mondrian:/" + catalog.getName();
    DataNode node = new DataNode("catalog");
    node.setProperty("definition", encodeUrl(definition));
    node.setProperty("datasourceInfo", datasourceInfo);
    NodeRepositoryFileData data = new NodeRepositoryFileData(node);
    if (metadata == null) {
        repository.createFile(catalog.getId(), new RepositoryFile.Builder("metadata").build(), data, null);
    } else {
        repository.updateFile(metadata, data, null);
    }
}
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)

Aggregations

RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)455 Test (org.junit.Test)183 ITenant (org.pentaho.platform.api.mt.ITenant)87 Matchers.anyString (org.mockito.Matchers.anyString)86 ArrayList (java.util.ArrayList)85 RepositoryFileAcl (org.pentaho.platform.api.repository2.unified.RepositoryFileAcl)83 Serializable (java.io.Serializable)56 IUnifiedRepository (org.pentaho.platform.api.repository2.unified.IUnifiedRepository)53 SimpleRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData)49 KettleException (org.pentaho.di.core.exception.KettleException)40 NodeRepositoryFileData (org.pentaho.platform.api.repository2.unified.data.node.NodeRepositoryFileData)40 ByteArrayInputStream (java.io.ByteArrayInputStream)39 UnifiedRepositoryException (org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)39 IOException (java.io.IOException)37 File (java.io.File)34 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)34 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)33 MetaStoreNamespaceExistsException (org.pentaho.metastore.api.exceptions.MetaStoreNamespaceExistsException)33 IdNotFoundException (org.pentaho.di.core.exception.IdNotFoundException)32 KettleFileException (org.pentaho.di.core.exception.KettleFileException)32