use of org.pentaho.agilebi.modeler.util.ModelerWorkspaceHelper in project data-access by pentaho.
the class DataSourceWizardService method createMondrianDswBundle.
/**
* Generate a mondrian schema from the model and create the appropriate import bundle
* @param domain domain with olap model
* @return import bundle
* @throws DatasourceServiceException
* @throws Exception If schema generation fails
*/
protected IPlatformImportBundle createMondrianDswBundle(Domain domain, RepositoryFileAclDto acl) throws DatasourceServiceException, DswPublishValidationException, IOException {
final String analysisDomainId = toAnalysisDomainId(domain.getId());
final String dataSource = ModelerService.getMondrianDatasource(domain);
// get olap logical model
final String locale = Locale.getDefault().toString();
ModelerWorkspace workspace = new ModelerWorkspace(new ModelerWorkspaceHelper(locale), dswService.getGeoContext());
workspace.setModelName(analysisDomainId);
workspace.setDomain(domain);
LogicalModel olapModel = workspace.getLogicalModel(ModelerPerspective.ANALYSIS);
if (olapModel == null) {
throw new IllegalArgumentException("No analysis model in xmi.");
}
// reference schema in xmi
olapModel.setProperty(MONDRIAN_CATALOG_REF, analysisDomainId);
// generate schema
MondrianModelExporter exporter = new MondrianModelExporter(olapModel, locale);
exporter.updateModelToNewDomainName(analysisDomainId);
String mondrianSchema = null;
try {
mondrianSchema = exporter.createMondrianModelXML();
} catch (Exception e) {
throw new DswPublishValidationException(Type.INVALID_XMI, e.getMessage());
}
// create bundle
final RepositoryFileImportBundle.Builder builder = new RepositoryFileImportBundle.Builder().input(IOUtils.toInputStream(mondrianSchema, ENCODING)).name(MONDRIAN_SCHEMA_NAME).charSet(ENCODING).overwriteFile(true).mime(MONDRIAN_MIME).withParam(IMPORT_DOMAIN_ID, analysisDomainId).withParam(MONDRIAN_CONNECTION_PARAM, "DataSource=" + dataSource);
if (acl != null) {
builder.acl(repositoryFileAclAdapter.unmarshal(acl)).applyAclSettings(true);
}
return builder.build();
}
Aggregations