Search in sources :

Example 11 with MetadataTable

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

the class MetadataEmfFacotryTest method testSetMetadataTable.

@Test
public void testSetMetadataTable() {
    IMetadataTable table = new MetadataTable();
    table.getAdditionalProperties().put(SAPBWTableHelper.SAP_INFOOBJECT_INNER_TYPE, SAPBWTableHelper.IO_INNERTYPE_ATTRIBUTE);
    MetadataEmfFactory factory = new MetadataEmfFactory();
    factory.setMetadataTable(table);
    Object innerType = factory.getMetadataType().getAdditionalProperties().get(SAPBWTableHelper.SAP_INFOOBJECT_INNER_TYPE);
    assertEquals(SAPBWTableHelper.IO_INNERTYPE_ATTRIBUTE, innerType);
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataEmfFactory(org.talend.designer.core.model.metadata.MetadataEmfFactory) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) Test(org.junit.Test)

Example 12 with MetadataTable

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

the class PostgresGenerationManagerTest method init.

private void init(String schema, String main_table, String lookup_table) {
    List<IConnection> incomingConnections = new ArrayList<IConnection>();
    String[] mainTableEntities = new String[] { "id", "name", "classNum" };
    String[] lookupEndtities = new String[] { "id", "score" };
    incomingConnections.add(mockConnection(schema, main_table, mainTableEntities));
    incomingConnections.add(mockConnection(schema, lookup_table, lookupEndtities));
    component.setIncomingConnections(incomingConnections);
    ExternalDbMapData externalData = new ExternalDbMapData();
    List<ExternalDbMapTable> inputs = new ArrayList<ExternalDbMapTable>();
    List<ExternalDbMapTable> outputs = new ArrayList<ExternalDbMapTable>();
    // main table
    ExternalDbMapTable inputTable = new ExternalDbMapTable();
    inputTable.setTableName(schema + "." + main_table);
    List<ExternalDbMapEntry> entities = getMetadataEntities(mainTableEntities, new String[3]);
    inputTable.setMetadataTableEntries(entities);
    inputs.add(inputTable);
    // lookup table
    inputTable = new ExternalDbMapTable();
    inputTable.setTableName(schema + "." + lookup_table);
    entities = getMetadataEntities(lookupEndtities, new String[2]);
    inputTable.setMetadataTableEntries(entities);
    inputs.add(inputTable);
    // output
    ExternalDbMapTable outputTable = new ExternalDbMapTable();
    outputTable.setName("grade");
    List<ExternalDbMapEntry> conditions = new ArrayList<ExternalDbMapEntry>();
    conditions.add(new ExternalDbMapEntry(schema + "." + main_table + ".id =3"));
    outputTable.setCustomWhereConditionsEntries(conditions);
    String[] names = new String[] { "id", "name", "classNum", "score" };
    String[] expressions = new String[] { schema + "." + main_table + ".id", schema + "." + main_table + ".name", schema + "." + main_table + ".classNum", schema + "." + lookup_table + ".score" };
    outputTable.setMetadataTableEntries(getMetadataEntities(names, expressions));
    outputs.add(outputTable);
    externalData.setInputTables(inputs);
    externalData.setOutputTables(outputs);
    component.setExternalData(externalData);
    List<IMetadataTable> metadataList = new ArrayList<IMetadataTable>();
    MetadataTable metadataTable = getMetadataTable(names);
    metadataTable.setLabel("grade");
    metadataList.add(metadataTable);
    component.setMetadataList(metadataList);
    Process process = mock(Process.class);
    when(process.getContextManager()).thenReturn(new JobContextManager());
    component.setProcess(process);
}
Also used : ExternalDbMapData(org.talend.designer.dbmap.external.data.ExternalDbMapData) ArrayList(java.util.ArrayList) IConnection(org.talend.core.model.process.IConnection) Process(org.talend.designer.core.ui.editor.process.Process) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ExternalDbMapTable(org.talend.designer.dbmap.external.data.ExternalDbMapTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) JobContextManager(org.talend.core.model.context.JobContextManager) ExternalDbMapEntry(org.talend.designer.dbmap.external.data.ExternalDbMapEntry)

Example 13 with MetadataTable

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

the class ShadowNode method getMetadataList.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.process.INode#getMetaDataList()
     */
@Override
public List<IMetadataTable> getMetadataList() {
    List<IMetadataTable> metadataList = super.getMetadataList();
    if (metadataList != null) {
        return metadataList;
    }
    List<IMetadataTable> metadatas = new ArrayList<IMetadataTable>();
    MetadataTable metadata = new MetadataTable();
    metadata.setTableName(this.getUniqueName());
    List<IMetadataColumn> columns = new ArrayList<IMetadataColumn>();
    for (int i = 0; i < columnNumber; i++) {
        MetadataColumn col = new MetadataColumn();
        //$NON-NLS-1$
        col.setLabel("row" + i);
        //$NON-NLS-1$
        col.setTalendType("id_String");
        //$NON-NLS-1$
        col.setType("String");
        columns.add(col);
    }
    metadata.setListColumns(columns);
    metadatas.add(metadata);
    return metadatas;
}
Also used : IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) MetadataColumn(org.talend.core.model.metadata.MetadataColumn) ArrayList(java.util.ArrayList) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn)

Example 14 with MetadataTable

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

the class AbstractSchemaController method createComboCommand.

@Override
protected Command createComboCommand(CCombo combo) {
    IMetadataTable repositoryMetadata = null;
    String fullParamName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    //$NON-NLS-1$
    String value = new String("");
    IElementParameter param = elem.getElementParameter(fullParamName);
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    // if change to build-in, unuse the validation rule if the component has.
    boolean isValRulesLost = false;
    IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
    if (value.equals(EmfComponent.BUILTIN) && currentValRuleObj != null) {
        if (!MessageDialog.openConfirm(combo.getShell(), //$NON-NLS-1$
        Messages.getString("AbstractSchemaController.validationrule.title.confirm"), Messages.getString("AbstractSchemaController.validationrule.selectBuildInMsg"))) {
            //$NON-NLS-1$
            return null;
        } else {
            isValRulesLost = true;
        }
    }
    org.talend.core.model.metadata.builder.connection.Connection connection = null;
    if (elem instanceof Node) {
        Node node = (Node) elem;
        Command baseCommand = null;
        boolean isReadOnly = false;
        String newRepositoryIdValue = null;
        if (node.getMetadataFromConnector(param.getContext()) != null) {
            isReadOnly = node.getMetadataFromConnector(param.getContext()).isReadOnly();
        }
        if (//$NON-NLS-1$
        value.equals(EmfComponent.BUILTIN) && isReadOnly && !"tLogCatcher".equals(node.getComponent().getName()) && !"tStatCatcher".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            boolean hasMetadataInput = false;
            if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0) {
                hasMetadataInput = true;
            }
            repositoryMetadata = new MetadataTable();
            if (hasMetadataInput) {
                for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
                    if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE))) {
                        repositoryMetadata = connec.getMetadataTable().clone();
                    }
                }
            }
        } else if (value.equals(EmfComponent.REPOSITORY)) {
            // Map<String, IMetadataTable> repositoryTableMap = dynamicProperty.getRepositoryTableMap();
            IElementParameter property = ((Node) elem).getElementParameter(EParameterName.PROPERTY_TYPE.getName());
            if ((property != null) && EmfComponent.REPOSITORY.equals(property.getValue())) {
                String propertySelected = (String) ((Node) elem).getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).getValue();
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                /* 16969 */
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(propertySelected);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                // item = factory.getLastVersion(propertySelected).getProperty().getItem();
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
            }
            IElementParameter repositorySchemaType = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
            String schemaSelected = (String) repositorySchemaType.getValue();
            if (schemaSelected == null) {
                //$NON-NLS-1$
                schemaSelected = "";
            }
            /* value can be devided means the value like "connectionid - label" */
            //$NON-NLS-1$
            String[] keySplitValues = schemaSelected.toString().split(" - ");
            if (keySplitValues.length > 1) {
                String connectionId = keySplitValues[0];
                String tableLabel = keySplitValues[1];
                IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                Item item = null;
                try {
                    IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                    if (repobj != null) {
                        Property tmpproperty = repobj.getProperty();
                        if (tmpproperty != null) {
                            item = tmpproperty.getItem();
                        }
                    }
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                }
                if (item != null && item instanceof ConnectionItem) {
                    final ConnectionItem connectionItem = (ConnectionItem) item;
                    if (connectionItem != null) {
                        connection = connectionItem.getConnection();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    boolean findTable = false;
                    Set<org.talend.core.model.metadata.builder.connection.MetadataTable> tables = null;
                    IGenericWizardService wizardService = null;
                    if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                        wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
                    }
                    if (wizardService != null && wizardService.isGenericItem(item)) {
                        tables = new HashSet<>(wizardService.getMetadataTables(connection));
                    } else {
                        tables = ConnectionHelper.getTables(connection);
                    }
                    for (org.talend.core.model.metadata.builder.connection.MetadataTable table : tables) {
                        if (table.getLabel().equals(tableLabel)) {
                            repositoryMetadata = ConvertionHelper.convert(table);
                            newRepositoryIdValue = schemaSelected;
                            findTable = true;
                            break;
                        }
                    }
                    if (!findTable) {
                        repositoryMetadata = new MetadataTable();
                    }
                } else {
                    repositoryMetadata = new MetadataTable();
                }
            } else {
                // value only got a empty string
                repositoryMetadata = new MetadataTable();
            }
        } else {
            baseCommand = new PropertyChangeCommand(elem, fullParamName, value);
        }
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        CompoundCommand cc = new CompoundCommand();
        if (baseCommand != null) {
            cc.add(baseCommand);
        } else {
            RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, newRepositoryIdValue, null);
            changeMetadataCommand.setConnection(connection);
            cc.add(changeMetadataCommand);
        }
        // unuse the validation rules of the component.
        if (isValRulesLost) {
            ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
        }
        return cc;
    }
    return null;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) List(java.util.List) ArrayList(java.util.ArrayList) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) Connection(org.talend.designer.core.ui.editor.connections.Connection) IConnection(org.talend.core.model.process.IConnection) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 15 with MetadataTable

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

the class ComboController method createButtonCommand.

/**
     * This method is used for "Guess Query" button.
     * 
     * @return
     */
private Command createButtonCommand() {
    IMetadataTable repositoryMetadata = null;
    IMetadataTable newRepositoryMetadata = null;
    String realTableName = null;
    String realTableId = null;
    // Only for getting the real table name.
    if (elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()).equals(EmfComponent.REPOSITORY)) {
        String paramName;
        IElementParameter repositorySchemaTypeParameter = elem.getElementParameter(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        Object repositoryControl = hashCurControls.get(repositorySchemaTypeParameter.getName());
        paramName = EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
        if (repositoryControl != null) {
            String selectedComboItem = ((CCombo) repositoryControl).getText();
            if (selectedComboItem != null && selectedComboItem.length() > 0) {
                //$NON-NLS-1$
                String value = new String("");
                for (int i = 0; i < elem.getElementParameters().size(); i++) {
                    IElementParameter param = elem.getElementParameters().get(i);
                    if (param.getName().equals(paramName)) {
                        for (int j = 0; j < param.getListItemsValue().length; j++) {
                            if (selectedComboItem.equals(param.getListItemsDisplayName()[j])) {
                                value = (String) param.getListItemsValue()[j];
                            }
                        }
                    }
                }
                if (elem instanceof Node) {
                    // this.dynamicProperty.updateRepositoryList();
                    String connectionId = value.toString().split(" - ")[0];
                    String tableLabel = value.toString().split(" - ")[1];
                    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                    Item item = null;
                    try {
                        IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                        if (repobj != null) {
                            Property property = repobj.getProperty();
                            if (property != null) {
                                item = property.getItem();
                            }
                        }
                    } catch (PersistenceException e) {
                        ExceptionHandler.process(e);
                    }
                    if (item != null && item instanceof ConnectionItem) {
                        boolean findTable = false;
                        Connection connection = ((ConnectionItem) item).getConnection();
                        for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                            if (table.getLabel().equals(tableLabel)) {
                                repositoryMetadata = ConvertionHelper.convert(table);
                                findTable = true;
                                break;
                            }
                        }
                        if (!findTable) {
                            repositoryMetadata = new MetadataTable();
                        }
                    }
                // if (repositoryTableMap.containsKey(value)) {
                // repositoryMetadata = repositoryTableMap.get(value);
                // realTableName = repositoryMetadata.getTableName();
                // realTableId = repositoryMetadata.getId();
                // } else {
                // repositoryMetadata = new MetadataTable();
                // }
                }
            }
        }
    }
    // Ends
    QueryGuessCommand cmd = null;
    INode node = null;
    if (elem instanceof INode) {
        node = (INode) elem;
    } else {
        // else instanceof Connection
        node = ((IConnection) elem).getSource();
    }
    newRepositoryMetadata = node.getMetadataList().get(0);
    if (newRepositoryMetadata == null) {
        String schemaSelected = (String) node.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
        if (schemaSelected != null) {
            String connectionId = schemaSelected.toString().split(" - ")[0];
            String tableLabel = schemaSelected.toString().split(" - ")[1];
            IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            Item item = null;
            try {
                IRepositoryViewObject repobj = factory.getLastVersion(connectionId);
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        item = property.getItem();
                    }
                }
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
            if (item != null && item instanceof ConnectionItem) {
                boolean findTable = false;
                Connection connection = ((ConnectionItem) item).getConnection();
                for (org.talend.core.model.metadata.builder.connection.MetadataTable table : ConnectionHelper.getTables(connection)) {
                    if (table.getLabel().equals(tableLabel)) {
                        repositoryMetadata = ConvertionHelper.convert(table);
                        findTable = true;
                        break;
                    }
                }
                if (!findTable) {
                    repositoryMetadata = new MetadataTable();
                }
            }
        // repositoryMetadata = repositoryTableMap.get(schemaSelected);
        } else if (newRepositoryMetadata == null) {
            MessageDialog.openWarning(new Shell(), Messages.getString("ComboController.alert"), //$NON-NLS-1$ //$NON-NLS-2$
            Messages.getString("ComboController.nothingGuess"));
            return cmd;
        }
    }
    cmd = new QueryGuessCommand(node, newRepositoryMetadata);
    /* parameter can be null,the setMaps won't use the third parameter */
    cmd.setMaps(dynamicProperty.getTableIdAndDbTypeMap(), dynamicProperty.getTableIdAndDbSchemaMap(), null);
    //$NON-NLS-1$
    String type = getValueFromRepositoryName("TYPE");
    cmd.setParameters(realTableId, realTableName, type);
    return cmd;
}
Also used : INode(org.talend.core.model.process.INode) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) Point(org.eclipse.swt.graphics.Point) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Shell(org.eclipse.swt.widgets.Shell) CCombo(org.eclipse.swt.custom.CCombo) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Aggregations

MetadataTable (org.talend.core.model.metadata.MetadataTable)61 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)46 IMetadataColumn (org.talend.core.model.metadata.IMetadataColumn)29 ArrayList (java.util.ArrayList)23 HashMap (java.util.HashMap)15 Map (java.util.Map)14 IElementParameter (org.talend.core.model.process.IElementParameter)14 Item (org.talend.core.model.properties.Item)14 MetadataColumn (org.talend.core.model.metadata.MetadataColumn)13 IConnection (org.talend.core.model.process.IConnection)13 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)13 Node (org.talend.designer.core.ui.editor.nodes.Node)11 List (java.util.List)9 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)9 Command (org.eclipse.gef.commands.Command)8 Point (org.eclipse.swt.graphics.Point)8 INode (org.talend.core.model.process.INode)8 ChangeMetadataCommand (org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand)8 PropertyChangeCommand (org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand)8 Connection (org.talend.designer.core.ui.editor.connections.Connection)8