Search in sources :

Example 71 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class UpdateJobletContextInJobMigrationTask method execute.

@Override
public ExecutionResult execute(Item item) {
    if (item instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) item;
        List<ContextType> contexts = processItem.getProcess().getContext();
        if (contexts.size() > 1) {
            boolean isModified = false;
            for (ContextType context1 : contexts) {
                List<ContextParameterType> params1 = context1.getContextParameter();
                for (ContextParameterType param1 : params1) {
                    String id = param1.getRepositoryContextId();
                    if (id != null) {
                        for (ContextType context2 : contexts) {
                            if (context2 != context1) {
                                List<ContextParameterType> params2 = context2.getContextParameter();
                                for (ContextParameterType param2 : params2) {
                                    if (param2.getName().equals(param1.getName()) && param2.getRepositoryContextId() == null) {
                                        param2.setRepositoryContextId(id);
                                        isModified = true;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            if (isModified) {
                try {
                    ProxyRepositoryFactory.getInstance().save(item, true);
                } catch (PersistenceException e) {
                    ExceptionHandler.process(e);
                    return ExecutionResult.FAILURE;
                }
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ProcessItem(org.talend.core.model.properties.ProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 72 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType 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 73 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class ExportProcessorHelper method exportJob.

public String exportJob(Processor processor, int statisticsPort, int tracePort, String watchParam, String log4jLevel, final IProgressMonitor progressMonitor) throws ProcessorException {
    ProcessItem processItem = (ProcessItem) processor.getProperty().getItem();
    processName = processor.getProperty().getLabel();
    //$NON-NLS-1$
    File archiveFile = new File(getTmpExportFolder(), "remote_run_export-" + processName + FileExtensions.ZIP_FILE_SUFFIX);
    Properties prop = new Properties();
    if (watchParam != null) {
        prop.setProperty(TalendProcessArgumentConstant.ARG_ENABLE_WATCH, watchParam);
    }
    // FIXME, maybe should try another way. it's not good, I think.
    // update directly the .item (without save it) in case of prompt
    // then the generation will be correct automatically in the .properties
    IContext context = processor.getContext();
    if (context != null) {
        List<IContextParameter> contextParameterList = context.getContextParameterList();
        if (contextParameterList != null && contextParameterList.size() > 0) {
            for (IContextParameter contextParameter : contextParameterList) {
                if (!contextParameter.isPromptNeeded()) {
                    continue;
                }
                for (Object curCType : processItem.getProcess().getContext()) {
                    ContextType cType = (ContextType) curCType;
                    if (context.getName().equals(cType.getName())) {
                        for (Object curParam : cType.getContextParameter()) {
                            ContextParameterType cParamType = (ContextParameterType) curParam;
                            if (contextParameter.getName().equals(cParamType.getName())) {
                                cParamType.setRawValue(contextParameter.getValue());
                            }
                        }
                    }
                }
            }
        }
    }
    export(progressMonitor, processItem, ERepositoryObjectType.getItemType(processItem), processor.getContext().getName(), archiveFile.toString(), log4jLevel, false, statisticsPort, tracePort, prop);
    return archiveFile.toString();
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IContext(org.talend.core.model.process.IContext) ProcessItem(org.talend.core.model.properties.ProcessItem) Properties(java.util.Properties) File(java.io.File) IContextParameter(org.talend.core.model.process.IContextParameter) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 74 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class EncryptDbPasswordMigrationTask method encryptContextPassword.

/**
     * DOC chuang Comment method "encryptContextPassword".
     * 
     * @param item
     * @param contextTypeList
     * @return
     */
private ExecutionResult encryptContextPassword(Item item, List<ContextType> contextTypeList) {
    boolean modify = false;
    if (contextTypeList != null) {
        for (ContextType type : contextTypeList) {
            List<ContextParameterType> paramTypes = type.getContextParameter();
            if (paramTypes != null) {
                for (ContextParameterType param : paramTypes) {
                    try {
                        // before migration task, the value should be raw. so keep it.
                        if (param.getValue() != null && PasswordEncryptUtil.isPasswordType(param.getType())) {
                            encryptPassword(param);
                            modify = true;
                        }
                    } catch (Exception e) {
                        ExceptionHandler.process(e);
                        return ExecutionResult.FAILURE;
                    }
                }
            }
        }
    }
    if (modify) {
        try {
            factory.save(item, true);
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.SUCCESS_NO_ALERT;
}
Also used : 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 75 with ContextType

use of org.talend.designer.core.model.utils.emf.talendfile.ContextType in project tdi-studio-se by Talend.

the class TosTokenCollector method collectJobDetails.

/**
     * DOC nrousseau Comment method "collectJobDetails".
     * 
     * @param all
     * @param jobDetails
     * @throws JSONException
     */
private void collectJobDetails(List<IRepositoryViewObject> allRvo, JSONObject jobDetails) throws JSONException {
    IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
    IWorkbenchWindow ww = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IEditorReference[] reference = new IEditorReference[0];
    if (ww != null) {
        IWorkbenchPage page = ww.getActivePage();
        reference = page.getEditorReferences();
    }
    List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
    Set<String> idsOpened = new HashSet<String>();
    for (IProcess2 process : processes) {
        idsOpened.add(process.getId());
    }
    JSONArray components = new JSONArray();
    int contextVarsNum = 0;
    int nbComponentsUsed = 0;
    for (IRepositoryViewObject rvo : allRvo) {
        Item item = rvo.getProperty().getItem();
        if (item instanceof ProcessItem) {
            ProcessType processType = ((ProcessItem) item).getProcess();
            for (NodeType node : (List<NodeType>) processType.getNode()) {
                JSONObject component_names = null;
                String componentName = node.getComponentName();
                int nbComp = 0;
                for (int i = 0; i < components.length(); i++) {
                    JSONObject temp = components.getJSONObject(i);
                    if (temp.get("component_name").equals(componentName)) {
                        //$NON-NLS-1$
                        //$NON-NLS-1$
                        nbComp = temp.getInt("count");
                        component_names = temp;
                        break;
                    }
                }
                if (component_names == null) {
                    component_names = new JSONObject();
                    components.put(component_names);
                }
                component_names.put("component_name", componentName);
                component_names.put("count", nbComp + 1);
                nbComponentsUsed++;
            }
            // context variable per job
            EList contexts = processType.getContext();
            if (contexts.size() > 0) {
                ContextType contextType = (ContextType) contexts.get(0);
                contextVarsNum += contextType.getContextParameter().size();
            }
        }
        if (factory.getStatus(item) != ERepositoryStatus.LOCK_BY_USER && !idsOpened.contains(item.getProperty().getId())) {
            // job is not locked and not opened by editor, so we can unload.
            if (item.getParent() instanceof FolderItem) {
                ((FolderItem) item.getParent()).getChildren().remove(item);
                item.setParent(null);
            }
            item.eResource().unload();
        }
    }
    jobDetails.put("components", components);
    jobDetails.put("nb.contextVars", contextVarsNum);
    jobDetails.put("nb.components", nbComponentsUsed);
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) JSONArray(us.monoid.json.JSONArray) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) ProcessItem(org.talend.core.model.properties.ProcessItem) Item(org.talend.core.model.properties.Item) FolderItem(org.talend.core.model.properties.FolderItem) DatabaseConnectionItem(org.talend.core.model.properties.DatabaseConnectionItem) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) IEditorReference(org.eclipse.ui.IEditorReference) EList(org.eclipse.emf.common.util.EList) FolderItem(org.talend.core.model.properties.FolderItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JSONObject(us.monoid.json.JSONObject) NodeType(org.talend.designer.core.model.utils.emf.talendfile.NodeType) IProcess2(org.talend.core.model.process.IProcess2) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ArrayList(java.util.ArrayList) EList(org.eclipse.emf.common.util.EList) List(java.util.List) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet)

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)108 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)27 ArrayList (java.util.ArrayList)26 ContextItem (org.talend.core.model.properties.ContextItem)21 PersistenceException (org.talend.commons.exception.PersistenceException)17 File (java.io.File)16 NoSQLServerException (org.talend.repository.nosql.exceptions.NoSQLServerException)15 HadoopClusterConnection (org.talend.repository.model.hadoopcluster.HadoopClusterConnection)13 NoSQLReflectionException (org.talend.repository.nosql.exceptions.NoSQLReflectionException)13 Test (org.junit.Test)12 HashMap (java.util.HashMap)10 List (java.util.List)10 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)8 Map (java.util.Map)8 EList (org.eclipse.emf.common.util.EList)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 Property (org.talend.core.model.properties.Property)6 HashSet (java.util.HashSet)5