Search in sources :

Example 1 with SalesforceSchemaConnectionItem

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

the class SalesforceTimeoutMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org .talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    if (item instanceof SalesforceSchemaConnectionItem) {
        boolean modify = false;
        SalesforceSchemaConnectionItem salesforceItem = (SalesforceSchemaConnectionItem) item;
        if (salesforceItem.getConnection() instanceof SalesforceSchemaConnection) {
            SalesforceSchemaConnection sfConnection = (SalesforceSchemaConnection) salesforceItem.getConnection();
            if (sfConnection.getTimeOut() == null || "".equals(sfConnection.getTimeOut())) {
                sfConnection.setTimeOut("60000");
                modify = true;
            }
        }
        if (modify) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
                return ExecutionResult.SUCCESS_WITH_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem)

Example 2 with SalesforceSchemaConnectionItem

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

the class AddLoginTypeForSalesforceMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    if (item instanceof SalesforceSchemaConnectionItem) {
        SalesforceSchemaConnectionItem connectionItem = (SalesforceSchemaConnectionItem) item;
        SalesforceSchemaConnection connection = (SalesforceSchemaConnection) connectionItem.getConnection();
        if (connection instanceof SalesforceSchemaConnection) {
            boolean modified = false;
            if (connection.getLoginType() == null) {
                connection.setLoginType(BASIC);
                modified = true;
            }
            if (modified) {
                try {
                    factory.save(item, true);
                    return ExecutionResult.SUCCESS_WITH_ALERT;
                } catch (Exception e) {
                    ExceptionHandler.process(e);
                    return ExecutionResult.FAILURE;
                }
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem)

Example 3 with SalesforceSchemaConnectionItem

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

the class SalesforceMultiSchemaMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org .talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    if (item instanceof SalesforceSchemaConnectionItem) {
        boolean modify = false;
        SalesforceSchemaConnectionItem salesforceItem = (SalesforceSchemaConnectionItem) item;
        if (salesforceItem.getConnection() instanceof SalesforceSchemaConnection) {
            SalesforceSchemaConnection sfConnection = (SalesforceSchemaConnection) salesforceItem.getConnection();
            SalesforceModuleUnit module = ConnectionFactory.eINSTANCE.createSalesforceModuleUnit();
            module.setId(ProxyRepositoryFactory.getInstance().getNextId());
            String moduleName = sfConnection.getModuleName();
            if (moduleName == null || "".equals(moduleName)) {
                moduleName = "Default";
            }
            module.setLabel(moduleName);
            module.setModuleName(moduleName);
            EList<orgomg.cwm.objectmodel.core.Package> originalPackages = sfConnection.getDataPackage();
            for (int i = 0; i < originalPackages.size(); i++) {
                MetadataTable table = (MetadataTable) originalPackages.get(i).getOwnedElement().get(0);
                if (originalPackages.get(i) instanceof RecordFile) {
                    table.setLabel(moduleName);
                }
                module.getTables().add(table);
            }
            sfConnection.getModules().add(module);
            modify = true;
        }
        if (modify) {
            try {
                ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
                factory.save(item, true);
                return ExecutionResult.SUCCESS_WITH_ALERT;
            } catch (Exception e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) RecordFile(orgomg.cwm.resource.record.RecordFile) MetadataTable(org.talend.core.model.metadata.builder.connection.MetadataTable) SalesforceModuleUnit(org.talend.core.model.metadata.builder.connection.SalesforceModuleUnit)

Example 4 with SalesforceSchemaConnectionItem

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

the class RepositoryChangeMetadataCommand method execute.

@Override
public void execute() {
    node.setPropertyValue(propName, newPropValue);
    String mainSchemaParamName = DesignerUtilities.getMainSchemaParameterName(node);
    if (mainSchemaParamName.equals(propName)) {
        IElementParameter elementParameter = node.getElementParameter(propName);
        if (elementParameter != null) {
            IElementParameter schemaTypeParam = elementParameter.getParentParameter().getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
            if (schemaTypeParam != null) {
                if (newPropValue != null && !"".equals(newPropValue)) {
                    //$NON-NLS-1$
                    schemaTypeParam.setValue(EmfComponent.REPOSITORY);
                } else {
                    schemaTypeParam.setValue(EmfComponent.BUILTIN);
                }
            }
        }
    }
    if (node.isExternalNode() && !node.isELTComponent()) {
        for (IElementParameter parameter : node.getElementParameters()) {
            if (parameter.getFieldType() == EParameterFieldType.TABLE) {
                if (!node.getMetadataList().isEmpty() && !node.getMetadataList().get(0).sameMetadataAs(newOutputMetadata)) {
                    parameter.setValue(new ArrayList<Map<String, Object>>());
                }
            }
        }
    }
    // ELT Input/output component need add the schema conetxt in Context Mode
    if (node.isELTComponent()) {
        //$NON-NLS-1$
        IElementParameter schemaParam = node.getElementParameter("ELT_SCHEMA_NAME");
        if (schemaParam != null && schemaParam.getValue() != null && newPropValue != null && connection != null && connection.isContextMode() && ContextParameterUtils.isContainContextParam(schemaParam.getValue().toString())) {
            ConnectionItem connectionItem = MetadataToolHelper.getConnectionItemFromRepository(newPropValue.toString());
            ConnectionContextHelper.addContextForNodeParameter(node, connectionItem, false);
        }
    }
    // IElementParameter schemaTypeParameter =
    // node.getElementParameter(propName).getParentParameter().getChildParameters().get(
    // EParameterName.SCHEMA_TYPE.getName());
    // IElementParameter repositorySchemaTypeParameter = node.getElementParameter(propName).getParentParameter()
    // .getChildParameters().get(EParameterName.REPOSITORY_SCHEMA_TYPE.getName());
    // String schemaType = (String) schemaTypeParameter.getValue();
    // bug 6028, Display the parameter of REPOSITORY_SCHEMA_TYPE
    // if (schemaType != null && schemaType.equals(EmfComponent.REPOSITORY)) {
    // repositorySchemaTypeParameter.setShow(true);
    // if (newRepositoryIdValue != null) {
    // oldRepositoryIdValue = (String) repositorySchemaTypeParameter.getValue();
    // repositorySchemaTypeParameter.setValue(newRepositoryIdValue);
    // }
    // } else {
    // repositorySchemaTypeParameter.setShow(false);
    // }
    // Xstream Cdc Type Mode
    boolean isXstreamCdcTypeMode = false;
    if (connection != null && connection instanceof DatabaseConnection) {
        String cdcTypeMode = ((DatabaseConnection) connection).getCdcTypeMode();
        if (CDCTypeMode.XSTREAM_MODE == CDCTypeMode.indexOf(cdcTypeMode)) {
            isXstreamCdcTypeMode = true;
        }
    }
    node.getElementParameter(EParameterName.UPDATE_COMPONENTS.getName()).setValue(true);
    String componentName = node.getComponent().getName();
    if (newOutputMetadata != null) {
        Map<String, String> addMap = newOutputMetadata.getAdditionalProperties();
        if (addMap.get(TaggedValueHelper.SYSTEMTABLENAME) != null && componentName.equals("tAS400CDC")) {
            //$NON-NLS-1$
            setDBTableFieldValue(node, addMap.get(TaggedValueHelper.SYSTEMTABLENAME), oldOutputMetadata.getTableName());
        } else if (isXstreamCdcTypeMode) {
            IElementParameter elementParameter = node.getElementParameter(propName);
            if (elementParameter != null) {
                if (oracleCdcComponent[0].equals(componentName) || oracleCdcComponent[1].equals(componentName)) {
                    IElementParameter schemaTypeParam = elementParameter.getParentParameter().getChildParameters().get(EParameterName.SCHEMA_TYPE.getName());
                    IElementParameter schemaParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                    if (schemaTypeParam != null) {
                        schemaTypeParam.setValue(EmfComponent.BUILTIN);
                        if (schemaParam != null && schemaParam.getValue() != null && schemaParam.getValue() instanceof IMetadataTable) {
                            newOutputMetadata.setListColumns((((IMetadataTable) schemaParam.getValue()).clone(true)).getListColumns());
                        }
                        if (oracleCdcComponent[1].equals(componentName)) {
                            newOutputMetadata.setListColumns(new ArrayList<IMetadataColumn>());
                        }
                    }
                }
            }
            setDBTableFieldValue(node, newOutputMetadata.getTableName(), oldOutputMetadata.getTableName());
        } else {
            setDBTableFieldValue(node, newOutputMetadata.getTableName(), oldOutputMetadata.getTableName());
        }
        //$NON-NLS-1$
        IElementParameter parameter = node.getElementParameter("SAP_FUNCTION");
        if (parameter != null) {
            setSAPFunctionName(node, parameter.getValue() == null ? null : (String) parameter.getValue());
        }
        if (newPropValue instanceof String) {
            if (orginalTable != null && orginalTable instanceof SAPBWTable) {
                String innerIOType = ((SAPBWTable) orginalTable).getInnerIOType();
                String sourceSysName = ((SAPBWTable) orginalTable).getSourceSystemName();
                IElementParameter schemaTypeParam = node.getElementParameterFromField(EParameterFieldType.SCHEMA_TYPE);
                IMetadataTable metadataTable = null;
                if (schemaTypeParam != null) {
                    metadataTable = node.getMetadataFromConnector(schemaTypeParam.getContext());
                }
                if (metadataTable != null) {
                    if (innerIOType != null) {
                        //$NON-NLS-1$
                        IElementParameter param = node.getElementParameter("INFO_OBJECT_TYPE");
                        if (param != null) {
                            param.setValue(innerIOType);
                            metadataTable.getAdditionalProperties().put(SAPBWTableHelper.SAP_INFOOBJECT_INNER_TYPE, innerIOType);
                        }
                    }
                    if (sourceSysName != null) {
                        //$NON-NLS-1$
                        IElementParameter param = node.getElementParameter("SOURCE_SYSTEM_NAME");
                        if (param != null) {
                            param.setValue(TalendTextUtils.addQuotes(sourceSysName));
                            metadataTable.getAdditionalProperties().put(SAPBWTableHelper.SAP_DATASOURCE_SOURCESYSNAME, sourceSysName);
                        }
                    }
                }
            }
        }
        setTableRelevantParameterValues();
        if (getConnection() != null) {
            // for salesforce
            IElementParameter param = node.getElementParameterFromField(EParameterFieldType.PROPERTY_TYPE);
            if (param != null && EmfComponent.REPOSITORY.equals(param.getChildParameters().get(EParameterName.PROPERTY_TYPE.getName()).getValue())) {
                IElementParameter module = node.getElementParameter("module.moduleName");
                if (module != null) {
                    String repositoryValue = module.getRepositoryValue();
                    if (repositoryValue == null) {
                        List<ComponentProperties> componentProperties = null;
                        IGenericWizardService wizardService = null;
                        if (GlobalServiceRegister.getDefault().isServiceRegistered(IGenericWizardService.class)) {
                            wizardService = (IGenericWizardService) GlobalServiceRegister.getDefault().getService(IGenericWizardService.class);
                        }
                        if (wizardService != null && wizardService.isGenericConnection(getConnection())) {
                            componentProperties = wizardService.getAllComponentProperties(getConnection(), null);
                        }
                        repositoryValue = String.valueOf(RepositoryToComponentProperty.getGenericRepositoryValue(getConnection(), componentProperties, module.getName()));
                    }
                    if (repositoryValue != null) {
                        Object objectValue = RepositoryToComponentProperty.getValue(getConnection(), repositoryValue, newOutputMetadata, node.getComponent().getName());
                        if (objectValue != null) {
                            module.setValue(objectValue);
                        }
                    }
                }
            }
        }
    }
    super.setConnection(connection);
    super.execute();
    String propertyType = (String) node.getPropertyValue(EParameterName.PROPERTY_TYPE.getName());
    if (propertyType != null) {
        if (propertyType.equals(EmfComponent.REPOSITORY)) {
            String propertyValue = (String) node.getPropertyValue(EParameterName.REPOSITORY_PROPERTY_TYPE.getName());
            IRepositoryViewObject lastVersion = UpdateRepositoryUtils.getRepositoryObjectById(propertyValue);
            if (lastVersion == null) {
                return;
            }
            Item item = lastVersion.getProperty().getItem();
            if (item instanceof ConnectionItem) {
                List<? extends IElementParameter> elementParameters = new ArrayList(node.getElementParameters());
                for (IElementParameter param : elementParameters) {
                    if (param.getRepositoryValue() != null && !param.getRepositoryValue().equals("")) {
                        //$NON-NLS-1$
                        boolean isCustomSfConn = false;
                        if (item instanceof SalesforceSchemaConnectionItem) {
                            SalesforceSchemaConnection sfConn = (SalesforceSchemaConnection) ((SalesforceSchemaConnectionItem) item).getConnection();
                            isCustomSfConn = sfConn.isUseCustomModuleName();
                        }
                        if (//$NON-NLS-1$
                        param.getRepositoryValue().equals("TYPE") || (param.getRepositoryValue().equals("MODULENAME") && item instanceof SalesforceSchemaConnectionItem && !isCustomSfConn)) {
                            //$NON-NLS-1$
                            continue;
                        }
                        if (param.getFieldType().equals(EParameterFieldType.TABLE) && param.getRepositoryValue().equals("XML_MAPPING")) {
                            //$NON-NLS-1$
                            List<Map<String, Object>> table = (List<Map<String, Object>>) node.getPropertyValue(param.getName());
                            IMetadataTable metaTable = node.getMetadataList().get(0);
                            RepositoryToComponentProperty.getTableXmlFileValue(((ConnectionItem) item).getConnection(), //$NON-NLS-1$
                            "XML_MAPPING", //$NON-NLS-1$
                            param, table, newOutputMetadata);
                            param.setRepositoryValueUsed(true);
                        } else {
                            if (connection != null && (xmlComponent[0].equals(componentName) || xmlComponent[1].equals(componentName) || xmlComponent[2].equals(componentName)) && connection instanceof XmlFileConnection && XmlUtil.isXSDFile(TalendQuoteUtils.removeQuotes(((XmlFileConnection) connection).getXmlFilePath())) && param.getRepositoryValue().equals("FILE_PATH")) {
                            // do nothing
                            } else {
                                Object value = RepositoryToComponentProperty.getValue(((ConnectionItem) item).getConnection(), param.getRepositoryValue(), newOutputMetadata);
                                if (value != null) {
                                    param.setValue(value);
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    node.setPropertyValue(EParameterName.UPDATE_COMPONENTS.getName(), Boolean.TRUE);
}
Also used : ComponentProperties(org.talend.components.api.properties.ComponentProperties) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) XmlFileConnection(org.talend.core.model.metadata.builder.connection.XmlFileConnection) ArrayList(java.util.ArrayList) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) IMetadataTable(org.talend.core.model.metadata.IMetadataTable) SalesforceSchemaConnection(org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection) ConnectionItem(org.talend.core.model.properties.ConnectionItem) SalesforceSchemaConnectionItem(org.talend.core.model.properties.SalesforceSchemaConnectionItem) Item(org.talend.core.model.properties.Item) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IGenericWizardService(org.talend.core.runtime.services.IGenericWizardService) DatabaseConnection(org.talend.core.model.metadata.builder.connection.DatabaseConnection) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) ArrayList(java.util.ArrayList) List(java.util.List) SAPBWTable(org.talend.core.model.metadata.builder.connection.SAPBWTable) Map(java.util.Map)

Aggregations

SalesforceSchemaConnection (org.talend.core.model.metadata.builder.connection.SalesforceSchemaConnection)4 SalesforceSchemaConnectionItem (org.talend.core.model.properties.SalesforceSchemaConnectionItem)4 ProxyRepositoryFactory (org.talend.core.repository.model.ProxyRepositoryFactory)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ComponentProperties (org.talend.components.api.properties.ComponentProperties)1 IMetadataTable (org.talend.core.model.metadata.IMetadataTable)1 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)1 MetadataTable (org.talend.core.model.metadata.builder.connection.MetadataTable)1 SAPBWTable (org.talend.core.model.metadata.builder.connection.SAPBWTable)1 SalesforceModuleUnit (org.talend.core.model.metadata.builder.connection.SalesforceModuleUnit)1 XmlFileConnection (org.talend.core.model.metadata.builder.connection.XmlFileConnection)1 IElementParameter (org.talend.core.model.process.IElementParameter)1 ConnectionItem (org.talend.core.model.properties.ConnectionItem)1 Item (org.talend.core.model.properties.Item)1 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)1 IGenericWizardService (org.talend.core.runtime.services.IGenericWizardService)1 RecordFile (orgomg.cwm.resource.record.RecordFile)1