Search in sources :

Example 21 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 22 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 23 with Property

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

the class NewSalesforceWizardMigrationTask method updateMetadataTable.

@Override
protected boolean updateMetadataTable(Connection oldConnection, Connection genericConnection, ComponentProperties componentProperties) {
    boolean modified = false;
    if (oldConnection == null || genericConnection == null || componentProperties == null) {
        return modified;
    }
    Set<MetadataTable> tables = ConnectionHelper.getTables(oldConnection);
    Set<MetadataTable> newTables = new HashSet<>();
    newTables.addAll(tables);
    for (MetadataTable metaTable : newTables) {
        try {
            Object object = ReflectionUtils.newInstance(REFLECTION_SALESFORCE_MODULE_PROPERTIES, componentProperties.getClass().getClassLoader(), new Object[] { metaTable.getName() });
            if (object != null && object instanceof ComponentProperties) {
                ComponentProperties salesforceModuleProperties = (ComponentProperties) object;
                //$NON-NLS-1$
                salesforceModuleProperties.getProperties("connection").copyValuesFrom(componentProperties, true, false);
                //$NON-NLS-1$
                NamedThing tmp = salesforceModuleProperties.getProperty("moduleName");
                //$NON-NLS-1$
                ((Property) tmp).setTaggedValue(IGenericConstants.REPOSITORY_VALUE, "moduleName");
                ((Property) tmp).setValue(metaTable.getLabel());
                TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
                serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
                serializedPropsTV.setValue(salesforceModuleProperties.toSerialized());
                metaTable.getTaggedValue().add(serializedPropsTV);
                TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
                schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
                schemaPropertyTV.setValue(SCHEMA_SCHEMA);
                metaTable.getTaggedValue().add(schemaPropertyTV);
                Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(metaTable);
                salesforceModuleProperties.setValue(SCHEMA_SCHEMA, schema);
                ((orgomg.cwm.objectmodel.core.Package) genericConnection).getOwnedElement().add(metaTable);
                modified = true;
            }
        } catch (Exception e) {
            ExceptionHandler.process(e);
        }
    }
    return modified;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) NamedThing(org.talend.daikon.NamedThing) IOException(java.io.IOException) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Property(org.talend.daikon.properties.property.Property) HashSet(java.util.HashSet)

Example 24 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)

Aggregations

Property (org.talend.daikon.properties.property.Property)24 ComponentProperties (org.talend.components.api.properties.ComponentProperties)14 NamedThing (org.talend.daikon.NamedThing)12 ArrayList (java.util.ArrayList)8 SchemaProperty (org.talend.daikon.properties.property.SchemaProperty)7 List (java.util.List)5 HashMap (java.util.HashMap)4 Schema (org.apache.avro.Schema)4 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)4 Properties (org.talend.daikon.properties.Properties)4 EnumProperty (org.talend.daikon.properties.property.EnumProperty)4 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)4 Map (java.util.Map)3 PresentationItem (org.talend.daikon.properties.PresentationItem)3 Form (org.talend.daikon.properties.presentation.Form)3 IOException (java.io.IOException)2 Properties (java.util.Properties)2 PersistenceException (org.talend.commons.exception.PersistenceException)2 ComponentReferenceProperties (org.talend.components.api.properties.ComponentReferenceProperties)2 ComponentService (org.talend.components.api.service.ComponentService)2