Search in sources :

Example 11 with GenericElementParameter

use of org.talend.designer.core.generic.model.GenericElementParameter in project tdi-studio-se by Talend.

the class NameAndLabelsReferenceController method createCommand.

public Command createCommand(Button button) {
    Object paramObj = button.getData(PARAM_OBJ);
    if (paramObj instanceof GenericElementParameter) {
        GenericElementParameter gParam = (GenericElementParameter) paramObj;
        if (gParam != null) {
            callBeforeActive(gParam);
            NameAndLabelsDialog nameAndLabelsDialog = new NameAndLabelsDialog(composite.getShell(), ComponentsUtils.getFormalPossibleValues(gParam), this.isInWizard());
            if (nameAndLabelsDialog.open() == IDialogConstants.OK_ID) {
                String propertyName = (String) button.getData(PARAMETER_NAME);
                String result = StringUtils.trimToEmpty(nameAndLabelsDialog.getResult());
                Text moduleText = (Text) hashCurControls.get(propertyName);
                moduleText.setText(result);
                PropertyChangeCommand pcc = new PropertyChangeCommand(elem, propertyName, result);
                return pcc;
            }
        }
    }
    return null;
}
Also used : PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) Text(org.eclipse.swt.widgets.Text)

Example 12 with GenericElementParameter

use of org.talend.designer.core.generic.model.GenericElementParameter in project tdi-studio-se by Talend.

the class NewComponentFrameworkMigrationTask method execute.

@Override
public ExecutionResult execute(final Item item) {
    final ProcessType processType = getProcessType(item);
    ComponentCategory category = ComponentCategory.getComponentCategoryFromItem(item);
    Properties props = getPropertiesFromFile();
    IComponentConversion conversion = new IComponentConversion() {

        @Override
        public void transform(NodeType nodeType) {
            if (nodeType == null || props == null) {
                return;
            }
            boolean modified = false;
            Map<String, String> schemaParamMap = new HashMap<>();
            String currComponentName = nodeType.getComponentName();
            String newComponentName = props.getProperty(currComponentName);
            nodeType.setComponentName(newComponentName);
            IComponent component = ComponentsFactoryProvider.getInstance().get(newComponentName, category.getName());
            ComponentProperties compProperties = ComponentsUtils.getComponentProperties(newComponentName);
            FakeNode fNode = new FakeNode(component);
            for (IElementParameter param : fNode.getElementParameters()) {
                if (param instanceof GenericElementParameter) {
                    String paramName = param.getName();
                    NamedThing currNamedThing = ComponentsUtils.getGenericSchemaElement(compProperties, paramName);
                    String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
                    if (oldParamName != null && !(oldParamName = oldParamName.trim()).isEmpty()) {
                        if (currNamedThing instanceof Property && (GenericTypeUtils.isSchemaType((Property<?>) currNamedThing))) {
                            schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
                        }
                        ElementParameterType paramType = getParameterType(nodeType, oldParamName);
                        if (paramType != null) {
                            if (currNamedThing instanceof ComponentReferenceProperties) {
                                ComponentReferenceProperties refProps = (ComponentReferenceProperties) currNamedThing;
                                refProps.referenceType.setValue(ComponentReferenceProperties.ReferenceType.COMPONENT_INSTANCE);
                                refProps.componentInstanceId.setStoredValue(ParameterUtilTool.convertParameterValue(paramType));
                                refProps.componentInstanceId.setTaggedValue(IGenericConstants.ADD_QUOTES, true);
                            } else {
                                processMappedElementParameter(props, nodeType, (GenericElementParameter) param, paramType, currNamedThing);
                            }
                            ParameterUtilTool.removeParameterType(nodeType, paramType);
                            modified = true;
                        }
                        if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
                            //$NON-NLS-1$
                            String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
                            //$NON-NLS-1$
                            String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                            paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
                            if (paramType != null) {
                                paramType.setName(param.getName() + schemaTypeName);
                            }
                            paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
                            if (paramType != null) {
                                paramType.setName(param.getName() + repSchemaTypeName);
                            }
                        }
                    } else {
                        processUnmappedElementParameter(props, nodeType, (GenericElementParameter) param, currNamedThing);
                    }
                } else {
                    if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
                        String paramName = param.getName();
                        schemaParamMap.put(paramName, props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName + IGenericConstants.EXP_SEPARATOR + "connector"));
                        String oldParamName = props.getProperty(currComponentName + IGenericConstants.EXP_SEPARATOR + paramName);
                        //$NON-NLS-1$
                        String schemaTypeName = ":" + EParameterName.SCHEMA_TYPE.getName();
                        //$NON-NLS-1$
                        String repSchemaTypeName = ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                        ElementParameterType paramType = getParameterType(nodeType, oldParamName + schemaTypeName);
                        if (paramType != null) {
                            paramType.setName(param.getName() + schemaTypeName);
                        }
                        paramType = getParameterType(nodeType, oldParamName + repSchemaTypeName);
                        if (paramType != null) {
                            paramType.setName(param.getName() + repSchemaTypeName);
                        }
                    }
                }
            }
            // Migrate schemas
            Map<String, MetadataType> metadatasMap = new HashMap<>();
            EList<MetadataType> metadatas = nodeType.getMetadata();
            for (MetadataType metadataType : metadatas) {
                metadatasMap.put(metadataType.getConnector(), metadataType);
            }
            Iterator<Entry<String, String>> schemaParamIter = schemaParamMap.entrySet().iterator();
            //$NON-NLS-1$
            String uniqueName = ParameterUtilTool.getParameterValue(nodeType, "UNIQUE_NAME");
            while (schemaParamIter.hasNext()) {
                Entry<String, String> schemaParamEntry = schemaParamIter.next();
                String newParamName = schemaParamEntry.getKey();
                String connectorMapping = schemaParamEntry.getValue();
                //$NON-NLS-1$
                String oldConnector = connectorMapping.split("->")[0];
                //$NON-NLS-1$
                String newConnector = connectorMapping.split("->")[1];
                MetadataType metadataType = metadatasMap.get(oldConnector);
                if (metadataType != null) {
                    metadataType.setConnector(newConnector);
                    MetadataEmfFactory factory = new MetadataEmfFactory();
                    factory.setMetadataType(metadataType);
                    IMetadataTable metadataTable = factory.getMetadataTable();
                    Schema schema = SchemaUtils.convertTalendSchemaIntoComponentSchema(ConvertionHelper.convert(metadataTable));
                    compProperties.setValue(newParamName, schema);
                }
                if (!oldConnector.equals(newConnector)) {
                    // if connector was changed, we should update the connections
                    for (Object connectionObj : processType.getConnection()) {
                        if (connectionObj instanceof ConnectionType) {
                            ConnectionType connectionType = (ConnectionType) connectionObj;
                            if (connectionType.getSource().equals(uniqueName) && connectionType.getConnectorName().equals(oldConnector)) {
                                connectionType.setConnectorName(newConnector);
                            }
                        }
                    }
                }
            }
            for (Object connectionObj : processType.getConnection()) {
                ConnectionType connection = (ConnectionType) connectionObj;
                if (connection.getSource() != null && connection.getSource().equals(uniqueName)) {
                    if (EConnectionType.FLOW_MAIN.getName().equals(connection.getConnectorName())) {
                        connection.setConnectorName(Connector.MAIN_NAME);
                    }
                }
            }
            if (modified) {
                String serializedProperties = compProperties.toSerialized();
                if (serializedProperties != null) {
                    ElementParameterType pType = //$NON-NLS-1$
                    ParameterUtilTool.createParameterType(//$NON-NLS-1$
                    null, //$NON-NLS-1$
                    "PROPERTIES", serializedProperties);
                    nodeType.getElementParameter().add(pType);
                }
            }
        }
    };
    if (processType != null) {
        boolean modified = false;
        for (Object obj : processType.getNode()) {
            if (obj != null && obj instanceof NodeType) {
                String componentName = ((NodeType) obj).getComponentName();
                String newComponentName = props.getProperty(componentName);
                if (newComponentName == null) {
                    continue;
                }
                IComponentFilter filter = new NameComponentFilter(componentName);
                modified = ModifyComponentsAction.searchAndModify((NodeType) obj, filter, Arrays.<IComponentConversion>asList(conversion)) || modified;
            }
        }
        if (modified) {
            try {
                ProxyRepositoryFactory.getInstance().save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : MetadataEmfFactory(org.talend.designer.core.model.metadata.MetadataEmfFactory) ComponentProperties(org.talend.components.api.properties.ComponentProperties) HashMap(java.util.HashMap) IComponent(org.talend.core.model.components.IComponent) Schema(org.apache.avro.Schema) NameComponentFilter(org.talend.core.model.components.filters.NameComponentFilter) Properties(java.util.Properties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) ComponentCategory(org.talend.core.model.components.ComponentCategory) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) Entry(java.util.Map.Entry) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) Property(org.talend.daikon.properties.property.Property) ConnectionType(org.talend.designer.core.model.utils.emf.talendfile.ConnectionType) EConnectionType(org.talend.core.model.process.EConnectionType) IComponentFilter(org.talend.core.model.components.filters.IComponentFilter) MetadataType(org.talend.designer.core.model.utils.emf.talendfile.MetadataType) NamedThing(org.talend.daikon.NamedThing) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) PersistenceException(org.talend.commons.exception.PersistenceException) ComponentReferenceProperties(org.talend.components.api.properties.ComponentReferenceProperties) IComponentConversion(org.talend.core.model.components.conversions.IComponentConversion)

Example 13 with GenericElementParameter

use of org.talend.designer.core.generic.model.GenericElementParameter in project tdi-studio-se by Talend.

the class SchemaUtils method updateComponentSchema.

public static void updateComponentSchema(INode node, IMetadataTable metadataTable, Boolean askPropagate) {
    if (node == null || metadataTable == null || node.getComponentProperties() == null) {
        return;
    }
    Schema schema = convertTalendSchemaIntoComponentSchema(ConvertionHelper.convert(metadataTable));
    INodeConnector connector = node.getConnectorFromName(metadataTable.getAttachedConnector());
    if (connector != null) {
        if (connector instanceof GenericNodeConnector) {
            node.getComponentProperties().setConnectedSchema(((GenericNodeConnector) connector).getComponentConnector(), schema, true);
        }
        for (IElementParameter param : new ArrayList<IElementParameter>(node.getElementParameters())) {
            if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType()) && connector.getName().equals(param.getContext())) {
                if (param instanceof GenericElementParameter) {
                    ((GenericElementParameter) param).setAskPropagate(askPropagate);
                }
                param.setValue(schema);
            }
        }
    }
}
Also used : GenericNodeConnector(org.talend.designer.core.generic.model.GenericNodeConnector) Schema(org.apache.avro.Schema) ArrayList(java.util.ArrayList) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 14 with GenericElementParameter

use of org.talend.designer.core.generic.model.GenericElementParameter in project tdi-studio-se by Talend.

the class GenericContextHandler method getContextParams.

@Override
public Set<IConnParamName> getContextParams() {
    Set<IConnParamName> contextParams = new HashSet<>();
    if (parameters != null) {
        for (IElementParameter param : parameters) {
            if (param instanceof GenericElementParameter) {
                GenericElementParameter genericElementParameter = (GenericElementParameter) param;
                if (genericElementParameter.isSupportContext()) {
                    GenericConnParamName connParamName = new GenericConnParamName();
                    String paramName = genericElementParameter.getName();
                    connParamName.setName(paramName);
                    connParamName.setContextVar(getValidContextVarName(paramName));
                    contextParams.add(connParamName);
                }
            }
        }
    }
    return contextParams;
}
Also used : GenericConnParamName(org.talend.metadata.managment.ui.utils.GenericConnParamName) GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter) IElementParameter(org.talend.core.model.process.IElementParameter) IConnParamName(org.talend.metadata.managment.ui.model.IConnParamName) HashSet(java.util.HashSet)

Example 15 with GenericElementParameter

use of org.talend.designer.core.generic.model.GenericElementParameter in project tdi-studio-se by Talend.

the class GenericDragAndDropHandler method setGenericRepositoryValue.

private void setGenericRepositoryValue(GenericConnection connection, INode node, IElementParameter param) {
    if (connection != null && param != null && param instanceof GenericElementParameter) {
        if (connection.getCompProperties() == null) {
            GenericElementParameter genericParam = (GenericElementParameter) param;
            connection.setCompProperties(genericParam.getRootProperties().toSerialized());
        }
    }
}
Also used : GenericElementParameter(org.talend.designer.core.generic.model.GenericElementParameter)

Aggregations

GenericElementParameter (org.talend.designer.core.generic.model.GenericElementParameter)20 ArrayList (java.util.ArrayList)11 IElementParameter (org.talend.core.model.process.IElementParameter)9 INode (org.talend.core.model.process.INode)8 List (java.util.List)6 ComponentProperties (org.talend.components.api.properties.ComponentProperties)6 ElementParameter (org.talend.designer.core.model.components.ElementParameter)6 ComponentReferenceProperties (org.talend.components.api.properties.ComponentReferenceProperties)5 NamedThing (org.talend.daikon.NamedThing)5 Form (org.talend.daikon.properties.presentation.Form)4 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)4 Node (org.talend.designer.core.ui.editor.nodes.Node)4 Schema (org.apache.avro.Schema)3 CCombo (org.eclipse.swt.custom.CCombo)3 Point (org.eclipse.swt.graphics.Point)3 INodeConnector (org.talend.core.model.process.INodeConnector)3 SimpleNamedThing (org.talend.daikon.SimpleNamedThing)3 Widget (org.talend.daikon.properties.presentation.Widget)3 Property (org.talend.daikon.properties.property.Property)3 FakeElement (org.talend.designer.core.model.FakeElement)3