Search in sources :

Example 1 with ITalendSynchronizer

use of org.talend.designer.codegen.ITalendSynchronizer in project tdi-studio-se by Talend.

the class ImportItemUtil method getRoutineSynchronizer.

// private void applyMigrationTasks(ItemRecord itemRecord, IProgressMonitor monitor) {
// Context ctx = CorePlugin.getContext();
// RepositoryContext repositoryContext = (RepositoryContext) ctx.getProperty(Context.REPOSITORY_CONTEXT_KEY);
// ITalendSynchronizer routineSynchronizer = getRoutineSynchronizer();
//
// ERepositoryObjectType repositoryType = itemRecord.getRepositoryType();
//
// Item item = null;
// try {
// List<IRepositoryViewObject> allVersion = ProxyRepositoryFactory.getInstance().getAllVersion(
// ProjectManager.getInstance().getCurrentProject(), itemRecord.getItemId(), itemRecord.getImportPath(),
// repositoryType);
// for (IRepositoryViewObject repositoryObject : allVersion) {
// if (repositoryObject.getProperty().getVersion().equals(itemRecord.getItemVersion())) {
// item = repositoryObject.getProperty().getItem();
// }
// }
// } catch (Exception e) {
// logError(e);
// }
//
// if (item == null) {
// return;
// }
//
// List<IProjectMigrationTask> toExecute = new ArrayList<IProjectMigrationTask>();
// for (String taskId : itemRecord.getMigrationTasksToApply()) {
// IProjectMigrationTask task = GetTasksHelper.getInstance().getProjectTask(taskId);
// if (task == null) {
//                log.warn(Messages.getString("ImportItemUtil.taskLogWarn", taskId)); //$NON-NLS-1$
// } else if (!task.isDeprecated()) {
// toExecute.add(task);
// }
//
// }
// Collections.sort(toExecute, new Comparator<IProjectMigrationTask>() {
//
// public int compare(IProjectMigrationTask o1, IProjectMigrationTask o2) {
// return o1.getOrder().compareTo(o2.getOrder());
// }
// });
//
// IProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
//
// for (IProjectMigrationTask task : toExecute) {
//            monitor.subTask(Messages.getString("ImportItemUtil.taskMonitor", task.getName(), itemRecord.getItemName())); //$NON-NLS-1$
// try {
// // in case the resource has been modified (see MergeTosMetadataMigrationTask for example)
// if ((item.getProperty().eResource() == null || item.eResource() == null)) {
// Property updatedProperty = factory.reload(item.getProperty());
// item = updatedProperty.getItem();
// }
//
// if (item != null) {
// ExecutionResult executionResult = task.execute(repositoryContext.getProject(), item);
// if (executionResult == ExecutionResult.FAILURE) {
//                        log.warn(Messages.getString("ImportItemUtil.itemLogWarn", itemRecord.getItemName(), task.getName())); //$NON-NLS-1$
// // TODO smallet add a warning/error to the job using
// // model
// }
// }
// } catch (Exception e) {
//                log.warn(Messages.getString("ImportItemUtil.itemLogException", itemRecord.getItemName(), task.getName()), e); //$NON-NLS-1$
// try {
// factory.deleteObjectPhysical(new RepositoryObject(item.getProperty()));
// break;// stop migrating the object it has be deleted
// } catch (PersistenceException e1) {
// log.error("Could not delete physical item(" + item.getProperty().getLabel() + "), Project may be corrupted.",
// e);
// }
// }
// }
//
// try {
// if (item != null && item instanceof RoutineItem) {
// RoutineUtils.changeRoutinesPackage(item);
// RoutineItem routineItem = (RoutineItem) item;
// routineSynchronizer.forceSyncRoutine(routineItem);
// routineSynchronizer.syncRoutine(routineItem, true);
// routineSynchronizer.getFile(routineItem);
// }
// // if (item.getProperty().eResource().isModified()) {
// // ProxyRepositoryFactory.getInstance().save(item, true);
// // item.getProperty().eResource().setModified(false);
// // }
// if (item.getProperty().eResource() != null) {
// ProxyRepositoryFactory.getInstance().unloadResources(item.getProperty());
// if (item.getParent() != null && item.getParent() instanceof FolderItem) {
// ((FolderItem) item.getParent()).getChildren().remove(item);
// item.setParent(null);
// }
// }
//
// itemRecord.setExistingItemWithSameId(null);
// itemRecord.clear();
//
// } catch (Exception e) {
// logError(e);
// }
// }
private ITalendSynchronizer getRoutineSynchronizer() {
    ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
    ECodeLanguage lang = ((RepositoryContext) CorePlugin.getContext().getProperty(Context.REPOSITORY_CONTEXT_KEY)).getProject().getLanguage();
    ITalendSynchronizer routineSynchronizer = null;
    switch(lang) {
        case JAVA:
            routineSynchronizer = service.createJavaRoutineSynchronizer();
            break;
        case PERL:
            routineSynchronizer = service.createPerlRoutineSynchronizer();
            break;
        default:
            //$NON-NLS-1$
            throw new UnsupportedOperationException(Messages.getString("ImportItemUtil.unknowException", lang));
    }
    return routineSynchronizer;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ECodeLanguage(org.talend.core.language.ECodeLanguage)

Example 2 with ITalendSynchronizer

use of org.talend.designer.codegen.ITalendSynchronizer in project tdi-studio-se by Talend.

the class SaveAsRoutineAction method run.

@Override
public void run() {
    SaveAsRoutineWizard processWizard = new SaveAsRoutineWizard(editorPart);
    WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), processWizard);
    if (dlg.open() == Window.OK) {
        try {
            RoutineItem routineItem = processWizard.getRoutineItem();
            // get the IFile
            ICodeGeneratorService service = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
            ITalendSynchronizer routineSynchronizer = null;
            switch(LanguageManager.getCurrentLanguage()) {
                case JAVA:
                    routineSynchronizer = service.createJavaRoutineSynchronizer();
                    break;
                case PERL:
                    routineSynchronizer = service.createPerlRoutineSynchronizer();
                    break;
                default:
            }
            IFile file = routineSynchronizer.getFile(routineItem);
            if (file == null) {
                return;
            }
            // Set readonly to false since created job will always be editable.
            RoutineEditorInput routineEditorInput = new RoutineEditorInput(file, routineItem);
            IWorkbenchPage page = getActivePage();
            IRepositoryNode repositoryNode = RepositoryNodeUtilities.getRepositoryNode(routineEditorInput.getItem().getProperty().getId(), false);
            routineEditorInput.setRepositoryNode(repositoryNode);
            // here really do the normal save as function
            IDocumentProvider provider = ((AbstractTextEditor) this.editorPart).getDocumentProvider();
            provider.aboutToChange(routineEditorInput);
            provider.saveDocument(null, routineEditorInput, provider.getDocument(this.editorPart.getEditorInput()), true);
            provider.changed(routineEditorInput);
            // copy back from the *.java file to *.item file.
            // @see:StandAloneTalendJavaEditor.doSave(IProgressMonitor monitor)
            ByteArray byteArray = routineItem.getContent();
            byteArray.setInnerContentFromFile(routineEditorInput.getFile());
            IProxyRepositoryFactory repFactory = DesignerPlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
            repFactory.save(routineItem);
            // close the old editor
            page.closeEditor(this.editorPart, false);
            // open the new editor, because at the same time, there will update the jobSetting/componentSetting view
            switch(LanguageManager.getCurrentLanguage()) {
                case JAVA:
                    page.openEditor(routineEditorInput, StandAloneTalendJavaEditor.ID, true);
                    break;
                default:
            }
        } catch (Exception e) {
            MessageDialog.openError(Display.getCurrent().getActiveShell(), "Error", "Routine could not be saved" + " : " + e.getMessage());
            ExceptionHandler.process(e);
        }
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) IRepositoryNode(org.talend.repository.model.IRepositoryNode) RoutineItem(org.talend.core.model.properties.RoutineItem) RoutineEditorInput(org.talend.repository.ui.actions.routines.RoutineEditorInput) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) IDocumentProvider(org.eclipse.ui.texteditor.IDocumentProvider) AbstractTextEditor(org.eclipse.ui.texteditor.AbstractTextEditor) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) ByteArray(org.talend.core.model.properties.ByteArray) WizardDialog(org.eclipse.jface.wizard.WizardDialog) SaveAsRoutineWizard(org.talend.designer.core.ui.wizards.SaveAsRoutineWizard) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory)

Example 3 with ITalendSynchronizer

use of org.talend.designer.codegen.ITalendSynchronizer in project tdi-studio-se by Talend.

the class HTMLDocGenerator method generateSourceCodeInfo.

/**
     * DOC qwei Comment method "generateSourceCodeInfo".
     */
private void generateSourceCodeInfo(ProcessItem item, Element element) {
    if (CorePlugin.getDefault().getPreferenceStore().getBoolean(ITalendCorePrefConstants.DOC_GENERATESOURCECODE)) {
        IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
        IProcess process = service.getProcessFromProcessItem(item);
        IProcessor processor = ProcessorUtilities.getProcessor(process, null, process.getContextManager().getDefaultContext());
        // hidePasswordInSourceCode4Doc(process);
        try {
            processor.cleanBeforeGenerate(TalendProcessOptionConstants.CLEAN_JAVA_CODES | TalendProcessOptionConstants.CLEAN_CONTEXTS | TalendProcessOptionConstants.CLEAN_DATA_SETS);
            processor.generateCode(false, true, false);
        } catch (ProcessorException e) {
            ExceptionHandler.process(e);
        }
        //$NON-NLS-1$
        Element sourceCodeInfoElement = DocumentHelper.createElement("sourcecodes");
        ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        // StringBuffer componentsCode = new StringBuffer();
        try {
            IFile codeFile = synchronizer.getFile(item);
            if (codeFile == null) {
                return;
            }
            //$NON-NLS-1$
            String tempStr = "";
            InputStream in = codeFile.getContents();
            BufferedReader buffer = new BufferedReader(new InputStreamReader(in));
            while ((tempStr = buffer.readLine()) != null) {
                //$NON-NLS-1$
                Element codeElement = DocumentHelper.createElement("code");
                // componentsCode.append(tempStr).append("\n");
                //$NON-NLS-1$
                codeElement.addAttribute("content", tempStr);
                sourceCodeInfoElement.add(codeElement);
            }
            buffer.close();
            in.close();
        } catch (Exception e) {
            // TODO Auto-generated catch block
            // e.printStackTrace();
            ExceptionHandler.process(e);
        }
        element.add(sourceCodeInfoElement);
    }
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) ProcessorException(org.talend.designer.runprocess.ProcessorException) IFile(org.eclipse.core.resources.IFile) InputStreamReader(java.io.InputStreamReader) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Element(org.dom4j.Element) BufferedReader(java.io.BufferedReader) IDesignerCoreService(org.talend.designer.core.IDesignerCoreService) IProcessor(org.talend.designer.runprocess.IProcessor) IProcess(org.talend.core.model.process.IProcess) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) IOException(java.io.IOException) SAXException(org.xml.sax.SAXException) ProcessorException(org.talend.designer.runprocess.ProcessorException) MalformedURLException(java.net.MalformedURLException) PersistenceException(org.talend.commons.exception.PersistenceException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Example 4 with ITalendSynchronizer

use of org.talend.designer.codegen.ITalendSynchronizer in project tdi-studio-se by Talend.

the class OpenExistVersionProcessWizard method getEditorInput.

protected RepositoryEditorInput getEditorInput(final Item item, final boolean readonly, final IWorkbenchPage page) throws SystemException {
    if (item instanceof ProcessItem) {
        ProcessItem processItem = (ProcessItem) item;
        return new ProcessEditorInput(processItem, true, false, readonly);
    } else if (item instanceof BusinessProcessItem) {
        BusinessProcessItem businessProcessItem = (BusinessProcessItem) item;
        IFile file = CorePlugin.getDefault().getDiagramModelService().getDiagramFileAndUpdateResource(page, businessProcessItem);
        return new RepositoryEditorInput(file, businessProcessItem);
    } else if (item instanceof RoutineItem) {
        final RoutineItem routineItem = (RoutineItem) item;
        final ICodeGeneratorService codeGenService = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
        ITalendSynchronizer routineSynchronizer = codeGenService.createRoutineSynchronizer();
        ProxyRepositoryFactory factory = ProxyRepositoryFactory.getInstance();
        String lastVersion = factory.getLastVersion(routineItem.getProperty().getId()).getVersion();
        String curVersion = routineItem.getProperty().getVersion();
        routineSynchronizer.syncRoutine(routineItem, true, true);
        final IFile file;
        if (curVersion != null && curVersion.equals(lastVersion)) {
            file = routineSynchronizer.getFile(routineItem);
        } else {
            file = routineSynchronizer.getRoutinesFile(routineItem);
        }
        if (file != null) {
            return new RoutineEditorInput(file, routineItem);
        }
    } else if (item instanceof SQLPatternItem) {
        SQLPatternItem patternItem = (SQLPatternItem) item;
        final ICodeGeneratorService codeGenService = (ICodeGeneratorService) GlobalServiceRegister.getDefault().getService(ICodeGeneratorService.class);
        ISQLPatternSynchronizer SQLPatternSynchronizer = codeGenService.getSQLPatternSynchronizer();
        SQLPatternSynchronizer.syncSQLPattern(patternItem, true);
        IFile file = SQLPatternSynchronizer.getSQLPatternFile(patternItem);
        if (file != null) {
            return new RepositoryEditorInput(file, patternItem);
        }
    }
    return null;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) RepositoryEditorInput(org.talend.core.repository.ui.editor.RepositoryEditorInput) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ISQLPatternSynchronizer(org.talend.designer.codegen.ISQLPatternSynchronizer) RoutineItem(org.talend.core.model.properties.RoutineItem) SQLPatternItem(org.talend.core.model.properties.SQLPatternItem) RoutineEditorInput(org.talend.repository.ui.actions.routines.RoutineEditorInput) ProcessEditorInput(org.talend.designer.core.ui.editor.ProcessEditorInput) ICodeGeneratorService(org.talend.designer.codegen.ICodeGeneratorService) ProxyRepositoryFactory(org.talend.core.repository.model.ProxyRepositoryFactory) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) BusinessProcessItem(org.talend.core.model.properties.BusinessProcessItem) ProcessItem(org.talend.core.model.properties.ProcessItem)

Example 5 with ITalendSynchronizer

use of org.talend.designer.codegen.ITalendSynchronizer in project tdi-studio-se by Talend.

the class JobErrorsChecker method getErrors.

public static List<IContainerEntry> getErrors() {
    List<IContainerEntry> input = new ArrayList<IContainerEntry>();
    try {
        Item item = null;
        IProxyRepositoryFactory proxyRepositoryFactory = CorePlugin.getDefault().getRepositoryService().getProxyRepositoryFactory();
        ITalendSynchronizer synchronizer = CorePlugin.getDefault().getCodeGeneratorService().createRoutineSynchronizer();
        Set<String> jobIds = new HashSet<String>();
        for (JobInfo jobInfo : LastGenerationInfo.getInstance().getLastGeneratedjobs()) {
            // TDI-28198:get right process item no matter the job open or close
            List<IRepositoryViewObject> allVersions = proxyRepositoryFactory.getAllVersion(jobInfo.getJobId());
            for (IRepositoryViewObject repositoryObject2 : allVersions) {
                Property property2 = repositoryObject2.getProperty();
                if (jobInfo.getJobVersion().equals(property2.getVersion())) {
                    item = property2.getItem();
                    break;
                }
            }
            if (item == null) {
                continue;
            }
            // get source file
            IFile sourceFile = synchronizer.getFile(item);
            if (sourceFile == null) {
                continue;
            }
            jobIds.add(item.getProperty().getId());
            // Property property = process.getProperty();
            Problems.addJobRoutineFile(sourceFile, ProblemType.JOB, item, true);
        }
        if (!CommonsPlugin.isHeadless()) {
            List<IRepositoryViewObject> routinesObjects = proxyRepositoryFactory.getAll(ERepositoryObjectType.ROUTINES, false);
            Set<String> dependentRoutines = LastGenerationInfo.getInstance().getRoutinesNeededWithSubjobPerJob(LastGenerationInfo.getInstance().getLastMainJob().getJobId(), LastGenerationInfo.getInstance().getLastMainJob().getJobVersion());
            if (routinesObjects != null) {
                for (IRepositoryViewObject obj : routinesObjects) {
                    Property property = obj.getProperty();
                    if (dependentRoutines.contains(property.getLabel())) {
                        Item routinesitem = property.getItem();
                        IFile routineFile = synchronizer.getFile(routinesitem);
                        Problems.addJobRoutineFile(routineFile, ProblemType.ROUTINE, routinesitem, true);
                    } else {
                        Problems.clearAllComliationError(property.getLabel());
                    }
                }
            }
        }
        Problems.refreshProblemTreeView();
        // collect error
        List<Problem> errors = Problems.getProblemList().getProblemsBySeverity(ProblemStatus.ERROR);
        ErrorDetailTreeBuilder builder = new ErrorDetailTreeBuilder();
        input.addAll(builder.createTreeInput(errors, jobIds));
    } catch (Exception e) {
        ExceptionHandler.process(e);
    }
    return input;
}
Also used : ITalendSynchronizer(org.talend.designer.codegen.ITalendSynchronizer) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) CoreException(org.eclipse.core.runtime.CoreException) SystemException(org.talend.commons.exception.SystemException) PersistenceException(org.talend.commons.exception.PersistenceException) Item(org.talend.core.model.properties.Item) JobInfo(org.talend.core.model.process.JobInfo) IRepositoryViewObject(org.talend.core.model.repository.IRepositoryViewObject) TalendProblem(org.talend.core.model.process.TalendProblem) Problem(org.talend.core.model.process.Problem) IContainerEntry(org.talend.core.model.process.IContainerEntry) Property(org.talend.core.model.properties.Property) IProxyRepositoryFactory(org.talend.repository.model.IProxyRepositoryFactory) HashSet(java.util.HashSet)

Aggregations

ITalendSynchronizer (org.talend.designer.codegen.ITalendSynchronizer)13 IFile (org.eclipse.core.resources.IFile)11 ICodeGeneratorService (org.talend.designer.codegen.ICodeGeneratorService)7 CoreException (org.eclipse.core.runtime.CoreException)6 PersistenceException (org.talend.commons.exception.PersistenceException)6 SystemException (org.talend.commons.exception.SystemException)6 Item (org.talend.core.model.properties.Item)5 Property (org.talend.core.model.properties.Property)5 IRepositoryViewObject (org.talend.core.model.repository.IRepositoryViewObject)5 IProxyRepositoryFactory (org.talend.repository.model.IProxyRepositoryFactory)5 IMarker (org.eclipse.core.resources.IMarker)3 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)3 Problem (org.talend.core.model.process.Problem)3 TalendProblem (org.talend.core.model.process.TalendProblem)3 RoutineItem (org.talend.core.model.properties.RoutineItem)3 HashSet (java.util.HashSet)2 IEditorPart (org.eclipse.ui.IEditorPart)2 IEditorReference (org.eclipse.ui.IEditorReference)2 ECodeLanguage (org.talend.core.language.ECodeLanguage)2 IProcess (org.talend.core.model.process.IProcess)2