use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class GenericContextUtil method createContextParameters.
public static List<IContextParameter> createContextParameters(String prefixName, Connection connection, Set<IConnParamName> paramSet) {
List<IContextParameter> varList = new ArrayList<>();
if (connection instanceof GenericConnection) {
GenericConnection conn = (GenericConnection) connection;
if (conn == null || prefixName == null || paramSet == null || paramSet.isEmpty()) {
return Collections.emptyList();
}
String paramPrefix = prefixName + ConnectionContextHelper.LINE;
String paramName = null;
for (IConnParamName param : paramSet) {
if (param instanceof GenericConnParamName) {
GenericConnParamName connParamName = (GenericConnParamName) param;
String name = connParamName.getName();
ComponentProperties componentProperties = getComponentProperties((GenericConnection) connection);
Property<?> property = componentProperties.getValuedProperty(name);
paramName = paramPrefix + connParamName.getContextVar();
JavaType type = JavaTypesManager.STRING;
if (property.isFlag(Property.Flags.ENCRYPT)) {
type = JavaTypesManager.PASSWORD;
}
if (GenericTypeUtils.isIntegerType(property)) {
type = JavaTypesManager.INTEGER;
}
String value = property == null || property.getValue() == null ? null : StringEscapeUtils.escapeJava(String.valueOf(property.getValue()));
ConnectionContextHelper.createParameters(varList, paramName, value, type);
}
}
}
return varList;
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method createContextParameters.
private static List<IContextParameter> createContextParameters(ConnectionItem connectionItem, Set<IConnParamName> paramSet) {
if (connectionItem == null) {
return null;
}
final String label = convertContextLabel(connectionItem.getProperty().getLabel());
Connection conn = connectionItem.getConnection();
List<IContextParameter> varList = null;
if (conn instanceof JSONFileConnection) {
varList = getJSONFileVariables(label, (JSONFileConnection) conn);
}
return varList;
}
use of org.talend.core.model.process.IContextParameter in project tdi-studio-se by Talend.
the class JSONConnectionContextHelper method getJSONFileVariables.
static List<IContextParameter> getJSONFileVariables(String prefixName, JSONFileConnection conn) {
if (conn == null || prefixName == null) {
return Collections.emptyList();
}
List<IContextParameter> varList = new ArrayList<IContextParameter>();
prefixName = prefixName + LINE;
String paramName = null;
if (!conn.isInputModel()) {
String outputFilePath = conn.getOutputFilePath();
paramName = prefixName + EParamName.OutputFilePath;
createParameters(varList, paramName, outputFilePath, JavaTypesManager.FILE);
} else {
String jsonFilePath = conn.getJSONFilePath();
String encoding = conn.getEncoding();
if (LANGUAGE.equals(ECodeLanguage.PERL)) {
jsonFilePath = TalendQuoteUtils.addQuotes(jsonFilePath);
encoding = TalendQuoteUtils.addQuotes(encoding);
}
paramName = prefixName + EParamName.FilePath;
createParameters(varList, paramName, jsonFilePath, JavaTypesManager.FILE);
paramName = prefixName + EParamName.Encoding;
createParameters(varList, paramName, encoding);
EList schema = conn.getSchema();
if (schema != null) {
Object object = schema.get(0);
if (object instanceof JSONXPathLoopDescriptor) {
JSONXPathLoopDescriptor loopDesc = (JSONXPathLoopDescriptor) object;
paramName = prefixName + EParamName.XPathQuery;
String absoluteXPathQuery = loopDesc.getAbsoluteXPathQuery();
if (LANGUAGE.equals(ECodeLanguage.PERL)) {
absoluteXPathQuery = TalendQuoteUtils.addQuotes(absoluteXPathQuery);
}
createParameters(varList, paramName, absoluteXPathQuery);
}
}
}
return varList;
}
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;
}
Aggregations