use of org.talend.core.model.context.JobContextManager 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.context.JobContextManager in project tdi-studio-se by Talend.
the class PostgresGenerationManagerTest method init.
private void init(String schema, String main_table, String lookup_table) {
List<IConnection> incomingConnections = new ArrayList<IConnection>();
String[] mainTableEntities = new String[] { "id", "name", "classNum" };
String[] lookupEndtities = new String[] { "id", "score" };
incomingConnections.add(mockConnection(schema, main_table, mainTableEntities));
incomingConnections.add(mockConnection(schema, lookup_table, lookupEndtities));
component.setIncomingConnections(incomingConnections);
ExternalDbMapData externalData = new ExternalDbMapData();
List<ExternalDbMapTable> inputs = new ArrayList<ExternalDbMapTable>();
List<ExternalDbMapTable> outputs = new ArrayList<ExternalDbMapTable>();
// main table
ExternalDbMapTable inputTable = new ExternalDbMapTable();
inputTable.setTableName(schema + "." + main_table);
List<ExternalDbMapEntry> entities = getMetadataEntities(mainTableEntities, new String[3]);
inputTable.setMetadataTableEntries(entities);
inputs.add(inputTable);
// lookup table
inputTable = new ExternalDbMapTable();
inputTable.setTableName(schema + "." + lookup_table);
entities = getMetadataEntities(lookupEndtities, new String[2]);
inputTable.setMetadataTableEntries(entities);
inputs.add(inputTable);
// output
ExternalDbMapTable outputTable = new ExternalDbMapTable();
outputTable.setName("grade");
List<ExternalDbMapEntry> conditions = new ArrayList<ExternalDbMapEntry>();
conditions.add(new ExternalDbMapEntry(schema + "." + main_table + ".id =3"));
outputTable.setCustomWhereConditionsEntries(conditions);
String[] names = new String[] { "id", "name", "classNum", "score" };
String[] expressions = new String[] { schema + "." + main_table + ".id", schema + "." + main_table + ".name", schema + "." + main_table + ".classNum", schema + "." + lookup_table + ".score" };
outputTable.setMetadataTableEntries(getMetadataEntities(names, expressions));
outputs.add(outputTable);
externalData.setInputTables(inputs);
externalData.setOutputTables(outputs);
component.setExternalData(externalData);
List<IMetadataTable> metadataList = new ArrayList<IMetadataTable>();
MetadataTable metadataTable = getMetadataTable(names);
metadataTable.setLabel("grade");
metadataList.add(metadataTable);
component.setMetadataList(metadataList);
Process process = mock(Process.class);
when(process.getContextManager()).thenReturn(new JobContextManager());
component.setProcess(process);
}
use of org.talend.core.model.context.JobContextManager in project tdi-studio-se by Talend.
the class UpdateContextParameterCommand method doExecute.
private void doExecute() {
if (result == null) {
return;
}
Object job = result.getJob();
if (job == null) {
return;
}
if (job instanceof IProcess2) {
IProcess2 process = (IProcess2) job;
ContextParameterMap deleteParameters = new ContextParameterMap();
Object updateObject = result.getUpdateObject();
List<IContext> listContext = process.getContextManager().getListContext();
if (updateObject instanceof Set) {
Set<String> names = (Set<String>) updateObject;
if (result.getResultType() == EUpdateResult.ADD && result.isChecked()) {
// check parameters that have been added to repository context group
checkNewRepositoryParameters(process, names);
return;
}
for (IContext context : listContext) {
for (IContextParameter param : context.getContextParameterList()) {
ContextItem item = null;
if (names != null && names.contains(param.getName())) {
switch(result.getResultType()) {
case DELETE:
item = (ContextItem) result.getParameter();
if (item != null && item.getProperty().getId().equals(param.getSource()) && result.isChecked()) {
// delete it later
deleteParameters.addParameter(context, param);
} else {
param.setSource(IContextParameter.BUILT_IN);
}
break;
case UPDATE:
item = (ContextItem) result.getParameter();
if (item != null && item.getProperty().getId().equals(param.getSource()) && result.isChecked()) {
ContextUtils.updateParameterFromRepository(item, param, context.getName());
} else {
param.setSource(IContextParameter.BUILT_IN);
}
break;
case RENAME:
List<Object> parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 3) {
item = (ContextItem) parameter.get(0);
String sourceId = item.getProperty().getId();
String oldName = (String) parameter.get(1);
String newName = (String) parameter.get(2);
if (oldName.equals(param.getName()) && sourceId.equals(param.getSource())) {
if (newName != null) {
param.setName(newName);
ContextUtils.updateParameterFromRepository(item, param, context.getName());
}
}
}
break;
// built-in
case BUIL_IN:
default:
param.setSource(IContextParameter.BUILT_IN);
break;
}
}
}
}
}
if (updateObject instanceof JobContext) {
if (result.getResultType() == EUpdateResult.ADD && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
IContext context = (IContext) updateObject;
String name = context.getName();
if (!listContext.contains(context) && result.getParameter() instanceof ContextItem) {
ContextItem item = (ContextItem) result.getParameter();
JobContext newContext = new JobContext(name);
List<IContextParameter> newParamList = new ArrayList<IContextParameter>();
newContext.setContextParameterList(newParamList);
JobContextParameter param = null;
// add other context params to the new group
for (IContextParameter contextParam : process.getContextManager().getDefaultContext().getContextParameterList()) {
boolean exist = false;
for (IContextParameter existParam : context.getContextParameterList()) {
if (contextParam.getName().equals(existParam.getName())) {
exist = true;
}
}
if (exist) {
continue;
}
param = (JobContextParameter) contextParam.clone();
param.setContext(newContext);
newParamList.add(param);
}
// current context params for the new group
for (int i = 0; i < context.getContextParameterList().size(); i++) {
IContextParameter oldParam = context.getContextParameterList().get(i);
param = (JobContextParameter) oldParam.clone();
param.setSource(item.getProperty().getId());
param.setContext(newContext);
newParamList.add(param);
}
listContext.add(newContext);
}
} else if (result.getResultType() == EUpdateResult.DELETE && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
IContext context = (IContext) updateObject;
if (result.getParameter() instanceof ContextItem) {
ContextItem item = (ContextItem) result.getParameter();
List<IContext> listC = new ArrayList<IContext>(listContext);
for (IContext con : listC) {
if (con.getName().equals(context.getName())) {
for (IContextParameter oldParam : con.getContextParameterList()) {
if (item.getProperty().getId().equals(oldParam.getSource())) {
listContext.remove(con);
}
}
}
}
}
return;
} else if (result.getResultType() == EUpdateResult.RENAME && result.getUpdateType() == EUpdateItemType.CONTEXT_GROUP && result.isChecked()) {
IContext context = (IContext) updateObject;
IContextManager contextManager = process.getContextManager();
Map<IContext, String> renameGroupContext = ((JobContextManager) contextManager).getRenameGroupContext();
String oldName = renameGroupContext.get(context);
if (result.getParameter() instanceof ContextItem) {
ContextItem item = (ContextItem) result.getParameter();
for (IContext con : listContext) {
if (con.getName().equals(oldName)) {
for (IContextParameter oldParam : con.getContextParameterList()) {
if (item.getProperty().getId().equals(oldParam.getSource())) {
con.setName(context.getName());
}
}
}
}
}
}
return;
}
// delete parameters
deleteParameters.removeFromContext();
// update parameters
if (result.getResultType() == EUpdateResult.RENAME) {
List<Object> parameter = (List<Object>) result.getParameter();
if (parameter.size() >= 3) {
String oldName = (String) parameter.get(1);
String newName = (String) parameter.get(2);
UpdateContextVariablesHelper.updateProcessForRenamed(process, oldName, newName);
// tRunJob parameters rename
IEditorReference[] reference = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
List<IProcess2> processes = RepositoryPlugin.getDefault().getDesignerCoreService().getOpenedProcess(reference);
Map<String, String> renamedMap = new HashMap<String, String>();
renamedMap.put(newName, oldName);
UpdateRunJobComponentContextHelper.updateOpenedJobRunJobComponentReference(processes, renamedMap, process.getId(), null);
try {
// perhaps, need optimize.
UpdateRunJobComponentContextHelper.updateItemRunJobComponentReference(DesignerPlugin.getDefault().getProxyRepositoryFactory(), renamedMap, process.getId(), null);
} catch (PersistenceException e) {
ExceptionHandler.process(e);
}
}
}
}
}
use of org.talend.core.model.context.JobContextManager in project tdi-studio-se by Talend.
the class GenericContextHandler method exportContext.
@Override
public boolean exportContext(ConnectionItem connectionItem) {
boolean isContextMode = connectionItem.getConnection().isContextMode();
if (isContextMode) {
ConnectionContextHelper.openInConetxtModeDialog();
} else {
String defaultContextName = ConnectionContextHelper.convertContextLabel(connectionItem.getProperty().getLabel());
if (StringUtils.isEmpty(defaultContextName)) {
//$NON-NLS-1$ //$NON-NLS-2$
MessageDialog.openError(DisplayUtils.getDefaultShell(), Messages.getString("GenericContextHandler.wizardTitle"), Messages.getString("GenericContextHandler.defineConnectionName"));
}
Set<IConnParamName> contextParams = getContextParams();
Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableModels = ConnectionContextHelper.exportAsContext(defaultContextName, connectionItem, contextParams);
if (variableModels != null) {
Iterator<ContextItem> contextItor = variableModels.keySet().iterator();
while (contextItor.hasNext()) {
ContextItem contextItem = contextItor.next();
List<ConectionAdaptContextVariableModel> apaptModels = variableModels.get(contextItem);
if (contextItem != null && apaptModels.size() == 0) {
// create
if (ConnectionContextHelper.contextManager instanceof JobContextManager) {
Map<String, String> map = ((JobContextManager) ConnectionContextHelper.contextManager).getNameMap();
// set properties for context mode
ConnectionContextHelper.setPropertiesForContextMode(defaultContextName, connectionItem, contextItem, contextParams, map);
}
} else {
// set properties for exist context
ConnectionContextHelper.setPropertiesForExistContextMode(connectionItem, contextParams, variableModels);
}
}
}
return true;
}
return false;
}
use of org.talend.core.model.context.JobContextManager in project tdi-studio-se by Talend.
the class AbstractJSONStepForm method exportAsContext.
/*
* (non-Javadoc)
*
* @see org.talend.repository.ui.swt.utils.AbstractForm#exportAsContext()
*/
@Override
protected void exportAsContext() {
if (hasContextBtn() && connectionItem != null) {
if (isContextMode()) {
JSONConnectionContextHelper.openInConetxtModeDialog();
} else {
Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableModels = JSONConnectionContextHelper.exportAsContext(connectionItem, getConetxtParams());
contextManager = JSONConnectionContextHelper.contextManager;
if (variableModels != null) {
Iterator<ContextItem> contextItor = variableModels.keySet().iterator();
while (contextItor.hasNext()) {
ContextItem contextItem = contextItor.next();
List<ConectionAdaptContextVariableModel> apaptModels = variableModels.get(contextItem);
if (contextItem != null && apaptModels.size() == 0) {
// create
if (contextManager instanceof JobContextManager) {
Map<String, String> map = ((JobContextManager) contextManager).getNameMap();
// set properties for context mode
JSONConnectionContextHelper.setPropertiesForContextMode(connectionItem, contextItem, getConetxtParams(), map);
}
} else {
// set properties for exist context
JSONConnectionContextHelper.setPropertiesForExistContextMode(connectionItem, getConetxtParams(), variableModels);
}
// refresh current UI.
initialize();
adaptFormToEditable();
}
}
}
}
}
Aggregations