Search in sources :

Example 26 with ContextItem

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

the class UnifyPasswordEncryption4ContextMigrationTask 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 ContextItem) {
        List<ContextType> contextTypeList = ((ContextItem) item).getContext();
        boolean modify = false;
        if (contextTypeList != null) {
            for (ContextType type : contextTypeList) {
                List<ContextParameterType> paramTypes = type.getContextParameter();
                if (paramTypes != null) {
                    for (ContextParameterType param : paramTypes) {
                        try {
                            String value = param.getValue();
                            if (value != null && PasswordEncryptUtil.isPasswordType(param.getType())) {
                                String rawPassword = PasswordEncryptUtil.decryptPassword(value);
                                param.setRawValue(rawPassword);
                                modify = true;
                            }
                        } catch (Exception e) {
                            ExceptionHandler.process(e);
                            return ExecutionResult.FAILURE;
                        }
                    }
                }
            }
        }
        if (modify) {
            try {
                factory.save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
                return ExecutionResult.FAILURE;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType) PersistenceException(org.talend.commons.exception.PersistenceException)

Example 27 with ContextItem

use of org.talend.core.model.properties.ContextItem in project tesb-studio-se by Talend.

the class CamelEditorDropTargetListener method createContext.

private void createContext() {
    if (selectSourceList.size() == 0) {
        return;
    }
    boolean created = false;
    for (Object source : selectSourceList) {
        if (source instanceof RepositoryNode) {
            RepositoryNode sourceNode = (RepositoryNode) source;
            Item item = sourceNode.getObject().getProperty().getItem();
            if (item instanceof ContextItem) {
                ContextItem contextItem = (ContextItem) item;
                EList context = contextItem.getContext();
                Set<String> contextSet = new HashSet<String>();
                Iterator iterator = context.iterator();
                while (iterator.hasNext()) {
                    Object obj = iterator.next();
                    if (obj instanceof ContextTypeImpl) {
                        EList contextParameters = ((ContextTypeImpl) obj).getContextParameter();
                        Iterator contextParas = contextParameters.iterator();
                        while (contextParas.hasNext()) {
                            ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
                            String name = contextParameterType.getName();
                            contextSet.add(name);
                        }
                    }
                }
                IEditorInput editorInput = editor.getEditorInput();
                if (editorInput instanceof JobEditorInput) {
                    JobEditorInput jobInput = (JobEditorInput) editorInput;
                    IProcess2 process = jobInput.getLoadedProcess();
                    IContextManager contextManager = process.getContextManager();
                    List<IContext> listContext = contextManager.getListContext();
                    Set<String> addedVars = ConnectionContextHelper.checkAndAddContextVariables(contextItem, contextSet, process.getContextManager(), false);
                    if (addedVars != null && !addedVars.isEmpty() && !ConnectionContextHelper.isAddContextVar(contextItem, contextManager, contextSet)) {
                        // show
                        Map<String, Set<String>> addedVarsMap = new HashMap<String, Set<String>>();
                        addedVarsMap.put(item.getProperty().getLabel(), contextSet);
                        if (ConnectionContextHelper.showContextdialog(process, contextItem, process.getContextManager(), addedVarsMap, contextSet)) {
                            created = true;
                        }
                    } else {
                        //$NON-NLS-1$
                        MessageDialog.openInformation(//$NON-NLS-1$
                        editor.getEditorSite().getShell(), //$NON-NLS-1$
                        "Adding Context", //$NON-NLS-1$
                        "Context \"" + contextItem.getProperty().getDisplayName() + "\" already exist.");
                    }
                }
            }
        }
    }
    if (created) {
        RepositoryPlugin.getDefault().getDesignerCoreService().switchToCurContextsView();
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) IContext(org.talend.core.model.process.IContext) Set(java.util.Set) HashSet(java.util.HashSet) HashMap(java.util.HashMap) ContextParameterTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextParameterTypeImpl) RepositoryNode(org.talend.repository.model.RepositoryNode) JobEditorInput(org.talend.core.ui.editor.JobEditorInput) ContextItem(org.talend.core.model.properties.ContextItem) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) EList(org.eclipse.emf.common.util.EList) Iterator(java.util.Iterator) IProcess2(org.talend.core.model.process.IProcess2) ContextTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ContextTypeImpl) IContextManager(org.talend.core.model.process.IContextManager) IEditorInput(org.eclipse.ui.IEditorInput) HashSet(java.util.HashSet)

Example 28 with ContextItem

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

the class AbstractJSONStepForm method exportAsContext.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.ui.swt.utils.AbstractForm#exportAsContext()
     */
@Override
protected void exportAsContext() {
    if (hasContextBtn() && connectionItem != null) {
        if (isContextMode()) {
            JSONConnectionContextHelper.openInConetxtModeDialog();
        } else {
            Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableModels = JSONConnectionContextHelper.exportAsContext(connectionItem, getConetxtParams());
            contextManager = JSONConnectionContextHelper.contextManager;
            if (variableModels != null) {
                Iterator<ContextItem> contextItor = variableModels.keySet().iterator();
                while (contextItor.hasNext()) {
                    ContextItem contextItem = contextItor.next();
                    List<ConectionAdaptContextVariableModel> apaptModels = variableModels.get(contextItem);
                    if (contextItem != null && apaptModels.size() == 0) {
                        // create
                        if (contextManager instanceof JobContextManager) {
                            Map<String, String> map = ((JobContextManager) contextManager).getNameMap();
                            // set properties for context mode
                            JSONConnectionContextHelper.setPropertiesForContextMode(connectionItem, contextItem, getConetxtParams(), map);
                        }
                    } else {
                        // set properties for exist context
                        JSONConnectionContextHelper.setPropertiesForExistContextMode(connectionItem, getConetxtParams(), variableModels);
                    }
                    // refresh current UI.
                    initialize();
                    adaptFormToEditable();
                }
            }
        }
    }
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) List(java.util.List) JobContextManager(org.talend.core.model.context.JobContextManager) ConectionAdaptContextVariableModel(org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)

Aggregations

ContextItem (org.talend.core.model.properties.ContextItem)28 ArrayList (java.util.ArrayList)9 PersistenceException (org.talend.commons.exception.PersistenceException)9 ProcessItem (org.talend.core.model.properties.ProcessItem)9 HashMap (java.util.HashMap)8 List (java.util.List)8 ConnectionItem (org.talend.core.model.properties.ConnectionItem)7 Item (org.talend.core.model.properties.Item)7 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)7 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)7 EList (org.eclipse.emf.common.util.EList)6 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)6 RepositoryNode (org.talend.repository.model.RepositoryNode)6 ConectionAdaptContextVariableModel (org.talend.core.ui.context.model.table.ConectionAdaptContextVariableModel)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 Iterator (java.util.Iterator)4 Map (java.util.Map)4 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 Connection (org.talend.core.model.metadata.builder.connection.Connection)4 IContext (org.talend.core.model.process.IContext)4