Search in sources :

Example 46 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class TalendDndHelper method sortFilteredComponnents.

private static List<IComponent> sortFilteredComponnents(Item item, RepositoryNode seletetedNode, ERepositoryObjectType type, List<IComponent> neededComponents) {
    List<IComponent> normalTopComponents = new ArrayList<IComponent>();
    List<IComponent> specialTopComponents = new ArrayList<IComponent>();
    for (IComponent component : neededComponents) {
        String name = component.getName();
        if (name.contains(OUTPUT) || name.contains(INPUT)) {
            normalTopComponents.add(component);
        } else if (isSpecialTop(item, seletetedNode, type, component)) {
            specialTopComponents.add(component);
        }
    }
    List<IComponent> sortedComponents = new ArrayList<IComponent>();
    sortedComponents.addAll(specialTopComponents);
    sortedComponents.addAll(normalTopComponents);
    // add the left components
    neededComponents.removeAll(specialTopComponents);
    neededComponents.removeAll(normalTopComponents);
    sortedComponents.addAll(neededComponents);
    return sortedComponents;
}
Also used : IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList)

Example 47 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class TalendDndHelper method filterNeededComponents.

public static List<IComponent> filterNeededComponents(Item item, RepositoryNode seletetedNode, ERepositoryObjectType type) {
    EDatabaseComponentName name = EDatabaseComponentName.getCorrespondingComponentName(item, type);
    List<IComponent> neededComponents = new ArrayList<IComponent>();
    if (name == null) {
        return neededComponents;
    }
    String productNameWanted = filterProductNameWanted(name, item);
    boolean hl7Related = false;
    boolean hl7Output = false;
    if (item instanceof HL7ConnectionItem) {
        hl7Related = true;
        EList list = ((HL7Connection) ((HL7ConnectionItem) item).getConnection()).getRoot();
        if (list != null && list.size() > 0) {
            hl7Output = true;
        }
    }
    // for mdm
    MdmConceptType mdmType = null;
    if (item instanceof MDMConnectionItem) {
        MDMConnectionItem mdmItem = (MDMConnectionItem) item;
        if (seletetedNode != null && seletetedNode.getObject() instanceof MetadataTableRepositoryObject) {
            MetadataTableRepositoryObject object = (MetadataTableRepositoryObject) seletetedNode.getObject();
            if (mdmItem.getConnection() instanceof MDMConnection) {
                MDMConnection connection = (MDMConnection) mdmItem.getConnection();
                for (Object obj : connection.getSchemas()) {
                    if (obj instanceof Concept && object.getLabel().equals(((Concept) obj).getLabel())) {
                        mdmType = ((Concept) obj).getConceptType();
                    }
                }
            }
        }
    }
    Set<IComponent> components = ComponentsFactoryProvider.getInstance().getComponents();
    EmfComponent emfComponent = null;
    for (IComponent component : components) {
        if (component instanceof EmfComponent) {
            emfComponent = (EmfComponent) component;
            String componentProductname = emfComponent.getRepositoryType();
            boolean value = true;
            if (type == ERepositoryObjectType.METADATA_CON_TABLE) {
                if (emfComponent.getName().toUpperCase().endsWith(MAP)) {
                    value = false;
                }
            }
            if (hl7Output && !component.getName().equals("tHL7Output")) {
                //$NON-NLS-1$
                value = false;
            } else if (hl7Related && !hl7Output && !component.getName().equals("tHL7Input")) {
                //$NON-NLS-N$ bug15632
                value = false;
            }
            boolean flag = filterComponent(component, name, type);
            if (((componentProductname != null && productNameWanted.endsWith(componentProductname)) && value) || flag) {
                Pattern pattern = Pattern.compile("^.*oracle.*$", Pattern.CASE_INSENSITIVE);
                if (pattern.matcher(name.getDBType()).matches() && (emfComponent.getName().equals("tAmazonOracleInput") || emfComponent.getName().equals("tAmazonOracleOutput"))) {
                    continue;
                }
                if (item instanceof MDMConnectionItem) {
                    if (MdmConceptType.INPUT.equals(mdmType) && emfComponent.getName().endsWith(INPUT)) {
                        neededComponents.add(emfComponent);
                    } else if (MdmConceptType.OUTPUT.equals(mdmType) && emfComponent.getName().endsWith(OUTPUT)) {
                        neededComponents.add(emfComponent);
                    } else if (MdmConceptType.RECEIVE.equals(mdmType) && emfComponent.getName().endsWith(RECEIVE)) {
                        neededComponents.add(emfComponent);
                    }
                } else {
                    neededComponents.add(emfComponent);
                }
            }
        }
    }
    return sortFilteredComponnents(item, seletetedNode, type, neededComponents);
}
Also used : Concept(org.talend.core.model.metadata.builder.connection.Concept) Pattern(java.util.regex.Pattern) IComponent(org.talend.core.model.components.IComponent) ArrayList(java.util.ArrayList) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) EList(org.eclipse.emf.common.util.EList) MdmConceptType(org.talend.core.model.metadata.builder.connection.MdmConceptType) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) EmfComponent(org.talend.designer.core.model.components.EmfComponent) HL7Connection(org.talend.core.model.metadata.builder.connection.HL7Connection)

Example 48 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class ChangeValuesFromRepositoryTest method setUp.

/**
     * DOC Administrator Comment method "setUp".
     *
     * @throws java.lang.Exception
     */
@Before
public void setUp() throws Exception {
    Property property = PropertiesFactory.eINSTANCE.createProperty();
    IProcess2 process = new Process(property);
    IComponent sourceCom = ComponentsFactoryProvider.getInstance().get("tMysqlInput", ComponentCategory.CATEGORY_4_DI.getName());
    IComponent targetCom = ComponentsFactoryProvider.getInstance().get("tMysqlOutput", ComponentCategory.CATEGORY_4_DI.getName());
    elem = new Node(sourceCom, process);
    elem.setLabel("tMysqlInput_1");
    target = new Node(targetCom, process);
    IMetadataTable table = createSimpleMetadata();
    table.setAttachedConnector("FLOW");
    List<IMetadataTable> metadataList = new ArrayList<IMetadataTable>();
    metadataList.add(table);
    elem.setMetadataList(metadataList);
    Connection conn = new Connection(elem, target, EConnectionType.FLOW_MAIN, "FLOW", "metaName", "row1", false);
    List<Connection> connList = new ArrayList<Connection>();
    connList.add(conn);
    target.setIncomingConnections(connList);
    elem.setOutgoingConnections(connList);
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IProcess2(org.talend.core.model.process.IProcess2) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) Process(org.talend.designer.core.ui.editor.process.Process) Property(org.talend.core.model.properties.Property) Before(org.junit.Before)

Example 49 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class RepositoryChangeMetadataCommandTest method testComponentSchemaUpdated.

@Test
public void testComponentSchemaUpdated() {
    IComponent component = ComponentsFactoryProvider.getInstance().get("tSalesforceInput", "DI");
    Node node = new Node(component, new Process(new FakePropertyImpl()));
    IMetadataTable table = node.getMetadataList().get(0);
    IMetadataColumn column = new MetadataColumn();
    column.setLabel("C1");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C2");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    column = new MetadataColumn();
    column.setLabel("C3");
    column.setTalendType(JavaTypesManager.STRING.getId());
    table.getListColumns().add(column);
    IMetadataTable newTable = table.clone(true);
    newTable.getListColumns().remove(0);
    IElementParameter schemaParam = null;
    for (IElementParameter param : node.getElementParameters()) {
        if (EParameterFieldType.SCHEMA_REFERENCE.equals(param.getFieldType())) {
            schemaParam = param;
            break;
        }
    }
    assertNotNull(schemaParam);
    //$NON-NLS-1$
    String fullParamName = SCHEMA_PARAM_NAME + ":REPOSITORY_SCHEMA_TYPE";
    //$NON-NLS-1$ //$NON-NLS-2$
    String propValue = "testconnid" + " - " + newTable.getTableName();
    RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand(node, fullParamName, propValue, newTable, null, null);
    changeMetadataCommand.execute();
    newTable = node.getMetadataList().get(0);
    String avroSchemaStr = ((SchemaProperties) node.getComponentProperties().getProperties("module.main")).schema.getStringValue();
    assertNotNull(avroSchemaStr);
    Schema avroSchema = new Schema.Parser().parse(avroSchemaStr);
    assertEquals(2, avroSchema.getFields().size());
    //$NON-NLS-1$
    assertNull(avroSchema.getField("C1"));
    assertEquals(avroSchemaStr, schemaParam.getValue().toString());
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) FakePropertyImpl(org.talend.core.model.repository.FakePropertyImpl) IComponent(org.talend.core.model.components.IComponent) Node(org.talend.designer.core.ui.editor.nodes.Node) Schema(org.apache.avro.Schema) IElementParameter(org.talend.core.model.process.IElementParameter) Process(org.talend.designer.core.ui.editor.process.Process) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) Test(org.junit.Test)

Example 50 with IComponent

use of org.talend.core.model.components.IComponent in project tdi-studio-se by Talend.

the class ConnectionTest method testCreateParallelizeParameters.

@Test
public void testCreateParallelizeParameters() {
    IComponent componentPar = ComponentsFactoryProvider.getInstance().get("tPartitioner", ComponentCategory.CATEGORY_4_DI.getName());
    INode node = new Node(componentPar, (Process) source.getProcess());
    assertEquals(node.getPropertyValue("NUM_PARTITIONS").toString(), connection.getPropertyValue("NUM_PARTITIONS").toString());
    assertEquals(node.getPropertyValue("HASH_PARTITION").toString(), connection.getPropertyValue("HASH_PARTITION").toString());
    assertEquals(node.getPropertyValue("HASH_KEYS").toString(), connection.getPropertyValue("HASH_KEYS").toString());
    IComponent componentCol = ComponentsFactoryProvider.getInstance().get("tRecollector", ComponentCategory.CATEGORY_4_DI.getName());
    node = new Node(componentCol, (Process) source.getProcess());
    assertEquals(node.getPropertyValue("IS_SORTING").toString(), connection.getPropertyValue("IS_SORTING").toString());
}
Also used : INode(org.talend.core.model.process.INode) IComponent(org.talend.core.model.components.IComponent) INode(org.talend.core.model.process.INode) Node(org.talend.designer.core.ui.editor.nodes.Node) Process(org.talend.designer.core.ui.editor.process.Process) Test(org.junit.Test)

Aggregations

IComponent (org.talend.core.model.components.IComponent)146 Node (org.talend.designer.core.ui.editor.nodes.Node)54 ArrayList (java.util.ArrayList)47 IElementParameter (org.talend.core.model.process.IElementParameter)36 Process (org.talend.designer.core.ui.editor.process.Process)36 Test (org.junit.Test)35 INode (org.talend.core.model.process.INode)33 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)22 List (java.util.List)15 Property (org.talend.core.model.properties.Property)15 FakePropertyImpl (org.talend.core.model.repository.FakePropertyImpl)15 NodeContainer (org.talend.designer.core.ui.editor.nodecontainer.NodeContainer)13 IComponentsFactory (org.talend.core.model.components.IComponentsFactory)12 Connection (org.talend.designer.core.ui.editor.connections.Connection)12 HashMap (java.util.HashMap)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)10 DataNode (org.talend.designer.core.model.process.DataNode)10 HashSet (java.util.HashSet)9 IConnection (org.talend.core.model.process.IConnection)9 Rectangle (org.eclipse.swt.graphics.Rectangle)8