Search in sources :

Example 6 with FileItem

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

the class PropertyTypeController method createComboCommand.

/*
     * (non-Javadoc)
     * 
     * @see
     * org.talend.designer.core.ui.editor.properties.controllers.AbstractRepositoryController#createComboCommand(org
     * .eclipse.swt.custom.CCombo)
     */
@Override
protected Command createComboCommand(CCombo combo) {
    Connection repositoryConnection = null;
    ConnectionItem repositoryConnectionItem = null;
    // hwang add
    FileItem repositoryFileItem = null;
    String paramName = (String) combo.getData(PARAMETER_NAME);
    IElementParameter param = elem.getElementParameter(paramName);
    String value = combo.getText();
    for (int j = 0; j < param.getListItemsValue().length; j++) {
        if (combo.getText().equals(param.getListItemsDisplayName()[j])) {
            value = (String) param.getListItemsValue()[j];
        }
    }
    if (value.equals(param.getValue())) {
        return null;
    }
    // Map<String, ConnectionItem> repositoryConnectionItemMap = null;
    IElementParameter repositoryParam = null;
    // hywang add for feature 6484
    Map<String, FileItem> repositoryFileItemMap = null;
    if (value.equals(EmfComponent.REPOSITORY)) {
        IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        if (dynamicProperty instanceof MultipleThreadDynamicComposite) {
            repositoryFileItemMap = ((MultipleThreadDynamicComposite) dynamicProperty).getRepositoryFileItemMap();
        }
        repositoryParam = param.getParentParameter().getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
        String connectionSelected = (String) repositoryParam.getValue();
        // if (repositoryConnectionItemMap.containsKey(connectionSelected)) {
        try {
            Item item = null;
            if (!StringUtils.isEmpty(connectionSelected)) {
                IRepositoryViewObject repobj = factory.getLastVersion(connectionSelected);
                if (repobj != null) {
                    Property property = repobj.getProperty();
                    if (property != null) {
                        item = property.getItem();
                    }
                }
                if (item != null && item instanceof ConnectionItem) {
                    repositoryConnectionItem = (ConnectionItem) factory.getLastVersion(connectionSelected).getProperty().getItem();
                    repositoryConnection = repositoryConnectionItem.getConnection();
                } else {
                    repositoryConnection = null;
                }
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
        }
        // for ruleItem,hywang add
        if (repositoryFileItemMap.containsKey(connectionSelected)) {
            repositoryFileItem = repositoryFileItemMap.get(connectionSelected);
        } else {
            if (!repositoryFileItemMap.isEmpty()) {
                repositoryFileItem = repositoryFileItemMap.values().iterator().next();
            } else {
                repositoryFileItem = null;
            }
        }
    }
    CompoundCommand cc = new CompoundCommand();
    if (repositoryConnectionItem != null) {
        initCDC(cc, repositoryConnectionItem);
    }
    ChangeValuesFromRepository changeValuesFromRepository1 = new ChangeValuesFromRepository(elem, repositoryConnection, paramName, value);
    cc.add(changeValuesFromRepository1);
    if (repositoryConnection != null) {
        ChangeValuesFromRepository changeValuesFromRepository2 = new ChangeValuesFromRepository(elem, repositoryConnection, repositoryParam.getParentParameter().getName() + ":" + repositoryParam.getName(), //$NON-NLS-1$
        repositoryConnectionItem.getProperty().getId());
        cc.add(changeValuesFromRepository2);
    }
    // hywang add for feature 6484
    if (repositoryFileItem != null) {
        final String id = repositoryFileItem.getProperty().getId();
        cc.add(new Command() {

            @Override
            public void execute() {
                IElementParameter elementParameter = elem.getElementParameter(EParameterName.PROPERTY_TYPE.getName());
                if (elementParameter != null) {
                    elementParameter = elementParameter.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                    if (elementParameter != null) {
                        elementParameter.setValue(id);
                    }
                }
            }
        });
    }
    if (value.equals(EmfComponent.REPOSITORY)) {
        updateDBType(cc, repositoryConnection);
    }
    return cc;
}
Also used : ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) Point(org.eclipse.swt.graphics.Point) MultipleThreadDynamicComposite(org.talend.designer.core.ui.views.properties.MultipleThreadDynamicComposite) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) FileItem(org.talend.core.model.properties.FileItem) Item(org.talend.core.model.properties.Item) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) CompoundCommand(org.eclipse.gef.commands.CompoundCommand) Command(org.eclipse.gef.commands.Command) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) IElementParameter(org.talend.core.model.process.IElementParameter) IDynamicProperty(org.talend.core.ui.properties.tab.IDynamicProperty) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 7 with FileItem

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

the class ComponentChooseDialog method createRefreshingPropertiesCommand.

/**
     * DOC bqian Comment method "createRefreshingPropertiesCommand".
     *
     * @param selectedNode
     * @param node
     */
private List<Command> createRefreshingPropertiesCommand(CompoundCommand cc, RepositoryNode selectedNode, Node node) {
    // List<Command> list = new ArrayList<Command>();
    if (selectedNode.getObject().getProperty().getItem() instanceof ConnectionItem) {
        String propertyId = selectedNode.getObject().getProperty().getId();
        ConnectionItem originalConnectionItem = (ConnectionItem) selectedNode.getObject().getProperty().getItem();
        ConnectionItem connectionItem = originalConnectionItem;
        Connection originalConnection = connectionItem.getConnection();
        Connection connection = connectionItem.getConnection();
        // if component is CDC, replace by the CDC connection.
        if (node.getComponent().getName().contains("CDC")) {
            // to replace by a flag CDC in component? //$NON-NLS-1$
            if (selectedNode.getObject().getProperty().getItem() instanceof DatabaseConnectionItem) {
                final DatabaseConnection databaseConnection = (DatabaseConnection) connection;
                CDCConnection cdcConn = databaseConnection.getCdcConns();
                if (cdcConn != null) {
                    EList cdcTypes = cdcConn.getCdcTypes();
                    if (cdcTypes != null && !cdcTypes.isEmpty()) {
                        CDCType cdcType = (CDCType) cdcTypes.get(0);
                        // replace property by CDC property.
                        propertyId = cdcType.getLinkDB();
                        try {
                            IRepositoryViewObject object = ProxyRepositoryFactory.getInstance().getLastVersion(propertyId);
                            if (object != null) {
                                if (object.getProperty().getItem() instanceof DatabaseConnectionItem) {
                                    DatabaseConnectionItem dbConnItem = (DatabaseConnectionItem) object.getProperty().getItem();
                                    // replace connection by CDC connection
                                    connectionItem = dbConnItem;
                                    connection = dbConnItem.getConnection();
                                }
                            }
                        } catch (PersistenceException e) {
                            ExceptionHandler.process(e);
                        }
                        // set cdc type mode.
                        IElementParameter logModeParam = node.getElementParameter(EParameterName.CDC_TYPE_MODE.getName());
                        if (logModeParam != null) {
                            String cdcTypeMode = ((DatabaseConnection) originalConnection).getCdcTypeMode();
                            Command logModeCmd = new PropertyChangeCommand(node, EParameterName.CDC_TYPE_MODE.getName(), CDCTypeMode.LOG_MODE.getName().equals(cdcTypeMode));
                            cc.add(logModeCmd);
                        }
                        // set lib for as400 so far.
                        //$NON-NLS-1$
                        final String name = "SOURCE_LIB";
                        IElementParameter libParam = node.getElementParameter(name);
                        if (libParam != null) {
                            Object propValue;
                            if (connection.isContextMode() && ContextParameterUtils.isContainContextParam(databaseConnection.getSID())) {
                                propValue = databaseConnection.getSID();
                            } else {
                                propValue = TalendTextUtils.addQuotes(databaseConnection.getSID());
                            }
                            Command libSettingCmd = new PropertyChangeCommand(node, name, propValue);
                            cc.add(libSettingCmd);
                        }
                    }
                }
            }
        }
        // fore EBCDIC, by cli
        if ((connectionItem instanceof EbcdicConnectionItem) && PluginChecker.isEBCDICPluginLoaded()) {
            // TDI-20505:integration the drag/drop for EBCDIC connection and EBCDIC metadataTable
            IRepositoryViewObject object = selectedNode.getObject();
            if (selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_EBCDIC) {
                for (MetadataTable table : ConnectionHelper.getTables(originalConnection)) {
                    Command ebcdicCmd = new RepositoryChangeMetadataForEBCDICCommand(node, IEbcdicConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
                    cc.add(ebcdicCmd);
                }
            }
            if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_TABLE) {
                MetadataTable table = null;
                if (object instanceof MetadataTableRepositoryObject) {
                    table = ((MetadataTableRepositoryObject) object).getTable();
                }
                Command ebcdicCmd = new RepositoryChangeMetadataForEBCDICCommand(node, IEbcdicConstant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
                cc.add(ebcdicCmd);
            }
        }
        // fore HL7, by gcui
        if ((selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_HL7 && PluginChecker.isHL7PluginLoaded()) || (selectedNode.getParent() != null && selectedNode.getParent().getObjectType() == ERepositoryObjectType.METADATA_FILE_HL7 && PluginChecker.isHL7PluginLoaded())) {
            if (originalConnection instanceof HL7ConnectionImpl) {
                if (((HL7ConnectionImpl) originalConnection).getRoot() != null) {
                    List<Map<String, String>> mapList = new ArrayList<Map<String, String>>();
                    for (Object obj : ((HL7ConnectionImpl) originalConnection).getRoot()) {
                        if (obj instanceof HL7FileNode) {
                            Map<String, String> newMap = new HashMap<String, String>();
                            newMap.put(IHL7Constant.ATTRIBUTE, ((HL7FileNode) obj).getAttribute());
                            newMap.put(IHL7Constant.PATH, ((HL7FileNode) obj).getFilePath());
                            newMap.put(IHL7Constant.COLUMN, ((HL7FileNode) obj).getRelatedColumn());
                            newMap.put(IHL7Constant.ORDER, String.valueOf(((HL7FileNode) obj).getOrder()));
                            newMap.put(IHL7Constant.VALUE, ((HL7FileNode) obj).getDefaultValue());
                            newMap.put(IHL7Constant.REPEATABLE, String.valueOf(((HL7FileNode) obj).isRepeatable()));
                            mapList.add(newMap);
                        }
                    }
                    IExternalNode externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
                    if (externalNode != null && externalNode.getElementParameter("ROOT") != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("ROOT").setValue(mapList);
                    }
                    String fileName = ((HL7ConnectionImpl) originalConnection).getOutputFilePath();
                    if (externalNode != null && externalNode.getElementParameter("FILENAME") != null && fileName != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("FILENAME").setValue(TalendTextUtils.addQuotes(fileName));
                    }
                }
            }
            // fore HL7, by gcui
            if (selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_HL7 && PluginChecker.isHL7PluginLoaded()) {
                for (MetadataTable table : ConnectionHelper.getTablesWithOrders(originalConnection)) {
                    Command hl7Cmd = new RepositoryChangeMetadataForHL7Command(node, IHL7Constant.TABLE_SCHEMAS, table.getLabel(), ConvertionHelper.convert(table));
                    cc.add(hl7Cmd);
                }
            }
        }
        // for brms
        if ((selectedNode.getObjectType() == ERepositoryObjectType.METADATA_FILE_BRMS && PluginChecker.isBRMSPluginLoaded()) || (selectedNode.getParent() != null && selectedNode.getParent().getObjectType() == ERepositoryObjectType.METADATA_FILE_BRMS && PluginChecker.isBRMSPluginLoaded())) {
            if (originalConnection instanceof BRMSConnectionImpl) {
                if (((BRMSConnectionImpl) originalConnection).getRoot() != null) {
                    List<Map<String, String>> rootList = new ArrayList<Map<String, String>>();
                    List<Map<String, String>> loopList = new ArrayList<Map<String, String>>();
                    List<Map<String, String>> groupList = new ArrayList<Map<String, String>>();
                    for (Object obj : ((BRMSConnectionImpl) originalConnection).getRoot()) {
                        if (obj instanceof XMLFileNode) {
                            Map<String, String> rootMap = new HashMap<String, String>();
                            //$NON-NLS-1$
                            rootMap.put("ATTRIBUTE", ((XMLFileNode) obj).getAttribute());
                            //$NON-NLS-1$
                            rootMap.put("PATH", ((XMLFileNode) obj).getXMLPath());
                            //$NON-NLS-1$
                            rootMap.put("COLUMN", ((XMLFileNode) obj).getRelatedColumn());
                            //$NON-NLS-1$
                            rootMap.put("ORDER", String.valueOf(((XMLFileNode) obj).getOrder()));
                            //$NON-NLS-1$
                            rootMap.put("VALUE", ((XMLFileNode) obj).getDefaultValue());
                            rootList.add(rootMap);
                        }
                    }
                    for (Object obj : ((BRMSConnectionImpl) originalConnection).getLoop()) {
                        if (obj instanceof XMLFileNode) {
                            Map<String, String> loopMap = new HashMap<String, String>();
                            //$NON-NLS-1$
                            loopMap.put("ATTRIBUTE", ((XMLFileNode) obj).getAttribute());
                            //$NON-NLS-1$
                            loopMap.put("PATH", ((XMLFileNode) obj).getXMLPath());
                            //$NON-NLS-1$
                            loopMap.put("COLUMN", ((XMLFileNode) obj).getRelatedColumn());
                            //$NON-NLS-1$
                            loopMap.put("ORDER", String.valueOf(((XMLFileNode) obj).getOrder()));
                            //$NON-NLS-1$
                            loopMap.put("VALUE", ((XMLFileNode) obj).getDefaultValue());
                            loopList.add(loopMap);
                        }
                    }
                    for (Object obj : ((BRMSConnectionImpl) originalConnection).getGroup()) {
                        if (obj instanceof XMLFileNode) {
                            Map<String, String> groupMap = new HashMap<String, String>();
                            //$NON-NLS-1$
                            groupMap.put("ATTRIBUTE", ((XMLFileNode) obj).getAttribute());
                            //$NON-NLS-1$
                            groupMap.put("PATH", ((XMLFileNode) obj).getXMLPath());
                            //$NON-NLS-1$
                            groupMap.put("COLUMN", ((XMLFileNode) obj).getRelatedColumn());
                            //$NON-NLS-1$
                            groupMap.put("ORDER", String.valueOf(((XMLFileNode) obj).getOrder()));
                            //$NON-NLS-1$
                            groupMap.put("VALUE", ((XMLFileNode) obj).getDefaultValue());
                            groupList.add(groupMap);
                        }
                    }
                    IExternalNode externalNode = ExternalUtilities.getExternalNodeReadyToOpen(node);
                    if (externalNode != null && externalNode.getElementParameter("ROOT") != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("ROOT").setValue(rootList);
                    }
                    if (externalNode != null && externalNode.getElementParameter("LOOP") != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("LOOP").setValue(loopList);
                    }
                    if (externalNode != null && externalNode.getElementParameter("GROUP") != null) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        externalNode.getElementParameter("GROUP").setValue(groupList);
                    }
                }
            }
        }
        IElementParameter propertyParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
        if (propertyParam != null) {
            propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
            propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName()).setValue(propertyId);
        }
        IProxyRepositoryFactory factory = DesignerPlugin.getDefault().getProxyRepositoryFactory();
        Map<String, IMetadataTable> repositoryTableMap = new HashMap<String, IMetadataTable>();
        if (!originalConnection.isReadOnly()) {
            for (Object tableObj : ConnectionHelper.getTables(originalConnection)) {
                org.talend.core.model.metadata.builder.connection.MetadataTable table;
                table = (org.talend.core.model.metadata.builder.connection.MetadataTable) tableObj;
                if (factory.getStatus(originalConnectionItem) != ERepositoryStatus.DELETED) {
                    if (!factory.isDeleted(table)) {
                        String value = table.getId();
                        IMetadataTable newTable = ConvertionHelper.convert(table);
                        repositoryTableMap.put(value, newTable);
                    }
                }
            }
        }
        // DesignerPlugin.getDefault().getProxyRepositoryFactory().getLastVersion("")
        if (propertyParam != null) {
            // command used to set property type
            IMetadataTable metadataTable = null;
            // && selectedNode.getObjectType() == ERepositoryObjectType.METADATA_CON_TABLE) {
            if (selectedNode.getObject() instanceof IMetadataTable) {
                metadataTable = (IMetadataTable) selectedNode.getObject();
                if (metadataTable != null && repositoryTableMap.get(metadataTable.getId()) != null) {
                    metadataTable = repositoryTableMap.get(metadataTable.getId());
                }
            }
            // }
            ChangeValuesFromRepository command1 = new ChangeValuesFromRepository(node, connection, metadataTable, propertyParam.getName() + ":" + EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), propertyId, //$NON-NLS-1$
            true);
            command1.setMaps(repositoryTableMap);
            if (selectedNode.getProperties(EProperties.CONTENT_TYPE) != ERepositoryObjectType.METADATA_CON_QUERY) {
                command1.setGuessQuery(true);
            }
            setSAPSpecailValueForCommand(selectedNode, command1);
            // for salesForce module
            SalesforceModuleRepositoryObject sfObject = null;
            if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_SALESFORCE_MODULE) {
                sfObject = (SalesforceModuleRepositoryObject) selectedNode.getObject();
            } else if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_TABLE) {
                IRepositoryViewObject object = selectedNode.getParent().getObject();
                if (object instanceof SalesforceModuleRepositoryObject) {
                    sfObject = (SalesforceModuleRepositoryObject) object;
                }
            }
            if (sfObject != null) {
                ModelElement modelElement = sfObject.getModelElement();
                if (modelElement instanceof SalesforceModuleUnit) {
                    command1.setSalesForceModuleUnit((SalesforceModuleUnit) modelElement);
                }
            }
            cc.add(command1);
        }
        // command used to set metadata
        getChangeMetadataCommand(cc, selectedNode, node, originalConnectionItem);
        // command used to set query
        if (selectedNode.getProperties(EProperties.CONTENT_TYPE) == ERepositoryObjectType.METADATA_CON_QUERY) {
            IElementParameter queryParam = node.getElementParameterFromField(EParameterFieldType.QUERYSTORE_TYPE);
            QueryRepositoryObject object = (QueryRepositoryObject) selectedNode.getObject();
            Query query = object.getQuery();
            //$NON-NLS-1$
            String value = originalConnectionItem.getProperty().getId() + " - " + query.getLabel();
            if (queryParam != null) {
                RepositoryChangeQueryCommand command3 = new RepositoryChangeQueryCommand(node, query, queryParam.getName() + ":" + EParameterName.REPOSITORY_QUERYSTORE_TYPE.getName(), //$NON-NLS-1$
                value);
                cc.add(command3);
            }
        } else {
            if (connection instanceof DatabaseConnection && hasQuery(node)) {
                DatabaseConnection connection2 = (DatabaseConnection) connection;
                String schema = connection2.getUiSchema();
                String dbType = connection2.getDatabaseType();
                QueryGuessCommand queryGuessCommand = null;
                if (node.getMetadataList().size() == 0) {
                    queryGuessCommand = new QueryGuessCommand(node, null, schema, dbType);
                } else {
                    // modified by hyWang for bug 7190
                    queryGuessCommand = new QueryGuessCommand(node, node.getMetadataList().get(0), schema, dbType, connection);
                }
                if (queryGuessCommand != null) {
                    cc.add(queryGuessCommand);
                }
            }
        }
    // context, moved to ChangeValuesFromRepository(bug 5198)
    // ConnectionContextHelper.addContextForNodeParameter(node, connectionItem);
    } else if (selectedNode.getObject().getProperty().getItem() instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) selectedNode.getObject().getProperty().getItem();
        // command used to set job
        String value = processItem.getProperty().getId();
        PropertyChangeCommand command4 = new PropertyChangeCommand(node, EParameterName.PROCESS_TYPE_PROCESS.getName(), value);
        cc.add(command4);
        PropertyChangeCommand command5 = new PropertyChangeCommand(node, EParameterName.PROCESS_TYPE_CONTEXT.getName(), processItem.getProcess().getDefaultContext());
        cc.add(command5);
    } else if (selectedNode.getObject().getProperty().getItem() instanceof FileItem) {
        // hywang add for 6484
        if (selectedNode.getObject().getProperty().getItem() instanceof RulesItem) {
            RulesItem rulesItem = (RulesItem) selectedNode.getObject().getProperty().getItem();
            //                String displayName = "Rules:" + rulesItem.getProperty().getLabel(); //$NON-NLS-N$
            IElementParameter propertyParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
            if (propertyParam != null) {
                propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
                // propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())
                // .setListItemsDisplayName(new String[] { displayName });
                final String showId = rulesItem.getProperty().getId();
                PropertyChangeCommand command6 = new PropertyChangeCommand(node, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
                cc.add(command6);
            }
        }
    } else if (selectedNode.getObject().getProperty().getItem() instanceof LinkRulesItem) {
        LinkRulesItem linkItem = (LinkRulesItem) selectedNode.getObject().getProperty().getItem();
        IElementParameter propertyParam = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
        if (propertyParam != null) {
            propertyParam.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).setValue(EmfComponent.REPOSITORY);
            // propertyParam.getChildParameters().get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName())
            // .setListItemsDisplayName(new String[] { displayName });
            final String showId = linkItem.getProperty().getId();
            PropertyChangeCommand command7 = new PropertyChangeCommand(node, EParameterName.REPOSITORY_PROPERTY_TYPE.getName(), showId);
            cc.add(command7);
        }
    }
    return null;
}
Also used : Query(org.talend.core.model.metadata.builder.connection.Query) HashMap(java.util.HashMap) ChangeValuesFromRepository(org.talend.designer.core.ui.editor.cmd.ChangeValuesFromRepository) ArrayList(java.util.ArrayList) QueryGuessCommand(org.talend.designer.core.ui.editor.cmd.QueryGuessCommand) RepositoryChangeQueryCommand(org.talend.designer.core.ui.editor.cmd.RepositoryChangeQueryCommand) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) HL7ConnectionImpl(org.talend.core.model.metadata.builder.connection.impl.HL7ConnectionImpl) SalesforceModuleUnit(org.talend.core.model.metadata.builder.connection.SalesforceModuleUnit) HL7FileNode(org.talend.core.model.metadata.builder.connection.HL7FileNode) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) XMLFileNode(org.talend.core.model.metadata.builder.connection.XMLFileNode) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) FileItem(org.talend.core.model.properties.FileItem) PropertyChangeCommand(org.talend.designer.core.ui.editor.cmd.PropertyChangeCommand) BRMSConnectionImpl(org.talend.core.model.metadata.builder.connection.impl.BRMSConnectionImpl) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) PersistenceException(org.talend.commons.exception.PersistenceException) SAPFunctionRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPFunctionRepositoryObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) MetadataTableRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataTableRepositoryObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) MetadataColumnRepositoryObject(org.talend.core.repository.model.repositoryObject.MetadataColumnRepositoryObject) SAPIDocRepositoryObject(org.talend.core.repository.model.repositoryObject.SAPIDocRepositoryObject) Map(java.util.Map) HashMap(java.util.HashMap) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) ValidationRulesConnectionItem(org.talend.core.model.properties.ValidationRulesConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) MDMConnectionItem(org.talend.core.model.properties.MDMConnectionItem) SAPConnectionItem(org.talend.core.model.properties.SAPConnectionItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) HL7ConnectionItem(org.talend.core.model.properties.HL7ConnectionItem) LinkRulesItem(org.talend.core.model.properties.LinkRulesItem) RulesItem(org.talend.core.model.properties.RulesItem) ModelElement(orgomg.cwm.objectmodel.core.ModelElement) RepositoryChangeMetadataForHL7Command(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForHL7Command) IElementParameter(org.talend.core.model.process.IElementParameter) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) IExternalNode(org.talend.core.model.process.IExternalNode) PolylineConnection(org.eclipse.draw2d.PolylineConnection) MDMConnection(org.talend.core.model.metadata.builder.connection.MDMConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) EbcdicConnectionItem(org.talend.core.model.properties.EbcdicConnectionItem) CDCConnection(org.talend.core.model.metadata.builder.connection.CDCConnection) RepositoryChangeMetadataForEBCDICCommand(org.talend.core.ui.metadata.command.RepositoryChangeMetadataForEBCDICCommand) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) QueryRepositoryObject(org.talend.core.repository.model.repositoryObject.QueryRepositoryObject) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) 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) CDCType(org.talend.core.model.metadata.builder.connection.CDCType)

Example 8 with FileItem

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

the class ImportItemUtil method resolveItem.

public void resolveItem(ResourcesManager manager, ItemRecord itemRecord) {
    if (itemRecord.isResolved()) {
        return;
    }
    InputStream stream = null;
    try {
        final Item item = itemRecord.getItem();
        boolean byteArray = (item instanceof FileItem);
        IPath itemPath = getItemPath(itemRecord.getPath(), item);
        Set<IPath> paths = manager.getPaths();
        // check the item file
        if (!paths.contains(itemPath)) {
            itemRecord.addError(itemRecord.getItemName() + " " + Messages.getString("ImportItemUtil.MissingItemFile") + " - " + itemPath);
            log.error(itemRecord.getItemName() + " " + Messages.getString("ImportItemUtil.MissingItemFile") + " - " + //$NON-NLS-1$
            itemPath);
            return;
        }
        stream = manager.getStream(itemPath);
        Resource resource = createResource(itemRecord, itemPath, byteArray);
        if (byteArray) {
            // TDI-24612
            // This part fixes a problem of import of routines from .tar.gz.
            // Seems either the Tar stream or emf got problems to read this.
            ByteArrayOutputStream baos = new ByteArrayOutputStream();
            byte[] buf = new byte[1024];
            int i = 0;
            while ((i = stream.read(buf)) != -1) {
                baos.write(buf, 0, i);
            }
            ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
            resource.load(bais, null);
        } else {
            resource.load(stream, null);
        }
        for (ReferenceFileItem rfItem : (List<ReferenceFileItem>) item.getReferenceResources()) {
            itemPath = getReferenceItemPath(itemRecord.getPath(), rfItem.getExtension());
            stream = manager.getStream(itemPath);
            Resource rfResource = createResource(itemRecord, itemPath, true);
            rfResource.load(stream, null);
        }
        Iterator<EObject> itRef = item.eCrossReferences().iterator();
        IPath parentPath = itemRecord.getPath().removeLastSegments(1);
        while (itRef.hasNext()) {
            EObject object = itRef.next();
            String linkedFile = EcoreUtil.getURI(object).toFileString();
            IPath linkedPath = parentPath.append(linkedFile);
            if (!paths.contains(linkedPath)) {
                if (linkedFile != null && !linkedFile.equals(itemPath.lastSegment()) && linkedFile.endsWith(itemPath.getFileExtension())) {
                    if (object.eIsProxy()) {
                        // if original href of the item point to some missing item file
                        // and if we can get the original item file from the name, recover it, but add a warning
                        ((EObjectImpl) object).eSetProxyURI(URI.createFileURI(itemPath.lastSegment()));
                        log.warn(itemRecord.getItemName() + " " + Messages.getString("ImportItemUtil.NotHrefCurrentItemFile") + " - " + //$NON-NLS-1$
                        itemRecord.getPath());
                    }
                }
            }
            EcoreUtil.resolve(object, resource);
        }
    } catch (IOException e) {
    // ignore
    } finally {
        if (stream != null) {
            try {
                stream.close();
            } catch (IOException e) {
            // ignore
            }
        }
    }
    itemRecord.setResolved(true);
}
Also used : ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) EObjectImpl(org.eclipse.emf.ecore.impl.EObjectImpl) IPath(org.eclipse.core.runtime.IPath) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CwmResource(org.talend.model.emf.CwmResource) TalendXMIResource(org.talend.commons.runtime.model.emf.TalendXMIResource) ByteArrayResource(org.talend.core.model.properties.helper.ByteArrayResource) Resource(org.eclipse.emf.ecore.resource.Resource) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) ContextItem(org.talend.core.model.properties.ContextItem) SnippetItem(org.talend.core.model.properties.SnippetItem) Item(org.talend.core.model.properties.Item) LinkDocumentationItem(org.talend.core.model.properties.LinkDocumentationItem) FolderItem(org.talend.core.model.properties.FolderItem) RoutineItem(org.talend.core.model.properties.RoutineItem) TDQItem(org.talend.core.model.properties.TDQItem) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) FileItem(org.talend.core.model.properties.FileItem) ReferenceFileItem(org.talend.core.model.properties.ReferenceFileItem) FileItem(org.talend.core.model.properties.FileItem) ByteArrayInputStream(java.io.ByteArrayInputStream) InternalEObject(org.eclipse.emf.ecore.InternalEObject) EObject(org.eclipse.emf.ecore.EObject) ArrayList(java.util.ArrayList) List(java.util.List) EList(org.eclipse.emf.common.util.EList)

Aggregations

FileItem (org.talend.core.model.properties.FileItem)8 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 PersistenceException (org.talend.commons.exception.PersistenceException)6 Item (org.talend.core.model.properties.Item)6 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)6 LinkRulesItem (org.talend.core.model.properties.LinkRulesItem)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 Connection (org.talend.core.model.metadata.builder.connection.Connection)4 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)4 IElementParameter (org.talend.core.model.process.IElementParameter)4 DatabaseConnectionItem (org.talend.core.model.properties.DatabaseConnectionItem)4 EList (org.eclipse.emf.common.util.EList)3 Command (org.eclipse.gef.commands.Command)3 CompoundCommand (org.eclipse.gef.commands.CompoundCommand)3 CDCConnection (org.talend.core.model.metadata.builder.connection.CDCConnection)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 ArrayList (java.util.ArrayList)2 EObject (org.eclipse.emf.ecore.EObject)2 InternalEObject (org.eclipse.emf.ecore.InternalEObject)2 IESBService (org.talend.core.IESBService)2