use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class FixUnevenItemContextParametersMigrationTask method execute.
@SuppressWarnings("unchecked")
@Override
public ExecutionResult execute(Item item) {
EList<ContextType> contexts = null;
String defualtGroupName = null;
if (item instanceof ProcessItem) {
// process, process_mr, process_storm, route, routelet.
ProcessItem processItem = (ProcessItem) item;
contexts = processItem.getProcess().getContext();
defualtGroupName = processItem.getProcess().getDefaultContext();
} else if (item instanceof JobletProcessItem) {
JobletProcessItem jobletItem = (JobletProcessItem) item;
contexts = jobletItem.getJobletProcess().getContext();
defualtGroupName = jobletItem.getJobletProcess().getDefaultContext();
} else if (item instanceof ContextItem) {
ContextItem contextItem = (ContextItem) item;
contexts = contextItem.getContext();
defualtGroupName = contextItem.getDefaultContext();
}
try {
ContextType defaultGroup = null;
for (ContextType context : contexts) {
if (context.getName().equals(defualtGroupName)) {
defaultGroup = context;
break;
}
}
if (defaultGroup == null && contexts.size() > 0) {
defaultGroup = contexts.get(0);
}
boolean contextChanged = false;
if (defaultGroup != null) {
Map<String, ContextParameterType> paramMap = new HashMap<String, ContextParameterType>();
List<String> paramNameList = new ArrayList<String>();
paramMap.putAll(collectDefaultGroupParams(defaultGroup, paramNameList));
for (ContextType context : contexts) {
if (context == defaultGroup) {
continue;
}
Map<String, ContextParameterType> otherGroupParam = collectDefaultGroupParams(context, paramNameList);
for (String paramName : otherGroupParam.keySet()) {
if (!paramMap.containsKey(paramName)) {
paramMap.put(paramName, otherGroupParam.get(paramName));
}
}
}
// make sure all groups have the same param list
for (ContextType context : contexts) {
EList<ContextParameterType> params = context.getContextParameter();
List<String> paramNames = new ArrayList<String>(paramNameList);
for (ContextParameterType param : params) {
if (paramNames.contains(param.getName())) {
paramNames.remove(param.getName());
}
}
if (!paramNames.isEmpty()) {
contextChanged = true;
for (String paramToAdd : paramNames) {
ContextParameterType toAdd = paramMap.get(paramToAdd);
context.getContextParameter().add(EcoreUtil.copy(toAdd));
}
}
}
// change param order if needed
for (ContextType context : contexts) {
EList<ContextParameterType> params = context.getContextParameter();
List<ContextParameterType> copyOfParam = new ArrayList<ContextParameterType>(params);
for (int i = 0; i < copyOfParam.size(); i++) {
ContextParameterType param = copyOfParam.get(i);
int indexOf = paramNameList.indexOf(param.getName());
if (i != indexOf) {
contextChanged = true;
params.remove(param);
params.add(indexOf, param);
}
}
}
// make sure params in different groups have the same repository id and type as default group
for (ContextType context : contexts) {
EList<ContextParameterType> params = context.getContextParameter();
for (ContextParameterType param : params) {
ContextParameterType paramDefault = paramMap.get(param.getName());
if (!paramDefault.getType().equals(param.getType())) {
contextChanged = true;
param.setType(paramDefault.getType());
}
if (paramDefault.getRepositoryContextId() == null && param.getRepositoryContextId() != null || (paramDefault.getRepositoryContextId() != null && !paramDefault.getRepositoryContextId().equals(param.getRepositoryContextId()))) {
contextChanged = true;
param.setRepositoryContextId(paramDefault.getRepositoryContextId());
}
}
}
}
if (contextChanged) {
ProxyRepositoryFactory.getInstance().save(item, true);
return ExecutionResult.SUCCESS_NO_ALERT;
}
} catch (PersistenceException e) {
ExceptionHandler.process(e);
return ExecutionResult.FAILURE;
}
return ExecutionResult.NOTHING_TO_DO;
}
use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method updateRunJobContext.
protected void updateRunJobContext() {
final JobContextManager manager = (JobContextManager) getProcess().getContextManager();
if (manager.isModified()) {
final Map<String, String> nameMap = manager.getNameMap();
// gcui:add a progressDialog.
Shell shell = null;
Display display = PlatformUI.getWorkbench().getDisplay();
if (display != null) {
shell = display.getActiveShell();
}
if (shell == null) {
display = Display.getCurrent();
if (display == null) {
display = Display.getDefault();
}
if (display != null) {
shell = display.getActiveShell();
}
}
ProgressMonitorDialog progressDialog = new ProgressMonitorDialog(shell);
IRunnableWithProgress runnable = new IRunnableWithProgress() {
@Override
public void run(final IProgressMonitor monitor) {
//$NON-NLS-1$
monitor.beginTask(Messages.getString("AbstractMultiPageTalendEditor_pleaseWait"), IProgressMonitor.UNKNOWN);
Display.getDefault().syncExec(new Runnable() {
@Override
public void run() {
IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
factory.executeRepositoryWorkUnit(new //$NON-NLS-1$
RepositoryWorkUnit<Object>(//$NON-NLS-1$
"..", //$NON-NLS-1$
this) {
@Override
protected void run() throws LoginException, PersistenceException {
try {
IProxyRepositoryFactory factory = CorePlugin.getDefault().getProxyRepositoryFactory();
Set<String> curContextVars = getCurrentContextVariables(manager);
IProcess2 process2 = getProcess();
String jobId = process2.getProperty().getId();
IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
List<IProcess2> processes = CorePlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
// gcui:if nameMap is empty it do nothing.
if (!nameMap.isEmpty()) {
UpdateRunJobComponentContextHelper.updateItemRunJobComponentReference(factory, nameMap, jobId, curContextVars);
UpdateRunJobComponentContextHelper.updateOpenedJobRunJobComponentReference(processes, nameMap, jobId, curContextVars);
}
// add for bug 9564
List<IRepositoryViewObject> all = factory.getAll(ERepositoryObjectType.PROCESS, true);
List<ProcessItem> allProcess = new ArrayList<ProcessItem>();
for (IRepositoryViewObject repositoryObject : all) {
Item item = repositoryObject.getProperty().getItem();
if (item instanceof ProcessItem) {
ProcessItem processItem = (ProcessItem) item;
allProcess.add(processItem);
}
}
UpdateRunJobComponentContextHelper.updateRefJobRunJobComponentContext(factory, allProcess, process2);
} catch (PersistenceException e) {
// e.printStackTrace();
ExceptionHandler.process(e);
}
manager.setModified(false);
}
});
}
});
monitor.done();
if (monitor.isCanceled()) {
try {
//$NON-NLS-1$
throw new InterruptedException("Save Fail");
} catch (InterruptedException e) {
ExceptionHandler.process(e);
}
}
}
};
try {
progressDialog.run(true, true, runnable);
} catch (InvocationTargetException e1) {
ExceptionHandler.process(e1);
} catch (InterruptedException e1) {
ExceptionHandler.process(e1);
}
}
}
use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method covertJobscriptOnPageChange.
private void covertJobscriptOnPageChange() {
try {
boolean isDirty = jobletEditor.isDirty();
jobletEditor.doSave(null);
IProcess2 oldProcess = getProcess();
ICreateXtextProcessService n = CorePlugin.getDefault().getCreateXtextProcessService();
Item item = oldProcess.getProperty().getItem();
ProcessType processType = null;
if (item instanceof ProcessItem) {
processType = n.convertDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
} else if (item instanceof JobletProcessItem) {
processType = n.convertJobletDesignerEditorInput(((IFile) jobletEditor.getEditorInput().getAdapter(IResource.class)).getLocation().toOSString(), oldProcess.getProperty());
}
if (item instanceof ProcessItem) {
((Process) oldProcess).updateProcess(processType);
} else if (item instanceof JobletProcessItem) {
((Process) oldProcess).updateProcess(processType);
}
oldProcess.getUpdateManager().updateAll();
designerEditor.setDirty(isDirty);
List<Node> nodes = (List<Node>) oldProcess.getGraphicalNodes();
List<Node> newNodes = new ArrayList<Node>();
newNodes.addAll(nodes);
for (Node node : newNodes) {
node.getProcess().checkStartNodes();
node.checkAndRefreshNode();
IElementParameter ep = node.getElementParameter("ACTIVATE");
if (ep != null && ep.getValue().equals(Boolean.FALSE)) {
node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
} else if (ep != null && ep.getValue().equals(Boolean.TRUE)) {
node.setPropertyValue(EParameterName.ACTIVATE.getName(), false);
node.setPropertyValue(EParameterName.ACTIVATE.getName(), true);
}
for (IElementParameter param : node.getElementParameters()) {
if (!param.getChildParameters().isEmpty()) {
if (param.getValue() != null && param.getValue() instanceof String && ((String) param.getValue()).contains(":")) {
String[] splited = ((String) param.getValue()).split(":");
String childNameNeeded = splited[0].trim();
String valueChild = TalendQuoteUtils.removeQuotes(splited[1].trim());
if (param.getChildParameters().containsKey(childNameNeeded)) {
param.getChildParameters().get(childNameNeeded).setValue(valueChild);
}
}
}
}
if (node.getNodeContainer() instanceof JobletContainer) {
JobletContainer jc = (JobletContainer) node.getNodeContainer();
if (node.isMapReduceStart()) {
//$NON-NLS-1$
jc.updateState("UPDATE_STATUS", "", jc.getPercentMap(), jc.getPercentReduce());
}
}
}
} catch (PersistenceException e) {
}
}
use of org.talend.core.model.properties.ProcessItem 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);
}
}
use of org.talend.core.model.properties.ProcessItem in project tdi-studio-se by Talend.
the class AbstractMultiPageTalendEditor method generateCode.
/**
* DOC bqian Comment method "generateCode".
*/
protected void generateCode() {
final IProcess2 process = getProcess();
if (!(process.getProperty().getItem() instanceof ProcessItem)) {
// shouldn't work for joblet
return;
}
if (process.getGeneratingNodes().size() != 0) {
Job job = new //$NON-NLS-1$
AccessingEmfJob(//$NON-NLS-1$
"Generating code") {
@Override
protected IStatus doRun(IProgressMonitor monitor) {
try {
ProcessorUtilities.generateCode(process, process.getContextManager().getDefaultContext(), false, false, true, ProcessorUtilities.GENERATE_WITH_FIRST_CHILD);
} catch (ProcessorException e) {
ExceptionHandler.process(e);
}
return Status.OK_STATUS;
}
};
job.setUser(true);
job.setPriority(Job.BUILD);
// start as soon as possible
job.schedule();
}
}
Aggregations