Search in sources :

Example 51 with IMetaStore

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

the class XMLOutputMetaTest method testLoadAndGetXml.

@Test
public void testLoadAndGetXml() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    Node stepnode = getTestNode();
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    IMetaStore metaStore = mock(IMetaStore.class);
    xmlOutputMeta.loadXML(stepnode, Collections.singletonList(dbMeta), metaStore);
    assertXmlOutputMeta(xmlOutputMeta);
}
Also used : Node(org.w3c.dom.Node) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 52 with IMetaStore

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

the class XMLOutputMetaTest method testGetFields.

@Test
public void testGetFields() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    xmlOutputMeta.setDefault();
    XMLField xmlField = new XMLField();
    xmlField.setFieldName("aField");
    xmlField.setLength(10);
    xmlField.setPrecision(3);
    xmlOutputMeta.setOutputFields(new XMLField[] { xmlField });
    RowMetaInterface row = mock(RowMetaInterface.class);
    RowMetaInterface rmi = mock(RowMetaInterface.class);
    StepMeta nextStep = mock(StepMeta.class);
    Repository repo = mock(Repository.class);
    IMetaStore metastore = mock(IMetaStore.class);
    ValueMetaInterface vmi = mock(ValueMetaInterface.class);
    when(row.searchValueMeta("aField")).thenReturn(vmi);
    xmlOutputMeta.getFields(row, "", new RowMetaInterface[] { rmi }, nextStep, new Variables(), repo, metastore);
    verify(vmi).setLength(10, 3);
}
Also used : Variables(org.pentaho.di.core.variables.Variables) Repository(org.pentaho.di.repository.Repository) RowMetaInterface(org.pentaho.di.core.row.RowMetaInterface) StepMeta(org.pentaho.di.trans.step.StepMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) ValueMetaInterface(org.pentaho.di.core.row.ValueMetaInterface) Test(org.junit.Test)

Example 53 with IMetaStore

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

the class XMLOutputMetaTest method testClone.

@Test
public void testClone() throws Exception {
    XMLOutputMeta xmlOutputMeta = new XMLOutputMeta();
    Node stepnode = getTestNode();
    DatabaseMeta dbMeta = mock(DatabaseMeta.class);
    IMetaStore metaStore = mock(IMetaStore.class);
    xmlOutputMeta.loadXML(stepnode, Collections.singletonList(dbMeta), metaStore);
    XMLOutputMeta cloned = (XMLOutputMeta) xmlOutputMeta.clone();
    assertNotSame(cloned, xmlOutputMeta);
    assertXmlOutputMeta(cloned);
}
Also used : Node(org.w3c.dom.Node) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) Test(org.junit.Test)

Example 54 with IMetaStore

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

the class StarModelerPerspective method createSharedDatabase.

protected void createSharedDatabase(CCombo targetDatabase) {
    Shell shell = Spoon.getInstance().getShell();
    boolean retry = true;
    while (retry) {
        try {
            DatabaseMeta dbMeta = new DatabaseMeta();
            DatabaseDialog databaseDialog = new DatabaseDialog(shell, dbMeta);
            if (databaseDialog.open() != null) {
                // Add dbMeta to the shared databases...
                // 
                IMetaStore metaStore = Spoon.getInstance().getMetaStore();
                DatabaseMetaStoreUtil.createDatabaseElement(metaStore, dbMeta);
                // Refresh the list...
                // 
                final List<DatabaseMeta> sharedDatabases = DatabaseMetaStoreUtil.getDatabaseElements(metaStore);
                String[] databaseNames = SharedDatabaseUtil.getSortedDatabaseNames(sharedDatabases);
                targetDatabase.setItems(databaseNames);
                targetDatabase.setText(dbMeta.getName());
            }
            retry = false;
        } catch (MetaStoreElementExistException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Title"), BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Message"), e);
        } catch (MetaStoreException e) {
            new ErrorDialog(shell, BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Title"), BaseMessages.getString(PKG, "StarModelerPerspective.Exception.UnableToCreateSharedDB.Message"), e);
            retry = false;
        }
    }
}
Also used : MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) Shell(org.eclipse.swt.widgets.Shell) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException) ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) LocalizedString(org.pentaho.metadata.model.concept.types.LocalizedString) DatabaseMeta(org.pentaho.di.core.database.DatabaseMeta) IMetaStore(org.pentaho.metastore.api.IMetaStore) DatabaseDialog(org.pentaho.di.ui.core.database.dialog.DatabaseDialog)

Example 55 with IMetaStore

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

the class StarModelerPerspective method save.

@Override
public boolean save(EngineMetaInterface meta, String fname, boolean isExport) {
    try {
        // 
        if (meta instanceof StarDomain) {
            StarDomain starDomain = (StarDomain) meta;
            // Make sure we pick the active MetaStore to save to, otherwise it's hard to verify
            // 
            IMetaStore metaStore = Spoon.getInstance().metaStore.getActiveMetaStore();
            LogChannel.GENERAL.logBasic("Saving star domain to meta store: " + metaStore.getName());
            // Save the name and description of the shared dimension in the metastore
            // 
            StarDomainMetaStoreUtil.saveStarDomain(metaStore, starDomain);
            // 
            for (LogicalTable sharedDimension : starDomain.getSharedDimensions()) {
                SharedDimensionMetaStoreUtil.saveSharedDimension(metaStore, sharedDimension, defaultLocale);
            }
            meta.clearChanged();
            Spoon.getInstance().enableMenus();
            return true;
        }
    } catch (Exception e) {
        new ErrorDialog(Spoon.getInstance().getShell(), "Error saving model", "There was an error while saving the model:", e);
    }
    return false;
}
Also used : ErrorDialog(org.pentaho.di.ui.core.dialog.ErrorDialog) LogicalTable(org.pentaho.metadata.model.LogicalTable) IMetaStore(org.pentaho.metastore.api.IMetaStore) XulException(org.pentaho.ui.xul.XulException) MetaStoreException(org.pentaho.metastore.api.exceptions.MetaStoreException) KettleException(org.pentaho.di.core.exception.KettleException) MetaStoreElementExistException(org.pentaho.metastore.api.exceptions.MetaStoreElementExistException)

Aggregations

IMetaStore (org.pentaho.metastore.api.IMetaStore)75 Test (org.junit.Test)55 DatabaseMeta (org.pentaho.di.core.database.DatabaseMeta)20 SQL (org.pentaho.di.core.sql.SQL)17 Repository (org.pentaho.di.repository.Repository)17 RowMetaInterface (org.pentaho.di.core.row.RowMetaInterface)11 TransMeta (org.pentaho.di.trans.TransMeta)11 Matchers.anyString (org.mockito.Matchers.anyString)10 ValueMetaString (org.pentaho.di.core.row.value.ValueMetaString)10 StepMeta (org.pentaho.di.trans.step.StepMeta)10 KettleException (org.pentaho.di.core.exception.KettleException)9 IMetaStoreElementType (org.pentaho.metastore.api.IMetaStoreElementType)9 Node (org.w3c.dom.Node)8 ArrayList (java.util.ArrayList)7 Variables (org.pentaho.di.core.variables.Variables)7 PushDownOptimizationMeta (org.pentaho.di.trans.dataservice.optimization.PushDownOptimizationMeta)7 MetaStoreException (org.pentaho.metastore.api.exceptions.MetaStoreException)7 IMetaStoreElement (org.pentaho.metastore.api.IMetaStoreElement)6 CheckResultInterface (org.pentaho.di.core.CheckResultInterface)5 StringObjectId (org.pentaho.di.repository.StringObjectId)5