Search in sources :

Example 1 with SAPConnectionItem

use of org.talend.core.model.properties.SAPConnectionItem in project tdi-studio-se by Talend.

the class RepositoryHelper method createTalendItem.

public TalendItem createTalendItem(Repository repository, Object object) {
    TalendItem result = null;
    if (object instanceof RepositoryNode) {
        RepositoryNode repositoryNode = (RepositoryNode) object;
        if (repositoryNode.getType() == RepositoryNode.ENodeType.REPOSITORY_ELEMENT) {
            IRepositoryViewObject repositoryObject = repositoryNode.getObject();
            ERepositoryObjectType nodeType = (ERepositoryObjectType) repositoryNode.getProperties(EProperties.CONTENT_TYPE);
            EClass class1 = getEClass(nodeType);
            if (class1 != null) {
                result = (TalendItem) BusinessFactory.eINSTANCE.create(class1);
                result.setRepository(repository);
                if (ERepositoryObjectType.METADATA_CON_TABLE.equals(repositoryObject.getRepositoryObjectType())) {
                    Property property = ((MetadataTableRepositoryObject) repositoryObject).getProperty();
                    Item item = property.getItem();
                    if (item instanceof SAPConnectionItem) {
                        if (repositoryNode.getParent() != null) {
                            result.setId(property.getId() + " - " + repositoryNode.getParent().getProperties(EProperties.LABEL) + " - " + repositoryObject.getLabel());
                        }
                    } else {
                        //$NON-NLS-1$
                        result.setId(property.getId() + " - " + repositoryObject.getLabel());
                    }
                } else if (ERepositoryObjectType.METADATA_CON_QUERY.equals(repositoryObject.getRepositoryObjectType())) {
                    Property property = ((QueryRepositoryObject) repositoryObject).getProperty();
                    //$NON-NLS-1$
                    result.setId(property.getId() + " - " + repositoryObject.getLabel());
                } else if (ERepositoryObjectType.METADATA_SAP_FUNCTION.equals(repositoryObject.getRepositoryObjectType())) {
                    Property property = ((SAPFunctionRepositoryObject) repositoryObject).getProperty();
                    //$NON-NLS-1$
                    result.setId(property.getId() + " - " + repositoryObject.getLabel());
                } else {
                    result.setId(repositoryObject.getId());
                }
                result.setLabel(repositoryObject.getLabel());
            }
        }
    }
    return result;
}
Also used : Item(org.talend.core.model.properties.Item) TalendItem(org.talend.designer.business.model.business.TalendItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) EClass(org.eclipse.emf.ecore.EClass) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TalendItem(org.talend.designer.business.model.business.TalendItem) RepositoryNode(org.talend.repository.model.RepositoryNode) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) Property(org.talend.core.model.properties.Property) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)

Example 2 with SAPConnectionItem

use of org.talend.core.model.properties.SAPConnectionItem in project tdi-studio-se by Talend.

the class ChangeValuesFromRepository method setOtherProperties.

/**
     * qzhang Comment method "setOtherProperties".
     */
private void setOtherProperties() {
    boolean metadataInput = false;
    IElementParameter currentParam = elem.getElementParameter(propertyName);
    Item item = null;
    IElementParameter repositoryParam = elem.getElementParameter(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
    if (repositoryParam != null) {
        item = UpdateRepositoryUtils.getConnectionItemByItemId((String) repositoryParam.getValue());
    }
    if (elem instanceof Node) {
        Node node = (Node) elem;
        if (node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_MAIN) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.FLOW_REF) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE) > 0 || node.getCurrentActiveLinksNbInput(EConnectionType.TABLE_REF) > 0) {
            metadataInput = true;
        }
        boolean hasSchema = elem.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE) != null ? true : elem.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE) != null;
        if (value.equals(EmfComponent.BUILTIN)) {
            if (!metadataInput && hasSchema) {
                elem.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), value);
            }
            elem.setPropertyValue(EParameterName.QUERYSTORE_TYPE.getName(), value);
        } else {
            if (hasSchema) {
                for (IElementParameter param : new ArrayList<IElementParameter>(elem.getElementParameters())) {
                    if (param.getFieldType().equals(EParameterFieldType.SCHEMA_TYPE) || (param.getFieldType().equals(EParameterFieldType.SCHEMA_REFERENCE) && EConnectionType.FLOW_MAIN.getName().equals(param.getContext()))) {
                        if (!metadataInput) {
                            IElementParameter repositorySchemaTypeParameter = param.getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
                            String repositoryTable = null;
                            if (propertyName.split(":")[1].equals(EParameterName.PROPERTY_TYPE.getName())) {
                                //$NON-NLS-1$
                                repositoryTable = (String) repositorySchemaTypeParameter.getValue();
                            } else if (item != null) {
                                if (item instanceof SAPConnectionItem) {
                                    if (getCurrentTableName() != null) {
                                        repositoryTable = item.getProperty().getId() + " - " + getCurrentTableName();
                                    }
                                } else {
                                    //$NON-NLS-1$
                                    repositoryTable = item.getProperty().getId() + " - " + getFirstRepositoryTable(item);
                                }
                                repositorySchemaTypeParameter.setValue(repositoryTable);
                            }
                            if (isNotSim) {
                                if (item != null && UpdateRepositoryUtils.getMetadataTablesFromItem(item) != null) {
                                    if (repositoryTable != null && !"".equals(repositoryTable)) {
                                        //$NON-NLS-1$
                                        param.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
                                        IMetadataTable table = MetadataToolHelper.getMetadataFromRepository(repositoryTable);
                                        // repositoryTableMap.get(repositoryTable);
                                        if (table != null) {
                                            table = table.clone();
                                            setDBTableFieldValue(node, table.getTableName(), null);
                                            setSAPFunctionName(node, table.getLabel());
                                            table.setTableName(node.getMetadataList().get(0).getTableName());
                                            if (!table.sameMetadataAs(node.getMetadataList().get(0))) {
                                                ChangeMetadataCommand cmd = new ChangeMetadataCommand(node, param, null, table, param);
                                                cmd.setConnection(connection);
                                                cmd.setRepositoryMode(true);
                                                cmd.execute(true);
                                            }
                                        }
                                    }
                                }
                            } else if (isMdmOutput()) {
                                if (item != null && UpdateRepositoryUtils.getMetadataTablesFromItem(item) != null && UpdateRepositoryUtils.getMetadataTablesFromItem(item).size() > 0) {
                                    if (repositoryTable != null && !"".equals(repositoryTable)) {
                                        //$NON-NLS-1$
                                        param.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
                                        IMetadataTable table = MetadataToolHelper.getMetadataFromRepository(repositoryTable);
                                        // repositoryTableMap.get(repositoryTable);
                                        if (table != null) {
                                            table = table.clone();
                                            setDBTableFieldValue(node, table.getTableName(), null);
                                            setSAPFunctionName(node, table.getLabel());
                                            table.setTableName(node.getMetadataList().get(0).getTableName());
                                            ChangeMetadataCommand cmd = new ChangeMetadataCommand(node, param, null, table, param);
                                            cmd.setConnection(connection);
                                            cmd.setRepositoryMode(true);
                                            cmd.execute(true);
                                        }
                                    }
                                }
                            } else {
                                if (item != null && UpdateRepositoryUtils.getMetadataTablesFromItem(item) != null && UpdateRepositoryUtils.getMetadataTablesFromItem(item).size() == 1) {
                                    if (repositoryTable != null && !"".equals(repositoryTable)) {
                                        //$NON-NLS-1$
                                        param.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
                                        IMetadataTable table = MetadataToolHelper.getMetadataFromRepository(repositoryTable);
                                        // repositoryTableMap.get(repositoryTable);
                                        if (table != null) {
                                            table = table.clone();
                                            setDBTableFieldValue(node, table.getTableName(), null);
                                            setSAPFunctionName(node, table.getLabel());
                                            table.setTableName(node.getMetadataList().get(0).getTableName());
                                            if (!table.sameMetadataAs(node.getMetadataList().get(0))) {
                                                ChangeMetadataCommand cmd = new ChangeMetadataCommand(node, param, null, table, param);
                                                cmd.setConnection(connection);
                                                cmd.setRepositoryMode(true);
                                                cmd.execute(true);
                                            }
                                        }
                                    }
                                } else // schema,it is invisible which design in the component
                                if (item != null && UpdateRepositoryUtils.getMetadataTablesFromItem(item) != null && (((INode) elem).getComponent().getName().equals("tWebService") || ((INode) elem).getComponent().getName().equals("tBRMS")) && UpdateRepositoryUtils.getMetadataTablesFromItem(item).size() == 2) {
                                    final List<MetadataTable> tables = UpdateRepositoryUtils.getMetadataTablesFromItem(item);
                                    if (tables != null && !tables.isEmpty()) {
                                        if (param.getName().equals("INPUT_SCHEMA")) {
                                            repositoryTable = item.getProperty().getId() + " - " + "Input";
                                            repositorySchemaTypeParameter.setValue(repositoryTable);
                                        } else {
                                            repositoryTable = item.getProperty().getId() + " - " + "Output";
                                            repositorySchemaTypeParameter.setValue(repositoryTable);
                                        }
                                        if (repositoryTable != null && !"".equals(repositoryTable)) {
                                            //$NON-NLS-1$
                                            param.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
                                            IMetadataTable table = MetadataToolHelper.getMetadataFromRepository(repositoryTable);
                                            if (table != null) {
                                                table = table.clone();
                                                setDBTableFieldValue(node, table.getTableName(), null);
                                                setSAPFunctionName(node, table.getLabel());
                                                INodeConnector mainConnector = node.getConnectorFromType(EConnectionType.FLOW_MAIN);
                                                IMetadataTable stable = null;
                                                INodeConnector outputConnector = mainConnector;
                                                if (mainConnector.getMaxLinkOutput() == 0) {
                                                    for (INodeConnector currentConnector : node.getListConnector()) {
                                                        if (!currentConnector.getBaseSchema().equals(EConnectionType.FLOW_MAIN.getName()) && currentConnector.getMaxLinkOutput() > 0) {
                                                            outputConnector = currentConnector;
                                                        }
                                                    }
                                                }
                                                if (param.getName().equals("INPUT_SCHEMA")) {
                                                    stable = node.getMetadataFromConnector("FLOW");
                                                } else if (param.getName().equals("SCHEMA")) {
                                                    stable = node.getMetadataFromConnector("OUTPUT");
                                                }
                                                if (stable != null) {
                                                    table.setTableName(stable.getTableName());
                                                    if (!table.sameMetadataAs(stable)) {
                                                        ChangeMetadataCommand cmd = new ChangeMetadataCommand(node, param, null, table, param);
                                                        cmd.setConnection(connection);
                                                        cmd.setRepositoryMode(true);
                                                        cmd.execute(true);
                                                    // break;
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        } else {
                            Node sourceNode = getRealSourceNode((INode) elem);
                            if (sourceNode != null) {
                                IMetadataTable sourceMetadataTable = sourceNode.getMetadataList().get(0);
                                Object sourceSchema = sourceNode.getPropertyValue(EParameterName.SCHEMA_TYPE.getName());
                                boolean isTake = !sourceNode.isExternalNode() && sourceSchema != null && elem.getPropertyValue(EParameterName.SCHEMA_TYPE.getName()) != null;
                                if (isTake && getTake()) {
                                    ChangeMetadataCommand cmd = new ChangeMetadataCommand((Node) elem, param, null, sourceMetadataTable, param);
                                    cmd.setConnection(connection);
                                    cmd.execute(true);
                                    elem.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), sourceSchema);
                                    if (sourceSchema.equals(EmfComponent.REPOSITORY)) {
                                        elem.setPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), sourceNode.getPropertyValue(EParameterName.REPOSITORY_SCHEMA_TYPE.getName()));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        IElementParameter queryParam = elem.getElementParameterFromField(EParameterFieldType.QUERYSTORE_TYPE, currentParam.getCategory());
        IElementParameter queryStoreType = null;
        if (queryParam != null) {
            queryStoreType = queryParam.getChildParameters().get(EParameterName.QUERYSTORE_TYPE.getName());
        }
        if (item != null) {
            final List<Query> queries = UpdateRepositoryUtils.getQueriesFromItem(item);
            if (propertyName.split(":")[1].equals(EParameterName.PROPERTY_TYPE.getName())) {
                //$NON-NLS-1$
                if (queries != null && !queries.isEmpty()) {
                    if (queryParam != null) {
                        queryStoreType.setValue(value);
                        if (value.equals(EmfComponent.REPOSITORY)) {
                            setQueryToRepositoryMode(queryParam, queries, item);
                        }
                    }
                // query change
                }
            } else {
                if (queryParam != null) {
                    if (this.isGuessQuery || queries == null || (queries != null && queries.isEmpty())) {
                        queryStoreType.setValue(EmfComponent.BUILTIN);
                    } else {
                        queryStoreType.setValue(EmfComponent.REPOSITORY);
                        setQueryToRepositoryMode(queryParam, queries, item);
                    }
                }
                List<MetadataTable> tables = UpdateRepositoryUtils.getMetadataTablesFromItem(item);
                if (tables == null || tables.isEmpty()) {
                    elem.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
                } else {
                    if (table != null && table.getTableName() != null) {
                        setDBTableFieldValue(node, table.getTableName(), null);
                    }
                }
            }
        }
    }
}
Also used : INode(org.talend.core.model.process.INode) Query(org.talend.core.model.metadata.builder.connection.Query) Node(org.talend.designer.core.ui.editor.nodes.Node) INode(org.talend.core.model.process.INode) ArrayList(java.util.ArrayList) INodeConnector(org.talend.core.model.process.INodeConnector) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter)

Example 3 with SAPConnectionItem

use of org.talend.core.model.properties.SAPConnectionItem in project tdi-studio-se by Talend.

the class AbstractSchemaController method createButtonCommand.

@Override
protected Command createButtonCommand(Button button) {
    // see 0003766: Problems with the read only mode of the properties on repository mode.
    if (checkForRepositoryShema(button)) {
        return null;
    }
    Button inputButton = button;
    IElementParameter switchParam = elem.getElementParameter(EParameterName.REPOSITORY_ALLOW_AUTO_SWITCH.getName());
    if (inputButton.getData(NAME).equals(SCHEMA)) {
        // this map wil hold the all input connection for the tUnite component
        Map<INode, Map<IMetadataTable, Boolean>> inputInfos = new HashMap<INode, Map<IMetadataTable, Boolean>>();
        INode node;
        if (elem instanceof Node) {
            node = (INode) elem;
        } else {
            // else instanceof Connection
            node = ((IConnection) elem).getSource();
        }
        IMetadataTable inputMetadata = null, inputMetaCopy = null;
        Connection inputConec = null;
        String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        IElementParameter param = node.getElementParameter(propertyName);
        IElementParameter connectionParam = param.getChildParameters().get(EParameterName.CONNECTION.getName());
        String connectionName = null;
        if (connectionParam != null) {
            connectionName = (String) connectionParam.getValue();
        }
        Object obj = button.getData(FORCE_READ_ONLY);
        boolean forceReadOnly = false;
        if (obj != null) {
            forceReadOnly = (Boolean) obj;
        }
        boolean inputReadOnly = false, outputReadOnly = false, inputReadOnlyNode = false, inputReadOnlyParam = false;
        for (Connection connec : (List<Connection>) node.getIncomingConnections()) {
            if (connec.isActivate() && (connec.getLineStyle().equals(EConnectionType.FLOW_MAIN) || connec.getLineStyle().equals(EConnectionType.TABLE) || connec.getLineStyle().equals(EConnectionType.FLOW_MERGE) || connec.getLineStyle() == EConnectionType.FLOW_REF)) {
                if (connectionName != null && !connec.getName().equals(connectionName)) {
                    continue;
                }
                inputMetadata = connec.getMetadataTable();
                inputMetaCopy = inputMetadata.clone();
                inputConec = connec;
                if (connec.getSource().isReadOnly()) {
                    inputReadOnlyNode = true;
                } else {
                    for (IElementParameter curParam : connec.getSource().getElementParameters()) {
                        if (curParam.getFieldType() == EParameterFieldType.SCHEMA_TYPE || curParam.getFieldType() == EParameterFieldType.SCHEMA_REFERENCE) {
                            if (curParam.isReadOnly()) {
                                inputReadOnlyParam = true;
                            }
                        }
                    }
                }
                // check if the inputMetadata is readonly
                if (inputMetadata != null) {
                    for (IMetadataColumn column : inputMetadata.getListColumns(true)) {
                        IMetadataColumn columnCopied = inputMetaCopy.getColumn(column.getLabel());
                        columnCopied.setCustom(column.isCustom());
                        columnCopied.setReadOnly(column.isReadOnly());
                    }
                    inputMetaCopy.setReadOnly(inputMetadata.isReadOnly());
                    inputReadOnly = prepareReadOnlyTable(inputMetaCopy, inputReadOnlyParam, inputReadOnlyNode);
                }
                // store the value for Dialog
                Map<IMetadataTable, Boolean> oneInput = new HashMap<IMetadataTable, Boolean>();
                oneInput.put(inputMetaCopy, inputReadOnly);
                inputInfos.put(connec.getSource(), oneInput);
            }
        }
        if (connectionParam != null && inputMetadata == null) {
            //$NON-NLS-1$
            MessageDialog.openError(//$NON-NLS-1$
            button.getShell(), //$NON-NLS-1$
            Messages.getString("AbstractSchemaController.inputNotSet"), //$NON-NLS-1$
            Messages.getString("AbstractSchemaController.connectionNotAvaliable"));
            return null;
        }
        IMetadataTable originaleMetadataTable = getMetadataTableFromXml(node);
        // check if the outputMetadata is readonly
        IMetadataTable originaleOutputTable = node.getMetadataFromConnector(param.getContext());
        // when several schema_type button ,need get the right one which is opening
        //$NON-NLS-1$
        IElementParameter schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
        // need setRepository here
        if (!param.getContext().equals(schemaParam.getContext())) {
            //$NON-NLS-1$
            schemaParam = param.getChildParameters().get("SCHEMA_TYPE");
        }
        if (schemaParam != null && EmfComponent.REPOSITORY.equals(schemaParam.getValue())) {
            if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
                ((MetadataTable) originaleOutputTable).setRepository(true);
            }
        } else if (schemaParam != null && EmfComponent.BUILTIN.equals(schemaParam.getValue())) {
            if (originaleOutputTable != null && originaleOutputTable instanceof MetadataTable) {
                ((MetadataTable) originaleOutputTable).setRepository(false);
            }
        }
        if ("tUniservBTGeneric".equals(node.getComponent().getName())) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            originaleOutputTable = node.getMetadataTable("OUTPUT_SCHEMA");
        }
        IMetadataTable outputMetaCopy = originaleOutputTable.clone(true);
        for (IMetadataColumn column : originaleOutputTable.getListColumns(true)) {
            IMetadataColumn columnCopied = outputMetaCopy.getColumn(column.getLabel());
            columnCopied.setCustom(column.isCustom());
            columnCopied.setReadOnly(column.isReadOnly());
            if (//$NON-NLS-1$ //$NON-NLS-2$
            ("tLogCatcher".equals(node.getComponent().getName()) || "tStatCatcher".equals(node.getComponent().getName())) && !outputMetaCopy.sameMetadataAs(originaleMetadataTable, IMetadataColumn.OPTIONS_NONE)) {
                columnCopied.setReadOnly(false);
            }
        }
        outputMetaCopy.setReadOnly(originaleOutputTable.isReadOnly() || param.isReadOnly(node.getElementParametersWithChildrens()));
        if (//$NON-NLS-1$ //$NON-NLS-2$
        ("tLogCatcher".equals(node.getComponent().getName()) || "tStatCatcher".equals(node.getComponent().getName())) && !outputMetaCopy.sameMetadataAs(originaleMetadataTable, IMetadataColumn.OPTIONS_NONE)) {
            outputMetaCopy.setReadOnly(false);
        }
        //$NON-NLS-1$
        IElementParameter schemaTypeParam = param.getChildParameters().get("SCHEMA_TYPE");
        List<IElementParameterDefaultValue> defaultValues = schemaTypeParam.getDefaultValues();
        for (IElementParameterDefaultValue elementParameterDefaultValue : defaultValues) {
            if (elementParameterDefaultValue.getDefaultValue() instanceof MetadataTable) {
                MetadataTable table = (MetadataTable) elementParameterDefaultValue.getDefaultValue();
                outputMetaCopy.setReadOnlyColumnPosition(table.getReadOnlyColumnPosition());
                break;
            }
        }
        outputMetaCopy.sortCustomColumns();
        if (!forceReadOnly) {
            outputReadOnly = prepareReadOnlyTable(outputMetaCopy, param.isReadOnly(), node.isReadOnly());
        } else {
            outputReadOnly = true;
        }
        // create the MetadataDialog
        MetadataDialog metaDialog = null;
        if (inputMetadata != null) {
            if (inputInfos != null && inputInfos.size() > 1 && connectionName == null) {
                MetadataDialogForMerge metaDialogForMerge = new MetadataDialogForMerge(composite.getShell(), inputInfos, outputMetaCopy, node, getCommandStack());
                //$NON-NLS-1$
                metaDialogForMerge.setText(Messages.getString("AbstractSchemaController.schemaOf") + node.getLabel());
                metaDialogForMerge.setInputReadOnly(inputReadOnly);
                metaDialogForMerge.setOutputReadOnly(outputReadOnly);
                if (metaDialogForMerge.open() == MetadataDialogForMerge.OK) {
                    // inputMetaCopy = metaDialog.getInputMetaData();
                    outputMetaCopy = metaDialogForMerge.getOutputMetaData();
                    // check if the metadata is modified
                    boolean modified = false;
                    if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                        modified = true;
                    } else {
                        if (inputMetadata != null) {
                            // Notice: the Map inputInfos maybe is modified by the dialog.
                            Set<INode> inputNodes = inputInfos.keySet();
                            for (INode inputNode : inputNodes) {
                                Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                                inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                                if (!inputMetaCopy.sameMetadataAs(inputNode.getMetadataList().get(0), IMetadataColumn.OPTIONS_NONE)) {
                                    modified = true;
                                }
                            }
                        }
                    }
                    // create the changeMetadataCommand
                    if (modified) {
                        if (switchParam != null) {
                            switchParam.setValue(Boolean.FALSE);
                        }
                        Command changeMetadataCommand = null;
                        // only output, no input
                        if (inputInfos.isEmpty()) {
                            changeMetadataCommand = new ChangeMetadataCommand(node, param, null, null, null, originaleOutputTable, outputMetaCopy);
                        } else {
                            Set<INode> inputNodes = inputInfos.keySet();
                            int count = 0;
                            for (INode inputNode : inputNodes) {
                                Map<IMetadataTable, Boolean> oneInput = inputInfos.get(inputNode);
                                inputMetaCopy = (IMetadataTable) oneInput.keySet().toArray()[0];
                                if (count == 0) {
                                    changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy);
                                } else {
                                    changeMetadataCommand = changeMetadataCommand.chain(new ChangeMetadataCommand(node, param, inputNode, inputNode.getMetadataList().get(0), inputMetaCopy, originaleOutputTable, outputMetaCopy));
                                }
                                count++;
                            }
                        }
                        return changeMetadataCommand;
                    }
                }
            } else {
                INode inputNode = (inputConec.getSource());
                if (inputMetaCopy.getAttachedConnector() == null) {
                    INodeConnector mainConnector;
                    if (inputNode.isELTComponent()) {
                        mainConnector = inputNode.getConnectorFromType(EConnectionType.TABLE);
                    } else {
                        mainConnector = inputNode.getConnectorFromType(EConnectionType.FLOW_MAIN);
                    }
                    inputMetaCopy.setAttachedConnector(mainConnector.getName());
                }
                metaDialog = new MetadataDialog(composite.getShell(), inputMetaCopy, inputNode, outputMetaCopy, node, getCommandStack());
            }
        } else {
            metaDialog = new MetadataDialog(composite.getShell(), outputMetaCopy, node, getCommandStack());
        }
        if (metaDialog != null) {
            //$NON-NLS-1$
            metaDialog.setText(Messages.getString("AbstractSchemaController.schema.title", node.getLabel()));
            metaDialog.setInputReadOnly(inputReadOnly);
            metaDialog.setOutputReadOnly(outputReadOnly);
            setMetadataTableOriginalNameList(inputMetadata, inputMetaCopy);
            setMetadataTableOriginalNameList(originaleOutputTable, outputMetaCopy);
            if (metaDialog.open() == MetadataDialog.OK) {
                inputMetaCopy = metaDialog.getInputMetaData();
                outputMetaCopy = metaDialog.getOutputMetaData();
                boolean modified = false;
                if (!outputMetaCopy.sameMetadataAs(originaleOutputTable, IMetadataColumn.OPTIONS_NONE)) {
                    modified = true;
                } else {
                    if (inputMetadata != null) {
                        if (!inputMetaCopy.sameMetadataAs(inputMetadata, IMetadataColumn.OPTIONS_NONE)) {
                            modified = true;
                        }
                    }
                }
                if (modified) {
                    if (switchParam != null) {
                        switchParam.setValue(Boolean.FALSE);
                    }
                    INode inputNode = null;
                    if (inputConec != null) {
                        inputNode = inputConec.getSource();
                    }
                    ChangeMetadataCommand changeMetadataCommand = new ChangeMetadataCommand(node, param, inputNode, inputMetadata, inputMetaCopy, originaleOutputTable, outputMetaCopy);
                    return changeMetadataCommand;
                }
            }
        }
    } else if (inputButton.getData(NAME).equals(RETRIEVE_SCHEMA)) {
        Node node = (Node) elem;
        // String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        final Command cmd = RetrieveSchemaHelper.retrieveSchemasCommand(node);
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        return cmd;
    } else if (inputButton.getData(NAME).equals(RESET_COLUMNS)) {
        Node node = (Node) elem;
        String propertyName = (String) inputButton.getData(PARAMETER_NAME);
        IElementParameter param = node.getElementParameter(propertyName);
        final Command cmd = SynchronizeSchemaHelper.createCommand(node, param);
        if (switchParam != null) {
            switchParam.setValue(Boolean.FALSE);
        }
        return cmd;
    } else if (button.getData(NAME).equals(REPOSITORY_CHOICE)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter schemaParam = elem.getElementParameter(paramName);
        ERepositoryObjectType type = ERepositoryObjectType.METADATA_CON_TABLE;
        String filter = schemaParam.getFilter();
        if (elem instanceof Node) {
            Node sapNode = (Node) elem;
            if (sapNode.getComponent().getName().startsWith("tESB")) {
                //$NON-NLS-1$
                filter = ERepositoryObjectType.SERVICESOPERATION.getType();
            }
        }
        RepositoryReviewDialog dialog = new RepositoryReviewDialog(button.getShell(), type, filter);
        if (dialog.open() == RepositoryReviewDialog.OK) {
            RepositoryNode node = dialog.getResult();
            while (node.getObject().getProperty().getItem() == null || (!(node.getObject().getProperty().getItem() instanceof ConnectionItem))) {
                node = node.getParent();
            }
            IRepositoryViewObject object = dialog.getResult().getObject();
            Property property = object.getProperty();
            String id = property.getId();
            // The name is Table Name.
            String name = object.getLabel();
            org.talend.core.model.metadata.builder.connection.MetadataTable table = null;
            if (property.getItem() instanceof SAPConnectionItem && object instanceof MetadataTableRepositoryObject) {
                MetadataTableRepositoryObject metadataObject = (MetadataTableRepositoryObject) object;
                table = (org.talend.core.model.metadata.builder.connection.MetadataTable) metadataObject.getModelElement();
                if (table.eContainer() instanceof SAPFunctionUnit) {
                    SAPFunctionUnit function = (SAPFunctionUnit) table.eContainer();
                    String tableType = table.getTableType() == null ? MetadataSchemaType.OUTPUT.name() : table.getTableType();
                    //$NON-NLS-1$ //$NON-NLS-2$
                    name = function.getLabel() + "/" + tableType + "/" + name;
                }
            }
            if (name != null) {
                if (elem instanceof Node) {
                    Node nodeElement = (Node) elem;
                    //$NON-NLS-1$
                    String value = id + " - " + name;
                    IMetadataTable repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
                    if (nodeElement.getComponent().getName().equals("tSQLTemplateMerge")) {
                        //$NON-NLS-1$
                        if (paramName.equals("SCHEMA")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            paramName = "SOURCE_TABLE";
                            Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            executeCommand(dbSelectorCommand);
                            Text labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            //$NON-NLS-1$
                            paramName = "SCHEMA:REPOSITORY_SCHEMA_TYPE";
                            dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
                            executeCommand(dbSelectorCommand);
                            labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(name));
                            //$NON-NLS-1$
                            paramName = "SCHEMA";
                        } else if (paramName.equals("SCHEMA_TARGET")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            paramName = "TARGET_TABLE";
                            Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            executeCommand(dbSelectorCommand);
                            Text labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            //$NON-NLS-1$
                            paramName = "SCHEMA_TARGET:REPOSITORY_SCHEMA_TYPE";
                            dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
                            executeCommand(dbSelectorCommand);
                            labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(name));
                            //$NON-NLS-1$
                            paramName = "SCHEMA_TARGET";
                        }
                    } else if (nodeElement.getComponent().getName().startsWith("tSQLTemplate")) {
                        //$NON-NLS-1$
                        if (paramName.equals("SCHEMA")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            paramName = "TABLE_NAME";
                            Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            executeCommand(dbSelectorCommand);
                            Text labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            //$NON-NLS-1$
                            paramName = "SCHEMA:REPOSITORY_SCHEMA_TYPE";
                            dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
                            executeCommand(dbSelectorCommand);
                            labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(name));
                            //$NON-NLS-1$
                            paramName = "SCHEMA";
                        } else if (paramName.equals("SCHEMA_TARGET")) {
                            //$NON-NLS-1$
                            //$NON-NLS-1$
                            paramName = "TABLE_NAME_TARGET";
                            Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            executeCommand(dbSelectorCommand);
                            Text labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                            //$NON-NLS-1$
                            paramName = "SCHEMA_TARGET:REPOSITORY_SCHEMA_TYPE";
                            dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(name));
                            executeCommand(dbSelectorCommand);
                            labelText = (Text) hashCurControls.get(paramName);
                            labelText.setText(TalendTextUtils.addQuotes(name));
                            //$NON-NLS-1$
                            paramName = "SCHEMA_TARGET";
                        }
                    } else if (nodeElement.getComponent().getName().startsWith("tSalesforce")) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        paramName = paramName + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName();
                        Command selectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(value));
                        executeCommand(selectorCommand);
                    } else {
                        Command dbSelectorCommand = new PropertyChangeCommand(elem, paramName, TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                        executeCommand(dbSelectorCommand);
                        Text labelText = (Text) hashCurControls.get(paramName);
                        if (labelText != null) {
                            labelText.setText(TalendTextUtils.addQuotes(repositoryMetadata.getTableName()));
                        }
                    }
                }
            }
            //$NON-NLS-1$
            String value = id + " - " + name;
            //$NON-NLS-1$
            String fullParamName = paramName + ":" + getRepositoryChoiceParamName();
            org.talend.core.model.metadata.builder.connection.Connection connection = null;
            if (elem instanceof Node) {
                IMetadataTable repositoryMetadata = null;
                if (table != null && table instanceof SAPBWTable) {
                    repositoryMetadata = ConvertionHelper.convert(table);
                } else {
                    repositoryMetadata = MetadataToolHelper.getMetadataFromRepository(value);
                    connection = MetadataToolHelper.getConnectionFromRepository(value);
                }
                // For SAP see bug 5423
                String functionId = node.getParent().getId();
                if (//$NON-NLS-1$//$NON-NLS-2$
                ((Node) elem).getUniqueName().startsWith("tSAP") && !((Node) elem).getUniqueName().startsWith("tSAPHana") && functionId != "-1") {
                    //$NON-NLS-1$
                    Node sapNode = (Node) elem;
                    repositoryMetadata = getMetadataFromRepository(id, functionId, name);
                    String functionName = node.getParent().getObject().getLabel();
                    for (IElementParameter param : sapNode.getElementParameters()) {
                        SAPParametersUtils.retrieveSAPParams(elem, connection, param, functionName);
                    }
                }
                // For validation rule.
                boolean isValRulesLost = false;
                IRepositoryViewObject currentValRuleObj = ValidationRulesUtil.getCurrentValidationRuleObjs(elem);
                if (currentValRuleObj != null) {
                    List<IRepositoryViewObject> valRuleObjs = ValidationRulesUtil.getRelatedValidationRuleObjs(value);
                    if (!ValidationRulesUtil.isCurrentValRuleObjInList(valRuleObjs, currentValRuleObj)) {
                        if (!MessageDialog.openConfirm(button.getShell(), //$NON-NLS-1$
                        Messages.getString("AbstractSchemaController.validationrule.title.confirm"), Messages.getString("AbstractSchemaController.validationrule.selectMetadataMsg"))) {
                            //$NON-NLS-1$
                            return null;
                        } else {
                            isValRulesLost = true;
                        }
                    }
                }
                if (repositoryMetadata == null) {
                    repositoryMetadata = new MetadataTable();
                }
                if (switchParam != null) {
                    switchParam.setValue(Boolean.FALSE);
                }
                CompoundCommand cc = new CompoundCommand();
                RepositoryChangeMetadataCommand changeMetadataCommand = new RepositoryChangeMetadataCommand((Node) elem, fullParamName, value, repositoryMetadata, null, null, table);
                changeMetadataCommand.setConnection(connection);
                cc.add(changeMetadataCommand);
                if (isValRulesLost) {
                    ValidationRulesUtil.appendRemoveValidationRuleCommands(cc, elem);
                }
                return cc;
            }
        }
    } else if (button.getData(NAME).equals(COPY_CHILD_COLUMNS)) {
        String paramName = (String) button.getData(PARAMETER_NAME);
        IElementParameter param = elem.getElementParameter(paramName);
        IElementParameter processParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
        IElementParameter processIdParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
        String id = (String) processIdParam.getValue();
        Item item = ItemCacheManager.getProcessItem(id);
        Node node = (Node) elem;
        copySchemaFromChildJob(node, item);
        // pop up the schema dialog
        MetadataDialog metaDialog = new MetadataDialog(composite.getShell(), node.getMetadataList().get(0), node, getCommandStack());
        //$NON-NLS-1$
        metaDialog.setText(Messages.getString("AbstractSchemaController.schemaOf") + node.getLabel());
        if (metaDialog.open() == MetadataDialog.OK) {
            IMetadataTable outputMetaData = metaDialog.getOutputMetaData();
            return new ChangeMetadataCommand(node, param, null, outputMetaData);
        }
    }
    return null;
}
Also used : INode(org.talend.core.model.process.INode) HashMap(java.util.HashMap) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) 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) INodeConnector(org.talend.core.model.process.INodeConnector) 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) Button(org.eclipse.swt.widgets.Button) IElementParameterDefaultValue(org.talend.core.model.process.IElementParameterDefaultValue) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataTable(org.talend.core.model.metadata.MetadataTable) MetadataDialog(org.talend.core.ui.metadata.dialog.MetadataDialog) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) ChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.ChangeMetadataCommand) IElementParameter(org.talend.core.model.process.IElementParameter) List(java.util.List) ArrayList(java.util.ArrayList) SAPBWTable(org.talend.core.model.metadata.builder.connection.SAPBWTable) ERepositoryObjectType(org.talend.core.model.repository.ERepositoryObjectType) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) 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) Text(org.eclipse.swt.widgets.Text) IMetadataColumn(org.talend.core.model.metadata.IMetadataColumn) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RepositoryReviewDialog(org.talend.repository.ui.dialog.RepositoryReviewDialog) Point(org.eclipse.swt.graphics.Point) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) 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) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) Map(java.util.Map) HashMap(java.util.HashMap) MetadataDialogForMerge(org.talend.core.ui.metadata.dialog.MetadataDialogForMerge)

Example 4 with SAPConnectionItem

use of org.talend.core.model.properties.SAPConnectionItem in project tdi-studio-se by Talend.

the class ComponentChooseDialog method getChangeMetadataCommand.

/**
     * DOC bqian Comment method "getChangeMetadataCommand".
     *
     * @param selectedNode
     * @param node
     * @param list
     * @param connectionItem
     */
private void getChangeMetadataCommand(CompoundCommand cc, RepositoryNode selectedNode, Node node, ConnectionItem connectionItem) {
    if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_COLUMN) {
        RepositoryNode columnParentNode = selectedNode.getParent().getParent();
        if (columnParentNode != null) {
            selectedNode = columnParentNode;
        }
    }
    if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_TABLE || selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_SAP_FUNCTION || selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_SALESFORCE_MODULE) {
        String etlSchema = null;
        if (connectionItem.getConnection() instanceof DatabaseConnection) {
            DatabaseConnection connection = (DatabaseConnection) connectionItem.getConnection();
            if (connection instanceof DatabaseConnection) {
                etlSchema = connection.getUiSchema();
            }
            if (!"".equals(etlSchema)) {
                //$NON-NLS-1$
                //$NON-NLS-1$
                IElementParameter e = node.getElementParameter("ELT_SCHEMA_NAME");
                if (e != null) {
                    if (connection.isContextMode() && ContextParameterUtils.isContainContextParam(etlSchema)) {
                        e.setValue(etlSchema);
                    } else {
                        e.setValue(TalendTextUtils.addQuotes(etlSchema));
                    }
                }
            // node.getElementParameter("ELT_SCHEMA_NAME").setValue("\"" + etlSchema + "\"");
            }
        }
        IRepositoryViewObject object = selectedNode.getObject();
        MetadataTable table = null;
        if (object instanceof MetadataTableRepositoryObject) {
            table = ((MetadataTableRepositoryObject) object).getTable();
        } else if (object instanceof SalesforceModuleRepositoryObject) {
            table = ((SalesforceModuleRepositoryObject) object).getDefaultTable();
            IRepositoryViewObject obj = null;
            if (selectedNode.getChildren() != null) {
                for (IRepositoryNode repositoryNode : selectedNode.getChildren()) {
                    obj = repositoryNode.getObject();
                    if (obj instanceof MetadataTableRepositoryObject) {
                        table = ((MetadataTableRepositoryObject) obj).getTable();
                        break;
                    }
                }
            }
        }
        // for SAP
        if (PluginChecker.isSAPWizardPluginLoaded() && connectionItem instanceof SAPConnectionItem) {
            getSAPCommand(cc, object, connectionItem, table, node);
            return;
        }
        if (table != null) {
            //$NON-NLS-1$
            String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
            IElementParameter schemaParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
            if (schemaParam == null) {
                schemaParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_REFERENCE);
            }
            IElementParameter queryParam = node.getElementParameterFromField(EParameterFieldType.QUERYSTORE_TYPE);
            if (queryParam != null) {
                queryParam = queryParam.getChildParameters().get(EParameterName.QUERYSTORE_TYPE.getName());
                if (queryParam != null) {
                    queryParam.setValue(EmfComponent.BUILTIN);
                }
            }
            // }
            if (PluginChecker.isHL7PluginLoaded() && connectionItem instanceof HL7ConnectionItem) {
                Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(node, IEbcdicConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
                cc.add(hl7Cmd);
                return;
            }
            if (schemaParam == null) {
                return;
            }
            if (node.isELTComponent()) {
                //$NON-NLS-1$
                node.setPropertyValue(EParameterName.LABEL.getName(), "__ELT_TABLE_NAME__");
            }
            schemaParam.getChildParameters().get(EParameterName.SCHEMA_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
            RepositoryChangeMetadataCommand command2 = new RepositoryChangeMetadataCommand(node, //$NON-NLS-1$
            schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, ConvertionHelper.convert(table), null, connectionItem.getConnection());
            cc.add(command2);
            return;
        }
    }
}
Also used : RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) IRepositoryNode(org.talend.repository.model.IRepositoryNode) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) ConnectionCreateCommand(org.talend.designer.core.ui.editor.cmd.ConnectionCreateCommand) RepositoryChangeMetadataForSAPCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForSAPCommand) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) CreateNodeContainerCommand(org.talend.designer.core.ui.editor.cmd.CreateNodeContainerCommand) RepositoryChangeQueryCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeQueryCommand) ConnectionReconnectCommand(org.talend.designer.core.ui.editor.cmd.ConnectionReconnectCommand) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) RepositoryChangeMetadataForEBCDICCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForEBCDICCommand) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection)

Example 5 with SAPConnectionItem

use of org.talend.core.model.properties.SAPConnectionItem in project tdi-studio-se by Talend.

the class RepositoryService method setInternalNodeHTMLMap.

@Override
public void setInternalNodeHTMLMap(INode node, Map<String, Object> internalNodeHTMLMap) {
    IElementParameter propertyParam = null;
    IElementParameter functionParam = null;
    for (IElementParameter param : node.getElementParameters()) {
        if ("PROPERTY".equals(param.getName())) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            propertyParam = param.getChildParameters().get("REPOSITORY_PROPERTY_TYPE");
        }
        if ("SAP_FUNCTION".equals(param.getName())) {
            //$NON-NLS-1$
            functionParam = param;
        }
    }
    if (propertyParam != null && functionParam != null) {
        try {
            IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion((String) propertyParam.getValue());
            if (lastVersion != null) {
                Item item = lastVersion.getProperty().getItem();
                if (item instanceof SAPConnectionItem) {
                    SAPConnectionItem sapItem = (SAPConnectionItem) item;
                    SAPConnection connection = (SAPConnection) sapItem.getConnection();
                    connection.getFuntions();
                    for (Object obj : connection.getFuntions()) {
                        if (obj instanceof SAPFunctionUnit) {
                            SAPFunctionUnit function = (SAPFunctionUnit) obj;
                            String functionName = (String) functionParam.getValue();
                            if (function.getName().equals(functionName.substring(1, functionName.length() - 1))) {
                                if (!function.getDocument().isEmpty()) {
                                    String document = ModelElementHelper.getFirstDocument(function).getReference();
                                    if (document != null && !"".equals(document)) {
                                        //$NON-NLS-1$
                                        internalNodeHTMLMap.put(node.getUniqueName(), //$NON-NLS-1$ //$NON-NLS-2$
                                        document.substring(document.indexOf("<font"), document.indexOf("</body>")));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
    }
}
Also used : SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) RulesItem(org.talend.core.model.properties.RulesItem) SAPConnection(org.talend.core.model.metadata.builder.connection.SAPConnection) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) JSONObject(org.talend.utils.json.JSONObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject)

Aggregations

SAPConnectionItem (org.talend.core.model.properties.SAPConnectionItem)5 IElementParameter (org.talend.core.model.process.IElementParameter)4 Item (org.talend.core.model.properties.Item)4 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)4 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 MetadataTableRepositoryObject (org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)3 RepositoryNode (org.talend.repository.model.RepositoryNode)3 ArrayList (java.util.ArrayList)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)2 SAPFunctionUnit (org.talend.core.model.metadata.builder.connection.SAPFunctionUnit)2 INode (org.talend.core.model.process.INode)2 INodeConnector (org.talend.core.model.process.INodeConnector)2 ConnectionItem (org.talend.core.model.properties.ConnectionItem)2 ContextItem (org.talend.core.model.properties.ContextItem)2 ProcessItem (org.talend.core.model.properties.ProcessItem)2 Property (org.talend.core.model.properties.Property)2 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)2 SalesforceModuleRepositoryObject (org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject)2