use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class ContextModifyCommand method propagateType.
private void propagateType(IContextManager contextManager, IContextParameter param) {
for (IContext context : contextManager.getListContext()) {
IContextParameter paramToModify = context.getContextParameter(param.getName());
paramToModify.setType(param.getType());
}
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class JavaProcessUtil method findMoreLibraries.
/**
* DOC YeXiaowei Comment method "findMoreLibraries".
*
* @param neededLibraries
* @param curParam
*/
public static void findMoreLibraries(final IProcess process, List<ModuleNeeded> modulesNeeded, IElementParameter curParam) {
Object value = curParam.getValue();
String name = curParam.getName();
if (name.equals("DRIVER_JAR")) {
// added for bug 13592. new parameter DRIVER_JAR was used for jdbc connection
if (value != null && value instanceof List) {
List list = (List) value;
for (int i = 0; i < list.size(); i++) {
if (list.get(i) instanceof HashMap) {
// JAR_NAME
HashMap map = (HashMap) list.get(i);
//$NON-NLS-1$
Object object = map.get("JAR_NAME");
if (object != null && object instanceof String) {
String driverName = (String) object;
if (driverName != null && !"".equals(driverName)) {
//$NON-NLS-1$
boolean isContextMode = ContextParameterUtils.containContextVariables(driverName);
if (isContextMode) {
getModulesInTable(process, curParam, modulesNeeded);
} else {
ModuleNeeded module = new ModuleNeeded(null, driverName, null, true);
modulesNeeded.add(module);
}
}
}
}
}
}
} else if (name.equals("DB_VERSION")) {
//$NON-NLS-1$
String jdbcName = (String) value;
if (jdbcName != null) {
String jars = //$NON-NLS-1$
(jdbcName).replaceAll(TalendTextUtils.QUOTATION_MARK, "").replaceAll(TalendTextUtils.SINGLE_QUOTE, //$NON-NLS-1$
"");
//$NON-NLS-1$
String separator = ";";
if (jars.contains(separator)) {
for (String jar : jars.split(separator)) {
if (!jar.contains(".")) {
//$NON-NLS-1$
continue;
}
ModuleNeeded module = new ModuleNeeded(null, jar, null, true);
modulesNeeded.add(module);
}
} else if (jars.contains(".")) {
//$NON-NLS-1$
ModuleNeeded module = new ModuleNeeded(null, jars, null, true);
modulesNeeded.add(module);
}
}
} else if (name.equals("HOTLIBS")) {
//$NON-NLS-1$
List<Map<String, Object>> tableValues = (List<Map<String, Object>>) value;
Object[] listItemsValue = curParam.getListItemsValue();
for (Map<String, Object> line : tableValues) {
//$NON-NLS-1$
Object libPath = line.get("LIBPATH");
if (libPath == null) {
continue;
}
String text = null;
if (libPath instanceof String && !StringUtils.isEmpty((String) libPath)) {
text = (String) libPath;
} else if (libPath instanceof Integer && listItemsValue != null) {
int index = ((Integer) libPath).intValue();
if (index > -1 && index < listItemsValue.length && listItemsValue[index] != null) {
if (listItemsValue[index] instanceof IElementParameter) {
text = (String) ((IElementParameter) listItemsValue[index]).getValue();
} else {
text = listItemsValue[index].toString();
}
}
}
if (text != null && text.contains(".")) {
//$NON-NLS-1$
boolean isContextMode = ContextParameterUtils.containContextVariables(text);
if (isContextMode) {
List<IContext> listContext = process.getContextManager().getListContext();
String var = ContextParameterUtils.getVariableFromCode(text);
for (IContext context : listContext) {
List<IContextParameter> contextParameterList = context.getContextParameterList();
for (IContextParameter contextPara : contextParameterList) {
String paramName = contextPara.getName();
if (var.equals(paramName)) {
ModuleNeeded module = getModuleNeededForContextParam(contextPara);
if (module != null && !modulesNeeded.contains(module)) {
module.setDynamic(true);
modulesNeeded.add(module);
}
}
}
}
} else {
ModuleNeeded module = new ModuleNeeded(null, TalendTextUtils.removeQuotes(text), null, true);
module.setDynamic(true);
modulesNeeded.add(module);
}
}
}
} else if (name.equals(EParameterName.HADOOP_CUSTOM_JARS.getDisplayName())) {
String jarsName = (String) value;
if (StringUtils.isNotEmpty(jarsName)) {
String jars = //$NON-NLS-1$
jarsName.replaceAll(TalendTextUtils.QUOTATION_MARK, "").replaceAll(TalendTextUtils.SINGLE_QUOTE, //$NON-NLS-1$
"");
//$NON-NLS-1$
String separator = ";";
for (String jar : jars.split(separator)) {
ModuleNeeded module = new ModuleNeeded(null, jar, null, true);
modulesNeeded.add(module);
}
}
}
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class JavaProcessUtil method getModulesInTable.
private static void getModulesInTable(final IProcess process, IElementParameter curParam, List<ModuleNeeded> modulesNeeded) {
if (!(curParam.getValue() instanceof List)) {
return;
}
List<Map<String, Object>> values = (List<Map<String, Object>>) curParam.getValue();
if (values != null && !values.isEmpty()) {
Object[] listItemsValue = curParam.getListItemsValue();
if (listItemsValue != null && listItemsValue.length > 0 && listItemsValue[0] instanceof IElementParameter) {
for (Object o : listItemsValue) {
IElementParameter param = (IElementParameter) o;
if (param.getFieldType() == EParameterFieldType.MODULE_LIST) {
for (Map<String, Object> line : values) {
String moduleName = (String) line.get(param.getName());
if (moduleName != null && !"".equals(moduleName)) {
//$NON-NLS-1$
boolean isContextMode = ContextParameterUtils.containContextVariables(moduleName);
if (isContextMode) {
List<IContext> listContext = process.getContextManager().getListContext();
for (IContext context : listContext) {
List<IContextParameter> contextParameterList = context.getContextParameterList();
for (IContextParameter contextPara : contextParameterList) {
String var = ContextParameterUtils.getVariableFromCode(moduleName);
if (var.equals(contextPara.getName())) {
String value = context.getContextParameter(contextPara.getName()).getValue();
if (curParam.getName().equals(EParameterName.DRIVER_JAR.getName()) && value.contains(";")) {
//$NON-NLS-1$
//$NON-NLS-1$
String[] jars = value.split(";");
for (String jar2 : jars) {
String jar = jar2;
//$NON-NLS-1$
jar = jar.substring(jar.lastIndexOf("\\") + 1);
ModuleNeeded module = new ModuleNeeded(null, jar, null, true);
modulesNeeded.add(module);
}
} else {
//$NON-NLS-1$
value = value.substring(value.lastIndexOf("\\") + 1);
ModuleNeeded module = new ModuleNeeded(null, value, null, true);
modulesNeeded.add(module);
}
}
}
}
} else {
ModuleNeeded mn = getModuleValue(process, moduleName);
if (line.get("JAR_NEXUS_VERSION") != null) {
String a = moduleName.replaceFirst("[.][^.]+$", "");
mn.setMavenUri("mvn:org.talend.libraries/" + a + "/" + line.get("JAR_NEXUS_VERSION") + "/jar");
}
modulesNeeded.add(mn);
}
}
}
}
}
}
}
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class ContextParameterPage method setParameter.
public void setParameter(IContextParameter contextParameter, List<? extends IContext> contexts) {
this.parameter = contextParameter;
existingParameterNames = new HashSet<String>();
for (IContext context : contexts) {
for (IContextParameter ctxPrm : context.getContextParameterList()) {
existingParameterNames.add(ctxPrm.getName());
}
}
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class TableController method updateContextList.
private void updateContextList(IElementParameter param) {
List<String> contextParameterNamesList = new ArrayList<String>();
IElementParameter processTypeParam = elem.getElementParameterFromField(EParameterFieldType.PROCESS_TYPE);
if (processTypeParam == null) {
processTypeParam = elem.getElementParameterFromField(EParameterFieldType.ROUTE_INPUT_PROCESS_TYPE);
if (processTypeParam == null) {
return;
}
}
boolean haveContextParamList = false;
for (Object valueParam : param.getListItemsValue()) {
if (valueParam instanceof IElementParameter) {
IElementParameter vParam = (IElementParameter) valueParam;
if (vParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
haveContextParamList = true;
break;
}
}
}
if (!haveContextParamList) {
return;
}
IElementParameter jobElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_PROCESS.getName());
IElementParameter jobVersionParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_VERSION.getName());
IElementParameter contextElemParam = processTypeParam.getChildParameters().get(EParameterName.PROCESS_TYPE_CONTEXT.getName());
// get context list
String processId = (String) jobElemParam.getValue();
String contextName = (String) contextElemParam.getValue();
if (contextName == null) {
contextName = new String();
}
if (processId == null || contextName == null) {
revertToolBarButtonState(false);
return;
}
IElementParameter useDynamic = elem.getElementParameter("USE_DYNAMIC_JOB");
if (useDynamic != null && Boolean.valueOf(String.valueOf(useDynamic.getValue()))) {
String[] split = processId.split(";");
processId = split[0];
}
ProcessItem processItem = ItemCacheManager.getProcessItem(processId, (String) jobVersionParam.getValue());
String[] contextParameterNames = null;
if (processItem != null) {
// achen modify to fix bug 0006107
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
// process = new Process(processItem.getProperty());
// process.loadXmlFile();
IContextManager contextManager = service.getProcessContextFromItem(processItem);
if (contextManager != null) {
IContext context = contextManager.getContext(contextName);
for (IContextParameter contextParam : context.getContextParameterList()) {
contextParameterNamesList.add(contextParam.getName());
}
}
contextParameterNames = contextParameterNamesList.toArray(new String[0]);
}
if (contextParameterNames == null || contextParameterNames.length == 0) {
contextParameterNamesList.clear();
// we rerebuild the list here from what was saved in the job before
for (HashMap<String, Object> values : (List<HashMap<String, Object>>) param.getValue()) {
//$NON-NLS-1$
String name = (String) values.get("PARAM_NAME_COLUMN");
contextParameterNamesList.add(name);
}
contextParameterNames = contextParameterNamesList.toArray(new String[0]);
}
// update table values
TableViewerCreator tableViewerCreator = (TableViewerCreator) hashCurControls.get(param.getName());
Object[] itemsValue = param.getListItemsValue();
if (tableViewerCreator != null) {
List colList = tableViewerCreator.getColumns();
for (int j = 0; j < itemsValue.length; j++) {
if ((j + 1) >= colList.size()) {
break;
}
if (itemsValue[j] instanceof IElementParameter) {
IElementParameter tmpParam = (IElementParameter) itemsValue[j];
if (tmpParam.getFieldType() == EParameterFieldType.CONTEXT_PARAM_NAME_LIST) {
tmpParam.setListItemsDisplayCodeName(contextParameterNames);
tmpParam.setListItemsDisplayName(contextParameterNames);
tmpParam.setListItemsValue(contextParameterNames);
// TDI-35251 won't set default, if not fount, keep error
// if (contextParameterNames.length > 0) {
// tmpParam.setDefaultClosedListValue(contextParameterNames[0]);
// } else {
//$NON-NLS-1$
tmpParam.setDefaultClosedListValue("");
// }
// j + 1 because first column is masked
TableViewerCreatorColumnNotModifiable column = (TableViewerCreatorColumnNotModifiable) colList.get(j + 1);
CCombo combo = (CCombo) column.getCellEditor().getControl();
String[] oldItems = combo.getItems();
combo.setItems(contextParameterNames);
List<Map<String, Object>> paramValues = (List<Map<String, Object>>) param.getValue();
String[] items = param.getListItemsDisplayCodeName();
for (int currentIndex = 0; currentIndex < paramValues.size(); currentIndex++) {
Map<String, Object> currentLine = paramValues.get(currentIndex);
Object o = currentLine.get(items[j]);
if (o instanceof Integer) {
Integer nb = (Integer) o;
if ((nb >= oldItems.length) || (nb == -1)) {
currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
} else {
currentLine.put(items[j], oldItems[nb]);
}
} else {
if (o instanceof String) {
Integer nb = new Integer(tmpParam.getIndexOfItemFromList((String) o));
if (nb == -1 && !"".equals(tmpParam.getDefaultClosedListValue())) {
currentLine.put(items[j], tmpParam.getDefaultClosedListValue());
}
}
}
}
}
}
}
}
// (bug 3740)
boolean checked = contextParameterNames != null && contextParameterNames.length > 0;
revertToolBarButtonState(checked);
}
Aggregations