Search in sources :

Example 1 with SAPFunctionUnit

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

the class ComponentChooseDialog method getSAPCommand.

/**
     * Added by Marvin Wang on July 12, 2012 for getting the command of SAP.
     *
     * @param object
     * @param connectionItem
     * @param table
     * @param node
     * @return
     */
private void getSAPCommand(CompoundCommand cc, IRepositoryViewObject object, ConnectionItem connectionItem, MetadataTable table, Node node) {
    SAPFunctionUnit functionUnit = null;
    if (object instanceof MetadataTableRepositoryObject) {
        IElementParameter schemaParam = null;
        List<IElementParameter> schemaTypeList = node.getElementParametersFromField(EParameterFieldType.SCHEMA_TYPE);
        for (IElementParameter param : schemaTypeList) {
            if (param.getName().equals("SCHEMA")) {
                //$NON-NLS-1$
                schemaParam = param;
                break;
            }
        }
        if (table.eContainer() instanceof SAPFunctionUnit) {
            // function parameter table
            functionUnit = (SAPFunctionUnit) table.eContainer();
            // To judge what the current node is, tSAPOutput or tSAPInput component.
            String sapComponentName = node.getComponent().getName();
            if ("tSAPBapi".equals(sapComponentName)) {
                //$NON-NLS-1$
                RepositoryChangeMetadataForSAPBapi command = new RepositoryChangeMetadataForSAPBapi(node, (SAPFunctionUnit) table.eContainer(), ConvertionHelper.convert(table), null);
                cc.add(command);
            } else {
                if (schemaParam != null) {
                    // repository id should be connectionid - sapfunctionName/type/tableName
                    String type = table.getTableType() == null ? MetadataSchemaType.OUTPUT.name() : table.getTableType();
                    String value = connectionItem.getProperty().getId() + " - " + functionUnit.getLabel() + "/" + type + "/" + //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
                    table.getLabel();
                    RepositoryChangeMetadataCommand changeValueCmd = new RepositoryChangeMetadataCommand(node, //$NON-NLS-1$
                    schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, ConvertionHelper.convert(table), null, connectionItem.getConnection());
                    cc.add(changeValueCmd);
                }
                IElementParameter schemasParam = node.getElementParameter(ISAPConstant.TABLE_SCHEMAS);
                if (schemasParam != null) {
                    Command sapCmd = new RepositoryChangeMetadataForSAPCommand(node, ISAPConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table), functionUnit);
                    cc.add(sapCmd);
                }
            }
        } else {
            // Sap Table : keep repository id as before
            if (schemaParam != null) {
                //$NON-NLS-1$
                String value = connectionItem.getProperty().getId() + " - " + table.getLabel();
                RepositoryChangeMetadataCommand changeValueCmd = new RepositoryChangeMetadataCommand(node, //$NON-NLS-1$
                schemaParam.getName() + ":" + EParameterName.REPOSITORY_SCHEMA_TYPE.getName(), value, ConvertionHelper.convert(table), null, connectionItem.getConnection(), table);
                cc.add(changeValueCmd);
            }
        }
    } else if (object instanceof SAPFunctionRepositoryObject) {
        functionUnit = (SAPFunctionUnit) ((SAPFunctionRepositoryObject) object).getAbstractMetadataObject();
        if (node.getComponent() != null && node.getComponent().getName().equals("tSAPBapi")) {
            //$NON-NLS-1$
            RepositoryChangeMetadataForSAPBapi command = new RepositoryChangeMetadataForSAPBapi(node, functionUnit, null, null);
            cc.add(command);
        } else {
            for (MetadataTable metadataTable : functionUnit.getTables()) {
                Command sapCmd = new RepositoryChangeMetadataForSAPCommand(node, ISAPConstant.TABLE_SCHEMAS, metadataTable.getLabel(), ConvertionHelper.convert(metadataTable), functionUnit);
                cc.add(sapCmd);
            }
        }
    }
}
Also used : RepositoryChangeMetadataForSAPBapi(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForSAPBapi) RepositoryChangeMetadataCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeMetadataCommand) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) 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) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) IElementParameter(org.talend.core.model.process.IElementParameter) RepositoryChangeMetadataForSAPCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForSAPCommand) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)

Example 2 with SAPFunctionUnit

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

the class ComponentChooseDialog method setSAPSpecailValueForCommand.

private void setSAPSpecailValueForCommand(RepositoryNode selectedNode, ChangeValuesFromRepository command) {
    // Noted by Marvin Wang on Jun. 29, 2012. The piece of code is used to judge if the selected node is SAP
    // Table node, if so, set up the table name to command.
    IRepositoryViewObject object = selectedNode.getObject();
    if (object instanceof MetadataColumnRepositoryObject) {
        object = selectedNode.getParent().getParent().getObject();
    }
    SAPFunctionUnit unit = null;
    if (object != null) {
        if (object instanceof MetadataTableRepositoryObject) {
            MetadataTableRepositoryObject tableObject = (MetadataTableRepositoryObject) object;
            MetadataTable abstractMetadataObject = (MetadataTable) tableObject.getAbstractMetadataObject();
            if (abstractMetadataObject != null && abstractMetadataObject.eContainer() instanceof SAPFunctionUnit) {
                unit = (SAPFunctionUnit) abstractMetadataObject.eContainer();
                command.setSapFunctionLabel(unit.getLabel());
                // set table name to functionName/type/tablename;
                String currentTableName = //$NON-NLS-1$ //$NON-NLS-2$
                unit.getLabel() + "/" + abstractMetadataObject.getTableType() + "/" + abstractMetadataObject.getLabel();
                command.setCurrentTableName(currentTableName);
            } else if (abstractMetadataObject instanceof SAPTable) {
                command.setCurrentTableName(abstractMetadataObject.getLabel());
            }
        } else if (object instanceof SAPFunctionRepositoryObject) {
            SAPFunctionRepositoryObject sapObj = (SAPFunctionRepositoryObject) object;
            unit = sapObj.getModelElement();
            command.setSapFunctionLabel(unit.getLabel());
        } else if (object instanceof SAPIDocRepositoryObject) {
            SAPIDocRepositoryObject sapObj = (SAPIDocRepositoryObject) object;
            command.setSapIDocLabel(sapObj.getLabel());
        }
    }
}
Also used : SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPTable(org.talend.core.model.metadata.builder.connection.SAPTable) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject)

Example 3 with SAPFunctionUnit

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

the class SAPParametersUtils method retrieveSAPParams.

/**
     * DOC xye Comment method "retrieveSAPParams".
     * 
     * @param param
     */
@SuppressWarnings("unchecked")
public static void retrieveSAPParams(final IElement elem, final Connection connection, final IElementParameter param, final String sapFunctionLabel) {
    if (param.getRepositoryValue() == null || !(connection instanceof SAPConnection)) {
        return;
    }
    if (param.getFieldType().equals(EParameterFieldType.TEXT) && param.getRepositoryValue().equals("SAP_FUNCTION")) {
        //$NON-NLS-1$
        if (connection != null && sapFunctionLabel != null) {
            SAPFunctionUnit unit = null;
            for (int i = 0; i < ((SAPConnection) connection).getFuntions().size(); i++) {
                SAPFunctionUnit tmp = ((SAPConnection) connection).getFuntions().get(i);
                if (tmp.getLabel().equals(sapFunctionLabel)) {
                    unit = tmp;
                    break;
                }
            }
            if (unit == null) {
                return;
            }
            param.setValue(TalendTextUtils.addQuotes(unit.getName()));
            param.setRepositoryValueUsed(true);
            param.setReadOnly(true);
        } else {
            param.setRepositoryValueUsed(false);
            param.setReadOnly(false);
        }
    } else if (param.getFieldType().equals(EParameterFieldType.TABLE)) {
        if (param.getRepositoryValue().equals("INPUT_PARAMS")) {
            //$NON-NLS-1$
            if (connection != null && sapFunctionLabel != null) {
                List<Map<String, Object>> table = (List<Map<String, Object>>) elem.getPropertyValue(param.getName());
                RepositoryToComponentProperty.getSAPInputAndOutputValue((SAPConnection) connection, table, sapFunctionLabel, true);
                param.setRepositoryValueUsed(true);
                param.setReadOnly(true);
            } else {
                param.setRepositoryValueUsed(false);
                param.setReadOnly(false);
            }
        }
        if ("SAP_PROPERTIES".equals(param.getRepositoryValue())) {
            //$NON-NLS-1$
            //$NON-NLS-1$
            Object value = RepositoryToComponentProperty.getValue(connection, "SAP_PROPERTIES", null);
            param.setValue(value);
            param.setRepositoryValueUsed(true);
            param.setReadOnly(true);
        }
    } else if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("OUTPUT_PARAMS")) {
        //$NON-NLS-1$
        if (connection != null && sapFunctionLabel != null) {
            List<Map<String, Object>> table = (List<Map<String, Object>>) elem.getPropertyValue(param.getName());
            RepositoryToComponentProperty.getSAPInputAndOutputValue((SAPConnection) connection, table, sapFunctionLabel, false);
            param.setRepositoryValueUsed(true);
            param.setReadOnly(true);
        } else {
            param.setRepositoryValueUsed(false);
            param.setReadOnly(false);
        }
    } else if (param.getRepositoryValue().equals("SAP_ITERATE_OUT_TYPE")) {
        //$NON-NLS-1$
        if (connection != null && sapFunctionLabel != null) {
            param.setValue(RepositoryToComponentProperty.getSAPValuesForFunction((SAPConnection) connection, sapFunctionLabel, //$NON-NLS-1$
            "SAP_ITERATE_OUT_TYPE"));
            param.setRepositoryValueUsed(true);
            param.setReadOnly(true);
        } else {
            param.setRepositoryValueUsed(false);
            param.setReadOnly(false);
        }
    } else if (param.getRepositoryValue().equals("SAP_ITERATE_OUT_TABLENAME")) {
        //$NON-NLS-1$
        if (connection != null && sapFunctionLabel != null) {
            param.setValue(RepositoryToComponentProperty.getSAPValuesForFunction((SAPConnection) connection, sapFunctionLabel, //$NON-NLS-1$
            "SAP_ITERATE_OUT_TABLENAME"));
            param.setRepositoryValueUsed(true);
            param.setReadOnly(true);
        } else {
            param.setRepositoryValueUsed(false);
            param.setReadOnly(false);
        }
    }
}
Also used : SAPConnection(org.talend.core.model.metadata.builder.connection.SAPConnection) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) List(java.util.List) Map(java.util.Map)

Example 4 with SAPFunctionUnit

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

the class UpdateNodeParameterCommand method updateSAPParameters.

/**
     * DOC YeXiaowei Comment method "updateSAPParameters".
     */
private void updateSAPParameters() {
    Object updateObject = result.getUpdateObject();
    if (updateObject == null) {
        return;
    }
    boolean builtin = true;
    if (updateObject instanceof Node) {
        Node node = (Node) updateObject;
        if (result.getResultType() == EUpdateResult.UPDATE) {
            if (result.isChecked()) {
                if (result.getParameter() instanceof SAPFunctionUnit) {
                    SAPFunctionUnit unit = (SAPFunctionUnit) result.getParameter();
                    for (IElementParameter param : node.getElementParameters()) {
                        SAPParametersUtils.retrieveSAPParams(node, unit.getConnection(), param, unit.getLabel());
                    }
                    builtin = false;
                }
            }
        }
        if (builtin) {
            // built-in
            node.setPropertyValue(EParameterName.SCHEMA_TYPE.getName(), EmfComponent.BUILTIN);
            for (IElementParameter param : node.getElementParameters()) {
                SAPParametersUtils.setNoRepositoryParams(param);
            }
        }
    }
}
Also used : SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) Node(org.talend.designer.core.ui.editor.nodes.Node) IExternalNode(org.talend.core.model.process.IExternalNode) INode(org.talend.core.model.process.INode) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 5 with SAPFunctionUnit

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

the class BusinessAssignmentComposite method createSelectionListener.

private void createSelectionListener() {
    tableViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            BusinessAssignment businessAssignment = getBusinessAssignment(event.getSelection());
            if (businessAssignment != null) {
                final IRepositoryView repositoryView = getRepositoryView();
                if (repositoryView != null) {
                    IProjectRepositoryNode rootRepositoryNode = repositoryView.getRoot();
                    TalendItem item = businessAssignment.getTalendItem();
                    //
                    if (item instanceof Routine && rootRepositoryNode instanceof ProjectRepositoryNode) {
                        RepositoryNodeUtilities.expandParentNode(getRepositoryView(), ((ProjectRepositoryNode) rootRepositoryNode).getRootRepositoryNode(ERepositoryObjectType.CODE));
                    }
                    selectChild(item, (IRepositoryNode) rootRepositoryNode);
                }
            }
        }

        private void selectChild(TalendItem item, IRepositoryNode rootRepositoryNode) {
            try {
                RepositoryNode curNode = null;
                JobSettingsView viewer = (JobSettingsView) PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().findView(JobSettingsView.ID);
                IRepositoryViewObject lastVersion = ProxyRepositoryFactory.getInstance().getLastVersion(item.getId());
                if (lastVersion != null) {
                    curNode = RepositoryNodeUtilities.getRepositoryNode(lastVersion);
                    select(viewer, curNode);
                } else if (item instanceof TableMetadata) {
                    MetadataTable table = MetadataToolHelper.getMetadataTableFromRepository(item.getId());
                    if (table != null) {
                        //$NON-NLS-1$
                        String id = item.getId().split(" - ")[0];
                        RepositoryNode node = RepositoryNodeUtilities.getMetadataTableFromConnection(item.getId());
                        IRepositoryView view = getRepositoryView();
                        if (view != null) {
                            RepositoryNodeUtilities.expandParentNode(view, node);
                            select(viewer, node);
                        }
                    }
                } else if (item instanceof Query) {
                    org.talend.core.model.metadata.builder.connection.Query query = MetadataToolHelper.getQueryFromRepository(item.getId());
                    if (query != null) {
                        //$NON-NLS-1$
                        String id = item.getId().split(" - ")[0];
                        IRepositoryView view = getRepositoryView();
                        RepositoryNode node = RepositoryNodeUtilities.getQueryFromConnection(item.getId());
                        RepositoryNodeUtilities.expandParentNode(view, node);
                        select(viewer, node);
                    }
                } else if (item instanceof SAPFunction) {
                    SAPFunctionUnit function = MetadataToolHelper.getSAPFunctionFromRepository(item.getId());
                    if (function != null) {
                        IRepositoryView view = getRepositoryView();
                        RepositoryNode node = RepositoryNodeUtilities.getSAPFunctionFromConnection(item.getId());
                        RepositoryNodeUtilities.expandParentNode(view, node);
                        select(viewer, node);
                    }
                } else {
                    for (IRepositoryNode node : rootRepositoryNode.getChildren()) {
                        RepositoryNode rNode = (RepositoryNode) node;
                        if (item instanceof SQLPattern && rNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.SQLPATTERNS) {
                            if (rNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
                                SQLPatternItem sqlItem = (SQLPatternItem) rNode.getObject().getProperty().getItem();
                                if (sqlItem.isSystem() && item.getLabel().equals(rNode.getObject().getLabel())) {
                                    select(viewer, rNode);
                                }
                            } else {
                                selectChild(item, rNode);
                            }
                        } else if (item instanceof Routine && rNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.ROUTINES) {
                            if (rNode.getType() == ENodeType.REPOSITORY_ELEMENT) {
                                RoutineItem sqlItem = (RoutineItem) rNode.getObject().getProperty().getItem();
                                if (sqlItem.isBuiltIn() && item.getLabel().equals(rNode.getObject().getLabel())) {
                                    select(viewer, rNode);
                                }
                            } else {
                                selectChild(item, rNode);
                            }
                        }
                    }
                }
            } catch (PersistenceException e) {
                // TODO Auto-generated catch block
                // e.printStackTrace();
                ExceptionHandler.process(e);
            }
        }

        private void select(JobSettingsView viewer, RepositoryNode repositoryNode) {
            if (viewer == null) {
                return;
            }
            if (repositoryNode == null) {
                return;
            }
            CorePlugin.getDefault().getRepositoryService().removeRepositoryTreeViewListener(viewer);
            final IRepositoryView repositoryView = getRepositoryView();
            if (repositoryView != null) {
                repositoryView.getViewer().setSelection(new StructuredSelection(repositoryNode));
            }
            CorePlugin.getDefault().getRepositoryService().addRepositoryTreeViewListener(viewer);
        }
    });
}
Also used : JobSettingsView(org.talend.designer.core.ui.views.jobsettings.JobSettingsView) BusinessAssignment(org.talend.designer.business.model.business.BusinessAssignment) Query(org.talend.designer.business.model.business.Query) SAPFunctionUnit(org.talend.core.model.metadata.builder.connection.SAPFunctionUnit) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) StructuredSelection(org.eclipse.jface.viewers.StructuredSelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) IRepositoryView(org.talend.repository.ui.views.IRepositoryView) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) TalendItem(org.talend.designer.business.model.business.TalendItem) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) TableMetadata(org.talend.designer.business.model.business.TableMetadata) SAPFunction(org.talend.designer.business.model.business.SAPFunction) SQLPattern(org.talend.designer.business.model.business.SQLPattern) IRepositoryNode(org.talend.repository.model.IRepositoryNode) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) RoutineItem(org.talend.core.model.properties.RoutineItem) Routine(org.talend.designer.business.model.business.Routine) ProjectRepositoryNode(org.talend.core.repository.model.ProjectRepositoryNode) RepositoryNode(org.talend.repository.model.RepositoryNode) IProjectRepositoryNode(org.talend.repository.model.nodes.IProjectRepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException)

Aggregations

SAPFunctionUnit (org.talend.core.model.metadata.builder.connection.SAPFunctionUnit)11 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)9 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)7 PersistenceException (org.talend.commons.exception.PersistenceException)6 List (java.util.List)5 Routine (org.talend.designer.business.model.business.Routine)5 SQLPattern (org.talend.designer.business.model.business.SQLPattern)5 TalendItem (org.talend.designer.business.model.business.TalendItem)5 IElementParameter (org.talend.core.model.process.IElementParameter)4 BusinessAssignment (org.talend.designer.business.model.business.BusinessAssignment)4 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)3 Query (org.talend.core.model.metadata.builder.connection.Query)3 Item (org.talend.core.model.properties.Item)3 ERepositoryObjectType (org.talend.core.model.repository.ERepositoryObjectType)3 ArrayList (java.util.ArrayList)2 Map (java.util.Map)2 Command (org.eclipse.gef.commands.Command)2 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)2 Image (org.eclipse.swt.graphics.Image)2 ECoreImage (org.talend.commons.ui.runtime.image.ECoreImage)2