Search in sources :

Example 6 with ComponentProperties

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

the class Component method createConnectors.

@Override
public List<INodeConnector> createConnectors(INode parentNode) {
    List<INodeConnector> listConnector = new ArrayList<>();
    ComponentProperties componentProperties = ComponentsUtils.getComponentProperties(getName());
    Set<? extends Connector> inputConnectors = componentProperties.getPossibleConnectors(false);
    if (inputConnectors.isEmpty()) {
        INodeConnector connector = null;
        connector = addStandardType(listConnector, EConnectionType.FLOW_MAIN, parentNode);
        connector.setMaxLinkInput(0);
        connector.setMaxLinkOutput(0);
    } else {
        for (Connector connector : inputConnectors) {
            addGenericType(listConnector, EConnectionType.FLOW_MAIN, connector.getName(), parentNode, componentProperties, false);
        }
    }
    Set<? extends Connector> outputConnectors = componentProperties.getPossibleConnectors(true);
    List<? extends Connector> sortedOutputConnectors = new ArrayList<>(outputConnectors);
    sortedOutputConnectors.sort(new Comparator<Connector>() {

        @Override
        public int compare(Connector o1, Connector o2) {
            if (Connector.MAIN_NAME.equals(o1.getName())) {
                return -1;
            }
            if (Connector.MAIN_NAME.equals(o2.getName())) {
                return 1;
            }
            return 0;
        }
    });
    for (Connector connector : sortedOutputConnectors) {
        EConnectionType type = EConnectionType.FLOW_MAIN;
        if (Connector.REJECT_NAME.equals(connector.getName())) {
            type = EConnectionType.REJECT;
        }
        addGenericType(listConnector, type, connector.getName(), parentNode, componentProperties, true);
    }
    addStandardType(listConnector, EConnectionType.RUN_IF, parentNode);
    addStandardType(listConnector, EConnectionType.ON_COMPONENT_OK, parentNode);
    addStandardType(listConnector, EConnectionType.ON_COMPONENT_ERROR, parentNode);
    addStandardType(listConnector, EConnectionType.ON_SUBJOB_OK, parentNode);
    addStandardType(listConnector, EConnectionType.ON_SUBJOB_ERROR, parentNode);
    Set<ConnectorTopology> topologies = componentDefinition.getSupportedConnectorTopologies();
    createIterateConnectors(topologies, listConnector, parentNode);
    for (int i = 0; i < EConnectionType.values().length; i++) {
        EConnectionType currentType = EConnectionType.values()[i];
        if ((currentType == EConnectionType.FLOW_REF) || (currentType == EConnectionType.FLOW_MERGE)) {
            continue;
        }
        boolean exists = false;
        for (INodeConnector curNodeConn : listConnector) {
            if (curNodeConn.getDefaultConnectionType().equals(currentType)) {
                exists = true;
                if (currentType == EConnectionType.FLOW_MAIN) {
                    curNodeConn.addConnectionProperty(EConnectionType.FLOW_REF, EConnectionType.FLOW_REF.getRGB(), EConnectionType.FLOW_REF.getDefaultLineStyle());
                    curNodeConn.addConnectionProperty(EConnectionType.FLOW_MERGE, EConnectionType.FLOW_MERGE.getRGB(), EConnectionType.FLOW_MERGE.getDefaultLineStyle());
                }
            }
        }
        if (!exists) {
            // will add by default all connectors not defined in
            NodeConnector nodeConnector = new NodeConnector(parentNode);
            nodeConnector.setDefaultConnectionType(currentType);
            nodeConnector.setName(currentType.getName());
            nodeConnector.setBaseSchema(currentType.getName());
            nodeConnector.addConnectionProperty(currentType, currentType.getRGB(), currentType.getDefaultLineStyle());
            nodeConnector.setLinkName(currentType.getDefaultLinkName());
            nodeConnector.setMenuName(currentType.getDefaultMenuName());
            if ((currentType == EConnectionType.PARALLELIZE) || (currentType == EConnectionType.SYNCHRONIZE)) {
                nodeConnector.setMaxLinkInput(1);
            } else {
                nodeConnector.setMaxLinkInput(0);
            }
            nodeConnector.setMaxLinkOutput(0);
            nodeConnector.setMinLinkInput(0);
            nodeConnector.setMinLinkOutput(0);
            listConnector.add(nodeConnector);
        }
    }
    return listConnector;
}
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) ComponentProperties(org.talend.components.api.properties.ComponentProperties) INodeConnector(org.talend.core.model.process.INodeConnector) NodeConnector(org.talend.designer.core.model.components.NodeConnector) ArrayList(java.util.ArrayList) INodeConnector(org.talend.core.model.process.INodeConnector) EConnectionType(org.talend.core.model.process.EConnectionType) ConnectorTopology(org.talend.components.api.component.ConnectorTopology)

Example 7 with ComponentProperties

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

the class Component method genericToSerialized.

@Override
public String genericToSerialized(IElementParameter param) {
    if (param instanceof GenericElementParameter) {
        Node node = (Node) ((GenericElementParameter) param).getElement();
        ComponentProperties properties = node.getComponentProperties();
        return properties.toSerialized();
    } else {
        ComponentProperties componentProperties = ComponentsUtils.getComponentProperties(getName());
        return componentProperties.toSerialized();
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode)

Example 8 with ComponentProperties

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

the class SchemaUtils method updateComponentSchema.

/**
     * DOC ycbai Comment method "updateComponentSchema".
     * <p>
     * Recreate a component schema by <code>metadataTable<code> and save it back into the <code>metadataTable<code>.
     * 
     * @param metadataTable
     * @param connection 
     */
public static void updateComponentSchema(MetadataTable metadataTable, Connection connection) {
    if (metadataTable == null) {
        return;
    }
    String componentPropertiesStr = null;
    String schemaPropertyName = null;
    TaggedValue componentPropertiesTaggedValue = null;
    EList<TaggedValue> taggedValues = metadataTable.getTaggedValue();
    for (TaggedValue taggedValue : taggedValues) {
        String tag = taggedValue.getTag();
        String tagValue = taggedValue.getValue();
        if (IComponentConstants.COMPONENT_PROPERTIES_TAG.equals(tag)) {
            componentPropertiesStr = tagValue;
            componentPropertiesTaggedValue = taggedValue;
        } else if (IComponentConstants.COMPONENT_SCHEMA_TAG.equals(tag)) {
            schemaPropertyName = tagValue;
        }
    }
    if (componentPropertiesStr != null && componentPropertiesTaggedValue != null && schemaPropertyName != null) {
        ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(componentPropertiesStr, connection);
        componentProperties.setValue(schemaPropertyName, convertTalendSchemaIntoComponentSchema(metadataTable));
        componentPropertiesTaggedValue.setValue(componentProperties.toSerialized());
    }
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue)

Example 9 with ComponentProperties

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

the class Salesforce620Migration 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 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 10 with ComponentProperties

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

the class NewSalesforceWizardMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    ComponentService service = ComponentsUtils.getComponentService();
    Properties props = getPropertiesFromFile();
    if (item instanceof ConnectionItem) {
        boolean modify = false;
        GenericConnectionItem genericConnectionItem = null;
        ConnectionItem connectionItem = (ConnectionItem) item;
        Connection connection = connectionItem.getConnection();
        // Init
        genericConnectionItem = initGenericConnectionItem(connectionItem);
        genericConnectionItem.setTypeName(TYPE_NAME);
        GenericConnection genericConnection = initGenericConnection(connection);
        initProperty(connectionItem, genericConnectionItem);
        ComponentWizard componentWizard = service.getComponentWizard(TYPE_NAME, genericConnectionItem.getProperty().getId());
        ComponentProperties componentProperties = (ComponentProperties) componentWizard.getForms().get(0).getProperties();
        componentProperties.init();
        // Update
        modify = updateComponentProperties(connection, componentProperties, props);
        //$NON-NLS-1$
        NamedThing nt = componentProperties.getProperty("loginType");
        if (nt instanceof Property) {
            Property property = (Property) nt;
            if ("OAuth2".equals(property.getStoredValue())) {
                //$NON-NLS-1$
                List<?> propertyPossibleValues = property.getPossibleValues();
                Object newValue = null;
                if (propertyPossibleValues != null) {
                    for (Object possibleValue : propertyPossibleValues) {
                        if (possibleValue.toString().equals("OAuth")) {
                            //$NON-NLS-1$
                            newValue = possibleValue;
                            break;
                        }
                    }
                }
                if (newValue == null) {
                    // set default value
                    newValue = propertyPossibleValues.get(0);
                }
                property.setValue(newValue);
                Property<?> endpoint = componentProperties.getValuedProperty("endpoint");
                SalesforceSchemaConnection sfConnection = (SalesforceSchemaConnection) connection;
                //$NON-NLS-1$
                componentProperties.setValue("endpoint", sfConnection.getWebServiceUrlTextForOAuth());
            }
            if (GenericTypeUtils.isEnumType(property)) {
                List<?> propertyPossibleValues = ((Property<?>) property).getPossibleValues();
                if (propertyPossibleValues != null) {
                    for (Object possibleValue : propertyPossibleValues) {
                        if (possibleValue.toString().equals(property.getStoredValue())) {
                            property.setStoredValue(possibleValue);
                            break;
                        }
                    }
                }
            }
        }
        // set empty value instead of default null value, this will add automatically the double quotes in the job
        // when drag&drop metadata
        //$NON-NLS-1$ //$NON-NLS-2$
        componentProperties.setValue("userPassword.securityKey", "");
        //$NON-NLS-1$
        Property property = componentProperties.getValuedProperty("userPassword.securityKey");
        //$NON-NLS-1$
        property.setTaggedValue(IGenericConstants.REPOSITORY_VALUE, "securityKey");
        genericConnection.setCompProperties(componentProperties.toSerialized());
        genericConnectionItem.setConnection(genericConnection);
        updateMetadataTable(connection, genericConnection, componentProperties);
        if (modify) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                IRepositoryViewObject object = factory.getLastVersion(item.getProperty().getId(), ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA.getFolder(), ERepositoryObjectType.METADATA_SALESFORCE_SCHEMA);
                if (object != null) {
                    factory.deleteObjectPhysical(object);
                }
                if (genericConnectionItem != null && connectionItem != null) {
                    factory.create(genericConnectionItem, new Path(connectionItem.getState().getPath()), true);
                }
                return ExecutionResult.SUCCESS_WITH_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : Path(org.eclipse.core.runtime.Path) ComponentProperties(org.talend.components.api.properties.ComponentProperties) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) Properties(java.util.Properties) ComponentProperties(org.talend.components.api.properties.ComponentProperties) NamedThing(org.talend.daikon.NamedThing) IOException(java.io.IOException) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ComponentWizard(org.talend.components.api.wizard.ComponentWizard) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ComponentService(org.talend.components.api.service.ComponentService) GenericConnection(org.talend.repository.generic.model.genericMetadata.GenericConnection) GenericConnectionItem(org.talend.repository.generic.model.genericMetadata.GenericConnectionItem) Property(org.talend.daikon.properties.property.Property)

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