Search in sources :

Example 6 with EParameterFieldType

use of org.talend.core.model.process.EParameterFieldType in project tdi-studio-se by Talend.

the class EncryptPasswordInComponentsMigrationTask method execute.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.core.model.migration.AbstractItemMigrationTask#execute(org.talend.core.model.properties.Item)
     */
@Override
public ExecutionResult execute(Item item) {
    ProcessType processType = getProcessType(item);
    try {
        boolean modified = false;
        ComponentCategory category = ComponentCategory.getComponentCategoryFromItem(item);
        for (Object nodeObjectType : processType.getNode()) {
            NodeType nodeType = (NodeType) nodeObjectType;
            IComponent component = ComponentsFactoryProvider.getInstance().get(nodeType.getComponentName(), category.getName());
            if (component == null) {
                continue;
            }
            FakeNode fNode = new FakeNode(component);
            for (Object paramObjectType : nodeType.getElementParameter()) {
                ElementParameterType param = (ElementParameterType) paramObjectType;
                IElementParameter paramFromEmf = fNode.getElementParameter(param.getName());
                if (paramFromEmf == null) {
                    // might be some deprecated / removed parameter.
                    continue;
                }
                EParameterFieldType paramFromComponent = paramFromEmf.getFieldType();
                if (EParameterFieldType.PASSWORD == paramFromComponent && param.getValue() != null) {
                    boolean encrypted = true;
                    try {
                        int ind = param.getValue().lastIndexOf(PasswordEncryptUtil.ENCRYPT_KEY);
                        if (ind == -1) {
                            encrypted = false;
                        } else {
                            String value = new StringBuilder(param.getValue()).replace(ind, ind + PasswordEncryptUtil.ENCRYPT_KEY.length(), "").toString();
                            PasswordEncryptUtil.decryptPassword(value);
                        }
                    } catch (Exception e) {
                        encrypted = false;
                    }
                    if (!encrypted) {
                        param.setValue(PasswordEncryptUtil.encryptPassword(param.getValue()) + PasswordEncryptUtil.ENCRYPT_KEY);
                        modified = true;
                    }
                }
            }
        }
        if (modified) {
            ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
            factory.save(item, true);
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : IComponent(org.talend.core.model.components.IComponent) ComponentCategory(org.talend.core.model.components.ComponentCategory) ElementParameterType(org.talend.designer.core.model.utils.emf.talendfile.ElementParameterType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) EParameterFieldType(org.talend.core.model.process.EParameterFieldType) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IElementParameter(org.talend.core.model.process.IElementParameter)

Aggregations

EParameterFieldType (org.talend.core.model.process.EParameterFieldType)6 ArrayList (java.util.ArrayList)3 List (java.util.List)2 Property (org.talend.daikon.properties.property.Property)2 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 Schema (org.apache.avro.Schema)1 CoreException (org.eclipse.core.runtime.CoreException)1 IConfigurationElement (org.eclipse.core.runtime.IConfigurationElement)1 CCombo (org.eclipse.swt.custom.CCombo)1 TableEditor (org.eclipse.swt.custom.TableEditor)1 Button (org.eclipse.swt.widgets.Button)1 Control (org.eclipse.swt.widgets.Control)1 TableItem (org.eclipse.swt.widgets.TableItem)1 Text (org.eclipse.swt.widgets.Text)1 Connector (org.talend.components.api.component.Connector)1 PropertyPathConnector (org.talend.components.api.component.PropertyPathConnector)1 ComponentProperties (org.talend.components.api.properties.ComponentProperties)1 EDatabaseTypeName (org.talend.core.database.EDatabaseTypeName)1