Search in sources :

Example 11 with IContext

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

the class JavaProcessor method generateCode.

/*
     * Append the generated java code form context into java file wihtin the project. If the file not existed new one
     * will be created.
     * 
     * @see org.talend.designer.runprocess.IProcessor#generateCode(org.talend.core .model.process.IContext, boolean,
     * boolean, boolean)
     */
@Override
public void generateCode(boolean statistics, boolean trace, boolean javaProperties, int option) throws ProcessorException {
    super.generateCode(statistics, trace, javaProperties, option);
    try {
        // hywang modified for 6484
        String currentJavaProject = ProjectManager.getInstance().getProject(property).getTechnicalLabel();
        ICodeGenerator codeGen;
        ICodeGeneratorService service = RunProcessPlugin.getDefault().getCodeGeneratorService();
        if (javaProperties) {
            //$NON-NLS-1$
            String javaInterpreter = "";
            //$NON-NLS-1$
            String javaLib = "";
            String javaContext = getContextPath().toPortableString();
            codeGen = service.createCodeGenerator(process, statistics, trace, javaInterpreter, javaLib, javaContext, currentJavaProject);
        } else {
            codeGen = service.createCodeGenerator(process, statistics, trace);
        }
        // set the selected context. if don't find, will keep default
        if (!process.getContextManager().getDefaultContext().getName().equals(context.getName())) {
            boolean found = false;
            for (IContext c : process.getContextManager().getListContext()) {
                if (c.getName().equals(context.getName())) {
                    found = true;
                }
            }
            if (found) {
                codeGen.setContextName(context.getName());
            }
        }
        //$NON-NLS-1$
        String processCode = "";
        try {
            // must before codegen for job to set the rule flag.
            if (PluginChecker.isRulesPluginLoaded()) {
                IRulesProviderService rulesService = (IRulesProviderService) GlobalServiceRegister.getDefault().getService(IRulesProviderService.class);
                if (rulesService != null) {
                    boolean useGenerateRuleFiles = false;
                    List<? extends INode> allNodes = this.process.getGeneratingNodes();
                    for (int i = 0; i < allNodes.size(); i++) {
                        if (allNodes.get(i) instanceof INode) {
                            INode node = allNodes.get(i);
                            if (rulesService.isRuleComponent(node) && !node.getElementParameter(EParameterName.PROPERTY_TYPE.getName()).getValue().toString().equals("BUILT_IN")) {
                                //$NON-NLS-1$
                                useGenerateRuleFiles = true;
                                break;
                            }
                        }
                    }
                    if (useGenerateRuleFiles && rulesService != null && currentJavaProject != null) {
                        rulesService.generateFinalRuleFiles(currentJavaProject, this.process);
                        LastGenerationInfo.getInstance().setUseRules(this.process.getId(), this.process.getVersion(), true);
                    }
                }
            }
            processCode = codeGen.generateProcessCode();
        } catch (SystemException e) {
            //$NON-NLS-1$
            throw new ProcessorException(Messages.getString("Processor.generationFailed"), e);
        } catch (IOException e) {
            ExceptionHandler.process(e);
        }
        if (!BitwiseOptionUtils.containOption(option, TalendProcessOptionConstants.GENERATE_WITHOUT_FORMAT)) {
            processCode = doFormat(processCode);
        }
        // see feature 4610:option to see byte length of each code method
        processCode = computeMethodSizeIfNeeded(processCode);
        InputStream codeStream = new ByteArrayInputStream(processCode.getBytes());
        // Generating files
        IFile codeFile = this.getCodeProject().getFile(this.getSrcCodePath());
        if (!codeFile.exists()) {
            // in win.
            try {
                org.talend.commons.utils.io.FilesUtils.removeExistedResources(null, codeFile, true, true);
            } catch (Exception e) {
                throw new ProcessorException(e);
            }
            IFolder parentFolder = (IFolder) codeFile.getParent();
            if (!parentFolder.exists()) {
                parentFolder.create(true, true, null);
            }
            codeFile.create(codeStream, true, null);
        } else {
            codeFile.setContents(codeStream, true, false, null);
        }
        // codeFile.getProject().refreshLocal(IResource.DEPTH_INFINITE, null);
        processCode = null;
        // updateContextCode(codeGen);
        //$NON-NLS-1$
        codeFile.getProject().deleteMarkers("org.eclipse.jdt.debug.javaLineBreakpointMarker", true, IResource.DEPTH_INFINITE);
        List<INode> breakpointNodes = CorePlugin.getContext().getBreakpointNodes(process);
        if (!breakpointNodes.isEmpty()) {
            String[] nodeNames = new String[breakpointNodes.size()];
            int pos = 0;
            String nodeName;
            for (INode node : breakpointNodes) {
                nodeName = node.getUniqueName();
                if (node.getComponent().getMultipleComponentManagers().size() > 0) {
                    //$NON-NLS-1$
                    nodeName += "_" + node.getComponent().getMultipleComponentManagers().get(0).getInput().getName();
                }
                //$NON-NLS-1$ //$NON-NLS-2$
                nodeNames[pos++] = "[" + nodeName + " main ] start";
            }
            int[] lineNumbers = getLineNumbers(codeFile, nodeNames);
            setBreakpoints(codeFile, getMainClass(), lineNumbers);
        }
    } catch (CoreException e1) {
        if (e1.getStatus() != null && e1.getStatus().getException() != null) {
            ExceptionHandler.process(e1.getStatus().getException());
        }
        //$NON-NLS-1$
        throw new ProcessorException(Messages.getString("Processor.tempFailed"), e1);
    }
}
Also used : INode(org.talend.core.model.process.INode) IContext(org.talend.core.model.process.IContext) ProcessorException(org.talend.designer.runprocess.ProcessorException) IFile(org.eclipse.core.resources.IFile) IRulesProviderService(org.talend.core.ui.services.IRulesProviderService) BufferedInputStream(java.io.BufferedInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) Base64InputStream(org.apache.commons.codec.binary.Base64InputStream) ZipInputStream(java.util.zip.ZipInputStream) InflaterInputStream(java.util.zip.InflaterInputStream) FilterInputStream(java.io.FilterInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) IJavaBreakpoint(org.eclipse.jdt.debug.core.IJavaBreakpoint) IJavaLineBreakpoint(org.eclipse.jdt.debug.core.IJavaLineBreakpoint) CoreException(org.eclipse.core.runtime.CoreException) DebugException(org.eclipse.debug.core.DebugException) IOException(java.io.IOException) SystemException(org.talend.commons.exception.SystemException) ProcessorException(org.talend.designer.runprocess.ProcessorException) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ICodeGenerator(org.talend.designer.codegen.ICodeGenerator) SystemException(org.talend.commons.exception.SystemException) CoreException(org.eclipse.core.runtime.CoreException) ByteArrayInputStream(java.io.ByteArrayInputStream) IFolder(org.eclipse.core.resources.IFolder)

Example 12 with IContext

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

the class UpdateCheckResult method getName.

@Override
@SuppressWarnings("unchecked")
public String getName() {
    IUpdateItemType updateType = getUpdateType();
    String displayName = updateType.getDisplayLabel();
    if (updateType instanceof EUpdateItemType) {
        switch((EUpdateItemType) updateType) {
            case NODE_SCHEMA:
                if (getResultType() == EUpdateResult.RENAME) {
                    List<Object> param = (List<Object>) getParameter();
                    String[] oldSourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName((String) param.get(1));
                    String[] newSourceIdAndChildName = UpdateManagerUtils.getSourceIdAndChildName((String) param.get(2));
                    String display = UpdateManagerHelper.getRenamedDisplay(oldSourceIdAndChildName[1], newSourceIdAndChildName[1]);
                    if (display != null) {
                        displayName = display;
                    }
                } else if (getResultType() == EUpdateResult.DELETE) {
                    // table delete by deselect
                    List<Object> param = (List<Object>) getParameter();
                    String tableDeleted = (String) param.get(0);
                    EUpdateResult status = (EUpdateResult) param.get(1);
                    String display = getDeleteOrReloadDisplay(tableDeleted, status);
                    if (display != null) {
                        displayName = display;
                    }
                } else if (getResultType() == EUpdateResult.RELOAD) {
                    // table reload by deselect and reselect
                    List<Object> param = (List<Object>) getParameter();
                    String tableReload = (String) param.get(0);
                    EUpdateResult status = (EUpdateResult) param.get(1);
                    String display = getDeleteOrReloadDisplay(tableReload, status);
                    if (display != null) {
                        displayName = display;
                    }
                } else {
                    if (getUpdateObject() instanceof INode && getParameter() instanceof List && PluginChecker.isEBCDICPluginLoaded()) {
                        IEBCDICProviderService service = (IEBCDICProviderService) GlobalServiceRegister.getDefault().getService(IEBCDICProviderService.class);
                        if (service != null && service.isEbcdicNode((INode) getUpdateObject())) {
                            List<Object> paramObjs = (List<Object>) getParameter();
                            if (paramObjs.size() >= 2) {
                                Object schemaName = paramObjs.get(1);
                                if (schemaName instanceof String) {
                                    displayName = displayName + UpdateManagerUtils.addBrackets((String) schemaName);
                                }
                            }
                        }
                    }
                }
                break;
            case NODE_PROPERTY:
            case NODE_QUERY:
            case JOBLET_SCHEMA:
            case NODE_VALIDATION_RULE:
                break;
            case JOB_PROPERTY_EXTRA:
                displayName = displayName + UpdateManagerUtils.addBrackets(EComponentCategory.EXTRA.getTitle());
                break;
            case JOB_PROPERTY_STATS_LOGS:
                displayName = displayName + UpdateManagerUtils.addBrackets(EComponentCategory.STATSANDLOGS.getTitle());
                break;
            case JOB_PROPERTY_HEADERFOOTER:
                displayName = displayName + UpdateManagerUtils.addBrackets(EComponentCategory.HEADERFOOTER.getTitle());
                break;
            case CONTEXT_GROUP:
                if (getUpdateObject() != null && getUpdateObject() instanceof IContext) {
                    displayName = ((IContext) getUpdateObject()).getName();
                }
                break;
            case CONTEXT:
                // case JOBLET_CONTEXT:
                {
                    String display = null;
                    switch(getResultType()) {
                        case RENAME:
                            List<Object> param = (List<Object>) getParameter();
                            display = UpdateManagerHelper.getRenamedDisplay((String) param.get(1), (String) param.get(2));
                            break;
                        default:
                            if (getUpdateObject() instanceof Collection) {
                                display = UpdateManagerHelper.getCollectionsDisplay(getUpdateObject(), false);
                            }
                            break;
                    }
                    if (display != null) {
                        displayName = display;
                    }
                    break;
                }
            case JOBLET_RENAMED:
                {
                    List<Object> param = (List<Object>) getParameter();
                    String display = UpdateManagerHelper.getRenamedDisplay((String) param.get(1), (String) param.get(2));
                    if (display != null) {
                        displayName = display;
                    }
                    break;
                }
            case RELOAD:
            case JUNIT_RELOAD:
                if (getParameter() != null && getParameter() instanceof PropertyChangeEvent) {
                    PropertyChangeEvent event = (PropertyChangeEvent) getParameter();
                    // reload all compoennts.
                    if (event.getSource() != null && !(event.getSource() instanceof IProcess)) {
                        displayName = updateType.getDisplayLabel();
                        break;
                    }
                }
                break;
            default:
        }
        return displayName;
    } else {
        return UpdateManagerProviderDetector.INSTANCE.getResultName(this);
    }
}
Also used : EUpdateResult(org.talend.core.model.update.EUpdateResult) INode(org.talend.core.model.process.INode) PropertyChangeEvent(java.beans.PropertyChangeEvent) IContext(org.talend.core.model.process.IContext) EUpdateItemType(org.talend.core.model.update.EUpdateItemType) IEBCDICProviderService(org.talend.core.service.IEBCDICProviderService) Collection(java.util.Collection) IUpdateItemType(org.talend.core.model.update.IUpdateItemType) List(java.util.List) IProcess(org.talend.core.model.process.IProcess)

Example 13 with IContext

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

the class RepositoryService method exportPigudf.

/*
     * (non-Javadoc)
     * 
     * @see org.talend.repository.model.IRepositoryService#exportPigudf(org.talend.designer.runprocess.IProcessor,
     * org.talend.core.model.properties.Property, int, int)
     */
@Override
public String exportPigudf(IProcessor processor, Property property, boolean isExport) throws ProcessorException {
    // build java project
    CorePlugin.getDefault().getRunProcessService().buildJavaProject();
    Map<ExportChoice, Object> exportChoiceMap = new EnumMap<ExportChoice, Object>(ExportChoice.class);
    exportChoiceMap.put(ExportChoice.needPigudf, true);
    ProcessItem processItem = (ProcessItem) property.getItem();
    ExportFileResource fileResource = new ExportFileResource(processItem, property.getLabel());
    ExportFileResource[] exportFileResources = new ExportFileResource[] { fileResource };
    IContext context = processor.getContext();
    //$NON-NLS-1$
    String contextName = "Default";
    if (context != null) {
        contextName = context.getName();
    }
    JobScriptsManager jobScriptsManager = JobScriptsManagerFactory.createManagerInstance(exportChoiceMap, contextName, JobScriptsManager.ALL_ENVIRONMENTS, -1, -1, JobExportType.POJO);
    URL url = jobScriptsManager.getExportPigudfResources(exportFileResources);
    if (url == null) {
        return null;
    }
    File file = new File(url.getFile());
    // String librariesPath = LibrariesManagerUtils.getLibrariesPath(ECodeLanguage.JAVA) + "/";
    //$NON-NLS-1$
    String librariesPath = processor.getCodeProject().getLocation() + "/lib/";
    String targetFileName = JobJavaScriptsManager.USERPIGUDF_JAR;
    if (!isExport) {
        targetFileName = property.getLabel() + '_' + property.getVersion() + '_' + JobJavaScriptsManager.USERPIGUDF_JAR;
    }
    File target = new File(librariesPath + targetFileName);
    try {
        FilesUtils.copyFile(file, target);
    } catch (IOException e) {
        throw new ProcessorException(e.getMessage());
    }
    return targetFileName;
}
Also used : IContext(org.talend.core.model.process.IContext) JobScriptsManager(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager) ProcessorException(org.talend.designer.runprocess.ProcessorException) ExportChoice(org.talend.repository.ui.wizards.exportjob.scriptsmanager.JobScriptsManager.ExportChoice) IOException(java.io.IOException) URL(java.net.URL) ProcessItem(org.talend.core.model.properties.ProcessItem) ExportFileResource(org.talend.repository.documentation.ExportFileResource) JSONObject(org.talend.utils.json.JSONObject) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) SalesforceModuleRepositoryObject(org.talend.core.repository.model.repositoryObject.SalesforceModuleRepositoryObject) EnumMap(java.util.EnumMap) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 14 with IContext

use of org.talend.core.model.process.IContext 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 15 with IContext

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

the class ProcessContextComposite method promptConfirmLauch.

public static boolean promptConfirmLauch(Shell shell, IContext context, IProcess process) {
    boolean continueLaunch = true;
    int nbValues = 0;
    if (context == null) {
        //$NON-NLS-1$
        throw new IllegalArgumentException("Context is null");
    }
    // Prompt for context values ?
    for (IContextParameter parameter : context.getContextParameterList()) {
        if (parameter.isPromptNeeded()) {
            nbValues++;
        }
    }
    if (nbValues > 0) {
        IContext contextCopy = context.clone();
        PromptDialog promptDialog = new PromptDialog(shell, contextCopy);
        if (promptDialog.open() == PromptDialog.OK) {
            for (IContextParameter param : context.getContextParameterList()) {
                boolean found = false;
                IContextParameter paramCopy = null;
                for (int i = 0; i < contextCopy.getContextParameterList().size() & !found; i++) {
                    paramCopy = contextCopy.getContextParameterList().get(i);
                    if (param.getName().equals(paramCopy.getName())) {
                        // param.setValueList(paramCopy.getValueList());
                        param.setInternalValue(paramCopy.getValue());
                        found = true;
                    }
                }
            }
            contextComboViewer.refresh();
            contextTableViewer.refresh();
            processNeedGenCode(process);
        } else {
            continueLaunch = false;
        }
    } else {
        if (context.isConfirmationNeeded()) {
            continueLaunch = //$NON-NLS-1$
            MessageDialog.openQuestion(//$NON-NLS-1$
            shell, //$NON-NLS-1$
            Messages.getString("ProcessComposite.confirmTitle"), //$NON-NLS-1$ 
            Messages.getString("ProcessComposite.confirmText", context.getName()));
        }
        updateDefaultValueForListTypeParameter(context.getContextParameterList());
    }
    return continueLaunch;
}
Also used : IContext(org.talend.core.model.process.IContext) IContextParameter(org.talend.core.model.process.IContextParameter)

Aggregations

IContext (org.talend.core.model.process.IContext)46 IContextParameter (org.talend.core.model.process.IContextParameter)14 ArrayList (java.util.ArrayList)13 List (java.util.List)11 IProcess (org.talend.core.model.process.IProcess)10 ProcessorException (org.talend.designer.runprocess.ProcessorException)10 HashMap (java.util.HashMap)9 ProcessItem (org.talend.core.model.properties.ProcessItem)8 IOException (java.io.IOException)7 IElementParameter (org.talend.core.model.process.IElementParameter)7 IProcessor (org.talend.designer.runprocess.IProcessor)7 File (java.io.File)6 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IContextManager (org.talend.core.model.process.IContextManager)6 HashSet (java.util.HashSet)5 IRunnableWithProgress (org.eclipse.jface.operation.IRunnableWithProgress)5 IProcess2 (org.talend.core.model.process.IProcess2)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 Map (java.util.Map)4