Search in sources :

Example 6 with ModelerWorkspace

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;
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) MondrianCatalogRepositoryHelper(org.pentaho.platform.plugin.services.importexport.legacy.MondrianCatalogRepositoryHelper) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace)

Example 7 with ModelerWorkspace

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);
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Example 8 with ModelerWorkspace

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();
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) ModelerWorkspaceHelper(org.pentaho.agilebi.modeler.util.ModelerWorkspaceHelper) GwtModelerWorkspaceHelper(org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper) MondrianModelExporter(org.pentaho.metadata.util.MondrianModelExporter) RepositoryFileImportBundle(org.pentaho.platform.plugin.services.importer.RepositoryFileImportBundle) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) FileNotFoundException(java.io.FileNotFoundException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) MondrianCatalogServiceException(org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException) ConnectionServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException) IOException(java.io.IOException)

Example 9 with ModelerWorkspace

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;
}
Also used : GwtModelerWorkspaceHelper(org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper) LogicalModel(org.pentaho.metadata.model.LogicalModel) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) IApplicationContext(org.pentaho.platform.api.engine.IApplicationContext) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) File(java.io.File) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException)

Example 10 with ModelerWorkspace

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);
    }
}
Also used : SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) ModelerException(org.pentaho.agilebi.modeler.ModelerException) SerializedResultSet(org.pentaho.platform.dataaccess.datasource.beans.SerializedResultSet) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) ModelerException(org.pentaho.agilebi.modeler.ModelerException) SQLException(java.sql.SQLException) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) SQLModelGeneratorException(org.pentaho.metadata.util.SQLModelGeneratorException) GwtModelerWorkspaceHelper(org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper) QueryDatasourceSummary(org.pentaho.platform.dataaccess.datasource.wizard.sources.query.QueryDatasourceSummary) SQLModelGenerator(org.pentaho.metadata.util.SQLModelGenerator) QueryValidationException(org.pentaho.platform.dataaccess.datasource.wizard.service.QueryValidationException) Domain(org.pentaho.metadata.model.Domain) ModelerWorkspace(org.pentaho.agilebi.modeler.ModelerWorkspace) DatasourceServiceException(org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)

Aggregations

ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)17 Domain (org.pentaho.metadata.model.Domain)10 LogicalModel (org.pentaho.metadata.model.LogicalModel)10 Test (org.junit.Test)8 Matchers.anyString (org.mockito.Matchers.anyString)7 GwtModelerWorkspaceHelper (org.pentaho.agilebi.modeler.gwt.GwtModelerWorkspaceHelper)7 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)6 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 PentahoAccessControlException (org.pentaho.platform.api.engine.PentahoAccessControlException)5 MondrianCatalogServiceException (org.pentaho.platform.plugin.action.mondrian.catalog.MondrianCatalogServiceException)5 IOException (java.io.IOException)4 File (java.io.File)3 InputStream (java.io.InputStream)3 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)3 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)3 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)3 ConnectionServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.ConnectionServiceException)3 IMondrianCatalogService (org.pentaho.platform.plugin.action.mondrian.catalog.IMondrianCatalogService)3 FileInputStream (java.io.FileInputStream)2 FileNotFoundException (java.io.FileNotFoundException)2