Search in sources :

Example 1 with RoutinesParameterType

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

the class SetupProcessDependenciesRoutinesAction method createRoutinesDependencies.

private void createRoutinesDependencies(ProcessType process, List<RoutineItemRecord> routineRecords) {
    if (routineRecords == null) {
        return;
    }
    for (RoutineItemRecord r : routineRecords) {
        List<RoutinesParameterType> routinesDependencies = process.getParameters().getRoutinesParameter();
        boolean found = false;
        for (RoutinesParameterType type : routinesDependencies) {
            // if (r.isSystem() == type.isSystem()) {
            if (type.getId().equals(r.getId()) || type.getName().equals(r.getName())) {
                found = true;
                break;
            }
        // }
        }
        if (!found) {
            RoutinesParameterType itemRecordType = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
            itemRecordType.setName(r.getName());
            itemRecordType.setId(r.getId());
            process.getParameters().getRoutinesParameter().add(itemRecordType);
        }
    }
}
Also used : RoutineItemRecord(org.talend.designer.core.ui.routine.RoutineItemRecord) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType)

Example 2 with RoutinesParameterType

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

the class GenerateGrammarController method generateJavaFile.

/**
     * Generate java source file
     * 
     * DOC ytao Comment method "generateJavaFile".
     */
private void generateJavaFile() {
    Node node = (Node) elem;
    final String JOB_NAME = node.getProcess().getName().toLowerCase();
    final String COMPONENT_NAME = node.getUniqueName().toLowerCase();
    String javaClassName = StringUtils.capitalize(JOB_NAME) + StringUtils.capitalize(COMPONENT_NAME);
    ITDQItemService service = (ITDQItemService) GlobalServiceRegister.getDefault().getService(ITDQItemService.class);
    File fileCreated = null;
    try {
        fileCreated = service.fileCreatedInRoutines(node, javaClassName);
    } catch (Exception ex) {
        MessageDialog.openError(Display.getDefault().getActiveShell(), //$NON-NLS-1$
        Messages.getString("GenerateGrammarController.prompt"), ex.getMessage());
    }
    if (fileCreated == null) {
        return;
    }
    try {
        RoutineItem returnItem = persistInRoutine(new Path(JOB_NAME), fileCreated, javaClassName);
        addReferenceJavaFile(returnItem, true);
        // ADD (to line 292) xwang 2011-08-12 add routine dependency in job
        if (node.getProcess() instanceof org.talend.designer.core.ui.editor.process.Process) {
            RoutinesParameterType r = TalendFileFactory.eINSTANCE.createRoutinesParameterType();
            r.setId(returnItem.getProperty().getId());
            r.setName(returnItem.getProperty().getLabel());
            List<RoutinesParameterType> routines = new ArrayList<RoutinesParameterType>();
            routines.add(r);
            ((org.talend.designer.core.ui.editor.process.Process) node.getProcess()).addGeneratingRoutines(routines);
        }
        refreshProject();
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    // remove temporary files of grammar
    FilesUtils.removeFolder(new File(fileCreated.getParent()), true);
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) Node(org.talend.designer.core.ui.editor.nodes.Node) ArrayList(java.util.ArrayList) RoutineItem(org.talend.core.model.properties.RoutineItem) SystemException(org.talend.commons.exception.SystemException) IOException(java.io.IOException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) ITDQItemService(org.talend.core.ITDQItemService)

Example 3 with RoutinesParameterType

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

the class AddRoutineDependenciesMigrationTask method execute.

@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
    if (!(item instanceof ProcessItem)) {
        return ExecutionResult.NOTHING_TO_DO;
    }
    try {
        ProcessItem item2 = (ProcessItem) item;
        if (item2.getProcess().getParameters() == null || item2.getProcess().getParameters().getRoutinesParameter() == null) {
            ParametersType parameterType = TalendFileFactory.eINSTANCE.createParametersType();
            item2.getProcess().setParameters(parameterType);
        }
        List<RoutinesParameterType> routinesDependencies = (List<RoutinesParameterType>) item2.getProcess().getParameters().getRoutinesParameter();
        List<RoutinesParameterType> neededRoutineDependencies = new ArrayList<RoutinesParameterType>();
        neededRoutineDependencies.addAll(RoutinesUtil.createJobRoutineDependencies(true));
        neededRoutineDependencies.addAll(RoutinesUtil.createJobRoutineDependencies(false));
        boolean modified = false;
        for (RoutinesParameterType added : neededRoutineDependencies) {
            boolean found = false;
            for (RoutinesParameterType type : routinesDependencies) {
                if (added.getId().equals(type.getId()) || added.getName().equals(type.getName())) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                routinesDependencies.add(added);
                modified = true;
            }
        }
        if (modified) {
            CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory().save(item, true);
            RelationshipItemBuilder.getInstance().addOrUpdateItem(item, true);
            return ExecutionResult.SUCCESS_WITH_ALERT;
        }
    } catch (Exception e) {
        ExceptionHandler.process(e);
        return ExecutionResult.FAILURE;
    }
    return ExecutionResult.NOTHING_TO_DO;
}
Also used : ProcessItem(org.talend.core.model.properties.ProcessItem) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType)

Example 4 with RoutinesParameterType

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

the class AbstractMultiPageTalendEditor method codeSync.

private void codeSync() {
    IProcess2 process = getProcess();
    if (!(process.getProperty().getItem() instanceof ProcessItem)) {
        // shouldn't work for joblet
        return;
    }
    if (jobletEditor == getEditor(oldPageIndex)) {
        // added for routines code generated switch editor 0 to 3.
        ProcessItem processItem = (ProcessItem) process.getProperty().getItem();
        covertJobscriptOnPageChange();
        ParametersType parameters = processItem.getProcess().getParameters();
        if (parameters != null && parameters.getRoutinesParameter() != null && parameters.getRoutinesParameter().size() == 0) {
            try {
                List<RoutinesParameterType> dependenciesInPreference = RoutinesUtil.createDependenciesInPreference();
                parameters.getRoutinesParameter().addAll(dependenciesInPreference);
            } catch (PersistenceException e) {
                ExceptionHandler.process(e);
            }
        }
    }
    // if some code has been generated already, for the editor we should need only the main job, not the childs.
    try {
        boolean lastGeneratedWithStats = ProcessorUtilities.getLastGeneratedWithStats(process.getId());
        boolean lastGeneratedWithTrace = ProcessorUtilities.getLastGeneratedWithTrace(process.getId());
        if (processor.isCodeGenerated()) {
            ProcessorUtilities.generateCode(process, process.getContextManager().getDefaultContext(), lastGeneratedWithStats, lastGeneratedWithTrace, true, ProcessorUtilities.GENERATE_MAIN_ONLY);
        } else {
            ProcessorUtilities.generateCode(process, process.getContextManager().getDefaultContext(), lastGeneratedWithStats, lastGeneratedWithTrace, true, ProcessorUtilities.GENERATE_WITH_FIRST_CHILD);
        }
    } catch (ProcessorException e) {
        ExceptionHandler.process(e);
    }
}
Also used : ProcessorException(org.talend.designer.runprocess.ProcessorException) JobletProcessItem(org.talend.core.model.properties.JobletProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) IProcess2(org.talend.core.model.process.IProcess2) PersistenceException(org.talend.commons.exception.PersistenceException) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType)

Example 5 with RoutinesParameterType

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

the class NewProcessWizard method createProcessItem.

@SuppressWarnings("unchecked")
protected void createProcessItem() {
    try {
        property.setId(repositoryFactory.getNextId());
        // changed by hqzhang for TDI-19527, label=displayName
        property.setLabel(property.getDisplayName());
        ProcessType process = TalendFileFactory.eINSTANCE.createProcessType();
        ParametersType parameterType = TalendFileFactory.eINSTANCE.createParametersType();
        // add depended routines.
        List<RoutinesParameterType> dependenciesInPreference = RoutinesUtil.createDependenciesInPreference();
        parameterType.getRoutinesParameter().addAll(dependenciesInPreference);
        process.setParameters(parameterType);
        processItem.setProcess(process);
        repositoryFactory.create(processItem, mainPage.getDestinationPath());
    } catch (PersistenceException e) {
        MessageDialog.openError(getShell(), Messages.getString("NewProcessWizard.failureTitle"), //$NON-NLS-1$
        Messages.getString("NewProcessWizard.failureText") + " : " + //$NON-NLS-1$ //$NON-NLS-2$
        e.getMessage());
        ExceptionHandler.process(e);
    }
}
Also used : ProcessType(org.talend.designer.core.model.utils.emf.talendfile.ProcessType) RoutinesParameterType(org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType) PersistenceException(org.talend.commons.exception.PersistenceException) ParametersType(org.talend.designer.core.model.utils.emf.talendfile.ParametersType)

Aggregations

RoutinesParameterType (org.talend.designer.core.model.utils.emf.talendfile.RoutinesParameterType)11 ParametersType (org.talend.designer.core.model.utils.emf.talendfile.ParametersType)7 ArrayList (java.util.ArrayList)6 ProcessItem (org.talend.core.model.properties.ProcessItem)6 Path (org.eclipse.core.runtime.Path)4 RoutineItem (org.talend.core.model.properties.RoutineItem)4 ProcessType (org.talend.designer.core.model.utils.emf.talendfile.ProcessType)4 List (java.util.List)3 IPath (org.eclipse.core.runtime.IPath)3 PersistenceException (org.talend.commons.exception.PersistenceException)3 Project (org.talend.core.model.general.Project)3 Property (org.talend.core.model.properties.Property)3 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)3 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)3 File (java.io.File)2 IOException (java.io.IOException)2 IFile (org.eclipse.core.resources.IFile)2 SystemException (org.talend.commons.exception.SystemException)2 Node (org.talend.designer.core.ui.editor.nodes.Node)2 Collection (java.util.Collection)1