use of org.talend.core.model.context.JobContextParameter in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method createParameters.
static void createParameters(List<IContextParameter> varList, String paramName, String value, JavaType type) {
if (varList == null || paramName == null) {
return;
}
if (value == null) {
value = EMPTY;
}
JobContextParameter contextParam = new JobContextParameter();
contextParam.setName(paramName);
switch(LanguageManager.getCurrentLanguage()) {
case JAVA:
if (type == null) {
contextParam.setType(MetadataTalendType.getDefaultTalendType());
} else {
contextParam.setType(type.getId());
}
break;
case PERL:
default:
if (type != null) {
if (type == JavaTypesManager.DIRECTORY) {
contextParam.setType(ContextParameterJavaTypeManager.PERL_DIRECTORY);
break;
} else if (type == JavaTypesManager.FILE) {
contextParam.setType(ContextParameterJavaTypeManager.PERL_FILE);
break;
} else if (type == JavaTypesManager.INTEGER) {
// int
contextParam.setType(MetadataTalendType.getPerlTypes()[3]);
break;
} else if (type == JavaTypesManager.PASSWORD) {
contextParam.setType(ContextParameterJavaTypeManager.PERL_PASSWORD);
break;
}
}
// string
contextParam.setType(MetadataTalendType.getPerlTypes()[5]);
break;
}
//$NON-NLS-1$
contextParam.setPrompt(paramName + "?");
if (value != null) {
contextParam.setValue(value);
}
contextParam.setComment(EMPTY);
varList.add(contextParam);
}
use of org.talend.core.model.context.JobContextParameter in project tdi-studio-se by Talend.
the class ContextParameterExtractor method buildParameterFrom.
private static IContextParameter buildParameterFrom(final Control text, final IContextManager manager, final String parameterName) {
//$NON-NLS-1$
String nameProposal = "";
if (text instanceof Text) {
nameProposal = ((Text) text).getSelectionText();
if (nameProposal.length() == 0) {
nameProposal = ((Text) text).getText();
}
} else {
if (text instanceof StyledText) {
nameProposal = ((StyledText) text).getSelectionText();
if (nameProposal.length() == 0) {
nameProposal = ((StyledText) text).getText();
}
}
}
if (LanguageManager.getCurrentLanguage().equals(ECodeLanguage.JAVA)) {
nameProposal = TalendTextUtils.removeQuotes(nameProposal);
}
String value = nameProposal;
if (ContextParameterUtils.containContextVariables(value)) {
//$NON-NLS-1$
MessageDialog.openError(//$NON-NLS-1$
new Shell(), //$NON-NLS-1$
Messages.getString("ContextParameterExtractor.ExistedTitle"), //$NON-NLS-1$
Messages.getString("ContextParameterExtractor.ExistedMessages"));
return null;
}
//$NON-NLS-1$ //$NON-NLS-2$
nameProposal = nameProposal.replace(" ", "_");
IContextParameter parameter = new JobContextParameter();
if (manager.checkValidParameterName(null, parameterName)) {
parameter.setName(parameterName);
} else if (manager.checkValidParameterName(null, nameProposal)) {
parameter.setName(nameProposal);
} else {
//$NON-NLS-1$
parameter.setName("");
}
ECodeLanguage curLanguage = LanguageManager.getCurrentLanguage();
if (curLanguage == ECodeLanguage.PERL) {
parameter.setType(MetadataTalendType.getDefaultTalendType());
} else {
parameter.setType(JavaTypesManager.getDefaultJavaType().getId());
}
//$NON-NLS-1$
parameter.setPrompt(parameterName + "?");
//$NON-NLS-1$
parameter.setComment("");
parameter.setValue(value);
return parameter;
}
use of org.talend.core.model.context.JobContextParameter 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.JobContextParameter in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method setContextParameter.
public static void setContextParameter(ContextItem item, Set<String> addedVars, List<ContextParameterTypeImpl> list, JobContext jobContext) {
for (ContextParameterTypeImpl contextImpl : list) {
for (String var : addedVars) {
if (var.equals(contextImpl.getName())) {
JobContextParameter contextParam = new JobContextParameter();
ContextUtils.updateParameter(contextImpl, contextParam);
contextParam.setSource(item.getProperty().getId());
contextParam.setContext(jobContext);
jobContext.getContextParameterList().add(contextParam);
}
}
}
}
use of org.talend.core.model.context.JobContextParameter 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);
}
}
}
Aggregations