use of org.talend.core.model.context.JobContext 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.JobContext in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method checkAndAddContextVariables.
public static void checkAndAddContextVariables(ContextItem item, IContextManager contextManager, Set<String> addedVars, Set<String> contextGoupNameSet) {
EList context = item.getContext();
Map<String, List<ContextParameterTypeImpl>> map = new HashMap<String, List<ContextParameterTypeImpl>>();
Iterator iterator = context.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof ContextTypeImpl) {
ContextTypeImpl contextTypeImpl = (ContextTypeImpl) obj;
String name = contextTypeImpl.getName();
EList contextParameters = contextTypeImpl.getContextParameter();
Iterator contextParas = contextParameters.iterator();
List<ContextParameterTypeImpl> list = new ArrayList<ContextParameterTypeImpl>();
while (contextParas.hasNext()) {
ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
list.add(contextParameterType);
}
map.put(name, list);
}
}
if (map.isEmpty()) {
return;
}
String defaultContextName = item.getDefaultContext();
Set<String> existGroupNameSet = new HashSet<String>();
for (IContext con : contextManager.getListContext()) {
existGroupNameSet.add(con.getName());
}
if (contextGoupNameSet.isEmpty()) {
contextGoupNameSet.add(defaultContextName);
}
Set<String> alreadyUpdateNameSet = new HashSet<String>();
for (String key : map.keySet()) {
for (String groupName : contextGoupNameSet) {
boolean isExtraGroup = false;
for (String existGroup : existGroupNameSet) {
if (key.equals(existGroup)) {
isExtraGroup = true;
alreadyUpdateNameSet.add(existGroup);
break;
}
}
if (key.equals(groupName) || isExtraGroup) {
List<ContextParameterTypeImpl> list = map.get(key);
JobContext jobContext = new JobContext(key);
boolean isExistContext = false;
if (isExtraGroup) {
for (IContext con : contextManager.getListContext()) {
if (key.equals(con.getName())) {
if (con instanceof JobContext) {
jobContext = (JobContext) con;
isExistContext = true;
break;
}
}
}
}
setContextParameter(item, addedVars, list, jobContext);
if (!isExistContext) {
contextManager.getListContext().add(jobContext);
}
break;
}
}
}
// if job context group is not in current add's context,then update context group value to default group value
existGroupNameSet.removeAll(alreadyUpdateNameSet);
List<ContextParameterTypeImpl> list = map.get(defaultContextName);
if (list == null) {
return;
}
}
use of org.talend.core.model.context.JobContext in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method checkAndAddContextsVarDND.
/**
*
* wzhang Comment method "checkAndAddContextsVarDND".
*
* @param item
* @param contextManager
*/
public static void checkAndAddContextsVarDND(ContextItem item, IContextManager contextManager) {
EList context = item.getContext();
Map<String, List<ContextParameterTypeImpl>> map = new HashMap<String, List<ContextParameterTypeImpl>>();
Iterator iterator = context.iterator();
while (iterator.hasNext()) {
Object obj = iterator.next();
if (obj instanceof ContextTypeImpl) {
ContextTypeImpl contextTypeImpl = (ContextTypeImpl) obj;
String name = contextTypeImpl.getName();
EList contextParameters = contextTypeImpl.getContextParameter();
Iterator contextParas = contextParameters.iterator();
List<ContextParameterTypeImpl> list = new ArrayList<ContextParameterTypeImpl>();
while (contextParas.hasNext()) {
ContextParameterTypeImpl contextParameterType = (ContextParameterTypeImpl) contextParas.next();
list.add(contextParameterType);
}
map.put(name, list);
}
}
if (map.isEmpty()) {
return;
}
contextManager.getListContext().clear();
String defaultContextName = item.getDefaultContext();
for (String key : map.keySet()) {
List<ContextParameterTypeImpl> list = map.get(key);
JobContext jobContext = new JobContext(key);
for (ContextParameterTypeImpl contextImpl : list) {
JobContextParameter contextParam = new JobContextParameter();
ContextUtils.updateParameter(contextImpl, contextParam);
contextParam.setSource(item.getProperty().getId());
contextParam.setContext(jobContext);
jobContext.getContextParameterList().add(contextParam);
}
contextManager.getListContext().add(jobContext);
if (key.equals(defaultContextName)) {
contextManager.setDefaultContext(jobContext);
}
}
}
use of org.talend.core.model.context.JobContext in project tdi-studio-se by Talend.
the class PostgresGenerationManagerTest method testBuildSqlSelect.
@Test
public void testBuildSqlSelect() {
// without context
String schema = "school";
String main_table = "classInfo";
String lookup_table = "scoreInfo";
init(schema, main_table, lookup_table);
PostgresGenerationManager manager = new PostgresGenerationManager();
String query = manager.buildSqlSelect(component, "grade");
assertNotNull(query);
query = query.replaceAll("[\\s]", "");
String expectedQuery = "\"SELECT" + "\\\"school\\\".\\\"classInfo\\\".\\\"id\\\",\\\"school\\\".\\\"classInfo\\\".\\\"name\\\",\\\"school\\\".\\\"classInfo\\\".\\\"classNum\\\",\\\"school\\\".\\\"scoreInfo\\\".\\\"score\\\"" + "FROM\\\"school\\\".\\\"classInfo\\\",\\\"school\\\".\\\"scoreInfo\\\"" + "WHERE\\\"school\\\".\\\"classInfo\\\".\\\"id\\\"=3\"";
assertEquals(expectedQuery, query);
// with context
schema = "context.schema";
main_table = "context.main_table";
lookup_table = "context.lookup";
init(schema, main_table, lookup_table);
JobContext newContext = new JobContext("Default");
List<IContextParameter> newParamList = new ArrayList<IContextParameter>();
newContext.setContextParameterList(newParamList);
JobContextParameter param = new JobContextParameter();
param.setName("schema");
newParamList.add(param);
param = new JobContextParameter();
param.setName("main_table");
newParamList.add(param);
param = new JobContextParameter();
param.setName("lookup");
newParamList.add(param);
component.getProcess().getContextManager().setDefaultContext(newContext);
query = manager.buildSqlSelect(component, "grade");
query = query.replaceAll("[\\s]", "");
expectedQuery = "\"SELECT\"+context.schema+\".\"+context.main_table+\".\\\"id\\\",\"+context.schema+\".\"+" + "context.main_table+\".\\\"name\\\",\"+context.schema+\".\"+context.main_table+\".\\\"classNum\\\",\"+" + "context.schema+\".\"+context.lookup+\".\\\"score\\\"FROM\"+context.schema+\".\"+" + "context.main_table+\",\"+context.schema+\".\"+context.lookup+\"WHERE\"+context.schema+\".\"+" + "context.main_table+\".\\\"id\\\"=3\"";
assertEquals(expectedQuery, query);
}
Aggregations