Search in sources :

Example 86 with ElementParameterType

use of org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType in project tdi-studio-se by Talend.

the class ElementParameter2ParameterType method saveElementParameters.

/**
     * save the EMF Model's parameters to Element
     *
     * @param elem
     * @param pType
     */
public static void saveElementParameters(Element elem, ParametersType pType) {
    EList<ElementParameterType> listParamType = pType.getElementParameter();
    listParamType.clear();
    Element defaultElement = getDefaultElement(pType);
    List<? extends IElementParameter> paramList = elem.getElementParametersWithChildrens();
    for (IElementParameter param : paramList) {
        ElementParameterType type = getElemeterParameterType(param);
        IElementParameter defalutParam = defaultElement.getElementParameter(type.getName());
        if (defalutParam != null) {
            listParamType.add(type);
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) Element(org.talend.core.model.process.Element) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 87 with ElementParameterType

use of org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType in project tdi-studio-se by Talend.

the class ElementParameter2ParameterType method loadElementParameters.

/**
     *
     * load project settings to no-opened process
     *
     * @param elemParam
     * @param projectPaType
     */
public static void loadElementParameters(ParametersType processType, ParametersType projectPaType, EParameterName paramName) {
    EList listParamType = projectPaType.getElementParameter();
    for (int j = 0; j < listParamType.size(); j++) {
        ElementParameterType pType = (ElementParameterType) listParamType.get(j);
        EList processParameters = processType.getElementParameter();
        ElementParameterType processParam = null;
        for (int i = 0; i < processParameters.size(); i++) {
            ElementParameterType paramType = (ElementParameterType) processParameters.get(i);
            if (paramType.getName().equals(pType.getName()) && paramType.getField() != null && paramType.getField().equals(pType.getField())) {
                processParam = paramType;
            } else if (pType.getName().contains(":")) {
                //$NON-NLS-1$
                StringTokenizer token = new StringTokenizer(pType.getName(), ":");
                String parentId = token.nextToken();
                String childId = token.nextToken();
                String[] split = paramType.getName().split(":");
                if (split.length != 2) {
                    continue;
                }
                String complexName = paramName + ":" + childId;
                if (complexName.equals(paramType.getName())) {
                    processParam = paramType;
                }
            }
            if (processParam != null) {
                break;
            }
        }
        if (processParam != null) {
            processParam.setValue(pType.getValue());
        } else {
            TalendFileFactory fileFact = TalendFileFactory.eINSTANCE;
            ElementParameterType processTypes = fileFact.createElementParameterType();
            processTypes.setName(pType.getName());
            processTypes.setField(pType.getField());
            processTypes.setValue(pType.getValue());
            processType.getElementParameter().add(processTypes);
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) StringTokenizer(java.util.StringTokenizer) EList(org.eclipse.emf.common.util.EList) TalendFileFactory(org.talend.designer.core.model.utils.emf.talendfile.TalendFileFactory)

Example 88 with ElementParameterType

use of org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType in project tdi-studio-se by Talend.

the class ParameterUtilTool method addParameterType.

public static void addParameterType(NodeType node, String field, String name, String value, List<?> elementParameterTypes) {
    ElementParameterType paramType = createParameterType(field, name, value, elementParameterTypes);
    addParameterType(node, paramType);
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)

Example 89 with ElementParameterType

use of org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType in project tdi-studio-se by Talend.

the class NewSalesforceMigrationTask method getParameterType.

@Override
protected ElementParameterType getParameterType(NodeType node, String paramName) {
    ElementParameterType paramType = ParameterUtilTool.findParameterType(node, paramName);
    if (node != null && paramType != null) {
        Object value = ParameterUtilTool.convertParameterValue(paramType);
        if ("MODULENAME".equals(paramName) && "CustomModule".equals(value)) {
            paramName = "CUSTOM_MODULE_NAME";
            if ("tSalesforceInput".equals(node.getComponentName())) {
                paramName = "CUSTOM_MODULE";
            }
            ElementParameterType customModuleName = ParameterUtilTool.findParameterType(node, paramName);
            if (customModuleName != null) {
                paramType.setValue(StringUtils.strip(String.valueOf(ParameterUtilTool.convertParameterValue(customModuleName)), "\""));
            }
        } else if ("CONNECTION".equals(paramName) && value != null && !"".equals(value)) {
            ElementParameterType useConnection = ParameterUtilTool.findParameterType(node, "USE_EXISTING_CONNECTION");
            if (useConnection != null && Boolean.valueOf(String.valueOf(ParameterUtilTool.convertParameterValue(useConnection)))) {
                return paramType;
            } else {
                return null;
            }
        } else if ("API".equals(paramName)) {
            if ("soap".equals(value)) {
                paramType.setValue("Query");
            } else {
                paramType.setValue("Bulk");
            }
        } else if ("LOGIN_TYPE".equals(paramName)) {
            if ("BASIC".equals(value)) {
                paramType.setValue("Basic");
            } else if ("OAUTH".equals(value)) {
                paramType.setValue("OAuth");
            }
        }
    }
    return paramType;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)

Example 90 with ElementParameterType

use of org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType in project tdi-studio-se by Talend.

the class Salesforce620Migration method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() != ECodeLanguage.JAVA || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    String[] componentsName = new String[] { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceConnection", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceBulkExec", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceGetDeleted", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceGetUpdated", "tSalesforceInput", "tSalesforceOutput", "tSalesforceOutputBulk", //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    "tSalesforceOutputBulkExec" };
    IComponentConversion changeJDBCDriverJarType = new IComponentConversion() {

        @Override
        public void transform(NodeType node) {
            ElementParameterType elemParamType = ComponentUtilities.getNodeProperty(node, "PROPERTIES");
            String propertiesString = elemParamType.getValue();
            SerializerDeserializer.Deserialized<ComponentProperties> fromSerialized = Properties.Helper.fromSerializedPersistent(propertiesString, ComponentProperties.class, new PostDeserializeSetup() {

                @Override
                public void setup(Object properties) {
                    ((Properties) properties).setValueEvaluator(new PropertyValueEvaluator() {

                        @Override
                        public Object evaluate(Property property, Object storedValue) {
                            if (storedValue instanceof String) {
                                if (GenericTypeUtils.isEnumType(property)) {
                                    ComponentProperties newProperties = ComponentsUtils.getComponentProperties(node.getComponentName());
                                    Property newProperty = (Property) newProperties.getProperty(property.getName());
                                    if (newProperty == null) {
                                        newProperty = (Property) newProperties.getProperty("connection.loginType");
                                    }
                                    if (newProperty != null) {
                                        List<?> propertyPossibleValues = ((Property<?>) newProperty).getPossibleValues();
                                        if (propertyPossibleValues != null) {
                                            for (Object possibleValue : propertyPossibleValues) {
                                                if (possibleValue.toString().equals(storedValue)) {
                                                    property.setStoredValue(possibleValue);
                                                    return possibleValue;
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                            return storedValue;
                        }
                    });
                }
            });
            ComponentProperties newProperties = ComponentsUtils.getComponentProperties(node.getComponentName());
            updateSubProperties(fromSerialized.object, newProperties);
            newProperties.copyValuesFrom(fromSerialized.object, true, false);
            NamedThing nt = newProperties.getProperty("module.moduleName");
            if (nt != null && nt instanceof Property) {
                Property moduleNameProperty = (Property) nt;
                String moduleName = (String) moduleNameProperty.getValue();
                if (ContextParameterUtils.isContainContextParam(moduleName)) {
                    moduleName = TalendQuoteUtils.removeQuotes(moduleName);
                } else {
                    moduleName = TalendQuoteUtils.addPairQuotesIfNotExist(moduleName);
                }
                moduleNameProperty.setStoredValue(moduleName);
            }
            nt = newProperties.getProperty("upsertRelationTable.columnName");
            if (nt != null && nt instanceof Property) {
                Property moduleNameProperty = (Property) nt;
                if (moduleNameProperty.getPossibleValues() == null || moduleNameProperty.getPossibleValues().isEmpty()) {
                    List<String> columns = new ArrayList<String>();
                    if (moduleNameProperty.getValue() instanceof String) {
                        String column = (String) moduleNameProperty.getValue();
                        columns.add(column);
                    } else if (moduleNameProperty.getValue() instanceof List) {
                        columns.addAll((Collection<? extends String>) moduleNameProperty.getValue());
                    }
                    moduleNameProperty.setPossibleValues(columns);
                }
            }
            elemParamType.setValue(newProperties.toSerialized());
        }
    };
    boolean modified = false;
    for (Object obj : processType.getNode()) {
        if (obj != null && obj instanceof NodeType) {
            String componentName = ((NodeType) obj).getComponentName();
            if (ArrayUtils.contains(componentsName, componentName)) {
                IComponentFilter filter = new NameComponentFilter(componentName);
                modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(changeJDBCDriverJarType)) || modified;
            }
        }
    }
    if (modified) {
        try {
            ProxyRepositoryFactory.getInstance().save(item, true);
            return ExecutionResult.SUCCESS_NO_ALERT;
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_WITH_ALERT;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) ArrayList(java.util.ArrayList) PropertyValueEvaluator(org.talend.daikon.properties.property.PropertyValueEvaluator) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) NamedThing(org.talend.daikon.NamedThing) 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) PersistenceException(org.talend.commons.exception.PersistenceException) SerializerDeserializer(org.talend.daikon.serialize.SerializerDeserializer) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) Property(org.talend.daikon.properties.property.Property) EnumProperty(org.talend.daikon.properties.property.EnumProperty) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion) PostDeserializeSetup(org.talend.daikon.serialize.PostDeserializeSetup)

Aggregations

ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)197 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)126 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)114 PersistenceException (org.talend.commons.exception.PersistenceException)86 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)85 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)83 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)83 EList (org.eclipse.emf.common.util.EList)40 ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)28 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)25 List (java.util.List)22 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)19 ArrayList (java.util.ArrayList)16 ProcessItem (org.talend.core.model.properties.ProcessItem)16 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)15 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)13 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)9 HashMap (java.util.HashMap)7 IOException (java.io.IOException)6 IElementParameter (org.talend.core.model.process.IElementParameter)6