Search in sources :

Example 41 with ComponentProperties

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

the class Component method initializeParametersForSchema.

/**
     * Sometimes the property parameters of schema are base on other parameters,but they might be initialized after the
     * schema. So there need to initialize the schema's again.
     *
     */
private void initializeParametersForSchema(List<ElementParameter> listParam, final INode node) {
    ComponentProperties rootProperty = node.getComponentProperties();
    Map<String, SchemaProperty> listSchemaProperties = new HashMap<>();
    findSchemaProperties(rootProperty, listParam, listSchemaProperties, null);
    for (String paramName : listSchemaProperties.keySet()) {
        boolean found = setupConnector(node, listParam, paramName, listSchemaProperties.get(paramName), true);
        if (!found) {
            // check in the input schema
            // for now we only handle input schema named MAIN. But we will name them "FLOW" to keep
            // compatibility.
            setupConnector(node, listParam, paramName, listSchemaProperties.get(paramName), false);
        }
    }
    ElementParameter autoSwitchParam = null;
    for (ElementParameter param : listParam) {
        // TUP-4161
        if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
            ElementParameter newParam = new ElementParameter(node);
            newParam.setCategory(EComponentCategory.BASIC);
            newParam.setName(EParameterName.SCHEMA_TYPE.getName());
            newParam.setDisplayName(EParameterName.SCHEMA_TYPE.getDisplayName());
            newParam.setListItemsDisplayName(new String[] { TEXT_BUILTIN, TEXT_REPOSITORY });
            newParam.setListItemsDisplayCodeName(new String[] { BUILTIN, REPOSITORY });
            newParam.setListItemsValue(new String[] { BUILTIN, REPOSITORY });
            newParam.setValue(BUILTIN);
            newParam.setNumRow(param.getNumRow());
            newParam.setFieldType(EParameterFieldType.TECHNICAL);
            newParam.setShow(false);
            //$NON-NLS-1$ //$NON-NLS-2$
            newParam.setShowIf(param.getName() + " =='" + REPOSITORY + "'");
            newParam.setReadOnly(param.isReadOnly());
            newParam.setNotShowIf(param.getNotShowIf());
            newParam.setContext(IGenericConstants.CONTEXT);
            newParam.setSerialized(true);
            newParam.setParentParameter(param);
            newParam = new ElementParameter(node);
            newParam.setCategory(EComponentCategory.BASIC);
            newParam.setName(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            newParam.setDisplayName(EParameterName.REPOSITORY_SCHEMA_TYPE.getDisplayName());
            newParam.setListItemsDisplayName(new String[] {});
            newParam.setListItemsValue(new String[] {});
            newParam.setNumRow(param.getNumRow());
            newParam.setFieldType(EParameterFieldType.TECHNICAL);
            //$NON-NLS-1$
            newParam.setValue("");
            newParam.setShow(false);
            newParam.setRequired(true);
            newParam.setReadOnly(param.isReadOnly());
            //$NON-NLS-1$//$NON-NLS-2$
            newParam.setShowIf(param.getName() + " =='" + REPOSITORY + "'");
            newParam.setNotShowIf(param.getNotShowIf());
            newParam.setContext(IGenericConstants.CONTEXT);
            newParam.setSerialized(true);
            newParam.setParentParameter(param);
            if (autoSwitchParam == null) {
                autoSwitchParam = new ElementParameter(node);
                autoSwitchParam.setCategory(EComponentCategory.TECHNICAL);
                autoSwitchParam.setName(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
                autoSwitchParam.setDisplayName(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getDisplayName());
                autoSwitchParam.setNumRow(param.getNumRow());
                autoSwitchParam.setFieldType(EParameterFieldType.CHECK);
                autoSwitchParam.setValue(Boolean.FALSE);
                autoSwitchParam.setShow(false);
                autoSwitchParam.setRequired(true);
                autoSwitchParam.setReadOnly(true);
            }
        }
    }
    if (autoSwitchParam != null) {
        listParam.add(autoSwitchParam);
    }
}
Also used : IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ComponentProperties(org.talend.components.api.properties.ComponentProperties) SchemaProperty(org.talend.daikon.properties.property.SchemaProperty) HashMap(java.util.HashMap)

Example 42 with ComponentProperties

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

the class Component method setupConnector.

/**
     * DOC nrousseau Comment method "setupConnector".
     *
     * @param node
     * @param rootProperty
     * @param paramName
     * @param schemaProperty
     * @param found
     * @return
     */
private boolean setupConnector(final INode node, List<ElementParameter> listParam, String paramName, SchemaProperty schemaProperty, boolean isOutput) {
    ComponentProperties rootProperty = node.getComponentProperties();
    boolean found = false;
    for (Connector connector : rootProperty.getPossibleConnectors(isOutput)) {
        if (!(schemaProperty.getValue() instanceof Schema)) {
            continue;
        }
        Schema schema = schemaProperty.getValue();
        if (connector instanceof PropertyPathConnector) {
            //$NON-NLS-1$
            String linkedSchema = ((PropertyPathConnector) connector).getPropertyPath() + ".schema";
            if (paramName.equals(linkedSchema)) {
                found = true;
                ElementParameter param = new ElementParameter(node);
                param.setName(paramName);
                param.setFieldType(EParameterFieldType.SCHEMA_REFERENCE);
                param.setShow(false);
                if (!isOutput) {
                    param.setContext(EConnectionType.FLOW_MAIN.getName());
                } else {
                    param.setContext(connector.getName());
                }
                param.setCategory(EComponentCategory.TECHNICAL);
                IElementParameterDefaultValue defaultValue = new ElementParameterDefaultValue();
                defaultValue.setDefaultValue(new Schema.Parser().parse(schema.toString()));
                param.getDefaultValues().add(defaultValue);
                listParam.add(param);
            }
        }
    }
    return found;
}
Also used : PropertyPathConnector(org.talend.components.api.component.PropertyPathConnector) INodeConnector(org.talend.core.model.process.INodeConnector) Connector(org.talend.components.api.component.Connector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) IElementParameter(org.talend.core.model.process.IElementParameter) ElementParameter(org.talend.designer.core.model.components.ElementParameter) ComponentProperties(org.talend.components.api.properties.ComponentProperties) PropertyPathConnector(org.talend.components.api.component.PropertyPathConnector) IElementParameterDefaultValue(org.talend.core.model.process.IElementParameterDefaultValue) IElementParameterDefaultValue(org.talend.core.model.process.IElementParameterDefaultValue) ElementParameterDefaultValue(org.talend.designer.core.model.components.ElementParameterDefaultValue) Schema(org.apache.avro.Schema) ElementParameterParser(org.talend.core.model.process.ElementParameterParser)

Example 43 with ComponentProperties

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

the class NewNetsuiteMigrationTask method processSearchConditionsTable.

private void processSearchConditionsTable(GenericElementParameter param, ElementParameterType paramType, NamedThing target) {
    ComponentProperties searchQueryProps = (ComponentProperties) target;
    List<ElementValueType> columns = paramType.getElementValue();
    if (!(columns != null && columns.size() > 0)) {
        return;
    }
    Map<String, String> columnMapping = new HashMap<String, String>();
    columnMapping.put("INPUT_COLUMN", "field");
    columnMapping.put("OPERATOR", "operator");
    columnMapping.put("RVALUE", "value1");
    columnMapping.put("RVALUE2", "value2");
    List<String> fieldPropPossibleValues = new ArrayList<String>();
    List<Map<String, Object>> tableEntries = new ArrayList<Map<String, Object>>();
    Map<String, Object> tableEntry = null;
    for (ElementValueType column : columns) {
        String sourceName = column.getElementRef();
        if ("INPUT_COLUMN".equals(sourceName)) {
            if (tableEntry != null) {
                tableEntries.add(tableEntry);
            }
            tableEntry = new HashMap<String, Object>();
        }
        String targetName = columnMapping.get(sourceName);
        Object targetValue = column.getValue();
        if ("field".equals(targetName)) {
            String mappedFieldName = toInitialLower(targetValue.toString());
            targetValue = mappedFieldName;
            fieldPropPossibleValues.add(mappedFieldName);
        } else if ("operator".equals(targetName)) {
            String mappedOperatorName = searchOperatorMapping.get(targetValue.toString());
            if (mappedOperatorName != null) {
                targetValue = mappedOperatorName;
            }
        }
        tableEntry.put(targetName, targetValue);
    }
    tableEntries.add(tableEntry);
    GenericTableUtils.setTableValues(searchQueryProps, tableEntries, param);
    Property<String> fieldProp = (Property<String>) searchQueryProps.getProperty("field");
    fieldProp.setPossibleValues(Arrays.asList("type"));
    Property<String> operatorProp = (Property<String>) searchQueryProps.getProperty("operator");
    List<String> operatorPropPossibleValues = new ArrayList<String>(searchOperatorMapping.values());
    Collections.sort(operatorPropPossibleValues);
    operatorProp.setPossibleValues(operatorPropPossibleValues);
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ElementValueType(org.talend.designer.core.model.utils.emf.talendfile.ElementValueType) HashMap(java.util.HashMap) Map(java.util.Map) Property(org.talend.daikon.properties.property.Property)

Example 44 with ComponentProperties

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

the class Component method getRepositoryType.

@Override
public String getRepositoryType(Connection connection) {
    String propertiesStr = null;
    IGenericWizardService wizardService = null;
    if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
        wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
    }
    if (wizardService != null) {
        propertiesStr = wizardService.getConnectionProperties(connection);
    }
    ComponentProperties properties = ComponentsUtils.getComponentPropertiesFromSerialized(propertiesStr, connection, false);
    if (properties != null) {
        ComponentWizardDefinition wizardDefinition = getWizardDefinition(properties);
        if (wizardDefinition != null) {
            return wizardDefinition.getName();
        }
    }
    return null;
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition)

Example 45 with ComponentProperties

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

the class Component method getWizardDefinition.

private ComponentWizardDefinition getWizardDefinition(ComponentProperties componentProperties) {
    ComponentWizardDefinition definition = null;
    if (componentProperties == null) {
        return null;
    }
    ComponentService service = ComponentsUtils.getComponentService();
    List<ComponentWizard> componentWizards = service.getComponentWizardsForProperties(componentProperties, null);
    for (ComponentWizard componentWizard : componentWizards) {
        definition = componentWizard.getDefinition();
        // Can we ensure it is the same wizard with metadata connection wizard by this way?
        if (definition.isTopLevel()) {
            return definition;
        }
    }
    List<NamedThing> namedThings = componentProperties.getProperties();
    for (NamedThing namedThing : namedThings) {
        if (namedThing instanceof ComponentProperties) {
            definition = getWizardDefinition((ComponentProperties) namedThing);
            if (definition != null && definition.isTopLevel()) {
                return definition;
            }
        }
    }
    return null;
}
Also used : ComponentWizard(org.talend.components.api.wizard.ComponentWizard) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentWizardDefinition(org.talend.components.api.wizard.ComponentWizardDefinition) ComponentService(org.talend.components.api.service.ComponentService) NamedThing(org.talend.daikon.NamedThing)

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