Search in sources :

Example 1 with ContextParameterType

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

the class HTMLDocGenerator method generateContextInfo.

/**
     * DOC YeXiaowei Comment method "generateContextInfo".
     * 
     * @return
     */
private void generateContextInfo(final Item item, final Element element) {
    EList contexts = null;
    if (item instanceof ProcessItem) {
        contexts = ((ProcessItem) item).getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        contexts = ((JobletProcessItem) item).getJobletProcess().getContext();
    }
    if (contexts == null || contexts.isEmpty()) {
        return;
    }
    // Context root //$NON-NLS-1$
    Element contextListElement = DocumentHelper.createElement("contextList");
    for (int i = 0, n = contexts.size(); i < n; i++) {
        // export single context infomation
        //$NON-NLS-1$
        Element contextElement = DocumentHelper.createElement("context");
        ContextType context = (ContextType) contexts.get(i);
        // Attributes
        //$NON-NLS-1$
        contextElement.addAttribute("name", HTMLDocUtils.checkString(context.getName()));
        IProxyRepositoryFactory repositoryFactory = CorePlugin.getDefault().getProxyRepositoryFactory();
        // Context parameters as children
        EList params = context.getContextParameter();
        if (params != null && !params.isEmpty()) {
            for (int j = 0, k = params.size(); j < k; j++) {
                /*
                     * <contextParameter comment="Give server name" name="server" prompt="Default Server "
                     * promptNeeded="false" repositoryContextId="_crJMkCCQEd2Oweh7yRMWjQ" type=""
                     * value="'192.168.0.109'"/>
                     */
                ContextParameterType param = (ContextParameterType) params.get(j);
                //$NON-NLS-1$
                Element contextParamElement = DocumentHelper.createElement("contextParameter");
                //$NON-NLS-1$
                contextParamElement.addAttribute("name", HTMLDocUtils.checkString(param.getName()));
                //$NON-NLS-1$
                contextParamElement.addAttribute("prompt", HTMLDocUtils.checkString(param.getPrompt()));
                contextParamElement.addAttribute("promptNeeded", HTMLDocUtils.checkString(Boolean.toString(//$NON-NLS-1$
                param.isPromptNeeded())));
                //$NON-NLS-1$
                contextParamElement.addAttribute("type", HTMLDocUtils.checkString(param.getType()));
                //$NON-NLS-1$ 
                contextParamElement.addAttribute("value", ParameterValueUtil.getValue4Doc(param));
                // replace repository id with context label
                if (param.getRepositoryContextId() != null) {
                    ContextItem contextItem = ContextUtils.getContextItemById2(param.getRepositoryContextId());
                    if (contextItem != null) {
                        // bug 5978: repository link to context item might be lost.
                        String label = contextItem.getProperty().getLabel();
                        //$NON-NLS-1$
                        contextParamElement.addAttribute("source", HTMLDocUtils.checkString(label));
                    }
                }
                contextElement.add(contextParamElement);
            }
        }
        contextListElement.add(contextElement);
    }
    element.add(contextListElement);
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) EList(org.eclipse.emf.common.util.EList) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) Element(org.dom4j.Element) Point(org.eclipse.draw2d.geometry.Point) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 2 with ContextParameterType

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

the class ProcessContextComposite method checkIsSameContextParameter.

/*
     * check same ContextParameter or not.
     */
private boolean checkIsSameContextParameter() {
    List<ContextItem> allContextItem = ContextUtils.getAllContextItem();
    for (IContext context : process.getContextManager().getListContext()) {
        for (IContextParameter param : context.getContextParameterList()) {
            if (allContextItem != null) {
                ContextItem contextItem = ContextUtils.getContextItemById(allContextItem, param.getSource());
                ContextType contextType = ContextUtils.getContextTypeByName(contextItem, context.getName(), true);
                ContextParameterType contextParameterType = ContextUtils.getContextParameterTypeByName(contextType, param.getName());
                if (!ContextUtils.samePropertiesForContextParameter(param, contextParameterType)) {
                    return false;
                }
                // if don't open the job to run it(not use the "Detect and update all jobs"), will show
                // UpdateDetectionDialog to update the context ,after updated the item, the contextComboViewer still
                // set the old one , so need refresh.
                IContext runJobViewContext = getSelectedContext();
                if (runJobViewContext != null) {
                    for (IContextParameter tempContext : runJobViewContext.getContextParameterList()) {
                        if (tempContext.getName().equals(contextParameterType.getName()) && !ContextUtils.samePropertiesForContextParameter(tempContext, contextParameterType)) {
                            return false;
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : ContextItem(org.talend.core.model.properties.ContextItem) ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 3 with ContextParameterType

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

the class AddContextCommentValueMigrationTask method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    EList<ContextType> contexts = null;
    if (item instanceof ProcessItem) {
        // process, process_mr, process_storm, route, routelet.
        ProcessItem processItem = (ProcessItem) item;
        contexts = processItem.getProcess().getContext();
    } else if (item instanceof JobletProcessItem) {
        JobletProcessItem jobletItem = (JobletProcessItem) item;
        contexts = jobletItem.getJobletProcess().getContext();
    } else if (item instanceof ContextItem) {
        ContextItem contextItem = (ContextItem) item;
        contexts = contextItem.getContext();
    }
    // 2 kinds of situation should be excluded before doing migration to the old context:
    // 1.has null, 2.all same comment values;
    // 1 is from 6.1.0 release and 5.6.2 patched TPS-1109, all null comment value will set to "".
    // for repository context in job, won't change anything because the repository context has been fixed
    // the update action will execute when opening job.
    boolean hasNull = false, isSame = true;
    if (contexts != null && contexts.size() > 1) {
        List<String> firstComments = new ArrayList<String>();
        for (int x = 0; x < contexts.size(); x++) {
            List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
            for (int y = 0; y < contextParams.size(); y++) {
                ContextParameterType param = contextParams.get(y);
                boolean isBuiltin = param.getRepositoryContextId() == null;
                String comment = param.getComment();
                if (comment == null) {
                    if (isBuiltin) {
                        //$NON-NLS-1$
                        param.setComment("");
                        hasNull = true;
                    }
                    continue;
                }
                // comments to show in old item before 5.6.1 are always in the first group.
                if (x == 0) {
                    if (!isBuiltin) {
                        //$NON-NLS-1$
                        firstComments.add("NOT_BUILTIN");
                    } else {
                        firstComments.add(comment);
                    }
                    continue;
                }
                if (isBuiltin && !comment.equals(firstComments.get(y))) {
                    isSame = false;
                }
            }
        }
        try {
            if (hasNull) {
                ProxyRepositoryFactory.getInstance().save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
            if (!isSame) {
                for (int x = 1; x < contexts.size(); x++) {
                    List<ContextParameterType> contextParams = contexts.get(x).getContextParameter();
                    for (int y = 0; y < contextParams.size(); y++) {
                        ContextParameterType param = contextParams.get(y);
                        String comment = param.getComment();
                        if (param.getRepositoryContextId() == null && !firstComments.get(y).equals(comment)) {
                            if (!firstComments.get(y).equals("NOT_BUILTIN")) {
                                //$NON-NLS-1$
                                param.setComment(firstComments.get(y));
                            }
                        }
                    }
                }
                ProxyRepositoryFactory.getInstance().save(item, true);
                return ExecutionResult.SUCCESS_NO_ALERT;
            }
        } catch (PersistenceException e) {
            ExceptionHandler.process(e);
            return ExecutionResult.FAILURE;
        }
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ContextItem(org.talend.core.model.properties.ContextItem) ArrayList(java.util.ArrayList) ProcessItem(org.talend.core.model.properties.ProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) PersistenceException(org.talend.commons.exception.PersistenceException) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 4 with ContextParameterType

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

the class JobContextUtils method getContextParametersMapByGroup.

private static Map<String, String> getContextParametersMapByGroup(ProcessItem processItem, String contextGroup) {
    ProcessType process = processItem.getProcess();
    if (process != null && contextGroup != null) {
        EList<?> context = process.getContext();
        if (context != null) {
            for (Object next : context) {
                ContextType ct = (ContextType) next;
                if (ct.getName().equals(contextGroup)) {
                    Map<String, String> contextParams = new HashMap<String, String>();
                    EList<ContextParameterType> params = ct.getContextParameter();
                    for (ContextParameterType param : params) {
                        contextParams.put(param.getName(), param.getRawValue());
                    }
                    return contextParams;
                }
            }
        }
    }
    return Collections.emptyMap();
}
Also used : ContextType(org.talend.designer.core.model.utils.emf.talendfile.ContextType) ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) HashMap(java.util.HashMap) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Example 5 with ContextParameterType

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

the class JobScriptsExportWizardPage method finish.

// protected String getDestinationValueSU() {
//        return this.suDestinationFilePath != null ? this.suDestinationFilePath : ""; //$NON-NLS-1$
//
// }
/**
     * The Finish button was pressed. Try to do the required work now and answer a boolean indicating success. If false
     * is returned then the wizard will not close.
     * 
     * @returns boolean
     */
@Override
public boolean finish() {
    // TODO
    if (treeViewer != null) {
        treeViewer.removeCheckStateListener(checkStateListener);
    }
    saveWidgetValues();
    if (manager == null) {
        manager = createJobScriptsManager();
    }
    if (!ensureTargetIsValid()) {
        return false;
    }
    if (ensureLog4jSettingIsValid()) {
        MessageDialog dialog = new MessageDialog(getShell(), "Question", null, Messages.getString("Log4jSettingPage.IlleagalBuild"), MessageDialog.QUESTION, new String[] { IDialogConstants.YES_LABEL, IDialogConstants.NO_LABEL }, 0);
        dialog.open();
        int result = dialog.getReturnCode();
        if (result != MessageDialog.OK) {
            return false;
        }
    }
    JobExportType jobExportType = getCurrentExportType1();
    if (JobExportType.POJO.equals(jobExportType)) {
        IRunnableWithProgress worker = new IRunnableWithProgress() {

            @Override
            public void run(IProgressMonitor monitor) throws InvocationTargetException, InterruptedException {
                buildJobWithMaven(JobExportType.POJO, monitor);
            }
        };
        try {
            getContainer().run(false, true, worker);
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    } else {
        List<ContextParameterType> contextEditableResultValuesList = null;
        if (manager != null) {
            contextEditableResultValuesList = manager.getContextEditableResultValuesList();
        }
        if (nodes.length == 1) {
            RepositoryNode node = nodes[0];
            if (node.getType() == ENodeType.SYSTEM_FOLDER) {
                manager.setTopFolderName(ProjectManager.getInstance().getCurrentProject().getLabel());
            } else {
                manager.setTopFolderName(getDefaultFileNameWithType());
            }
        } else {
            manager.setTopFolderName(getDefaultFileNameWithType());
        }
        // for feature:11976, recover back the old default manager value with ContextParameters
        if (contextEditableResultValuesList == null) {
            manager.setContextEditableResultValuesList(new ArrayList<ContextParameterType>());
        } else {
            manager.setContextEditableResultValuesList(contextEditableResultValuesList);
        }
        manager.setMultiNodes(isMultiNodes());
        // achen modify to fix bug 0006222
        IRunnableWithProgress worker = new JobExportAction(Arrays.asList(getCheckNodes()), getSelectedJobVersion(), manager, originalRootFolderName, getProcessType());
        try {
            getContainer().run(false, true, worker);
        } catch (InvocationTargetException e) {
            MessageBoxExceptionHandler.process(e.getCause(), getShell());
            return false;
        } catch (InterruptedException e) {
            return false;
        }
    }
    // see bug 7181
    if (zipOption != null && zipOption.equals("true")) {
        // unzip
        try {
            String zipFile;
            if (manager != null) {
                zipFile = manager.getDestinationPath();
            } else {
                zipFile = getDestinationValue();
                int separatorIndex = zipFile.lastIndexOf(File.separator);
                if (separatorIndex == -1) {
                    //$NON-NLS-1$
                    String userDir = System.getProperty("user.dir");
                    zipFile = userDir + File.separator + zipFile;
                }
            }
            // Added by Marvin Wang on Feb.1, 2012 for bug TDI-18824
            File file = new File(zipFile);
            if (file.exists()) {
                ZipToFile.unZipFile(zipFile, file.getParentFile().getAbsolutePath());
            }
        } catch (Exception e) {
            MessageBoxExceptionHandler.process(e, getShell());
            return false;
        }
    }
    if (treeViewer != null) {
        treeViewer.dispose();
    }
    // end
    return true;
}
Also used : JobExportAction(org.talend.repository.ui.wizards.exportjob.action.JobExportAction) RepositoryNode(org.talend.repository.model.RepositoryNode) IRepositoryNode(org.talend.repository.model.IRepositoryNode) Point(org.eclipse.swt.graphics.Point) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) IOException(java.io.IOException) IRunnableWithProgress(org.eclipse.jface.operation.IRunnableWithProgress) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) JobExportType(org.talend.repository.ui.wizards.exportjob.JavaJobScriptsExportWSWizardPage.JobExportType) MessageDialog(org.eclipse.jface.dialogs.MessageDialog) ZipToFile(org.talend.repository.ui.utils.ZipToFile) File(java.io.File) ContextParameterType(org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)

Aggregations

ContextParameterType (org.talend.designer.core.model.utils.emf.talendfile.ContextParameterType)35 ContextType (org.talend.designer.core.model.utils.emf.talendfile.ContextType)27 ContextItem (org.talend.core.model.properties.ContextItem)11 ArrayList (java.util.ArrayList)8 PersistenceException (org.talend.commons.exception.PersistenceException)7 HashMap (java.util.HashMap)6 Test (org.junit.Test)6 ProcessItem (org.talend.core.model.properties.ProcessItem)5 EList (org.eclipse.emf.common.util.EList)4 List (java.util.List)3 JobContextManager (org.talend.core.model.context.JobContextManager)3 DatabaseConnection (org.talend.core.model.metadata.builder.connection.DatabaseConnection)3 JobletProcessItem (org.talend.core.model.properties.JobletProcessItem)3 Property (org.talend.core.model.properties.Property)3 File (java.io.File)2 IContext (org.talend.core.model.process.IContext)2 IContextParameter (org.talend.core.model.process.IContextParameter)2 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashSet (java.util.HashSet)1