Search in sources :

Example 36 with ContextType

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

the class ProcessController method updateContextList.

/**
     * 
     * ggu Comment method "updateContextList".
     * 
     * @param processParam
     */
private void updateContextList(IElementParameter processParam) {
    if (processParam == null || (processParam.getFieldType() != EParameterFieldType.PROCESS_TYPE && processParam.getFieldType() != EParameterFieldType.ROUTE_INPUT_PROCESS_TYPE)) {
        return;
    }
    // for context type
    List<String> contextNameList = new ArrayList<String>();
    List<String> contextValueList = new ArrayList<String>();
    // for version type
    List<String> versionNameList = new ArrayList<String>();
    List<String> versionValueList = new ArrayList<String>();
    versionNameList.add(ItemCacheManager.LATEST_VERSION);
    versionValueList.add(ItemCacheManager.LATEST_VERSION);
    IElementParameter jobNameParam = processParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
    // feature 19312
    Item item = null;
    StringBuffer labels = new StringBuffer("");
    List<IRepositoryViewObject> allVersion = new ArrayList<IRepositoryViewObject>();
    final String strJobId = (String) jobNameParam.getValue();
    String[] strJobIds = strJobId.split(ProcessController.COMMA);
    for (int i = 0; i < strJobIds.length; i++) {
        String id = strJobIds[i];
        if (StringUtils.isNotEmpty(id)) {
            allVersion = ProcessorUtilities.getAllVersionObjectById(id);
            // IRepositoryObject lastVersionObject = null;
            String label = null;
            if (allVersion != null) {
                String oldVersion = null;
                for (IRepositoryViewObject obj : allVersion) {
                    String version = obj.getVersion();
                    if (oldVersion == null) {
                        oldVersion = version;
                    }
                    if (VersionUtils.compareTo(version, oldVersion) >= 0) {
                        item = obj.getProperty().getItem();
                    // lastVersionObject = obj;
                    }
                    oldVersion = version;
                    versionNameList.add(version);
                    versionValueList.add(version);
                }
                label = item.getProperty().getLabel();
                if (i > 0) {
                    labels.append(ProcessController.COMMA);
                }
                labels.append(label);
            // IPath path = RepositoryNodeUtilities.getPath(lastVersionObject);
            // if (path != null) {
            // label = path.toString() + IPath.SEPARATOR + label;
            // }
            } else {
            // FIXME TUP-5524, don't set empty, keep the id value instead.
            // final String parentName = processParam.getName() + ":"; //$NON-NLS-1$
            // if (elem != null) {
            // // can be called in multi-thread, dispose method may be already called before executing this
            // method
            //elem.setPropertyValue(parentName + jobNameParam.getName(), ""); //$NON-NLS-1$
            // }
            }
        }
    }
    jobNameParam.setLabelFromRepository(labels.toString());
    // set default context
    String defalutValue = null;
    if (item != null && item instanceof ProcessItem) {
        for (Object o : ((ProcessItem) item).getProcess().getContext()) {
            if (o instanceof ContextType) {
                ContextType context = (ContextType) o;
                contextNameList.add(context.getName());
                contextValueList.add(context.getName());
            }
        }
        defalutValue = ((ProcessItem) item).getProcess().getDefaultContext();
    }
    setProcessTypeRelatedValues(processParam, contextNameList, contextValueList, EParameterName.PROCESS_TYPE_CONTEXT.getName(), defalutValue);
    setProcessTypeRelatedValues(processParam, versionNameList, versionValueList, EParameterName.PROCESS_TYPE_VERSION.getName(), null);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) Item(org.talend.core.model.properties.Item) ProcessItem(org.talend.core.model.properties.ProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) IElementParameter(org.talend.core.model.process.IElementParameter) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject)

Example 37 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 38 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 39 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)

Example 40 with ContextType

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

the class ExportJobUtil method getJobContextValues.

/**
     * DOC zli Comment method "getJobContextValues".
     * 
     * @param processItem
     * @param contextName
     * @return
     */
@SuppressWarnings("rawtypes")
public static List<ContextParameterType> getJobContextValues(ProcessItem processItem, String contextName) {
    if (contextName == null) {
        return null;
    }
    // else do next line
    List<ContextParameterType> list = new ArrayList<ContextParameterType>();
    EList contexts = ((ProcessTypeImpl) processItem.getProcess()).getContext();
    for (int i = 0; i < contexts.size(); i++) {
        Object object = contexts.get(i);
        if (object instanceof ContextType) {
            ContextType contextType = (ContextType) object;
            if (contextName.equals(contextType.getName())) {
                EList contextParameter = contextType.getContextParameter();
                for (int j = 0; j < contextParameter.size(); j++) {
                    Object object2 = contextParameter.get(j);
                    if (object2 instanceof ContextParameterType) {
                        ContextParameterType contextParameterType = (ContextParameterType) object2;
                        list.add(contextParameterType);
                    }
                }
                return list;
            }
        }
    }
    return null;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) EList(org.eclipse.emf.common.util.EList) ArrayList(java.util.ArrayList) ProcessTypeImpl(org.talend.designer.core.model.utils.emf.talendfile.impl.ProcessTypeImpl) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Aggregations

ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)58 ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)19 PersistenceException (org.talend.commons.exception.PersistenceException)16 ArrayList (java.util.ArrayList)15 File (java.io.File)13 ContextItem (org.talend.core.model.properties.ContextItem)9 ProcessItem (org.talend.core.model.properties.ProcessItem)9 IOException (java.io.IOException)7 FileNotFoundException (java.io.FileNotFoundException)6 FileOutputStream (java.io.FileOutputStream)6 List (java.util.List)6 EList (org.eclipse.emf.common.util.EList)6 HashMap (java.util.HashMap)5 Test (org.junit.Test)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 IProject (org.eclipse.core.resources.IProject)4 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)4 BufferedReader (java.io.BufferedReader)3 EOFException (java.io.EOFException)3 FileInputStream (java.io.FileInputStream)3