Search in sources :

Example 46 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class ElementParameterTest method main.

/**
     * DOC nrousseau Comment method "main".
     * 
     * @param args
     */
public static void main(String[] args) {
    List<IElementParameter> listParams = new ArrayList<IElementParameter>();
    ElementParameter param = new ElementParameter(null);
    //$NON-NLS-1$
    param.setName("VAR1");
    //$NON-NLS-1$
    param.setValue("value1");
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
    listParams.add(param);
    param = new ElementParameter(null);
    //$NON-NLS-1$
    param.setName("VAR2");
    //$NON-NLS-1$
    param.setValue("value2");
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
    listParams.add(param);
    param = new ElementParameter(null);
    //$NON-NLS-1$
    param.setName("VAR3");
    //$NON-NLS-1$
    param.setValue("value3");
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
    listParams.add(param);
    param = new ElementParameter(null);
    //$NON-NLS-1$
    param.setName("VAR4");
    //$NON-NLS-1$
    param.setValue("value4");
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
    listParams.add(param);
    param = new ElementParameter(null);
    //$NON-NLS-1$
    param.setName("VAR5");
    //$NON-NLS-1$
    param.setValue("value5;value6");
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsDisplayCodeName(new String[] { "VALUE1", "VALUE2", "VALUE3", "VALUE4", "VALUE5", "VALUE5_6" });
    //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ //$NON-NLS-6$
    param.setListItemsValue(new String[] { "value1", "value2", "value3", "value4", "value5", "value5;value6" });
    listParams.add(param);
    param = new ElementParameter(null);
    //$NON-NLS-1$
    param.setName("VAR6");
    param.setValue(new Boolean(true));
    listParams.add(param);
    param = new ElementParameter(null);
    //$NON-NLS-1$
    param.setName("VAR7");
    //$NON-NLS-1$
    param.setValue("value1");
    //$NON-NLS-1$ //$NON-NLS-2$
    param.setListItemsDisplayCodeName(new String[] { "POSTGRESQL", "ORACLE" });
    //$NON-NLS-1$ //$NON-NLS-2$
    param.setListItemsValue(new String[] { "value1", "value2" });
    listParams.add(param);
    ElementParameter paramToTest = new ElementParameter(null);
    //$NON-NLS-1$
    paramToTest.setName("VAR_TEST");
    Assert.assertTrue(testParam(//$NON-NLS-1$
    "((VAR1 == 'VALUE1' and VAR2 == 'VALUE2') or (VAR3 != 'VALUE3')) or (VAR4 == 'VALUE4')", //$NON-NLS-1$
    paramToTest, listParams));
    Assert.assertTrue(testParam(//$NON-NLS-1$
    "((VAR1 == 'VALUE1' AND VAR2 == 'VALUE2') OR (VAR3 != 'VALUE3')) OR (VAR4 == 'VALUE4')", //$NON-NLS-1$
    paramToTest, listParams));
    Assert.assertTrue(testParam(//$NON-NLS-1$
    "(VAR4 == 'VALUE4') or ((VAR1 == 'VALUE1' and VAR2 == 'VALUE2') or VAR3 != 'VALUE3')", //$NON-NLS-1$
    paramToTest, listParams));
    Assert.assertTrue(testParam(//$NON-NLS-1$
    "((VAR1 == 'VALUE1' and VAR2 == 'VALUE2') and (VAR3 != 'VALUE3' or VAR4 == 'VALUE4'))", //$NON-NLS-1$
    paramToTest, listParams));
    Assert.assertFalse(testParam(//$NON-NLS-1$
    "VAR4 != 'VALUE4' and (VAR2 == 'VALUE2' or VAR1 == 'VALUE1')", //$NON-NLS-1$
    paramToTest, listParams));
    //$NON-NLS-1$
    Assert.assertTrue(testParam("(VAR5 == 'VALUE5_6') and (VAR6 == 'true')", paramToTest, listParams));
    //$NON-NLS-1$
    Assert.assertTrue(testParam("VAR6 == 'true'", paramToTest, listParams));
    //$NON-NLS-1$
    Assert.assertTrue(testParam("(VAR7 == 'POSTGRESQL') or (VAR7 == 'ORACLE')", paramToTest, listParams));
}
Also used : ElementParameter(org.talend.designer.core.model.components.ElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 47 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class GenericTableUtilsTest method testGetTableValues.

@Test
public void testGetTableValues() {
    MyTestTable tableProperties = new MyTestTable("tableProp");
    List<String> columnValues = new ArrayList<String>();
    columnValues.add("Text1");
    columnValues.add("Text2");
    tableProperties.column1.setValue(columnValues);
    columnValues = new ArrayList<String>();
    columnValues.add("true");
    columnValues.add("false");
    tableProperties.column2.setValue(columnValues);
    columnValues = new ArrayList<String>();
    columnValues.add("Value1");
    columnValues.add("Value3");
    tableProperties.column3.setValue(columnValues);
    IElement elem = new FakeElement("test");
    IElementParameter tableParam = new ElementParameter(elem);
    tableParam.setName("myTable");
    IElementParameter column1 = new ElementParameter(elem);
    column1.setName("column1");
    column1.setFieldType(EParameterFieldType.TEXT);
    IElementParameter column2 = new ElementParameter(elem);
    column2.setName("column2");
    column2.setFieldType(EParameterFieldType.CHECK);
    IElementParameter column3 = new ElementParameter(elem);
    column3.setName("column3");
    column3.setFieldType(EParameterFieldType.CLOSED_LIST);
    List<String> values = new ArrayList<>();
    values.add("Value1");
    values.add("Value2");
    values.add("Value3");
    column3.setListItemsValue(values.toArray());
    List<String> codeNames = new ArrayList<>();
    codeNames.add("column1");
    codeNames.add("column2");
    codeNames.add("column3");
    tableParam.setListItemsDisplayCodeName(codeNames.toArray(new String[0]));
    List<IElementParameter> childParams = new ArrayList<>();
    childParams.add(column1);
    childParams.add(column2);
    childParams.add(column3);
    tableParam.setListItemsValue(childParams.toArray());
    List<Map<String, Object>> table = GenericTableUtils.getTableValues(tableProperties, tableParam);
    assertEquals(2, table.size());
    Map<String, Object> line1 = table.get(0);
    Map<String, Object> line2 = table.get(1);
    assertEquals("Text1", line1.get("column1"));
    assertEquals(Boolean.TRUE, line1.get("column2"));
    assertEquals("Value1", line1.get("column3"));
    assertEquals("Text2", line2.get("column1"));
    assertEquals(Boolean.FALSE, line2.get("column2"));
    assertEquals("Value3", line2.get("column3"));
}
Also used : IElement(org.talend.core.model.process.IElement) ArrayList(java.util.ArrayList) FakeElement(org.talend.designer.core.model.FakeElement) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 48 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class ComponentTest method testGetElementParameterValueFromComponentProperties.

@Test
public void testGetElementParameterValueFromComponentProperties() {
    //$NON-NLS-1$ //$NON-NLS-2$
    IComponent sfComponent = ComponentsFactoryProvider.getInstance().get("tSalesforceInput", "DI");
    INode node = new Node(sfComponent, new Process(new FakePropertyImpl()));
    ComponentProperties props = node.getComponentProperties();
    Form form = props.getForm(Form.MAIN);
    IElementParameter param = new GenericElementParameter(node, node.getComponentProperties(), form, form.getWidget("condition"), //$NON-NLS-1$
    null);
    Object obj = component.getElementParameterValueFromComponentProperties(node, param);
    Assert.assertNotNull(obj);
}
Also used : INode(org.talend.core.model.process.INode) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) IComponent(org.talend.core.model.components.IComponent) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) Test(org.junit.Test)

Example 49 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class ExpressionTest method testEvaluateDistrib_link.

@Test
public void testEvaluateDistrib_link() {
    List<IElementParameter> params = new ArrayList<>();
    ElementParameter param1 = createMockParameter("PARA1", true, null);
    params.add(param1);
    ElementParameter paramNode = mock(ElementParameter.class);
    INode testElement = mock(INode.class);
    when(paramNode.getName()).thenReturn("PARANODE");
    TextElementParameter testParam = mock(TextElementParameter.class);
    when(paramNode.getElement()).thenReturn(testElement);
    when(paramNode.getElement().getElementName()).thenReturn("testComponent");
    when(testElement.getElementParametersWithChildrens()).thenReturn((List) Arrays.asList(testParam));
    when(testParam.getVariableName()).thenReturn("__CONNECTION__");
    when(testParam.getValue()).thenReturn("relatedNode");
    INode relatedNode = mock(INode.class);
    when(relatedNode.getUniqueName()).thenReturn("relatedNode");
    when(relatedNode.getElementParameters()).thenReturn((List) params);
    IProcess process = mock(IProcess.class);
    when(process.getGeneratingNodes()).thenReturn((List) Arrays.asList(relatedNode));
    when(testElement.getProcess()).thenReturn(process);
    params.add(paramNode);
    ElementParameter distrib = createMockParameter("DISTRIBUTION", "CUSTOM");
    params.add(distrib);
    ElementParameter version = createMockParameter("HIVE_VERSION", "testVersion");
    params.add(version);
    ElementParameter invaliddistrib = createMockParameter("INVALDDISTRIB", "INVALID");
    params.add(invaliddistrib);
    assertTrue(Expression.evaluateDistrib("DISTRIB[#LINK@NODE.CONNECTION.DISTRIBUTION, #LINK@NODE.CONNECTION.HIVE_VERSION].doSupportUseDatanodeHostname[]", params, paramNode));
    assertFalse(Expression.evaluateDistrib("!DISTRIB[#LINK@NODE.CONNECTION.DISTRIBUTION, #LINK@NODE.CONNECTION.HIVE_VERSION].doSupportUseDatanodeHostname[]", params, paramNode));
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) TextElementParameter(org.talend.core.model.runprocess.shadow.TextElementParameter) INode(org.talend.core.model.process.INode) TextElementParameter(org.talend.core.model.runprocess.shadow.TextElementParameter) ArrayList(java.util.ArrayList) IElementParameter(org.talend.core.model.process.IElementParameter) IProcess(org.talend.core.model.process.IProcess) Test(org.junit.Test)

Example 50 with IElementParameter

use of org.talend.core.model.process.IElementParameter in project tdi-studio-se by Talend.

the class ExpressionTest method testIsShowFunctionClosedListItem.

@Test
public void testIsShowFunctionClosedListItem() {
    List<IElementParameter> parameters = spy(new ArrayList<IElementParameter>());
    ElementParameter param1 = createMockParameter("PARA1.VALUE1", true, null);
    ElementParameter param2 = createMockParameter("PARA1.VALUE2", false, null);
    ElementParameter param3 = createMockParameter("PARA2", false, "isShow[PARA1.VALUE1]");
    ElementParameter param4 = createMockParameter("PARA3", false, "isShow[PARA1.VALUE2]");
    updateParameters(parameters, param1, param2, param3, param4);
    assertTrue(Expression.evaluate("isShow[PARA1.VALUE1]", parameters, param3));
    assertFalse(Expression.evaluate("isShow[PARA1.VALUE2]", parameters, param4));
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) TextElementParameter(org.talend.core.model.runprocess.shadow.TextElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) Test(org.junit.Test)

Aggregations

IElementParameter (org.talend.core.model.process.IElementParameter)439 ArrayList (java.util.ArrayList)165 List (java.util.List)112 Node (org.talend.designer.core.ui.editor.nodes.Node)108 Map (java.util.Map)99 INode (org.talend.core.model.process.INode)94 HashMap (java.util.HashMap)87 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)73 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)69 Point (org.eclipse.swt.graphics.Point)57 ElementParameter (org.talend.designer.core.model.components.ElementParameter)48 ConnectionItem (org.talend.core.model.properties.ConnectionItem)45 IConnection (org.talend.core.model.process.IConnection)40 PersistenceException (org.talend.commons.exception.PersistenceException)39 Item (org.talend.core.model.properties.Item)38 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)37 IComponent (org.talend.core.model.components.IComponent)36 CCombo (org.eclipse.swt.custom.CCombo)33 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)29 Connection (org.talend.core.model.metadata.builder.connection.Connection)28