Search in sources :

Example 61 with ComponentProperties

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

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

the class ComponentsUtilsTest method testGetParametersFromForm.

@Test
public void testGetParametersFromForm() {
    //$NON-NLS-1$
    ComponentProperties props = (ComponentProperties) new TestProperties("test").init();
    Form form = props.getForm(Form.MAIN);
    /*
         * Test wizard
         */
    Element element = new FakeElement(form.getName());
    // Test readonly case
    List<ElementParameter> parameters = ComponentsUtils.getParametersFromForm(element, false, null, props, form);
    for (ElementParameter parameter : parameters) {
        assertFalse(parameter.isReadOnly());
    }
    element.setReadOnly(true);
    parameters = ComponentsUtils.getParametersFromForm(element, false, null, props, form);
    for (ElementParameter parameter : parameters) {
        assertTrue(parameter.isReadOnly());
    }
    /*
         * Test component
         */
    // Test parameter initialization case (mainly to test ComponentsUtils.getParameterValue() method).
    checkParameterInitializationStatus(true);
    checkParameterInitializationStatus(false);
}
Also used : GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) 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) FakeElement(org.talend.designer.core.model.FakeElement) Test(org.junit.Test)

Example 63 with ComponentProperties

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

the class ComponentsUtilsTest method checkParameterInitializationStatus.

private void checkParameterInitializationStatus(boolean isInitializing) {
    INode node = createSFTestNode();
    ComponentProperties props = node.getComponentProperties();
    props.setValueEvaluator(null);
    Form form = props.getForm(Form.ADVANCED);
    List<ElementParameter> parameters = ComponentsUtils.getParametersFromForm(node, isInitializing, null, props, form);
    checkParameterInitializationStatus(parameters, isInitializing);
}
Also used : INode(org.talend.core.model.process.INode) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ComponentProperties(org.talend.components.api.properties.ComponentProperties) Form(org.talend.daikon.properties.presentation.Form)

Example 64 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 65 with ComponentProperties

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

the class RepositoryChangeMetadataCommand method execute.

@Override
public void execute() {
    node.setPropertyValue(propName, newPropValue);
    String mainSchemaParamName = DesignerUtilities.getMainSchemaParameterName(node);
    if (mainSchemaParamName.equals(propName)) {
        IElementParameter elementParameter = node.getElementParameter(propName);
        if (elementParameter != null) {
            IElementParameter schemaTypeParam = elementParameter.getParentParameter().getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
            if (schemaTypeParam != null) {
                if (newPropValue != null && !"".equals(newPropValue)) {
                    //$NON-NLS-1$
                    schemaTypeParam.setValue(EmfComponent.REPOSITORY);
                } else {
                    schemaTypeParam.setValue(EmfComponent.BUILTIN);
                }
            }
        }
    }
    if (node.isExternalNode() && !node.isELTComponent()) {
        for (IElementParameter parameter : node.getElementParameters()) {
            if (parameter.getFieldType() == EParameterFieldType.TABLE) {
                if (!node.getMetadataList().isEmpty() && !node.getMetadataList().get(0).sameMetadataAs(newOutputMetadata)) {
                    parameter.setValue(new ArrayList<Map<String, Object>>());
                }
            }
        }
    }
    // ELT Input/output component need add the schema conetxt in Context Mode
    if (node.isELTComponent()) {
        //$NON-NLS-1$
        IElementParameter schemaParam = node.getElementParameter("ELT_SCHEMA_NAME");
        if (schemaParam != null && schemaParam.getValue() != null && newPropValue != null && connection != null && connection.isContextMode() && ContextParameterUtils.isContainContextParam(schemaParam.getValue().toString())) {
            ConnectionItem connectionItem = MetadataToolHelper.getConnectionItemFromRepository(newPropValue.toString());
            ConnectionContextHelper.addContextForNodeParameter(node, connectionItem, false);
        }
    }
    // IElementParameter schemaTypeParameter =
    // node.getElementParameter(propName).getParentParameter().getChildParameters().get(
    // EParameterName.SCHEMA_TYPE.getName());
    // IElementParameter repositorySchemaTypeParameter = node.getElementParameter(propName).getParentParameter()
    // .getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
    // String schemaType = (String) schemaTypeParameter.getValue();
    // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
    // if (schemaType != null && schemaType.equals(EmfComponent.REPOSITORY)) {
    // repositorySchemaTypeParameter.setShow(true);
    // if (newRepositoryIdValue != null) {
    // oldRepositoryIdValue = (String) repositorySchemaTypeParameter.getValue();
    // repositorySchemaTypeParameter.setValue(newRepositoryIdValue);
    // }
    // } else {
    // repositorySchemaTypeParameter.setShow(false);
    // }
    // Xstream Cdc Type Mode
    boolean isXstreamCdcTypeMode = false;
    if (connection != null && connection instanceof DatabaseConnection) {
        String cdcTypeMode = ((DatabaseConnection) connection).getCdcTypeMode();
        if (CDCTypeMode.XSTREAM_MODE == CDCTypeMode.indexOf(cdcTypeMode)) {
            isXstreamCdcTypeMode = true;
        }
    }
    node.getElementParameter(EParameterName.UPDATE_COMPONENTS.getName()).setValue(true);
    String componentName = node.getComponent().getName();
    if (newOutputMetadata != null) {
        Map<String, String> addMap = newOutputMetadata.getAdditionalProperties();
        if (addMap.get(TaggedValueHelper.SYSTEMTABLENAME) != null && componentName.equals("tAS400CDC")) {
            //$NON-NLS-1$
            setDBTableFieldValue(node, addMap.get(TaggedValueHelper.SYSTEMTABLENAME), oldOutputMetadata.getTableName());
        } else if (isXstreamCdcTypeMode) {
            IElementParameter elementParameter = node.getElementParameter(propName);
            if (elementParameter != null) {
                if (oracleCdcComponent[0].equals(componentName) || oracleCdcComponent[1].equals(componentName)) {
                    IElementParameter schemaTypeParam = elementParameter.getParentParameter().getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
                    IElementParameter schemaParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                    if (schemaTypeParam != null) {
                        schemaTypeParam.setValue(EmfComponent.BUILTIN);
                        if (schemaParam != null && schemaParam.getValue() != null && schemaParam.getValue() instanceof IMetadataTable) {
                            newOutputMetadata.setListColumns((((IMetadataTable) schemaParam.getValue()).clone(true)).getListColumns());
                        }
                        if (oracleCdcComponent[1].equals(componentName)) {
                            newOutputMetadata.setListColumns(new ArrayList<IMetadataColumn>());
                        }
                    }
                }
            }
            setDBTableFieldValue(node, newOutputMetadata.getTableName(), oldOutputMetadata.getTableName());
        } else {
            setDBTableFieldValue(node, newOutputMetadata.getTableName(), oldOutputMetadata.getTableName());
        }
        //$NON-NLS-1$
        IElementParameter parameter = node.getElementParameter("SAP_FUNCTION");
        if (parameter != null) {
            setSAPFunctionName(node, parameter.getValue() == null ? null : (String) parameter.getValue());
        }
        if (newPropValue instanceof String) {
            if (orginalTable != null && orginalTable instanceof SAPBWTable) {
                String innerIOType = ((SAPBWTable) orginalTable).getInnerIOType();
                String sourceSysName = ((SAPBWTable) orginalTable).getSourceSystemName();
                IElementParameter schemaTypeParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                IMetadataTable metadataTable = null;
                if (schemaTypeParam != null) {
                    metadataTable = node.getMetadataFromConnector(schemaTypeParam.getContext());
                }
                if (metadataTable != null) {
                    if (innerIOType != null) {
                        //$NON-NLS-1$
                        IElementParameter param = node.getElementParameter("INFO_OBJECT_TYPE");
                        if (param != null) {
                            param.setValue(innerIOType);
                            metadataTable.getAdditionalProperties().put(SAPBWTableHelper.SAP_INFOOBJECT_INNER_TYPE, innerIOType);
                        }
                    }
                    if (sourceSysName != null) {
                        //$NON-NLS-1$
                        IElementParameter param = node.getElementParameter("SOURCE_SYSTEM_NAME");
                        if (param != null) {
                            param.setValue(TalendTextUtils.addQuotes(sourceSysName));
                            metadataTable.getAdditionalProperties().put(SAPBWTableHelper.SAP_DATASOURCE_SOURCESYSNAME, sourceSysName);
                        }
                    }
                }
            }
        }
        setTableRelevantParameterValues();
        if (getConnection() != null) {
            // for salesforce
            IElementParameter param = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
            if (param != null && EmfComponent.REPOSITORY.equals(param.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getValue())) {
                IElementParameter module = node.getElementParameter("module.moduleName");
                if (module != null) {
                    String repositoryValue = module.getRepositoryValue();
                    if (repositoryValue == null) {
                        List<ComponentProperties> componentProperties = null;
                        IGenericWizardService wizardService = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                            wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
                        }
                        if (wizardService != null && wizardService.isGenericConnection(getConnection())) {
                            componentProperties = wizardService.getAllComponentProperties(getConnection(), null);
                        }
                        repositoryValue = String.valueOf(RepositoryToComponentProperty.getGenericRepositoryValue(getConnection(), componentProperties, module.getName()));
                    }
                    if (repositoryValue != null) {
                        Object objectValue = RepositoryToComponentProperty.getValue(getConnection(), repositoryValue, newOutputMetadata, node.getComponent().getName());
                        if (objectValue != null) {
                            module.setValue(objectValue);
                        }
                    }
                }
            }
        }
    }
    super.setConnection(connection);
    super.execute();
    String propertyType = (String) node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName());
    if (propertyType != null) {
        if (propertyType.equals(EmfComponent.REPOSITORY)) {
            String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
            if (lastVersion == null) {
                return;
            }
            Item item = lastVersion.getProperty().getItem();
            if (item instanceof ConnectionItem) {
                List<? extends IElementParameter> elementParameters = new ArrayList(node.getElementParameters());
                for (IElementParameter param : elementParameters) {
                    if (param.getRepositoryValue() != null && !param.getRepositoryValue().equals("")) {
                        //$NON-NLS-1$
                        boolean isCustomSfConn = false;
                        if (item instanceof SalesforceSchemaConnectionItem) {
                            SalesforceSchemaConnection sfConn = (SalesforceSchemaConnection) ((SalesforceSchemaConnectionItem) item).getConnection();
                            isCustomSfConn = sfConn.isUseCustomModuleName();
                        }
                        if (//$NON-NLS-1$
                        param.getRepositoryValue().equals("TYPE") || (param.getRepositoryValue().equals("MODULENAME") && item instanceof SalesforceSchemaConnectionItem && !isCustomSfConn)) {
                            //$NON-NLS-1$
                            continue;
                        }
                        if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("XML_MAPPING")) {
                            //$NON-NLS-1$
                            List<Map<String, Object>> table = (List<Map<String, Object>>) node.getPropertyValue(param.getName());
                            IMetadataTable metaTable = node.getMetadataList().get(0);
                            RepositoryToComponentProperty.getTableXmlFileValue(((ConnectionItem) item).getConnection(), //$NON-NLS-1$
                            "XML_MAPPING", //$NON-NLS-1$
                            param, table, newOutputMetadata);
                            param.setRepositoryValueUsed(true);
                        } else {
                            if (connection != null && (xmlComponent[0].equals(componentName) || xmlComponent[1].equals(componentName) || xmlComponent[2].equals(componentName)) && connection instanceof XmlFileConnection && XmlUtil.isXSDFile(TalendQuoteUtils.removeQuotes(((XmlFileConnection) connection).getXmlFilePath())) && param.getRepositoryValue().equals("FILE_PATH")) {
                            // do nothing
                            } else {
                                Object value = RepositoryToComponentProperty.getValue(((ConnectionItem) item).getConnection(), param.getRepositoryValue(), newOutputMetadata);
                                if (value != null) {
                                    param.setValue(value);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    node.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) ArrayList(java.util.ArrayList) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) Item(org.talend.core.model.properties.Item) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) List(java.util.List) SAPBWTable(org.talend.core.model.metadata.builder.connection.SAPBWTable) Map(java.util.Map)

Aggregations

ComponentProperties (org.talend.components.api.properties.ComponentProperties)76 Test (org.junit.Test)22 Form (org.talend.daikon.properties.presentation.Form)17 Property (org.talend.daikon.properties.property.Property)17 ArrayList (java.util.ArrayList)16 NamedThing (org.talend.daikon.NamedThing)13 GenericConnection (org.talend.repository.generic.model.genericMetadata.GenericConnection)13 Properties (org.talend.daikon.properties.Properties)10 List (java.util.List)9 IElementParameter (org.talend.core.model.process.IElementParameter)9 INode (org.talend.core.model.process.INode)9 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)8 Schema (org.apache.avro.Schema)7 ComponentDefinition (org.talend.components.api.component.ComponentDefinition)7 ComponentService (org.talend.components.api.service.ComponentService)7 ComponentWizard (org.talend.components.api.wizard.ComponentWizard)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