Search in sources :

Example 31 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class ChangeMetadataCommandTest 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);
    ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, schemaParam, null, null, null, table, newTable);
    changeMetadataCommand.execute();
    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 32 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class ConnectionCreateCommandTest method executeSimpleInputToSimpleOutput3.

/**
     * simple input to simple output with no metadata and without schema auto propagate.
     */
private ConnectionCreateCommand executeSimpleInputToSimpleOutput3() {
    IProcess2 process = getFakeProcess();
    Node simpleInputNode = NodeTestCreator.createSimpleInputNode(process);
    // simple tests only since it's simply using the class ConnectionManager which already have JUnits.
    List<Object> args = new ArrayList<Object>();
    args.add(simpleInputNode.getUniqueName());
    //$NON-NLS-1$
    args.add("connectionName");
    simpleInputNode.getMetadataList().clear();
    IMetadataTable table = createSimpleMetadata1();
    table.setTableName(simpleInputNode.getUniqueName());
    table.setLabel(simpleInputNode.getUniqueName());
    //$NON-NLS-1$
    table.setAttachedConnector("FLOW");
    simpleInputNode.getMetadataList().add(table);
    // set null, the command should take the schema from the component directly
    args.add(null);
    //$NON-NLS-1$
    ConnectionCreateCommand ccc = new ConnectionCreateCommand(simpleInputNode, "FLOW", args);
    ConnectionCreateCommand.setCreatingConnection(true);
    Node simpleOutputNode = NodeTestCreator.createSimpleOutputNodeNoPropagate(process);
    ccc.setTarget(simpleOutputNode);
    ccc.execute();
    assertEquals(simpleInputNode.getOutgoingConnections().size(), 1);
    assertEquals(simpleOutputNode.getIncomingConnections().size(), 1);
    assertEquals(simpleOutputNode.getMetadataList().size(), 1);
    IMetadataTable outputMetadata = simpleOutputNode.getMetadataList().get(0);
    // no propagation
    assertEquals(outputMetadata.getListColumns().size(), 0);
    IConnection connection = simpleInputNode.getOutgoingConnections().get(0);
    assertEquals(simpleOutputNode.getIncomingConnections().get(0), connection);
    assertEquals(connection.getSource(), simpleInputNode);
    assertEquals(connection.getTarget(), simpleOutputNode);
    assertEquals(connection.getMetaName(), simpleInputNode.getUniqueName());
    //$NON-NLS-1$
    assertEquals(connection.getConnectorName(), "FLOW");
    //$NON-NLS-1$
    INodeConnector inputConnector = simpleInputNode.getConnectorFromName("FLOW");
    //$NON-NLS-1$
    INodeConnector outputConnector = simpleOutputNode.getConnectorFromName("FLOW");
    assertEquals(inputConnector.getCurLinkNbOutput(), 1);
    assertEquals(outputConnector.getCurLinkNbInput(), 1);
    return ccc;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Node(org.talend.designer.core.ui.editor.nodes.Node) IProcess2(org.talend.core.model.process.IProcess2) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) INodeConnector(org.talend.core.model.process.INodeConnector)

Example 33 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class ConnectionCreateActionTest method createSimpleMetadata.

private IMetadataTable createSimpleMetadata() {
    IMetadataTable table = new org.talend.core.model.metadata.MetadataTable();
    IMetadataColumn column1 = new MetadataColumn();
    //$NON-NLS-1$
    column1.setLabel("C1");
    //$NON-NLS-1$
    column1.setTalendType("id_String");
    table.getListColumns().add(column1);
    IMetadataColumn column2 = new MetadataColumn();
    //$NON-NLS-1$
    column2.setLabel("C2");
    //$NON-NLS-1$
    column2.setTalendType("id_String");
    table.getListColumns().add(column2);
    IMetadataColumn column3 = new MetadataColumn();
    //$NON-NLS-1$
    column3.setLabel("C3");
    //$NON-NLS-1$
    column3.setTalendType("id_Integer");
    table.getListColumns().add(column3);
    return table;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 34 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class ConnectionCreateActionTest method testRun2.

private void testRun2() {
    EConnectionType ct = EConnectionType.FLOW_MAIN;
    String text = "Main";
    String tableName = text;
    IMetadataTable meta = node.getMetadataTable("JOBS");
    String connectionName = meta.getTableName();
    assertEquals(connectionName, "JOBS");
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) EConnectionType(org.talend.core.model.process.EConnectionType)

Example 35 with IMetadataTable

use of org.talend.core.model.metadata.IMetadataTable in project tdi-studio-se by Talend.

the class SchemaUtilsTest method testUpdateComponentSchema.

@Test
public void testUpdateComponentSchema() {
    //$NON-NLS-1$
    String TEST_TABLE_NAME = "testTable";
    //$NON-NLS-1$
    String TEST_COL_NAME = "userId";
    //$NON-NLS-1$
    String ADDED_COL_NAME = "added";
    //$NON-NLS-1$
    String SCHEMA_PROP_NAME = "schema.schema";
    // Create the test MetadataTable.
    MetadataTable table = createMetadataTable(TEST_TABLE_NAME);
    MetadataColumn testColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
    testColumn.setName(TEST_COL_NAME);
    testColumn.setLabel(testColumn.getName());
    //$NON-NLS-1$
    testColumn.setDefaultValue("1");
    testColumn.setTalendType(JavaTypesManager.STRING.getId());
    table.getColumns().add(testColumn);
    // Create one component properties which has one schema property.
    //$NON-NLS-1$
    TestProperties props = (TestProperties) new TestProperties("test").init();
    Schema oldSchema = SchemaBuilder.record(TEST_TABLE_NAME).fields().name(TEST_COL_NAME).type().stringType().noDefault().endRecord();
    props.schema.schema.setValue(oldSchema);
    // Set the component properties and schema property name into MetadataTable.
    TaggedValue serializedPropsTV = CoreFactory.eINSTANCE.createTaggedValue();
    serializedPropsTV.setTag(IComponentConstants.COMPONENT_PROPERTIES_TAG);
    serializedPropsTV.setValue(props.toSerialized());
    table.getTaggedValue().add(serializedPropsTV);
    TaggedValue schemaPropertyTV = CoreFactory.eINSTANCE.createTaggedValue();
    schemaPropertyTV.setTag(IComponentConstants.COMPONENT_SCHEMA_TAG);
    schemaPropertyTV.setValue(SCHEMA_PROP_NAME);
    table.getTaggedValue().add(schemaPropertyTV);
    // Add another MetadataColumn into MetadataTable.
    MetadataColumn addedColumn = ConnectionFactory.eINSTANCE.createMetadataColumn();
    addedColumn.setName(ADDED_COL_NAME);
    addedColumn.setLabel(addedColumn.getName());
    //$NON-NLS-1$
    addedColumn.setDefaultValue("x");
    addedColumn.setTalendType(JavaTypesManager.STRING.getId());
    table.getColumns().add(addedColumn);
    // Invoke updateComponentSchema() method.
    SchemaUtils.updateComponentSchema(table, null);
    // Check if the schema object is updated correctly.
    String componentPropertiesStr = null;
    String schemaPropertyName = null;
    EList<TaggedValue> taggedValues = table.getTaggedValue();
    for (TaggedValue taggedValue : taggedValues) {
        String tag = taggedValue.getTag();
        String tagValue = taggedValue.getValue();
        if (IComponentConstants.COMPONENT_PROPERTIES_TAG.equals(tag)) {
            componentPropertiesStr = tagValue;
        } else if (IComponentConstants.COMPONENT_SCHEMA_TAG.equals(tag)) {
            schemaPropertyName = tagValue;
        }
    }
    ComponentProperties componentProperties = ComponentsUtils.getComponentPropertiesFromSerialized(componentPropertiesStr, null);
    Object schemaValue = componentProperties.getValuedProperty(schemaPropertyName).getValue();
    Schema avroSchema = getAvroSchema(schemaValue);
    props.schema.schema.setValue(avroSchema);
    assertNotNull(avroSchema.getField(TEST_COL_NAME));
    assertNotNull(avroSchema.getField(ADDED_COL_NAME));
    assertEquals(2, avroSchema.getFields().size());
    // Test method updateComponentSchema(ComponentProperties componentProperties, String schemaPropertyName,
    // IMetadataTable metadataTable)
    IMetadataTable iMetadataTable = MetadataToolHelper.convert(table);
    iMetadataTable.getListColumns().remove(1);
    SchemaUtils.updateComponentSchema(props, SCHEMA_PROP_NAME, iMetadataTable);
    schemaValue = props.getValuedProperty(schemaPropertyName).getValue();
    avroSchema = getAvroSchema(schemaValue);
    assertNotNull(avroSchema.getField(TEST_COL_NAME));
    assertNull(avroSchema.getField(ADDED_COL_NAME));
    assertEquals(1, avroSchema.getFields().size());
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataColumn(org.talend.core.model.metadata.builder.connection.MetadataColumn) ComponentProperties(org.talend.components.api.properties.ComponentProperties) TaggedValue(orgomg.cwm.objectmodel.core.TaggedValue) Schema(org.apache.avro.Schema) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) Test(org.junit.Test)

Aggregations

IMetadataTable (org.talend.core.model.metadata.IMetadataTable)212 ArrayList (java.util.ArrayList)102 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)81 IElementParameter (org.talend.core.model.process.IElementParameter)67 IConnection (org.talend.core.model.process.IConnection)66 List (java.util.List)56 INode (org.talend.core.model.process.INode)54 Node (org.talend.designer.core.ui.editor.nodes.Node)50 HashMap (java.util.HashMap)48 Map (java.util.Map)39 MetadataTable (org.talend.core.model.metadata.MetadataTable)34 INodeConnector (org.talend.core.model.process.INodeConnector)32 Connection (org.talend.designer.core.ui.editor.connections.Connection)28 Process (org.talend.designer.core.ui.editor.process.Process)25 IComponent (org.talend.core.model.components.IComponent)22 ConnectionItem (org.talend.core.model.properties.ConnectionItem)20 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)18 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)17 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)16 Point (org.eclipse.swt.graphics.Point)15