Search in sources :

Example 1 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class DatabaseMetaStoreUtil method loadDatabaseMetaFromDatabaseElement.

public static DatabaseMeta loadDatabaseMetaFromDatabaseElement(IMetaStore metaStore, IMetaStoreElement element) throws KettlePluginException {
    DatabaseMeta databaseMeta = new DatabaseMeta();
    PluginRegistry pluginRegistry = PluginRegistry.getInstance();
    // Load the appropriate database plugin (database interface)
    // 
    String pluginId = getChildString(element, MetaStoreConst.DB_ATTR_ID_PLUGIN_ID);
    String driverClassName = getChildString(element, MetaStoreConst.DB_ATTR_DRIVER_CLASS);
    if (Utils.isEmpty(pluginId) && Utils.isEmpty(driverClassName)) {
        throw new KettlePluginException("The attributes 'plugin_id' and 'driver_class' can't be both empty");
    }
    if (Utils.isEmpty(pluginId)) {
        // Determine pluginId using the plugin registry.
        // 
        List<PluginInterface> plugins = pluginRegistry.getPlugins(DatabasePluginType.class);
        for (PluginInterface plugin : plugins) {
            DatabaseInterface databaseInterface = (DatabaseInterface) pluginRegistry.loadClass(plugin);
            if (driverClassName.equalsIgnoreCase(databaseInterface.getDriverClass())) {
                pluginId = plugin.getIds()[0];
            }
        }
    }
    if (Utils.isEmpty(pluginId)) {
        throw new KettlePluginException("The 'plugin_id' attribute could not be determined using 'driver_class' value '" + driverClassName + "'");
    }
    // Look for the plugin
    // 
    PluginInterface plugin = PluginRegistry.getInstance().getPlugin(DatabasePluginType.class, pluginId);
    DatabaseInterface databaseInterface = (DatabaseInterface) PluginRegistry.getInstance().loadClass(plugin);
    databaseInterface.setPluginId(pluginId);
    databaseMeta.setDatabaseInterface(databaseInterface);
    databaseMeta.setObjectId(new StringObjectId(element.getId()));
    databaseMeta.setName(element.getName());
    databaseMeta.setDescription(getChildString(element, MetaStoreConst.DB_ATTR_ID_DESCRIPTION));
    String accessTypeString = getChildString(element, MetaStoreConst.DB_ATTR_ID_ACCESS_TYPE);
    if (Utils.isEmpty(accessTypeString)) {
        accessTypeString = DatabaseMeta.getAccessTypeDesc(DatabaseMeta.TYPE_ACCESS_NATIVE);
    }
    databaseMeta.setAccessType(DatabaseMeta.getAccessType(accessTypeString));
    databaseMeta.setHostname(getChildString(element, MetaStoreConst.DB_ATTR_ID_HOSTNAME));
    databaseMeta.setDBPort(getChildString(element, MetaStoreConst.DB_ATTR_ID_PORT));
    databaseMeta.setDBName(getChildString(element, MetaStoreConst.DB_ATTR_ID_DATABASE_NAME));
    databaseMeta.setUsername(getChildString(element, MetaStoreConst.DB_ATTR_ID_USERNAME));
    databaseMeta.setPassword(metaStore.getTwoWayPasswordEncoder().decode(getChildString(element, MetaStoreConst.DB_ATTR_ID_PASSWORD)));
    databaseMeta.setServername(getChildString(element, MetaStoreConst.DB_ATTR_ID_SERVERNAME));
    databaseMeta.setDataTablespace(getChildString(element, MetaStoreConst.DB_ATTR_ID_DATA_TABLESPACE));
    databaseMeta.setIndexTablespace(getChildString(element, MetaStoreConst.DB_ATTR_ID_INDEX_TABLESPACE));
    IMetaStoreAttribute attributesChild = element.getChild(MetaStoreConst.DB_ATTR_ID_ATTRIBUTES);
    if (attributesChild != null) {
        // Now add a list of all the attributes set on the database connection...
        // 
        Properties attributes = databaseMeta.getAttributes();
        for (IMetaStoreAttribute attr : attributesChild.getChildren()) {
            String code = attr.getId();
            String value = getAttributeString(attr);
            attributes.put(code, Const.NVL(value, ""));
        }
    }
    return databaseMeta;
}
Also used : DatabaseInterface(org.pentaho.di.core.database.DatabaseInterface) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException) PluginRegistry(org.pentaho.di.core.plugins.PluginRegistry) PluginInterface(org.pentaho.di.core.plugins.PluginInterface) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) Properties(java.util.Properties) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) StringObjectId(org.pentaho.di.repository.StringObjectId)

Example 2 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class DatabaseMetaStoreUtil method populateDatabaseElement.

public static IMetaStoreElement populateDatabaseElement(IMetaStore metaStore, DatabaseMeta databaseMeta) throws MetaStoreException {
    if (!metaStore.namespaceExists(PentahoDefaults.NAMESPACE)) {
        throw new MetaStoreException("Namespace '" + PentahoDefaults.NAMESPACE + "' doesn't exist.");
    }
    // If the data type doesn't exist, error out...
    // 
    IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME);
    if (elementType == null) {
        throw new MetaStoreException("Unable to find the database connection type");
    }
    elementType = populateDatabaseElementType(metaStore);
    // generate a new database element and populate it with metadata
    // 
    IMetaStoreElement element = metaStore.newElement(elementType, databaseMeta.getName(), null);
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PLUGIN_ID, databaseMeta.getPluginId()));
    element.setName(databaseMeta.getName());
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DESCRIPTION, databaseMeta.getDescription()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_ACCESS_TYPE, databaseMeta.getAccessTypeDesc()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_HOSTNAME, databaseMeta.getHostname()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PORT, databaseMeta.getDatabasePortNumberString()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DATABASE_NAME, databaseMeta.getDatabaseName()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_USERNAME, databaseMeta.getUsername()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_PASSWORD, metaStore.getTwoWayPasswordEncoder().encode(databaseMeta.getPassword())));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_SERVERNAME, databaseMeta.getServername()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_DATA_TABLESPACE, databaseMeta.getDataTablespace()));
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_INDEX_TABLESPACE, databaseMeta.getIndexTablespace()));
    IMetaStoreAttribute attributesChild = metaStore.newAttribute(MetaStoreConst.DB_ATTR_ID_ATTRIBUTES, null);
    element.addChild(attributesChild);
    // Now add a list of all the attributes set on the database connection...
    // 
    Properties attributes = databaseMeta.getAttributes();
    Enumeration<Object> keys = databaseMeta.getAttributes().keys();
    while (keys.hasMoreElements()) {
        String code = (String) keys.nextElement();
        String attribute = (String) attributes.get(code);
        // Add it to the attributes child
        // 
        attributesChild.addChild(metaStore.newAttribute(code, attribute));
    }
    // Extra information for 3rd-party tools:
    // 
    // The driver class
    // 
    element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_DRIVER_CLASS, databaseMeta.getDriverClass()));
    // 
    try {
        element.addChild(metaStore.newAttribute(MetaStoreConst.DB_ATTR_JDBC_URL, databaseMeta.getURL()));
    } catch (Exception e) {
        throw new MetaStoreException("Unable to assemble URL from database '" + databaseMeta.getName() + "'", e);
    }
    return element;
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) IMetaStoreElementType(org.pentaho.metastore.api.IMetaStoreElementType) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement) Properties(java.util.Properties) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettlePluginException(org.pentaho.di.core.exception.KettlePluginException)

Example 3 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class MetaStoreTestBase method generateCustomerDimensionElement.

private IMetaStoreElement generateCustomerDimensionElement(IMetaStore metaStore, IMetaStoreElementType elementType) throws MetaStoreException {
    IMetaStoreElement element = metaStore.newElement();
    element.setElementType(elementType);
    element.setName(CUSTOMER_DIMENSION_NAME);
    element.addChild(metaStore.newAttribute("description", "This is the shared customer dimension"));
    element.addChild(metaStore.newAttribute("physical_table", "DIM_CUSTOMER"));
    IMetaStoreAttribute fieldsElement = metaStore.newAttribute("fields", null);
    element.addChild(fieldsElement);
    // A technical key
    // 
    IMetaStoreAttribute fieldElement = metaStore.newAttribute("field_0", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "Customer TK"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "Customer Technical key"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "customer_tk"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Integer"));
    // A version field
    // 
    fieldElement = metaStore.newAttribute("field_1", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "version field"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "dimension version field (1..N)"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "version"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Integer"));
    // Natural key
    // 
    fieldElement = metaStore.newAttribute("field_2", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "Customer ID"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "Customer ID as a natural key of this dimension"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "customer_id"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Integer"));
    // Start date
    // 
    fieldElement = metaStore.newAttribute("field_3", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "Start date"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "Start of validity of this dimension entry"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "start_date"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Date"));
    // End date
    // 
    fieldElement = metaStore.newAttribute("field_4", null);
    fieldsElement.addChild(fieldElement);
    fieldElement.addChild(metaStore.newAttribute("field_name", "End date"));
    fieldElement.addChild(metaStore.newAttribute("field_description", "End of validity of this dimension entry"));
    fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "end_date"));
    fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "Date"));
    // 
    for (int i = 5; i <= 10; i++) {
        fieldElement = metaStore.newAttribute("field_" + i, null);
        fieldsElement.addChild(fieldElement);
        fieldElement.addChild(metaStore.newAttribute("field_name", "Field name " + i));
        fieldElement.addChild(metaStore.newAttribute("field_description", "Field description " + i));
        fieldElement.addChild(metaStore.newAttribute("field_phyiscal_name", "physical_name_" + i));
        fieldElement.addChild(metaStore.newAttribute("field_kettle_type", "String"));
    }
    // Some security
    // 
    element.setOwner(metaStore.newElementOwner("joe", MetaStoreElementOwnerType.USER));
    // The "users" role has read/write permissions
    // 
    IMetaStoreElementOwner usersRole = metaStore.newElementOwner("users", MetaStoreElementOwnerType.ROLE);
    MetaStoreOwnerPermissions usersRoleOwnerPermissions = new MetaStoreOwnerPermissions(usersRole, MetaStoreObjectPermission.READ, MetaStoreObjectPermission.UPDATE);
    element.getOwnerPermissionsList().add(usersRoleOwnerPermissions);
    return element;
}
Also used : IMetaStoreElementOwner(org.pentaho.metastore.api.security.IMetaStoreElementOwner) MetaStoreOwnerPermissions(org.pentaho.metastore.api.security.MetaStoreOwnerPermissions) IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 4 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class PurRepositoryIT method populateElement.

protected IMetaStoreElement populateElement(IMetaStore metaStore, IMetaStoreElementType elementType, String name) throws MetaStoreException {
    IMetaStoreElement element = metaStore.newElement();
    element.setElementType(elementType);
    element.setName(name);
    for (int i = 1; i <= 5; i++) {
        element.addChild(metaStore.newAttribute("id " + i, "value " + i));
    }
    IMetaStoreAttribute subAttr = metaStore.newAttribute("sub-attr", null);
    for (int i = 101; i <= 110; i++) {
        subAttr.addChild(metaStore.newAttribute("sub-id " + i, "sub-value " + i));
    }
    element.addChild(subAttr);
    return element;
}
Also used : IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute) IMetaStoreElement(org.pentaho.metastore.api.IMetaStoreElement)

Example 5 with IMetaStoreAttribute

use of org.pentaho.metastore.api.IMetaStoreAttribute in project pentaho-kettle by pentaho.

the class PurRepositoryIT method validateElement.

protected void validateElement(IMetaStoreElement element, String name) throws MetaStoreException {
    assertEquals(name, element.getName());
    assertEquals(6, element.getChildren().size());
    for (int i = 1; i <= 5; i++) {
        IMetaStoreAttribute child = element.getChild("id " + i);
        assertEquals("value " + i, child.getValue());
    }
    IMetaStoreAttribute subAttr = element.getChild("sub-attr");
    assertNotNull(subAttr);
    assertEquals(10, subAttr.getChildren().size());
    for (int i = 101; i <= 110; i++) {
        IMetaStoreAttribute child = subAttr.getChild("sub-id " + i);
        assertNotNull(child);
        assertEquals("sub-value " + i, child.getValue());
    }
}
Also used : IMetaStoreAttribute(org.pentaho.metastore.api.IMetaStoreAttribute)

Aggregations

IMetaStoreAttribute (org.pentaho.metastore.api.IMetaStoreAttribute)13 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)6 Properties (java.util.Properties)2 KettlePluginException (org.pentaho.di.core.exception.KettlePluginException)2 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)2 IMetaStoreElementOwner (org.pentaho.metastore.api.security.IMetaStoreElementOwner)2 MetaStoreOwnerPermissions (org.pentaho.metastore.api.security.MetaStoreOwnerPermissions)2 DataNode (org.pentaho.platform.api.repository2.unified.data.node.DataNode)2 Date (java.util.Date)1 TreeItem (org.eclipse.swt.widgets.TreeItem)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 RowMetaAndData (org.pentaho.di.core.RowMetaAndData)1 DatabaseInterface (org.pentaho.di.core.database.DatabaseInterface)1 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)1 PluginInterface (org.pentaho.di.core.plugins.PluginInterface)1 PluginRegistry (org.pentaho.di.core.plugins.PluginRegistry)1 ValueMetaInteger (org.pentaho.di.core.row.value.ValueMetaInteger)1 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)1 LongObjectId (org.pentaho.di.repository.LongObjectId)1