Search in sources :

Example 71 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class ChangeAS400DBVersionMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ConnectionItem connectionItem = (ConnectionItem) item;
    DatabaseConnection connection = (DatabaseConnection) connectionItem.getConnection();
    if (connection != null) {
        if (connection.getDatabaseType().equals("AS400")) {
            if (connection.getDbVersionString() != null && connection.getDbVersionString().equals(NOTEXIST)) {
                connection.setDbVersionString(EXIST);
                try {
                    ProxyRepositoryFactory.getInstance().save(item);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                    return ExecutionResult.FAILURE;
                }
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
        } else {
            return ExecutionResult.NOTHING_TO_DO;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 72 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class QueryGuessCommandTest method generateNewTeradataQuery2.

@Test
public void generateNewTeradataQuery2() throws NoSuchMethodException, SecurityException, IllegalAccessException, IllegalArgumentException, InvocationTargetException, PersistenceException {
    ProxyRepositoryFactory repFactory = ProxyRepositoryFactory.getInstance();
    String propertyId = repFactory.getNextId();
    try {
        DatabaseConnection connection = ConnectionFactory.eINSTANCE.createDatabaseConnection();
        connection.setSID("myschema");
        Property connectionProperty = PropertiesFactory.eINSTANCE.createProperty();
        connectionProperty.setAuthor(((RepositoryContext) CoreRuntimePlugin.getInstance().getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getUser());
        connectionProperty.setVersion(VersionUtils.DEFAULT_VERSION);
        //$NON-NLS-1$
        connectionProperty.setStatusCode("");
        connectionProperty.setId(propertyId);
        connectionProperty.setLabel("test_connection");
        ConnectionItem connectionItem = PropertiesFactory.eINSTANCE.createDatabaseConnectionItem();
        connectionItem.setProperty(connectionProperty);
        connectionItem.setConnection(connection);
        repFactory.create(connectionItem, new Path(""));
        node = Mockito.mock(INode.class);
        connection.setContextMode(true);
        TdTable table = RelationalFactory.eINSTANCE.createTdTable();
        table.setName("tableName");
        table.setLabel("tableLabel");
        TdColumn column1 = RelationalFactory.eINSTANCE.createTdColumn();
        column1.setName("id");
        TdColumn column2 = RelationalFactory.eINSTANCE.createTdColumn();
        column2.setName("name");
        table.getColumns().add(column1);
        table.getColumns().add(column2);
        metadataTable = ConvertionHelper.convert(table);
        ElementParameter parameter = new ElementParameter(node);
        parameter.setName("DBTABLE");
        parameter.setValue(table.getName());
        Mockito.when(node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName())).thenReturn("REPOSITORY");
        Mockito.when(node.getElementParameterFromField(EParameterFieldType.DBTABLE)).thenReturn(parameter);
        ElementParameter connectionId = new ElementParameter(node);
        connectionId.setValue(connectionProperty.getId());
        Mockito.when(node.getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())).thenReturn(connectionId);
        // test case 1
        String schema = "";
        String dbType = EDatabaseTypeName.TERADATA.getDisplayName();
        String expectedQuery = "\"SELECT myschema.tableName.\\\"id\\\", myschema.tableName.name FROM myschema.tableName\"";
        QueryGuessCommand command = new QueryGuessCommand(node, metadataTable, schema, dbType, connection);
        Method method = command.getClass().getDeclaredMethod("generateNewQuery");
        method.setAccessible(true);
        String queryString = (String) method.invoke(command);
        Assert.assertEquals(expectedQuery, queryString);
    } catch (Exception e) {
        throw e;
    } finally {
        IRepositoryViewObject lastVersion = repFactory.getLastVersion(propertyId);
        if (lastVersion != null) {
            repFactory.deleteObjectPhysical(lastVersion);
        }
    }
}
Also used : Path(org.eclipse.core.runtime.Path) INode(org.talend.core.model.process.INode) TdTable(org.talend.cwm.relational.TdTable) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException) PersistenceException(org.talend.commons.exception.PersistenceException) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) TdColumn(org.talend.cwm.relational.TdColumn) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Property(org.talend.core.model.properties.Property) Test(org.junit.Test)

Example 73 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class GenericRepositoryContentHandler method newSchemaWizard.

@Override
public IWizard newSchemaWizard(IWorkbench workbench, boolean creation, IRepositoryViewObject object, MetadataTable metadataTable, String[] existingNames, boolean forceReadOnly) {
    if (object == null) {
        return null;
    }
    IWorkbench wb = workbench;
    if (wb == null) {
        wb = PlatformUI.getWorkbench();
    }
    MetadataTable table = metadataTable;
    if (table == null && object instanceof MetadataTableRepositoryObject) {
        MetadataTableRepositoryObject metaTableRepObj = (MetadataTableRepositoryObject) object;
        table = metaTableRepObj.getTable();
    }
    if (table == null) {
        return null;
    }
    ConnectionItem connectionItem = (ConnectionItem) object.getProperty().getItem();
    table = SchemaUtils.getMetadataTable(connectionItem.getConnection(), table.getLabel(), table.eContainer().getClass());
    return new GenericSchemaWizard(wb, creation, object, connectionItem, table, forceReadOnly);
}
Also used : IWorkbench(org.eclipse.ui.IWorkbench) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) GenericSchemaWizard(org.talend.repository.generic.ui.GenericSchemaWizard) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)

Example 74 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class ChangeMSSQLDBVersionMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ConnectionItem connectionItem = (ConnectionItem) item;
    DatabaseConnection connection = (DatabaseConnection) connectionItem.getConnection();
    if (connection != null) {
        if (connection.getDatabaseType().equals("Microsoft SQL Server")) {
            if (connection.getDbVersionString() != null && connection.getDbVersionString().equals(WRONG_VERSION)) {
                connection.setDbVersionString(DEFAULT_VERSION);
                try {
                    ProxyRepositoryFactory.getInstance().save(item);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                    return ExecutionResult.FAILURE;
                }
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
        } else {
            return ExecutionResult.NOTHING_TO_DO;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) PersistenceException(org.talend.commons.exception.PersistenceException) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 75 with ConnectionItem

use of org.talend.core.model.properties.ConnectionItem in project tdi-studio-se by Talend.

the class DetecteViewImpactAction method init.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.commons.ui.swt.actions.ITreeContextualAction#init(org.eclipse.jface.viewers.TreeViewer,
     * org.eclipse.jface.viewers.IStructuredSelection)
     */
@Override
public void init(TreeViewer viewer, IStructuredSelection selection) {
    // try to check via extension point first.
    boolean canWork = UpdateManagerProviderDetector.INSTANCE.validateAction(viewer, selection);
    if (canWork) {
        setEnabled(true);
        return;
    }
    canWork = !selection.isEmpty() && selection.size() == 1;
    if (canWork) {
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        if (factory.isUserReadOnlyOnCurrentProject()) {
            canWork = false;
        } else {
            Object o = selection.getFirstElement();
            RepositoryNode node = (RepositoryNode) o;
            ENodeType nodeType = node.getType();
            switch(nodeType) {
                case REPOSITORY_ELEMENT:
                    ERepositoryObjectType objectType = node.getObjectType();
                    /*
                     * TESB-6415 if it's "CAMEL" product, then is disable
                     */
                    if (objectType != null) {
                        String[] products = objectType.getProducts();
                        if (products != null && products.length == 1 && "CAMEL".equals(products[0])) {
                            setEnabled(false);
                            return;
                        }
                    }
                    if (objectType == ERepositoryObjectType.METADATA_CON_TABLE) {
                        IRepositoryViewObject repositoryObject = node.getObject();
                        if (repositoryObject != null) {
                            Item item2 = repositoryObject.getProperty().getItem();
                            if (item2 instanceof DatabaseConnectionItem) {
                                DatabaseConnectionItem item = (DatabaseConnectionItem) repositoryObject.getProperty().getItem();
                                DatabaseConnection connection = (DatabaseConnection) item.getConnection();
                                CDCConnection cdcConns = connection.getCdcConns();
                                if (cdcConns != null) {
                                    if (repositoryObject instanceof MetadataTableRepositoryObject) {
                                        MetadataTable table = ((MetadataTableRepositoryObject) repositoryObject).getTable();
                                        String tableType = table.getTableType();
                                        canWork = RepositoryConstants.TABLE.equals(tableType);
                                        break;
                                    }
                                }
                            }
                        }
                        canWork = true;
                    } else if (objectType == ERepositoryObjectType.METADATA_CON_QUERY || objectType == ERepositoryObjectType.METADATA_CONNECTIONS || objectType == ERepositoryObjectType.METADATA_FILE_DELIMITED || objectType == ERepositoryObjectType.METADATA_FILE_POSITIONAL || objectType == ERepositoryObjectType.METADATA_FILE_REGEXP || objectType == ERepositoryObjectType.METADATA_FILE_XML || objectType == ERepositoryObjectType.METADATA_FILE_LDIF || objectType == ERepositoryObjectType.METADATA_FILE_EXCEL || objectType == ERepositoryObjectType.METADATA_SAPCONNECTIONS || objectType == ERepositoryObjectType.METADATA_FILE_EBCDIC || objectType == ERepositoryObjectType.METADATA_FILE_HL7 || objectType == ERepositoryObjectType.METADATA_VALIDATION_RULES || objectType == ERepositoryObjectType.METADATA_FILE_FTP || objectType == ERepositoryObjectType.METADATA_FILE_BRMS || objectType == ERepositoryObjectType.METADATA_MDMCONNECTION || objectType == ERepositoryObjectType.CONTEXT || objectType == ERepositoryObjectType.JOBLET) {
                        canWork = true;
                    } else if (objectType == ERepositoryObjectType.BUSINESS_PROCESS || objectType == ERepositoryObjectType.PROCESS || objectType == ERepositoryObjectType.ROUTINES || objectType == ERepositoryObjectType.PIG_UDF || objectType == ERepositoryObjectType.JOB_SCRIPT || objectType == ERepositoryObjectType.SQLPATTERNS || objectType == ERepositoryObjectType.JOB_DOC || objectType == ERepositoryObjectType.JOBLET_DOC || objectType == ERepositoryObjectType.DOCUMENTATION || objectType == ERepositoryObjectType.PROCESS_MR || objectType == ERepositoryObjectType.METADATA_CON_COLUMN || (ERepositoryObjectType.TEST_CONTAINER != null && objectType == ERepositoryObjectType.TEST_CONTAINER)) {
                        canWork = false;
                    } else {
                        Object obj = selection.getFirstElement();
                        RepositoryNode nodeObj = (RepositoryNode) obj;
                        Item item = nodeObj.getObject().getProperty().getItem();
                        if (item instanceof ConnectionItem) {
                            if (GlobalServiceRegister.getDefault().isServiceRegistered(IESBService.class)) {
                                IESBService service = (IESBService) GlobalServiceRegister.getDefault().getService(IESBService.class);
                                if (service != null) {
                                    boolean flag = service.isServiceItem(item.eClass().getClassifierID());
                                    if (flag) {
                                        canWork = false;
                                        break;
                                    }
                                }
                            }
                        }
                        for (IRepositoryContentHandler handler : RepositoryContentManager.getHandlers()) {
                            ERepositoryObjectType stype = handler.getRepositoryObjectType(item);
                            if (stype == objectType) {
                                canWork = true;
                                break;
                            }
                        }
                        if (RepositoryContentManager.getHandlers().size() < 0) {
                            canWork = false;
                        }
                    }
                    break;
                default:
                    canWork = false;
            }
            RepositoryNode parent = node.getParent();
            if (canWork && parent != null && parent.isBin()) {
                canWork = false;
            }
            if (canWork && !ProjectManager.getInstance().isInCurrentMainProject(node)) {
                canWork = false;
            }
        }
    }
    setEnabled(canWork);
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) RepositoryNode(org.talend.repository.model.RepositoryNode) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IRepositoryContentHandler(org.talend.core.model.repository.IRepositoryContentHandler) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) IESBService(org.talend.core.IESBService) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) ENodeType(org.talend.repository.model.IRepositoryNode.ENodeType) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

ConnectionItem (org.talend.core.model.properties.ConnectionItem)79 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)44 PersistenceException (org.talend.commons.exception.PersistenceException)38 Connection (org.talend.core.model.metadata.builder.connection.Connection)38 IElementParameter (org.talend.core.model.process.IElementParameter)38 Item (org.talend.core.model.properties.Item)34 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)31 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)27 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)20 ArrayList (java.util.ArrayList)19 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)19 Property (org.talend.core.model.properties.Property)17 ChangeValuesFromRepository (org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)17 RepositoryNode (org.talend.repository.model.RepositoryNode)17 INode (org.talend.core.model.process.INode)15 Node (org.talend.designer.core.ui.editor.nodes.Node)15 List (java.util.List)14 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)14 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)13 ProcessItem (org.talend.core.model.properties.ProcessItem)12