Search in sources :

Example 1 with HeaderFooterConnection

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

the class UpdateMainParameterCommand method execute.

@Override
public void execute() {
    if (result == null) {
        return;
    }
    Object job = result.getJob();
    if (job == null) {
        return;
    }
    if (job instanceof IProcess2) {
        Process process = (Process) job;
        EComponentCategory category = null;
        IUpdateItemType updateType = result.getUpdateType();
        if (updateType instanceof EUpdateItemType) {
            switch((EUpdateItemType) updateType) {
                case JOB_PROPERTY_EXTRA:
                    category = EComponentCategory.EXTRA;
                    break;
                case JOB_PROPERTY_STATS_LOGS:
                    category = EComponentCategory.STATSANDLOGS;
                    break;
                case JOB_PROPERTY_HEADERFOOTER:
                    category = EComponentCategory.HEADERFOOTER;
                    break;
                case JOB_PROPERTY_STORM:
                    if (ComponentCategory.CATEGORY_4_SPARKSTREAMING.getName().equals(process.getComponentsType())) {
                        category = EComponentCategory.SPARK_JOB_CONFIG;
                    }
                    break;
                case JOB_PROPERTY_MAPREDUCE:
                    if (ComponentCategory.CATEGORY_4_MAPREDUCE.getName().equals(process.getComponentsType())) {
                        category = EComponentCategory.MAPREDUCE_JOB_CONFIG_FOR_HADOOP;
                    } else if (ComponentCategory.CATEGORY_4_SPARK.getName().equals(process.getComponentsType())) {
                        category = EComponentCategory.SPARK_JOB_CONFIG;
                    }
                    break;
                default:
            }
            if (category == EComponentCategory.HEADERFOOTER) {
                if (result.getResultType() == EUpdateResult.UPDATE) {
                    if (result.isChecked()) {
                        for (IElementParameter param : process.getElementParameters()) {
                            if (param.getCategory() == EComponentCategory.HEADERFOOTER) {
                                IElementParameter headerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_HEADERID.getName());
                                if (headerIDParameter != null) {
                                    IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) headerIDParameter.getValue());
                                    HeaderFooterConnection repositoryConnection = null;
                                    if (lastVersion != null) {
                                        final Item item = lastVersion.getProperty().getItem();
                                        if (item != null && item instanceof ConnectionItem) {
                                            repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
                                            if (repositoryConnection != null) {
                                                Boolean isHeader = repositoryConnection.isIsHeader();
                                                String libraries = repositoryConnection.getLibraries();
                                                String mainCode = repositoryConnection.getMainCode();
                                                String imports = repositoryConnection.getImports();
                                                process.getElementParameter(EParameterName.HEADER_ENABLED.getName()).setValue(isHeader);
                                                process.getElementParameter(EParameterName.HEADER_LIBRARY.getName()).setValue(libraries);
                                                process.getElementParameter(EParameterName.HEADER_CODE.getName()).setValue(mainCode);
                                                process.getElementParameter(EParameterName.HEADER_IMPORT.getName()).setValue(imports);
                                            }
                                        }
                                    }
                                }
                                IElementParameter footerIDParameter = process.getElementParameter(EParameterName.HEADERFOOTER_FOOTERID.getName());
                                if (footerIDParameter != null) {
                                    IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById((String) footerIDParameter.getValue());
                                    HeaderFooterConnection repositoryConnection = null;
                                    if (lastVersion != null) {
                                        final Item item = lastVersion.getProperty().getItem();
                                        if (item != null && item instanceof ConnectionItem) {
                                            repositoryConnection = (HeaderFooterConnection) ((HeaderFooterConnectionItem) item).getConnection();
                                            if (repositoryConnection != null) {
                                                Boolean isHeader = repositoryConnection.isIsHeader();
                                                String libraries = repositoryConnection.getLibraries();
                                                String mainCode = repositoryConnection.getMainCode();
                                                String imports = repositoryConnection.getImports();
                                                process.getElementParameter(EParameterName.FOOTER_ENABLED.getName()).setValue(!isHeader);
                                                process.getElementParameter(EParameterName.FOOTER_LIBRARY.getName()).setValue(libraries);
                                                process.getElementParameter(EParameterName.FOOTER_CODE.getName()).setValue(mainCode);
                                                process.getElementParameter(EParameterName.FOOTER_IMPORT.getName()).setValue(imports);
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (category != null) {
                boolean repository = false;
                if (result.getResultType() == EUpdateResult.UPDATE) {
                    // upgrade from repository
                    if (result.isChecked()) {
                        IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
                        if (property != null) {
                            Map<String, IElementParameter> childParameters = property.getChildParameters();
                            if (childParameters != null) {
                                IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
                                // is repository
                                if (elementParameter != null && EmfComponent.REPOSITORY.equals(elementParameter.getValue())) {
                                    for (IElementParameter param : process.getElementParameters()) {
                                        if (param.getCategory() != category) {
                                            continue;
                                        }
                                        String repositoryValue = param.getRepositoryValue();
                                        if (param.isShow(process.getElementParameters()) && (repositoryValue != null) && (!param.getName().equals(EParameterName.PROPERTY_TYPE.getName()))) {
                                            Object objectValue = RepositoryToComponentProperty.getValue((org.talend.core.model.metadata.builder.connection.Connection) result.getParameter(), repositoryValue, null);
                                            if (objectValue != null) {
                                                if (param.getFieldType().equals(EParameterFieldType.CLOSED_LIST) && repositoryValue.equals(UpdatesConstants.TYPE)) {
                                                    boolean found = false;
                                                    String[] items = param.getListRepositoryItems();
                                                    for (int i = 0; (i < items.length) && (!found); i++) {
                                                        if (objectValue.equals(items[i])) {
                                                            found = true;
                                                            process.setPropertyValue(param.getName(), param.getListItemsValue()[i]);
                                                        }
                                                    }
                                                } else if (EParameterName.HADOOP_ADVANCED_PROPERTIES.getName().equals(param.getName()) || EParameterName.SPARK_ADVANCED_PROPERTIES.getName().equals(param.getName())) {
                                                    List<Map> list = (ArrayList) param.getValue();
                                                    for (Map map : list) {
                                                        if (map.get("BUILDIN") != null && map.get("BUILDIN").equals("TRUE")) {
                                                            if (objectValue instanceof List) {
                                                                ((List) objectValue).add(map);
                                                            }
                                                        }
                                                    }
                                                    process.setPropertyValue(param.getName(), objectValue);
                                                } else {
                                                    process.setPropertyValue(param.getName(), objectValue);
                                                }
                                                param.setRepositoryValueUsed(true);
                                                param.setReadOnly(true);
                                                repository = true;
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                IElementParameter property = process.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE, category);
                Map<String, IElementParameter> childParameters = null;
                if (property != null) {
                    childParameters = property.getChildParameters();
                }
                if (!repository) {
                    if (childParameters != null) {
                        IElementParameter elementParameter = childParameters.get(EParameterName.PROPERTY_TYPE.getName());
                        elementParameter.setValue(EmfComponent.BUILTIN);
                    }
                    // built-in
                    IElementParameter dbTypeParam = null;
                    IElementParameter impliciteDbType = null;
                    for (IElementParameter param : process.getElementParameters()) {
                        if (param.getCategory() != category) {
                            continue;
                        }
                        String repositoryValue = param.getRepositoryValue();
                        if (param.isShow(process.getElementParameters()) && (repositoryValue != null)) {
                            // for mysql db verion
                            if (EParameterName.DB_TYPE.getName().equals(param.getName()) && "TYPE".equals(repositoryValue)) {
                                dbTypeParam = param;
                            }
                            if ("DB_TYPE_IMPLICIT_CONTEXT".equals(param.getName()) && "TYPE".equals(repositoryValue)) {
                                impliciteDbType = param;
                            }
                            if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && dbTypeParam != null && dbTypeParam.getValue() != null) {
                                final int indexOfItem = dbTypeParam.getIndexOfItemFromList(dbTypeParam.getValue().toString());
                                String dbType = dbTypeParam.getListItemsDisplayCodeName()[indexOfItem];
                                setDBVersionForMysql(param, dbType);
                            } else if (EParameterName.DB_VERSION.getName().equals(repositoryValue) && impliciteDbType != null && impliciteDbType.getValue() != null) {
                                final int indexOfItem = impliciteDbType.getIndexOfItemFromList(impliciteDbType.getValue().toString());
                                String dbType = impliciteDbType.getListItemsDisplayCodeName()[indexOfItem];
                                setDBVersionForMysql(param, dbType);
                            }
                            param.setRepositoryValueUsed(false);
                            param.setReadOnly(false);
                        }
                    }
                } else {
                    if (childParameters != null) {
                        IElementParameter elementParameter = childParameters.get(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
                        ConnectionItem connItem = UpdateRepositoryUtils.getConnectionItemByItemId((String) elementParameter.getValue());
                        ConnectionContextHelper.addContextForProcessParameter(process, connItem, category, false);
                    }
                }
            }
        }
    // else { // for extension
    }
}
Also used : HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) ArrayList(java.util.ArrayList) Process(org.talend.designer.core.ui.editor.process.Process) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) Item(org.talend.core.model.properties.Item) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) ArrayList(java.util.ArrayList) List(java.util.List) Map(java.util.Map) EComponentCategory(org.talend.core.model.process.EComponentCategory)

Example 2 with HeaderFooterConnection

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

the class RepositoryTypeProcessor method selectRepositoryNode.

@Override
protected boolean selectRepositoryNode(Viewer viewer, RepositoryNode parentNode, RepositoryNode node) {
    final String repositoryType = getRepositoryType();
    if (node == null) {
        return false;
    }
    if (node.getContentType() == ERepositoryObjectType.REFERENCED_PROJECTS) {
        return true;
    }
    // for sub folders
    if (node.getType() == ENodeType.STABLE_SYSTEM_FOLDER) {
        return false;
    }
    // for Db Connections
    if (node.getType() == ENodeType.SYSTEM_FOLDER) {
        return true;
    }
    // }
    IRepositoryViewObject object = node.getObject();
    if (object == null || object.getProperty().getItem() == null) {
        return false;
    }
    if (object instanceof MetadataTable) {
        return false;
    }
    Item item = object.getProperty().getItem();
    if (item instanceof FolderItem) {
        return true;
    }
    if (item instanceof ConnectionItem) {
        ConnectionItem connectionItem = (ConnectionItem) item;
        Connection connection = connectionItem.getConnection();
        // tAdvancedFileOutputXML
        if (repositoryType != null && repositoryType.equals(ERepositoryCategoryType.XMLOUTPUT.getName())) {
            if (connection instanceof XmlFileConnection && ((XmlFileConnection) connection).isInputModel()) {
                return false;
            }
        }
        if (repositoryType.startsWith(ERepositoryCategoryType.DATABASE.getName())) {
            //$NON-NLS-1$
            String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
            if (repositoryType.contains(":")) {
                // database //$NON-NLS-1$
                // is
                // specified
                // //$NON-NLS-1$
                //$NON-NLS-1$
                String neededDbType = repositoryType.substring(repositoryType.indexOf(":") + 1);
                if (hidenTypeSelection) {
                    return true;
                }
                if (!MetadataTalendType.sameDBProductType(neededDbType, currentDbType)) {
                    return false;
                }
            }
        }
    }
    if (repositoryType.startsWith(ERepositoryCategoryType.HEADERFOOTER.getName())) {
        if (item instanceof HeaderFooterConnectionItem) {
            HeaderFooterConnectionItem connectionItem = (HeaderFooterConnectionItem) item;
            HeaderFooterConnection connection = (HeaderFooterConnection) connectionItem.getConnection();
            boolean isHeader = connection.isIsHeader();
            if ((isHeader && isHeaderButton) || (!isHeader && !isHeaderButton)) {
                return true;
            } else {
                return false;
            }
        }
    }
    return true;
}
Also used : Item(org.talend.core.model.properties.Item) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) FolderItem(org.talend.core.model.properties.FolderItem) HeaderFooterConnectionItem(org.talend.core.model.properties.HeaderFooterConnectionItem) ConnectionItem(org.talend.core.model.properties.ConnectionItem) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) MetadataTable(org.talend.core.model.metadata.MetadataTable) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection)

Example 3 with HeaderFooterConnection

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

the class DynamicTabbedPropertySection method updateRepositoryListExtra.

private void updateRepositoryListExtra(IElementParameter param, String[] repositoryConnectionNameList, String[] repositoryConnectionValueList, boolean extra) {
    String paramName = EParameterName.PROPERTY_TYPE.getName();
    // if (extra) {
    // paramName = extraPropertyTypeName;
    // }
    String repositoryValue = elem.getElementParameter(paramName).getRepositoryValue();
    if (repositoryValue != null) {
        List<String> connectionNamesList = new ArrayList<String>();
        List<String> connectionValuesList = new ArrayList<String>();
        for (String key : repositoryConnectionItemMap.keySet()) {
            ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
            Connection connection = connectionItem.getConnection();
            String name = //$NON-NLS-1$
            getRepositoryAliasName(connectionItem) + ":" + connectionItem.getProperty().getLabel();
            if ((connection instanceof DelimitedFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.DELIMITED.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof PositionalFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.POSITIONAL.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof RegexpFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.REGEX.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof XmlFileConnection) && (repositoryValue.equals(ERepositoryCategoryType.XML.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof FileExcelConnection) && (repositoryValue.equals(ERepositoryCategoryType.EXCEL.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof GenericSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.GENERIC.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof LDAPSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.LDAP.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof SalesforceSchemaConnection) && (repositoryValue.equals(ERepositoryCategoryType.SALESFORCE.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
            if ((connection instanceof DatabaseConnection) && (repositoryValue.startsWith(ERepositoryCategoryType.DATABASE.getName()))) {
                //$NON-NLS-1$
                String currentDbType = (String) RepositoryToComponentProperty.getValue(connection, "TYPE", null);
                if (repositoryValue.contains(":")) {
                    // database //$NON-NLS-1$
                    // is
                    // specified
                    // //$NON-NLS-1$
                    //$NON-NLS-1$
                    String neededDbType = repositoryValue.substring(repositoryValue.indexOf(":") + 1);
                    if (neededDbType.equals(currentDbType)) {
                        addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
                    }
                } else {
                    addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
                }
            }
            if ((connection instanceof HeaderFooterConnection) && (repositoryValue.equals(ERepositoryCategoryType.HEADERFOOTER.getName()))) {
                addOrderDisplayNames(connectionValuesList, connectionNamesList, key, name);
            }
        }
        repositoryConnectionNameList = connectionNamesList.toArray(new String[0]);
        repositoryConnectionValueList = connectionValuesList.toArray(new String[0]);
    } else {
        List<String> connectionValuesList = new ArrayList<String>();
        List<String> connectionStringList = new ArrayList<String>();
        for (String key : repositoryConnectionItemMap.keySet()) {
            ConnectionItem connectionItem = repositoryConnectionItemMap.get(key);
            String name = connectionItem.getProperty().getLabel();
            addOrderDisplayNames(connectionValuesList, connectionStringList, key, name);
        }
        repositoryConnectionNameList = connectionStringList.toArray(new String[0]);
        repositoryConnectionValueList = connectionValuesList.toArray(new String[0]);
    }
    param.setListItemsDisplayName(repositoryConnectionNameList);
    param.setListItemsValue(repositoryConnectionValueList);
    if (!repositoryConnectionItemMap.keySet().contains(param.getValue())) {
        if (repositoryConnectionNameList.length > 0) {
            // paramName = EParameterName.REPOSITORY_PROPERTY_TYPE.getName();
            // if (extra) {
            // paramName = extraRepositoryPropertyTypeName;
            // }
            elem.setPropertyValue(paramName, repositoryConnectionValueList[0]);
        }
    }
}
Also used : ConnectionItem(org.talend.core.model.properties.ConnectionItem) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) ArrayList(java.util.ArrayList) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) GenericSchemaConnection(org.talend.core.model.metadata.builder.connection.GenericSchemaConnection) PositionalFileConnection(org.talend.core.model.metadata.builder.connection.PositionalFileConnection) RegexpFileConnection(org.talend.core.model.metadata.builder.connection.RegexpFileConnection) IConnection(org.talend.core.model.process.IConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) Connection(org.talend.core.model.metadata.builder.connection.Connection) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) QueriesConnection(org.talend.core.model.metadata.builder.connection.QueriesConnection) LDAPSchemaConnection(org.talend.core.model.metadata.builder.connection.LDAPSchemaConnection) FileExcelConnection(org.talend.core.model.metadata.builder.connection.FileExcelConnection) FileExcelConnection(org.talend.core.model.metadata.builder.connection.FileExcelConnection) DelimitedFileConnection(org.talend.core.model.metadata.builder.connection.DelimitedFileConnection) RegexpFileConnection(org.talend.core.model.metadata.builder.connection.RegexpFileConnection) PositionalFileConnection(org.talend.core.model.metadata.builder.connection.PositionalFileConnection) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) GenericSchemaConnection(org.talend.core.model.metadata.builder.connection.GenericSchemaConnection) LDAPSchemaConnection(org.talend.core.model.metadata.builder.connection.LDAPSchemaConnection) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) HeaderFooterConnection(org.talend.core.model.metadata.builder.connection.HeaderFooterConnection)

Aggregations

HeaderFooterConnection (org.talend.core.model.metadata.builder.connection.HeaderFooterConnection)3 ConnectionItem (org.talend.core.model.properties.ConnectionItem)3 ArrayList (java.util.ArrayList)2 Connection (org.talend.core.model.metadata.builder.connection.Connection)2 XmlFileConnection (org.talend.core.model.metadata.builder.connection.XmlFileConnection)2 HeaderFooterConnectionItem (org.talend.core.model.properties.HeaderFooterConnectionItem)2 Item (org.talend.core.model.properties.Item)2 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)2 List (java.util.List)1 Map (java.util.Map)1 MetadataTable (org.talend.core.model.metadata.MetadataTable)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 DelimitedFileConnection (org.talend.core.model.metadata.builder.connection.DelimitedFileConnection)1 FileExcelConnection (org.talend.core.model.metadata.builder.connection.FileExcelConnection)1 GenericSchemaConnection (org.talend.core.model.metadata.builder.connection.GenericSchemaConnection)1 LDAPSchemaConnection (org.talend.core.model.metadata.builder.connection.LDAPSchemaConnection)1 PositionalFileConnection (org.talend.core.model.metadata.builder.connection.PositionalFileConnection)1 QueriesConnection (org.talend.core.model.metadata.builder.connection.QueriesConnection)1 RegexpFileConnection (org.talend.core.model.metadata.builder.connection.RegexpFileConnection)1 SalesforceSchemaConnection (org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection)1