Search in sources :

Example 31 with Property

use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.

the class Salesforce620WizardMigration method updateSubProperties.

/**
     * DOC nrousseau Comment method "updateSubProperties".
     * 
     * @param properties
     * @param newProperties
     */
private void updateSubProperties(ComponentProperties properties, ComponentProperties newProperties) {
    if (newProperties == null) {
        return;
    }
    for (NamedThing nt : properties.getProperties()) {
        if (nt instanceof Property) {
            Property property = (Property) nt;
            Object storedValue = property.getStoredValue();
            if (storedValue instanceof String) {
                String stringValue = (String) storedValue;
                if (ContextParameterUtils.isContainContextParam(stringValue)) {
                    continue;
                }
                Property newProperty = (Property) newProperties.getProperty(property.getName());
                if (newProperty != null) {
                    if (GenericTypeUtils.isBooleanType(newProperty)) {
                        if (stringValue.isEmpty()) {
                            property.setValue(Boolean.FALSE);
                        } else {
                            property.setValue(new Boolean(stringValue));
                        }
                    } else if (GenericTypeUtils.isEnumType(newProperty) && (!(newProperty instanceof EnumProperty))) {
                        property.setStoredValue(TalendQuoteUtils.removeQuotes(stringValue));
                    } else if (GenericTypeUtils.isEnumType(newProperty)) {
                        List<?> propertyPossibleValues = ((Property<?>) newProperty).getPossibleValues();
                        if (propertyPossibleValues != null) {
                            for (Object possibleValue : propertyPossibleValues) {
                                if (possibleValue.toString().equals(storedValue)) {
                                    property.setStoredValue(possibleValue);
                                    break;
                                }
                            }
                        }
                    }
                }
            } else {
                Property newProperty = (Property) newProperties.getProperty(property.getName());
                if (GenericTypeUtils.isBooleanType(newProperty)) {
                    // value can only be null (so false)
                    property.setValue(Boolean.FALSE);
                }
            }
        } else if (nt instanceof ComponentProperties) {
            updateSubProperties((ComponentProperties) nt, (ComponentProperties) newProperties.getProperty(nt.getName()));
        }
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) EnumProperty(org.talend.daikon.properties.property.EnumProperty) NamedThing(org.talend.daikon.NamedThing) Property(org.talend.daikon.properties.property.Property) EnumProperty(org.talend.daikon.properties.property.EnumProperty)

Example 32 with Property

use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.

the class GenericConnectionUtil method synNamePropertyWithItem.

/**
     * Syncronize the value of <code>name</code> property between component properties and connection item.
     * 
     * @param item the item which name property belong to.
     * @return return true if property is updated, otherwise return false;
     */
public static boolean synNamePropertyWithItem(GenericConnectionItem item) {
    GenericConnection connection = (GenericConnection) item.getConnection();
    String compPropertiesStr = connection.getCompProperties();
    if (compPropertiesStr == null) {
        return false;
    }
    ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(compPropertiesStr, connection);
    if (componentProperties == null) {
        return false;
    }
    Property nameProperty = (Property) componentProperties.getProperty(IGenericConstants.NAME_PROPERTY);
    if (nameProperty == null) {
        return false;
    }
    Object namePropertyVal = nameProperty.getValue();
    String newName = item.getProperty().getLabel();
    if (newName != null && !newName.equals(namePropertyVal)) {
        nameProperty.setValue(newName);
        connection.setCompProperties(componentProperties.toSerialized());
        return true;
    }
    return false;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Property(org.talend.daikon.properties.property.Property)

Example 33 with Property

use of org.talend.daikon.properties.property.Property in project tdi-studio-se by Talend.

the class ComponentsUtilsTest method testGetFormalPossibleValues.

@Test
public void testGetFormalPossibleValues() {
    ComponentService componentService = ComponentsUtils.getComponentService();
    //$NON-NLS-1$
    ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
    Form form = props.getForm(Form.MAIN);
    Element element = new FakeElement(form.getName());
    Widget testWidget = null;
    Property testProperty = null;
    Collection<Widget> widgets = form.getWidgets();
    Iterator<Widget> widgetsIterator = widgets.iterator();
    while (widgetsIterator.hasNext()) {
        Widget widget = widgetsIterator.next();
        NamedThing content = widget.getContent();
        if (content instanceof Property) {
            testWidget = widget;
            testProperty = (Property) content;
            break;
        }
    }
    assertNotNull(testWidget);
    assertNotNull(testProperty);
    // Test NamedThing type
    List<NamedThing> namedThings = new ArrayList<>();
    namedThings.add(new SimpleNamedThing("p1", "Test P1"));
    namedThings.add(new SimpleNamedThing("p2", "Test P2"));
    namedThings.add(new SimpleNamedThing("p3", "Test P3"));
    testProperty.setPossibleValues(namedThings);
    GenericElementParameter param = new GenericElementParameter(element, props, form, testWidget, componentService);
    param.setPossibleValues(testProperty.getPossibleValues());
    List<NamedThing> possibleValues = ComponentsUtils.getFormalPossibleValues(param);
    assertEquals(3, possibleValues.size());
    namedThings.retainAll(possibleValues);
    assertEquals(3, namedThings.size());
    // Test Integer type which is not support yet
    List<Integer> ints = new ArrayList<>();
    ints.add(1);
    ints.add(2);
    ints.add(3);
    testProperty.setPossibleValues(ints);
    param = new GenericElementParameter(element, props, form, testWidget, componentService);
    param.setPossibleValues(testProperty.getPossibleValues());
    possibleValues = ComponentsUtils.getFormalPossibleValues(param);
    assertEquals(0, possibleValues.size());
    // Test StringProperty
    testWidget = null;
    StringProperty testStringProperty = null;
    widgetsIterator = widgets.iterator();
    while (widgetsIterator.hasNext()) {
        Widget widget = widgetsIterator.next();
        NamedThing content = widget.getContent();
        if (content instanceof StringProperty) {
            testWidget = widget;
            testStringProperty = (StringProperty) content;
            break;
        }
    }
    assertNotNull(testWidget);
    assertNotNull(testStringProperty);
    testStringProperty.setPossibleNamedThingValues(namedThings);
    param = new GenericElementParameter(element, props, form, testWidget, componentService);
    param.setPossibleValues(testStringProperty.getPossibleValues());
    possibleValues = ComponentsUtils.getFormalPossibleValues(param);
    assertEquals(3, possibleValues.size());
    List<String> pvNames = new ArrayList<>();
    for (NamedThing pv : possibleValues) {
        pvNames.add(pv.getName());
    }
    for (NamedThing nt : namedThings) {
        assertTrue(pvNames.contains(nt.getName()));
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) Element(org.talend.core.model.process.Element) FakeElement(org.talend.designer.core.model.FakeElement) Widget(org.talend.daikon.properties.presentation.Widget) ArrayList(java.util.ArrayList) StringProperty(org.talend.daikon.properties.property.StringProperty) NamedThing(org.talend.daikon.NamedThing) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) FakeElement(org.talend.designer.core.model.FakeElement) SimpleNamedThing(org.talend.daikon.SimpleNamedThing) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ComponentService(org.talend.components.api.service.ComponentService) StringProperty(org.talend.daikon.properties.property.StringProperty) Property(org.talend.daikon.properties.property.Property) Test(org.junit.Test)

Example 34 with Property

use of org.talend.daikon.properties.property.Property in project components by Talend.

the class ComponentDefinitionTest method testReturnProperties.

@Test
public void testReturnProperties() {
    TestComponentDefinition tcd = new TestComponentDefinition();
    Property[] props = tcd.getReturnProperties();
    assertEquals("return1", props[0].getName());
    assertEquals(5, props.length);
    // Make sure i18N works
    assertEquals("Error Message", props[1].getDisplayName());
    assertEquals("Number of line", props[2].getDisplayName());
    assertEquals("Number of success", props[3].getDisplayName());
    assertEquals("Number of reject", props[4].getDisplayName());
}
Also used : TestComponentDefinition(org.talend.components.api.testcomponent.TestComponentDefinition) Property(org.talend.daikon.properties.property.Property) Matchers.hasProperty(org.hamcrest.Matchers.hasProperty) Test(org.junit.Test)

Example 35 with Property

use of org.talend.daikon.properties.property.Property in project components by Talend.

the class TSplunkEventCollectorTestIT method testAfterExtendedOutput.

@Test
public void testAfterExtendedOutput() throws Throwable {
    ComponentProperties props;
    props = new TSplunkEventCollectorDefinition().createProperties();
    ComponentTestUtils.checkSerialize(props, errorCollector);
    Property<Boolean> extendedOutput = (Property<Boolean>) props.getProperty("extendedOutput");
    assertEquals(true, extendedOutput.getValue());
    Form advForm = props.getForm(Form.ADVANCED);
    assertFalse(advForm.getWidget("eventsBatchSize").isHidden());
    extendedOutput.setValue(false);
    props = checkAndAfter(advForm, "extendedOutput", props);
    advForm = props.getForm(Form.ADVANCED);
    assertTrue(advForm.isRefreshUI());
    assertTrue(advForm.getWidget("eventsBatchSize").isHidden());
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form) Property(org.talend.daikon.properties.property.Property) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest)

Aggregations

Property (org.talend.daikon.properties.property.Property)42 ComponentProperties (org.talend.components.api.properties.ComponentProperties)20 NamedThing (org.talend.daikon.NamedThing)17 Form (org.talend.daikon.properties.presentation.Form)13 ArrayList (java.util.ArrayList)11 Test (org.junit.Test)10 List (java.util.List)7 Schema (org.apache.avro.Schema)7 Properties (org.talend.daikon.properties.Properties)6 SchemaProperty (org.talend.daikon.properties.property.SchemaProperty)6 PresentationItem (org.talend.daikon.properties.PresentationItem)5 StringProperty (org.talend.daikon.properties.property.StringProperty)5 HashMap (java.util.HashMap)4 SalesforceConnectionProperties (org.talend.components.salesforce.SalesforceConnectionProperties)4 TSalesforceInputProperties (org.talend.components.salesforce.tsalesforceinput.TSalesforceInputProperties)4 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)4 Map (java.util.Map)3 PropertyPathConnector (org.talend.components.api.component.PropertyPathConnector)3 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)3 SalesforceModuleProperties (org.talend.components.salesforce.SalesforceModuleProperties)3