Search in sources :

Example 6 with ElementValueType

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

the class MoveExcelSheetnameToSheetlistForJava method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() == ECodeLanguage.PERL || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        //$NON-NLS-1$
        IComponentFilter filter1 = new NameComponentFilter("tFileInputExcel");
        IComponentConversion addNewProperty = new IComponentConversion() {

            public void transform(NodeType node) {
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "SHEETLIST", "TABLE");
                List<ElementValueType> values = new ArrayList<ElementValueType>();
                ElementValueType eValue = TalendFileFactory.eINSTANCE.createElementValueType();
                //$NON-NLS-1$
                eValue.setElementRef("SHEETNAME");
                //$NON-NLS-1$
                eValue.setValue(ComponentUtilities.getNodePropertyValue(node, "SHEETNAME"));
                values.add(eValue);
                //$NON-NLS-1$
                ComponentUtilities.setNodeProperty(node, "SHEETLIST", values);
            }
        };
        //$NON-NLS-1$
        IComponentConversion removeOldProperty = new RemovePropertyComponentConversion("SHEETNAME");
        ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(addNewProperty, removeOldProperty));
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ArrayList(java.util.ArrayList) RemovePropertyComponentConversion(org.talend.core.model.components.conversions.RemovePropertyComponentConversion) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 7 with ElementValueType

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

the class MoveFileListFilemaskToFilemaskListForJava method execute.

@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    if (getProject().getLanguage() == ECodeLanguage.PERL || processType == null) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        //$NON-NLS-1$
        IComponentFilter filter1 = new NameComponentFilter("tFileList");
        IComponentConversion addNewProperty = new IComponentConversion() {

            public void transform(NodeType node) {
                //$NON-NLS-1$ //$NON-NLS-2$
                ComponentUtilities.addNodeProperty(node, "FILES", "TABLE");
                List<ElementValueType> values = new ArrayList<ElementValueType>();
                ElementValueType eValue = TalendFileFactory.eINSTANCE.createElementValueType();
                //$NON-NLS-1$
                eValue.setElementRef("FILEMASK");
                //$NON-NLS-1$
                eValue.setValue(ComponentUtilities.getNodePropertyValue(node, "FILEMASK"));
                values.add(eValue);
                //$NON-NLS-1$
                ComponentUtilities.setNodeProperty(node, "FILES", values);
            }
        };
        ModifyComponentsAction.searchAndModify(item, processType, filter1, Arrays.<IComponentConversion>asList(addNewProperty));
        return ExecutionResult.SUCCESS_WITH_ALERT;
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) ArrayList(java.util.ArrayList) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 8 with ElementValueType

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

the class CSetHeaderSupportMultiHeadersTask method cSetHeaderMigrate.

@SuppressWarnings({ "rawtypes", "unchecked" })
private void cSetHeaderMigrate(NodeType currentNode) throws PersistenceException {
    List parameters = currentNode.getElementParameter();
    String headerName = null;
    String useBean = null;
    String expression = null;
    String language = null;
    String bean = null;
    for (Object tmp : parameters) {
        ElementParameterType param = (ElementParameterType) tmp;
        String paramName = param.getName();
        if ("HEADER".equals(paramName)) {
            headerName = param.getValue();
        } else if ("USE_BEAN".equals(paramName)) {
            useBean = param.getValue();
        } else if ("BEAN".equals(paramName)) {
            bean = param.getValue();
        } else if ("LANGUAGES".equals(paramName)) {
            language = param.getValue();
        } else if ("EXPRESSION".equals(paramName)) {
            expression = param.getValue();
        }
    }
    // setName
    ElementValueType newNameValue = TalendFileFactory.eINSTANCE.createElementValueType();
    newNameValue.setElementRef("NAME");
    newNameValue.setValue(headerName);
    // set LANGUAGE
    ElementValueType newLanguageValue = TalendFileFactory.eINSTANCE.createElementValueType();
    newLanguageValue.setElementRef("LANGUAGE");
    if ("true".equals(useBean)) {
        newLanguageValue.setValue("bean");
    } else {
        newLanguageValue.setValue(language);
    }
    // set EXPRESSION
    ElementValueType newExpressionValue = TalendFileFactory.eINSTANCE.createElementValueType();
    newExpressionValue.setElementRef("EXPRESSION");
    if ("true".equals(useBean)) {
        newExpressionValue.setValue(bean);
    } else {
        newExpressionValue.setValue(expression);
    }
    ElementParameterType newParameter = TalendFileFactory.eINSTANCE.createElementParameterType();
    newParameter.setName("VALUES");
    newParameter.setField("TABLE");
    newParameter.getElementValue().add(newNameValue);
    newParameter.getElementValue().add(newLanguageValue);
    newParameter.getElementValue().add(newExpressionValue);
    parameters.add(newParameter);
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) List(java.util.List) ArrayList(java.util.ArrayList)

Example 9 with ElementValueType

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

the class ConsumesTypeMigrationTask method updateConsumesType.

/**
	 * Update consumes type in case POST/PUT, set default consumes type to
	 * "XML-JSON".
	 * 
	 * @param currentNode
	 *            the current node
	 * @return true, if successful
	 */
@SuppressWarnings("unchecked")
private boolean updateConsumesType(NodeType currentNode) {
    List<?> elementParameter = currentNode.getElementParameter();
    ElementParameterType schemasParam = findElementByName(elementParameter, "SCHEMAS", ElementParameterType.class);
    if (schemasParam == null) {
        return false;
    }
    @SuppressWarnings("rawtypes") List elementValues = schemasParam.getElementValue();
    ElementValueType value_HTTP_VERB = findElementByName(elementValues, "HTTP_VERB", ElementValueType.class);
    ElementValueType value_CONSUMES = findElementByName(elementValues, "CONSUMES", ElementValueType.class);
    if (value_HTTP_VERB == null || value_CONSUMES != null) {
        return false;
    }
    if (value_HTTP_VERB.getValue().equals("POST") || value_HTTP_VERB.getValue().equals("PUT")) {
        value_CONSUMES = TalendFileFactory.eINSTANCE.createElementValueType();
        value_CONSUMES.setElementRef("CONSUMES");
        value_CONSUMES.setValue("XML-JSON");
        elementValues.add(value_CONSUMES);
        return true;
    }
    return false;
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) List(java.util.List)

Example 10 with ElementValueType

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

the class FormContentTypeMigrationTask method updateFormConsumeContentTypeFor.

private void updateFormConsumeContentTypeFor(String connectorName, NodeType currentNode) {
    for (Object o : currentNode.getElementParameter()) {
        if (!(o instanceof ElementParameterType)) {
            continue;
        }
        ElementParameterType ept = (ElementParameterType) o;
        if ("SCHEMAS".equals(ept.getName())) {
            EList elementValue = ept.getElementValue();
            if (elementValue == null || elementValue.isEmpty()) {
                break;
            }
            int size = elementValue.size();
            for (int i = 0; i < size; i++) {
                ElementValueType evt = (ElementValueType) elementValue.get(i);
                if ("SCHEMA".equals(evt.getElementRef()) && connectorName.equals(evt.getValue())) {
                    /*
        				 * i+1 : HTTP_VERB i+2 : URI_PATTERN
        				 */
                    if (i + 3 == size) {
                        ElementValueType newType = TalendFileFactory.eINSTANCE.createElementValueType();
                        newType.setElementRef("CONSUMES");
                        newType.setValue("FORM");
                        elementValue.add(newType);
                    } else if (i + 3 < size && !"CONSUMES".equals((ElementValueType) elementValue.get(i + 3))) {
                        ElementValueType newType = TalendFileFactory.eINSTANCE.createElementValueType();
                        newType.setElementRef("CONSUMES");
                        newType.setValue("FORM");
                        elementValue.add(i + 3, newType);
                    }
                    break;
                }
            }
            break;
        }
    }
}
Also used : ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) EList(org.eclipse.emf.common.util.EList) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)

Aggregations

ElementValueType (org.talend.designer.core.model.utils.emf.talendfile.ElementValueType)35 ElementParameterType (org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType)28 NodeType (org.talend.designer.core.model.utils.emf.talendfile.NodeType)21 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)16 IComponentConversion (org.talend.core.model.components.conversions.IComponentConversion)15 IComponentFilter (org.talend.core.model.components.filters.IComponentFilter)15 NameComponentFilter (org.talend.core.model.components.filters.NameComponentFilter)13 ArrayList (java.util.ArrayList)12 List (java.util.List)11 EList (org.eclipse.emf.common.util.EList)8 HashMap (java.util.HashMap)7 Map (java.util.Map)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)4 ConnectionType (org.talend.designer.core.model.utils.emf.talendfile.ConnectionType)4 HashSet (java.util.HashSet)2 EObject (org.eclipse.emf.ecore.EObject)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2 RemovePropertyComponentConversion (org.talend.core.model.components.conversions.RemovePropertyComponentConversion)2