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;
}
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);
}
}
}
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);
}
}
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;
}
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;
}
Aggregations