use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method exportAsContext.
/**
*
* ggu Comment method "exportAsContext".
*
*/
public static Map<ContextItem, List<ConectionAdaptContextVariableModel>> exportAsContext(ConnectionItem connItem, Set<IConnParamName> paramSet) {
if (connItem == null) {
return null;
}
List<IContextParameter> varList = createContextParameters(connItem, paramSet);
if (varList == null || varList.isEmpty()) {
return null;
}
String contextName = convertContextLabel(connItem.getProperty().getLabel());
ISelection selection = getRepositoryContext(contextName, false);
if (selection == null) {
return null;
}
Map<ContextItem, List<ConectionAdaptContextVariableModel>> variableContextMap = new HashMap();
List<ConectionAdaptContextVariableModel> models = new ArrayList<ConectionAdaptContextVariableModel>();
Set<String> connectionVaribles = getConnVariables(connItem, paramSet);
ContextModeWizard contextWizard = new ContextModeWizard(contextName, selection.isEmpty(), selection, varList, connectionVaribles);
WizardDialog dlg = new WizardDialog(Display.getCurrent().getActiveShell(), contextWizard);
if (dlg.open() == Window.OK) {
ContextItem contextItem = contextWizard.getContextItem();
models = contextWizard.getAdaptModels();
if (contextItem != null) {
variableContextMap.put(contextItem, models);
}
contextManager = contextWizard.getContextManager();
if (contextItem != null) {
contextItem.getProperty().setLabel(contextName);
}
return variableContextMap;
}
return null;
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class SpagicJavaDeployManager method getProperties.
public List<URL> getProperties(ProcessItem processItem, String contextName) {
List<URL> list = new ArrayList<URL>();
Properties p = new Properties();
FileOutputStream out = null;
String projectName = getCorrespondingProjectName(processItem);
String jobName = processItem.getProperty().getLabel();
String jobFolderName = JavaResourcesHelper.getJobFolderName(escapeFileNameSpace(processItem), processItem.getProperty().getVersion());
try {
// List<SpagoBiServer> listServerSapgo = null;
// listServerSapgo = SpagicServerHelper.parse(new SpagicPreferencePage().getPreferenceStore().getString(
// SpagoBiServer.SPAGOBI_SERVER));
// if (listServerSapgo != null && !listServerSapgo.isEmpty()) {
// Iterator<SpagoBiServer> iterator = listServerSapgo.iterator();
// while (iterator.hasNext()) {
// SpagoBiServer spagoBiServer = iterator.next();
// }
// }
IPath path = getSrcRootLocation();
//$NON-NLS-1$
File file = new File(getTmpFolder() + PATH_SEPARATOR + "spagic.properties");
//$NON-NLS-1$
path = path.append(projectName).append(jobFolderName).append(jobName + ".java");
BufferedReader buff = new BufferedReader(new FileReader(path.toPortableString()));
int nbLine = 0;
while (buff.readLine() != null) {
nbLine++;
}
out = new FileOutputStream(file);
PrintStream ps = new PrintStream(out);
IDesignerCoreService service = CorePlugin.getDefault().getDesignerCoreService();
IProcess process = service.getProcessFromProcessItem(processItem);
List<IContextParameter> ctxParams = process.getContextManager().getContext(contextName).getContextParameterList();
for (IContextParameter ctxParam : ctxParams) {
p.put(ctxParam.getName(), ctxParam.getValue());
}
p.put("JobClassName", //$NON-NLS-1$
getCorrespondingProjectName(null) + //$NON-NLS-1$
"." + JavaResourcesHelper.getJobFolderName(processItem.getProperty().getLabel(), processItem.getProperty().getVersion()) + "." + //$NON-NLS-1$
processItem.getProperty().getLabel());
//$NON-NLS-1$
p.put("talendJobClassDescription", HTMLDocUtils.checkString(processItem.getProperty().getDescription()));
//$NON-NLS-1$
p.put("rowNumber", Integer.toString(nbLine));
//$NON-NLS-1$ //$NON-NLS-2$
p.put("host", "localhost");
p.list(ps);
ps.flush();
list.add(file.toURI().toURL());
} catch (Exception e) {
ExceptionHandler.process(e);
} finally {
if (out != null) {
try {
out.close();
} catch (Exception e) {
}
}
}
return list;
}
use of org.talend.core.model.process.IContextParameter in project tesb-studio-se by Talend.
the class ContextPartGenerator method generatePart.
public CharSequence generatePart(IContext designerContext) throws CodeGeneratorException {
List<IContextParameter> listParameters = designerContext.getContextParameterList();
if (listParameters == null) {
return "";
}
CodeGeneratorArgument codeGenArgument = argumentBuilder.build();
codeGenArgument.setContextName(designerContext.getName());
List<IContextParameter> listParametersCopy = tranformEncryptedParams(listParameters);
codeGenArgument.setNode(listParametersCopy);
JetBean jetBean = JetUtil.createJetBean(codeGenArgument);
jetBean.setTemplateRelativeUri(ECamelTemplate.CONTEXT.getTemplateURL());
return JetUtil.jetGenerate(jetBean);
}
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);
}
}
}
}
}
}
}
}
Aggregations