Search in sources :

Example 6 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class MultiColAnalysisCreationTest method getColumns.

/**
 * DOC scorreia Comment method "getColumn".
 *
 * @param dataManager
 * @return
 * @throws Exception
 */
private List<TdColumn> getColumns(Connection dataManager) throws Exception {
    List<Catalog> tdCatalogs = CatalogHelper.getCatalogs(dataManager.getDataPackage());
    Catalog catalog = null;
    for (Catalog tdCatalog : tdCatalogs) {
        if (CATALOG.equals(tdCatalog.getName())) {
            catalog = tdCatalog;
            break;
        }
    }
    Assert.assertNotNull(catalog);
    Assert.assertFalse(tdCatalogs.isEmpty());
    // $NON-NLS-1$
    System.out.println("analysed Catalog: " + catalog.getName());
    List<TdTable> tables = DqRepositoryViewService.getTables(dataManager, catalog, TABLE, true, false);
    // store tables in catalog
    CatalogHelper.addTables(tables, catalog);
    Assert.assertFalse(tables.isEmpty());
    TdTable tdTable = tables.get(0);
    // $NON-NLS-1$
    System.out.println("analyzed Table: " + tdTable.getName());
    List<TdColumn> columns;
    columns = DqRepositoryViewService.getColumns(dataManager, tdTable, null, true);
    // MOD scorreia 2009-01-29 columns are stored in the table
    // TableHelper.addColumns(tdTable, columns);
    Assert.assertFalse(columns.isEmpty());
    List<TdColumn> usedCols = new ArrayList<TdColumn>();
    for (TdColumn tdColumn : columns) {
        for (String c : COLUMNS) {
            if (tdColumn.getName().equals(c)) {
                usedCols.add(tdColumn);
            }
        }
    }
    // set DM type for each used column
    for (TdColumn tdColumn : usedCols) {
        final int javaType = tdColumn.getJavaType();
        if (Java2SqlType.isNumbericInSQL(javaType)) {
            MetadataHelper.setDataminingType(DataminingType.INTERVAL, tdColumn);
        } else if (Java2SqlType.isTextInSQL(javaType)) {
            MetadataHelper.setDataminingType(DataminingType.NOMINAL, tdColumn);
        }
    }
    return usedCols;
}
Also used : TdTable(org.talend.cwm.relational.TdTable) TdColumn(org.talend.cwm.relational.TdColumn) ArrayList(java.util.ArrayList) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 7 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class ExportConnectionToTOSActionRealTest method addCataPackage.

private static Catalog addCataPackage(String packageName, DatabaseConnectionItem connItem) throws PersistenceException {
    Connection connection = connItem.getConnection();
    Catalog createCatalog = CatalogHelper.createCatalog(packageName);
    ConnectionHelper.addCatalog(createCatalog, connection);
    return createCatalog;
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 8 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class ExportConnectionToTOSActionRealTest method testRuncase2.

/**
 * Test method for {@link org.talend.dataprofiler.core.ui.action.actions.ExportConnectionToTOSAction#run()}.
 *
 * @throws PersistenceException
 *
 * case2: create new connection from schema below catalog case
 */
@Test
public void testRuncase2() throws PersistenceException {
    // connectionNode
    DatabaseConnectionItem createOldConnectionItem = createConnectionItem("ExportConnectionToTOSActionRealTest2", null, false, // $NON-NLS-1$
    true);
    initCatalogList(createOldConnectionItem);
    initSchemaOfCagalogList(createOldConnectionItem);
    IRepositoryViewObject createdByUs = factory.getLastVersion(createOldConnectionItem.getProperty().getId());
    Assert.assertTrue(createdByUs != null);
    // $NON-NLS-1$
    Assert.assertTrue("ExportConnectionToTOSActionRealTest2".equals(createdByUs.getLabel()));
    // ~connectionNode
    List<Package> packageList = new ArrayList<Package>();
    packageList.add(schema1);
    createAction = PowerMockito.spy(new ExportConnectionToTOSAction(packageList));
    PowerMockito.doNothing().when(createAction).openSuccessInformation();
    PowerMockito.doNothing().when(createAction).refreshViewerAndNode();
    createAction.run();
    IRepositoryViewObject createByAction = getNewCreatedConnectionByName(createOldConnectionItem.getConnection().getLabel() + "_" + // $NON-NLS-1$
    schema1.getName());
    DatabaseConnectionItem item = (DatabaseConnectionItem) createByAction.getProperty().getItem();
    Connection newConnection = item.getConnection();
    Catalog exportedCatalog = CatalogHelper.getCatalog(newConnection, catalog1.getName());
    Assert.assertTrue(exportedCatalog != null);
    Assert.assertTrue(newConnection.getLabel().equals(// $NON-NLS-1$
    createOldConnectionItem.getConnection().getLabel() + "_" + schema1.getName()));
    Assert.assertTrue(exportedCatalog != catalog1);
    factory.deleteObjectPhysical(createByAction);
    factory.deleteObjectPhysical(createdByUs);
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IMetadataConnection(org.talend.core.model.metadata.IMetadataConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Package(orgomg.cwm.objectmodel.core.Package) Catalog(orgomg.cwm.resource.relational.Catalog) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) Test(org.junit.Test)

Example 9 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class DBConnectionDuplicateHandleTest method compareResult.

/**
 * DOC zshen Comment method "compareResult".
 *
 * @param newConnectionItem
 * @param oldConnectionItem
 */
private void compareResult(DatabaseConnectionItem newConnectionItem, DatabaseConnectionItem oldConnectionItem) {
    Connection newConnection = newConnectionItem.getConnection();
    Connection oldConnection = oldConnectionItem.getConnection();
    // check connection has been persistenced
    Assert.assertTrue(newConnection != null);
    Assert.assertTrue(newConnection.eResource() != null);
    Assert.assertTrue(!newConnection.eIsProxy());
    Assert.assertTrue(oldConnection != null);
    Assert.assertTrue(oldConnection.eResource() != null);
    Assert.assertTrue(!oldConnection.eIsProxy());
    // check name and label has been set
    Assert.assertEquals(oldConnection.getName(), oldConnectionName);
    Assert.assertEquals(oldConnection.getLabel(), oldConnectionName);
    Assert.assertEquals(newConnection.getName(), newConnectionName);
    Assert.assertEquals(newConnection.getLabel(), newConnectionName);
    // check catalog size is same
    List<Catalog> newCatalogs = ConnectionHelper.getCatalogs(newConnection);
    List<Catalog> oldCatalogs = ConnectionHelper.getCatalogs(oldConnection);
    Assert.assertTrue(newCatalogs.size() == 2);
    Assert.assertTrue(oldCatalogs.size() == 2);
    // check the structor of connection is valid
    // $NON-NLS-1$
    Catalog oldCatalog1 = CatalogHelper.getCatalog(oldConnection, "catalog1");
    // $NON-NLS-1$
    Catalog newCatalog1 = CatalogHelper.getCatalog(newConnection, "catalog1");
    // $NON-NLS-1$
    Catalog oldCatalog2 = CatalogHelper.getCatalog(oldConnection, "catalog2");
    // $NON-NLS-1$
    Catalog newCatalog2 = CatalogHelper.getCatalog(newConnection, "catalog2");
    Assert.assertTrue(oldCatalog1 != null);
    Assert.assertTrue(newCatalog1 != null);
    Assert.assertTrue(oldCatalog2 != null);
    Assert.assertTrue(newCatalog2 != null);
}
Also used : DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Catalog(orgomg.cwm.resource.relational.Catalog)

Example 10 with Catalog

use of orgomg.cwm.resource.relational.Catalog in project tdq-studio-se by Talend.

the class AbstractCommonActionProviderRealProjectTest method testGetConnectionCase7.

/**
 * Test method for
 * {@link org.talend.dataprofiler.core.ui.action.provider.AbstractCommonActionProvider#getConnection(java.lang.Object)}
 * . case7 :input parameter is DBViewFolderRepNode
 */
@Test
public void testGetConnectionCase7() {
    // create FileConnection
    // connection
    IRepositoryViewObject lastVersion = null;
    String propertyID = createConnectionItem(connectionName, null, null);
    // $NON-NLS-1$
    Catalog createCatalog = createCatalog("catalog1");
    try {
        lastVersion = factory.getLastVersion(propertyID);
        lastVersion = new MetadataCatalogRepositoryObject(lastVersion, createCatalog);
    } catch (PersistenceException e) {
        log.error(e, e);
        Assert.fail(e.getMessage());
    }
    // ~connection data
    // ~FileConnection
    // create DFColumnFolderRepNode
    Assert.assertFalse(lastVersion == null);
    RepositoryNode dbCatalogRepNode = DQRepNodeCreateFactory.createDBCatalogRepNode(lastVersion, null, ENodeType.TDQ_REPOSITORY_ELEMENT, null);
    DBViewFolderRepNode dbViewFolderRepNode = new DBViewFolderRepNode(null, dbCatalogRepNode, null, null);
    // ~DFColumnFolderRepNode
    AbstractCommonActionProvider provider = new AbstractCommonActionProvider();
    Connection connection = provider.getConnection(dbViewFolderRepNode);
    Assert.assertTrue(connection != null);
}
Also used : IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) MetadataCatalogRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataCatalogRepositoryObject) RepositoryNode(org.talend.repository.model.RepositoryNode) Catalog(orgomg.cwm.resource.relational.Catalog) DBViewFolderRepNode(org.talend.dq.nodes.DBViewFolderRepNode) Test(org.junit.Test)

Aggregations

Catalog (orgomg.cwm.resource.relational.Catalog)106 Schema (orgomg.cwm.resource.relational.Schema)56 Connection (org.talend.core.model.metadata.builder.connection.Connection)32 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)31 ArrayList (java.util.ArrayList)28 TdTable (org.talend.cwm.relational.TdTable)27 Test (org.junit.Test)19 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 TdColumn (org.talend.cwm.relational.TdColumn)19 IRepositoryNode (org.talend.repository.model.IRepositoryNode)17 RepositoryNode (org.talend.repository.model.RepositoryNode)17 ModelElement (orgomg.cwm.objectmodel.core.ModelElement)16 Package (orgomg.cwm.objectmodel.core.Package)15 MetadataCatalogRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataCatalogRepositoryObject)12 TdExpression (org.talend.cwm.relational.TdExpression)11 EObject (org.eclipse.emf.ecore.EObject)10 Expression (orgomg.cwm.objectmodel.core.Expression)10 RegularExpression (org.talend.dataquality.domain.pattern.RegularExpression)9 List (java.util.List)8 PersistenceException (org.talend.commons.exception.PersistenceException)8