use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.
the class DataSourceWizardService method doGetDSWFilesAsDownload.
public Map<String, InputStream> doGetDSWFilesAsDownload(String dswId) throws PentahoAccessControlException {
if (!canManageACL()) {
throw new PentahoAccessControlException();
}
// First get the metadata files;
Map<String, InputStream> fileData = getMetadataFiles(dswId);
// Then get the corresponding mondrian files
Domain domain = metadataDomainRepository.getDomain(dswId);
ModelerWorkspace model = createModelerWorkspace();
model.setDomain(domain);
LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (logicalModel == null) {
logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
MondrianCatalogRepositoryHelper helper = createMondrianCatalogRepositoryHelper();
String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
fileData.putAll(helper.getModrianSchemaFiles(catalogRef));
parseMondrianSchemaNameWrapper(dswId, fileData);
}
return fileData;
}
use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.
the class DataSourceWizardService method removeDSW.
public void removeDSW(String dswId) throws PentahoAccessControlException {
try {
ensureDataAccessPermissionCheck();
} catch (ConnectionServiceException e) {
throw new PentahoAccessControlException();
}
Domain domain = metadataDomainRepository.getDomain(dswId);
ModelerWorkspace model = createModelerWorkspace();
model.setDomain(domain);
LogicalModel logicalModel = model.getLogicalModel(ModelerPerspective.ANALYSIS);
if (logicalModel == null) {
logicalModel = model.getLogicalModel(ModelerPerspective.REPORTING);
}
if (logicalModel.getProperty(MONDRIAN_CATALOG_REF) != null) {
String catalogRef = (String) logicalModel.getProperty(MONDRIAN_CATALOG_REF);
try {
mondrianCatalogService.removeCatalog(catalogRef, getSession());
} catch (MondrianCatalogServiceException e) {
logger.warn("Failed to remove mondrian catalog", e);
}
}
try {
dswService.deleteLogicalModel(domain.getId(), logicalModel.getId());
} catch (DatasourceServiceException ex) {
logger.warn("Failed to remove logical model", ex);
}
metadataDomainRepository.removeDomain(dswId);
}
use of org.pentaho.agilebi.modeler.ModelerWorkspace 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();
}
use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.
the class DebugModelerService method serializeModels.
public String serializeModels(Domain domain, String name) throws Exception {
String domainId;
PentahoSystemHelper.init();
initKettle();
try {
DSWDatasourceServiceImpl datasourceService = new DSWDatasourceServiceImpl();
ModelerWorkspace model = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), datasourceService.getGeoContext());
model.setModelName(name);
model.setDomain(domain);
String solutionStorage = AgileHelper.getDatasourceSolutionStorage();
// $NON-NLS-1$ //$NON-NLS-2$
String metadataLocation = "resources" + RepositoryFile.SEPARATOR + "metadata";
String path = solutionStorage + RepositoryFile.SEPARATOR + metadataLocation + RepositoryFile.SEPARATOR;
// $NON-NLS-1$
domainId = path + name + ".xmi";
IApplicationContext appContext = PentahoSystem.getApplicationContext();
if (appContext != null) {
path = PentahoSystem.getApplicationContext().getSolutionPath(path);
}
File pathDir = new File(path);
if (!pathDir.exists()) {
pathDir.mkdirs();
}
IPentahoSession session = getSession();
// Keep a reference to the mondrian catalog
model.getWorkspaceHelper().populateDomain(model);
LogicalModel lModel = domain.getLogicalModels().get(0);
String catName = lModel.getName(LocalizedString.DEFAULT_LOCALE);
// $NON-NLS-1$
lModel.setProperty("MondrianCatalogRef", catName);
// Serialize domain to xmi.
/*
DISABLED DUE TO USE OF OLD API
String base = PentahoSystem.getApplicationContext().getSolutionRootPath();
String parentPath = ActionInfo.buildSolutionPath(solutionStorage, metadataLocation, ""); //$NON-NLS-1$
int status = repository.publish(base, '/' + parentPath, name + ".xmi", reportXML.getBytes("UTF-8"),
true); //$NON-NLS-1$ //$NON-NLS-2$
if (status != ISolutionRepository.FILE_ADD_SUCCESSFUL) {
throw new RuntimeException("Unable to save to repository. Status: " + status); //$NON-NLS-1$
}
// Serialize domain to olap schema.
lModel = domain.getLogicalModels().get(1);
MondrianModelExporter exporter = new MondrianModelExporter(lModel, LocalizedString.DEFAULT_LOCALE);
String mondrianSchema = exporter.createMondrianModelXML();
Document schemaDoc = DocumentHelper.parseText(mondrianSchema);
byte[] schemaBytes = schemaDoc.asXML().getBytes("UTF-8"); //$NON-NLS-1$
status = repository.publish(base, '/' + parentPath, name + ".mondrian.xml", schemaBytes, true); //$NON-NLS-1$
if (status != ISolutionRepository.FILE_ADD_SUCCESSFUL) {
throw new RuntimeException("Unable to save to repository. Status: " + status); //$NON-NLS-1$
}
// Refresh Metadata
PentahoSystem.publish(session, MetadataPublisher.class.getName());
*/
// Write this catalog to the default Pentaho DataSource and refresh the cache.
// $NON-NLS-1$
File file = new File(path + name + ".mondrian.xml");
// Need to find a better way to get the connection name instead of using the Id.
String catConnectStr = "Provider=mondrian;DataSource=\"" + ((SqlPhysicalModel) domain.getPhysicalModels().get(0)).getId() + // $NON-NLS-1$
"\"";
String catDef = // $NON-NLS-1$
"solution:" + solutionStorage + RepositoryFile.SEPARATOR + "resources" + RepositoryFile.SEPARATOR + "metadata" + RepositoryFile.SEPARATOR + file.getName();
addCatalog(catName, catConnectStr, catDef, session);
} catch (Exception e) {
getLogger().error(e);
throw e;
}
return domainId;
}
use of org.pentaho.agilebi.modeler.ModelerWorkspace in project data-access by pentaho.
the class InMemoryDSWDatasourceServiceImpl method generateQueryDomain.
@Override
public QueryDatasourceSummary generateQueryDomain(String name, String query, DatabaseConnection connection, DatasourceDTO datasourceDTO) throws DatasourceServiceException {
ModelerWorkspace modelerWorkspace = new ModelerWorkspace(new GwtModelerWorkspaceHelper(), getGeoContext());
ModelerService modelerService = new ModelerService();
modelerWorkspace.setModelName(name);
try {
Boolean securityEnabled = (getPermittedRoleList() != null && getPermittedRoleList().size() > 0) || (getPermittedUserList() != null && getPermittedUserList().size() > 0);
SerializedResultSet resultSet = DatasourceInMemoryServiceHelper.getSerializeableResultSet(connection.getName(), query, Integer.parseInt("10"), null);
SQLModelGenerator sqlModelGenerator = new SQLModelGenerator(name, connection.getName(), connection.getDatabaseType().getShortName(), resultSet.getColumnTypes(), resultSet.getColumns(), query, securityEnabled, getPermittedRoleList(), getPermittedUserList(), getDefaultAcls(), "joe");
Domain domain = sqlModelGenerator.generate();
modelerWorkspace.setDomain(domain);
modelerWorkspace.getWorkspaceHelper().autoModelFlat(modelerWorkspace);
modelerWorkspace.setModelName(datasourceDTO.getDatasourceName());
modelerWorkspace.getWorkspaceHelper().populateDomain(modelerWorkspace);
domain.getLogicalModels().get(0).setProperty("datasourceModel", serializeModelState(datasourceDTO));
domain.getLogicalModels().get(0).setProperty("DatasourceType", "SQL-DS");
QueryDatasourceSummary summary = new QueryDatasourceSummary();
modelerService.serializeModels(domain, modelerWorkspace.getModelName());
summary.setDomain(domain);
return summary;
} catch (SQLModelGeneratorException smge) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", smge.getLocalizedMessage()), smge);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
smge);
} catch (QueryValidationException e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0009_QUERY_VALIDATION_FAILED", e.getLocalizedMessage()), // $NON-NLS-1$
e);
} catch (ModelerException e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
e);
} catch (Exception e) {
logger.error(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0016_UNABLE_TO_GENERATE_MODEL", e.getLocalizedMessage()), e);
throw new DatasourceServiceException(Messages.getErrorString("InMemoryDatasourceServiceImpl.ERROR_0015_UNABLE_TO_GENERATE_MODEL"), // $NON-NLS-1$
e);
}
}
Aggregations