Search in sources :

Example 1 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-kettle by pentaho.

the class JobGeneratorTest method setUp.

@Before
public void setUp() throws Exception {
    final StarDomain starDomain = mock(StarDomain.class);
    final Domain domain = mock(Domain.class);
    when(domain.getProperty(eq(DefaultIDs.DOMAIN_TARGET_DATABASE))).thenReturn("test_domain_target_db");
    when(starDomain.getDomain()).thenReturn(domain);
    final Repository repository = mock(Repository.class);
    final RepositoryDirectoryInterface targetDirectory = mock(RepositoryDirectoryInterface.class);
    final DatabaseMeta meta = Mockito.mock(DatabaseMeta.class);
    Mockito.when(meta.getName()).thenReturn("test_domain_target_db");
    final LinkedList<DatabaseMeta> databases = new LinkedList<DatabaseMeta>() {

        {
            add(meta);
        }
    };
    final String locale = Locale.US.toString();
    jobGenerator = new JobGenerator(starDomain, repository, targetDirectory, databases, locale);
}
Also used : RepositoryDirectoryInterface(org.pentaho.di.repository.RepositoryDirectoryInterface) Repository(org.pentaho.di.repository.Repository) StarDomain(org.pentaho.di.starmodeler.StarDomain) Domain(org.pentaho.metadata.model.Domain) StarDomain(org.pentaho.di.starmodeler.StarDomain) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) LinkedList(java.util.LinkedList) Before(org.junit.Before)

Example 2 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-kettle by pentaho.

the class MetadataGenerator method generatePhysicalMetadataModel.

public Domain generatePhysicalMetadataModel() throws KettleException {
    // First do some checking and lookups...
    // 
    String targetDatabaseName = ConceptUtil.getString(logicalDomain, DefaultIDs.DOMAIN_TARGET_DATABASE);
    if (Utils.isEmpty(targetDatabaseName)) {
        throw new KettleException("Please specify a target database!");
    }
    DatabaseMeta targetDatabaseMeta = DatabaseMeta.findDatabase(databases, targetDatabaseName);
    if (targetDatabaseMeta == null) {
        throw new KettleException("Target database with name '" + targetDatabaseName + "' can't be found!");
    }
    // Now start creation of a new domain with physical underpinning.
    // 
    Domain domain = new Domain();
    // Copy the domain information...
    // 
    domain.setId(createId("DOMAIN", null, domain));
    domain.setName(logicalDomain.getName());
    domain.setDescription(logicalDomain.getDescription());
    // 
    for (LogicalModel logicalModel : logicalDomain.getLogicalModels()) {
        // Copy model information...
        // 
        LogicalModel model = new LogicalModel();
        model.setId(createId("MODEL", domain, model));
        model.setName(logicalModel.getName());
        model.setDescription(logicalModel.getDescription());
        // Create a physical model...
        // 
        SqlPhysicalModel sqlModel = new SqlPhysicalModel();
        sqlModel.setDatasource(createSqlDataSource(targetDatabaseMeta));
        model.setPhysicalModel(sqlModel);
        for (LogicalTable logicalTable : logicalModel.getLogicalTables()) {
            LogicalTable table = new LogicalTable();
            table.setId(createId("LOGICAL_TABLE", logicalModel, logicalTable));
            table.setName(logicalTable.getName());
            table.setDescription(logicalTable.getDescription());
            String targetTable = ConceptUtil.getString(logicalTable, DefaultIDs.LOGICAL_TABLE_PHYSICAL_TABLE_NAME);
            SqlPhysicalTable sqlTable = new SqlPhysicalTable(sqlModel);
            table.setPhysicalTable(sqlTable);
            // Copy name & description from physical level...
            // 
            sqlTable.setId(createId("PHYSICAL_TABLE", logicalModel, logicalTable));
            sqlTable.setName(logicalTable.getName());
            sqlTable.setDescription(logicalTable.getDescription());
            sqlTable.setTableType(ConceptUtil.getTableType(logicalTable));
            sqlTable.setTargetSchema(targetDatabaseMeta.getPreferredSchemaName());
            sqlTable.setTargetTable(targetTable);
        }
    }
    return domain;
}
Also used : KettleException(org.pentaho.di.core.exception.KettleException) LogicalModel(org.pentaho.metadata.model.LogicalModel) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) LogicalTable(org.pentaho.metadata.model.LogicalTable) Domain(org.pentaho.metadata.model.Domain) SqlPhysicalModel(org.pentaho.metadata.model.SqlPhysicalModel) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) SqlPhysicalTable(org.pentaho.metadata.model.SqlPhysicalTable)

Example 3 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-platform by pentaho.

the class MetadataImportHandler method StripDswFromStream.

InputStream StripDswFromStream(InputStream inputStream) throws Exception {
    // Check if this is valid xml
    InputStream inputStream2 = null;
    String xmi = null;
    XmiParser xmiParser = new XmiParser();
    try {
        byte[] is = IOUtils.toByteArray(inputStream);
        xmi = new String(is, "UTF-8");
        // now, try to see if the xmi can be parsed (ie, check if it's valid xmi)
        Domain domain = xmiParser.parseXmi(new java.io.ByteArrayInputStream(is));
        boolean changed = false;
        Iterator<LogicalModel> iterator = domain.getLogicalModels().iterator();
        while (iterator.hasNext()) {
            LogicalModel logicalModel = iterator.next();
            // $NON-NLS-1$
            Object property = logicalModel.getProperty(DSW_SOURCE_PROPERTY);
            if (property != null) {
                // definition we only want to import the metadata portion.
                if (logicalModel.getProperty(LogicalModel.PROPERTY_OLAP_DIMS) != null) {
                    // This logical model is an Olap model that needs to be removed from metadata
                    iterator.remove();
                } else {
                    // Remove properties that make this a DSW
                    logicalModel.removeChildProperty(DSW_SOURCE_PROPERTY);
                    logicalModel.removeChildProperty(AGILE_BI_VERSION_PROPERTY);
                    logicalModel.removeChildProperty(WIZARD_GENERATED_PROPERTY);
                }
                changed = true;
            }
        }
        if (changed) {
            // The model was modified, regenerate the xml
            xmi = xmiParser.generateXmi(domain);
        }
        // xmi is valid. Create a new inputstream for the actual import action.
        inputStream2 = new java.io.ByteArrayInputStream(xmi.getBytes("UTF-8"));
    } catch (Exception e) {
        throw new PlatformImportException(e.getMessage(), PlatformImportException.PUBLISH_TO_SERVER_FAILED, e);
    }
    return inputStream2;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) LogicalModel(org.pentaho.metadata.model.LogicalModel) ByteArrayInputStream(java.io.ByteArrayInputStream) XmiParser(org.pentaho.metadata.util.XmiParser) Domain(org.pentaho.metadata.model.Domain)

Example 4 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method getDomain.

/**
 * retrieve a domain from the repo. This does lazy loading of the repo, so it calls reloadDomains() if not already
 * loaded.
 *
 * @param domainId domain to get from the repository
 * @return domain object
 */
@Override
public Domain getDomain(final String domainId) {
    if (logger.isDebugEnabled()) {
        logger.debug("getDomain(" + domainId + ")");
    }
    if (StringUtils.isEmpty(domainId)) {
        throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
    }
    Domain domain = null;
    try {
        // Load the domain file
        final RepositoryFile file = getMetadataRepositoryFile(domainId);
        if (file != null) {
            if (hasAccessFor(file)) {
                SimpleRepositoryFileData data = repository.getDataForRead(file.getId(), SimpleRepositoryFileData.class);
                if (data != null) {
                    InputStream is = data.getStream();
                    try {
                        domain = xmiParser.parseXmi(is);
                    } finally {
                        IOUtils.closeQuietly(is);
                    }
                    domain.setId(domainId);
                    logger.debug("loaded domain");
                    // Load any I18N bundles
                    loadLocaleStrings(domainId, domain);
                    logger.debug("loaded I18N bundles");
                } else {
                    throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "data not found"));
                }
            } else {
                throw new PentahoAccessControlException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, "access denied"));
            }
        }
    } catch (Exception e) {
        if (!(e instanceof UnifiedRepositoryException || e instanceof PentahoAccessControlException)) {
            throw new UnifiedRepositoryException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0005_ERROR_RETRIEVING_DOMAIN", domainId, e.getLocalizedMessage()), e);
        }
    }
    // Return
    return domain;
}
Also used : SimpleRepositoryFileData(org.pentaho.platform.api.repository2.unified.data.simple.SimpleRepositoryFileData) ByteArrayInputStream(java.io.ByteArrayInputStream) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) InputStream(java.io.InputStream) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) RepositoryFile(org.pentaho.platform.api.repository2.unified.RepositoryFile) Domain(org.pentaho.metadata.model.Domain) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DomainStorageException(org.pentaho.metadata.repository.DomainStorageException) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException) DomainIdNullException(org.pentaho.metadata.repository.DomainIdNullException) PentahoAccessControlException(org.pentaho.platform.api.engine.PentahoAccessControlException) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) IOException(java.io.IOException)

Example 5 with Domain

use of org.pentaho.metadata.model.Domain in project pentaho-platform by pentaho.

the class PentahoMetadataDomainRepository method removeModel.

/**
 * remove a model from a domain which is stored either on a disk or memory.
 *
 * @param domainId
 * @param modelId
 */
@Override
public void removeModel(final String domainId, final String modelId) throws DomainIdNullException, DomainStorageException {
    if (logger.isDebugEnabled()) {
        logger.debug("removeModel(" + domainId + ", " + modelId + ")");
    }
    if (StringUtils.isEmpty(domainId)) {
        throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0004_DOMAIN_ID_INVALID", domainId));
    }
    if (StringUtils.isEmpty(modelId)) {
        throw new IllegalArgumentException(messages.getErrorString("PentahoMetadataDomainRepository.ERROR_0006_MODEL_ID_INVALID"));
    }
    // Get the domain and remove the model
    final Domain domain = getDomain(domainId);
    if (null != domain) {
        boolean found = false;
        final Iterator<LogicalModel> iter = domain.getLogicalModels().iterator();
        while (iter.hasNext()) {
            LogicalModel model = iter.next();
            if (modelId.equals(model.getId())) {
                iter.remove();
                found = true;
                break;
            }
        }
        // Update the domain if we change it
        if (found) {
            try {
                storeDomain(domain, true);
                flushDomains();
            } catch (DomainAlreadyExistsException ignored) {
            // This can't happen since we have setup overwrite to true
            }
        }
    }
}
Also used : LogicalModel(org.pentaho.metadata.model.LogicalModel) DomainAlreadyExistsException(org.pentaho.metadata.repository.DomainAlreadyExistsException) Domain(org.pentaho.metadata.model.Domain)

Aggregations

Domain (org.pentaho.metadata.model.Domain)76 LogicalModel (org.pentaho.metadata.model.LogicalModel)29 Test (org.junit.Test)18 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)13 LocalizedString (org.pentaho.metadata.model.concept.types.LocalizedString)13 DatasourceServiceException (org.pentaho.platform.dataaccess.datasource.wizard.service.DatasourceServiceException)13 Matchers.anyString (org.mockito.Matchers.anyString)12 ModelerWorkspace (org.pentaho.agilebi.modeler.ModelerWorkspace)11 DomainStorageException (org.pentaho.metadata.repository.DomainStorageException)11 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)11 InputStream (java.io.InputStream)10 DomainAlreadyExistsException (org.pentaho.metadata.repository.DomainAlreadyExistsException)10 XmiParser (org.pentaho.metadata.util.XmiParser)10 SqlPhysicalModel (org.pentaho.metadata.model.SqlPhysicalModel)9 DomainIdNullException (org.pentaho.metadata.repository.DomainIdNullException)9 LogicalColumn (org.pentaho.metadata.model.LogicalColumn)8 RepositoryFile (org.pentaho.platform.api.repository2.unified.RepositoryFile)8 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)7 BusinessData (org.pentaho.platform.dataaccess.datasource.beans.BusinessData)7