Search in sources :

Example 1 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class AddPortForTCassandraConfigurationSpark method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    final ProcessType processType = getProcessType(item);
    //$NON-NLS-1$ 
    String[] compNames = { "tCassandraConfiguration" };
    IComponentConversion conversion = new IComponentConversion() {

        @Override
        public void transform(NodeType node) {
            if (node == null) {
                return;
            }
            //$NON-NLS-1$
            ElementParameterType parameter = ComponentUtilities.getNodeProperty(node, "PORT");
            List<Object> needRemovedList = new ArrayList<Object>();
            if (parameter == null) {
                // get the value of native port if the user defined it on the configuration table
                String portValue = null;
                //$NON-NLS-1$
                ElementParameterType configTable = ComponentUtilities.getNodeProperty(node, "CASSANDRA_CONFIGURATION");
                boolean findNative = false;
                boolean findRpc = false;
                for (Object e : configTable.getElementValue()) {
                    ElementValueTypeImpl el = (ElementValueTypeImpl) e;
                    if (findNative && "VALUE".equals(el.getElementRef())) {
                        //$NON-NLS-1$
                        portValue = el.getValue();
                        needRemovedList.add(e);
                        findNative = false;
                    }
                    if (findRpc && "VALUE".equals(el.getElementRef())) {
                        //$NON-NLS-1$
                        needRemovedList.add(e);
                        findRpc = false;
                    }
                    if ("KEY".equals(el.getElementRef())) {
                        //$NON-NLS-1$
                        if ("connection_native_port".equals(el.getValue())) {
                            //$NON-NLS-1$
                            findNative = true;
                            needRemovedList.add(e);
                        }
                        if ("connection_rpc_port".equals(el.getValue())) {
                            //$NON-NLS-1$
                            findRpc = true;
                            needRemovedList.add(e);
                        }
                    }
                }
                configTable.getElementValue().removeAll(needRemovedList);
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "PORT", "TEXT");
                //$NON-NLS-1$ //$NON-NLS-2$ 
                ComponentUtilities.setNodeValue(node, "PORT", portValue == null ? "\"9042\"" : portValue);
            }
        }
    };
    for (String name : compNames) {
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(conversion));
        } catch (PersistenceException e) {
            // TODO Auto-generated catch block
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) ArrayList(java.util.ArrayList) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ElementValueTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ElementValueTypeImpl) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 2 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class AddSchemaDefaultValue4tFileInputDelimited method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    IComponentFilter filter = new NameComponentFilter("tFileInputDelimited");
    try {
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            public void transform(NodeType node) {
                EList<EObject> list = node.eContents();
                for (EObject object : list) {
                    if (object instanceof MetadataType) {
                        MetadataType flow = (MetadataType) object;
                        if ("FLOW".equalsIgnoreCase(flow.getConnector())) {
                            Iterator<?> columns = flow.getColumn().iterator();
                            while (columns.hasNext()) {
                                Object outColumn = columns.next();
                                if (outColumn instanceof ColumnType) {
                                    ColumnType column = ((ColumnType) outColumn);
                                    JavaType javaType = JavaTypesManager.getJavaTypeFromId(column.getType());
                                    boolean isJavaPrimitiveType = JavaTypesManager.isJavaPrimitiveType(javaType, column.isNullable());
                                    if (isJavaPrimitiveType && (column.getDefaultValue() == null || column.getDefaultValue().isEmpty())) {
                                        String defaultValue = JavaTypesManager.getDefaultValueFromJavaType(javaType.getPrimitiveClass().getSimpleName(), null);
                                        if (defaultValue != null) {
                                            column.setDefaultValue(defaultValue);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }));
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ColumnType(org.talend.designer.core.model.utils.emf.talendfile.ColumnType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) JavaType(org.talend.core.model.metadata.types.JavaType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) EObject(org.eclipse.emf.ecore.EObject) PersistenceException(org.talend.commons.exception.PersistenceException) EObject(org.eclipse.emf.ecore.EObject) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 3 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class ChangeDefaultValueForCassandraOutputBatch method execute.

/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.talend.core.model.migration.AbstractItemMigrationTask#execute(org
	 * .talend.core.model.properties.Item)
	 */
@Override
public ExecutionResult execute(Item item) {
    final ProcessType processType = getProcessType(item);
    //$NON-NLS-1$
    String[] compNames = { "tCassandraOutput" };
    IComponentConversion conversion = new IComponentConversion() {

        @Override
        public void transform(NodeType node) {
            if (node == null) {
                return;
            }
            ElementParameterType parameter = ComponentUtilities.getNodeProperty(node, //$NON-NLS-1$
            "ASYNC");
            if (parameter == null) {
                ComponentUtilities.addNodeProperty(node, "ASYNC", //$NON-NLS-1$ //$NON-NLS-2$
                "CHECK");
                ComponentUtilities.setNodeValue(node, "ASYNC", //$NON-NLS-1$ //$NON-NLS-2$
                "false");
            }
        }
    };
    for (String name : compNames) {
        IComponentFilter filter = new NameComponentFilter(name);
        try {
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(conversion));
        } catch (PersistenceException e) {
            // TODO Auto-generated catch block
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) PersistenceException(org.talend.commons.exception.PersistenceException) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 4 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class ChangeDefaultValueFortNormalizeCSVOption method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    IComponentFilter filter = new NameComponentFilter("tNormalize");
    try {
        ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

            public void transform(NodeType node) {
                ElementParameterType useCSVOption = ComponentUtilities.getNodeProperty(node, "CSV_OPTION");
                if (useCSVOption != null && "true".equals(useCSVOption.getValue())) {
                    if (ComponentUtilities.getNodeProperty(node, "DISCARD_TRAILING_EMPTY_STR") != null) {
                        ComponentUtilities.getNodeProperty(node, "DISCARD_TRAILING_EMPTY_STR").setValue("false");
                    }
                    if (ComponentUtilities.getNodeProperty(node, "TRIM") == null) {
                        ComponentUtilities.addNodeProperty(node, "TRIM", "CHECK");
                        ComponentUtilities.getNodeProperty(node, "TRIM").setValue("true");
                    }
                }
            }
        }));
    } catch (PersistenceException e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 5 with NameComponentFilter

use of org.talend.core.model.components.filters.NameComponentFilter in project tdi-studio-se by Talend.

the class ChangeDefaultValueMigrationTaskBug8562 method execute.

/*
     * (non-Javadoc)
     * 
     * @seeorg.talend.core.model.migration.AbstractJobMigrationTask#executeOnProcess(org.talend.core.model.properties.
     * ProcessItem)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    //$NON-NLS-1$
    String[] componentsName = new String[] { "tSalesforceOutput" };
    try {
        for (int i = 0; i < componentsName.length; i++) {
            IComponentFilter filter = new NameComponentFilter(componentsName[i]);
            ModifyComponentsAction.searchAndModify(item, processType, filter, Arrays.<IComponentConversion>asList(new IComponentConversion() {

                public void transform(NodeType node) {
                    if (ComponentUtilities.getNodeProperty(node, "EXTENDINSERT") == null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$ //$NON-NLS-2$
                        ComponentUtilities.addNodeProperty(node, "EXTENDINSERT", "CHECK");
                        //$NON-NLS-1$ //$NON-NLS-2$
                        ComponentUtilities.getNodeProperty(node, "EXTENDINSERT").setValue("false");
                    }
                }
            }));
        }
        return ExecutionResult.SUCCESS_NO_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Aggregations

NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)145 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)143 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)143 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)142 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)108 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)83 PersistenceException (org.talend.commons.exception.PersistenceException)75 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)13 ArrayList (java.util.ArrayList)8 RenameComponentConversion (org.talend.core.model.components.conversions.RenameComponentConversion)6 List (java.util.List)5 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)4 RemovePropertyComponentConversion (org.talend.core.model.components.conversions.RemovePropertyComponentConversion)3 MetadataType (org.talend.designer.core.model.utils.emf.talendfile.MetadataType)3 HashMap (java.util.HashMap)2 ComponentProperties (org.talend.components.api.properties.ComponentProperties)2 AddPropertyCSVOptionConversion (org.talend.core.model.components.conversions.AddPropertyCSVOptionConversion)2 AddPropertyLoopTypeConversion (org.talend.core.model.components.conversions.AddPropertyLoopTypeConversion)2 AddQuotesInPropertyComponentConversion (org.talend.core.model.components.conversions.AddQuotesInPropertyComponentConversion)2 EConnectionType (org.talend.core.model.process.EConnectionType)2