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

The following examples show how to use org.pentaho.metastore.api.IMetaStore#getElements() . 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: SerializableMetaStore.java    From kettle-beam with Apache License 2.0 6 votes vote down vote up
/**
 * Create a copy of all elements in an existing metastore.
 *
 * @param source the source store to copy over
 */
public SerializableMetaStore(IMetaStore source) throws MetaStoreException {
  List<String> srcNamespaces = source.getNamespaces();
  for (String srcNamespace : srcNamespaces) {
    createNamespace( srcNamespace );
    List<IMetaStoreElementType> srcElementTypes = source.getElementTypes( srcNamespace );
    for (IMetaStoreElementType srcElementType : srcElementTypes) {

      IMetaStoreElementType elementType = newElementType( srcNamespace );
      elementType.setName( srcElementType.getName() );
      elementType.setDescription( srcElementType.getDescription() );
      createElementType(srcNamespace, elementType);

      List<IMetaStoreElement> srcElements = source.getElements( srcNamespace, elementType );
      for (IMetaStoreElement srcElement : srcElements) {
        IMetaStoreElement element = newElement();
        element.setName( srcElement.getName() );
        element.setValue( srcElement.getValue() );

        copyChildren(srcElement, element);

        createElement(srcNamespace, elementType, element);
      }
    }
  }
}
 
Example 2
Source File: DatabaseMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
public static List<DatabaseMeta> getDatabaseElements( IMetaStore metaStore ) throws MetaStoreException {
  List<DatabaseMeta> databases = new ArrayList<DatabaseMeta>();

  // If the data type doesn't exist, it's an empty list...
  //
  IMetaStoreElementType elementType =
    metaStore.getElementTypeByName(
      PentahoDefaults.NAMESPACE, PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME );
  if ( elementType == null ) {
    return databases;
  }

  List<IMetaStoreElement> elements = metaStore.getElements( PentahoDefaults.NAMESPACE, elementType );
  for ( IMetaStoreElement element : elements ) {
    try {
      DatabaseMeta databaseMeta = loadDatabaseMetaFromDatabaseElement( metaStore, element );
      databases.add( databaseMeta );
    } catch ( Exception e ) {
      throw new MetaStoreException( "Unable to load database from element with name '"
        + element.getName() + "' and type '" + elementType.getName() + "'", e );
    }
  }

  return databases;
}
 
Example 3
Source File: SerializableMetaStoreTest.java    From kettle-beam with Apache License 2.0 5 votes vote down vote up
private void assertEqualMetastores( IMetaStore store1, IMetaStore store2 ) throws MetaStoreException {
  List<String> namespaces1 = store1.getNamespaces();
  List<String> namespaces2 = store2.getNamespaces();
  assertEquals( namespaces1.size(), namespaces2.size());

  for (int n=0;n<namespaces1.size();n++) {
    String namespace1 = namespaces1.get( n );
    String namespace2 = namespaces2.get( n );
    assertEquals( namespace1, namespace2 );

    List<IMetaStoreElementType> elementTypes1 = store1.getElementTypes( namespace1 );
    List<IMetaStoreElementType> elementTypes2 = store2.getElementTypes( namespace2 );
    assertEquals( elementTypes1.size(), elementTypes2.size() );
    for (int t=0;t<elementTypes1.size();t++) {
      IMetaStoreElementType elementType1 = elementTypes1.get(t);
      IMetaStoreElementType elementType2 = elementTypes2.get(t);
      assertEquals(elementType1.getName(), elementType2.getName());
      assertEquals(elementType1.getDescription(), elementType2.getDescription());

      List<IMetaStoreElement> elements1 = store1.getElements( namespace1, elementType1 );
      List<IMetaStoreElement> elements2 = store2.getElements( namespace2, elementType2 );
      assertEquals( elements1.size(), elements2.size() );
      for (int e=0;e<elements1.size();e++) {

        IMetaStoreElement element1 = elements1.get(e);
        IMetaStoreElement element2 = elements2.get(e);

        assertEquals( element1.getName(), element2.getName() );

        assertEqualAttributes(element1, element2);
      }
    }
  }
}
 
Example 4
Source File: StarModelerPerspective.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
protected void testMetaStore() {
  try {
    // Force repository meta store
    IMetaStore metaStore = Spoon.getInstance().getRepository().getMetaStore();

    LogChannel.GENERAL.logBasic("Active metastore: "+metaStore.getName());

    StarDomainMetaStoreUtil.verifyNamespaceCreated(metaStore, "pentaho");
    IMetaStoreElementType elementType = StarDomainMetaStoreUtil.getStarDomainElementType(metaStore);
    if (elementType==null) {
      throw new KettleException("Unable to find star domain element type");
    }
    LogChannel.GENERAL.logBasic("Found star domain element type: "+elementType.getName()+" : "+elementType.getDescription());

    elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, elementType.getName());
    if (elementType==null) {
      throw new KettleException("Unable to find star domain element type by name");
    }

    LogChannel.GENERAL.logBasic("Found element type by name");

    List<IdNameDescription> list = new ArrayList<IdNameDescription>();
    for (IMetaStoreElement element : metaStore.getElements(PentahoDefaults.NAMESPACE, elementType)) {
      IdNameDescription nameDescription = new IdNameDescription(element.getId(), element.getName(), null);
      list.add(nameDescription);
    }
    LogChannel.GENERAL.logBasic("Found "+list.size()+" star domain elements.");

    StarDomainMetaStoreUtil.getStarDomainList(metaStore);

  } catch(Exception e) {
    new ErrorDialog(Spoon.getInstance().getShell(), "ERROR", "Error testing meta store: ", e);
  }
}
 
Example 5
Source File: StarDomainMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static List<IdNameDescription> getStarDomainList(IMetaStore metaStore) throws MetaStoreException {
  IMetaStoreElementType elementType = getStarDomainElementType(metaStore);
  List<IdNameDescription> list = new ArrayList<IdNameDescription>();
  for (IMetaStoreElement element : metaStore.getElements(namespace, elementType)) {
    IdNameDescription nameDescription = new IdNameDescription(element.getId(), element.getName(), getChildString(element, Attribute.ID_STAR_DOMAIN_DESCRIPTION.id));
    list.add(nameDescription);
  }
  return list;
}
 
Example 6
Source File: MetaStoreExplorerDialog.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
public void refreshTree() throws MetaStoreException {
  tree.removeAll();

  // Top level: the MetaStore
  //
  for ( int m = 0; m < metaStoreList.size(); m++ ) {
    IMetaStore metaStore = metaStoreList.get( m );
    TreeItem metaStoreItem = new TreeItem( tree, SWT.NONE );

    metaStoreItem.setText( 0, Const.NVL( metaStore.getName(), "metastore-" + ( m + 1 ) ) );
    metaStoreItem.setText( 1, Const.NVL( metaStore.getDescription(), "" ) );

    // level: Namespace
    //
    List<String> namespaces = metaStore.getNamespaces();
    for ( String namespace : namespaces ) {
      TreeItem namespaceItem = new TreeItem( metaStoreItem, SWT.NONE );

      namespaceItem.setText( 0, Const.NVL( namespace, "" ) );

      // level: element type
      //
      List<IMetaStoreElementType> elementTypes = metaStore.getElementTypes( namespace );
      for ( IMetaStoreElementType elementType : elementTypes ) {
        TreeItem elementTypeItem = new TreeItem( namespaceItem, SWT.NONE );

        elementTypeItem.setText( 0, Const.NVL( elementType.getName(), "" ) );
        elementTypeItem.setText( 1, Const.NVL( elementType.getDescription(), "" ) );

        // level: element
        //
        List<IMetaStoreElement> elements = metaStore.getElements( namespace, elementType );
        for ( final IMetaStoreElement element : elements ) {
          TreeItem elementItem = new TreeItem( elementTypeItem, SWT.NONE );

          elementItem.setText( 0, Const.NVL( element.getName(), "" ) );
          elementItem.setText( 2, Const.NVL( element.getId(), "" ) );

          elementItem.addListener( SWT.Selection, new Listener() {

            @Override
            public void handleEvent( Event event ) {
              log.logBasic( "Selected : " + element.getName() );
            }
          } );

          addAttributesToTree( elementItem, element );
        }

      }
    }
  }
  TreeUtil.setOptimalWidthOnColumns( tree );
  TreeMemory.setExpandedFromMemory( tree, META_STORE_EXPLORER_DIALOG_TREE );
}