Search in sources :

Example 36 with ConnectionItem

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

the class CreateFTPConnectionAction method doRun.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.ui.actions.AContextualAction#doRun()
     */
@Override
protected void doRun() {
    RepositoryNode dbConnectionNode = getCurrentRepositoryNode();
    if (isToolbar()) {
        if (dbConnectionNode != null && dbConnectionNode.getContentType() != ERepositoryObjectType.METADATA_FILE_FTP) {
            dbConnectionNode = null;
        }
        if (dbConnectionNode == null) {
            dbConnectionNode = getRepositoryNodeForDefault(ERepositoryObjectType.METADATA_FILE_FTP);
        }
    }
    RepositoryNode metadataNode = dbConnectionNode.getParent();
    if (metadataNode != null) {
        // Force focus to the repositoryView and open Metadata and DbConnection nodes
        IRepositoryView viewPart = getViewPart();
        if (viewPart != null) {
            viewPart.setFocus();
            viewPart.expand(metadataNode, true);
            viewPart.expand(dbConnectionNode, true);
        }
    }
    FTPConnection connection = null;
    IPath pathToSave = null;
    // Define the RepositoryNode, by default Metadata/DbConnection
    RepositoryNode node = dbConnectionNode;
    ISelection selection = null;
    // When the userSelection is an element of metadataNode, use it !
    if (!isToolbar()) {
        Object userSelection = ((IStructuredSelection) getSelection()).getFirstElement();
        if (userSelection instanceof RepositoryNode) {
            switch(((RepositoryNode) userSelection).getType()) {
                case REPOSITORY_ELEMENT:
                case SIMPLE_FOLDER:
                case SYSTEM_FOLDER:
                    node = (RepositoryNode) userSelection;
                    break;
            }
        }
        selection = getSelection();
    }
    boolean creation = false;
    // Define the repositoryObject DatabaseConnection and his pathToSave
    switch(node.getType()) {
        case REPOSITORY_ELEMENT:
            // pathToSave = null;
            connection = (FTPConnection) ((ConnectionItem) node.getObject().getProperty().getItem()).getConnection();
            creation = false;
            break;
        case SIMPLE_FOLDER:
            pathToSave = RepositoryNodeUtilities.getPath(node);
            connection = ConnectionFactory.eINSTANCE.createFTPConnection();
            creation = true;
            break;
        case SYSTEM_FOLDER:
            //$NON-NLS-1$
            pathToSave = new Path("");
            connection = ConnectionFactory.eINSTANCE.createFTPConnection();
            creation = true;
            break;
    }
    // Init the content of the Wizard
    init(node);
    FTPWizard ftpWizard;
    if (isToolbar()) {
        ftpWizard = new FTPWizard(PlatformUI.getWorkbench(), creation, node, getExistingNames());
        ftpWizard.setToolBar(true);
    } else {
        ftpWizard = new FTPWizard(PlatformUI.getWorkbench(), creation, selection, getExistingNames());
    }
    // Open the Wizard
    WizardDialog wizardDialog = new WizardDialog(Display.getCurrent().getActiveShell(), ftpWizard);
    wizardDialog.setPageSize(700, 550);
    wizardDialog.create();
    wizardDialog.open();
    IRepositoryView view = getViewPart();
    if (view != null) {
        view.expand(dbConnectionNode, true);
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) FTPConnectionItem(org.talend.core.model.properties.FTPConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) FTPConnection(org.talend.core.model.metadata.builder.connection.FTPConnection) FTPWizard(org.talend.repository.ftp.ui.wizards.FTPWizard) WizardDialog(org.eclipse.jface.wizard.WizardDialog)

Example 37 with ConnectionItem

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

the class NewDelimitedFileWizardMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    ComponentService service = ComponentsUtils.getComponentService();
    Properties props = getPropertiesFromFile();
    if (item instanceof ConnectionItem) {
        boolean modify = false;
        GenericConnectionItem genericConnectionItem = null;
        ConnectionItem connectionItem = (ConnectionItem) item;
        Connection connection = connectionItem.getConnection();
        // Init
        genericConnectionItem = initGenericConnectionItem(connectionItem);
        genericConnectionItem.setTypeName(TYPE_NAME);
        GenericConnection genericConnection = initGenericConnection(connection);
        initProperty(connectionItem, genericConnectionItem);
        ComponentWizard componentWizard = service.getComponentWizard(TYPE_NAME, genericConnectionItem.getProperty().getId());
        ComponentProperties componentProperties = (ComponentProperties) componentWizard.getForms().get(0).getProperties();
        componentProperties.init();
        // Update
        modify = updateComponentProperties(connection, componentProperties, props);
        genericConnection.setCompProperties(componentProperties.toSerialized());
        genericConnectionItem.setConnection(genericConnection);
        updateMetadataTable(connection, genericConnection, componentProperties);
        if (modify) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                IRepositoryViewObject object = factory.getLastVersion(item.getProperty().getId(), ERepositoryObjectType.METADATA_FILE_DELIMITED.getFolder(), ERepositoryObjectType.METADATA_FILE_DELIMITED);
                if (object != null) {
                    factory.deleteObjectPhysical(object);
                }
                if (genericConnectionItem != null && connectionItem != null) {
                    factory.create(genericConnectionItem, new Path(connectionItem.getState().getPath()), true);
                }
                return ExecutionResult.SUCCESS_WITH_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : Path(org.eclipse.core.runtime.Path) ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Properties(java.util.Properties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) IOException(java.io.IOException) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ComponentService(org.talend.components.api.service.ComponentService) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem)

Example 38 with ConnectionItem

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

the class AddContextGroupNameMigrationTask method addContextGroupName.

private boolean addContextGroupName(Item item) throws PersistenceException {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean modified = false;
    if (item instanceof ConnectionItem) {
        Connection con = ((ConnectionItem) item).getConnection();
        ContextItem originalItem = ContextUtils.getContextItemById2(con.getContextId());
        if (originalItem != null) {
            if (con.getContextName() == null || "".equals(con.getContextName())) {
                con.setContextName(originalItem.getDefaultContext());
                factory.save(item);
                modified = true;
            }
        }
    }
    return modified;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 39 with ConnectionItem

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

the class AddCopyBookXc2jFileMigrationTask method updateXc2jFilePath.

private boolean updateXc2jFilePath(Item item) throws PersistenceException, IOException {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    boolean update = false;
    if (item instanceof ConnectionItem) {
        ConnectionItem connectionItem = (ConnectionItem) item;
        Connection con = connectionItem.getConnection();
        if (con instanceof EbcdicConnection) {
            ReferenceFileItem createReferenceFileItem = null;
            // the old copybook version depands MidFile
            String midFile = ((EbcdicConnection) con).getMidFile();
            if (midFile != null) {
                File xc2jMidFile = new File(midFile);
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                if (xc2jMidFile.exists()) {
                    readXc2jFile(xc2jMidFile, baos);
                }
                // create a referenceItem first,maybe it has content,maybe is empty,decide by the midFile
                if (connectionItem.getReferenceResources().isEmpty()) {
                    createReferenceFileItem = PropertiesFactory.eINSTANCE.createReferenceFileItem();
                    ByteArray byteArray = PropertiesFactory.eINSTANCE.createByteArray();
                    createReferenceFileItem.setContent(byteArray);
                    createReferenceFileItem.setExtension("xc2j");
                    connectionItem.getReferenceResources().add(createReferenceFileItem);
                } else {
                    createReferenceFileItem = (ReferenceFileItem) connectionItem.getReferenceResources().get(0);
                }
                createReferenceFileItem.getContent().setInnerContent(baos.toByteArray());
                // create the phyhical x2cj file and set referenceFileItem content for it
                String xc2jFilePath = getReferenceXc2jFile(connectionItem).getLocation().makeAbsolute().toFile().getAbsolutePath();
                getXc2jFileFromBytes(createReferenceFileItem.getContent().getInnerContent(), xc2jFilePath);
                update = true;
            }
        }
        if (update) {
            factory.save(connectionItem, true);
        }
    }
    return update;
}
Also used : EbcdicConnection(org.talend.core.model.metadata.builder.connection.EbcdicConnection) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Connection(org.talend.core.model.metadata.builder.connection.Connection) EbcdicConnection(org.talend.core.model.metadata.builder.connection.EbcdicConnection) ByteArray(org.talend.core.model.properties.ByteArray) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 40 with ConnectionItem

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

the class ErDiagramComposite method getSqlStatement.

//$NON-NLS-1$
@SuppressWarnings("unchecked")
private String getSqlStatement() {
    //$NON-NLS-1$
    String sql = "";
    List<String> tables = new ArrayList<String>();
    List<String> columns = new ArrayList<String>();
    List<String> wheres = new ArrayList<String>();
    if (editor != null) {
        if (editor.getViewer().getContents() instanceof ErDiagramPart) {
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String schemaPrefix = "".equals(getSchema()) ? "" : getSchema() + ".";
            //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
            String schemaPrefixWithDoubleQuotes = "".equals(getSchema()) ? "" : "\"" + getSchema() + "\".";
            ErDiagramPart er = (ErDiagramPart) editor.getViewer().getContents();
            for (Object object : er.getChildren()) {
                if (object instanceof TablePart) {
                    TablePart tablePart = (TablePart) object;
                    Table table = (Table) tablePart.getModel();
                    if (TextUtil.isDoubleQuotesNeededDbType(getCurrentDbType())) {
                        //$NON-NLS-1$
                        tables.add(schemaPrefixWithDoubleQuotes + "\"" + table.getElementName() + "\"");
                    } else {
                        tables.add(schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(table.getElementName(), getCurrentDbType()));
                    }
                    boolean oracleDbType = TextUtil.isOracleDbType(getCurrentDbType());
                    for (Object obj : tablePart.getChildren()) {
                        if (obj instanceof ColumnPart) {
                            ColumnPart columnPart = (ColumnPart) obj;
                            Column column = (Column) columnPart.getModel();
                            CheckBox isSelected = columnPart.getPrimativeFigure().getFigureCustomColumnIsSelectedFigure();
                            if (isSelected != null && isSelected.isSelected() && !column.getElementName().equals("*")) {
                                //$NON-NLS-1$
                                if (TextUtil.isDoubleQuotesNeededDbType(getCurrentDbType())) {
                                    //$NON-NLS-1$
                                    columns.add(schemaPrefixWithDoubleQuotes + "\"" + table.getElementName() + "\".\"" + column.getElementName() + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                                    "\"");
                                } else {
                                    // added by hyWang
                                    String leftQuote = TalendTextUtils.getQuoteByDBType(getCurrentDbType(), true);
                                    String rightQuote = TalendTextUtils.getQuoteByDBType(getCurrentDbType(), false);
                                    String columnContent = column.getElementName();
                                    //$NON-NLS-1$
                                    Pattern pattern = Pattern.compile("\\w+");
                                    Matcher matcher = pattern.matcher(columnContent);
                                    EDatabaseTypeName dbType = EDatabaseTypeName.getTypeFromDbType(getCurrentDbType());
                                    // modify for bug 12092
                                    boolean sqlKeyword = KeywordsValidator.isSqlKeyword(column.getElementName(), dbType.getProduct());
                                    if (!matcher.matches() || (sqlKeyword && oracleDbType)) {
                                        columns.add(schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(table.getElementName(), getCurrentDbType()) + //$NON-NLS-1$
                                        "." + TalendTextUtils.addQuotesWithSpaceField(leftQuote + column.getElementName() + rightQuote, getCurrentDbType()));
                                    } else {
                                        columns.add(schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(table.getElementName(), getCurrentDbType()) + //$NON-NLS-1$
                                        "." + TalendTextUtils.addQuotesWithSpaceField(column.getElementName(), getCurrentDbType()));
                                    }
                                }
                            }
                            for (Relation rel : (List<Relation>) column.getOutputs()) {
                                Column source = rel.getSource();
                                Column target = rel.getTarget();
                                if (TextUtil.isDoubleQuotesNeededDbType(getCurrentDbType())) {
                                    String where1 = schemaPrefixWithDoubleQuotes + "\"" + source.getTable().getElementName() + //$NON-NLS-1$ //$NON-NLS-2$
                                    "\".\"" + source.getElementName() + "\"= " + schemaPrefixWithDoubleQuotes + "\"" + //$NON-NLS-1$
                                    target.getTable().getElementName() + "\".\"" + target.getElementName() + //$NON-NLS-1$ //$NON-NLS-2$
                                    "\"";
                                    if (!wheres.contains(where1)) {
                                        wheres.add(where1);
                                    }
                                } else {
                                    String where1 = schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(source.getTable().getElementName(), getCurrentDbType()) + //$NON-NLS-1$
                                    "." + TalendTextUtils.addQuotesWithSpaceField(source.getElementName(), getCurrentDbType()) + //$NON-NLS-1$
                                    "=" + schemaPrefix + TalendTextUtils.addQuotesWithSpaceField(target.getTable().getElementName(), getCurrentDbType()) + //$NON-NLS-1$
                                    "." + TalendTextUtils.addQuotesWithSpaceField(target.getElementName(), getCurrentDbType());
                                    if (!wheres.contains(where1)) {
                                        wheres.add(where1);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    // Mssql query need add catalog and schema before the table, like this "catolog.schema.table"
    Connection conn = null;
    if (rootNode != null) {
        Item connectionItem = rootNode.getObject().getProperty().getItem();
        if (connectionItem instanceof ConnectionItem) {
            conn = ((ConnectionItem) connectionItem).getConnection();
        }
    }
    if (getCurrentDbType() != null && (getCurrentDbType().equals(EDatabaseTypeName.MSSQL.getDisplayName()) || getCurrentDbType().equals(EDatabaseTypeName.MSSQL.name())) && conn != null) {
        List<String> newTables = new ArrayList<String>();
        for (String str : tables) {
            newTables.add(getMssqlCatalog(str, conn));
        }
        tables = newTables;
    }
    sql = getSelectStatement(tables, columns, wheres);
    if (sql.endsWith(",")) {
        //$NON-NLS-1$
        return sql.substring(0, sql.length() - 1);
    } else if (sql.endsWith(" and ")) {
        //$NON-NLS-1$
        return sql.substring(0, sql.length() - 5);
    }
    //$NON-NLS-1$
    return "";
}
Also used : Pattern(java.util.regex.Pattern) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Table(org.talend.sqlbuilder.erdiagram.ui.nodes.Table) Matcher(java.util.regex.Matcher) ConnectionItem(org.talend.core.model.properties.ConnectionItem) ArrayList(java.util.ArrayList) TablePart(org.talend.sqlbuilder.erdiagram.ui.parts.TablePart) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Relation(org.talend.sqlbuilder.erdiagram.ui.nodes.Relation) Column(org.talend.sqlbuilder.erdiagram.ui.nodes.Column) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) CheckBox(org.eclipse.draw2d.CheckBox) ColumnPart(org.talend.sqlbuilder.erdiagram.ui.parts.ColumnPart) List(java.util.List) ArrayList(java.util.ArrayList) EDatabaseTypeName(org.talend.core.database.EDatabaseTypeName) ErDiagramPart(org.talend.sqlbuilder.erdiagram.ui.parts.ErDiagramPart)

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