Search in sources :

Example 1 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository in project tdi-studio-se by Talend.

the class ComponentChooseDialog method getPropertyPublicPart.

private Command getPropertyPublicPart(RepositoryNode selectedNode, IElementParameter param, Node node, ConnectionItem connectionItem) {
    param.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
    ChangeValuesFromRepository command2 = new ChangeValuesFromRepository(node, connectionItem.getConnection(), param.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
    selectedNode.getObject().getProperty().getId());
    if (selectedNode.getObject() instanceof IMetadataTable) {
        IMetadataTable metadataTable = (IMetadataTable) selectedNode.getObject();
        command2.setTable(metadataTable);
    }
    return command2;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)

Example 2 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository in project tdi-studio-se by Talend.

the class ConvertRepositoryNodeToProcessNode method convertToProcessNode.

public void convertToProcessNode(ConnectionItem connectionItem, String tableName) throws ProcessorException {
    EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(connectionItem, ERepositoryObjectType.METADATA_CONNECTIONS);
    String componentName = null;
    componentName = name.getDefaultComponentName();
    IComponent dbInputComponent = ComponentsFactoryProvider.getInstance().get(componentName, ComponentCategory.CATEGORY_4_DI.getName());
    Process process = new Process(GuessSchemaProcess.getNewmockProperty());
    node = new Node(dbInputComponent, process);
    selectedContext = node.getProcess().getContextManager().getDefaultContext();
    // TDI-20011
    IMetadataTable table = UpdateRepositoryUtils.getTableByName(connectionItem, tableName);
    if (table == null) {
        table = new MetadataTable();
        table.setTableName(tableName);
        table.setLabel(tableName);
    }
    IElementParameter propertyParam = ((Node) node).getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
    IElementParameter schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
    if (schemaParam == null) {
        schemaParam = ((Node) node).getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
    }
    String propertyId = connectionItem.getProperty().getId();
    String schema = databaseConnection.getUiSchema();
    String dbType = databaseConnection.getDatabaseType();
    //$NON-NLS-1$
    String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
    CompoundCommand cc = new CompoundCommand();
    // inital parameters command
    ChangeValuesFromRepository changeValueCommand = new ChangeValuesFromRepository(node, databaseConnection, propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
    propertyId);
    changeValueCommand.ignoreContextMode(true);
    cc.add(changeValueCommand);
    // change metadata command
    RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) node, //$NON-NLS-1$
    schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, table, null, null);
    cc.add(changeMetadataCommand);
    // guess query command
    QueryGuessCommand queryGuessCommand = new QueryGuessCommand(node, node.getMetadataList().get(0), schema, dbType, databaseConnection);
    cc.add(queryGuessCommand);
    // execute the commands
    cc.execute();
    //$NON-NLS-1$
    IElementParameter query = node.getElementParameter("QUERY");
    //
    memoSQL = query.getValue().toString();
    String memoSQLTemp = TalendTextUtils.removeQuotesIfExist(memoSQL);
    if ((memoSQLTemp == null || memoSQLTemp.equals("")) && tableName != null && !tableName.equals("")) {
        //$NON-NLS-1$
        boolean check = !Pattern.matches("^\\w+$", tableName);
        boolean isJDBCForMysql = databaseConnection.getURL() == null ? false : databaseConnection.getURL().startsWith("jdbc:mysql");
        if ((dbType.equals(EDatabaseTypeName.MYSQL.getDisplayName()) || isJDBCForMysql) && check) {
            tableName = TalendQuoteUtils.addQuotes(tableName, TalendQuoteUtils.ANTI_QUOTE);
        }
        memoSQL = "select * from " + tableName;
        memoSQL = TalendTextUtils.addSQLQuotes(memoSQL);
    }
}
Also used : RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) GuessSchemaProcess(org.talend.designer.core.ui.editor.properties.controllers.GuessSchemaProcess) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 3 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository 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 4 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository in project tdi-studio-se by Talend.

the class ComponentChooseDialog method propaHadoopCfgChanges.

/**
     * DOC ycbai Comment method "propaHadoopCfgChanges".
     *
     * <P>
     * Propagate the changes from hadoop cluster to M/R process when drag&drop hadoop subnode from repository view to
     * M/R process.
     * </P>
     *
     * @param repositoryNode
     */
private void propaHadoopCfgChanges(IRepositoryNode repositoryNode) {
    if (repositoryNode == null || repositoryNode.getObject() == null) {
        return;
    }
    IHadoopClusterService hadoopClusterService = HadoopRepositoryUtil.getHadoopClusterService();
    if (hadoopClusterService == null || !hadoopClusterService.isHadoopSubnode(repositoryNode)) {
        return;
    }
    IProcess process = editor.getProcess();
    if (!ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) && !ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
        return;
    }
    if ((process instanceof IProcess2) && (((IProcess2) process).getProperty().getItem() instanceof JobletProcessItem)) {
        return;
    }
    Item subItem = repositoryNode.getObject().getProperty().getItem();
    String propertyParamName = MR_PROPERTY_PREFIX + EParameterName.PROPERTY_TYPE.getName();
    String propertyRepTypeParamName = MR_PROPERTY_PREFIX + EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
    IElementParameter propertyParam = process.getElementParameter(propertyParamName);
    if (propertyParam == null) {
        return;
    }
    String repositoryValue = propertyParam.getRepositoryValue();
    if (repositoryValue == null) {
        return;
    }
    //$NON-NLS-1$
    String[] supportedRepositoryTypes = repositoryValue.split("\\|");
    String repositoryType = hadoopClusterService.getRepositoryTypeOfHadoopSubItem(subItem);
    if (!ArrayUtils.contains(supportedRepositoryTypes, repositoryType)) {
        return;
    }
    Item hadoopClusterItem = hadoopClusterService.getHadoopClusterBySubitemId(new Project(ProjectManager.getInstance().getProject(subItem)), subItem.getProperty().getId());
    String hadoopClusterId = hadoopClusterItem.getProperty().getId();
    if (EmfComponent.REPOSITORY.equals(propertyParam.getValue())) {
        // do nothing when select the same hadoop cluster.
        String propertyId = (String) process.getElementParameter(propertyRepTypeParamName).getValue();
        if (hadoopClusterId.equals(propertyId)) {
            return;
        }
    }
    Connection connection = ((ConnectionItem) subItem).getConnection();
    if (hadoopClusterService.hasDiffsFromClusterToProcess(subItem, process)) {
        boolean confirmUpdate = MessageDialog.openConfirm(editor.getSite().getShell(), //$NON-NLS-1$
        Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.title"), //$NON-NLS-1$
        Messages.getString("TalendEditorDropTargetListener.updateHadoopCfgDialog.msg"));
        if (confirmUpdate) {
            // Update spark mode to YARN_CLIENT if repository
            if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType()) || ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
                IElementParameter sparkLocalParam = process.getElementParameter(HadoopConstants.SPARK_LOCAL_MODE);
                IElementParameter sparkParam = process.getElementParameter(HadoopConstants.SPARK_MODE);
                if (sparkLocalParam != null && (Boolean) (sparkLocalParam.getValue())) {
                    sparkLocalParam.setValue(false);
                }
                if (sparkParam != null && !HadoopConstants.SPARK_MODE_YARN_CLIENT.equals(sparkParam.getValue())) {
                    sparkParam.setValue(HadoopConstants.SPARK_MODE_YARN_CLIENT);
                }
            }
            propertyParam.setValue(EmfComponent.REPOSITORY);
            ChangeValuesFromRepository command = new ChangeValuesFromRepository(process, connection, propertyRepTypeParamName, subItem.getProperty().getId());
            execCommandStack(command);
        }
    }
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) PolylineConnection(org.eclipse.draw2d.PolylineConnection) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) RulesItem(org.talend.core.model.properties.RulesItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) FileItem(org.talend.core.model.properties.FileItem) Project(org.talend.core.model.general.Project) IHadoopClusterService(org.talend.core.hadoop.IHadoopClusterService) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) IProcess2(org.talend.core.model.process.IProcess2) IElementParameter(org.talend.core.model.process.IElementParameter) IProcess(org.talend.core.model.process.IProcess)

Example 5 with ChangeValuesFromRepository

use of org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository in project tdi-studio-se by Talend.

the class StatsAndLogsHelper method changeRepositoryConnection.

static void changeRepositoryConnection(Element process, StatsAndLogsComposite statsComposite) {
    String propertyType = (String) ElementParameter2ParameterType.getParameterValue(process, EParameterName.PROPERTY_TYPE.getName());
    String id = (String) (ElementParameter2ParameterType.getParameterValue(process, EParameterName.PROPERTY_TYPE.getName()));
    Connection repositoryConnection = null;
    /* 16969 */
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    Item item = null;
    try {
        IRepositoryViewObject repobj = factory.getLastVersion(id);
        if (repobj != null) {
            Property tmpproperty = repobj.getProperty();
            if (tmpproperty != null) {
                item = tmpproperty.getItem();
            }
        }
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
    }
    if (item != null && item instanceof ConnectionItem) {
        repositoryConnection = ((ConnectionItem) item).getConnection();
    } else {
        repositoryConnection = null;
    }
    ChangeValuesFromRepository cmd1 = new ChangeValuesFromRepository(process, repositoryConnection, ImplicitContextLoadHelper.getExtraParameterName(EParameterName.PROPERTY_TYPE) + ":" + EParameterName.PROPERTY_TYPE.getName(), //$NON-NLS-1$
    propertyType);
    ChangeValuesFromRepository cmd2 = new ChangeValuesFromRepository(process, repositoryConnection, ImplicitContextLoadHelper.getExtraParameterName(EParameterName.PROPERTY_TYPE) + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), //$NON-NLS-1$
    id);
    AbstractMultiPageTalendEditor part = (AbstractMultiPageTalendEditor) ((IProcess2) process).getEditor();
    if (part instanceof AbstractMultiPageTalendEditor) {
        Object adapter = (part).getTalendEditor().getAdapter(CommandStack.class);
        if (adapter != null) {
            CommandStack commandStack = ((CommandStack) adapter);
            commandStack.execute(cmd1);
            commandStack.execute(cmd2);
        }
    }
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) CommandStack(org.eclipse.gef.commands.CommandStack) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ConnectionItem(org.talend.core.model.properties.ConnectionItem) AbstractMultiPageTalendEditor(org.talend.designer.core.ui.AbstractMultiPageTalendEditor) Connection(org.talend.core.model.metadata.builder.connection.Connection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

ChangeValuesFromRepository (org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository)24 IElementParameter (org.talend.core.model.process.IElementParameter)19 ConnectionItem (org.talend.core.model.properties.ConnectionItem)18 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)14 Connection (org.talend.core.model.metadata.builder.connection.Connection)13 PersistenceException (org.talend.commons.exception.PersistenceException)11 Item (org.talend.core.model.properties.Item)10 Property (org.talend.core.model.properties.Property)9 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)8 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)8 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)7 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)5 ProcessItem (org.talend.core.model.properties.ProcessItem)5 AbstractMultiPageTalendEditor (org.talend.designer.core.ui.AbstractMultiPageTalendEditor)5 CommandStack (org.eclipse.gef.commands.CommandStack)4 CDCConnection (org.talend.core.model.metadata.builder.connection.CDCConnection)4 Element (org.talend.core.model.process.Element)4 FileItem (org.talend.core.model.properties.FileItem)4 LinkRulesItem (org.talend.core.model.properties.LinkRulesItem)4 Command (org.eclipse.gef.commands.Command)3