Search in sources :

Example 46 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.

the class ComponentTest method testGetCodegenPropInfosWithoutReferenceObject.

@Test
public void testGetCodegenPropInfosWithoutReferenceObject() {
    //$NON-NLS-1$
    ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
    List<CodegenPropInfo> propInfos = component.getCodegenPropInfos(props);
    for (CodegenPropInfo propInfo : propInfos) {
        Properties properties = propInfo.props;
        if (properties instanceof ComponentReferenceProperties) {
            ComponentReferenceProperties crp = (ComponentReferenceProperties) properties;
            assertEquals(Boolean.TRUE, crp.componentInstanceId.getTaggedValue(IGenericConstants.ADD_QUOTES));
            assertEquals(Boolean.TRUE, crp.referenceDefinitionName.getTaggedValue(IGenericConstants.ADD_QUOTES));
            //please see ComponentRefController class, the reference will be set when some ui action happen, so expect the value is null as no any ui action here
            assertNull(crp.getReference());
        }
    }
}
Also used : TestProperties(org.talend.designer.core.generic.utils.TestProperties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) CodegenPropInfo(org.talend.designer.core.generic.model.Component.CodegenPropInfo) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) TestProperties(org.talend.designer.core.generic.utils.TestProperties) Properties(org.talend.daikon.properties.Properties) TestReferencedProperties(org.talend.designer.core.generic.utils.TestReferencedProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) Test(org.junit.Test)

Example 47 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties 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 48 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties 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 49 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.

the class GenericConnectionUtilTest method testSynNamePropertyWithItem.

@Test
public void testSynNamePropertyWithItem() {
    //$NON-NLS-1$
    String namePropertyValue = "test";
    //$NON-NLS-1$
    TestProperties props = (TestProperties) new TestProperties("test").init();
    props.name.setValue(namePropertyValue);
    String serializedProps = props.toSerialized();
    GenericConnectionItem testItem = createTestItem(namePropertyValue, serializedProps);
    GenericConnection testConn = (GenericConnection) testItem.getConnection();
    boolean itemChanged = GenericConnectionUtil.synNamePropertyWithItem(testItem);
    assertFalse(itemChanged);
    ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(serializedProps, testConn);
    assertEquals(namePropertyValue, componentProperties.getValuedProperty(IGenericConstants.NAME_PROPERTY).getValue());
    //$NON-NLS-1$
    String newPropertyValue = "test1";
    testItem.getProperty().setLabel(newPropertyValue);
    itemChanged = GenericConnectionUtil.synNamePropertyWithItem(testItem);
    assertTrue(itemChanged);
    componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(testConn.getCompProperties(), testConn);
    assertEquals(newPropertyValue, componentProperties.getValuedProperty(IGenericConstants.NAME_PROPERTY).getValue());
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) Test(org.junit.Test)

Example 50 with ComponentProperties

use of org.talend.components.api.properties.ComponentProperties in project tdi-studio-se by Talend.

the class GenericDragAndDropHandlerTest method testIsGenericRepositoryValue.

@Test
public void testIsGenericRepositoryValue() {
    Connection connection = mock(Connection.class);
    AbstractDragAndDropServiceHandler abstractDragAndDropServiceHandler = mock(AbstractDragAndDropServiceHandler.class);
    List<ComponentProperties> componentProsList = new ArrayList<>();
    boolean isGenericRepositoryValue = abstractDragAndDropServiceHandler.isGenericRepositoryValue(componentProsList, //$NON-NLS-1$
    "paramName1");
    assertEquals(false, isGenericRepositoryValue);
    connection = mock(GenericConnection.class);
    GenericDragAndDropHandler genericDragAndDropHandler = mock(GenericDragAndDropHandler.class);
    when(genericDragAndDropHandler.canHandle(connection)).thenReturn(true);
    //$NON-NLS-1$
    isGenericRepositoryValue = genericDragAndDropHandler.isGenericRepositoryValue(null, "paramName2");
    assertEquals(false, isGenericRepositoryValue);
// PowerMockito.mockStatic(ComponentsUtils.class);
// ComponentProperties mockComponentProperties = mock(ComponentProperties.class);
// when(ComponentsUtils.getComponentPropertiesFromSerialized(null)).thenReturn(mockComponentProperties);
// List<Property> propertyValues = new ArrayList<Property>();
// Property element = ComponentPropertyFactory.newReturnsProperty();
// propertyValues.add(element);
// when(ComponentsUtils.getAllValuedProperties(mockComponentProperties)).thenReturn(propertyValues);
//        isGenericRepositoryValue = genericDragAndDropHandler.isGenericRepositoryValue(connection, "QueryMode");//$NON-NLS-1$
// assertEquals(true, isGenericRepositoryValue);
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) ArrayList(java.util.ArrayList) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) AbstractDragAndDropServiceHandler(org.talend.core.model.utils.AbstractDragAndDropServiceHandler) Test(org.junit.Test)

Aggregations

ComponentProperties (org.talend.components.api.properties.ComponentProperties)50 ArrayList (java.util.ArrayList)14 NamedThing (org.talend.daikon.NamedThing)13 Property (org.talend.daikon.properties.property.Property)13 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)13 Form (org.talend.daikon.properties.presentation.Form)10 List (java.util.List)9 IElementParameter (org.talend.core.model.process.IElementParameter)9 INode (org.talend.core.model.process.INode)9 Properties (org.talend.daikon.properties.Properties)9 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8 Test (org.junit.Test)7 ComponentService (org.talend.components.api.service.ComponentService)7 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)7 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)7 ElementParameter (org.talend.designer.core.model.components.ElementParameter)7 Map (java.util.Map)6 Schema (org.apache.avro.Schema)6 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)6