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