Java Code Examples for org.pentaho.metastore.api.IMetaStore#newElement()

The following examples show how to use org.pentaho.metastore.api.IMetaStore#newElement() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PurRepositoryIT.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example 2
Source File: SharedDimensionMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static void saveSharedDimension(IMetaStore metaStore, LogicalTable sharedDimension, String locale) throws MetaStoreException {
  IMetaStoreElementType elementType = getSharedDimensionElementType(metaStore);
  IMetaStoreElement element = null;
  if (sharedDimension.getId()!=null) {
    element = metaStore.getElement(namespace, elementType, sharedDimension.getId());
  }

  if (element!=null) {
    // Update the shared dimension!
    //
    populateElementWithSharedDimension(metaStore, sharedDimension, locale, elementType, element);
    metaStore.updateElement(namespace, elementType, sharedDimension.getId(), element);
  } else {
    // New shared dimension
    //
    element = metaStore.newElement();
    populateElementWithSharedDimension(metaStore, sharedDimension, locale, elementType, element);
    metaStore.createElement(namespace, elementType, element);
  }

  sharedDimension.setId(element.getId());
}
 
Example 3
Source File: ModelMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
private static IMetaStoreElement populateElement(IMetaStore metaStore, LogicalModel model) throws MetaStoreException {
  try {
    IMetaStoreElement element = metaStore.newElement();
    element.setName(model.getName(defaultLocale));
    element.addChild( metaStore.newAttribute(Attribute.ID_MODEL_DESCRIPTION.id, model.getDescription(defaultLocale)) );

    IMetaStoreAttribute logicalTablesAttribute = metaStore.newAttribute(Attribute.ID_LOGICAL_TABLES.id, model.getDescription(defaultLocale));
    element.addChild(logicalTablesAttribute);
    for (LogicalTable logicalTable : model.getLogicalTables()) {

      IMetaStoreAttribute logicalTableAttribute = metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE.id, model.getDescription(defaultLocale));
      logicalTablesAttribute.addChild(logicalTableAttribute);

      //

      // Save the ID as well as the name (for safety)
      //
      logicalTableAttribute.addChild(metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE_ID.id, logicalTable.getId()));
      logicalTableAttribute.addChild(metaStore.newAttribute(Attribute.ID_LOGICAL_TABLE_NAME.id, logicalTable.getName()));
    }

    return element;
  } catch(Exception e) {
    throw new MetaStoreException("Unable to populate metastore element from logical model", e);
  }
}
 
Example 4
Source File: StarDomainMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static void saveStarDomain(IMetaStore metaStore, StarDomain starDomain) throws MetaStoreException {
  IMetaStoreElementType elementType = getStarDomainElementType(metaStore);
  IMetaStoreElement element = null;
  if (starDomain.getObjectId()!=null) {
    // verify the ID!
    //
    element = metaStore.getElement(namespace, elementType, starDomain.getObjectId().toString());
  }

  if (element==null) {
    // Create a new element
    //
    element = metaStore.newElement();
    populateElementWithStarDomain(metaStore, starDomain, element, elementType);
    metaStore.createElement(namespace, elementType, element);
  } else {
    // Update an existing element
    //
    populateElementWithStarDomain(metaStore, starDomain, element, elementType);
    metaStore.updateElement(namespace, elementType, starDomain.getObjectId().toString(), element);
  }
  starDomain.setObjectId(new StringObjectId(element.getId().toString()));
}
 
Example 5
Source File: KettleMetaStoreTestBase.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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" ) );

  // A few columns...
  //
  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;
}
 
Example 6
Source File: DatabaseMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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() ) );

    // The URL
    //
    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;
  }
 
Example 7
Source File: MetaStoreTestBase.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
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" ) );

  // A few columns...
  //
  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;
}