use of org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper in project data-access by pentaho.
the class ModelerService method serializeModels.
public String serializeModels(final Domain domain, final String name, final boolean doOlap) throws Exception {
String domainId = null;
initKettle();
if (dataAccessPermHandler.hasDataAccessPermission(PentahoSessionHolder.getSession())) {
SecurityHelper.getInstance().runAsSystem(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
if (datasourceService == null) {
datasourceService = new DSWDatasourceServiceImpl();
}
ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), datasourceService.getGeoContext());
model.setModelName(name);
model.setDomain(domain);
if (name.endsWith(".xmi")) {
domain.setId(name);
} else {
domain.setId(name + ".xmi");
}
LogicalModel lModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (lModel == null) {
lModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
lModel.setProperty("AGILE_BI_GENERATED_SCHEMA", "TRUE");
lModel.setProperty("WIZARD_GENERATED_SCHEMA", "TRUE");
String catName = lModel.getName(Locale.getDefault().toString());
// strip off the _olap suffix for the catalog ref
catName = catName.replace(BaseModelerWorkspaceHelper.OLAP_SUFFIX, "");
if (doOlap) {
// $NON-NLS-1$
lModel.setProperty("MondrianCatalogRef", catName);
}
// Stores metadata into JCR.
IMetadataDomainRepository metadataDomainRep = PentahoSystem.get(IMetadataDomainRepository.class);
if (metadataDomainRep != null) {
metadataDomainRep.storeDomain(model.getDomain(), true);
}
// Serialize domain to olap schema.
if (doOlap) {
MondrianModelExporter exporter = new MondrianModelExporter(lModel, Locale.getDefault().toString());
String mondrianSchema = exporter.createMondrianModelXML();
IPentahoSession session = PentahoSessionHolder.getSession();
if (session != null) {
// first remove the existing schema, including any
// model annotations which may have been previously applied
IMondrianCatalogService mondrianCatalogService = // $NON-NLS-1$
PentahoSystem.get(IMondrianCatalogService.class, "IMondrianCatalogService", session);
// try to get the current catalog
MondrianCatalog currentCatalog = mondrianCatalogService.getCatalog(catName, session);
// if current catalog exists, remove it
if (currentCatalog != null) {
mondrianCatalogService.removeCatalog(catName, session);
}
session.setAttribute("MONDRIAN_SCHEMA_XML_CONTENT", mondrianSchema);
// $NON-NLS-1$
String catConnectStr = "Provider=mondrian;DataSource=\"" + getMondrianDatasource(domain) + "\"";
addCatalog(catName, catConnectStr, session);
}
}
} catch (Exception e) {
logger.error(e);
throw e;
}
return null;
}
});
}
return domainId;
}
Aggregations