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

The following examples show how to use org.pentaho.metastore.api.IMetaStore#newElementType() . 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: DatabaseMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static IMetaStoreElementType populateDatabaseElementType( IMetaStore metaStore ) throws MetaStoreException {

    // The new type will typically have an ID so all we need to do is give the type a name and a description.
    //
    IMetaStoreElementType elementType = metaStore.newElementType( PentahoDefaults.NAMESPACE );

    // Name and description...
    //
    elementType.setName( PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_NAME );
    elementType.setDescription( PentahoDefaults.DATABASE_CONNECTION_ELEMENT_TYPE_DESCRIPTION );
    return elementType;
  }
 
Example 2
Source File: SharedDimensionMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static IMetaStoreElementType getSharedDimensionElementType(IMetaStore metaStore) throws MetaStoreException {
  verifyNamespaceCreated(metaStore, namespace);

  IMetaStoreElementType elementType = metaStore.getElementTypeByName(namespace, METASTORE_SHARED_DIMENSION_TYPE_NAME);
  if (elementType==null) {
    // create the type
    //
    elementType = metaStore.newElementType(namespace);
    elementType.setName(METASTORE_SHARED_DIMENSION_TYPE_NAME);
    elementType.setDescription(METASTORE_SHARED_DIMENSION_TYPE_DESCRIPTION);
    metaStore.createElementType(namespace, elementType);
  }
  return elementType;
}
 
Example 3
Source File: ModelMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static IMetaStoreElementType getLogicalModelElementType(IMetaStore metaStore) throws MetaStoreException {
  verifyNamespaceCreated(metaStore, PentahoDefaults.NAMESPACE);

  IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, METASTORE_STAR_MODEL_TYPE_NAME);
  if (elementType==null) {
    // create the type
    //
    elementType = metaStore.newElementType(PentahoDefaults.NAMESPACE);
    elementType.setName(METASTORE_STAR_MODEL_TYPE_NAME);
    elementType.setDescription(METASTORE_STAR_MODEL_TYPE_DESCRIPTION);
    metaStore.createElementType(PentahoDefaults.NAMESPACE, elementType);
  }
  return elementType;
}
 
Example 4
Source File: ModelMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static IMetaStoreElementType getLogicalTableElementType(IMetaStore metaStore) throws MetaStoreException {
  verifyNamespaceCreated(metaStore, PentahoDefaults.NAMESPACE);

  IMetaStoreElementType elementType = metaStore.getElementTypeByName(PentahoDefaults.NAMESPACE, METASTORE_LOGICAL_TABLE_TYPE_NAME);
  if (elementType==null) {
    // create the type
    //
    elementType = metaStore.newElementType(PentahoDefaults.NAMESPACE);
    elementType.setName(METASTORE_LOGICAL_TABLE_TYPE_NAME);
    elementType.setDescription(METASTORE_LOGICAL_TABLE_TYPE_DESCRIPTION);
    metaStore.createElementType(PentahoDefaults.NAMESPACE, elementType);
  }
  return elementType;
}
 
Example 5
Source File: StarDomainMetaStoreUtil.java    From pentaho-kettle with Apache License 2.0 5 votes vote down vote up
public static IMetaStoreElementType createStarDomainElementType(IMetaStore metaStore) throws MetaStoreElementTypeExistsException, MetaStoreException {
  IMetaStoreElementType elementType = metaStore.newElementType(namespace);
  elementType.setName(METASTORE_STAR_DOMAIN_TYPE_NAME);
  elementType.setDescription(METASTORE_STAR_DOMAIN_TYPE_DESCRIPTION);
  metaStore.createElementType(namespace, elementType);

  return elementType;
}
 
Example 6
Source File: PurRepositoryIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testMetaStoreElementTypes() throws MetaStoreException {
  IMetaStore metaStore = repository.getMetaStore();
  assertNotNull( metaStore );
  String ns = PentahoDefaults.NAMESPACE;

  // We start with a clean slate...
  //
  assertEquals( 1, metaStore.getNamespaces().size() );
  assertEquals( true, metaStore.namespaceExists( ns ) );

  // Now create an element type
  //
  IMetaStoreElementType elementType = metaStore.newElementType( ns );
  elementType.setName( PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME );
  elementType.setDescription( PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION );

  metaStore.createElementType( ns, elementType );

  IMetaStoreElementType verifyElementType = metaStore.getElementType( ns, elementType.getId() );
  assertEquals( PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName() );
  assertEquals( PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription() );

  verifyElementType = metaStore.getElementTypeByName( ns, PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME );
  assertEquals( PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME, verifyElementType.getName() );
  assertEquals( PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION, verifyElementType.getDescription() );

  // Get the list of element type ids.
  //
  List<String> ids = metaStore.getElementTypeIds( ns );
  assertNotNull( ids );
  assertEquals( 1, ids.size() );
  assertEquals( elementType.getId(), ids.get( 0 ) );

  // Verify that we can't delete the namespace since it has content in it!
  //
  try {
    metaStore.deleteNamespace( ns );
    fail( "The namespace deletion didn't cause an exception because there are still an element type in it" );
  } catch ( MetaStoreDependenciesExistsException e ) {
    assertNotNull( e.getDependencies() );
    assertEquals( 1, e.getDependencies().size() );
    assertEquals( elementType.getId(), e.getDependencies().get( 0 ) );
  }

  metaStore.deleteElementType( ns, elementType );
  assertEquals( 0, metaStore.getElementTypes( ns ).size() );

  metaStore.deleteNamespace( ns );
}
 
Example 7
Source File: PurRepositoryIT.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
@Test
public void testMetaStoreElements() throws MetaStoreException {
  // Set up a namespace
  //
  String ns = PentahoDefaults.NAMESPACE;
  IMetaStore metaStore = repository.getMetaStore();
  if ( !metaStore.namespaceExists( ns ) ) {
    metaStore.createNamespace( ns );
  }

  // And an element type
  //
  IMetaStoreElementType elementType = metaStore.newElementType( ns );
  elementType.setName( PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_NAME );
  elementType.setDescription( PentahoDefaults.KETTLE_DATA_SERVICE_ELEMENT_TYPE_DESCRIPTION );
  metaStore.createElementType( ns, elementType );

  // Now we play with elements...
  //
  IMetaStoreElement oneElement = populateElement( metaStore, elementType, "Element One" );
  metaStore.createElement( ns, elementType, oneElement );

  IMetaStoreElement verifyOneElement = metaStore.getElement( ns, elementType, oneElement.getId() );
  assertNotNull( verifyOneElement );
  validateElement( verifyOneElement, "Element One" );

  assertEquals( 1, metaStore.getElements( ns, elementType ).size() );

  IMetaStoreElement twoElement = populateElement( metaStore, elementType, "Element Two" );
  metaStore.createElement( ns, elementType, twoElement );

  IMetaStoreElement verifyTwoElement = metaStore.getElement( ns, elementType, twoElement.getId() );
  assertNotNull( verifyTwoElement );

  assertEquals( 2, metaStore.getElements( ns, elementType ).size() );

  try {
    metaStore.deleteElementType( ns, elementType );
    fail( "Delete element type failed to properly detect element dependencies" );
  } catch ( MetaStoreDependenciesExistsException e ) {
    List<String> ids = e.getDependencies();
    assertEquals( 2, ids.size() );
    assertTrue( ids.contains( oneElement.getId() ) );
    assertTrue( ids.contains( twoElement.getId() ) );
  }

  metaStore.deleteElement( ns, elementType, oneElement.getId() );

  assertEquals( 1, metaStore.getElements( ns, elementType ).size() );

  metaStore.deleteElement( ns, elementType, twoElement.getId() );

  assertEquals( 0, metaStore.getElements( ns, elementType ).size() );
}