Search in sources :

Example 26 with Connection

use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.

the class ComboController method createButtonCommand.

/**
     * This method is used for "Guess Query" button.
     * 
     * @return
     */
private Command createButtonCommand() {
    IMetadataTable repositoryMetadata = null;
    IMetadataTable newRepositoryMetadata = null;
    String realTableName = null;
    String realTableId = null;
    // Only for getting the real table name.
    if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
        String paramName;
        IElementParameter repositorySchemaTypeParameter = elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        Object repositoryControl = hashCurControls.get(repositorySchemaTypeParameter.getName());
        paramName = EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
        if (repositoryControl != null) {
            String selectedComboItem = ((CCombo) repositoryControl).getText();
            if (selectedComboItem != null && selectedComboItem.length() > 0) {
                //$NON-NLS-1$
                String value = new String("");
                for (int i = 0; i < elem.getElementParameters().size(); i++) {
                    IElementParameter param = elem.getElementParameters().get(i);
                    if (param.getName().equals(paramName)) {
                        for (int j = 0; j < param.getListItemsValue().length; j++) {
                            if (selectedComboItem.equals(param.getListItemsDisplayName()[j])) {
                                value = (String) param.getListItemsValue()[j];
                            }
                        }
                    }
                }
                if (elem instanceof Node) {
                    // this.dynamicProperty.updateRepositoryList();
                    String connectionId = value.toString().split(" - ")[0];
                    String tableLabel = value.toString().split(" - ")[1];
                    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                    Item item = null;
                    try {
                        IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                        if (repobj != null) {
                            Property property = repobj.getProperty();
                            if (property != null) {
                                item = property.getItem();
                            }
                        }
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                    if (item != null && item instanceof ConnectionItem) {
                        boolean findTable = false;
                        Connection connection = ((ConnectionItem) item).getConnection();
                        for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                            if (table.getLabel().equals(tableLabel)) {
                                repositoryMetadata = ConvertionHelper.convert(table);
                                findTable = true;
                                break;
                            }
                        }
                        if (!findTable) {
                            repositoryMetadata = new MetadataTable();
                        }
                    }
                // if (repositoryTableMap.containsKey(value)) {
                // repositoryMetadata = repositoryTableMap.get(value);
                // realTableName = repositoryMetadata.getTableName();
                // realTableId = repositoryMetadata.getId();
                // } else {
                // repositoryMetadata = new MetadataTable();
                // }
                }
            }
        }
    }
    // Ends
    QueryGuessCommand cmd = null;
    INode node = null;
    if (elem instanceof INode) {
        node = (INode) elem;
    } else {
        // else instanceof Connection
        node = ((IConnection) elem).getSource();
    }
    newRepositoryMetadata = node.getMetadataList().get(0);
    if (newRepositoryMetadata == null) {
        String schemaSelected = (String) node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        if (schemaSelected != null) {
            String connectionId = schemaSelected.toString().split(" - ")[0];
            String tableLabel = schemaSelected.toString().split(" - ")[1];
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            Item item = null;
            try {
                IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        item = property.getItem();
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
            if (item != null && item instanceof ConnectionItem) {
                boolean findTable = false;
                Connection connection = ((ConnectionItem) item).getConnection();
                for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                    if (table.getLabel().equals(tableLabel)) {
                        repositoryMetadata = ConvertionHelper.convert(table);
                        findTable = true;
                        break;
                    }
                }
                if (!findTable) {
                    repositoryMetadata = new MetadataTable();
                }
            }
        // repositoryMetadata = repositoryTableMap.get(schemaSelected);
        } else if (newRepositoryMetadata == null) {
            MessageDialog.openWarning(new Shell(), Messages.getString("ComboController.alert"), //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("ComboController.nothingGuess"));
            return cmd;
        }
    }
    cmd = new QueryGuessCommand(node, newRepositoryMetadata);
    /* parameter can be null,the setMaps won't use the third parameter */
    cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(), dynamicProperty.getTableIdAndDbSchemaMap(), null);
    //$NON-NLS-1$
    String type = getValueFromRepositoryName("TYPE");
    cmd.setParameters(realTableId, realTableName, type);
    return cmd;
}
Also used : INode(org.talend.core.model.process.INode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Shell(org.eclipse.swt.widgets.Shell) CCombo(org.eclipse.swt.custom.CCombo) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 27 with Connection

use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.

the class AbstractRepositoryController method getConnection.

/**
     *
     * DOC wzhang Comment method "getConnection".
     *
     * @return
     */
private Connection getConnection() {
    if (this.elem == null) {
        return null;
    }
    if (elem instanceof Node) {
        IElementParameter elementParameter = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
        if (elementParameter != null && !EmfComponent.BUILTIN.equals(elementParameter.getValue())) {
            String propertyValue = (String) (((Node) elem).getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()));
            IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
            if (lastVersion != null) {
                final Item item = lastVersion.getProperty().getItem();
                if (item != null && item instanceof ConnectionItem) {
                    Connection repositoryConn = ((ConnectionItem) item).getConnection();
                    return repositoryConn;
                }
            }
        }
    }
    return null;
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Connection(org.talend.core.model.metadata.builder.connection.Connection) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 28 with Connection

use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.

the class JsonPathMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    boolean modified = false;
    if (item instanceof JSONFileConnectionItem) {
        Connection conn = ((JSONFileConnectionItem) item).getConnection();
        if (conn instanceof JSONFileConnection) {
            ((JSONFileConnection) conn).setReadbyMode(EJsonReadbyMode.XPATH.getValue());
            modified = true;
        }
    }
    try {
        if (modified) {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            factory.save(item, true);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) JSONFileConnection(org.talend.repository.model.json.JSONFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) JSONFileConnectionItem(org.talend.repository.model.json.JSONFileConnectionItem)

Example 29 with Connection

use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.

the class ValidationRuleTypeController method createComboCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
     * .eclipse.swt.custom.CCombo)
     */
@Override
protected Command createComboCommand(CCombo combo) {
    Connection repositoryConnection = null;
    String paramName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter param = elem.getElementParameter(paramName);
    String value = combo.getText();
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    if (value.equals(param.getValue())) {
        return null;
    }
    ChangeValuesFromRepository changeValuesFromRepository = new ChangeValuesFromRepository(elem, repositoryConnection, paramName, value);
    return changeValuesFromRepository;
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) Connection(org.talend.core.model.metadata.builder.connection.Connection) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 30 with Connection

use of org.talend.core.model.metadata.builder.connection.Connection in project tdi-studio-se by Talend.

the class NewSalesforceWizardMigrationTask 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);
        //$NON-NLS-1$
        NamedThing nt = componentProperties.getProperty("loginType");
        if (nt instanceof Property) {
            Property property = (Property) nt;
            if ("OAuth2".equals(property.getStoredValue())) {
                //$NON-NLS-1$
                List<?> propertyPossibleValues = property.getPossibleValues();
                Object newValue = null;
                if (propertyPossibleValues != null) {
                    for (Object possibleValue : propertyPossibleValues) {
                        if (possibleValue.toString().equals("OAuth")) {
                            //$NON-NLS-1$
                            newValue = possibleValue;
                            break;
                        }
                    }
                }
                if (newValue == null) {
                    // set default value
                    newValue = propertyPossibleValues.get(0);
                }
                property.setValue(newValue);
                Property<?> endpoint = componentProperties.getValuedProperty("endpoint");
                SalesforceSchemaConnection sfConnection = (SalesforceSchemaConnection) connection;
                //$NON-NLS-1$
                componentProperties.setValue("endpoint", sfConnection.getWebServiceUrlTextForOAuth());
            }
            if (GenericTypeUtils.isEnumType(property)) {
                List<?> propertyPossibleValues = ((Property<?>) property).getPossibleValues();
                if (propertyPossibleValues != null) {
                    for (Object possibleValue : propertyPossibleValues) {
                        if (possibleValue.toString().equals(property.getStoredValue())) {
                            property.setStoredValue(possibleValue);
                            break;
                        }
                    }
                }
            }
        }
        // set empty value instead of default null value, this will add automatically the double quotes in the job
        // when drag&drop metadata
        //$NON-NLS-1$ //$NON-NLS-2$
        componentProperties.setValue("userPassword.securityKey", "");
        //$NON-NLS-1$
        Property property = componentProperties.getValuedProperty("userPassword.securityKey");
        //$NON-NLS-1$
        property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, "securityKey");
        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_SALESFORCE_SCHEMA.getFolder(), ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
                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) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) Properties(java.util.Properties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) NamedThing(org.talend.daikon.NamedThing) IOException(java.io.IOException) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) 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) Property(org.talend.daikon.properties.property.Property)

Aggregations

Connection (org.talend.core.model.metadata.builder.connection.Connection)74 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)42 ConnectionItem (org.talend.core.model.properties.ConnectionItem)39 PersistenceException (org.talend.commons.exception.PersistenceException)28 IElementParameter (org.talend.core.model.process.IElementParameter)27 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)26 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)20 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)19 Item (org.talend.core.model.properties.Item)19 ArrayList (java.util.ArrayList)14 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)14 Property (org.talend.core.model.properties.Property)14 ChangeValuesFromRepository (org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)13 QueriesConnection (org.talend.core.model.metadata.builder.connection.QueriesConnection)12 XmlFileConnection (org.talend.core.model.metadata.builder.connection.XmlFileConnection)9 IConnection (org.talend.core.model.process.IConnection)9 IMetadataConnection (org.talend.core.model.metadata.IMetadataConnection)8 IDynamicProperty (org.talend.core.ui.properties.tab.IDynamicProperty)8 List (java.util.List)7 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)7