Compare commits
198 Commits
patch/TPS-
...
dchmyga/TP
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b3004fa91e | ||
|
|
f79ca47317 | ||
|
|
aa067a70b0 | ||
|
|
ac0e9332ec | ||
|
|
d090841fb0 | ||
|
|
b21b77980d | ||
|
|
40f7502d52 | ||
|
|
2ae299afbf | ||
|
|
c928d6f456 | ||
|
|
8b10f58b29 | ||
|
|
037fe2654e | ||
|
|
b7d3d4dd5b | ||
|
|
c14e9c2e5d | ||
|
|
3ec58bc01a | ||
|
|
fe4f6df6b2 | ||
|
|
5cc63fe6d8 | ||
|
|
cae81a6172 | ||
|
|
ee7068dc53 | ||
|
|
e826fdc490 | ||
|
|
10509c005c | ||
|
|
54971f678f | ||
|
|
c64a3a276b | ||
|
|
bd99714f18 | ||
|
|
cc5b551d84 | ||
|
|
ce18e0ffd1 | ||
|
|
d8aad268c2 | ||
|
|
b9e74d9f02 | ||
|
|
4539464127 | ||
|
|
0721ad904b | ||
|
|
0de13ccfee | ||
|
|
4468aaa175 | ||
|
|
a6c8578551 | ||
|
|
e7cd94f879 | ||
|
|
2daa07e10f | ||
|
|
4418345c3e | ||
|
|
4b243ce10e | ||
|
|
e5338b845e | ||
|
|
f95639be52 | ||
|
|
15ee342c10 | ||
|
|
606d704249 | ||
|
|
8db7b77fb0 | ||
|
|
9edc76339a | ||
|
|
ae8bf4b59a | ||
|
|
df4ee764ea | ||
|
|
a453e16e66 | ||
|
|
f25c4badd1 | ||
|
|
94b67f8772 | ||
|
|
31b4ee7333 | ||
|
|
5027b0121b | ||
|
|
b6cc2476f9 | ||
|
|
48949763d2 | ||
|
|
5ef8452927 | ||
|
|
65b6907dcd | ||
|
|
c7218025c6 | ||
|
|
4d7fe6a502 | ||
|
|
22e414d893 | ||
|
|
16fcf7d1c9 | ||
|
|
42c51a8624 | ||
|
|
7c625d9201 | ||
|
|
39042a308b | ||
|
|
65f229036c | ||
|
|
26b45c6f3e | ||
|
|
dc14b124c8 | ||
|
|
a7ae3334f8 | ||
|
|
e21710c699 | ||
|
|
7ac71ac864 | ||
|
|
fd37124ecd | ||
|
|
8cefa89ecd | ||
|
|
56120b75bb | ||
|
|
aafe501e22 | ||
|
|
5f14941414 | ||
|
|
d2ff4a74ac | ||
|
|
aed787a905 | ||
|
|
c5dfff2320 | ||
|
|
6e6d11bf5a | ||
|
|
3eaf12697f | ||
|
|
ca4b013c76 | ||
|
|
754b49bf37 | ||
|
|
7804c32c0c | ||
|
|
1ea3d2e8c8 | ||
|
|
d34ed648a7 | ||
|
|
ec4847911c | ||
|
|
5dfc5caeaa | ||
|
|
d08835d811 | ||
|
|
e8d6bff08d | ||
|
|
e6bcd0b81a | ||
|
|
58243b216a | ||
|
|
5cfa7b3b98 | ||
|
|
1d1f782cd0 | ||
|
|
e3e9c9b401 | ||
|
|
08266054c0 | ||
|
|
4d944f0910 | ||
|
|
c001e4245e | ||
|
|
c7c5c410db | ||
|
|
8712fc8845 | ||
|
|
268697b578 | ||
|
|
aa4bfa79f7 | ||
|
|
ca527877e2 | ||
|
|
4c4e091b14 | ||
|
|
1d40c1d03f | ||
|
|
d32e660ed5 | ||
|
|
62e6776a9d | ||
|
|
0fd6e2a5ae | ||
|
|
1dea872eca | ||
|
|
dd3d7aab1e | ||
|
|
39d9ecb7ae | ||
|
|
ffd480faf6 | ||
|
|
d769a705f9 | ||
|
|
b1e8227987 | ||
|
|
3729ca4734 | ||
|
|
f1f0e3b3fa | ||
|
|
751e157764 | ||
|
|
d8d591f985 | ||
|
|
0d52d35d65 | ||
|
|
14bb82b680 | ||
|
|
875273246b | ||
|
|
9b7e750f26 | ||
|
|
cfc470383e | ||
|
|
90ed0e0146 | ||
|
|
8b09f8c12c | ||
|
|
4e6719fea2 | ||
|
|
a76b533335 | ||
|
|
4ce30defb8 | ||
|
|
f297c329c9 | ||
|
|
ac087dd899 | ||
|
|
8d6aac4487 | ||
|
|
f78773ba76 | ||
|
|
bff58f3865 | ||
|
|
d60cbe30c9 | ||
|
|
bfbf8d37cc | ||
|
|
17338305be | ||
|
|
99375c5886 | ||
|
|
e77b4a347c | ||
|
|
069c169de5 | ||
|
|
339af1f06b | ||
|
|
c6d2e700a3 | ||
|
|
8efc0df5fa | ||
|
|
0cf7abbc1b | ||
|
|
1cca5a725f | ||
|
|
51c17366b3 | ||
|
|
2efd0a576b | ||
|
|
0d1feddcdc | ||
|
|
b63eda5b00 | ||
|
|
62076c3dde | ||
|
|
be32d236ce | ||
|
|
784eddb637 | ||
|
|
fceb75306c | ||
|
|
18f58c3227 | ||
|
|
be9e3c5f7b | ||
|
|
1f22ba1d95 | ||
|
|
ad128e1de4 | ||
|
|
0255fe7ab2 | ||
|
|
a773b349c9 | ||
|
|
185223d211 | ||
|
|
5ee921c424 | ||
|
|
31ef759a19 | ||
|
|
7d27951987 | ||
|
|
65de33bbe0 | ||
|
|
c7c49f64d3 | ||
|
|
5c85ca8901 | ||
|
|
205ba4a34b | ||
|
|
a56e6a9f87 | ||
|
|
bd47c35822 | ||
|
|
18dfd7c0eb | ||
|
|
82b3293fa1 | ||
|
|
1b063578fb | ||
|
|
288b8630b1 | ||
|
|
010e5ca7f7 | ||
|
|
87e4186271 | ||
|
|
0595e5008f | ||
|
|
093d44312b | ||
|
|
970e8b623f | ||
|
|
f6bddbf553 | ||
|
|
4a4c9ea1b1 | ||
|
|
a879db668b | ||
|
|
d61cf31fc7 | ||
|
|
f1962c39a9 | ||
|
|
9230e47ee4 | ||
|
|
ed172de48d | ||
|
|
0f579c6e72 | ||
|
|
568088d394 | ||
|
|
7e911f0b99 | ||
|
|
16b2b9bf62 | ||
|
|
44aabcdecd | ||
|
|
839af2e2f8 | ||
|
|
e89df33f76 | ||
|
|
a8c01d85da | ||
|
|
2420214bf6 | ||
|
|
1c5404c12e | ||
|
|
49cba020f9 | ||
|
|
396868b931 | ||
|
|
4f429f6a98 | ||
|
|
218aa295f1 | ||
|
|
c364565c33 | ||
|
|
04fc9056b9 | ||
|
|
507da793eb | ||
|
|
9dfee4a013 | ||
|
|
d8e2ccab3a |
68
PATCH_RELEASE_NOTE.md
Normal file
68
PATCH_RELEASE_NOTE.md
Normal file
@@ -0,0 +1,68 @@
|
||||
---
|
||||
version: 7.2.1
|
||||
module: https://talend.poolparty.biz/coretaxonomy/42
|
||||
product:
|
||||
- https://talend.poolparty.biz/coretaxonomy/23
|
||||
---
|
||||
|
||||
# TPS-4883
|
||||
|
||||
| Info | Value |
|
||||
| ---------------- | ---------------- |
|
||||
| Patch Name | Patch\_20210727_TPS-4883\_v1-7.2.1 |
|
||||
| Release Date | 2021-07-27 |
|
||||
| Target Version | Talend-Studio-20190620\_1446-V7.2.1 |
|
||||
| Product affected | Talend Studio |
|
||||
|
||||
## Introduction
|
||||
|
||||
This is a self-contained patch.
|
||||
|
||||
**NOTE**: For information on how to obtain this patch, reach out to your Support contact at Talend.
|
||||
|
||||
## Fixed issues
|
||||
|
||||
This patch contains the following fixes:
|
||||
|
||||
- TPS-4883 [7.2.1] Lose precision when loading BigDecimal data to MSSQL with single insert query (TDI-45907)
|
||||
|
||||
## Prerequisites
|
||||
|
||||
Consider the following requirements for your system:
|
||||
|
||||
- Talend Studio 7.2.1 must be installed.
|
||||
|
||||
|
||||
## Installation
|
||||
|
||||
### Installing the patch using Software update
|
||||
|
||||
1) Logon TAC and switch to Configuration->Software Update, then enter the correct values and save referring to the documentation: https://help.talend.com/reader/f7Em9WV_cPm2RRywucSN0Q/j9x5iXV~vyxMlUafnDejaQ
|
||||
|
||||
2) Switch to Software update page, where the new patch will be listed. The patch can be downloaded from here into the nexus repository.
|
||||
|
||||
3) On Studio Side: Logon Studio with remote mode, on the logon page the Update button is displayed: click this button to install the patch.
|
||||
|
||||
### Installing the patch using Talend Studio
|
||||
|
||||
1) Create a folder named "patches" under your studio installer directory and copy the patch .zip file to this folder.
|
||||
|
||||
2) Restart your studio: a window pops up, then click OK to install the patch, or restart the commandline and the patch will be installed automatically.
|
||||
|
||||
### Installing the patch using Commandline
|
||||
|
||||
Execute the following commands:
|
||||
|
||||
1. Talend-Studio-win-x86_64.exe -nosplash -application org.talend.commandline.CommandLine -consoleLog -data commandline-workspace startServer -p 8002 --talendDebug
|
||||
2. initRemote {tac_url} -ul {TAC login username} -up {TAC login password}
|
||||
3. checkAndUpdate -tu {TAC login username} -tup {TAC login password}
|
||||
|
||||
## Uninstallation
|
||||
Backup the Affected files list below. Uninstall the patch by restore the backup files.
|
||||
|
||||
## Affected files for this patch
|
||||
|
||||
The following files are installed by this patch:
|
||||
|
||||
- {Talend\_Studio\_path}/plugins/org.talend.designer.components.localprovider\_7.2.1.20190614\_0309/components/tMSSqlOutput/tMSSqlOutput\_end.javajet
|
||||
- {Talend\_Studio\_path}/plugins/org.talend.designer.components.localprovider\_7.2.1.20190614\_0309/components/tMSSqlOutput/tMSSqlOutput\_main.javajet
|
||||
@@ -59,88 +59,76 @@ if((codePart.equals(ECodePart.END))&&(stat || logstashCurrent)){
|
||||
List<String> needToEndConnNames = new ArrayList<String>();
|
||||
INode nextNode = node.getOutgoingConnections(EConnectionType.ITERATE).get(0).getTarget();
|
||||
NodeUtil.fillConnectionsForStat(needToEndConnNames, nextNode);
|
||||
%>
|
||||
|
||||
<%if(stat) {%>
|
||||
if(execStat){
|
||||
<%
|
||||
for(String connName : needToEndConnNames){
|
||||
if(!needToEndConnNames.isEmpty()) {
|
||||
if(stat && logstashCurrent) {
|
||||
%>
|
||||
runStat.updateStatOnConnection("<%=connName%>"+iterateId,2, 0);
|
||||
runStat.updateStatAndLog(execStat,enableLogStash,iterateId,2,0<%for(String connName : needToEndConnNames){%>,"<%=connName%>"<%}%>);
|
||||
<%
|
||||
} else {
|
||||
if(stat) {%>
|
||||
if(execStat){
|
||||
runStat.updateStatOnConnection(iterateId,2,0<%for(String connName : needToEndConnNames){%>,"<%=connName%>"<%}%>);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(logstashCurrent) {//now only finish the log, not send, TODO%>
|
||||
if(enableLogStash){
|
||||
runStat.log(iterateId,2,0<%for(String connName : needToEndConnNames){%>,"<%=connName%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(logstashCurrent) {//now only finish the log, not send, TODO%>
|
||||
if(enableLogStash){
|
||||
<%
|
||||
for(String connName : needToEndConnNames){
|
||||
%>
|
||||
runStat.logStatOnConnection("<%=connName%>"+iterateId,2, 0);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<%
|
||||
}
|
||||
if(connSet.size()>0){
|
||||
for(IConnection con:connSet){
|
||||
INode source = con.getSource();
|
||||
String sourceNodeId = source.getUniqueName();
|
||||
String sourceNodeComponent = source.getComponent().getName();
|
||||
%>
|
||||
<%if(stat) {%>
|
||||
if(execStat){
|
||||
if(resourceMap.get("inIterateVComp") == null || !((Boolean)resourceMap.get("inIterateVComp"))){
|
||||
runStat.updateStatOnConnection("<%=con.getUniqueName()%>"+iterateId,2, 0);
|
||||
}
|
||||
|
||||
if(connSet.size()>0) {
|
||||
if(stat && logstashCurrent && (connSet.size()==1)) {//the most common case, write this ugly logic for 65535 issue
|
||||
for(IConnection con:connSet){
|
||||
INode source = con.getSource();
|
||||
String sourceNodeId = source.getUniqueName();
|
||||
String sourceNodeComponent = source.getComponent().getName();
|
||||
for (INode jobStructureCatcher : jobCatcherNodes) {
|
||||
%>
|
||||
if(runStat.updateStatAndLog(execStat,enableLogStash,resourceMap,iterateId,"<%=con.getUniqueName()%>",2,0,
|
||||
<%=jobStructureCatcher.getUniqueName()%>,"<%=sourceNodeId%>","<%=sourceNodeComponent%>","<%=node.getUniqueName()%>","<%=node.getComponent().getName()%>","<%="REJECT".equals(con.getConnectorName()) ? "reject" : "output"%>")) {
|
||||
<%=jobStructureCatcher.getDesignSubjobStartNode().getUniqueName() %>Process(globalMap);
|
||||
}
|
||||
<%
|
||||
break;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if(stat){
|
||||
%>
|
||||
if(execStat){
|
||||
runStat.updateStat(resourceMap,iterateId,2,0<%for(IConnection con : connSet){%>,"<%=con.getUniqueName()%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(logstashCurrent) {%>
|
||||
if(enableLogStash){
|
||||
if(resourceMap.get("inIterateVComp") == null || !((Boolean)resourceMap.get("inIterateVComp"))){
|
||||
<%
|
||||
if(logstashCurrent){
|
||||
%>
|
||||
if(enableLogStash) {
|
||||
<%
|
||||
for(IConnection con:connSet){
|
||||
INode source = con.getSource();
|
||||
String sourceNodeId = source.getUniqueName();
|
||||
String sourceNodeComponent = source.getComponent().getName();
|
||||
for (INode jobStructureCatcher : jobCatcherNodes) {
|
||||
%>
|
||||
RunStat.StatBean talend_statebean = runStat.logStatOnConnection("<%=con.getUniqueName()%>"+iterateId,2, 0);
|
||||
|
||||
<%=jobStructureCatcher.getUniqueName() %>.addConnectionMessage(
|
||||
"<%=sourceNodeId%>",
|
||||
"<%=sourceNodeComponent%>",
|
||||
false,
|
||||
"<%="REJECT".equals(con.getConnectorName()) ? "reject" : "output"%>",
|
||||
"<%=con.getUniqueName()%>",
|
||||
talend_statebean.getNbLine(),
|
||||
talend_statebean.getStartTime(),
|
||||
talend_statebean.getEndTime()
|
||||
);
|
||||
|
||||
<%=jobStructureCatcher.getUniqueName() %>.addConnectionMessage(
|
||||
"<%=node.getUniqueName()%>",
|
||||
"<%=node.getComponent().getName()%>",
|
||||
true,
|
||||
"input",
|
||||
"<%=con.getUniqueName()%>",
|
||||
talend_statebean.getNbLine(),
|
||||
talend_statebean.getStartTime(),
|
||||
talend_statebean.getEndTime()
|
||||
);
|
||||
<%=jobStructureCatcher.getDesignSubjobStartNode().getUniqueName() %>Process(globalMap);
|
||||
if(runStat.log(resourceMap,iterateId,"<%=con.getUniqueName()%>",2,0,
|
||||
<%=jobStructureCatcher.getUniqueName()%>,"<%=sourceNodeId%>","<%=sourceNodeComponent%>","<%=node.getUniqueName()%>","<%=node.getComponent().getName()%>","<%="REJECT".equals(con.getConnectorName()) ? "reject" : "output"%>")) {
|
||||
<%=jobStructureCatcher.getDesignSubjobStartNode().getUniqueName() %>Process(globalMap);
|
||||
}
|
||||
<%
|
||||
break;
|
||||
}
|
||||
%>
|
||||
}
|
||||
}
|
||||
%>
|
||||
}
|
||||
<%
|
||||
}
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
@@ -146,83 +146,82 @@
|
||||
boolean logstashCurrent = !cid.startsWith("tJobStructureCatcher") && !cid.startsWith("talend") && enableLogStash;
|
||||
|
||||
if ((codePart.equals(ECodePart.BEGIN))&&(stat || logstashCurrent)&&connSet.size()>0) {
|
||||
for(IConnection con:connSet){
|
||||
%>
|
||||
if (<%if(stat){%>execStat<%}%><%if(stat && logstashCurrent){%> || <%}%><%if(logstashCurrent){%>enableLogStash<%}%>) {
|
||||
if(resourceMap.get("inIterateVComp") == null){
|
||||
<%if(containsTPartitioner){%>
|
||||
java.util.concurrent.ConcurrentHashMap<Object, Object> concurrentHashMap_<%=con.getUniqueName() %> = (java.util.concurrent.ConcurrentHashMap) globalMap.get("concurrentHashMap");
|
||||
concurrentHashMap_<%=con.getUniqueName() %>.putIfAbsent("<%=con.getUniqueName() %>" + iterateLoop,new java.util.concurrent.atomic.AtomicInteger(0));
|
||||
java.util.concurrent.atomic.AtomicInteger stats_<%=con.getUniqueName() %> = (java.util.concurrent.atomic.AtomicInteger) concurrentHashMap_<%=con.getUniqueName() %>.get("<%=con.getUniqueName() %>" + iterateLoop);
|
||||
int step_<%=con.getUniqueName() %> = stats_<%=con.getUniqueName() %>.incrementAndGet()<=1?0:1;
|
||||
<%if(stat) {%>
|
||||
if(execStat) {
|
||||
runStat.updateStatOnConnection("<%=con.getUniqueName() %>"+iterateId, step_<%=con.getUniqueName()%>, 0);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(logstashCurrent) {%>
|
||||
if(enableLogStash) {
|
||||
runStat.logStatOnConnection("<%=con.getUniqueName()%>"+iterateId, step_<%=con.getUniqueName()%>, 0);
|
||||
}
|
||||
<%}%>
|
||||
<%}else{%>
|
||||
<%if(stat) {%>
|
||||
if(execStat) {
|
||||
runStat.updateStatOnConnection("<%=con.getUniqueName() %>"+iterateId, 0, 0);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(logstashCurrent) {%>
|
||||
if(enableLogStash) {
|
||||
runStat.logStatOnConnection("<%=con.getUniqueName()%>"+iterateId, 0, 0);
|
||||
}
|
||||
<%}%>
|
||||
<%}%>
|
||||
if(containsTPartitioner) {
|
||||
%>
|
||||
if(<%if(stat){%>execStat<%}%><%if(stat && logstashCurrent){%> || <%}%><%if(logstashCurrent){%>enableLogStash<%}%>) {
|
||||
runStat.updateStatOnConnectionAndLog(resourceMap,globalMap,iterateLoop,iterateId,<%if(stat){%>execStat<%} else {%>false<%}%>,enableLogStash,0<%for(IConnection con : connSet){%>,"<%=con.getUniqueName()%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
} else {
|
||||
if(stat && logstashCurrent) {
|
||||
%>
|
||||
runStat.updateStatAndLog(execStat,enableLogStash,resourceMap,iterateId,0,0<%for(IConnection con : connSet){%>,"<%=con.getUniqueName()%>"<%}%>);
|
||||
<%
|
||||
} else {
|
||||
if(stat) {
|
||||
%>
|
||||
if(execStat) {
|
||||
runStat.updateStatOnConnection(resourceMap,iterateId,0,0<%for(IConnection con : connSet){%>,"<%=con.getUniqueName()%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
}
|
||||
}
|
||||
|
||||
<%
|
||||
|
||||
if(logstashCurrent) {
|
||||
%>
|
||||
if(enableLogStash) {
|
||||
runStat.log(resourceMap,iterateId,0,0<%for(IConnection con : connSet){%>,"<%=con.getUniqueName()%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if((codePart.equals(ECodePart.MAIN))&&(stat || logstashCurrent)&&connSet.size()>0){
|
||||
for(IConnection con:connSet){
|
||||
%>
|
||||
|
||||
//<%=con.getUniqueName()%>
|
||||
//<%=(String)codeGenArgument.getIncomingName()%>
|
||||
|
||||
|
||||
<%if (!node.getComponent().useMerge()) {%>
|
||||
<%if(stat) {%>
|
||||
if(execStat){
|
||||
runStat.updateStatOnConnection("<%=con.getUniqueName() %>"+iterateId,1, 1);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(logstashCurrent) {%>
|
||||
if(enableLogStash) {
|
||||
runStat.logStatOnConnection("<%=con.getUniqueName() %>"+iterateId,1, 1);
|
||||
}
|
||||
<%}%>
|
||||
<%
|
||||
} else if(con.getUniqueName().equals((String)codeGenArgument.getIncomingName())){
|
||||
if(!node.getComponent().useMerge()) {
|
||||
if(stat && logstashCurrent) {
|
||||
%>
|
||||
<%if(stat) {%>
|
||||
if(execStat){
|
||||
runStat.updateStatOnConnection("<%=con.getUniqueName() %>"+iterateId,1, 1);
|
||||
runStat.updateStatAndLog(execStat,enableLogStash,iterateId,1,1<%for(IConnection con : connSet){%>,"<%=con.getUniqueName()%>"<%}%>);
|
||||
<%
|
||||
} else {
|
||||
if(stat) {
|
||||
%>
|
||||
if(execStat){
|
||||
runStat.updateStatOnConnection(iterateId,1,1<%for(IConnection con : connSet){%>,"<%=con.getUniqueName()%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(logstashCurrent) {%>
|
||||
if(enableLogStash) {
|
||||
runStat.logStatOnConnection("<%=con.getUniqueName() %>"+iterateId,1, 1);
|
||||
if(logstashCurrent) {
|
||||
%>
|
||||
if(enableLogStash) {
|
||||
runStat.log(iterateId,1,1<%for(IConnection con : connSet){%>,"<%=con.getUniqueName()%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
}
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
for(IConnection connection:connSet){
|
||||
if(connection.getUniqueName().equals((String)codeGenArgument.getIncomingName())){
|
||||
if(stat && logstashCurrent) {
|
||||
%>
|
||||
runStat.updateStatAndLog(execStat,enableLogStash,iterateId,1,1<%for(IConnection con : connSet){if(con.getUniqueName().equals((String)codeGenArgument.getIncomingName())){%>,"<%=con.getUniqueName()%>"<%}}%>);
|
||||
<%
|
||||
} else {
|
||||
if(stat) {%>
|
||||
if(execStat){
|
||||
runStat.updateStatOnConnection(iterateId,1,1<%for(IConnection con : connSet){if(con.getUniqueName().equals((String)codeGenArgument.getIncomingName())){%>,"<%=con.getUniqueName()%>"<%}}%>);
|
||||
}
|
||||
<%}
|
||||
|
||||
if(logstashCurrent) {%>
|
||||
if(enableLogStash) {
|
||||
runStat.log(iterateId,1,1<%for(IConnection con : connSet){if(con.getUniqueName().equals((String)codeGenArgument.getIncomingName())){%>,"<%=con.getUniqueName()%>"<%}}%>);
|
||||
}
|
||||
<%}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -251,7 +250,7 @@
|
||||
for (INode jobStructureCatcher : jobCatcherNodes) {
|
||||
%>
|
||||
if(enableLogStash) {
|
||||
<%=jobStructureCatcher.getUniqueName() %>.addComponentMessage("<%=node.getUniqueName()%>", "<%=node.getComponent().getName()%>");
|
||||
<%=jobStructureCatcher.getUniqueName() %>.addCM("<%=node.getUniqueName()%>", "<%=node.getComponent().getName()%>");
|
||||
<%=jobStructureCatcher.getDesignSubjobStartNode().getUniqueName() %>Process(globalMap);
|
||||
}
|
||||
<%
|
||||
@@ -266,46 +265,37 @@
|
||||
List<String> needToStartConnNames = new ArrayList<String>();
|
||||
INode nextNode = node.getOutgoingConnections(EConnectionType.ITERATE).get(0).getTarget();
|
||||
NodeUtil.fillConnectionsForStat(needToStartConnNames, nextNode);
|
||||
if(needToStartConnNames.isEmpty()) {
|
||||
//do nothing
|
||||
} else if(containsTPartitioner){
|
||||
%>
|
||||
if(<%if(stat){%>execStat<%}%><%if(stat && logstashCurrent){%> || <%}%><%if(logstashCurrent){%>enableLogStash<%}%>){
|
||||
<%
|
||||
for(String connName : needToStartConnNames){
|
||||
%>
|
||||
<%if(containsTPartitioner){%>
|
||||
java.util.concurrent.ConcurrentHashMap<Object, Object> concurrentHashMap_<%=connName%> = (java.util.concurrent.ConcurrentHashMap) globalMap.get("concurrentHashMap");
|
||||
concurrentHashMap_<%=connName%>.putIfAbsent("<%=connName%>" + iterateLoop,new java.util.concurrent.atomic.AtomicInteger(0));
|
||||
java.util.concurrent.atomic.AtomicInteger stats_<%=connName%> = (java.util.concurrent.atomic.AtomicInteger) concurrentHashMap_<%=connName%>.get("<%=connName%>" + iterateLoop);
|
||||
|
||||
int step_<%=connName %> = stats_<%=connName%>.incrementAndGet()<=1?0:1;
|
||||
<%if(stat) {%>
|
||||
if(execStat) {
|
||||
runStat.updateStatOnConnection("<%=connName%>"+iterateId, step_<%=connName%>, 0);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(logstashCurrent) {%>
|
||||
if(enableLogStash) {
|
||||
runStat.logStatOnConnection("<%=connName%>"+iterateId, step_<%=connName%>, 0);
|
||||
}
|
||||
<%}%>
|
||||
<%}else{%>
|
||||
<%if(stat) {%>
|
||||
if(execStat) {
|
||||
runStat.updateStatOnConnection("<%=connName%>"+iterateId, 0, 0);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(logstashCurrent) {%>
|
||||
if(enableLogStash) {
|
||||
runStat.logStatOnConnection("<%=connName%>"+iterateId, 0, 0);
|
||||
}
|
||||
<%}%>
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
runStat.updateStatOnConnectionAndLog(globalMap,iterateLoop,iterateId,<%if(stat){%>execStat<%} else {%>false<%}%>,enableLogStash,0<%for(String connName : needToStartConnNames){%>,"<%=connName%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
} else {
|
||||
if(stat && logstashCurrent) {
|
||||
%>
|
||||
runStat.updateStatAndLog(execStat,enableLogStash,iterateId,0,0<%for(String connName : needToStartConnNames){%>,"<%=connName%>"<%}%>);
|
||||
<%
|
||||
} else {
|
||||
if(stat){
|
||||
%>
|
||||
if(execStat){
|
||||
runStat.updateStatOnConnection(iterateId,0,0<%for(String connName : needToStartConnNames){%>,"<%=connName%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
<%if(logstashCurrent) {%>
|
||||
if(enableLogStash){
|
||||
runStat.log(iterateId,0,0<%for(String connName : needToStartConnNames){%>,"<%=connName%>"<%}%>);
|
||||
}
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
<%
|
||||
}else if(codePart.equals(ECodePart.MAIN)){
|
||||
%>
|
||||
resourceMap.put("inIterateVComp", true);
|
||||
|
||||
@@ -106,6 +106,21 @@
|
||||
exist_tSQLDB = true;
|
||||
}
|
||||
|
||||
|
||||
String[] tcompV0Components = new String[] {
|
||||
"tAzureStorageConnection",
|
||||
"tGoogleDriveConnection",
|
||||
"tMarketoConnection",
|
||||
"tSnowflakeConnection",
|
||||
"tSalesforceConnection",
|
||||
"tNetsuiteConnection",
|
||||
"tMarkLogicConnection"
|
||||
};
|
||||
List<INode> tcompV0ComponentsList = new ArrayList<INode>();
|
||||
for (String tcompV0Component : tcompV0Components) {
|
||||
tcompV0ComponentsList.addAll((List<INode>)process.getNodesOfType(tcompV0Component));
|
||||
}
|
||||
|
||||
boolean exist_tSCP = false;
|
||||
List<INode> scpComponentsList = (List<INode>)process.getNodesOfType("tSCPConnection");
|
||||
if (scpComponentsList.size() > 0) {
|
||||
@@ -165,6 +180,8 @@
|
||||
exist_tSalesforce = true;
|
||||
}
|
||||
|
||||
List<INode> snowflakeComponentsList = (List<INode>)process.getNodesOfType("tSnowflakeConnection");
|
||||
|
||||
boolean exist_tSAP= false;
|
||||
List<INode> sapComponentsList = (List<INode>)process.getNodesOfType("tSAPConnection");
|
||||
if (sapComponentsList.size() > 0) {
|
||||
@@ -445,6 +462,7 @@
|
||||
lastStr = "";
|
||||
}
|
||||
}
|
||||
enableLogStash = "true".equalsIgnoreCase(System.getProperty("monitoring"));
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(!"".equals(log4jLevel)){
|
||||
@@ -493,7 +511,13 @@
|
||||
properties_<%=jobCatcherNode.getUniqueName()%>.setProperty("appender.file.maxsize", "52428800");
|
||||
properties_<%=jobCatcherNode.getUniqueName()%>.setProperty("appender.file.maxbackup", "20");
|
||||
properties_<%=jobCatcherNode.getUniqueName()%>.setProperty("host", "false");
|
||||
|
||||
|
||||
System.getProperties().stringPropertyNames().stream()
|
||||
.filter(it -> it.startsWith("monitoring.audit.logger.properties."))
|
||||
.forEach(key -> properties_<%=jobCatcherNode.getUniqueName()%>.setProperty(key.substring("monitoring.audit.logger.properties.".length()), System.getProperty(key)));
|
||||
|
||||
org.apache.log4j.Logger.getLogger("audit").setLevel(org.apache.log4j.Level.DEBUG);
|
||||
|
||||
auditLogger_<%=jobCatcherNode.getUniqueName()%> = org.talend.job.audit.JobEventAuditLoggerFactory.createJobAuditLogger(properties_<%=jobCatcherNode.getUniqueName()%>);
|
||||
}
|
||||
<%
|
||||
@@ -584,7 +608,16 @@
|
||||
} //endIf
|
||||
%>
|
||||
context.setContextType("<%=ctxParam.getName()%>", "<%=ctxParam.getType()%>");
|
||||
if(context.getStringValue("<%=ctxParam.getName()%>") == null) {
|
||||
context.<%=ctxParam.getName()%> = null;
|
||||
} else {
|
||||
<%//}B1 block%>
|
||||
<%
|
||||
String typeToGenerate ="String";
|
||||
if( !(ctxParam.getType().equals("id_File") || ctxParam.getType().equals("id_Directory") ||ctxParam.getType().equals("id_List Of Value"))) {
|
||||
typeToGenerate=JavaTypesManager.getTypeToGenerate(ctxParam.getType(),true);
|
||||
}
|
||||
|
||||
if (ctxParam.getType().equals("id_Password")) {
|
||||
%>
|
||||
String pwd_<%=ctxParam.getName()%>_value = context.getProperty("<%=ctxParam.getName()%>");
|
||||
@@ -602,13 +635,7 @@
|
||||
}
|
||||
}
|
||||
<%
|
||||
continue;
|
||||
}
|
||||
String typeToGenerate ="String";
|
||||
if( !(ctxParam.getType().equals("id_File") || ctxParam.getType().equals("id_Directory") ||ctxParam.getType().equals("id_List Of Value"))) {
|
||||
typeToGenerate=JavaTypesManager.getTypeToGenerate(ctxParam.getType(),true);
|
||||
}
|
||||
if(typeToGenerate.equals("java.util.Date")) {
|
||||
} else if(typeToGenerate.equals("java.util.Date")) {
|
||||
%>
|
||||
try{
|
||||
String context_<%=ctxParam.getName()%>_value = context.getProperty("<%=ctxParam.getName()%>");
|
||||
@@ -667,6 +694,10 @@
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<%//{B1 block%>
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
} <%/*close last method*/%>
|
||||
@@ -1259,13 +1290,11 @@ if (execStat) {
|
||||
} else {
|
||||
type = "ftp";
|
||||
}
|
||||
if ("ftp".equals(type)) { %>
|
||||
((com.enterprisedt.net.ftp.FTPClient) obj_conn).quit();
|
||||
<%} else if ("sftp".equals(type)) { %>
|
||||
if ("sftp".equals(type)) { %>
|
||||
((com.jcraft.jsch.ChannelSftp) obj_conn).quit();
|
||||
<%} else { %>
|
||||
((org.apache.commons.net.ftp.FTPSClient) obj_conn).disconnect();
|
||||
<%}%>
|
||||
<%} else { %>
|
||||
((org.apache.commons.net.ftp.FTPClient) obj_conn).disconnect();
|
||||
<%}%>
|
||||
}
|
||||
<% } %>
|
||||
} catch (java.lang.Exception e) {
|
||||
@@ -1440,12 +1469,14 @@ if (execStat) {
|
||||
<% } %>
|
||||
<% for (INode existNode : existComponentsList) { %>
|
||||
connections.put("col_<%=existNode.getUniqueName()%>", globalMap.get("col_<%=existNode.getUniqueName()%>"));
|
||||
<% } %>
|
||||
<% }
|
||||
|
||||
<% for (INode salesforceNode : salesforceComponentsList) { %>
|
||||
connections.put("conn_<%=salesforceNode.getUniqueName()%>", globalMap.get("conn_<%=salesforceNode.getUniqueName()%>"));
|
||||
<% } %>
|
||||
<% for (INode sapNode : sapComponentsList) { %>
|
||||
for (INode tcompV0ConnectionNode : tcompV0ComponentsList) { %>
|
||||
connections.put("<%=tcompV0ConnectionNode.getUniqueName()%>_connection", globalMap.get("<%=tcompV0ConnectionNode.getUniqueName()%>_connection"));
|
||||
connections.put("<%=tcompV0ConnectionNode.getUniqueName()%>_COMPONENT_RUNTIME_PROPERTIES", globalMap.get("<%=tcompV0ConnectionNode.getUniqueName()%>_COMPONENT_RUNTIME_PROPERTIES"));
|
||||
<% }
|
||||
|
||||
for (INode sapNode : sapComponentsList) { %>
|
||||
connections.put("conn_<%=sapNode.getUniqueName()%>", globalMap.get("conn_<%=sapNode.getUniqueName()%>"));
|
||||
<% } %>
|
||||
<% for (INode gsNode : gsComponentsList) { %>
|
||||
@@ -1509,12 +1540,10 @@ if (execStat) {
|
||||
}
|
||||
} else if (arg.startsWith("--log4jLevel=")) {
|
||||
log4jLevel = arg.substring(13);
|
||||
} else if (arg.startsWith("--monitoring=")) {//for trunjob call
|
||||
enableLogStash = "true".equalsIgnoreCase(arg.substring(13));
|
||||
}
|
||||
|
||||
if(!enableLogStash) {
|
||||
enableLogStash = "true".equalsIgnoreCase(System.getProperty("monitoring"));
|
||||
} else if (arg.startsWith("--monitoring") && arg.contains("=")) {//for trunjob call
|
||||
final int equal = arg.indexOf('=');
|
||||
final String key = arg.substring("--".length(), equal);
|
||||
System.setProperty(key, arg.substring(equal + 1));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -62,6 +62,8 @@ class IndexedRecordToRowStructGenerator {
|
||||
%>
|
||||
boolean <%=codeVarIsDynamicInitialized%> = false;
|
||||
routines.system.Dynamic <%=codeVarDynamic%> = new routines.system.Dynamic();
|
||||
//Workaround for TDI-44051, TcimpV0 do not need DbmsID
|
||||
<%=codeVarDynamic%>.setDbmsId("<%=cid%>");
|
||||
<%
|
||||
}
|
||||
|
||||
@@ -115,10 +117,11 @@ class IndexedRecordToRowStructGenerator {
|
||||
for (org.apache.avro.Schema.Field dynamicField_<%=cid%> : dynSchema_<%=cid%>.getFields()){
|
||||
routines.system.DynamicMetadata dynamicMetadata_<%=cid%> = new routines.system.DynamicMetadata();
|
||||
org.apache.avro.Schema dynamicFieldSchema_<%=cid%> = dynamicField_<%=cid%>.schema();
|
||||
String dbName = dynamicField_<%=cid%>.getProp("talend.field.dbColumnName");
|
||||
// set name
|
||||
dynamicMetadata_<%=cid%>.setName(dynamicField_<%=cid%>.name());
|
||||
// set db name
|
||||
dynamicMetadata_<%=cid%>.setDbName(dynamicField_<%=cid%>.name());
|
||||
dynamicMetadata_<%=cid%>.setDbName(dbName==null?dynamicField_<%=cid%>.name():dbName);
|
||||
// set nullable
|
||||
if (org.talend.daikon.avro.AvroUtils.isNullable(dynamicFieldSchema_<%=cid%>)) {
|
||||
dynamicMetadata_<%=cid%>.setNullable(true);
|
||||
|
||||
@@ -139,7 +139,7 @@ for (INode node : process.getNodesOfType("tRESTClient")) {
|
||||
}
|
||||
|
||||
boolean talendEsbJobFactory = actAsProvider || !process.getNodesOfType("tRouteInput").isEmpty();
|
||||
boolean talendEsbJob = talendEsbJobFactory || actAsConsumer || ProcessorUtilities.isEsbJob(process.getId(), process.getVersion());
|
||||
boolean talendEsbJob = talendEsbJobFactory || actAsConsumer || ProcessorUtilities.isEsbJob(process);
|
||||
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(process, "__LOG4J_ACTIVATE__"));
|
||||
|
||||
@@ -289,6 +289,15 @@ if(isRunInMultiThread){
|
||||
}
|
||||
<% } %>
|
||||
}
|
||||
|
||||
//if the stored or passed value is "<TALEND_NULL>" string, it mean null
|
||||
public String getStringValue(String key) {
|
||||
String origin_value = this.getProperty(key);
|
||||
if(NULL_VALUE_EXPRESSION_IN_COMMAND_STRING_FOR_CHILD_JOB_ONLY.equals(origin_value)) {
|
||||
return null;
|
||||
}
|
||||
return origin_value;
|
||||
}
|
||||
|
||||
<%
|
||||
for (IContextParameter ctxParam :params)
|
||||
|
||||
@@ -66,6 +66,7 @@ import org.talend.designer.codegen.model.CodeGeneratorEmittersPoolFactory;
|
||||
import org.talend.designer.codegen.model.CodeGeneratorInternalTemplatesFactoryProvider;
|
||||
import org.talend.designer.codegen.proxy.JetProxy;
|
||||
import org.talend.designer.core.generic.model.Component;
|
||||
import org.talend.designer.runprocess.ProcessorUtilities;
|
||||
|
||||
/**
|
||||
* CodeGenerator.
|
||||
@@ -353,8 +354,12 @@ public class CodeGenerator implements ICodeGenerator {
|
||||
.getDefault().getService(IResourcesDependenciesService.class);
|
||||
String resourcePathForContext = null;
|
||||
if (process instanceof IProcess2) {
|
||||
resourcePathForContext = resourceService.getResourcePathForContext(process,
|
||||
contextPar.getValue());
|
||||
String value = contextPar.getValue();
|
||||
// for runtime
|
||||
if (!ProcessorUtilities.isExportConfig()) {
|
||||
contextPar.setType(JavaTypesManager.FILE.getId());
|
||||
}
|
||||
resourcePathForContext = resourceService.getResourcePathForContext(process, value);
|
||||
} else {
|
||||
// for PreviewFileInputContentDataProcess run
|
||||
resourcePathForContext = resourceService.getResourceItemFilePath(contextPar.getValue());
|
||||
|
||||
@@ -94,7 +94,7 @@ public class JavaRoutineSynchronizer extends AbstractRoutineSynchronizer {
|
||||
|
||||
private void syncRoutineItems(Collection<RoutineItem> routineObjects, boolean forceUpdate) throws SystemException {
|
||||
for (RoutineItem routineItem : routineObjects) {
|
||||
syncRoutine(routineItem, true, true, forceUpdate);
|
||||
syncRoutine(routineItem, true, forceUpdate);
|
||||
}
|
||||
syncSystemRoutine(ProjectManager.getInstance().getCurrentProject());
|
||||
}
|
||||
|
||||
@@ -28,9 +28,9 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.ResourceBundle;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Semaphore;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
@@ -70,7 +70,6 @@ import org.talend.core.model.components.ComponentCategory;
|
||||
import org.talend.core.model.components.ComponentManager;
|
||||
import org.talend.core.model.components.ComponentProviderInfo;
|
||||
import org.talend.core.model.components.ComponentUtilities;
|
||||
import org.talend.core.model.components.EComponentType;
|
||||
import org.talend.core.model.components.IComponent;
|
||||
import org.talend.core.model.components.IComponentsFactory;
|
||||
import org.talend.core.model.components.IComponentsHandler;
|
||||
@@ -838,23 +837,21 @@ public class ComponentsFactory implements IComponentsFactory {
|
||||
init(false);
|
||||
}
|
||||
|
||||
for (IComponent comp : componentList) {
|
||||
if (comp.getComponentType() != EComponentType.JOBLET) {
|
||||
continue;
|
||||
}
|
||||
String comName = comp.getName();
|
||||
if (comp != null && paletteType.equals(comp.getPaletteType())) {
|
||||
if (comName.equals(name)) {
|
||||
return comp;
|
||||
} else if (new JobletUtil().matchExpression(comName)) {
|
||||
String[] names = comName.split(":"); //$NON-NLS-1$
|
||||
comName = names[1];
|
||||
if (comName.equals(name)) {
|
||||
return comp;
|
||||
}
|
||||
// check if reference joblet component presents
|
||||
JobletUtil jobletUtils = new JobletUtil();
|
||||
Optional<IComponent> result = jobletUtils.findComponentByName(componentList, name, paletteType);
|
||||
if (!result.isPresent()) {
|
||||
// check if any name matching joblet component presents
|
||||
if (jobletUtils.matchExpression(name)) {
|
||||
name = StringUtils.substringAfterLast(name, ":"); //$NON-NLS-1$
|
||||
if (StringUtils.isNotBlank(name)) {
|
||||
result = jobletUtils.findComponentByName(componentList, name, paletteType);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (result.isPresent()) {
|
||||
return result.get();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
<project name="org.talend.designer.components.libs" default="buildall" basedir=".">
|
||||
|
||||
<target name="buildall">
|
||||
<ant antfile="filecopy/build.xml" target="process" inheritall="no" />
|
||||
<ant antfile="talend_file_enhanced_20070724/build.xml" target="process" inheritall="no" />
|
||||
<ant antfile="sugarCRMManagement/build.xml" target="process" inheritall="no" />
|
||||
<ant antfile="TalendSAX/build.xml" target="process" inheritall="no" />
|
||||
</target>
|
||||
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -41,8 +41,8 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<version>1.10</version>
|
||||
</dependency>
|
||||
<version>1.19</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
<resources>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<groupId>org.talend.components.lib</groupId>
|
||||
<artifactId>commons-net-ftps-proxy</artifactId>
|
||||
<version>3.6.1-talend-20190128</version>
|
||||
<version>3.6.1-talend-20190819</version>
|
||||
|
||||
<name>commons-net-talend</name>
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ package org.talend.ftp;
|
||||
import java.lang.reflect.Field;
|
||||
import java.lang.reflect.Method;
|
||||
import java.net.Socket;
|
||||
import java.net.InetAddress;
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.net.ssl.SSLContext;
|
||||
@@ -29,11 +30,13 @@ public class SSLSessionReuseFTPSClient extends FTPSClient {
|
||||
final Object cache = sessionHostPortCache.get(context);
|
||||
final Method putMethod = cache.getClass().getDeclaredMethod("put", Object.class, Object.class);
|
||||
putMethod.setAccessible(true);
|
||||
final Method getHostMethod = socket.getClass().getDeclaredMethod("getHost");
|
||||
getHostMethod.setAccessible(true);
|
||||
Object host = getHostMethod.invoke(socket);
|
||||
final String key =
|
||||
String.format("%s:%s", host, String.valueOf(socket.getPort())).toLowerCase(Locale.ROOT);
|
||||
InetAddress address = socket.getInetAddress();
|
||||
int port = socket.getPort();
|
||||
|
||||
String key = String.format("%s:%s", address.getHostName(), String.valueOf(port)).toLowerCase(Locale.ROOT);
|
||||
putMethod.invoke(cache, key, session);
|
||||
|
||||
key = String.format("%s:%s", address.getHostAddress(), String.valueOf(port)).toLowerCase(Locale.ROOT);
|
||||
putMethod.invoke(cache, key, session);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
||||
3
main/plugins/org.talend.designer.components.libs/libs_src/filecopy/.gitignore
vendored
Normal file
3
main/plugins/org.talend.designer.components.libs/libs_src/filecopy/.gitignore
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
.classpath
|
||||
.project
|
||||
target/
|
||||
@@ -1,88 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project name="org.talend.designer.components.libs" default="process" basedir=".">
|
||||
|
||||
<property name="component.plugin.home" value="../../../org.talend.designer.components.localprovider/components" />
|
||||
|
||||
<!-- #################################################### -->
|
||||
|
||||
<!-- modification 1: config -->
|
||||
<property name="jar.name" value="filecopy.jar" />
|
||||
<property name="component.name" value="tFileCopy" />
|
||||
<property name="author.name" value="wyang" />
|
||||
|
||||
<!-- modification 2: compile classpath -->
|
||||
<path id="compile.classpath">
|
||||
</path>
|
||||
|
||||
<!-- #################################################### -->
|
||||
|
||||
|
||||
<!-- sourcecode and final jar path -->
|
||||
<property name="source.home" value="." />
|
||||
<property name="jar.home" value="${component.plugin.home}/${component.name}/${jar.name}" />
|
||||
|
||||
<!-- temp dir for clasee files -->
|
||||
<property name="build.dir" value="../../build" />
|
||||
|
||||
<!-- compile option -->
|
||||
<property name="compile.debug" value="true" />
|
||||
<property name="compile.deprecation" value="false" />
|
||||
<property name="compile.optimize" value="true" />
|
||||
|
||||
|
||||
<target name="process" description="prepare a temp dir">
|
||||
<antcall target="prepare" />
|
||||
<antcall target="compile" />
|
||||
<antcall target="clean" />
|
||||
</target>
|
||||
|
||||
<target name="prepare" description="prepare a temp dir">
|
||||
<delete dir="${build.dir}" />
|
||||
<mkdir dir="${build.dir}" />
|
||||
<mkdir dir="${build.dir}/classes" />
|
||||
</target>
|
||||
|
||||
<target name="compile" description="Compile Java sources">
|
||||
|
||||
<!-- compile -->
|
||||
<javac srcdir="${source.home}" destdir="${build.dir}/classes" debug="${compile.debug}" deprecation="${compile.deprecation}" optimize="${compile.optimize}">
|
||||
<classpath refid="compile.classpath" />
|
||||
</javac>
|
||||
|
||||
<!-- include source code -->
|
||||
<copy todir="${build.dir}/classes">
|
||||
<fileset dir="${source.home}">
|
||||
<exclude name="build.xml" />
|
||||
</fileset>
|
||||
</copy>
|
||||
|
||||
<!-- make jar -->
|
||||
<tstamp>
|
||||
<format property="date" pattern="yyyy-MM-dd HH:mm:ss" />
|
||||
</tstamp>
|
||||
|
||||
<jar destfile="${build.dir}/${jar.name}" basedir="${build.dir}/classes">
|
||||
<manifest>
|
||||
<!-- who -->
|
||||
<attribute name="Built-By" value="${author.name}" />
|
||||
<!-- when -->
|
||||
<attribute name="Built-Date" value="${date}"/>
|
||||
<!-- JDK version -->
|
||||
<attribute name="Created-By" value="${java.version} (${java.vendor})" />
|
||||
<!-- Information about the program itself -->
|
||||
<attribute name="Implementation-Vendor" value="Talend SA" />
|
||||
<attribute name="Implementation-Title" value="${jar.name}" />
|
||||
<attribute name="Implementation-Version" value="1.0" />
|
||||
</manifest>
|
||||
</jar>
|
||||
|
||||
<!-- move jar -->
|
||||
<move file="${build.dir}/${jar.name}" tofile="${jar.home}" />
|
||||
|
||||
</target>
|
||||
|
||||
<target name="clean" description="clean the temp dir">
|
||||
<delete dir="${build.dir}" />
|
||||
<mkdir dir="${build.dir}" />
|
||||
</target>
|
||||
</project>
|
||||
@@ -1,190 +0,0 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.nio.MappedByteBuffer;
|
||||
import java.nio.channels.FileChannel;
|
||||
import java.security.AccessController;
|
||||
import java.security.PrivilegedAction;
|
||||
|
||||
/**
|
||||
* DOC Administrator class global comment. Detailled comment
|
||||
*/
|
||||
public class FileCopy {
|
||||
|
||||
private final static long L_SIZE = 100 * 1024 * 1024; // 100M
|
||||
|
||||
private final static long M_SIZE = 10 * 1024 * 1024; // 10M
|
||||
|
||||
private final static long S_SIZE = 0; // 0M
|
||||
|
||||
public static void copyFile(String srcFileName, String desFileName, boolean delSrc) throws Exception {
|
||||
|
||||
FileInputStream srcInputStream = null;
|
||||
try{
|
||||
srcInputStream = new FileInputStream(srcFileName);
|
||||
long lastModified = new File(srcFileName).lastModified();
|
||||
int available = srcInputStream.available();
|
||||
if (available > L_SIZE) {// X > 100M
|
||||
copyFileL(srcFileName, srcInputStream, desFileName, delSrc);
|
||||
} else if (available > M_SIZE) {// 10M < X <100M
|
||||
copyFileM(srcFileName, srcInputStream, desFileName, delSrc);
|
||||
} else { // X < 10M
|
||||
copyFileS(srcFileName, srcInputStream, desFileName, delSrc);
|
||||
}
|
||||
// keep modification_time
|
||||
new File(desFileName).setLastModified(lastModified);
|
||||
}finally{
|
||||
if(srcInputStream!=null){
|
||||
srcInputStream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyFileS(String srcFileName, FileInputStream srcInputStream, String desFileName, boolean delSrc)
|
||||
throws IOException {
|
||||
File source = new File(srcFileName);
|
||||
File dest = new File(desFileName);
|
||||
|
||||
FileInputStream in = null;
|
||||
FileOutputStream out = null;
|
||||
try {
|
||||
in = srcInputStream;
|
||||
out = new FileOutputStream(dest);
|
||||
|
||||
byte[] buf = new byte[1024];
|
||||
int len = 0;
|
||||
while ((len = in.read(buf)) != -1) {
|
||||
out.write(buf, 0, len);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
if (delSrc) {
|
||||
source.delete();
|
||||
}
|
||||
|
||||
} finally {
|
||||
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyFileM(String srcFileName, FileInputStream srcInputStream, String desFileName, boolean delSrc)
|
||||
throws IOException {
|
||||
File source = new File(srcFileName);
|
||||
File dest = new File(desFileName);
|
||||
|
||||
FileChannel in = null;
|
||||
FileChannel out = null;
|
||||
try {
|
||||
in = srcInputStream.getChannel();
|
||||
out = new FileOutputStream(dest).getChannel();
|
||||
|
||||
int maxCount = (32 * 1024 * 1024) - (28 * 1024);
|
||||
long size = in.size();
|
||||
long position = 0;
|
||||
while (position < size) {
|
||||
position += in.transferTo(position, maxCount, out);
|
||||
}
|
||||
|
||||
in.close();
|
||||
out.close();
|
||||
|
||||
if (delSrc) {
|
||||
source.delete();
|
||||
}
|
||||
} finally {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void copyFileL(String srcFileName, FileInputStream srcInputStream, String desFileName, boolean delSrc)
|
||||
throws Exception {
|
||||
File source = new File(srcFileName);
|
||||
File dest = new File(desFileName);
|
||||
|
||||
FileChannel in = null, out = null;
|
||||
try {
|
||||
in = srcInputStream.getChannel();
|
||||
out = new FileOutputStream(dest).getChannel();
|
||||
|
||||
long size = in.size();
|
||||
long position = 0;
|
||||
final long MAP_SIZE = 33525760;
|
||||
MappedByteBuffer buf = null;
|
||||
while (true) {
|
||||
if (position + MAP_SIZE >= size) {
|
||||
buf = in.map(FileChannel.MapMode.READ_ONLY, position, size - position);
|
||||
out.write(buf);
|
||||
//For But TDI-26493, here must clean first, or it can't delete
|
||||
clean(buf);
|
||||
break;
|
||||
} else {
|
||||
buf = in.map(FileChannel.MapMode.READ_ONLY, position, MAP_SIZE);
|
||||
out.write(buf);
|
||||
// here must clean first, or it can't delete
|
||||
clean(buf);
|
||||
position += MAP_SIZE;
|
||||
}
|
||||
}
|
||||
in.close();
|
||||
out.close();
|
||||
|
||||
if (delSrc) {
|
||||
source.delete();
|
||||
}
|
||||
|
||||
} finally {
|
||||
if (in != null) {
|
||||
in.close();
|
||||
}
|
||||
if (out != null) {
|
||||
out.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static void clean(final Object buffer) throws Exception {
|
||||
AccessController.doPrivileged(new PrivilegedAction() {
|
||||
|
||||
public Object run() {
|
||||
try {
|
||||
Method getCleanerMethod = buffer.getClass().getMethod("cleaner", new Class[0]);
|
||||
getCleanerMethod.setAccessible(true);
|
||||
sun.misc.Cleaner cleaner = (sun.misc.Cleaner) getCleanerMethod.invoke(buffer, new Object[0]);
|
||||
cleaner.clean();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,73 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>filecopy</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>talend-copy</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
<java.source.version>1.8</java.source.version>
|
||||
<junit5.version>5.4.2</junit5.version>
|
||||
</properties>
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceSnapshot/</url>
|
||||
<snapshots>
|
||||
<enabled>true</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>false</enabled>
|
||||
</releases>
|
||||
</snapshotRepository>
|
||||
<repository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
<snapshots>
|
||||
<enabled>false</enabled>
|
||||
</snapshots>
|
||||
<releases>
|
||||
<enabled>true</enabled>
|
||||
</releases>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-api</artifactId>
|
||||
<version>${junit5.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<version>${junit5.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.8.1</version>
|
||||
<configuration>
|
||||
<source>${java.source.version}</source>
|
||||
<target>${java.source.version}</target>
|
||||
<showDeprecation>true</showDeprecation>
|
||||
<showWarnings>true</showWarnings>
|
||||
<fork>true</fork>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
@@ -0,0 +1,49 @@
|
||||
// ============================================================================
|
||||
//
|
||||
// Copyright (C) 2006-2019 Talend Inc. - www.talend.com
|
||||
//
|
||||
// This source code is available under agreement available at
|
||||
// %InstallDIR%\features\org.talend.rcp.branding.%PRODUCTNAME%\%PRODUCTNAME%license.txt
|
||||
//
|
||||
// You should have received a copy of the agreement
|
||||
// along with this program; if not, write to Talend SA
|
||||
// 9 rue Pages 92150 Suresnes, France
|
||||
//
|
||||
// ============================================================================
|
||||
package org.talend;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardCopyOption;
|
||||
|
||||
/**
|
||||
* DOC Administrator class global comment. Detailled comment
|
||||
*/
|
||||
public class FileCopy {
|
||||
|
||||
/** Private constructor, only static methods */
|
||||
private FileCopy() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy files.
|
||||
*
|
||||
* @param srcFileName : file name for source file.
|
||||
* @param desFileName : file name for destination file.
|
||||
* @param delSrc : true if delete source.
|
||||
* @throws IOException : if IO pb.
|
||||
*/
|
||||
public static void copyFile(String srcFileName, String desFileName, boolean delSrc) throws IOException {
|
||||
final File source = new File(srcFileName);
|
||||
final File destination = new File(desFileName);
|
||||
|
||||
if (delSrc) {
|
||||
// move : more efficient if in same FS and mustr delete existing file.
|
||||
Files.move(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
} else {
|
||||
Files.copy(source.toPath(), destination.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,128 @@
|
||||
package org.talend;
|
||||
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.StandardOpenOption;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Test for FileCopy.class with diffents file size.
|
||||
*
|
||||
* @author clesaec
|
||||
*
|
||||
*/
|
||||
class FileCopyTest {
|
||||
|
||||
@Test
|
||||
void testCopyFile() throws Exception {
|
||||
final URL repCopy = Thread.currentThread().getContextClassLoader().getResource("copy");
|
||||
|
||||
File small = this.buildFile("small.txt", 10L * 1024L);
|
||||
small.deleteOnExit();
|
||||
File smallCopy = new File(repCopy.getPath(), "small.txt");
|
||||
smallCopy.deleteOnExit();
|
||||
|
||||
FileCopy.copyFile(small.getPath(), smallCopy.getPath(), false);
|
||||
|
||||
Assertions.assertTrue(smallCopy.exists(), "small file fail to copy (not created)");
|
||||
Assertions.assertTrue(small.exists(), "small file : original file deleted");
|
||||
Assertions.assertEquals(smallCopy.length(), small.length(), "Size error");
|
||||
|
||||
File medium = this.buildFile("medium.txt", 30L * 1024L * 1024L);
|
||||
medium.deleteOnExit();
|
||||
File mediumCopy = new File(repCopy.getPath(), "medium.txt");
|
||||
mediumCopy.deleteOnExit();
|
||||
|
||||
FileCopy.copyFile(medium.getPath(), mediumCopy.getPath(), false);
|
||||
|
||||
Assertions.assertTrue(mediumCopy.exists(), "medium file fail to copy (not created)");
|
||||
Assertions.assertTrue(medium.exists(), "medium file : original file deleted");
|
||||
Assertions.assertEquals(mediumCopy.length(), medium.length(), "Size error");
|
||||
|
||||
File large = this.buildFile("large.txt", 110L * 1024L * 1024L);
|
||||
large.deleteOnExit();
|
||||
long startTime = System.nanoTime();
|
||||
File largeCopy = new File(repCopy.getPath(), "large.txt");
|
||||
long duration = System.nanoTime() - startTime;
|
||||
System.out.println("Duration for 110 Mo file : " + TimeUnit.NANOSECONDS.toMicros(duration) + " µs");
|
||||
largeCopy.deleteOnExit();
|
||||
|
||||
FileCopy.copyFile(large.getPath(), largeCopy.getPath(), false);
|
||||
|
||||
Assertions.assertTrue(largeCopy.exists(), "small file fail to copy (not created)");
|
||||
Assertions.assertTrue(large.exists(), "small file : original file deleted");
|
||||
Assertions.assertEquals(largeCopy.length(), large.length(), "Size error");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCopyMv() throws Exception {
|
||||
final URL repCopy = Thread.currentThread().getContextClassLoader().getResource("copy");
|
||||
|
||||
File file = this.buildFile("fileToMove.txt", 10L * 1024L);
|
||||
file.deleteOnExit();
|
||||
File copy = new File(repCopy.getPath(), "fileToMove.txt");
|
||||
long referenceSize = file.length();
|
||||
if (copy.exists()) {
|
||||
copy.delete();
|
||||
}
|
||||
copy.deleteOnExit();
|
||||
|
||||
FileCopy.copyFile(file.getPath(), copy.getPath(), true);
|
||||
|
||||
Assertions.assertFalse(file.exists(), "file not delete");
|
||||
Assertions.assertTrue(copy.exists(), "small file : original file deleted");
|
||||
Assertions.assertEquals(referenceSize, copy.length(), "Size error");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCopyWithDelete() throws Exception {
|
||||
final URL repCopy = Thread.currentThread().getContextClassLoader().getResource("copy");
|
||||
|
||||
File file = this.buildFile("fileToDelete.txt", 10L * 1024L);
|
||||
file.deleteOnExit();
|
||||
File copy = new File(repCopy.getPath(), "fileToDelete.txt");
|
||||
long referenceSize = file.length();
|
||||
if (!copy.exists()) {
|
||||
copy.createNewFile();
|
||||
}
|
||||
copy.deleteOnExit();
|
||||
|
||||
FileCopy.copyFile(file.getPath(), copy.getPath(), true);
|
||||
|
||||
Assertions.assertFalse(file.exists(), "file not delete");
|
||||
Assertions.assertTrue(copy.exists(), "small file : original file deleted");
|
||||
Assertions.assertEquals(referenceSize, copy.length(), "Size error");
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a new file for testing.
|
||||
*
|
||||
* @param name : name of file.
|
||||
* @param minSize : minimum size.
|
||||
* @return the new file.
|
||||
* @throws IOException : on IO pb.
|
||||
*/
|
||||
private File buildFile(String name, long minSize) throws IOException {
|
||||
final URL repGenerated = Thread.currentThread().getContextClassLoader().getResource("generated");
|
||||
final File generatedFile = new File(repGenerated.getPath(), name);
|
||||
if (generatedFile.exists()) {
|
||||
generatedFile.delete();
|
||||
}
|
||||
final String data = "{ data to put in generated file for it have the desired sized }" + System.lineSeparator();
|
||||
|
||||
long nbeIteration = (minSize / data.length()) + 1;
|
||||
try (BufferedWriter writer = Files.newBufferedWriter(generatedFile.toPath(), StandardOpenOption.CREATE)) {
|
||||
for (long i = 0; i < nbeIteration; i++) {
|
||||
writer.append(data);
|
||||
}
|
||||
}
|
||||
|
||||
return generatedFile;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
Just here to not have an empty directory.
|
||||
@@ -0,0 +1 @@
|
||||
Just here to not have an empty directory.
|
||||
@@ -7,7 +7,7 @@
|
||||
<groupId>net.sf.json-lib</groupId>
|
||||
<artifactId>json-lib</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
<version>2.4.1-talend</version>
|
||||
<version>2.4.5-talend</version>
|
||||
<name>json-lib</name>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package net.sf.json.util;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import net.sf.json.JSONArray;
|
||||
import net.sf.json.JSONException;
|
||||
import net.sf.json.JSONNull;
|
||||
@@ -414,7 +415,7 @@ public class JSONTokener {
|
||||
}
|
||||
|
||||
try{
|
||||
return NumberUtils.createNumber(s);
|
||||
return createNumber(s);
|
||||
}catch( Exception e ){
|
||||
return s;
|
||||
}
|
||||
@@ -435,6 +436,26 @@ public class JSONTokener {
|
||||
return s;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method has been added to fix https://jira.talendforge.org/browse/TDI-42689
|
||||
*
|
||||
* @param s The String representation of the number
|
||||
* @return The Number instance
|
||||
*/
|
||||
private Number createNumber(String s){
|
||||
boolean isDecimal = s.indexOf('.') != -1;
|
||||
|
||||
if(isDecimal){
|
||||
Double d = Double.valueOf(s);
|
||||
if(Double.POSITIVE_INFINITY == Math.abs(d)){
|
||||
return new BigDecimal(s);
|
||||
}
|
||||
return d;
|
||||
}
|
||||
|
||||
return NumberUtils.createNumber(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Look at the next character in the source string.
|
||||
*
|
||||
|
||||
@@ -104,16 +104,17 @@ public final class JSONUtils {
|
||||
return "null";
|
||||
}
|
||||
|
||||
// Shave off trailing zeros and decimal point, if possible.
|
||||
// Shave off trailing zeros. Keep decimal to keep type double
|
||||
|
||||
String s = Double.toString( d );
|
||||
if( s.indexOf( '.' ) > 0 && s.indexOf( 'e' ) < 0 && s.indexOf( 'E' ) < 0 ){
|
||||
while( s.endsWith( "0" ) ){
|
||||
while(s.charAt(s.length() - 1) == '0'){
|
||||
if(s.endsWith(".0")){
|
||||
break;
|
||||
}
|
||||
|
||||
s = s.substring( 0, s.length() - 1 );
|
||||
}
|
||||
if( s.endsWith( "." ) ){
|
||||
s = s.substring( 0, s.length() - 1 );
|
||||
}
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
@@ -184,14 +185,12 @@ public final class JSONUtils {
|
||||
return Integer.class;
|
||||
}else if( isLong( n ) ){
|
||||
return Long.class;
|
||||
}else if( isFloat( n ) ){
|
||||
return Float.class;
|
||||
}else if( isBigInteger( n ) ){
|
||||
return BigInteger.class;
|
||||
}else if( isBigDecimal( n ) ){
|
||||
return BigDecimal.class;
|
||||
}else if( isDouble( n ) ){
|
||||
return Double.class;
|
||||
}else if( isBigDecimal( n ) ){
|
||||
return BigDecimal.class;
|
||||
}else{
|
||||
throw new JSONException( "Unsupported type" );
|
||||
}
|
||||
@@ -442,17 +441,19 @@ public final class JSONUtils {
|
||||
}
|
||||
testValidity( n );
|
||||
|
||||
// Shave off trailing zeros and decimal point, if possible.
|
||||
// Shave off trailing zeros. Keep decimal to keep type double
|
||||
|
||||
String s = n.toString();
|
||||
if( s.indexOf( '.' ) > 0 && s.indexOf( 'e' ) < 0 && s.indexOf( 'E' ) < 0 ){
|
||||
while( s.endsWith( "0" ) ){
|
||||
s = s.substring( 0, s.length() - 1 );
|
||||
}
|
||||
if( s.endsWith( "." ) ){
|
||||
while(s.charAt(s.length() - 1) == '0'){
|
||||
if(s.endsWith(".0")){
|
||||
break;
|
||||
}
|
||||
|
||||
s = s.substring( 0, s.length() - 1 );
|
||||
}
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -163,6 +163,11 @@ public class XMLSerializer {
|
||||
*/
|
||||
private boolean useLongDecimals;
|
||||
|
||||
/**
|
||||
* flag for if parse empty elements as empty strings
|
||||
*/
|
||||
private boolean useEmptyStrings;
|
||||
|
||||
/**
|
||||
* Creates a new XMLSerializer with default options.<br>
|
||||
* <ul>
|
||||
@@ -803,6 +808,8 @@ public class XMLSerializer {
|
||||
clazz = JSONTypes.OBJECT;
|
||||
}else if( JSONTypes.ARRAY.compareToIgnoreCase( clazzText ) == 0 ){
|
||||
clazz = JSONTypes.ARRAY;
|
||||
} else if(JSONTypes.STRING.equalsIgnoreCase(clazzText)) {
|
||||
clazz = JSONTypes.STRING;
|
||||
}
|
||||
}
|
||||
return clazz;
|
||||
@@ -1414,6 +1421,8 @@ public class XMLSerializer {
|
||||
String text = element.getValue();
|
||||
params = StringUtils.split( paramsAttribute.getValue(), "," );
|
||||
setOrAccumulate( jsonObject, key, new JSONFunction( params, text ) );
|
||||
} else if( useEmptyStrings && clazz != null && clazz.equalsIgnoreCase(JSONTypes.STRING) ) {
|
||||
setTextValue(jsonObject, key, element);
|
||||
}else{
|
||||
if( isArray( element, false ) ){
|
||||
setOrAccumulate( jsonObject, key, processArrayElement( element, defaultType ) );
|
||||
@@ -1421,19 +1430,23 @@ public class XMLSerializer {
|
||||
setOrAccumulate( jsonObject, key, simplifyValue( jsonObject,
|
||||
processObjectElement( element, defaultType ) ) );
|
||||
}else{
|
||||
String value;
|
||||
if( isKeepCData && isCData( element ) ){
|
||||
value = "<![CDATA[" + element.getValue() + "]]>";
|
||||
}else{
|
||||
value = element.getValue();
|
||||
}
|
||||
setOrAccumulate( jsonObject, key, trimSpaceFromValue( value ) );
|
||||
setTextValue(jsonObject, key, element);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void setTextValue(final JSONObject jsonObject, final String key, final Element element) {
|
||||
String value;
|
||||
if( isKeepCData && isCData( element ) ){
|
||||
value = "<![CDATA[" + element.getValue() + "]]>";
|
||||
}else{
|
||||
value = element.getValue();
|
||||
}
|
||||
setOrAccumulate( jsonObject, key, trimSpaceFromValue( value ) );
|
||||
}
|
||||
|
||||
private boolean isCData( Element element ) {
|
||||
if( element.getChildCount() == 1 ){
|
||||
final Node child = element.getChild( 0 );
|
||||
@@ -1493,6 +1506,14 @@ public class XMLSerializer {
|
||||
return str;
|
||||
}
|
||||
|
||||
public void setUseEmptyStrings(boolean useEmptyStrings) {
|
||||
this.useEmptyStrings = useEmptyStrings;
|
||||
}
|
||||
|
||||
public boolean isUseEmptyStrings() {
|
||||
return this.useEmptyStrings;
|
||||
}
|
||||
|
||||
private static class CustomElement extends Element {
|
||||
private static String getName( String name ) {
|
||||
int colon = name.indexOf( ':' );
|
||||
|
||||
@@ -27,6 +27,7 @@ import net.sf.json.processors.PropertyNameProcessor;
|
||||
import net.sf.json.sample.BeanA;
|
||||
import net.sf.json.sample.BeanB;
|
||||
import net.sf.json.sample.BeanC;
|
||||
import net.sf.json.sample.BeanD;
|
||||
import net.sf.json.sample.BeanFoo;
|
||||
import net.sf.json.sample.BeanWithFunc;
|
||||
import net.sf.json.sample.ChildBean;
|
||||
@@ -1042,6 +1043,17 @@ public class TestJSONObject extends TestCase {
|
||||
JSONArray.toArray( jsonObject.getJSONArray( "intarray" ) ) );
|
||||
}
|
||||
|
||||
public void testToBean_BeanD() {
|
||||
String json = "{bool:true,integer:1,string:\"json\",doublearray:[4.2424245783E7, 123456789.2424245783E7, 6.0]}";
|
||||
JSONObject jsonObject = JSONObject.fromObject( json );
|
||||
BeanD bean = (BeanD) JSONObject.toBean( jsonObject, BeanD.class );
|
||||
assertEquals( jsonObject.get( "bool" ), Boolean.valueOf( bean.isBool() ) );
|
||||
assertEquals( jsonObject.get( "integer" ), new Integer( bean.getInteger() ) );
|
||||
assertEquals( jsonObject.get( "string" ), bean.getString() );
|
||||
Assertions.assertEquals( bean.getDoublearray(),
|
||||
JSONArray.toArray( jsonObject.getJSONArray( "doublearray" ) ) );
|
||||
}
|
||||
|
||||
public void testToBean_ClassBean() {
|
||||
JSONObject json = new JSONObject();
|
||||
json.element( "klass", "java.lang.Object" );
|
||||
@@ -1050,9 +1062,29 @@ public class TestJSONObject extends TestCase {
|
||||
assertEquals( Object.class, bean.getKlass() );
|
||||
}
|
||||
|
||||
public void testToBean_DynaBean__BigInteger_BigDecimal() {
|
||||
public void testToBean_DynaBean__BigInteger_Double() {
|
||||
BigInteger l = new BigDecimal( "1.7976931348623157E308" ).toBigInteger();
|
||||
BigDecimal m = new BigDecimal( "1.7976931348623157E307" ).add( new BigDecimal( "0.0001" ) );
|
||||
JSONObject json = new JSONObject().element( "i", BigInteger.ZERO )
|
||||
.element( "d", MorphUtils.BIGDECIMAL_ONE )
|
||||
.element( "bi", l )
|
||||
.element( "bd", m );
|
||||
Object bean = JSONObject.toBean( json );
|
||||
Object i = ((MorphDynaBean) bean).get( "i" );
|
||||
Object d = ((MorphDynaBean) bean).get( "d" );
|
||||
assertTrue( i instanceof Integer );
|
||||
assertTrue( d instanceof Integer );
|
||||
|
||||
Object bi = ((MorphDynaBean) bean).get( "bi" );
|
||||
Object bd = ((MorphDynaBean) bean).get( "bd" );
|
||||
assertTrue( bi instanceof BigInteger );
|
||||
assertTrue( bd instanceof Double );
|
||||
}
|
||||
|
||||
|
||||
public void testToBean_DynaBean__BigInteger_BigDecimal() {
|
||||
BigInteger l = new BigDecimal( "1.7976931348623157E308" ).toBigInteger();
|
||||
BigDecimal m = new BigDecimal( "-1.7976931348623157E309" ).add( new BigDecimal( "0.0001" ) );
|
||||
JSONObject json = new JSONObject().element( "i", BigInteger.ZERO )
|
||||
.element( "d", MorphUtils.BIGDECIMAL_ONE )
|
||||
.element( "bi", l )
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package net.sf.json.sample;
|
||||
|
||||
import org.apache.commons.lang.builder.ToStringBuilder;
|
||||
import org.apache.commons.lang.builder.ToStringStyle;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author Andres Almiray <aalmiray@users.sourceforge.net>
|
||||
*/
|
||||
public class BeanD extends BeanA {
|
||||
private Double[] doublearray = new Double[3];
|
||||
|
||||
public Double[] getDoublearray() {
|
||||
return doublearray;
|
||||
}
|
||||
|
||||
public void setDoublearray(Double[] doublearray) {
|
||||
this.doublearray = doublearray;
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString( this, ToStringStyle.MULTI_LINE_STYLE );
|
||||
}
|
||||
}
|
||||
@@ -17,6 +17,7 @@
|
||||
package net.sf.json.util;
|
||||
|
||||
import java.io.StringWriter;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import net.sf.json.JSONFunction;
|
||||
@@ -93,7 +94,7 @@ public class TestJSONBuilder extends TestCase {
|
||||
.endObject();
|
||||
JSONObject jsonObj = JSONObject.fromObject( w.toString() );
|
||||
assertEquals( Boolean.TRUE, jsonObj.get( "bool" ) );
|
||||
assertEquals( new Double( 1.1d ), jsonObj.get( "numDouble" ) );
|
||||
assertEquals( Double.valueOf( "1.1" ), jsonObj.get( "numDouble" ) );
|
||||
assertEquals( new Long( 2 ).longValue(), ((Number) jsonObj.get( "numInt" )).longValue() );
|
||||
assertEquals( "text", jsonObj.get( "text" ) );
|
||||
assertTrue( JSONUtils.isFunction( jsonObj.get( "func" ) ) );
|
||||
|
||||
@@ -20,6 +20,8 @@ import junit.framework.TestCase;
|
||||
import net.sf.json.JSONFunction;
|
||||
import net.sf.json.JSONObject;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* @author Andres Almiray <aalmiray@users.sourceforge.net>
|
||||
*/
|
||||
@@ -85,7 +87,7 @@ public class TestJSONStringer extends TestCase {
|
||||
.endObject();
|
||||
JSONObject jsonObj = JSONObject.fromObject( b.toString() );
|
||||
assertEquals( Boolean.TRUE, jsonObj.get( "bool" ) );
|
||||
assertEquals( new Double( 1.1d ), jsonObj.get( "numDouble" ) );
|
||||
assertEquals( Double.valueOf( "1.1" ), jsonObj.get( "numDouble" ) );
|
||||
assertEquals( new Long( 2 ).longValue(), ((Number) jsonObj.get( "numInt" )).longValue() );
|
||||
assertEquals( "text", jsonObj.get( "text" ) );
|
||||
assertTrue( JSONUtils.isFunction( jsonObj.get( "func" ) ) );
|
||||
|
||||
@@ -44,7 +44,25 @@ public class TestJSONUtils extends TestCase {
|
||||
}
|
||||
|
||||
public void testDoubleToString_trailingZeros() {
|
||||
assertEquals( "200", JSONUtils.doubleToString( 200.00000 ) );
|
||||
assertEquals( "200.0", JSONUtils.doubleToString( 200.00000 ) );
|
||||
}
|
||||
|
||||
public void testDoubleToString() {
|
||||
Map<String, Double> expected = new HashMap<>();
|
||||
expected.put("200.0", 200.0d);
|
||||
expected.put("200.0", 200.000d);
|
||||
expected.put("200.1", 200.1d);
|
||||
expected.put("200.1", 200.10d);
|
||||
expected.put("200.1", 200.1000d);
|
||||
expected.put("200.12345", 200.12345d);
|
||||
expected.put("200.12345", 200.123450000d);
|
||||
expected.put("200.101", 200.101d);
|
||||
expected.put("1.0E-8", 1.0E-8);
|
||||
expected.put("200.0", 200d);
|
||||
|
||||
for(String key : expected.keySet()){
|
||||
assertEquals(key,JSONUtils.doubleToString(expected.get(key)));
|
||||
}
|
||||
}
|
||||
|
||||
public void testGetFunctionParams() {
|
||||
@@ -101,6 +119,28 @@ public class TestJSONUtils extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testNumberToString() {
|
||||
Map<String, Number> expected = new HashMap<>();
|
||||
|
||||
expected.put("0", Integer.valueOf("00000"));
|
||||
expected.put("123", Integer.valueOf("123"));
|
||||
expected.put("-123", Integer.valueOf("-123"));
|
||||
|
||||
expected.put("0.0", Double.valueOf("0"));
|
||||
expected.put("0.0", Double.valueOf("0.00000"));
|
||||
expected.put("120.0001", Double.valueOf("120.0001000"));
|
||||
expected.put("-120.0001", Double.valueOf("-120.0001000"));
|
||||
|
||||
expected.put("0.0", Float.valueOf("0"));
|
||||
expected.put("0.0", Float.valueOf("0.00000"));
|
||||
expected.put("120.0001", Float.valueOf("120.0001000"));
|
||||
expected.put("-120.0001", Float.valueOf("-120.0001000"));
|
||||
|
||||
for(String key : expected.keySet()) {
|
||||
assertEquals(key, JSONUtils.numberToString(expected.get(key)));
|
||||
}
|
||||
}
|
||||
|
||||
public void testQuote_emptyString() {
|
||||
assertEquals( "\"\"", JSONUtils.quote( "" ) );
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>talend-codegen-utils</artifactId>
|
||||
<!-- release for revert version of library -->
|
||||
<version>0.25.4</version>
|
||||
<version>0.28.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<properties>
|
||||
|
||||
@@ -51,6 +51,8 @@ public final class TypeConverter {
|
||||
|
||||
public static final String LIST = "id_List";
|
||||
|
||||
public static final String OBJECT = "id_Object";
|
||||
|
||||
private TypeConverter() {
|
||||
// Class provides static utility methods and shouldn't be instantiated
|
||||
}
|
||||
@@ -167,6 +169,8 @@ public final class TypeConverter {
|
||||
return SHORT;
|
||||
case "java.util.Date":
|
||||
return DATE;
|
||||
case "java.lang.Object":
|
||||
return OBJECT;
|
||||
default:
|
||||
throw new UnsupportedOperationException("Unrecognized java class " + javaClass);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>job-audit</artifactId>
|
||||
<version>1.0.1</version>
|
||||
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>job-audit</artifactId>
|
||||
<version>1.0</version>
|
||||
|
||||
<properties>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
</properties>
|
||||
|
||||
|
||||
<repositories>
|
||||
<repository>
|
||||
<id>talend_nexus</id>
|
||||
@@ -23,7 +23,7 @@
|
||||
<url>${talend.nexus.url}/nexus/content/repositories/TalendOpenSourceRelease/</url>
|
||||
</repository>
|
||||
</repositories>
|
||||
|
||||
|
||||
<distributionManagement>
|
||||
<snapshotRepository>
|
||||
<id>talend_nexus_deployment</id>
|
||||
@@ -46,32 +46,36 @@
|
||||
</releases>
|
||||
</repository>
|
||||
</distributionManagement>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.talend.daikon</groupId>
|
||||
<artifactId>daikon-audit</artifactId>
|
||||
<version>0.31.8</version>
|
||||
</dependency>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.talend.daikon</groupId>
|
||||
<artifactId>audit-logback</artifactId>
|
||||
<version>0.31.8</version>
|
||||
<groupId>org.talend.daikon</groupId>
|
||||
<artifactId>audit-common</artifactId>
|
||||
<version>1.8.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
<version>1.3.0-alpha4</version>
|
||||
<groupId>org.talend.daikon</groupId>
|
||||
<artifactId>audit-log4j1</artifactId>
|
||||
<version>1.8.0</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<dependency>
|
||||
<groupId>log4j</groupId>
|
||||
<artifactId>log4j</artifactId>
|
||||
<version>1.2.17</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-api</artifactId>
|
||||
<version>2.12.1</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.logging.log4j</groupId>
|
||||
<artifactId>log4j-core</artifactId>
|
||||
<version>2.12.1</version>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -18,13 +18,30 @@ public class JobEventAuditLoggerFactory {
|
||||
final AuditConfigurationMap config = AuditConfiguration.loadFromProperties(properties);
|
||||
|
||||
AbstractBackend logger = null;
|
||||
String loggerClass = "org.talend.logging.audit.logback.LogbackBackend";
|
||||
|
||||
//load log4j2 implement firstly
|
||||
String loggerClass = "org.talend.logging.audit.log4j2.Log4j2Backend";
|
||||
try {
|
||||
final Class<?> clz = Class.forName(loggerClass);
|
||||
logger = (AbstractBackend) clz.getConstructor(AuditConfigurationMap.class).newInstance(config);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
throw new RuntimeException("Unable to load backend " + loggerClass, e);
|
||||
}
|
||||
final Class<?> clz = Class.forName(loggerClass);
|
||||
logger = (AbstractBackend) clz.getConstructor(AuditConfigurationMap.class).newInstance(config);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
//load log4j1 implement if not found log4j2
|
||||
if (logger == null) {
|
||||
loggerClass = "org.talend.logging.audit.log4j1.Log4j1Backend";
|
||||
try {
|
||||
final Class<?> clz = Class.forName(loggerClass);
|
||||
logger = (AbstractBackend) clz.getConstructor(AuditConfigurationMap.class).newInstance(config);
|
||||
} catch (ReflectiveOperationException e) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
|
||||
if(logger == null) {
|
||||
throw new RuntimeException("Unable to load backend : " + loggerClass);
|
||||
}
|
||||
|
||||
final DefaultAuditLoggerBase loggerBase = new DefaultAuditLoggerBase(logger, config);
|
||||
|
||||
@@ -38,4 +55,4 @@ public class JobEventAuditLoggerFactory {
|
||||
return (T) Proxy.newProxyInstance(AuditLoggerFactory.class.getClassLoader(), new Class<?>[] { clz },
|
||||
new ProxyEventAuditLogger(auditLoggerBase));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,8 @@ public class JobAuditLoggerTest {
|
||||
|
||||
public static void main(String[] args) {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("root.logger", "audit");
|
||||
String root_logger_name = "audit";
|
||||
props.setProperty("root.logger", root_logger_name);
|
||||
props.setProperty("encoding", "UTF-8");
|
||||
props.setProperty("application.name", "Talend Studio");
|
||||
props.setProperty("service.name", "Talend Studio Job");
|
||||
@@ -19,6 +20,10 @@ public class JobAuditLoggerTest {
|
||||
props.setProperty("appender.file.maxsize", "52428800");
|
||||
props.setProperty("appender.file.maxbackup", "20");
|
||||
props.setProperty("host", "false");
|
||||
|
||||
org.apache.logging.log4j.core.config.Configurator.setLevel(root_logger_name, org.apache.logging.log4j.Level.DEBUG);
|
||||
//org.apache.log4j.Logger.getLogger("audit").setLevel(org.apache.log4j.Level.DEBUG);
|
||||
|
||||
final JobAuditLogger logger = JobEventAuditLoggerFactory.createJobAuditLogger(props);
|
||||
Context context = JobContextBuilder.create().jobName("fetch_from_s3_every_day").jobId("jobid_123")
|
||||
.jobVersion("0.1").connectorType("tXMLMAP").connectorId("tXMLMap_1")
|
||||
@@ -31,4 +36,4 @@ public class JobAuditLoggerTest {
|
||||
logger.flowOutput(context);
|
||||
logger.jobstop(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,16 +3,16 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>talend-mscrm</artifactId>
|
||||
<version>3.4-20190513</version>
|
||||
<version>3.4-20210618</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>talend-mscrm</name>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<cxf.version>3.1.1</cxf.version>
|
||||
<odata.version>4.3.0</odata.version>
|
||||
<slf4j.version>1.7.12</slf4j.version>
|
||||
<jackson.version>2.11.4</jackson.version>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
</properties>
|
||||
|
||||
@@ -105,11 +105,27 @@
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.microsoft.azure</groupId>
|
||||
<artifactId>adal4j</artifactId>
|
||||
<version>1.1.1-patch</version>
|
||||
<version>1.1.1-20191012</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-core</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-databind</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.fasterxml.jackson.core</groupId>
|
||||
<artifactId>jackson-annotations</artifactId>
|
||||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
<build>
|
||||
@@ -122,21 +138,6 @@
|
||||
</resource>
|
||||
</resources>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>default-jar</id>
|
||||
<phase>package</phase>
|
||||
<goals>
|
||||
<goal>jar</goal>
|
||||
</goals>
|
||||
<configuration>
|
||||
<outputDirectory>../../../org.talend.libraries.crm/lib</outputDirectory>
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
|
||||
@@ -1,8 +1,11 @@
|
||||
package org.talend.ms.crm;
|
||||
|
||||
import java.rmi.RemoteException;
|
||||
import java.util.Iterator;
|
||||
import java.util.UUID;
|
||||
|
||||
import javax.naming.AuthenticationException;
|
||||
import javax.naming.ServiceUnavailableException;
|
||||
import javax.xml.stream.XMLStreamException;
|
||||
|
||||
import org.apache.axiom.om.OMAbstractFactory;
|
||||
@@ -19,28 +22,32 @@ import org.apache.axis2.client.ServiceClient;
|
||||
import org.apache.axis2.context.ConfigurationContext;
|
||||
import org.apache.axis2.context.ConfigurationContextFactory;
|
||||
import org.apache.axis2.transport.http.HTTPConstants;
|
||||
import org.apache.axis2.transport.http.HTTPTransportConstants;
|
||||
import org.apache.axis2.transport.http.HttpTransportProperties;
|
||||
import org.apache.axis2.transport.http.HttpTransportProperties.ProxyProperties;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.datacontract.schemas._2004._07.system_collections_generic.KeyValuePairOfEndpointTypestringztYlk6OT;
|
||||
import org.apache.http.HttpEntity;
|
||||
import org.apache.http.HttpStatus;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.impl.client.CloseableHttpClient;
|
||||
import org.apache.http.impl.client.HttpClients;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.apache.olingo.client.api.http.HttpClientException;
|
||||
import org.talend.ms.crm.odata.ClientConfiguration;
|
||||
import org.talend.ms.crm.odata.authentication.AuthStrategyFactory;
|
||||
import org.talend.ms.crm.odata.authentication.IAuthStrategy;
|
||||
import org.talend.ms.crm.sdk.Instance;
|
||||
import org.talend.ms.crm.sdk.OnlineAuthenticationPolicy;
|
||||
import org.talend.ms.crm.sdk.OrganizationServiceStubWrapper;
|
||||
import org.talend.ms.crm.sdk.RequestDateTimeData;
|
||||
import org.talend.ms.crm.sdk.SecurityData;
|
||||
import org.talend.ms.crm.sdk.WsdlTokenManager;
|
||||
|
||||
import com.microsoft.schemas.xrm._2011.contracts.DiscoveryServiceStub;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.MapperFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.OrganizationServiceStub;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.discovery.EndpointType;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteDocument;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteDocument.Execute;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteResponseDocument;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.discovery.ExecuteResponseDocument.ExecuteResponse;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.discovery.OrganizationDetail;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.discovery.RetrieveOrganizationRequest;
|
||||
import com.microsoft.schemas.xrm._2011.contracts.discovery.RetrieveOrganizationResponse;
|
||||
|
||||
// ============================================================================
|
||||
//
|
||||
@@ -63,21 +70,15 @@ public class MSCRMClient {
|
||||
|
||||
static Logger logger = Logger.getLogger(MSCRMClient.class.getName());
|
||||
|
||||
/**
|
||||
* Microsoft account (e.g. youremail@live.com) or Microsoft Office 365 (Org ID e.g.
|
||||
* youremail@yourorg.onmicrosoft.com) User Name.
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* Microsoft account or Microsoft Office 365 (Org ID) Password.
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* Unique Name of the organization
|
||||
*/
|
||||
private String orgName;
|
||||
|
||||
/**
|
||||
* Unique Name of the organization
|
||||
*/
|
||||
private ClientConfiguration clientConfiguration;
|
||||
|
||||
/**
|
||||
* Suffix for the Flat WSDL
|
||||
@@ -86,88 +87,84 @@ public class MSCRMClient {
|
||||
|
||||
private OrganizationServiceStub serviceStub;
|
||||
|
||||
private Integer timeout;
|
||||
private String discoveryServiceURL = "https://globaldisco.crm.dynamics.com/api/discovery/v2.0/Instances";
|
||||
|
||||
/**
|
||||
* This sample application registration values are available for all online instances
|
||||
* This is suggested to use for development and prototyping purposes.For production use, you should create an AppId or ClientId that is specific
|
||||
* to your tenant in the Azure Management portal.
|
||||
*
|
||||
*/
|
||||
private static final String DEFAULT_CLIENT_ID = "51f81489-12ee-4a9e-aaae-a2591f45987d";
|
||||
|
||||
private IAuthStrategy authStrategy;
|
||||
|
||||
private Boolean reuseHttpClient;
|
||||
public MSCRMClient(ClientConfiguration clientConfiguration, String orgName, String discoveryServiceURL) throws AuthenticationException {
|
||||
this.clientConfiguration = clientConfiguration;
|
||||
this.orgName = orgName;
|
||||
this.discoveryServiceURL = discoveryServiceURL;
|
||||
init();
|
||||
|
||||
private int maxConnectionRetries = 5;
|
||||
}
|
||||
|
||||
private void init() throws AuthenticationException {
|
||||
if (clientConfiguration != null && discoveryServiceURL != null && discoveryServiceURL.indexOf("/api/discovery/") > 0) {
|
||||
clientConfiguration.setResource(discoveryServiceURL.substring(0, discoveryServiceURL.indexOf("/api/discovery/")));
|
||||
}
|
||||
|
||||
if(clientConfiguration != null) {
|
||||
if (discoveryServiceURL != null && discoveryServiceURL.indexOf("/api/discovery/") > 0) {
|
||||
clientConfiguration.setResource(discoveryServiceURL.substring(0, discoveryServiceURL.indexOf("/api/discovery/")));
|
||||
}
|
||||
if (clientConfiguration.getClientId()==null || clientConfiguration.getClientId().isEmpty()) {
|
||||
clientConfiguration.setClientId(DEFAULT_CLIENT_ID);
|
||||
}
|
||||
}
|
||||
|
||||
private int attemptsInterval = 1000;
|
||||
|
||||
public MSCRMClient(String username, String password, String orgName) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
this.orgName = orgName;
|
||||
authStrategy = AuthStrategyFactory.createAuthStrategy(this.clientConfiguration);
|
||||
authStrategy.init();
|
||||
|
||||
}
|
||||
|
||||
public void setTimeout(Integer timeout) {
|
||||
this.timeout = timeout;
|
||||
}
|
||||
|
||||
public void setReuseHttpClient(Boolean reuseHttpClient) {
|
||||
this.reuseHttpClient = reuseHttpClient;
|
||||
}
|
||||
|
||||
public void setMaxConnectionRetries(int maxConnectionRetries) {
|
||||
this.maxConnectionRetries = maxConnectionRetries;
|
||||
}
|
||||
|
||||
public void setAttemptsInterval(int attemptsInterval) {
|
||||
this.attemptsInterval = attemptsInterval;
|
||||
}
|
||||
|
||||
public OrganizationServiceStub getOnlineConnection(String discoveryServiceURL) throws Exception {
|
||||
return new OrganizationServiceStubWrapper(doGetOnlineConnection(discoveryServiceURL), this, discoveryServiceURL,
|
||||
maxConnectionRetries, attemptsInterval);
|
||||
public OrganizationServiceStub getOnlineConnection() throws Exception {
|
||||
return new OrganizationServiceStubWrapper(doGetOnlineConnection(), this, discoveryServiceURL,
|
||||
clientConfiguration.getMaxRetryTimes(), clientConfiguration.getIntervalTime());
|
||||
}
|
||||
|
||||
/**
|
||||
* URL for the Discovery Service For North America Microsoft account, discovery service url is
|
||||
* https://dev.crm.dynamics.com/XRMServices/2011/Discovery.svc Microsoft office 365, discovery service url is
|
||||
* https://disco.crm.dynamics.com/XRMServices/2011/Discovery.svc To use appropriate discovery service url for other
|
||||
* Organization information is stored in the Instance table of the Discovery Service. To see the kind of information contained in that table,
|
||||
* send an HTTP GET request to the service for one of your instances.
|
||||
* environments refer http://technet.microsoft.com/en-us/library/gg309401.aspx
|
||||
*
|
||||
* @throws Exception
|
||||
*/
|
||||
public OrganizationServiceStub doGetOnlineConnection(String discoveryServiceURL) throws Exception {
|
||||
public OrganizationServiceStub doGetOnlineConnection() throws Exception {
|
||||
|
||||
try {
|
||||
// Retrieve the authentication policy for the discovery service.
|
||||
OnlineAuthenticationPolicy discoveryPolicy = new OnlineAuthenticationPolicy(discoveryServiceURL + FlatWSDLSuffix);
|
||||
WsdlTokenManager discoeryTokenManager = new WsdlTokenManager();
|
||||
// Authenticate the user using the discovery authentication policy.
|
||||
SecurityData discoverySecurityData = discoeryTokenManager.authenticate(discoveryServiceURL, username, password,
|
||||
discoveryPolicy.getAppliesTo(), discoveryPolicy.getPolicy(), discoveryPolicy.getIssuerUri());
|
||||
// Retrieve discovery stub using organization URL with the security data.
|
||||
DiscoveryServiceStub discoveryServiceStub = createDiscoveryServiceStub(discoveryServiceURL, discoverySecurityData);
|
||||
// Retrieve organization service url using discovery stub.
|
||||
String orgUrl = discoverOrganizationUrl(discoveryServiceStub, orgName);
|
||||
// The discovery service stub cannot be reused against the organization service
|
||||
// as the Issuer and AppliesTo may differ between the discovery and organization services.
|
||||
// Retrieve the authentication policy for the organization service.
|
||||
OnlineAuthenticationPolicy organizationPolicy = new OnlineAuthenticationPolicy(orgUrl + FlatWSDLSuffix);
|
||||
WsdlTokenManager orgTokenManager = new WsdlTokenManager();
|
||||
// Authenticate the user using the organization authentication policy.
|
||||
SecurityData securityData = orgTokenManager.authenticate(orgUrl, username, password,
|
||||
organizationPolicy.getAppliesTo(), organizationPolicy.getPolicy(), organizationPolicy.getIssuerUri());
|
||||
String serviceURL = discoveryServiceURL;
|
||||
if(!discoveryServiceURL.contains("(")) {
|
||||
serviceURL = discoveryServiceURL+"(UniqueName='"+orgName+"')";
|
||||
}
|
||||
|
||||
String orgUrl = getOrgURL( serviceURL);
|
||||
// The discovery service stub cannot be reused against the organization service
|
||||
// as the Issuer and AppliesTo may differ between the discovery and organization services.
|
||||
// Retrieve the authentication policy for the organization service.
|
||||
OnlineAuthenticationPolicy organizationPolicy = new OnlineAuthenticationPolicy(orgUrl + FlatWSDLSuffix);
|
||||
WsdlTokenManager orgTokenManager = new WsdlTokenManager();
|
||||
// Authenticate the user using the organization authentication policy.
|
||||
SecurityData securityData = orgTokenManager.authenticate(orgUrl, clientConfiguration.getUserName(), clientConfiguration.getPassword(),
|
||||
organizationPolicy.getAppliesTo(), organizationPolicy.getPolicy(), organizationPolicy.getIssuerUri());
|
||||
|
||||
// Retrieve organization stub using organization URL with the security data.
|
||||
serviceStub = createOrganizationServiceStub(orgUrl, securityData);
|
||||
// Retrieve organization stub using organization URL with the security data.
|
||||
serviceStub = createOrganizationServiceStub(orgUrl, securityData);
|
||||
|
||||
Options options = serviceStub._getServiceClient().getOptions();
|
||||
if (reuseHttpClient != null) {
|
||||
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.REUSE_HTTP_CLIENT, reuseHttpClient);
|
||||
}
|
||||
if (timeout != null) {
|
||||
options.setTimeOutInMilliSeconds(Long.valueOf(timeout));
|
||||
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.SO_TIMEOUT, timeout);
|
||||
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CONNECTION_TIMEOUT, timeout);
|
||||
}
|
||||
|
||||
} catch (IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage e) {
|
||||
throw new Exception(e.getFaultMessage().getDiscoveryServiceFault().getMessage());
|
||||
}
|
||||
Options options = serviceStub._getServiceClient().getOptions();
|
||||
|
||||
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.REUSE_HTTP_CLIENT, clientConfiguration.isReuseHttpClient());
|
||||
options.setTimeOutInMilliSeconds(Long.valueOf(clientConfiguration.getTimeout()));
|
||||
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.SO_TIMEOUT, clientConfiguration.getTimeout());
|
||||
options.setProperty(org.apache.axis2.transport.http.HTTPConstants.CONNECTION_TIMEOUT, clientConfiguration.getTimeout());
|
||||
return serviceStub;
|
||||
|
||||
}
|
||||
@@ -184,18 +181,6 @@ public class MSCRMClient {
|
||||
}
|
||||
}
|
||||
|
||||
private static DiscoveryServiceStub createDiscoveryServiceStub(String discoveryServiceURL, SecurityData securityData)
|
||||
throws RemoteException, XMLStreamException {
|
||||
try {
|
||||
DiscoveryServiceStub stub = new DiscoveryServiceStub(getConfigurationContext(), discoveryServiceURL);
|
||||
setServiceClientOptions(stub._getServiceClient(), securityData);
|
||||
return stub;
|
||||
} catch (RemoteException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
|
||||
private static void setServiceClientOptions(ServiceClient sc, SecurityData securityData) throws AxisFault, XMLStreamException {
|
||||
Options options = sc.getOptions();
|
||||
|
||||
@@ -305,45 +290,6 @@ public class MSCRMClient {
|
||||
return ctx;
|
||||
}
|
||||
|
||||
private static String discoverOrganizationUrl(DiscoveryServiceStub serviceStub, String organizationUniqueName)
|
||||
throws RemoteException, IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage {
|
||||
try {
|
||||
RetrieveOrganizationRequest request = RetrieveOrganizationRequest.Factory.newInstance();
|
||||
|
||||
request.setUniqueName(organizationUniqueName);
|
||||
|
||||
Execute exe = Execute.Factory.newInstance();
|
||||
exe.setRequest(request);
|
||||
|
||||
ExecuteDocument exeDoc = ExecuteDocument.Factory.newInstance();
|
||||
exeDoc.setExecute(exe);
|
||||
|
||||
ExecuteResponseDocument executeRespDoc = serviceStub.execute(exeDoc);
|
||||
ExecuteResponse executeResp = executeRespDoc.getExecuteResponse();
|
||||
|
||||
RetrieveOrganizationResponse result = (RetrieveOrganizationResponse) executeResp.getExecuteResult();
|
||||
|
||||
OrganizationDetail orgDetail = result.getDetail();
|
||||
|
||||
KeyValuePairOfEndpointTypestringztYlk6OT[] keyValuePairs = orgDetail.getEndpoints()
|
||||
.getKeyValuePairOfEndpointTypestringztYlk6OTArray();
|
||||
|
||||
for (KeyValuePairOfEndpointTypestringztYlk6OT keyValuePair : keyValuePairs) {
|
||||
|
||||
if (keyValuePair.getKey() == EndpointType.ORGANIZATION_SERVICE) {
|
||||
return keyValuePair.getValue();
|
||||
}
|
||||
}
|
||||
} catch (RemoteException e) {
|
||||
logger.error(e.getMessage());
|
||||
throw e;
|
||||
} catch (IDiscoveryService_Execute_DiscoveryServiceFaultFault_FaultMessage e) {
|
||||
logger.error(e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static HttpTransportProperties.ProxyProperties getProxyProperties() {
|
||||
String proxyHost = null;
|
||||
String proxyPort = null;
|
||||
@@ -369,5 +315,55 @@ public class MSCRMClient {
|
||||
}
|
||||
return proxyProps;
|
||||
}
|
||||
|
||||
private String getOrgURL(String discoveryServiceURL) throws ServiceUnavailableException {
|
||||
try {
|
||||
HttpGet request = new HttpGet(discoveryServiceURL);
|
||||
|
||||
// https://docs.microsoft.com/en-us/powerapps/developer/data-platform/webapi/discover-url-organization-web-api#authentication
|
||||
authStrategy.configureRequest(request);
|
||||
|
||||
try (CloseableHttpClient httpClient = HttpClients.createDefault();
|
||||
CloseableHttpResponse response = httpClient.execute(request)) {
|
||||
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
if(statusCode != HttpStatus.SC_NO_CONTENT && statusCode != HttpStatus.SC_CREATED && statusCode != HttpStatus.SC_OK) {
|
||||
String message = null;
|
||||
if (statusCode == HttpStatus.SC_NOT_FOUND ) {
|
||||
message = "The organization '"+orgName+"' does not exist.";
|
||||
} else {
|
||||
message = response.getStatusLine().getReasonPhrase();
|
||||
}
|
||||
throw new HttpClientException(message);
|
||||
}
|
||||
|
||||
HttpEntity entity = response.getEntity();
|
||||
String orgUrl = null;
|
||||
if (entity != null) {
|
||||
String result = EntityUtils.toString(entity);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true);
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
JsonNode tree = mapper.readTree(result);
|
||||
Iterator<JsonNode> iter = tree.path("value").elements();
|
||||
while (iter.hasNext()){
|
||||
JsonNode node = iter.next();
|
||||
Instance instance = mapper.readValue(node.toString(), Instance.class);
|
||||
// Should only return one instance.
|
||||
if(orgName.equals(instance.getUniqueName())) {
|
||||
orgUrl = instance.getApiUrl() + "/XRMServices/2011/Organization.svc";
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if(orgUrl == null) {
|
||||
throw new HttpClientException("No organization available.");
|
||||
}
|
||||
return orgUrl;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new ServiceUnavailableException(e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,85 @@
|
||||
package org.talend.ms.crm.sdk;
|
||||
|
||||
public class Instance {
|
||||
|
||||
public String id;
|
||||
|
||||
public String uniqueName;
|
||||
|
||||
public String urlName;
|
||||
|
||||
public String friendlyName;
|
||||
|
||||
public String state;
|
||||
|
||||
public String version;
|
||||
|
||||
public String url;
|
||||
|
||||
public String apiUrl;
|
||||
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(String id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getUniqueName() {
|
||||
return uniqueName;
|
||||
}
|
||||
|
||||
public void setUniqueName(String uniqueName) {
|
||||
this.uniqueName = uniqueName;
|
||||
}
|
||||
|
||||
public String getUrlName() {
|
||||
return urlName;
|
||||
}
|
||||
|
||||
public void setUrlName(String urlName) {
|
||||
this.urlName = urlName;
|
||||
}
|
||||
|
||||
public String getFriendlyName() {
|
||||
return friendlyName;
|
||||
}
|
||||
|
||||
public void setFriendlyName(String friendlyName) {
|
||||
this.friendlyName = friendlyName;
|
||||
}
|
||||
|
||||
public String getState() {
|
||||
return state;
|
||||
}
|
||||
|
||||
public void setState(String state) {
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public String getVersion() {
|
||||
return version;
|
||||
}
|
||||
|
||||
public void setVersion(String version) {
|
||||
this.version = version;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public String getApiUrl() {
|
||||
return apiUrl;
|
||||
}
|
||||
|
||||
public void setApiUrl(String apiUrl) {
|
||||
this.apiUrl = apiUrl;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -100,7 +100,7 @@ public class OrganizationServiceStubWrapper extends OrganizationServiceStub {
|
||||
}
|
||||
|
||||
private void renewToken() throws Exception {
|
||||
orgStub = client.doGetOnlineConnection(discoveryServiceUrl);
|
||||
orgStub = client.doGetOnlineConnection();
|
||||
}
|
||||
|
||||
private void sleep() {
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<artifactId>talendExcel-1.4-20190531</artifactId>
|
||||
<artifactId>talendExcel-1.6-20210127</artifactId>
|
||||
<version>6.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
|
||||
@@ -69,6 +69,10 @@ public class ExcelTool {
|
||||
private int rowAccessWindowSize = SXSSFWorkbook.DEFAULT_WINDOW_SIZE;// used in auto flush
|
||||
|
||||
private boolean isTrackAllColumns = false;
|
||||
|
||||
private boolean isTruncateExceedingCharacters = false;
|
||||
|
||||
private static final int CELL_CHARACTERS_LIMIT = 32767;
|
||||
|
||||
public ExcelTool() {
|
||||
cellStylesMapping = new HashMap<>();
|
||||
@@ -274,7 +278,10 @@ public class ExcelTool {
|
||||
|
||||
public void addCellValue(String stringValue) {
|
||||
addCell();
|
||||
curCell.setCellValue(stringValue);
|
||||
String value = isTruncateExceedingCharacters && stringValue != null && stringValue.length() > CELL_CHARACTERS_LIMIT
|
||||
? stringValue.substring(0, CELL_CHARACTERS_LIMIT)
|
||||
: stringValue;
|
||||
curCell.setCellValue(value);
|
||||
curCell.setCellStyle(getNormalCellStyle());
|
||||
}
|
||||
|
||||
@@ -349,4 +356,8 @@ public class ExcelTool {
|
||||
((SXSSFSheet) sheet).flushRows();
|
||||
}
|
||||
}
|
||||
|
||||
public void setTruncateExceedingCharacters(boolean isTruncateExceedingCharacters) {
|
||||
this.isTruncateExceedingCharacters = isTruncateExceedingCharacters;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<groupId>org.talend.components.lib</groupId>
|
||||
<artifactId>talendsap</artifactId>
|
||||
<name>talendsap</name>
|
||||
<version>1.0.1</version>
|
||||
<version>1.0.2</version>
|
||||
|
||||
<properties>
|
||||
<talend.nexus.url>https://artifacts-oss.talend.com</talend.nexus.url>
|
||||
|
||||
@@ -90,6 +90,7 @@ public class DocumentExtractor {
|
||||
List<Element> tablesAndChangingElements = new ArrayList<Element>(3);
|
||||
tablesAndChangingElements.add(functionElement.element("TABLES"));
|
||||
tablesAndChangingElements.add(functionElement.element("CHANGING"));
|
||||
tablesAndChangingElements.add(functionElement.element("OUTPUT"));
|
||||
|
||||
for(Element tablesOrChangingElement : tablesAndChangingElements) {
|
||||
if (tablesOrChangingElement == null) {
|
||||
@@ -121,6 +122,10 @@ public class DocumentExtractor {
|
||||
}
|
||||
result.add(row);
|
||||
}
|
||||
|
||||
if(!result.isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
@@ -49,11 +49,11 @@ public class DocumentHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public void addSingleParameter(String name, String value, boolean isChanging) {
|
||||
public void addSingleParameter(String name, String value, SAPParameterType parameter_type) {
|
||||
if(value == null) {
|
||||
value = "";
|
||||
}
|
||||
if (isChanging) {
|
||||
if (parameter_type == SAPParameterType.CHANGING) {
|
||||
correctChanging();
|
||||
changing.addElement(name).setText(value);
|
||||
} else {
|
||||
@@ -62,8 +62,8 @@ public class DocumentHelper {
|
||||
}
|
||||
}
|
||||
|
||||
public void addStructParameter(String name, boolean isChanging) {
|
||||
if (isChanging) {
|
||||
public void addStructParameter(String name, SAPParameterType parameter_type) {
|
||||
if (parameter_type == SAPParameterType.CHANGING) {
|
||||
correctChanging();
|
||||
currentStruct = changing.addElement(name);
|
||||
} else {
|
||||
@@ -79,13 +79,16 @@ public class DocumentHelper {
|
||||
currentStruct.addElement(name).setText(value);
|
||||
}
|
||||
|
||||
public void addTableParameter(String name, boolean isChanging) {
|
||||
if (isChanging) {
|
||||
public void addTableParameter(String name, SAPParameterType parameter_type) {
|
||||
if (parameter_type == SAPParameterType.CHANGING) {
|
||||
correctChanging();
|
||||
currentTable = changing.addElement(name);
|
||||
} else {
|
||||
} else if(parameter_type == SAPParameterType.TABLES) {
|
||||
correctTables();
|
||||
currentTable = tables.addElement(name);
|
||||
} else {
|
||||
correctInput();
|
||||
currentTable = input.addElement(name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,18 +111,18 @@ public class DocumentHelper {
|
||||
DocumentHelper helper = new DocumentHelper();
|
||||
helper.setFunctionName("READ_TABLE_FUNCTION");
|
||||
|
||||
helper.addSingleParameter("ID", "1", true);
|
||||
helper.addSingleParameter("NAME", "gaoyan", false);
|
||||
helper.addSingleParameter("ID", "1", SAPParameterType.CHANGING);
|
||||
helper.addSingleParameter("NAME", "gaoyan", SAPParameterType.IMPORT);
|
||||
|
||||
helper.addStructParameter("INFO", true);
|
||||
helper.addStructParameter("INFO", SAPParameterType.CHANGING);
|
||||
helper.addStructChildParameter("ID", "2");
|
||||
helper.addStructChildParameter("NAME", "wangwei");
|
||||
|
||||
helper.addStructParameter("INFO1", false);
|
||||
helper.addStructParameter("INFO1", SAPParameterType.IMPORT);
|
||||
helper.addStructChildParameter("ID1", "4");
|
||||
helper.addStructChildParameter("NAME1", "momo");
|
||||
|
||||
helper.addTableParameter("TABLE1", false);
|
||||
helper.addTableParameter("TABLE1", SAPParameterType.TABLES);
|
||||
for (int i = 0; i < 200000; i++) {
|
||||
helper.addTableRow();
|
||||
helper.addTableRowChildParameter("c1", i + "");
|
||||
@@ -132,7 +135,7 @@ public class DocumentHelper {
|
||||
helper.addTableRowChildParameter("c8", "wangwei" + i);
|
||||
}
|
||||
|
||||
helper.addTableParameter("TABLE2", false);
|
||||
helper.addTableParameter("TABLE2", SAPParameterType.TABLES);
|
||||
for (int i = 0; i < 2; i++) {
|
||||
helper.addTableRow();
|
||||
helper.addTableRowChildParameter("ID4", i + "");
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package org.talend.sap;
|
||||
|
||||
public enum SAPParameterType {
|
||||
IMPORT,
|
||||
CHANGING,
|
||||
TABLES,
|
||||
EXPORT
|
||||
}
|
||||
@@ -46,7 +46,7 @@
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-compress</artifactId>
|
||||
<version>1.10</version>
|
||||
<version>1.19</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
@@ -55,4 +55,4 @@
|
||||
<version>6.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
||||
</project>
|
||||
|
||||
@@ -5,9 +5,9 @@
|
||||
>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.talend.libraries</groupId>
|
||||
<groupId>org.talend.components.lib</groupId>
|
||||
<artifactId>thashfile</artifactId>
|
||||
<version>3.0-20170711</version>
|
||||
<version>3.1-20190910</version>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>thashfile</name>
|
||||
@@ -45,8 +45,8 @@
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
<version>3.5.1</version>
|
||||
<configuration>
|
||||
<source>1.7</source>
|
||||
<target>1.7</target>
|
||||
<source>1.8</source>
|
||||
<target>1.8</target>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
|
||||
@@ -9,45 +9,44 @@ import java.util.concurrent.ConcurrentHashMap;
|
||||
import org.talend.designer.components.hashfile.memory.AdvancedMemoryHashFile;
|
||||
|
||||
public class MapHashFile {
|
||||
//use this map instead of globalMap
|
||||
// use this map instead of globalMap
|
||||
private Map<String, AdvancedMemoryHashFile> resourceMap = new ConcurrentHashMap<>();
|
||||
//keep the present key of AdvancedMemoryHashFile as key and the previous key as value
|
||||
// keep the present key of AdvancedMemoryHashFile as key and the previous key as
|
||||
// value
|
||||
private Map<String, String> keyMap = new ConcurrentHashMap<>();
|
||||
//singleton
|
||||
// singleton
|
||||
private static final MapHashFile mhf = new MapHashFile();
|
||||
|
||||
public static TalendMultiThreadLockMap resourceLockMap = new TalendMultiThreadLockMap();
|
||||
public static TalendMultiThreadLockMap resourceLockMap = new TalendMultiThreadLockMap();
|
||||
|
||||
public static class TalendMultiThreadLockMap {
|
||||
public static class TalendMultiThreadLockMap {
|
||||
|
||||
private Map<Object, Object> tMultiTheadLockMap = new HashMap<Object, Object>();
|
||||
private Map<Object, Object> tMultiTheadLockMap = new ConcurrentHashMap<>();
|
||||
|
||||
public Object get(Object key) {
|
||||
return tMultiTheadLockMap.computeIfAbsent(key, k -> new Object());
|
||||
}
|
||||
|
||||
public void remove(Object key) {
|
||||
tMultiTheadLockMap.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
public synchronized Object get(Object key) {
|
||||
if (tMultiTheadLockMap.get(key) == null) {
|
||||
tMultiTheadLockMap.put(key, new Object());
|
||||
}
|
||||
return tMultiTheadLockMap.get(key);
|
||||
}
|
||||
|
||||
public synchronized void remove(Object key){
|
||||
tMultiTheadLockMap.remove(key);
|
||||
}
|
||||
}
|
||||
|
||||
private MapHashFile() {
|
||||
}
|
||||
|
||||
public static MapHashFile getMapHashFile() {
|
||||
return mhf;
|
||||
}
|
||||
|
||||
//get the linked AdvancedMemoryHashFile
|
||||
|
||||
// get the linked AdvancedMemoryHashFile
|
||||
public AdvancedMemoryHashFile getAdvancedMemoryHashFile(String key) {
|
||||
AdvancedMemoryHashFile amhf = resourceMap.get(key);
|
||||
String prekey = keyMap.get(key);
|
||||
//if present AdvancedMemoryHashFile is null get the AdvancedMemoryHashFile before present.
|
||||
// if present AdvancedMemoryHashFile is null get the AdvancedMemoryHashFile
|
||||
// before present.
|
||||
int size = keyMap.size();
|
||||
while(amhf==null && (size--)>0){
|
||||
while (amhf == null && (size--) > 0) {
|
||||
amhf = resourceMap.get(prekey);
|
||||
prekey = keyMap.get(prekey);
|
||||
}
|
||||
@@ -61,16 +60,18 @@ public class MapHashFile {
|
||||
public Map<String, String> getKeyMap() {
|
||||
return keyMap;
|
||||
}
|
||||
public void clearCache(String key){
|
||||
|
||||
public void clearCache(String key) {
|
||||
clearChildCache(getRootCache(key));
|
||||
}
|
||||
public void clearChildCache(String root){
|
||||
|
||||
public void clearChildCache(String root) {
|
||||
Set<String> set = keyMap.keySet();
|
||||
synchronized(keyMap) {
|
||||
synchronized (keyMap) {
|
||||
Iterator<String> it = set.iterator();
|
||||
while(it.hasNext()){
|
||||
while (it.hasNext()) {
|
||||
String key = it.next();
|
||||
if(root.equals(keyMap.get(key))){
|
||||
if (root.equals(keyMap.get(key))) {
|
||||
this.resourceMap.remove(key);
|
||||
this.keyMap.remove(key);
|
||||
clearChildCache(key);
|
||||
@@ -79,11 +80,11 @@ public class MapHashFile {
|
||||
}
|
||||
this.resourceMap.remove(root);
|
||||
}
|
||||
|
||||
public String getRootCache(String cache){
|
||||
|
||||
public String getRootCache(String cache) {
|
||||
String root;
|
||||
while((root = keyMap.get(cache))!=null){
|
||||
cache=root;
|
||||
while ((root = keyMap.get(cache)) != null) {
|
||||
cache = root;
|
||||
}
|
||||
return cache;
|
||||
}
|
||||
|
||||
@@ -54,11 +54,11 @@ for(IConnection conn : outgoingConns) {
|
||||
<%
|
||||
}
|
||||
}
|
||||
log4jCodeGenerateUtil.query(node);
|
||||
%>
|
||||
query_<%=cid %> = <%=dbquery%>;
|
||||
whetherReject_<%=cid%> = false;
|
||||
<%
|
||||
log4jCodeGenerateUtil.query(node, "query_" + cid);
|
||||
List<IMetadataTable> metadatas = node.getMetadataList();
|
||||
if ((metadatas!=null)&&(metadatas.size()>0)) {
|
||||
IMetadataTable metadata = metadatas.get(0);
|
||||
@@ -131,7 +131,7 @@ try {
|
||||
<%
|
||||
}
|
||||
}
|
||||
log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Execute the query: '\" + "+dbquery +" + \"' has finished.");
|
||||
log4jCodeGenerateUtil.logInfo(node,"info",cid+" - Execute the query: '\" + query_" + cid + " + \"' has finished.");
|
||||
%>
|
||||
<% //feature 0010425
|
||||
if(usePrepareStatement){
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
String user = ElementParameterParser.getValue(node, "__USER__");
|
||||
String node_type = ElementParameterParser.getValue(node, "__NODE_TYPE__");
|
||||
String node_count = ElementParameterParser.getValue(node, "__NODE_COUNT__");
|
||||
if (node_count.isEmpty()) {
|
||||
node_count = "1";
|
||||
}
|
||||
|
||||
boolean isLog4jEnabled = "true".equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
|
||||
@@ -88,52 +91,46 @@
|
||||
.withMasterUsername(<%=user%>)
|
||||
.withMasterUserPassword(decryptedPwd_<%=cid%>)
|
||||
|
||||
.withNodeType(<%=node_type%>)
|
||||
.withNodeType(<%=node_type%>);
|
||||
|
||||
<%
|
||||
if(new Integer(node_count) > 1){
|
||||
%>
|
||||
.withNumberOfNodes(<%=node_count%>)
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
.withClusterType("single-node")
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
//advanced settings
|
||||
<%if(parameterUtil.isValid(parameter_group_name)) {%>
|
||||
.withClusterParameterGroupName(<%=parameter_group_name%>)
|
||||
<%}%>
|
||||
|
||||
<%if(parameterUtil.isValid(subnet_group_name)) {%>
|
||||
.withClusterSubnetGroupName(<%=subnet_group_name%>)
|
||||
if (<%=node_count%> > 1) {
|
||||
request_<%=cid%> = request_<%=cid%>.withNumberOfNodes(<%=node_count%>);
|
||||
} else {
|
||||
request_<%=cid%> = request_<%=cid%>.withClusterType("single-node");
|
||||
}
|
||||
|
||||
//advanced settings
|
||||
<%if(parameterUtil.isValid(parameter_group_name)) {%>
|
||||
request_<%=cid%> = request_<%=cid%>.withClusterParameterGroupName(<%=parameter_group_name%>);
|
||||
<%}%>
|
||||
|
||||
<%if(parameterUtil.isValid(subnet_group_name)) {%>
|
||||
request_<%=cid%> = request_<%=cid%>.withClusterSubnetGroupName(<%=subnet_group_name%>);
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
if(publicly_accessible) {
|
||||
%>
|
||||
request_<%=cid%> = request_<%=cid%>.withPubliclyAccessible(true);
|
||||
<%if(set_public_ip_address) {%>
|
||||
request_<%=cid%> = request_<%=cid%>.withElasticIp(<%=elastic_ip%>);
|
||||
<%}%>
|
||||
|
||||
<%
|
||||
if(publicly_accessible) {
|
||||
%>
|
||||
.withPubliclyAccessible(true)
|
||||
<%if(set_public_ip_address) {%>
|
||||
.withElasticIp(<%=elastic_ip%>)
|
||||
<%}%>
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
.withPubliclyAccessible(false)
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
<%if(parameterUtil.isValid(availability_zone)) {%>
|
||||
.withAvailabilityZone(<%=availability_zone%>)
|
||||
<%}%>
|
||||
|
||||
<%if(parameterUtil.isValid(vpc_security_groupids)) {%>
|
||||
.withVpcSecurityGroupIds(<%=vpc_security_groupids%>.split(","))
|
||||
<%}%>
|
||||
;
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
request_<%=cid%> = request_<%=cid%>.withPubliclyAccessible(false);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
<%if(parameterUtil.isValid(availability_zone)) {%>
|
||||
request_<%=cid%> = request_<%=cid%>.withAvailabilityZone(<%=availability_zone%>);
|
||||
<%}%>
|
||||
|
||||
<%if(parameterUtil.isValid(vpc_security_groupids)) {%>
|
||||
request_<%=cid%> = request_<%=cid%>.withVpcSecurityGroupIds(<%=vpc_security_groupids%>.split(","));
|
||||
<%}%>
|
||||
|
||||
|
||||
com.amazonaws.services.redshift.model.Cluster result_<%=cid%> = client_<%=cid%>.createCluster(request_<%=cid%>);
|
||||
<%if(isLog4jEnabled) {%>
|
||||
|
||||
@@ -149,7 +149,7 @@
|
||||
<IMPORTS>
|
||||
<IMPORT
|
||||
NAME="Talen File Enhanced"
|
||||
MODULE="talend_file_enhanced_20070724.jar" MVN="mvn:org.talend.libraries/talend_file_enhanced_20070724/6.0.0" UrlPath="platform:/plugin/org.talend.libraries.custom/lib/talend_file_enhanced_20070724.jar"
|
||||
MODULE="talend_file_enhanced-1.1.jar" MVN="mvn:org.talend.components.lib/talend_file_enhanced/1.1" UrlPath="platform:/plugin/org.talend.libraries.custom/lib/talend_file_enhanced-1.1.jar"
|
||||
REQUIRED="true"
|
||||
/>
|
||||
</IMPORTS>
|
||||
|
||||
@@ -32,6 +32,8 @@
|
||||
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
|
||||
boolean useCustomNullMarker = ElementParameterParser.getBooleanValue(node, "__USE_CUSTOM_NULL_MARKER__");
|
||||
String nullMarker = useCustomNullMarker ? ElementParameterParser.getValue(node, "__CUSTOM_NULL_MARKER__") : "\"\\\\N\"";
|
||||
String passwordFieldName = "";
|
||||
|
||||
if (authMode.equals("OAUTH")) {
|
||||
@@ -360,7 +362,7 @@
|
||||
queryLoad_<%=cid%>.setDestinationTable(destinationTable_<%=cid%>);
|
||||
queryLoad_<%=cid%>.setSourceUris(java.util.Arrays.asList(<%=ElementParameterParser.getValue(node, "__GS_FILE__")%>));
|
||||
queryLoad_<%=cid%>.setSkipLeadingRows(<%=ElementParameterParser.getValue(node, "__GS_FILE_HEADER__")%>);
|
||||
queryLoad_<%=cid%>.setNullMarker("\\N");
|
||||
queryLoad_<%=cid%>.setNullMarker(<%= nullMarker %>);
|
||||
config_<%=cid%>.setLoad(queryLoad_<%=cid%>);
|
||||
|
||||
job_<%=cid%>.setConfiguration(config_<%=cid%>);
|
||||
@@ -536,7 +538,6 @@
|
||||
|
||||
com.google.cloud.bigquery.Schema schema_<%=cid%> = com.google.cloud.bigquery.Schema.of(fields_<%=cid%>);
|
||||
com.google.cloud.bigquery.TableInfo tableInfo_<%=cid%> = com.google.cloud.bigquery.TableInfo.newBuilder(tableId_<%=cid%>, com.google.cloud.bigquery.StandardTableDefinition.of(schema_<%=cid%>)).build();
|
||||
table_<%=cid%> = bigquery_<%=cid%>.create(tableInfo_<%=cid%>);
|
||||
loadJobBuilder_<%=cid%>.setSchema(schema_<%=cid%>);
|
||||
}
|
||||
|
||||
@@ -573,15 +574,16 @@
|
||||
loadJobBuilder_<%=cid%>.setDestinationTable(tableId_<%=cid%>);
|
||||
com.google.cloud.bigquery.CsvOptions.Builder csvOptions_<%=cid%> = com.google.cloud.bigquery.CsvOptions.newBuilder();
|
||||
csvOptions_<%=cid%>.setAllowQuotedNewLines(true);
|
||||
csvOptions_<%=cid%>.setSkipLeadingRows(<%=ElementParameterParser.getValue(node, "__GS_FILE_HEADER__")%>);
|
||||
|
||||
<%if("true".equals(ElementParameterParser.getValue(node, "__SET_FIELD_DELIMITER__"))) {
|
||||
%>
|
||||
loadJobBuilder_<%=cid%>.setFormatOptions(csvOptions_<%=cid%>.setFieldDelimiter(<%=fieldDelimiter%>).build());
|
||||
csvOptions_<%=cid%>.setFieldDelimiter(<%=fieldDelimiter%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
loadJobBuilder_<%=cid%>.setNullMarker("\\N");
|
||||
loadJobBuilder_<%=cid%>.setFormatOptions(csvOptions_<%=cid%>.build());
|
||||
loadJobBuilder_<%=cid%>.setNullMarker(<%= nullMarker %>);
|
||||
com.google.cloud.bigquery.Job job_<%=cid%> = bigquery_<%=cid%>.create(com.google.cloud.bigquery.JobInfo.of(loadJobBuilder_<%=cid%>.build()));
|
||||
job_<%=cid%> = job_<%=cid%>.waitFor(com.google.cloud.RetryOption.initialRetryDelay(org.threeten.bp.Duration.ofSeconds(1)));
|
||||
if (job_<%=cid%> != null && job_<%=cid%>.getStatus().getError() == null) {
|
||||
|
||||
@@ -173,10 +173,16 @@
|
||||
SHOW_IF="(SET_FIELD_DELIMITER == 'true')">
|
||||
<DEFAULT>","</DEFAULT>
|
||||
</PARAMETER>
|
||||
<PARAMETER NAME="DROP" FIELD="CHECK" REQUIRED="true" NUM_ROW="25" SHOW_IF="AUTH_MODE == 'SERVICEACCOUNT'">
|
||||
<PARAMETER NAME="USE_CUSTOM_NULL_MARKER" FIELD="CHECK" NUM_ROW="25">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
<PARAMETER NAME="CUSTOM_NULL_MARKER" FIELD="TEXT" NUM_ROW="25" SHOW_IF="USE_CUSTOM_NULL_MARKER=='true'">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
<PARAMETER NAME="DROP" FIELD="CHECK" REQUIRED="true" NUM_ROW="30" SHOW_IF="AUTH_MODE == 'SERVICEACCOUNT'">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
<PARAMETER NAME="ENCODING" FIELD="ENCODING_TYPE" NUM_ROW="30"
|
||||
<PARAMETER NAME="ENCODING" FIELD="ENCODING_TYPE" NUM_ROW="35"
|
||||
REQUIRED="true" REPOSITORY_VALUE="ENCODING">
|
||||
<DEFAULT>"ISO-8859-15"</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
@@ -40,6 +40,8 @@ ENCODING.NAME=Encoding
|
||||
TOKEN_NAME.NAME=token properties File Name
|
||||
SET_FIELD_DELIMITER.NAME=Set the field delimiter
|
||||
FIELD_DELIMITER.NAME=
|
||||
USE_CUSTOM_NULL_MARKER.NAME=Use custom null marker
|
||||
CUSTOM_NULL_MARKER.NAME=
|
||||
DROP.NAME=Drop table if exists
|
||||
|
||||
DIE_ON_ERROR.NAME=Die on error
|
||||
|
||||
@@ -21,7 +21,7 @@ class BigQueryUtil_<%=cid%> {
|
||||
private String genTempName(String prefix){
|
||||
return "temp_" + prefix + java.util.UUID.randomUUID().toString().replaceAll("-", "") + "<%=cid%>".toLowerCase().replaceAll("[^a-z0-9]", "0").replaceAll("^[^a-z]", "a") + Integer.toHexString(java.util.concurrent.ThreadLocalRandom.current().nextInt());
|
||||
}
|
||||
|
||||
|
||||
public void cleanup() throws Exception{
|
||||
if(useLargeResult){
|
||||
bigqueryclient.tables().delete(projectId, tempDataset, tempTable).execute();
|
||||
@@ -38,11 +38,11 @@ class BigQueryUtil_<%=cid%> {
|
||||
job.setConfiguration(config);
|
||||
List<com.google.api.services.bigquery.model.TableReference> referencedTables = bigqueryclient.jobs().insert(projectId, job).execute().getStatistics().getQuery().getReferencedTables();
|
||||
if(referencedTables != null && !referencedTables.isEmpty()) {
|
||||
location = bigqueryclient.tables().get(projectId, referencedTables.get(0).getDatasetId(), referencedTables.get(0).getTableId()).execute().getLocation();
|
||||
location = bigqueryclient.tables().get(referencedTables.get(0).getProjectId(), referencedTables.get(0).getDatasetId(), referencedTables.get(0).getTableId()).execute().getLocation();
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
||||
|
||||
private void createDataset(String location) throws Exception {
|
||||
com.google.api.services.bigquery.model.Dataset dataset = new com.google.api.services.bigquery.model.Dataset().setDatasetReference(new com.google.api.services.bigquery.model.DatasetReference().setProjectId(projectId).setDatasetId(tempDataset));
|
||||
if(location != null) {
|
||||
@@ -53,11 +53,11 @@ class BigQueryUtil_<%=cid%> {
|
||||
dataset.setDescription(description);
|
||||
bigqueryclient.datasets().insert(projectId, dataset).execute();
|
||||
}
|
||||
|
||||
|
||||
public com.google.api.services.bigquery.model.Job executeQuery(String query, boolean useLargeResult) throws Exception{
|
||||
return executeQuery(query, useLargeResult, true);
|
||||
}
|
||||
|
||||
|
||||
public com.google.api.services.bigquery.model.Job executeQuery(String query, boolean useLargeResult, boolean useLegacySql) throws Exception{
|
||||
com.google.api.services.bigquery.model.JobConfigurationQuery queryConfig = new com.google.api.services.bigquery.model.JobConfigurationQuery();
|
||||
queryConfig.setQuery(query);
|
||||
@@ -74,13 +74,13 @@ class BigQueryUtil_<%=cid%> {
|
||||
.setDatasetId(tempDataset)
|
||||
.setTableId(tempTable));
|
||||
}
|
||||
|
||||
|
||||
com.google.api.services.bigquery.model.JobConfiguration config = new com.google.api.services.bigquery.model.JobConfiguration();
|
||||
config.setQuery(queryConfig);
|
||||
|
||||
|
||||
com.google.api.services.bigquery.model.Job job = new com.google.api.services.bigquery.model.Job();
|
||||
job.setConfiguration(config);
|
||||
|
||||
|
||||
com.google.api.services.bigquery.model.Job insert = null;
|
||||
com.google.api.services.bigquery.model.JobReference jobId = null;
|
||||
try {
|
||||
@@ -122,7 +122,7 @@ class BigQueryUtil_<%=cid%> {
|
||||
}
|
||||
throw e;
|
||||
}
|
||||
|
||||
|
||||
<%
|
||||
if(isLog4jEnabled){
|
||||
%>
|
||||
@@ -146,7 +146,7 @@ class BigQueryUtil_<%=cid%> {
|
||||
<%
|
||||
}
|
||||
%>
|
||||
return executeQuery(query, true);
|
||||
return executeQuery(query, true, useLegacySql);
|
||||
}
|
||||
<%}%>
|
||||
// Do not throw exception to avoid behavior changed(because it may throw "duplicate" exception which do not throw before);
|
||||
@@ -164,13 +164,13 @@ class BigQueryUtil_<%=cid%> {
|
||||
}// else job successful
|
||||
break;
|
||||
}
|
||||
// Pause execution for one second before polling job status again, to
|
||||
// Pause execution for one second before polling job status again, to
|
||||
// reduce unnecessary calls to the BigQUery API and lower overall
|
||||
// application bandwidth.
|
||||
Thread.sleep(1000);
|
||||
}
|
||||
|
||||
|
||||
return insert;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,10 +221,9 @@
|
||||
}
|
||||
|
||||
String query_<%=cid%> = <%=query%>;
|
||||
String dataset = query_<%=cid%>.substring(query_<%=cid%>.indexOf("from") + 4, query_<%=cid%>.indexOf(".")).trim();
|
||||
String temp_table = "temp_" + dataset + java.util.UUID.randomUUID().toString().replaceAll("-", "")
|
||||
+ "<%=cid%>".toLowerCase().replaceAll("[^a-z0-9]", "0").replaceAll("^[^a-z]", "a")
|
||||
+ Integer.toHexString(java.util.concurrent.ThreadLocalRandom.current().nextInt());
|
||||
<% if(isLog4jEnabled) { %>
|
||||
log.info("<%=cid%> - query " + <%=query%>);
|
||||
<% } %>
|
||||
|
||||
com.google.cloud.bigquery.BigQuery bigquery_<%=cid%> = com.google.cloud.bigquery.BigQueryOptions.newBuilder()
|
||||
.setCredentials(credentials_<%=cid%>)
|
||||
@@ -233,25 +232,55 @@
|
||||
.getService();
|
||||
|
||||
com.google.cloud.bigquery.QueryJobConfiguration.Builder queryConfiguration_<%=cid%> = com.google.cloud.bigquery.QueryJobConfiguration.newBuilder(<%=query%>).setUseLegacySql(<%=useLegacySql%>);
|
||||
|
||||
<%
|
||||
if (resultSizeType.equals("LARGE") || resultSizeType.equals("AUTO")) {
|
||||
%>
|
||||
queryConfiguration_<%=cid%>.setDestinationTable(com.google.cloud.bigquery.TableId.of(dataset, temp_table)).setAllowLargeResults(true);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
com.google.cloud.bigquery.JobId jobId_<%=cid%> = com.google.cloud.bigquery.JobId.of(java.util.UUID.randomUUID().toString());
|
||||
com.google.cloud.bigquery.Job job_<%=cid%> = bigquery_<%=cid%>.create(com.google.cloud.bigquery.JobInfo.newBuilder(queryConfiguration_<%=cid%>.build()).setJobId(jobId_<%=cid%>).build());
|
||||
|
||||
<%
|
||||
if(isLog4jEnabled){
|
||||
%>
|
||||
<%if (resultSizeType.equals("LARGE") || resultSizeType.equals("AUTO")) {%>
|
||||
|
||||
com.google.cloud.bigquery.QueryJobConfiguration jobConfDryRun_<%=cid%> = queryConfiguration_<%=cid%> .setDryRun(true).build();
|
||||
com.google.cloud.bigquery.Job jobDryRun_<%=cid%> = bigquery_<%=cid%>.create(com.google.cloud.bigquery.JobInfo.of(jobConfDryRun_<%=cid%>));
|
||||
|
||||
String queryLocation_<%=cid%> =jobDryRun_<%=cid%>.getJobId().getLocation();
|
||||
String location_<%=cid%> = queryLocation_<%=cid%> == null ? "US" : queryLocation_<%=cid%>;
|
||||
String tempDataset_<%=cid%> = java.util.UUID.randomUUID().toString().replaceAll("-", "")
|
||||
+ Integer.toHexString(java.util.concurrent.ThreadLocalRandom.current().nextInt())
|
||||
+ Integer.toHexString(java.util.concurrent.ThreadLocalRandom.current().nextInt());
|
||||
String tempTable_<%=cid%> = java.util.UUID.randomUUID().toString().replaceAll("-", "")
|
||||
+ Integer.toHexString(java.util.concurrent.ThreadLocalRandom.current().nextInt())
|
||||
+ Integer.toHexString(java.util.concurrent.ThreadLocalRandom.current().nextInt());
|
||||
<% if(isLog4jEnabled){ %>
|
||||
log.info("<%=cid%> - query location :" + queryLocation_<%=cid%>);
|
||||
log.info("<%=cid%> - temporary dataset location :" + location_<%=cid%>);
|
||||
log.info("<%=cid%> - temporary Dataset name : " + tempDataset_<%=cid%>);
|
||||
log.info("<%=cid%> - temporary table name : " + tempTable_<%=cid%>);
|
||||
<% } %>
|
||||
|
||||
com.google.cloud.bigquery.DatasetInfo datasetInfo_<%=cid%> = com.google.cloud.bigquery.DatasetInfo.newBuilder(tempDataset_<%=cid%>).setLocation(location_<%=cid%>).build();
|
||||
com.google.cloud.bigquery.Dataset dataset_<%=cid%> = bigquery_<%=cid%> .create(datasetInfo_<%=cid%>);
|
||||
|
||||
queryConfiguration_<%=cid%>
|
||||
.setDryRun(false)
|
||||
.setAllowLargeResults(true)
|
||||
.setDestinationTable(com.google.cloud.bigquery.TableId.of(tempDataset_<%=cid%>, tempTable_<%=cid%>));
|
||||
|
||||
com.google.cloud.bigquery.JobId jobId_<%=cid%> = com.google.cloud.bigquery.JobId
|
||||
.newBuilder().setProject(<%=projectId%>)
|
||||
.setJob(java.util.UUID.randomUUID().toString())
|
||||
.setLocation(location_<%=cid%>)
|
||||
.build();
|
||||
|
||||
<% if(isLog4jEnabled){ %>
|
||||
log.info("<%=cid%> - job location : " + jobId_<%=cid%>.getLocation());
|
||||
<% } %>
|
||||
<% } else { %>
|
||||
com.google.cloud.bigquery.JobId jobId_<%=cid%> = com.google.cloud.bigquery.JobId.of(<%=projectId%>,java.util.UUID.randomUUID().toString());
|
||||
|
||||
<% } %>
|
||||
com.google.cloud.bigquery.Job job_<%=cid%> = bigquery_<%=cid%>.create(com.google.cloud.bigquery.JobInfo.newBuilder(queryConfiguration_<%=cid%>.build()).setJobId(jobId_<%=cid%>).build());
|
||||
|
||||
|
||||
<% if(isLog4jEnabled) { %>
|
||||
log.info("<%=cid%> - Sending job " + jobId_<%=cid%> + " with query: " + <%=query%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<% } %>
|
||||
|
||||
job_<%=cid%> = job_<%=cid%>.waitFor();
|
||||
|
||||
if (job_<%=cid%> == null) {
|
||||
@@ -260,13 +289,9 @@
|
||||
throw new RuntimeException(job_<%=cid%>.getStatus().getError().toString());
|
||||
}
|
||||
|
||||
<%
|
||||
if(isLog4jEnabled){
|
||||
%>
|
||||
<% if(isLog4jEnabled) { %>
|
||||
log.info("<%=cid%> - Job " + jobId_<%=cid%> + " finished successfully.");
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<% } %>
|
||||
com.google.cloud.bigquery.TableResult result_<%=cid%> = job_<%=cid%>.getQueryResults();
|
||||
long nb_line_<%=cid%> = 0;
|
||||
<%
|
||||
|
||||
@@ -10,7 +10,10 @@ imports="
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
String cid = node.getUniqueName();
|
||||
String authMode = ElementParameterParser.getValue(node,"__AUTH_MODE__");
|
||||
String authMode = ElementParameterParser.getValue(node,"__AUTH_MODE__");
|
||||
String projectId = ElementParameterParser.getValue(node,"__PROJECT_ID__");
|
||||
String resultSizeType = ElementParameterParser.getValue(node,"__RESULT_SIZE__");
|
||||
|
||||
if (authMode.equals("OAUTH")) {
|
||||
%>
|
||||
}
|
||||
@@ -24,7 +27,10 @@ imports="
|
||||
} else if (authMode.equals("SERVICEACCOUNT")) {
|
||||
%>
|
||||
}
|
||||
bigquery_<%=cid%>.delete(com.google.cloud.bigquery.TableId.of(dataset, temp_table));
|
||||
<% if (resultSizeType.equals("LARGE") || resultSizeType.equals("AUTO")) { %>
|
||||
com.google.cloud.bigquery.DatasetId datasetId_<%=cid%> = com.google.cloud.bigquery.DatasetId.of(<%=projectId%>, tempDataset_<%=cid%>);
|
||||
bigquery_<%=cid%>.delete(datasetId_<%=cid%>, com.google.cloud.bigquery.BigQuery.DatasetDeleteOption.deleteContents());
|
||||
<% }%>
|
||||
<%
|
||||
} else {
|
||||
throw new IllegalArgumentException("authentication mode should be either \"SERVICEACCOUNT\" or \"OAUTH\", but it is " + authMode);
|
||||
|
||||
@@ -55,7 +55,12 @@
|
||||
<PARAMETER NAME="TEXT_ENCLOSURE" FIELD="TEXT" REQUIRED="true" NUM_ROW="30" MAX_LENGTH="1" REPOSITORY_VALUE="TEXT_ENCLOSURE" SHOW="false">
|
||||
<DEFAULT>"\""</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="USE_CUSTOM_NULL_MARKER" FIELD="CHECK" NUM_ROW="35">
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
<PARAMETER NAME="CUSTOM_NULL_MARKER" FIELD="TEXT" NUM_ROW="35" SHOW_IF="USE_CUSTOM_NULL_MARKER=='true'">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
<PARAMETER NAME="CREATE" FIELD="CHECK" REQUIRED="true" NUM_ROW="40">
|
||||
<DEFAULT>true</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
@@ -25,7 +25,8 @@
|
||||
boolean checkDiskSpace = ("true").equals(ElementParameterParser.getValue(node,"__CHECK_DISK_SPACE__"));
|
||||
boolean flushOnRow = ("true").equals(ElementParameterParser.getValue(node, "__FLUSHONROW__"));
|
||||
String flushMod = ElementParameterParser.getValue(node, "__FLUSHONROW_NUM__");
|
||||
|
||||
boolean useCustomNullMarker = ElementParameterParser.getBooleanValue(node, "__USE_CUSTOM_NULL_MARKER__");
|
||||
String nullMarker = useCustomNullMarker ? ElementParameterParser.getValue(node, "__CUSTOM_NULL_MARKER__") : "\"\\\\N\"";
|
||||
String encoding = ElementParameterParser.getValue(node,"__ENCODING__");
|
||||
|
||||
List< ? extends IConnection> conns = node.getIncomingConnections();
|
||||
@@ -35,8 +36,8 @@
|
||||
if (conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
|
||||
List<IMetadataColumn> columns = metadata.getListColumns();
|
||||
int sizeColumns = columns.size();
|
||||
%>
|
||||
String[] row_<%=cid%>=new String[]{<%for(int j=0;j<sizeColumns;j++){%>"\\N",<%}%>}; //empty value must be NULL('\N' in bulk file)
|
||||
%>
|
||||
String[] row_<%=cid%>=new String[]{<%for(int j=0;j<sizeColumns;j++){%> <%= nullMarker %>,<%}%>}; //empty value must be defined by null marker('\N' is default in bulk file)
|
||||
<%
|
||||
for (int i = 0; i < sizeColumns; i++) {
|
||||
IMetadataColumn column = columns.get(i);
|
||||
@@ -64,24 +65,10 @@
|
||||
%>
|
||||
row_<%=cid%>[<%=i%>] = <%=conn.getName() %>.<%=column.getLabel() %>;
|
||||
<%
|
||||
}else if(javaType == JavaTypesManager.DATE && pattern == null){
|
||||
%>
|
||||
row_<%=cid%>[<%=i%>] = FormatterUtils.format_Date(<%=conn.getName() %>.<%=column.getLabel() %>, "yyyy-MM-dd");
|
||||
<%
|
||||
}else if(javaType == JavaTypesManager.DATE && pattern != null){
|
||||
if(pattern.length() > 12){
|
||||
%>
|
||||
row_<%=cid%>[<%=i%>] = FormatterUtils.format_Date(<%=conn.getName() %>.<%=column.getLabel() %>, "yyyy-MM-dd HH:mm:ss");
|
||||
<%
|
||||
}else if(pattern.length() == 12 || "\"\"".equals(pattern)) {
|
||||
%>
|
||||
row_<%=cid%>[<%=i%>] = FormatterUtils.format_Date(<%=conn.getName() %>.<%=column.getLabel() %>, "yyyy-MM-dd");
|
||||
<%
|
||||
}else {
|
||||
%>
|
||||
row_<%=cid%>[<%=i%>] = FormatterUtils.format_Date(<%=conn.getName() %>.<%=column.getLabel() %>, <%=pattern%>);
|
||||
<%
|
||||
}
|
||||
}else if(javaType == JavaTypesManager.DATE){
|
||||
%>
|
||||
row_<%=cid%>[<%=i%>] = FormatterUtils.format_Date(<%=conn.getName() %>.<%=column.getLabel() %>, <%=(pattern != null && !("\"\"").equals(pattern)) ? pattern : "\"yyyy-MM-dd\""%>);
|
||||
<%
|
||||
}else if(javaType == JavaTypesManager.BYTE_ARRAY){
|
||||
%>
|
||||
row_<%=cid%>[<%=i%>] = java.nio.charset.Charset.forName(<%=encoding %>).decode(java.nio.ByteBuffer.wrap(<%=conn.getName() %>.<%=column.getLabel() %>)).toString();
|
||||
@@ -100,7 +87,7 @@
|
||||
}
|
||||
%>
|
||||
} else {
|
||||
row_<%=cid%>[<%=i%>] = "\\N";
|
||||
row_<%=cid%>[<%=i%>] = <%= nullMarker %>;
|
||||
}
|
||||
<%
|
||||
}
|
||||
|
||||
@@ -24,4 +24,5 @@ RECORDS_CONTAIN_NULL_VALUE.NAME=Records contain NULL value
|
||||
PROPERTY.NAME=Property Type
|
||||
CHECK_DISK_SPACE.NAME=Check disk space
|
||||
|
||||
|
||||
USE_CUSTOM_NULL_MARKER.NAME=Use custom null marker
|
||||
CUSTOM_NULL_MARKER.NAME=
|
||||
|
||||
@@ -17,40 +17,40 @@ imports="
|
||||
CodeGeneratorArgument codeGenArgument = (CodeGeneratorArgument) argument;
|
||||
INode node = (INode)codeGenArgument.getArgument();
|
||||
String cid = node.getUniqueName();
|
||||
|
||||
|
||||
String useExistingConn = ElementParameterParser.getValue(node,"__USE_EXISTING_CONNECTION__");
|
||||
String accessToken = ElementParameterParser.getValue(node, "__ACCESS_TOKEN__");
|
||||
String refreshToken = ElementParameterParser.getValue(node, "__REFRESH_TOKEN__");
|
||||
|
||||
|
||||
String clientId = ElementParameterParser.getValue(node, "__CLIENT_ID__");
|
||||
String clientSecret = ElementParameterParser.getValue(node, "__CLIENT_SECRET__");
|
||||
|
||||
|
||||
String connection = ElementParameterParser.getValue(node,"__CONNECTION__");
|
||||
String connectionKey = "\"conn_" + connection+"\"";
|
||||
|
||||
|
||||
String path = ElementParameterParser.getValue(node, "__PATH__");
|
||||
String filelistType = ElementParameterParser.getValue(node, "__LIST_MODE__");
|
||||
boolean includeSubDirectories = "true".equals(ElementParameterParser.getValue(node, "__INCLUDSUBDIR__"));
|
||||
|
||||
|
||||
final boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
log4jFileUtil.componentStartInfo(node);
|
||||
|
||||
|
||||
List<IMetadataTable> metadatas = node.getMetadataList();
|
||||
IMetadataTable metadata = null;
|
||||
if ((metadatas!=null)&&(metadatas.size()>0)) {
|
||||
metadata = metadatas.get(0);
|
||||
metadata = metadatas.get(0);
|
||||
}
|
||||
|
||||
|
||||
List< ? extends IConnection> outputConnections = node.getOutgoingSortedConnections();
|
||||
|
||||
String dataOutputConnection = null;
|
||||
|
||||
String dataOutputConnection = null;
|
||||
for(IConnection conn : outputConnections) {
|
||||
if(conn.getLineStyle().hasConnectionCategory(IConnectionCategory.DATA)) {
|
||||
dataOutputConnection = conn.getName();
|
||||
break;
|
||||
} // if(conn) end
|
||||
} // for(conns) end
|
||||
|
||||
|
||||
%>
|
||||
<%
|
||||
if(!"true".equals(useExistingConn)){
|
||||
@@ -105,115 +105,81 @@ if(!"true".equals(useExistingConn)){
|
||||
<%=cid%>_client.authenticate(new com.box.boxjavalibv2.dao.BoxOAuthToken(<%=cid%>_map));
|
||||
}
|
||||
<%
|
||||
} else {
|
||||
} else {
|
||||
%>
|
||||
com.box.boxjavalibv2.BoxClient <%=cid%>_client = (com.box.boxjavalibv2.BoxClient)globalMap.get(<%=connectionKey%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
String <%=cid%>_path = normalizePath(<%=path%>);
|
||||
boolean <%=cid%>_hasError = false;
|
||||
String <%=cid%>_name = getFolderFromPath(<%=cid%>_path);
|
||||
com.box.boxjavalibv2.dao.BoxFile <%=cid%>_boxFile = null;
|
||||
com.box.boxjavalibv2.dao.BoxFolder <%=cid%>_boxFolder = null;
|
||||
if ((<%=cid%>_name.equals("All Files") && (<%=cid%>_path.isEmpty() || <%=cid%>_path == null)))
|
||||
{
|
||||
<%=cid%>_boxFolder = <%=cid%>_client.getFoldersManager().getFolder("0",null);
|
||||
}
|
||||
else
|
||||
{
|
||||
com.box.restclientv2.requestsbase.BoxDefaultRequestObject <%=cid%>_requestObject = new com.box.restclientv2.requestsbase.BoxDefaultRequestObject();
|
||||
if (<%=cid%>_name.equals("All Files") || <%=cid%>_path.equals("All Files"))
|
||||
{
|
||||
<%=cid%>_boxFolder = <%=cid%>_client.getFoldersManager().getFolder("0", null);
|
||||
}
|
||||
else
|
||||
{
|
||||
String parentPath = normalizePath(<%=cid%>_path.replace(<%=cid%>_name, ""));
|
||||
|
||||
<%=cid%>_boxFolder = <%=cid%>_client.getFoldersManager().getFolder("0", <%=cid%>_requestObject);
|
||||
|
||||
if ("All Files".equals(parentPath)) {
|
||||
|
||||
for (com.box.boxjavalibv2.dao.BoxTypedObject <%=cid%>_boxTypedObject : <%=cid%>_boxFolder.getItemCollection().getEntries()) {
|
||||
if (<%=cid%>_boxTypedObject.getValue("name").equals(<%=cid%>_name)) {
|
||||
if ("folder".equals(<%=cid%>_boxTypedObject.getType())) {
|
||||
<%=cid%>_boxFolder = <%=cid%>_client.getFoldersManager().getFolder(<%=cid%>_boxTypedObject.getId(), <%=cid%>_requestObject);
|
||||
} else {
|
||||
<%=cid%>_boxFile = <%=cid%>_client.getFilesManager().getFile(<%=cid%>_boxTypedObject.getId(),<%=cid%>_requestObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
com.box.boxjavalibv2.dao.BoxFolder <%=cid%>_rootFolder = <%=cid%>_client.getFoldersManager().getFolder("0", null);
|
||||
com.box.boxjavalibv2.dao.BoxItem <%=cid%>_boxItem;
|
||||
|
||||
} else {
|
||||
|
||||
List<String> <%=cid%>_paths = new java.util.ArrayList<String>(java.util.Arrays.asList(parentPath.split("/")));
|
||||
|
||||
<%=cid%>_boxFolder = getBoxFolderRecursively(<%=cid%>_paths, <%=cid%>_boxFolder, <%=cid%>_client);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (<%=cid%>_boxFile == null && <%=cid%>_boxFolder == null)
|
||||
{
|
||||
throw new Exception("<%=cid%> - " + "No file or directory found in " + <%=path%>);
|
||||
}
|
||||
else if (<%=cid%>_boxFolder != null)
|
||||
{
|
||||
java.util.List<com.box.boxjavalibv2.dao.BoxItem> <%=cid%>_children = new java.util.ArrayList<com.box.boxjavalibv2.dao.BoxItem>();
|
||||
<%if(includeSubDirectories){%>
|
||||
<%if(filelistType.equalsIgnoreCase("Directories")){%>
|
||||
<%=cid%>_children = getChildrenRecursively(<%=cid%>_client, <%=cid%>_boxFolder, <%=cid%>_children, true, false);
|
||||
<%} else if (filelistType.equalsIgnoreCase("Files")){%>
|
||||
<%=cid%>_children = getChildrenRecursively(<%=cid%>_client, <%=cid%>_boxFolder, <%=cid%>_children, false, true);
|
||||
<%} else {%>
|
||||
<%=cid%>_children = getChildrenRecursively(<%=cid%>_client, <%=cid%>_boxFolder, <%=cid%>_children, true, true);
|
||||
<%}%>
|
||||
<%}%>
|
||||
<%else{%>
|
||||
for (com.box.boxjavalibv2.dao.BoxTypedObject obj : <%=cid%>_boxFolder.getItemCollection().getEntries())
|
||||
{
|
||||
<%if(filelistType.equalsIgnoreCase("Directories")){%>
|
||||
if(obj.getType().equals("folder"))
|
||||
{
|
||||
com.box.boxjavalibv2.dao.BoxFolder folder = <%=cid%>_client.getFoldersManager().getFolder(obj.getId(), null);
|
||||
<%=cid%>_children.add(folder);
|
||||
}
|
||||
<%} else if (filelistType.equalsIgnoreCase("Files")){%>
|
||||
if (obj.getType().equals("file"))
|
||||
{
|
||||
com.box.boxjavalibv2.dao.BoxFile file = <%=cid%>_client.getFilesManager().getFile(obj.getId(), null);
|
||||
<%=cid%>_children.add(file);
|
||||
}
|
||||
<%} else {%>
|
||||
if(obj.getType().equals("folder"))
|
||||
{
|
||||
com.box.boxjavalibv2.dao.BoxFolder folder = <%=cid%>_client.getFoldersManager().getFolder(obj.getId(), null);
|
||||
<%=cid%>_children.add(folder);
|
||||
}
|
||||
else if (obj.getType().equals("file"))
|
||||
{
|
||||
com.box.boxjavalibv2.dao.BoxFile file = <%=cid%>_client.getFilesManager().getFile(obj.getId(), null);
|
||||
<%=cid%>_children.add(file);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
|
||||
int <%=cid%>_slashPosition = <%=cid%>_path.indexOf("/");
|
||||
String <%=cid%>_rootFolderName = <%=cid%>_slashPosition == -1 ? <%=cid%>_path : <%=cid%>_path.substring(0, <%=cid%>_slashPosition);
|
||||
if (<%=cid%>_rootFolderName.equals("All Files")) {
|
||||
List<String> <%=cid%>_pathItems = new java.util.ArrayList<String>(java.util.Arrays.asList(<%=cid%>_path.split("/")));
|
||||
<%=cid%>_pathItems.remove(0);
|
||||
try {
|
||||
<%=cid%>_boxItem = getBoxItemRecursively(<%=cid%>_pathItems, <%=cid%>_rootFolder, <%=cid%>_client);
|
||||
} catch (Exception e) {
|
||||
throw new Exception("<%=cid%> - " + "The path to file or directory was not found in " + <%=cid%>_path, e);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
for (com.box.boxjavalibv2.dao.BoxItem <%=cid%>_item : <%=cid%>_children)
|
||||
{
|
||||
String <%=cid%>_itemPath = getBoxItemPath(<%=cid%>_item);
|
||||
globalMap.put("<%=cid%>_NAME", <%=cid%>_item.getName());
|
||||
globalMap.put("<%=cid%>_ID", <%=cid%>_item.getId());
|
||||
globalMap.put("<%=cid%>_FILE_PATH", <%=cid%>_itemPath);
|
||||
globalMap.put("<%=cid%>_FILE_DIRECTORY", <%=cid%>_itemPath + <%=cid%>_item.getName());
|
||||
globalMap.put("<%=cid%>_TYPE",<%=cid%>_item.getType());
|
||||
globalMap.put("<%=cid%>_LAST_MODIFIED", <%=cid%>_item.getModifiedAt());
|
||||
globalMap.put("<%=cid%>_SIZE", <%=cid%>_item.getSize());
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
} else {
|
||||
throw new Exception("<%=cid%> - " + "The path to file or directory was not found in " + <%=cid%>_path);
|
||||
}
|
||||
|
||||
java.util.List<com.box.boxjavalibv2.dao.BoxItem> <%=cid%>_items = new java.util.ArrayList<>();
|
||||
if (<%=cid%>_boxItem.getType().equals("folder")) {
|
||||
com.box.boxjavalibv2.dao.BoxFolder <%=cid%>_boxFolder = (com.box.boxjavalibv2.dao.BoxFolder) <%=cid%>_boxItem;
|
||||
<%if(includeSubDirectories) {%>
|
||||
<%if(filelistType.equalsIgnoreCase("Directories")) {%>
|
||||
<%=cid%>_items = getChildrenRecursively(<%=cid%>_client, <%=cid%>_boxFolder, <%=cid%>_items, true, false);
|
||||
<%} else if (filelistType.equalsIgnoreCase("Files")) {%>
|
||||
<%=cid%>_items = getChildrenRecursively(<%=cid%>_client, <%=cid%>_boxFolder, <%=cid%>_items, false, true);
|
||||
<%} else {%>
|
||||
<%=cid%>_items = getChildrenRecursively(<%=cid%>_client, <%=cid%>_boxFolder, <%=cid%>_items, true, true);
|
||||
<%}%>
|
||||
<%} else {%>
|
||||
for (com.box.boxjavalibv2.dao.BoxTypedObject obj : <%=cid%>_boxFolder.getItemCollection().getEntries())
|
||||
{
|
||||
<%if(filelistType.equalsIgnoreCase("Directories")) {%>
|
||||
if(obj.getType().equals("folder"))
|
||||
{
|
||||
com.box.boxjavalibv2.dao.BoxFolder folder = <%=cid%>_client.getFoldersManager().getFolder(obj.getId(), null);
|
||||
<%=cid%>_items.add(folder);
|
||||
}
|
||||
<%} else if (filelistType.equalsIgnoreCase("Files")) {%>
|
||||
if (obj.getType().equals("file"))
|
||||
{
|
||||
com.box.boxjavalibv2.dao.BoxFile file = <%=cid%>_client.getFilesManager().getFile(obj.getId(), null);
|
||||
<%=cid%>_items.add(file);
|
||||
}
|
||||
<%} else {%>
|
||||
if(obj.getType().equals("folder"))
|
||||
{
|
||||
com.box.boxjavalibv2.dao.BoxFolder folder = <%=cid%>_client.getFoldersManager().getFolder(obj.getId(), null);
|
||||
<%=cid%>_items.add(folder);
|
||||
}
|
||||
else if (obj.getType().equals("file"))
|
||||
{
|
||||
com.box.boxjavalibv2.dao.BoxFile file = <%=cid%>_client.getFilesManager().getFile(obj.getId(), null);
|
||||
<%=cid%>_items.add(file);
|
||||
}
|
||||
<%}%>
|
||||
}
|
||||
<%}%>
|
||||
} else if (<%=cid%>_boxItem.getType().equals("file")) {
|
||||
com.box.boxjavalibv2.dao.BoxFile <%=cid%>_boxFile = (com.box.boxjavalibv2.dao.BoxFile) <%=cid%>_boxItem;
|
||||
<%=cid%>_items.add(<%=cid%>_boxFile);
|
||||
}
|
||||
|
||||
for (com.box.boxjavalibv2.dao.BoxItem <%=cid%>_item : <%=cid%>_items) {
|
||||
String <%=cid%>_itemPath = getBoxItemPath(<%=cid%>_item);
|
||||
globalMap.put("<%=cid%>_NAME", <%=cid%>_item.getName());
|
||||
globalMap.put("<%=cid%>_ID", <%=cid%>_item.getId());
|
||||
globalMap.put("<%=cid%>_FILE_PATH", <%=cid%>_itemPath);
|
||||
globalMap.put("<%=cid%>_FILE_DIRECTORY", <%=cid%>_itemPath + <%=cid%>_item.getName());
|
||||
globalMap.put("<%=cid%>_TYPE",<%=cid%>_item.getType());
|
||||
globalMap.put("<%=cid%>_LAST_MODIFIED", <%=cid%>_item.getModifiedAt());
|
||||
globalMap.put("<%=cid%>_SIZE", <%=cid%>_item.getSize());
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
%>
|
||||
}
|
||||
|
||||
}
|
||||
//globalMap.put("<%=cid%>_NB_FILE", NB_FILE<%=cid%>);
|
||||
|
||||
|
||||
|
||||
@@ -898,8 +898,8 @@
|
||||
<IMPORT NAME="Driver-VERTICA_7.0.1" MODULE="vertica-jdbc-7.0.1-0.jar" MVN="mvn:org.talend.libraries/vertica-jdbc-7.0.1-0/6.0.0" REQUIRED_IF="(DBTYPE=='VERTICA') and (USE_EXISTING_CONNECTION == 'false') and (DB_VERTICA_VERSION=='VERTICA_7_0_X')" />
|
||||
<IMPORT NAME="Driver-VERTICA_7.1.2" MODULE="vertica-jdbc-7.1.2-0.jar" MVN="mvn:org.talend.libraries/vertica-jdbc-7.1.2-0/6.0.0" REQUIRED_IF="(DBTYPE=='VERTICA') and (USE_EXISTING_CONNECTION == 'false') and (DB_VERTICA_VERSION=='VERTICA_7_1_X')" />
|
||||
<IMPORT NAME="Driver-EXASolution" MODULE="exajdbc-6.0.9302.jar" MVN="mvn:org.talend.libraries/exajdbc-6.0.9302/6.3.0" REQUIRED_IF="(DBTYPE=='EXASOL') and (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Driver-Redshift" MODULE="redshift-jdbc42-no-awssdk-1.2.20.1043.jar" MVN="mvn:com.amazon.redshift/redshift-jdbc42-no-awssdk/1.2.20.1043" REQUIRED_IF="(DBTYPE=='REDSHIFT') and (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Driver-Snowflake" MODULE="snowflake-jdbc-3.5.3.jar" MVN="mvn:net.snowflake/snowflake-jdbc/3.5.3" REQUIRED_IF="(DBTYPE=='SNOWFLAKE') and (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Driver-Redshift" MODULE="redshift-jdbc42-no-awssdk-1.2.32.1056.jar" MVN="mvn:com.amazon.redshift/redshift-jdbc42-no-awssdk/1.2.32.1056" REQUIRED_IF="(DBTYPE=='REDSHIFT') and (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Driver-Snowflake" MODULE="snowflake-jdbc-3.11.1.jar" MVN="mvn:net.snowflake/snowflake-jdbc/3.11.1" REQUIRED_IF="(DBTYPE=='SNOWFLAKE') and (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Driver-VERTICA_9.0" MODULE="vertica-jdbc-9.0.0-0.jar" MVN="mvn:org.talend.libraries/vertica-jdbc-9.0.0-0/6.0.0" REQUIRED_IF="(DBTYPE=='VERTICA') and (USE_EXISTING_CONNECTION == 'false') and (DB_VERTICA_VERSION=='VERTICA_9_0')"/>
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
@@ -2103,7 +2103,7 @@ class SnowflaketManager extends Manager {
|
||||
StringBuilder javaCode = new StringBuilder();
|
||||
if(useExistingConnection) {
|
||||
javaCode.append(retrieveTable());
|
||||
javaCode.append("java.sql.Connection conn_" + cid + " = (java.sql.Connection)globalMap.get(\"" + connection + "_Connection\");");
|
||||
javaCode.append("java.sql.Connection conn_" + cid + " = (java.sql.Connection)globalMap.get(\"" + connection + "_connection\");");
|
||||
} else {
|
||||
javaCode.append(super.getConnection());
|
||||
}
|
||||
|
||||
@@ -45,8 +45,8 @@ String xmlfile = ElementParameterParser.getValue(node, "__XMLFILE__");
|
||||
java.lang.StringBuilder sb<%=cid %>=new java.lang.StringBuilder("");
|
||||
|
||||
try{
|
||||
br<%=cid %> = new java.io.BufferedReader(new java.io.InputStreamReader(url<%=cid %>.openStream()));
|
||||
|
||||
br<%=cid %> = new java.io.BufferedReader(new UnicodeReader(url<%=cid %>.openStream(), null));
|
||||
|
||||
char[] buffer<%=cid %> = new char[1024];
|
||||
int length<%=cid %> = -1;
|
||||
while ((length<%=cid %> = br<%=cid %>.read(buffer<%=cid %>)) != -1)
|
||||
@@ -66,7 +66,9 @@ String xmlfile = ElementParameterParser.getValue(node, "__XMLFILE__");
|
||||
dbf<%=cid %> = javax.xml.parsers.DocumentBuilderFactory.newInstance();
|
||||
dbf<%=cid %>.setValidating(false);
|
||||
db<%=cid %> = dbf<%=cid %>.newDocumentBuilder();
|
||||
org.w3c.dom.Document doc<%=cid %> = db<%=cid %>.parse(new java.io.StringBufferInputStream(sb<%=cid%>.toString()));
|
||||
org.w3c.dom.Document doc<%=cid %> = db<%=cid %>.parse(
|
||||
new java.io.ByteArrayInputStream(sb<%=cid%>.toString().getBytes("UTF-8")));
|
||||
|
||||
String rootnode<%=cid %>=doc<%=cid %>.getDocumentElement().getNodeName();
|
||||
|
||||
String encoding=null;
|
||||
@@ -89,8 +91,8 @@ String xmlfile = ElementParameterParser.getValue(node, "__XMLFILE__");
|
||||
|
||||
int offsetRoot<%=cid %>=sb<%=cid %>.indexOf("<"+rootnode<%=cid %>);
|
||||
sb<%=cid%>.replace(0, offsetRoot<%=cid %>, reference<%=cid %>);
|
||||
is<%=cid %>=new java.io.StringBufferInputStream(sb<%=cid %>.toString());
|
||||
|
||||
is<%=cid %> = new java.io.ByteArrayInputStream(sb<%=cid%>.toString().getBytes("UTF-8"));
|
||||
|
||||
class MyHandler<%=cid %> extends org.xml.sax.helpers.DefaultHandler{
|
||||
String errorMessage = null;
|
||||
public void error(org.xml.sax.SAXParseException e) throws org.xml.sax.SAXException {
|
||||
|
||||
@@ -40,8 +40,8 @@
|
||||
</ADVANCED_PARAMETERS>
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT MODULE="janet-java-1.1.jar" MVN="mvn:org.talend.libraries/janet-java-1.1/6.0.0" NAME="janet-java-1.1"
|
||||
REQUIRED="true" />
|
||||
<IMPORT MODULE="janet-java-1.2.jar" MVN="mvn:org.talend.libraries/janet-java-1.2/6.0.0" NAME="janet-java-1.2"
|
||||
REQUIRED="true" />
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
<RETURNS>
|
||||
|
||||
@@ -94,7 +94,7 @@
|
||||
</ADVANCED_PARAMETERS>
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT MODULE="janet-java-1.1.jar" MVN="mvn:org.talend.libraries/janet-java-1.1/6.0.0" NAME="janet-java-1.1"
|
||||
<IMPORT MODULE="janet-java-1.2.jar" MVN="mvn:org.talend.libraries/janet-java-1.2/6.0.0" NAME="janet-java-1.2"
|
||||
REQUIRED="true" />
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
org.talend.designer.dbmap.language.generation.GenericDbGenerationManager gm = new org.talend.designer.dbmap.language.generation.GenericDbGenerationManager();
|
||||
org.talend.designer.dbmap.language.mssql.MssqlGenerationManager gm = new org.talend.designer.dbmap.language.mssql.MssqlGenerationManager();
|
||||
String uniqueNameComponent = null;
|
||||
IDbLanguage currentLanguage = gm.getLanguage();
|
||||
|
||||
|
||||
@@ -305,48 +305,54 @@ for(Column colStmt:stmtStructure){
|
||||
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
String insertQuery_<%=cid %> = "INSERT INTO "+tableName_<%=cid%>+"(<%=insertColName.toString()%>) ("+select_query_<%=cid %>+")";
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(insertQuery_<%=cid %>);
|
||||
String insertQuery_<%=cid %> = "INSERT INTO "+tableName_<%=cid%>+"(<%=insertColName.toString()%>) ("+select_query_<%=cid %>+")";
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(insertQuery_<%=cid %>);
|
||||
|
||||
<%
|
||||
}else if (("UPDATE").equals(dataAction)){
|
||||
if(useUpdateStatement){
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
String updateQuery_<%=cid %> = select_query_<%=cid %>
|
||||
String updateQuery_<%=cid %> = select_query_<%=cid %>;
|
||||
<%
|
||||
}else{
|
||||
}else{
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> "
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> ";
|
||||
<%
|
||||
}
|
||||
}
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
if(select_query_<%=cid %>.indexOf("WHERE")==-1){
|
||||
updateQuery_<%=cid %> +=" WHERE ";
|
||||
}else{
|
||||
updateQuery_<%=cid %> +=" AND ";
|
||||
}
|
||||
updateQuery_<%=cid %>+= <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
<%
|
||||
}else{
|
||||
%>
|
||||
updateQuery_<%=cid %> += " WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") "
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(updateQuery_<%=cid %>);
|
||||
<%
|
||||
}else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") "
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" AND " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
pstmt_<%=cid %> = conn_<%=cid%>.prepareStatement(deleteQuery_<%=cid %>);
|
||||
|
||||
<%
|
||||
}
|
||||
%>
|
||||
int nb_line_<%=cid%> = 0;
|
||||
int nb_line_updated_<%=cid%> = 0;
|
||||
int nb_line_inserted_<%=cid%> = 0;
|
||||
|
||||
@@ -33,4 +33,4 @@ USE_DIFFERENT_TABLE.NAME=Use different table name
|
||||
DIFFERENT_TABLE_NAME.NAME=Table name
|
||||
IS_TABLE_NAME_VARIABLE.NAME=Table name from connection name is variable
|
||||
|
||||
USE_UPDATE_STATEMENT.NAME=Use update statement
|
||||
USE_UPDATE_STATEMENT.NAME=Use update statement without subqueries
|
||||
@@ -181,6 +181,17 @@
|
||||
</PARAMETER>
|
||||
|
||||
</PARAMETERS>
|
||||
|
||||
<ADVANCED_PARAMETERS>
|
||||
<PARAMETER
|
||||
NAME="PROPERTIES"
|
||||
FIELD="TEXT"
|
||||
NUM_ROW="1"
|
||||
REPOSITORY_VALUE="PROPERTIES_STRING"
|
||||
SHOW_IF="(#LINK@CONNECTOR.OUT.TABLE_REF == '0') AND (USE_EXISTING_CONNECTION == 'false')">
|
||||
<DEFAULT>""</DEFAULT>
|
||||
</PARAMETER>
|
||||
</ADVANCED_PARAMETERS>
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
|
||||
@@ -48,4 +48,5 @@ DB_VERSION.ITEM.MYSQL_5=Mysql 5
|
||||
DB_VERSION.ITEM.MYSQL_8=Mysql 8
|
||||
DB_VERSION.ITEM.MARIADB=MariaDB
|
||||
|
||||
PROPERTIES.NAME=Additional JDBC Parameters
|
||||
CONNECTION.NAME=Component List
|
||||
@@ -52,6 +52,7 @@ imports="
|
||||
String dbuser = null;
|
||||
String dbVersion = "";
|
||||
boolean useExistingConn = false;
|
||||
String dbproperties = null;
|
||||
if(previousNode != null) {
|
||||
dbhost = ElementParameterParser.getValue(previousNode, "__HOST__");
|
||||
dbport = ElementParameterParser.getValue(previousNode, "__PORT__");
|
||||
@@ -59,6 +60,7 @@ imports="
|
||||
dbuser = ElementParameterParser.getValue(previousNode, "__USER__");
|
||||
useExistingConn = ("true").equals(ElementParameterParser.getValue(previousNode, "__USE_EXISTING_CONNECTION__"));
|
||||
dbVersion = ElementParameterParser.getValue(previousNode, "__DB_VERSION__");
|
||||
dbproperties = ElementParameterParser.getValue(previousNode, "__PROPERTIES__");
|
||||
}
|
||||
|
||||
String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__");
|
||||
@@ -96,7 +98,11 @@ imports="
|
||||
%>
|
||||
String driverClass_<%=cid%> = "<%=drverClass%>";
|
||||
java.lang.Class.forName(driverClass_<%=cid%>);
|
||||
<%if(dbproperties == null || ("\"\"").equals(dbproperties) || ("").equals(dbproperties)) {%>
|
||||
String url_<%=cid %> = "<%=jdbcURL%>://"+<%=dbhost%>+":"+<%=dbport%>+"/"+<%=dbname%>;
|
||||
<%} else {%>
|
||||
String url_<%=cid %> = "<%=jdbcURL%>://"+<%=dbhost%>+":"+<%=dbport%>+"/"+<%=dbname%>+"?"+<%=dbproperties%>;
|
||||
<%}%>
|
||||
String dbUser_<%=cid%> = <%=dbuser%>;
|
||||
|
||||
<%
|
||||
|
||||
@@ -140,7 +140,15 @@
|
||||
|
||||
</PARAMETERS>
|
||||
|
||||
<ADVANCED_PARAMETERS>
|
||||
<ADVANCED_PARAMETERS>
|
||||
<PARAMETER
|
||||
NAME="USE_UPDATE_STATEMENT"
|
||||
FIELD="CHECK"
|
||||
NUM_ROW="10"
|
||||
SHOW_IF="DATA_ACTION=='UPDATE'"
|
||||
>
|
||||
<DEFAULT>false</DEFAULT>
|
||||
</PARAMETER>
|
||||
</ADVANCED_PARAMETERS>
|
||||
|
||||
<CODEGENERATION>
|
||||
|
||||
@@ -35,6 +35,7 @@ skeleton="../templates/db_output_bulk.skeleton"
|
||||
String differenttable = ElementParameterParser.getValue(node, "__DIFFERENT_TABLE_NAME__");
|
||||
boolean useDifferentTable = "true".equals(ElementParameterParser.getValue(node, "__USE_DIFFERENT_TABLE__"));
|
||||
boolean isTableNameVariable="true".equals(ElementParameterParser.getValue(node, "__IS_TABLE_NAME_VARIABLE__"));
|
||||
boolean useUpdateStatement="true".equals(ElementParameterParser.getValue(node, "__USE_UPDATE_STATEMENT__"));
|
||||
%>
|
||||
String select_query_<%=cid %> = null;
|
||||
String tableName_<%=cid%> = null;
|
||||
@@ -93,7 +94,7 @@ skeleton="../templates/db_output_bulk.skeleton"
|
||||
String username = "username_" + connection;
|
||||
String connectionKey=null;
|
||||
if("tSnowflakeConnection".equals(connNode.getComponent().getName())){
|
||||
connectionKey=connection+"_Connection";
|
||||
connectionKey=connection+"_connection";
|
||||
}else{
|
||||
connectionKey=conn;
|
||||
}
|
||||
@@ -156,21 +157,36 @@ skeleton="../templates/db_output_bulk.skeleton"
|
||||
}
|
||||
|
||||
if(("INSERT").equals(dataAction)){
|
||||
%>
|
||||
String insertQuery_<%=cid %> = "INSERT INTO "+tableName_<%=cid%>+"(<%=insertColName.toString()%>) ("+select_query_<%=cid %>+")";
|
||||
<%
|
||||
} else if (("UPDATE").equals(dataAction)){
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> "
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
%>
|
||||
String insertQuery_<%=cid %> = "INSERT INTO "+tableName_<%=cid%>+"(<%=insertColName.toString()%>) ("+select_query_<%=cid %>+")";
|
||||
<%
|
||||
} else if (("UPDATE").equals(dataAction)){
|
||||
if(useUpdateStatement){
|
||||
%>
|
||||
String updateQuery_<%=cid %> = select_query_<%=cid %>;
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
if (updateQuery_<%=cid %>.toUpperCase().contains(" WHERE ")) {
|
||||
updateQuery_<%=cid %> += " AND (" + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%> + ")";
|
||||
} else {
|
||||
updateQuery_<%=cid %> += " WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>;
|
||||
}
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
String updateQuery_<%=cid %> = "UPDATE "+tableName_<%=cid%>+" SET <%=updateSetStmt.toString()%> "
|
||||
<%
|
||||
if(CodeGenerationUtils.hasAlphaNumericCharacter(whereClause)) {
|
||||
%>
|
||||
+" WHERE " + <%=CodeGenerationUtils.replaceAllCrBySpace(whereClause)%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
;
|
||||
<%
|
||||
}
|
||||
} else if (("DELETE").equals(dataAction)){
|
||||
%>
|
||||
String deleteQuery_<%=cid %> = "DELETE FROM "+ tableName_<%=cid%>+" WHERE EXISTS ("+select_query_<%=cid %>+") "
|
||||
|
||||
@@ -40,4 +40,6 @@ TABLE_ACTION.ITEM.CREATE_IF_NOT_EXISTS=Create table if not exists
|
||||
TABLE_ACTION.ITEM.DROP_IF_EXISTS_AND_CREATE=Drop table if exists and create
|
||||
TABLE_ACTION.ITEM.DROP_CREATE=Drop and create table
|
||||
TABLE_ACTION.ITEM.NONE=None
|
||||
TABLE_ACTION.NAME=Action on table
|
||||
TABLE_ACTION.NAME=Action on table
|
||||
|
||||
USE_UPDATE_STATEMENT.NAME=Use update statement without subqueries
|
||||
@@ -107,7 +107,7 @@ imports="
|
||||
}
|
||||
else{
|
||||
%>
|
||||
String url_<%=cid%> = "jdbc:sqlanywhere:Host=" + <%=dbhost %> + ":" + <%=dbport %> + ";DatabaseName" + <%=dbname %> + ";" + <%=dbproperties%>;
|
||||
String url_<%=cid%> = "jdbc:sqlanywhere:Host=" + <%=dbhost %> + ":" + <%=dbport %> + ";DatabaseName=" + <%=dbname %> + ";" + <%=dbproperties%>;
|
||||
<%
|
||||
}
|
||||
}
|
||||
|
||||
@@ -178,7 +178,7 @@
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java_DOM4J1.6" MODULE="dom4j-1.6.1.jar" MVN="mvn:dom4j/dom4j/1.6.1" UrlPath="platform:/plugin/org.talend.libraries.dom4j-jaxen/lib/dom4j-1.6.1.jar" REQUIRED_IF="READ_BY == 'XPATH'" BundleID="" />
|
||||
<IMPORT NAME="Java_JAXEN1.1" MODULE="jaxen-1.1.1.jar" MVN="mvn:org.talend.libraries/jaxen-1.1.1/6.0.0" UrlPath="platform:/plugin/org.talend.libraries.dom4j-jaxen/lib/jaxen-1.1.1.jar" REQUIRED_IF="READ_BY == 'XPATH'" BundleID="" />
|
||||
<IMPORT NAME="json-lib" MODULE="json-lib-2.4.1-talend.jar" MVN="mvn:net.sf.json-lib/json-lib/2.4.1-talend" REQUIRED_IF="READ_BY == 'XPATH'" />
|
||||
<IMPORT NAME="json-lib" MODULE="json-lib-2.4.5-talend.jar" MVN="mvn:net.sf.json-lib/json-lib/2.4.5-talend" REQUIRED_IF="READ_BY == 'XPATH'" />
|
||||
<IMPORT NAME="commons_lang" MODULE="commons-lang-2.6.jar" MVN="mvn:commons-lang/commons-lang/2.6" UrlPath="platform:/plugin/org.talend.libraries.apache.common/lib/commons-lang-2.6.jar" REQUIRED_IF="READ_BY == 'XPATH'" />
|
||||
<IMPORT NAME="commons_logging" MODULE="commons-logging-1.1.1.jar" MVN="mvn:org.talend.libraries/commons-logging-1.1.1/6.0.0" UrlPath="platform:/base/plugins/org.apache.commons.logging_1.1.1.v201101211721.jar" REQUIRED_IF="READ_BY == 'XPATH'" />
|
||||
<IMPORT NAME="ezmorph" MODULE="ezmorph-1.0.6.jar" MVN="mvn:org.talend.libraries/ezmorph-1.0.6/6.0.0" UrlPath="platform:/plugin/org.talend.libraries.jackson/lib/ezmorph-1.0.6.jar" REQUIRED_IF="READ_BY == 'XPATH'" />
|
||||
|
||||
@@ -149,7 +149,7 @@
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Talen File Enhanced"
|
||||
MODULE="talend_file_enhanced_20070724.jar" MVN="mvn:org.talend.libraries/talend_file_enhanced_20070724/6.0.0" UrlPath="platform:/plugin/org.talend.libraries.custom/lib/talend_file_enhanced_20070724.jar" REQUIRED="true" />
|
||||
MODULE="talend_file_enhanced-1.1.jar" MVN="mvn:org.talend.components.lib/talend_file_enhanced/1.1" UrlPath="platform:/plugin/org.talend.libraries.custom/lib/talend_file_enhanced-1.1.jar" REQUIRED="true" />
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
|
||||
@@ -17,20 +17,16 @@
|
||||
if (connObj != null) {
|
||||
try {
|
||||
|
||||
<% if (sftp == false && ftps == false) { %>
|
||||
com.enterprisedt.net.ftp.FTPClient conn = (com.enterprisedt.net.ftp.FTPClient) connObj;
|
||||
conn.executeCommand("quit");
|
||||
<% } else if (sftp) { %>
|
||||
<% if (sftp) { %>
|
||||
com.jcraft.jsch.ChannelSftp channel = (com.jcraft.jsch.ChannelSftp) connObj;
|
||||
com.jcraft.jsch.Session session = channel.getSession();
|
||||
channel.disconnect();
|
||||
session.disconnect();
|
||||
<% } else if (ftps) { %>
|
||||
org.apache.commons.net.ftp.FTPSClient conn = (org.apache.commons.net.ftp.FTPSClient) connObj;
|
||||
conn.disconnect();
|
||||
<% } else { %>
|
||||
System.err.println("Invalid tFTPConnection configuration.");
|
||||
<% } %>
|
||||
org.apache.commons.net.ftp.FTPClient conn = (org.apache.commons.net.ftp.FTPClient) connObj;
|
||||
conn.disconnect();
|
||||
<% }
|
||||
%>
|
||||
|
||||
} catch (Exception e) {
|
||||
globalMap.put("<%=cid%>_ERROR_MESSAGE", e.getMessage());
|
||||
|
||||
@@ -15,16 +15,13 @@
|
||||
%>
|
||||
Object connObj = globalMap.get("conn_<%=connection%>");
|
||||
if (connObj != null) {
|
||||
<% if (sftp == false && ftps == false) { %>
|
||||
com.enterprisedt.net.ftp.FTPClient conn = (com.enterprisedt.net.ftp.FTPClient) connObj;
|
||||
conn.executeCommand("quit");
|
||||
<% } else if (sftp) { %>
|
||||
<% if (sftp) { %>
|
||||
com.jcraft.jsch.ChannelSftp channel = (com.jcraft.jsch.ChannelSftp) connObj;
|
||||
com.jcraft.jsch.Session session = channel.getSession();
|
||||
channel.disconnect();
|
||||
session.disconnect();
|
||||
<% } else if (ftps) { %>
|
||||
org.apache.commons.net.ftp.FTPSClient conn = (org.apache.commons.net.ftp.FTPSClient) connObj;
|
||||
<% } else { %>
|
||||
org.apache.commons.net.ftp.FTPClient conn = (org.apache.commons.net.ftp.FTPClient) connObj;
|
||||
conn.disconnect();
|
||||
<% } %>
|
||||
|
||||
|
||||
@@ -1,88 +0,0 @@
|
||||
<%@ jet
|
||||
%>
|
||||
|
||||
boolean retry_<%=cid%> = false;
|
||||
int retry_count_<%=cid%> = 0;
|
||||
int retry_max_<%=cid%> = 5;
|
||||
|
||||
com.jcraft.jsch.Session session_<%=cid%> = null;
|
||||
com.jcraft.jsch.Channel channel_<%=cid%> = null;
|
||||
|
||||
do {
|
||||
retry_<%=cid%> = false;
|
||||
|
||||
com.jcraft.jsch.JSch jsch_<%=cid%> = new com.jcraft.jsch.JSch();
|
||||
|
||||
<%if (("PUBLICKEY").equals(authMethod)){%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - SFTP authentication using a public key.");
|
||||
log.debug("<%=cid%> - Private key: '" + <%=privateKey%> + "'.");
|
||||
<%}%>
|
||||
jsch_<%=cid%>.addIdentity(<%=privateKey %>, defaultUserInfo_<%=cid%>.getPassphrase());
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%> = jsch_<%=cid%>.getSession(<%=user%>, <%=host%>, <%=port%>);
|
||||
session_<%=cid%>.setConfig("PreferredAuthentications", "publickey,password,keyboard-interactive,gssapi-with-mic");
|
||||
|
||||
<%if (("PASSWORD").equals(authMethod)) {%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - SFTP authentication using a password.");
|
||||
<%}%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
session_<%=cid%>.setPassword(decryptedPassword_<%=cid%>);
|
||||
<%}%>
|
||||
|
||||
session_<%=cid%>.setUserInfo(defaultUserInfo_<%=cid%>);
|
||||
<%if (!useProxy) {%>
|
||||
if(("true").equals(System.getProperty("http.proxySet")) ){
|
||||
com.jcraft.jsch.ProxyHTTP proxy_<%=cid%> = new com.jcraft.jsch.ProxyHTTP(System.getProperty("http.proxyHost"),Integer.parseInt(System.getProperty("http.proxyPort")));
|
||||
if(!"".equals(System.getProperty("http.proxyUser"))){
|
||||
proxy_<%=cid%>.setUserPasswd(System.getProperty("http.proxyUser"),System.getProperty("http.proxyPassword"));
|
||||
}
|
||||
session_<%=cid%>.setProxy(proxy_<%=cid%>);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" + <%=user%> + "'.");
|
||||
<%}%>
|
||||
|
||||
channel_<%=cid%> = null;
|
||||
try {
|
||||
session_<%=cid%>.connect();
|
||||
channel_<%=cid%> = session_<%=cid%>.openChannel("sftp");
|
||||
channel_<%=cid%>.connect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
} catch (com.jcraft.jsch.JSchException e_<%=cid%>) {
|
||||
try {
|
||||
if(channel_<%=cid%>!=null) {
|
||||
channel_<%=cid%>.disconnect();
|
||||
}
|
||||
|
||||
if(session_<%=cid%>!=null) {
|
||||
session_<%=cid%>.disconnect();
|
||||
}
|
||||
} catch(java.lang.Exception ce_<%=cid%>) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - close sftp connection failed : " + ce_<%=cid%>.getClass() + " : " + ce_<%=cid%>.getMessage());
|
||||
<%}%>
|
||||
}
|
||||
|
||||
String message_<%=cid%> = new TalendException(null, null, null).getExceptionCauseMessage(e_<%=cid%>);
|
||||
if(message_<%=cid%>.contains("Signature length not correct") || message_<%=cid%>.contains("connection is closed by foreign host")) {
|
||||
retry_<%=cid%> = true;
|
||||
retry_count_<%=cid%>++;
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - connect: Signature length not correct or connection is closed by foreign host, so retry, retry time : " + retry_count_<%=cid%>);
|
||||
<%}%>
|
||||
} else {
|
||||
throw e_<%=cid%>;
|
||||
}
|
||||
}
|
||||
} while(retry_<%=cid%> && (retry_count_<%=cid%> < retry_max_<%=cid%>));
|
||||
|
||||
com.jcraft.jsch.ChannelSftp c_<%=cid%> = (com.jcraft.jsch.ChannelSftp)channel_<%=cid%>;
|
||||
@@ -28,7 +28,7 @@ String authMethod = ElementParameterParser.getValue(node, "__AUTH_METHOD__");
|
||||
String privateKey = ElementParameterParser.getValue(node, "__PRIVATEKEY__");
|
||||
boolean ftps = ("true").equals(ElementParameterParser.getValue(node, "__FTPS__"));
|
||||
String keystoreFile = ElementParameterParser.getValue(node, "__KEYSTORE_FILE__");
|
||||
String sEncoding = ElementParameterParser.getValue(node, "__ENCODING__");
|
||||
String encoding = ElementParameterParser.getValue(node, "__ENCODING__");
|
||||
String securityMode = ElementParameterParser.getValue(node, "__SECURITY_MODE__");
|
||||
String protectionLevel = ElementParameterParser.getValue(node, "__FTPS_PROT__");
|
||||
String protectionBufferSize = ElementParameterParser.getValue(node, "__FTPS_PROTECTION_BUFF_SIZE__");
|
||||
@@ -60,42 +60,22 @@ if (ElementParameterParser.canEncrypt(node, passwordFieldName)) {
|
||||
});
|
||||
<%
|
||||
}
|
||||
|
||||
%>
|
||||
<%
|
||||
if (!sftp && !ftps) { // *** ftp *** //
|
||||
if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - " + <%=(("ACTIVE").equals(connectMode))?"\"Using the active mode.\"":"\"Using the passive mode.\""%>);
|
||||
<%}%>
|
||||
com.enterprisedt.net.ftp.FTPClient ftp_<%=cid %> = new com.enterprisedt.net.ftp.FTPClient();
|
||||
ftp_<%=cid %>.setRemoteHost(<%=host %>);
|
||||
ftp_<%=cid %>.setRemotePort(<%=port %>);
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPClient ftp_<%=cid %> = null;
|
||||
<%
|
||||
passwordFieldName = "__PASS__";
|
||||
%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftp_connect.javajet"%>
|
||||
|
||||
<%if (("ACTIVE").equals(connectMode)) {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.ACTIVE);
|
||||
<%} else {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.PASV);
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setControlEncoding(<%=sEncoding%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" +<%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect();
|
||||
|
||||
<%
|
||||
passwordFieldName = "__PASS__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
globalMap.put("conn_<%=cid%>",ftp_<%=cid %>);
|
||||
globalMap.put("conn_<%=cid%>",ftp_<%=cid %>);
|
||||
<%
|
||||
} else if (!ftps) { // *** sftp *** //
|
||||
%>
|
||||
class MyUserInfo implements com.jcraft.jsch.UserInfo, com.jcraft.jsch.UIKeyboardInteractive {
|
||||
|
||||
|
||||
<%
|
||||
passwordFieldName = "__PASSPHRASE__";
|
||||
if (ElementParameterParser.canEncrypt(node, passwordFieldName)) {
|
||||
@@ -138,99 +118,20 @@ if (!sftp && !ftps) { // *** ftp *** //
|
||||
passwordFieldName = "__PASS__";
|
||||
%>
|
||||
|
||||
<%@ include file="sftp_connect.javajet"%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/sftp_connect.javajet"%>
|
||||
|
||||
<%if(use_encoding) {%>
|
||||
c_<%=cid%>.setFilenameEncoding(<%=sEncoding%>);
|
||||
c_<%=cid%>.setFilenameEncoding(<%=encoding%>);
|
||||
<%}%>
|
||||
|
||||
globalMap.put("conn_<%=cid%>", c_<%=cid%>);
|
||||
<%
|
||||
} else { // *** ftps *** //
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = null;
|
||||
|
||||
<%@ include file="../templates/FTP/ftpsTrust.javajet"%>
|
||||
javax.net.ssl.SSLContext sslContext_<%=cid %> = null;
|
||||
javax.net.ssl.TrustManager[] trustManager_<%=cid %> = null;
|
||||
javax.net.ssl.SSLSocketFactory sslSocketFactory_<%=cid %> = null;
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = null;
|
||||
MyTrust_<%=cid%> myTrust_<%=cid%> = null;
|
||||
|
||||
try {
|
||||
sslContext_<%=cid %> = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
myTrust_<%=cid%> = new MyTrust_<%=cid%>();
|
||||
trustManager_<%=cid %> = myTrust_<%=cid%>.getTrustManagers();
|
||||
sslContext_<%=cid %>.init(null, trustManager_<%=cid %>, new java.security.SecureRandom());
|
||||
sslSocketFactory_<%=cid %> = sslContext_<%=cid %>.getSocketFactory();
|
||||
boolean isHTTPProxyUsed = "true".equals(System.getProperty("http.proxySet"));
|
||||
if (isHTTPProxyUsed) {
|
||||
String httpProxyHost = System.getProperty("http.proxyHost");
|
||||
int httpProxyPort = Integer.getInteger("http.proxyPort");
|
||||
String httpProxyUser = System.getProperty("http.proxyUser");
|
||||
String httpProxyPass = System.getProperty("http.proxyPassword");
|
||||
|
||||
ftp_<%=cid %> = new org.talend.ftp.HTTPProxyFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>, httpProxyHost, httpProxyPort, httpProxyUser, httpProxyPass);
|
||||
} else {
|
||||
ftp_<%=cid %> = new org.talend.ftp.SSLSessionReuseFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>);
|
||||
}
|
||||
ftp_<%=cid %>.setControlEncoding(<%=sEncoding %>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> -FTPS security Mode is <%=securityMode%>.");
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" + <%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect(<%=host %>,<%=ftpsPort%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setRemoteVerificationEnabled(<%=useRemoteVerification %>);
|
||||
<%
|
||||
passwordFieldName = "__PASS__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isLoginSuccessful_<%=cid %> = ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
|
||||
if (!isLoginSuccessful_<%=cid %>) {
|
||||
throw new RuntimeException("Login failed");
|
||||
}
|
||||
|
||||
ftp_<%=cid %>.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
|
||||
<%
|
||||
if (protectionBufferSize != null && !protectionBufferSize.isEmpty() ) {
|
||||
%>
|
||||
ftp_<%=cid %>.execPBSZ(<%=protectionBufferSize %>);
|
||||
<%
|
||||
}
|
||||
|
||||
if (protectionLevel != null && !protectionLevel.isEmpty()) {
|
||||
%>
|
||||
ftp_<%=cid %>.execPROT(<%=protectionLevel %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
} catch (Exception e) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error("<%=cid%> - Can't create connection: " + e.getMessage());
|
||||
<%}%>
|
||||
throw e;
|
||||
}
|
||||
|
||||
<%
|
||||
if ("PASSIVE".equals(connectMode)) {
|
||||
%>
|
||||
ftp_<%=cid %>.enterLocalPassiveMode();
|
||||
<%
|
||||
if (isLog4jEnabled) {
|
||||
%>
|
||||
log.debug("<%=cid%> - Using the passive mode.");
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
globalMap.put("conn_<%=cid%>", ftp_<%=cid %>);
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftps_connect.javajet"%>
|
||||
globalMap.put("conn_<%=cid%>", ftp_<%=cid %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
@@ -185,7 +185,6 @@
|
||||
REQUIRED="true" NOT_SHOW_IF="(SFTP == 'true') and (USE_ENCODING == 'false')">
|
||||
<DEFAULT>"ISO-8859-15"</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
</PARAMETERS>
|
||||
|
||||
<ADVANCED_PARAMETERS>
|
||||
@@ -236,10 +235,10 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java-FTP" MODULE="edtftpj-2.5.0.jar" MVN="mvn:com.enterprisedt/edtftpj/2.5.0" UrlPath="platform:/plugin/org.talend.libraries.ftp/lib/edtftpj-2.5.0.jar" REQUIRED_IF="(SFTP == 'false') AND (FTPS == 'false')"/>
|
||||
<IMPORT NAME="Java-SFTP" MODULE="jsch-0.1.55.jar" MVN="mvn:com.jcraft/jsch/0.1.55" REQUIRED_IF="(SFTP == 'true')"/>
|
||||
<IMPORT NAME="Java-FTPS" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(FTPS == 'true')" />
|
||||
<IMPORT NAME="Java-FTPS-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190128.jar" MVN="mvn:org.talend.libraries/commons-net-ftps-proxy/3.6.1-talend-20190128" REQUIRED_IF="(FTPS == 'true')" />
|
||||
<IMPORT NAME="Java-FTP+S" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(SFTP == 'false')" />
|
||||
<IMPORT NAME="FTP+S-Proxy-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190819.jar" MVN="mvn:org.talend.components.lib/commons-net-ftps-proxy/3.6.1-talend-20190819" REQUIRED_IF="(FTPS == 'true')" />
|
||||
<IMPORT NAME="talend-proxy" MODULE="talend-proxy-1.0.1.jar" MVN="mvn:org.talend.components.lib/talend-proxy/1.0.1" REQUIRED="true" />
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
|
||||
@@ -55,6 +55,8 @@ if (("true").equals(useExistingConn)) {
|
||||
} else {
|
||||
sftp = ("true").equals(ElementParameterParser.getValue(node, "__SFTP__"));
|
||||
ftps = ("true").equals(ElementParameterParser.getValue(node, "__FTPS__"));
|
||||
%>
|
||||
<%
|
||||
}
|
||||
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
@@ -129,7 +131,7 @@ int nb_file_<%=cid%> = 0;
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="../tFTPConnection/sftp_connect.javajet"%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/sftp_connect.javajet"%>
|
||||
|
||||
<%if(use_encoding) {%>
|
||||
c_<%=cid%>.setFilenameEncoding(<%=encoding%>);
|
||||
@@ -166,191 +168,70 @@ int nb_file_<%=cid%> = 0;
|
||||
for (java.util.Map<String, String> map<%=cid %> : list<%=cid %>) {
|
||||
|
||||
<%
|
||||
} else if (ftps) { // *** ftps *** //
|
||||
} else {
|
||||
if (ftps) { // *** ftps *** //
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = null;
|
||||
<%
|
||||
if (("false").equals(useExistingConn)) {
|
||||
String keystoreFile = ElementParameterParser.getValue(node, "__KEYSTORE_FILE__");
|
||||
String securityMode = ElementParameterParser.getValue(node, "__SECURITY_MODE__");
|
||||
%>
|
||||
<%@ include file="../templates/FTP/ftpsTrust.javajet"%>
|
||||
javax.net.ssl.SSLContext sslContext_<%=cid %> = null;
|
||||
javax.net.ssl.TrustManager[] trustManager_<%=cid %> = null;
|
||||
javax.net.ssl.SSLSocketFactory sslSocketFactory_<%=cid %> = null;
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> =null;
|
||||
MyTrust_<%=cid %> myTrust_<%=cid%> = null;
|
||||
|
||||
try {
|
||||
sslContext_<%=cid %> = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
myTrust_<%=cid%> = new MyTrust_<%=cid%>();
|
||||
trustManager_<%=cid %> = myTrust_<%=cid%>.getTrustManagers();
|
||||
sslContext_<%=cid %>.init(null, trustManager_<%=cid %>, new java.security.SecureRandom());
|
||||
sslSocketFactory_<%=cid %> = sslContext_<%=cid %>.getSocketFactory();
|
||||
boolean isHTTPProxyUsed = "true".equals(System.getProperty("http.proxySet"));
|
||||
if (isHTTPProxyUsed) {
|
||||
String httpProxyHost = System.getProperty("http.proxyHost");
|
||||
int httpProxyPort = Integer.getInteger("http.proxyPort");
|
||||
String httpProxyUser = System.getProperty("http.proxyUser");
|
||||
String httpProxyPass = System.getProperty("http.proxyPassword");
|
||||
|
||||
ftp_<%=cid %> = new org.talend.ftp.HTTPProxyFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>, httpProxyHost, httpProxyPort, httpProxyUser, httpProxyPass);
|
||||
} else {
|
||||
ftp_<%=cid %> = new org.talend.ftp.SSLSessionReuseFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>);
|
||||
}
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> -FTPS security Mode is <%=securityMode%>.");
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" + <%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect(<%=host %>,<%=ftpsPort %>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setRemoteVerificationEnabled(<%=useRemoteVerification %>);
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftps_connect.javajet"%>
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isLoginSuccessful_<%=cid %> = ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
|
||||
if (!isLoginSuccessful_<%=cid %>) {
|
||||
throw new RuntimeException("Login failed");
|
||||
}
|
||||
|
||||
<%
|
||||
if (protectionBufferSize != null && !protectionBufferSize.isEmpty() ) {
|
||||
%>
|
||||
ftp_<%=cid %>.execPBSZ(<%=protectionBufferSize %>);
|
||||
<%
|
||||
}
|
||||
|
||||
if (protectionLevel != null && !protectionLevel.isEmpty()) {
|
||||
%>
|
||||
ftp_<%=cid %>.execPROT(<%=protectionLevel %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
} catch (Exception e) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error("<%=cid%> - Can't create connection: " + e.getMessage());
|
||||
<%}%>
|
||||
<%
|
||||
if (dieOnError) {
|
||||
%>
|
||||
throw e;
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
e.printStackTrace();
|
||||
<%
|
||||
}
|
||||
%>
|
||||
}
|
||||
|
||||
<%
|
||||
if ("PASSIVE".equals(connectMode)) {
|
||||
%>
|
||||
ftp_<%=cid %>.enterLocalPassiveMode();
|
||||
<%
|
||||
if (isLog4jEnabled) {
|
||||
%>
|
||||
log.debug("<%=cid%> - Using the passive mode.");
|
||||
<%
|
||||
}
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient) globalMap.get("<%=conn %>");
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient) globalMap.get("<%=conn %>");
|
||||
<%
|
||||
if (moveToCurrentDir) {
|
||||
%>
|
||||
boolean cwdSuccess_<%=cid %> = ftp_<%=cid %>.changeWorkingDirectory(<%=remotedir %>);
|
||||
|
||||
if (!cwdSuccess_<%=cid %>) {
|
||||
throw new RuntimeException("Failed to change remote directory. " + ftp_<%=cid %>.getReplyString());
|
||||
}
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
<% /*store real pwd*/ %>
|
||||
String rootWorkDir_<%=cid %> = ftp_<%=cid %>.printWorkingDirectory();
|
||||
java.util.List<java.util.Map<String,String>> list<%=cid %> = new java.util.ArrayList<>();
|
||||
|
||||
<%
|
||||
for (int i=0; i<files.size(); i++) {
|
||||
Map<String, String> line = files.get(i);
|
||||
} else {// *** ftp *** //
|
||||
%>
|
||||
java.util.Map<String,String> map<%=cid %><%=i %> = new java.util.HashMap<String,String>();
|
||||
map<%=cid %><%=i %>.put(<%= line.get("FILEMASK") %>,"");
|
||||
list<%=cid %>.add(map<%=cid %><%=i %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
for (java.util.Map<String, String> map<%=cid %> : list<%=cid %>) {
|
||||
<%
|
||||
} else {// *** ftp *** //
|
||||
%>
|
||||
com.enterprisedt.net.ftp.FTPClient ftp_<%=cid %> =null;
|
||||
org.apache.commons.net.ftp.FTPClient ftp_<%=cid %> =null;
|
||||
|
||||
<%if (("true").equals(useExistingConn)) {%>
|
||||
ftp_<%=cid %> = (com.enterprisedt.net.ftp.FTPClient)globalMap.get("<%=conn %>");
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPClient) globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteHost() + ",Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteAddress().toString() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%if(!moveToCurrentDir){%>
|
||||
String rootDir_<%=cid %> = ftp_<%=cid %>.pwd();
|
||||
<%}%>
|
||||
<%} else {%>
|
||||
ftp_<%=cid %> = new com.enterprisedt.net.ftp.FTPClient();
|
||||
ftp_<%=cid %>.setRemoteHost(<%=host %>);
|
||||
ftp_<%=cid %>.setRemotePort(<%=port %>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - " + <%=(("ACTIVE").equals(connectMode))?"\"Using the active mode.\"":"\"Using the passive mode.\""%>);
|
||||
<%}%>
|
||||
<%if (("ACTIVE").equals(connectMode)) {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.ACTIVE);
|
||||
<%} else {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.PASV);
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username: '" +<%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect();
|
||||
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%}%>
|
||||
java.util.List<java.util.Map<String,String>> list<%=cid %> = new java.util.ArrayList<java.util.Map<String,String>>();
|
||||
|
||||
<%for (int i = 0; i < files.size(); i++) {
|
||||
Map<String, String> line = files.get(i);
|
||||
%>
|
||||
java.util.Map<String,String> map<%=cid %><%=i %> = new java.util.HashMap<String,String>();
|
||||
map<%=cid %><%=i %>.put(<%= line.get("FILEMASK") %>,"");
|
||||
list<%=cid %>.add(map<%=cid %><%=i %>);
|
||||
<%}%>
|
||||
String remotedir<%=cid %> = <%=remotedir%>;
|
||||
ftp_<%=cid %>.chdir(remotedir<%=cid %>);
|
||||
String root<%=cid %> = ftp_<%=cid %>.pwd();
|
||||
<%} else {
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftp_connect.javajet"%>
|
||||
<%}%>
|
||||
<%
|
||||
}//common code ftp and ftps:
|
||||
%>
|
||||
<%
|
||||
if (("true").equals(useExistingConn) && moveToCurrentDir) {
|
||||
%>
|
||||
boolean cwdSuccess_<%=cid %> = ftp_<%=cid %>.changeWorkingDirectory(<%=remotedir %>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
<%if("FILE".equals(targetType)){%>
|
||||
log.info("<%=cid%> - Deleting file from server.");
|
||||
<%}else{%>
|
||||
log.info("<%=cid%> - Deleting directory from server.");
|
||||
<%}%>
|
||||
<%}%>
|
||||
for (java.util.Map<String, String> map<%=cid %> : list<%=cid %>) {
|
||||
<%}%>
|
||||
if (!cwdSuccess_<%=cid %>) {
|
||||
throw new RuntimeException("Failed to change remote directory. " + ftp_<%=cid %>.getReplyString());
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<% /*store real pwd*/ %>
|
||||
String rootWorkDir_<%=cid %> = ftp_<%=cid %>.printWorkingDirectory();
|
||||
java.util.List<java.util.Map<String,String>> list<%=cid %> = new java.util.ArrayList<>();
|
||||
<%
|
||||
for (int i=0; i<files.size(); i++) {
|
||||
Map<String, String> line = files.get(i);
|
||||
%>
|
||||
java.util.Map<String,String> map<%=cid %><%=i %> = new java.util.HashMap<String,String>();
|
||||
map<%=cid %><%=i %>.put(<%= line.get("FILEMASK") %>,"");
|
||||
list<%=cid %>.add(map<%=cid %><%=i %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
for (java.util.Map<String, String> map<%=cid %> : list<%=cid %>) {
|
||||
<%
|
||||
}
|
||||
%>
|
||||
@@ -70,14 +70,14 @@
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
}catch(java.net.SocketException se_<%=cid%>){
|
||||
}catch(java.io.IOException ioe_<%=cid%>){
|
||||
//ignore failure
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - " + se_<%=cid%>.getMessage());
|
||||
log.warn("<%=cid%> - " + ioe_<%=cid%>.getMessage());
|
||||
<%}%>
|
||||
}
|
||||
<%
|
||||
@@ -86,18 +86,12 @@
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}else{
|
||||
if(!moveToCurrentDir){
|
||||
%>
|
||||
ftp_<%=cid %>.chdir(rootDir_<%=cid %>);
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
@@ -177,7 +177,7 @@
|
||||
<DEFAULT>"."</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="MOVE_TO_THE_CURRENT_DIRECTORY" FIELD="CHECK" NUM_ROW="31" SHOW_IF="USE_EXISTING_CONNECTION == 'true'">
|
||||
<PARAMETER NAME="MOVE_TO_THE_CURRENT_DIRECTORY" FIELD="CHECK" NUM_ROW="31" SHOW_IF="(USE_EXISTING_CONNECTION == 'true') AND (#LINK@NODE.CONNECTION.SFTP == 'false')">
|
||||
<DEFAULT>true</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
@@ -292,13 +292,13 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java-FTP" MODULE="edtftpj-2.5.0.jar" MVN="mvn:com.enterprisedt/edtftpj/2.5.0" REQUIRED_IF="(SFTP == 'false') AND (FTPS == 'false') AND (USE_EXISTING_CONNECTION == 'false')"/>
|
||||
<IMPORT NAME="Java-SFTP" MODULE="jsch-0.1.55.jar" MVN="mvn:com.jcraft/jsch/0.1.55" REQUIRED_IF="(SFTP == 'true') AND (USE_EXISTING_CONNECTION == 'false')"/>
|
||||
<IMPORT NAME="jakarta-oro" MODULE="jakarta-oro-2.0.8.jar" MVN="mvn:org.talend.libraries/jakarta-oro-2.0.8/6.0.0" UrlPath="platform:/plugin/org.talend.libraries.apache/lib/jakarta-oro-2.0.8.jar" REQUIRED="true" />
|
||||
<IMPORT NAME="Java-FTPS" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(FTPS == 'true') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Java-FTPS-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190128.jar"
|
||||
MVN="mvn:org.talend.libraries/commons-net-ftps-proxy/3.6.1-talend-20190128" UrlPath="platform:/plugin/org.talend.designer.components.localprovider/components/tFTPConnection/commons-net-ftps-proxy-3.6.1-talend-20190128.jar"
|
||||
REQUIRED_IF="(FTPS == 'true') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Java-FTP+S" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(SFTP == 'false') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="FTP+S-Proxy-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190819.jar"
|
||||
MVN="mvn:org.talend.components.lib/commons-net-ftps-proxy/3.6.1-talend-20190819"
|
||||
REQUIRED_IF="(SFTP == 'false') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="talend-proxy" MODULE="talend-proxy-1.0.1.jar" MVN="mvn:org.talend.components.lib/talend-proxy/1.0.1" REQUIRED_IF="USE_EXISTING_CONNECTION == 'false'" />
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
<RETURNS>
|
||||
|
||||
@@ -95,7 +95,7 @@
|
||||
|
||||
|
||||
<%
|
||||
}else if (ftps) { // *** ftps *** //
|
||||
}else { // *** ftp, ftps *** //
|
||||
%>
|
||||
for (String key<%=cid %> : keySet<%=cid %>) {
|
||||
<% /*prepare filemask*/ %>
|
||||
@@ -241,73 +241,6 @@
|
||||
|
||||
<% /*return to root dir for next filemask*/ %>
|
||||
ftp_<%=cid %>.changeWorkingDirectory(rootWorkDir_<%=cid %>);
|
||||
<%
|
||||
}else {// *** ftp *** //
|
||||
%>
|
||||
try {
|
||||
for (String key<%=cid %> : keySet<%=cid %>) {
|
||||
String filemask<%=cid %> = key<%=cid %>;
|
||||
String dir<%=cid %> = null;
|
||||
<%if(!usePerl5) {//perl5 mode not support windows(\) path separator at the mask string%>
|
||||
String mask<%=cid %> = filemask<%=cid %>.replaceAll("\\\\", "/") ;
|
||||
<%}else{%>
|
||||
String mask<%=cid %> = filemask<%=cid %>;
|
||||
<%}%>
|
||||
int i<%=cid %> = mask<%=cid %>.lastIndexOf('/');
|
||||
if (i<%=cid %>!=-1) {
|
||||
dir<%=cid %> = mask<%=cid %>.substring(0, i<%=cid %>);
|
||||
mask<%=cid %> = mask<%=cid %>.substring(i<%=cid %>+1);
|
||||
}
|
||||
if (dir<%=cid %>!=null && !"".equals(dir<%=cid %>)) ftp_<%=cid %>.chdir(dir<%=cid %>);
|
||||
<%if(!usePerl5) {%>
|
||||
mask<%=cid %> = org.apache.oro.text.GlobCompiler.globToPerl5(mask<%=cid %>.toCharArray(), org.apache.oro.text.GlobCompiler.DEFAULT_MASK);
|
||||
<%}%>
|
||||
String[] fileName_<%=cid%> = null;
|
||||
boolean dirFailed_<%=cid%> = false;
|
||||
try{
|
||||
fileName_<%=cid%> = ftp_<%=cid%>.dir(null,false);
|
||||
}catch(com.enterprisedt.net.ftp.FTPException e_<%=cid%>){
|
||||
dirFailed_<%=cid%> = true;
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - " + e_<%=cid%>.getMessage());
|
||||
<%}%>
|
||||
}
|
||||
if((fileName_<%=cid%> == null) || dirFailed_<%=cid%> || (fileName_<%=cid%>.length <= 0)){
|
||||
com.enterprisedt.net.ftp.FTPFile[] fileList_<%=cid%> = ftp_<%=cid%>.dirDetails(null);
|
||||
fileName_<%=cid%> = new String[fileList_<%=cid%>.length];
|
||||
for (int i_<%=cid%> = 0 ; i_<%=cid%> < fileList_<%=cid%>.length ; i_<%=cid%>++){
|
||||
fileName_<%=cid%>[i_<%=cid%>] = fileList_<%=cid%>[i_<%=cid%>].getName();
|
||||
}
|
||||
}
|
||||
for (String file_<%=cid%> : fileName_<%=cid%>) {
|
||||
if (file_<%=cid%>.matches(mask<%=cid %>)) {
|
||||
<%
|
||||
if("FILE".equals(targetType)){
|
||||
%>
|
||||
ftp_<%=cid %>.delete(file_<%=cid%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - File '" + file_<%=cid%> + "' was deleted from the remote directory " + <%=remotedir %> + ".");
|
||||
<%}%>
|
||||
<%
|
||||
}else{
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Directory '" + file_<%=cid%> + "' was deleted from the remote directory " + <%=remotedir %> + ".");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.rmdir(file_<%=cid%>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File deleted.");
|
||||
nb_file_<%=cid%>++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}catch(com.enterprisedt.net.ftp.FTPException e_<%=cid %>){
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "Deleting file action error");
|
||||
throw e_<%=cid %>;
|
||||
}
|
||||
ftp_<%=cid %>.chdir(root<%=cid %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
@@ -57,6 +57,8 @@ if (("true").equals(useExistingConn)) {
|
||||
} else {
|
||||
sftp = ("true").equals(ElementParameterParser.getValue(node, "__SFTP__"));
|
||||
ftps = ("true").equals(ElementParameterParser.getValue(node, "__FTPS__"));
|
||||
%>
|
||||
<%
|
||||
}
|
||||
|
||||
String passwordFieldName = "";
|
||||
@@ -134,7 +136,7 @@ if (sftp) { // *** sftp *** //
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="../tFTPConnection/sftp_connect.javajet"%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/sftp_connect.javajet"%>
|
||||
|
||||
<%if(use_encoding) {%>
|
||||
c_<%=cid%>.setFilenameEncoding(<%=encoding%>);
|
||||
@@ -153,134 +155,38 @@ if (sftp) { // *** sftp *** //
|
||||
}
|
||||
<%
|
||||
}
|
||||
} else if (ftps) { // *** ftps *** //
|
||||
if (("false").equals(useExistingConn)) {
|
||||
String keystoreFile = ElementParameterParser.getValue(node, "__KEYSTORE_FILE__");
|
||||
String securityMode = ElementParameterParser.getValue(node, "__SECURITY_MODE__");
|
||||
} else { // *** ftp+s *** //
|
||||
if (ftps) {
|
||||
%>
|
||||
<%@ include file="../templates/FTP/ftpsTrust.javajet"%>
|
||||
javax.net.ssl.SSLContext sslContext_<%=cid %> = null;
|
||||
javax.net.ssl.TrustManager[] trustManager_<%=cid %> = null;
|
||||
javax.net.ssl.SSLSocketFactory sslSocketFactory_<%=cid %> = null;
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> =null;
|
||||
MyTrust_<%=cid %> myTrust_<%=cid%> = null;
|
||||
|
||||
try {
|
||||
sslContext_<%=cid %> = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
myTrust_<%=cid%> = new MyTrust_<%=cid%>();
|
||||
trustManager_<%=cid %> = myTrust_<%=cid%>.getTrustManagers();
|
||||
sslContext_<%=cid %>.init(null, trustManager_<%=cid %>, new java.security.SecureRandom());
|
||||
sslSocketFactory_<%=cid %> = sslContext_<%=cid %>.getSocketFactory();
|
||||
boolean isHTTPProxyUsed = "true".equals(System.getProperty("http.proxySet"));
|
||||
if (isHTTPProxyUsed) {
|
||||
String httpProxyHost = System.getProperty("http.proxyHost");
|
||||
int httpProxyPort = Integer.getInteger("http.proxyPort");
|
||||
String httpProxyUser = System.getProperty("http.proxyUser");
|
||||
String httpProxyPass = System.getProperty("http.proxyPassword");
|
||||
|
||||
ftp_<%=cid %> = new org.talend.ftp.HTTPProxyFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>, httpProxyHost, httpProxyPort, httpProxyUser, httpProxyPass);
|
||||
} else {
|
||||
ftp_<%=cid %> = new org.talend.ftp.SSLSessionReuseFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>);
|
||||
}
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> -FTPS security Mode is <%=securityMode%>.");
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" + <%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect(<%=host %>,<%=ftpsPort %>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setRemoteVerificationEnabled(<%=useRemoteVerification %>);
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = null;
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
if (("false").equals(useExistingConn)) {
|
||||
String keystoreFile = ElementParameterParser.getValue(node, "__KEYSTORE_FILE__");
|
||||
String securityMode = ElementParameterParser.getValue(node, "__SECURITY_MODE__");
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isLoginSuccessful_<%=cid %> = ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
|
||||
if (!isLoginSuccessful_<%=cid %>) {
|
||||
throw new RuntimeException("Login failed");
|
||||
}
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftps_connect.javajet"%>
|
||||
<%
|
||||
if (protectionBufferSize != null && !protectionBufferSize.isEmpty() ) {
|
||||
} else {
|
||||
%>
|
||||
ftp_<%=cid %>.execPBSZ(<%=protectionBufferSize %>);
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient) globalMap.get("<%=conn %>");
|
||||
<%
|
||||
}
|
||||
|
||||
if (protectionLevel != null && !protectionLevel.isEmpty()) {
|
||||
}
|
||||
} else { // *** ftp *** //
|
||||
%>
|
||||
ftp_<%=cid %>.execPROT(<%=protectionLevel %>);
|
||||
org.apache.commons.net.ftp.FTPClient ftp_<%=cid %> = null;
|
||||
<%
|
||||
}
|
||||
if (("true").equals(useExistingConn)) {%>
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPClient) globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Use an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteAddress().toString() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%} else {
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
} catch (Exception e) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error("<%=cid%> - Can't create connection: " + e.getMessage());
|
||||
<%}%>
|
||||
throw e;
|
||||
}
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftp_connect.javajet"%>
|
||||
<%
|
||||
if ("PASSIVE".equals(connectMode)) {
|
||||
%>
|
||||
ftp_<%=cid %>.enterLocalPassiveMode();
|
||||
<%
|
||||
if (isLog4jEnabled) {
|
||||
%>
|
||||
log.debug("<%=cid%> - Using the passive mode.");
|
||||
<%
|
||||
}
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient) globalMap.get("<%=conn %>");
|
||||
<%
|
||||
}
|
||||
} else { // *** ftp *** //
|
||||
%>
|
||||
com.enterprisedt.net.ftp.FTPClient ftp_<%=cid %> = null;
|
||||
|
||||
<% if (("true").equals(useExistingConn)) {%>
|
||||
ftp_<%=cid %> = (com.enterprisedt.net.ftp.FTPClient)globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Use an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteHost() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%} else {%>
|
||||
ftp_<%=cid %> = new com.enterprisedt.net.ftp.FTPClient();
|
||||
ftp_<%=cid %>.setRemoteHost(<%=host %>);
|
||||
ftp_<%=cid %>.setRemotePort(<%=port %>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - " + <%=(("ACTIVE").equals(connectMode))?"\"Using the active mode.\"":"\"Using the passive mode.\""%>);
|
||||
<%}%>
|
||||
|
||||
<%if (("ACTIVE").equals(connectMode)) {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.ACTIVE);
|
||||
<%} else {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.PASV);
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username: '" +<%=username %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect();
|
||||
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
ftp_<%=cid %>.login(<%=username %>, decryptedPassword_<%=cid%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host%> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}
|
||||
}%>
|
||||
|
||||
@@ -56,41 +56,35 @@ if (sftp) { // *** sftp *** //
|
||||
<%
|
||||
}
|
||||
} else { // *** ftp *** //
|
||||
if (!("true").equals(useExistingConn)) {
|
||||
if (("true").equals(ignoreFailureAtQuit)) {
|
||||
%>
|
||||
try {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
} catch(java.net.SocketException se_<%=cid%>) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - " + se_<%=cid%>.getMessage());
|
||||
<%}%>
|
||||
//ignore failure
|
||||
}
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
} else {
|
||||
if (moveToCurrentDir) {
|
||||
if (!("true").equals(useExistingConn)) {
|
||||
if (("true").equals(ignoreFailureAtQuit)) {
|
||||
%>
|
||||
ftp_<%=cid %>.chdir(<%=remoteDir %>);
|
||||
try {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
} catch(java.io.IOException ioe_<%=cid%>) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - " + ioe_<%=cid%>.getMessage());
|
||||
<%}%>
|
||||
//ignore failure
|
||||
}
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
<%
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
%>
|
||||
|
||||
@@ -170,7 +170,7 @@ COMPATIBILITY="ALL"
|
||||
<DEFAULT>"."</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="MOVE_TO_THE_CURRENT_DIRECTORY" FIELD="CHECK" NUM_ROW="61" SHOW_IF="USE_EXISTING_CONNECTION == 'true'">
|
||||
<PARAMETER NAME="MOVE_TO_THE_CURRENT_DIRECTORY" FIELD="CHECK" NUM_ROW="61" SHOW_IF="(USE_EXISTING_CONNECTION == 'true') AND (#LINK@NODE.CONNECTION.SFTP == 'false')">
|
||||
<DEFAULT>true</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
@@ -280,12 +280,12 @@ COMPATIBILITY="ALL"
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java-FTP" MODULE="edtftpj-2.5.0.jar" MVN="mvn:com.enterprisedt/edtftpj/2.5.0" UrlPath="platform:/plugin/org.talend.libraries.ftp/lib/edtftpj-2.5.0.jar" REQUIRED_IF="(SFTP == 'false') AND (FTPS == 'false') AND (USE_EXISTING_CONNECTION == 'false')"/>
|
||||
<IMPORT NAME="Java-SFTP" MODULE="jsch-0.1.55.jar" MVN="mvn:com.jcraft/jsch/0.1.55" REQUIRED_IF="(SFTP == 'true') AND (USE_EXISTING_CONNECTION == 'false')"/>
|
||||
<IMPORT NAME="Java-FTPS" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(FTPS == 'true') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Java-FTPS-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190128.jar"
|
||||
MVN="mvn:org.talend.libraries/commons-net-ftps-proxy/3.6.1-talend-20190128" UrlPath="platform:/plugin/org.talend.designer.components.localprovider/components/tFTPConnection/commons-net-ftps-proxy-3.6.1-talend-20190128.jar"
|
||||
REQUIRED_IF="(FTPS == 'true') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Java-FTP+S" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(SFTP == 'false') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="FTP+S-Proxy-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190819.jar"
|
||||
MVN="mvn:org.talend.components.lib/commons-net-ftps-proxy/3.6.1-talend-20190819"
|
||||
REQUIRED_IF="(SFTP == 'false') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="talend-proxy" MODULE="talend-proxy-1.0.1.jar" MVN="mvn:org.talend.components.lib/talend-proxy/1.0.1" REQUIRED_IF="USE_EXISTING_CONNECTION == 'false'" />
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ if (sftp) { // *** sftp *** //
|
||||
}
|
||||
globalMap.put("<%=cid %>_DIRECTORYNAME", <%=directoryname %>);
|
||||
<%}
|
||||
} else if (ftps) { // *** ftps *** //
|
||||
} else { // *** ftp+s *** //
|
||||
%>
|
||||
//change working dir and save root
|
||||
String remoteDir_<%=cid %> = (<%=remoteDir %>).replaceAll("\\\\","/");
|
||||
@@ -155,35 +155,5 @@ if (sftp) { // *** sftp *** //
|
||||
ftp_<%=cid %>.changeWorkingDirectory(remoteDir_<%=cid %>);
|
||||
<%
|
||||
}
|
||||
} else { // *** ftp *** //
|
||||
if (isFileType){%>
|
||||
String remoteDir_<%=cid %> = (<%=remoteDir %>).replaceAll("\\\\","/");
|
||||
if (ftp_<%=cid %>.exists<%="File" %>(remoteDir_<%=cid %> + "/" + <%=filename %>)) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - '" + <%=filename%> + "' exists in the remote directory '"+ <%=remoteDir %> + "' .");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_EXISTS", true);
|
||||
} else {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - '" + <%=filename%> + "' doesn't exist in the remote directory '"+ <%=remoteDir %> + "' .");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_EXISTS", false);
|
||||
}
|
||||
globalMap.put("<%=cid %>_FILENAME", <%=filename %>);
|
||||
<%} else {%>
|
||||
String remoteDir_<%=cid %> = (<%=remoteDir %>).replaceAll("\\\\","/");
|
||||
String directoryname_<%=cid %> = (<%=directoryname %>).replaceAll("\\\\","/");
|
||||
if (ftp_<%=cid %>.exists<%="Directory" %>(remoteDir_<%=cid %> + "/" + directoryname_<%=cid %>)) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - '" + <%=directoryname %> + "' exists in the remote directory '"+ <%=remoteDir %> + "' .");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_EXISTS", true);
|
||||
} else {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - '" + <%=directoryname %> + "' doesn't exist in the remote directory '"+ <%=remoteDir %> + "' .");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_EXISTS", false);
|
||||
}
|
||||
globalMap.put("<%=cid %>_DIRECTORYNAME", <%=directoryname %>);
|
||||
<%}
|
||||
}%>
|
||||
}
|
||||
%>
|
||||
@@ -56,6 +56,8 @@ if (("true").equals(useExistingConn)) {
|
||||
} else {
|
||||
sftp = ("true").equals(ElementParameterParser.getValue(node, "__SFTP__"));
|
||||
ftps = ("true").equals(ElementParameterParser.getValue(node, "__FTPS__"));
|
||||
%>
|
||||
<%
|
||||
}
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
String passwordFieldName = "";
|
||||
@@ -151,7 +153,7 @@ if (sftp) {// *** sftp *** //
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="../tFTPConnection/sftp_connect.javajet"%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/sftp_connect.javajet"%>
|
||||
|
||||
<%if(use_encoding) {%>
|
||||
c_<%=cid%>.setFilenameEncoding(<%=encoding%>);
|
||||
@@ -232,255 +234,104 @@ if (sftp) {// *** sftp *** //
|
||||
globalMap.put("<%=cid %>_CURRENT_FILEPATH", currentFilePath_<%=cid%>);
|
||||
nb_file_<%=cid%>++;
|
||||
<%
|
||||
} else if (ftps) { // *** ftps *** //
|
||||
if (("false").equals(useExistingConn)) {
|
||||
String keystoreFile = ElementParameterParser.getValue(node, "__KEYSTORE_FILE__");
|
||||
String securityMode = ElementParameterParser.getValue(node, "__SECURITY_MODE__");
|
||||
} else {
|
||||
if (ftps) { // *** ftps *** //
|
||||
%>
|
||||
<%@ include file="../templates/FTP/ftpsTrust.javajet"%>
|
||||
javax.net.ssl.SSLContext sslContext_<%=cid %> = null;
|
||||
javax.net.ssl.TrustManager[] trustManager_<%=cid %> = null;
|
||||
javax.net.ssl.SSLSocketFactory sslSocketFactory_<%=cid %> = null;
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> =null;
|
||||
MyTrust_<%=cid %> myTrust_<%=cid%> = null;
|
||||
|
||||
try {
|
||||
sslContext_<%=cid %> = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
myTrust_<%=cid%> = new MyTrust_<%=cid%>();
|
||||
trustManager_<%=cid %> = myTrust_<%=cid%>.getTrustManagers();
|
||||
sslContext_<%=cid %>.init(null, trustManager_<%=cid %>, new java.security.SecureRandom());
|
||||
sslSocketFactory_<%=cid %> = sslContext_<%=cid %>.getSocketFactory();
|
||||
boolean isHTTPProxyUsed = "true".equals(System.getProperty("http.proxySet"));
|
||||
if (isHTTPProxyUsed) {
|
||||
String httpProxyHost = System.getProperty("http.proxyHost");
|
||||
int httpProxyPort = Integer.getInteger("http.proxyPort");
|
||||
String httpProxyUser = System.getProperty("http.proxyUser");
|
||||
String httpProxyPass = System.getProperty("http.proxyPassword");
|
||||
|
||||
ftp_<%=cid %> = new org.talend.ftp.HTTPProxyFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>, httpProxyHost, httpProxyPort, httpProxyUser, httpProxyPass);
|
||||
} else {
|
||||
ftp_<%=cid %> = new org.talend.ftp.SSLSessionReuseFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>);
|
||||
}
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> -FTPS security Mode is <%=securityMode%>.");
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" + <%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect(<%=host %>,<%=ftpsPort %>);
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = null;
|
||||
<%
|
||||
if(isLog4jEnabled){
|
||||
if (("false").equals(useExistingConn)) {
|
||||
String keystoreFile = ElementParameterParser.getValue(node, "__KEYSTORE_FILE__");
|
||||
String securityMode = ElementParameterParser.getValue(node, "__SECURITY_MODE__");
|
||||
%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftps_connect.javajet"%>
|
||||
<%
|
||||
}
|
||||
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
} else {
|
||||
%>
|
||||
ftp_<%=cid %>.setRemoteVerificationEnabled(<%=useRemoteVerification %>);
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isLoginSuccessful_<%=cid %> = ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
|
||||
if (!isLoginSuccessful_<%=cid %>) {
|
||||
throw new RuntimeException("Login failed");
|
||||
}
|
||||
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient) globalMap.get("<%=conn %>");
|
||||
<%
|
||||
if (protectionBufferSize != null && !protectionBufferSize.isEmpty() ) {
|
||||
}
|
||||
} else { // *** ftp
|
||||
%>
|
||||
ftp_<%=cid %>.execPBSZ(<%=protectionBufferSize %>);
|
||||
org.apache.commons.net.ftp.FTPClient ftp_<%=cid %> = null;
|
||||
<%
|
||||
}
|
||||
|
||||
if (protectionLevel != null && !protectionLevel.isEmpty()) {
|
||||
if (("true").equals(useExistingConn)) {%>
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPClient) globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Use an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteAddress().toString() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%
|
||||
} else {
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
ftp_<%=cid %>.execPROT(<%=protectionLevel %>);
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftp_connect.javajet"%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
} catch (Exception e) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error("<%=cid%> - Can't create connection: " + e.getMessage());
|
||||
<%}%>
|
||||
throw e;
|
||||
}
|
||||
<%
|
||||
if ("PASSIVE".equals(connectMode)) {
|
||||
%>
|
||||
ftp_<%=cid %>.enterLocalPassiveMode();
|
||||
<%
|
||||
if (isLog4jEnabled) {
|
||||
%>
|
||||
log.debug("<%=cid%> - Using the passive mode.");
|
||||
<%
|
||||
}
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient) globalMap.get("<%=conn %>");
|
||||
String rootDir_<%=cid %> = ftp_<%=cid %>.printWorkingDirectory();
|
||||
<%
|
||||
}
|
||||
%>
|
||||
int nb_file_<%=cid%> = 0;
|
||||
org.apache.commons.net.ftp.FTPFile[] ftpFiles_<%=cid %> = null;
|
||||
List<org.apache.commons.net.ftp.FTPFile> fileListTemp_<%=cid %> = new java.util.ArrayList<>();
|
||||
|
||||
<%/*read files*/ %>
|
||||
String remotedir_<%=cid %> = (<%=remotedir%>).replaceAll("\\\\","/");
|
||||
boolean cwdSuccess_<%=cid %> = ftp_<%=cid %>.changeWorkingDirectory(remotedir_<%=cid %>);
|
||||
|
||||
if (!cwdSuccess_<%=cid %>) {
|
||||
throw new RuntimeException("Failed to change remote directory. " + ftp_<%=cid %>.getReplyString());
|
||||
}
|
||||
|
||||
ftpFiles_<%=cid %> = ftp_<%=cid %>.listFiles();
|
||||
<%
|
||||
if ("true".equals(useExistingConn) && !moveToCurrentDir) {
|
||||
%>
|
||||
<%/*return to previous dir */%>
|
||||
ftp_<%=cid %>.changeWorkingDirectory(rootDir_<%=cid %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<%/*prepare masks*/ %>
|
||||
for (String filemask_<%=cid %> : maskList_<%=cid %>) {
|
||||
java.util.regex.Pattern fileNamePattern_<%=cid %> = java.util.regex.Pattern.compile(filemask_<%=cid %>.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*"));
|
||||
|
||||
for (org.apache.commons.net.ftp.FTPFile ftpFile_<%=cid %> : ftpFiles_<%=cid %>) {
|
||||
if (fileNamePattern_<%=cid %>.matcher(ftpFile_<%=cid %>.getName()).matches()) {
|
||||
fileListTemp_<%=cid %>.add(ftpFile_<%=cid %>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String currentFilePath_<%=cid%> = remotedir_<%=cid %>;
|
||||
if(!remotedir_<%=cid%>.endsWith("/")&&!remotedir_<%=cid%>.endsWith("\\")){
|
||||
currentFilePath_<%=cid%> += "/";
|
||||
}
|
||||
|
||||
for (int i = 0; i < fileListTemp_<%=cid %>.size(); i++) {
|
||||
org.apache.commons.net.ftp.FTPFile ftpFile_<%=cid %> = fileListTemp_<%=cid %>.get(i);
|
||||
String currentFileName_<%=cid%> = null;
|
||||
<%
|
||||
if (dirFull) {
|
||||
%>
|
||||
currentFileName_<%=cid%> = ftpFile_<%=cid %>.toString();
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
currentFileName_<%=cid%> = ftpFile_<%=cid %>.getName();
|
||||
<%
|
||||
}
|
||||
|
||||
if(isLog4jEnabled) {
|
||||
%>
|
||||
log.debug("<%=cid%> - List file : '" + currentFilePath_<%=cid%> + "' .");
|
||||
<%
|
||||
}
|
||||
}
|
||||
} //common code for ftp and ftps:
|
||||
%>
|
||||
<%/*set to globalMap*/ %>
|
||||
globalMap.put("<%=cid %>_CURRENT_FILE", currentFileName_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_CURRENT_FILEPATH", currentFilePath_<%=cid%> + ftpFile_<%=cid %>.getName());
|
||||
nb_file_<%=cid %>++;
|
||||
int nb_file_<%=cid%> = 0;
|
||||
org.apache.commons.net.ftp.FTPFile[] ftpFiles_<%=cid %> = null;
|
||||
String rootDir_<%=cid %> = ftp_<%=cid %>.printWorkingDirectory();
|
||||
List<org.apache.commons.net.ftp.FTPFile> fileListTemp_<%=cid %> = new java.util.ArrayList<>();
|
||||
|
||||
<%/*read files*/ %>
|
||||
String remotedir_<%=cid %> = (<%=remotedir%>).replaceAll("\\\\","/");
|
||||
boolean cwdSuccess_<%=cid %> = ftp_<%=cid %>.changeWorkingDirectory(remotedir_<%=cid %>);
|
||||
|
||||
if (!cwdSuccess_<%=cid %>) {
|
||||
throw new RuntimeException("Failed to change remote directory. " + ftp_<%=cid %>.getReplyString());
|
||||
}
|
||||
|
||||
ftpFiles_<%=cid %> = ftp_<%=cid %>.listFiles();
|
||||
<%
|
||||
} else { // *** ftp *** //
|
||||
if ("true".equals(useExistingConn) && !moveToCurrentDir) {
|
||||
%>
|
||||
int nb_file_<%=cid%> = 0;
|
||||
com.enterprisedt.net.ftp.FTPClient ftp_<%=cid %> =null;
|
||||
|
||||
<%if (("true").equals(useExistingConn)) {%>
|
||||
ftp_<%=cid %> = (com.enterprisedt.net.ftp.FTPClient)globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Use an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteHost() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%if(!moveToCurrentDir){%>
|
||||
String rootDir_<%=cid %> = ftp_<%=cid %>.pwd();
|
||||
<%}%>
|
||||
<%} else {%>
|
||||
ftp_<%=cid %> = new com.enterprisedt.net.ftp.FTPClient();
|
||||
ftp_<%=cid %>.setRemoteHost(<%=host %>);
|
||||
ftp_<%=cid %>.setRemotePort(<%=port %>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - " + <%=(("ACTIVE").equals(connectMode))?"\"Using the active mode.\"":"\"Using the passive mode.\""%>);
|
||||
<%}%>
|
||||
<%if (("ACTIVE").equals(connectMode)) {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.ACTIVE);
|
||||
<%} else {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.PASV);
|
||||
<%}%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" +<%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
ftp_<%=cid %>.connect();
|
||||
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%}%>
|
||||
String remotedir_<%=cid %> = (<%=remotedir%>).replaceAll("\\\\","/");
|
||||
ftp_<%=cid %>.chdir(remotedir_<%=cid %>);
|
||||
String[] fileList_<%=cid %> = ftp_<%=cid %>.dir(null, true);
|
||||
String[] fileListwithNames_<%=cid %> = ftp_<%=cid %>.dir(null, false);
|
||||
<%/*return to previous dir */%>
|
||||
ftp_<%=cid %>.changeWorkingDirectory(rootDir_<%=cid %>);
|
||||
<%
|
||||
if (("true").equals(useExistingConn)) {
|
||||
if(!moveToCurrentDir){
|
||||
}
|
||||
%>
|
||||
ftp_<%=cid %>.chdir(rootDir_<%=cid %>);
|
||||
<%
|
||||
}
|
||||
}
|
||||
<%/*prepare masks*/ %>
|
||||
for (String filemask_<%=cid %> : maskList_<%=cid %>) {
|
||||
java.util.regex.Pattern fileNamePattern_<%=cid %> = java.util.regex.Pattern.compile(filemask_<%=cid %>.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*"));
|
||||
|
||||
for (org.apache.commons.net.ftp.FTPFile ftpFile_<%=cid %> : ftpFiles_<%=cid %>) {
|
||||
if (fileNamePattern_<%=cid %>.matcher(ftpFile_<%=cid %>.getName()).matches()) {
|
||||
fileListTemp_<%=cid %>.add(ftpFile_<%=cid %>);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
String currentFilePath_<%=cid%> = remotedir_<%=cid %>;
|
||||
if(!remotedir_<%=cid%>.endsWith("/")&&!remotedir_<%=cid%>.endsWith("\\")){
|
||||
currentFilePath_<%=cid%> += "/";
|
||||
}
|
||||
|
||||
for (int i = 0; i < fileListTemp_<%=cid %>.size(); i++) {
|
||||
org.apache.commons.net.ftp.FTPFile ftpFile_<%=cid %> = fileListTemp_<%=cid %>.get(i);
|
||||
String currentFileName_<%=cid%> = null;
|
||||
<%
|
||||
if (dirFull) {
|
||||
%>
|
||||
List<String> fileListTemp_<%=cid %> = new java.util.ArrayList<String>();
|
||||
List<String> fileListTempWithNames_<%=cid %> = new java.util.ArrayList<String>();
|
||||
currentFileName_<%=cid%> = ftpFile_<%=cid %>.toString();
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
currentFileName_<%=cid%> = ftpFile_<%=cid %>.getName();
|
||||
<%
|
||||
}
|
||||
|
||||
for (String filemask_<%=cid %> : maskList_<%=cid %>) {
|
||||
java.util.regex.Pattern fileNamePattern_<%=cid %> = java.util.regex.Pattern.compile(filemask_<%=cid %>.replaceAll("\\.", "\\\\.").replaceAll("\\*", ".*"));
|
||||
for (int i_<%=cid%> = 0; i_<%=cid%> < fileList_<%=cid%>.length; i_<%=cid%>++){
|
||||
String filemaskTemp_<%=cid%> = fileList_<%=cid%>[i_<%=cid%>];
|
||||
String filemaskTempName_<%=cid%> = fileListwithNames_<%=cid%>[i_<%=cid%>];
|
||||
|
||||
if (fileNamePattern_<%=cid %>.matcher(filemaskTempName_<%=cid %>).matches()) {
|
||||
fileListTemp_<%=cid %>.add(filemaskTemp_<%=cid %>);
|
||||
fileListTempWithNames_<%=cid%>.add(fileListwithNames_<%=cid%>[i_<%=cid%>]);
|
||||
}
|
||||
}
|
||||
}
|
||||
int i_<%=cid %> = -1;
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Listing files from server.");
|
||||
<%}%>
|
||||
while (++i_<%=cid %> < fileListTemp_<%=cid %>.size()) {
|
||||
<% if (dirFull){%>
|
||||
String currentFileName_<%=cid%> = fileListTemp_<%=cid %>.get(i_<%=cid %>);
|
||||
<% } else {%>
|
||||
String currentFileName_<%=cid%> = fileListTempWithNames_<%=cid %>.get(i_<%=cid %>);
|
||||
<% }%>
|
||||
|
||||
String currentFilePath_<%=cid%> = remotedir_<%=cid %>;
|
||||
if(!remotedir_<%=cid%>.endsWith("/")&&!remotedir_<%=cid%>.endsWith("\\")){
|
||||
currentFilePath_<%=cid%> += "/";
|
||||
}
|
||||
currentFilePath_<%=cid%> += fileListTempWithNames_<%=cid%>.get(i_<%=cid%>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - List file : '" + currentFilePath_<%=cid%> + "' .");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_CURRENT_FILE", currentFileName_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_CURRENT_FILEPATH", currentFilePath_<%=cid%>);
|
||||
nb_file_<%=cid%>++;
|
||||
<%}%>
|
||||
if(isLog4jEnabled) {
|
||||
%>
|
||||
log.debug("<%=cid%> - List file : '" + currentFilePath_<%=cid%> + "' .");
|
||||
<%
|
||||
}
|
||||
%>
|
||||
<%/*set to globalMap*/ %>
|
||||
globalMap.put("<%=cid %>_CURRENT_FILE", currentFileName_<%=cid%>);
|
||||
globalMap.put("<%=cid %>_CURRENT_FILEPATH", currentFilePath_<%=cid%> + ftpFile_<%=cid %>.getName());
|
||||
nb_file_<%=cid %>++;
|
||||
<%
|
||||
} //end common code part
|
||||
%>
|
||||
@@ -65,14 +65,14 @@ if (sftp && !("true").equals(useExistingConn)) {// *** sftp *** //
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
} catch (java.net.SocketException se_<%=cid%>) {
|
||||
} catch (java.io.IOException ioe_<%=cid%>) {
|
||||
//ignore failure
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - " + se_<%=cid%>.getMessage());
|
||||
log.warn("<%=cid%> - " + ioe_<%=cid%>.getMessage());
|
||||
<%}%>
|
||||
}
|
||||
<%
|
||||
@@ -81,7 +81,7 @@ if (sftp && !("true").equals(useExistingConn)) {// *** sftp *** //
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
|
||||
@@ -155,7 +155,7 @@
|
||||
<DEFAULT>"."</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
<PARAMETER NAME="MOVE_TO_THE_CURRENT_DIRECTORY" FIELD="CHECK" NUM_ROW="41" SHOW_IF="USE_EXISTING_CONNECTION == 'true'">
|
||||
<PARAMETER NAME="MOVE_TO_THE_CURRENT_DIRECTORY" FIELD="CHECK" NUM_ROW="41" SHOW_IF="(USE_EXISTING_CONNECTION == 'true') AND (#LINK@NODE.CONNECTION.SFTP == 'false')">
|
||||
<DEFAULT>true</DEFAULT>
|
||||
</PARAMETER>
|
||||
|
||||
@@ -258,12 +258,12 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java-FTP" MODULE="edtftpj-2.5.0.jar" MVN="mvn:com.enterprisedt/edtftpj/2.5.0" REQUIRED_IF="(SFTP == 'false') AND (FTPS == 'false') AND (USE_EXISTING_CONNECTION == 'false')"/>
|
||||
<IMPORT NAME="Java-SFTP" MODULE="jsch-0.1.55.jar" MVN="mvn:com.jcraft/jsch/0.1.55" REQUIRED_IF="(SFTP == 'true') AND (USE_EXISTING_CONNECTION == 'false')"/>
|
||||
<IMPORT NAME="Java-FTPS" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(FTPS == 'true') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Java-FTPS-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190128.jar"
|
||||
MVN="mvn:org.talend.libraries/commons-net-ftps-proxy/3.6.1-talend-20190128" UrlPath="platform:/plugin/org.talend.designer.components.localprovider/components/tFTPConnection/commons-net-ftps-proxy-3.6.1-talend-20190128.jar"
|
||||
REQUIRED_IF="(FTPS == 'true') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Java-FTP+S" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(SFTP == 'false') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="FTP+S-Proxy-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190819.jar"
|
||||
MVN="mvn:org.talend.components.lib/commons-net-ftps-proxy/3.6.1-talend-20190819"
|
||||
REQUIRED_IF="(SFTP == 'false') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="talend-proxy" MODULE="talend-proxy-1.0.1.jar" MVN="mvn:org.talend.components.lib/talend-proxy/1.0.1" REQUIRED_IF="USE_EXISTING_CONNECTION == 'false'" />
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
<RETURNS>
|
||||
|
||||
@@ -62,6 +62,8 @@ if (("true").equals(useExistingConn)) {
|
||||
} else {
|
||||
sftp = ("true").equals(ElementParameterParser.getValue(node, "__SFTP__"));
|
||||
ftps = ("true").equals(ElementParameterParser.getValue(node, "__FTPS__"));
|
||||
%>
|
||||
<%
|
||||
}
|
||||
|
||||
boolean isLog4jEnabled = ("true").equals(ElementParameterParser.getValue(node.getProcess(), "__LOG4J_ACTIVATE__"));
|
||||
@@ -153,9 +155,9 @@ if (sftp) { // *** sftp *** //
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="../tFTPConnection/sftp_connect.javajet"%>
|
||||
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/sftp_connect.javajet"%>
|
||||
|
||||
<%if(use_encoding) {%>
|
||||
c_<%=cid%>.setFilenameEncoding(<%=encoding%>);
|
||||
<%}%>
|
||||
@@ -202,93 +204,52 @@ if (sftp) { // *** sftp *** //
|
||||
<%}%>
|
||||
}
|
||||
<%
|
||||
} else if (ftps) { // *** ftps *** //
|
||||
if (("false").equals(useExistingConn)) {
|
||||
String keystoreFile = ElementParameterParser.getValue(node, "__KEYSTORE_FILE__");
|
||||
String securityMode = ElementParameterParser.getValue(node, "__SECURITY_MODE__");
|
||||
} else {
|
||||
if (ftps) { // *** ftps *** //
|
||||
%>
|
||||
<%@ include file="../templates/FTP/ftpsTrust.javajet"%>
|
||||
javax.net.ssl.SSLContext sslContext_<%=cid %> = null;
|
||||
javax.net.ssl.TrustManager[] trustManager_<%=cid %> = null;
|
||||
javax.net.ssl.SSLSocketFactory sslSocketFactory_<%=cid %> = null;
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> =null;
|
||||
MyTrust_<%=cid %> myTrust_<%=cid%> = null;
|
||||
try {
|
||||
sslContext_<%=cid %> = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
myTrust_<%=cid%> = new MyTrust_<%=cid%>();
|
||||
trustManager_<%=cid %> = myTrust_<%=cid%>.getTrustManagers();
|
||||
sslContext_<%=cid %>.init(null, trustManager_<%=cid %>, new java.security.SecureRandom());
|
||||
sslSocketFactory_<%=cid %> = sslContext_<%=cid %>.getSocketFactory();
|
||||
boolean isHTTPProxyUsed = "true".equals(System.getProperty("http.proxySet"));
|
||||
if (isHTTPProxyUsed) {
|
||||
String httpProxyHost = System.getProperty("http.proxyHost");
|
||||
int httpProxyPort = Integer.getInteger("http.proxyPort");
|
||||
String httpProxyUser = System.getProperty("http.proxyUser");
|
||||
String httpProxyPass = System.getProperty("http.proxyPassword");
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = null;
|
||||
<%
|
||||
if (("false").equals(useExistingConn)) {
|
||||
String keystoreFile = ElementParameterParser.getValue(node, "__KEYSTORE_FILE__");
|
||||
String securityMode = ElementParameterParser.getValue(node, "__SECURITY_MODE__");
|
||||
%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftps_connect.javajet"%>
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient) globalMap.get("<%=conn %>");
|
||||
<%
|
||||
}
|
||||
} else { // *** ftp *** //
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPClient ftp_<%=cid %> = null;
|
||||
<%
|
||||
if (("true").equals(useExistingConn)) {
|
||||
%>
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPClient) globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Use an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteAddress().toString() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%
|
||||
} else {
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftp_connect.javajet"%>
|
||||
<%
|
||||
}
|
||||
|
||||
ftp_<%=cid %> = new org.talend.ftp.HTTPProxyFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>, httpProxyHost, httpProxyPort, httpProxyUser, httpProxyPass);
|
||||
} else {
|
||||
ftp_<%=cid %> = new org.talend.ftp.SSLSessionReuseFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>);
|
||||
}
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> -FTPS security Mode is <%=securityMode%>.");
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" + <%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect(<%=host %>,<%=ftpsPort %>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setRemoteVerificationEnabled(<%=useRemoteVerification %>);
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
if("binary".equalsIgnoreCase(mode)){
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isLoginSuccessful_<%=cid %> = ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
|
||||
if (!isLoginSuccessful_<%=cid %>) {
|
||||
throw new RuntimeException("Login failed");
|
||||
}
|
||||
|
||||
ftp_<%=cid %>.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE); //to calculate md5 for binary files correctly
|
||||
ftp_<%=cid %>.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
|
||||
<%
|
||||
if (protectionBufferSize != null && !protectionBufferSize.isEmpty() ) {
|
||||
} else {
|
||||
%>
|
||||
ftp_<%=cid %>.execPBSZ(<%=protectionBufferSize %>);
|
||||
ftp_<%=cid %>.setFileType(org.apache.commons.net.ftp.FTP.ASCII_FILE_TYPE);
|
||||
<%
|
||||
}
|
||||
|
||||
if (protectionLevel != null && !protectionLevel.isEmpty()) {
|
||||
%>
|
||||
ftp_<%=cid %>.execPROT(<%=protectionLevel %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
} catch (Exception e) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error("<%=cid%> - Can't create connection: " + e.getMessage());
|
||||
<%}%>
|
||||
throw e;
|
||||
}
|
||||
<%
|
||||
if ("PASSIVE".equals(connectMode)) {
|
||||
%>
|
||||
ftp_<%=cid %>.enterLocalPassiveMode();
|
||||
<%
|
||||
if (isLog4jEnabled) {
|
||||
%>
|
||||
log.debug("<%=cid%> - Using the passive mode.");
|
||||
<%
|
||||
}
|
||||
}
|
||||
} else {
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient) globalMap.get("<%=conn %>");
|
||||
<%
|
||||
}
|
||||
}
|
||||
} //common code for ftp and ftps:
|
||||
%>
|
||||
String remoteDir_<%=cid %> = (<%=remoteDir %>).replaceAll("\\\\", "/");
|
||||
org.apache.commons.net.ftp.FTPFile[] allFiles_<%=cid %> = ftp_<%=cid %>.listFiles(remoteDir_<%=cid %>);
|
||||
@@ -330,84 +291,5 @@ if (sftp) { // *** sftp *** //
|
||||
<%}%>
|
||||
}
|
||||
<%
|
||||
} else {// *** ftp *** //
|
||||
%>
|
||||
com.enterprisedt.net.ftp.FTPClient ftp_<%=cid %> =null;
|
||||
|
||||
<%if (("true").equals(useExistingConn)) {%>
|
||||
ftp_<%=cid %> = (com.enterprisedt.net.ftp.FTPClient)globalMap.get("<%=conn %>");
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Use an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteHost() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%} else {%>
|
||||
ftp_<%=cid %> = new com.enterprisedt.net.ftp.FTPClient();
|
||||
ftp_<%=cid %>.setRemoteHost(<%=host %>);
|
||||
ftp_<%=cid %>.setRemotePort(<%=port %>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - " + <%=(("ACTIVE").equals(connectMode))?"\"Using the active mode.\"":"\"Using the passive mode.\""%>);
|
||||
<%}%>
|
||||
<%if (("ACTIVE").equals(connectMode)) {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.ACTIVE);
|
||||
<%} else {%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.PASV);
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" +<%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect();
|
||||
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
ftp_<%=cid %>.login(<%=username %>, decryptedPassword_<%=cid%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%}%>
|
||||
<%
|
||||
//add feature 19709,add the "Transfer mode" option,
|
||||
//the default transfer mode is ASCII,we don't change the mode when ascii is choosed.
|
||||
if("binary".equalsIgnoreCase(mode)){
|
||||
%>
|
||||
ftp_<%=cid %>.setType(com.enterprisedt.net.ftp.FTPTransferType.BINARY);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
String remoteDir_<%=cid %> = <%=remoteDir %>.replaceAll("\\\\", "/");
|
||||
<%=outputConnName %> = new <%=outputConnName %>Struct();
|
||||
String remoteFile_<%=cid %> = <%=remoteDir %> + "/" + <%=filename%>;
|
||||
|
||||
if (ftp_<%=cid %>.exists(remoteFile_<%=cid %>)) {
|
||||
<%=outputConnName %>.abs_path = (remoteFile_<%=cid %>).replaceAll("//", "/");
|
||||
<%=outputConnName %>.dirname = <%=remoteDir %>;
|
||||
<%=outputConnName %>.basename = <%=filename%>;
|
||||
<%=outputConnName %>.size = ftp_<%=cid %>.size(remoteFile_<%=cid %>);
|
||||
<%=outputConnName %>.mtime = ftp_<%=cid %>.modtime(remoteFile_<%=cid %>).getTime();
|
||||
<%=outputConnName %>.mtime_string =ftp_<%=cid %>.modtime(remoteFile_<%=cid %>).toString();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log4jSb_<%=cid%>.append("<%=cid%> - File properties for remoteDir is : '" + <%=remoteDir %> + "',file name is : '" + <%=filename%> +"',file size is : '" + <%=outputConnName %>.size + "',file last modify time is : '" + <%=outputConnName %>.mtime_string + "'");
|
||||
<%}%>
|
||||
|
||||
<%if (MD5) {%>
|
||||
// Calculation of the Message Digest MD5
|
||||
java.security.MessageDigest dgs_<%=cid %> = java.security.MessageDigest.getInstance("MD5");
|
||||
dgs_<%=cid %>.update(ftp_<%=cid %>.get(remoteFile_<%=cid %>));
|
||||
<%=outputConnName %>.md5 =String.format("%032x", new java.math.BigInteger(1, dgs_<%=cid %>.digest()));
|
||||
<%if(isLog4jEnabled){%>
|
||||
log4jSb_<%=cid%>.append(",md5 message is : '"+ <%=outputConnName %>.md5 + "'.");
|
||||
<%}%>
|
||||
<%}%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug(log4jSb_<%=cid%>);
|
||||
<%}%>
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
|
||||
@@ -80,13 +80,13 @@ if (sftp && !bUseExistingConn) { // *** sftp *** //
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
} catch (java.net.SocketException se_<%=cid%>) {
|
||||
} catch (java.io.IOException ioe_<%=cid%>) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - " + se_<%=cid%>.getMessage());
|
||||
log.warn("<%=cid%> - " + ioe_<%=cid%>.getMessage());
|
||||
<%}%>
|
||||
//ignore failure
|
||||
}
|
||||
@@ -94,7 +94,7 @@ if (sftp && !bUseExistingConn) { // *** sftp *** //
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
|
||||
@@ -255,12 +255,12 @@
|
||||
|
||||
<CODEGENERATION>
|
||||
<IMPORTS>
|
||||
<IMPORT NAME="Java-FTP" MODULE="edtftpj-2.5.0.jar" MVN="mvn:com.enterprisedt/edtftpj/2.5.0" UrlPath="platform:/plugin/org.talend.libraries.ftp/lib/edtftpj-2.5.0.jar" REQUIRED_IF="(SFTP == 'false') AND (FTPS == 'false') AND (USE_EXISTING_CONNECTION == 'false')"/>
|
||||
<IMPORT NAME="Java-SFTP" MODULE="jsch-0.1.55.jar" MVN="mvn:com.jcraft/jsch/0.1.55" REQUIRED_IF="(SFTP == 'true') AND (USE_EXISTING_CONNECTION == 'false')"/>
|
||||
<IMPORT NAME="Java-FTPS" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(FTPS == 'true') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Java-FTPS-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190128.jar"
|
||||
MVN="mvn:org.talend.libraries/commons-net-ftps-proxy/3.6.1-talend-20190128" UrlPath="platform:/plugin/org.talend.designer.components.localprovider/components/tFTPConnection/commons-net-ftps-proxy-3.6.1-talend-20190128.jar"
|
||||
REQUIRED_IF="(FTPS == 'true') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="Java-FTP+S" MODULE="commons-net-3.6.jar" MVN="mvn:commons-net/commons-net/3.6" REQUIRED_IF="(SFTP == 'false') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="FTP+S-Proxy-talend" MODULE="commons-net-ftps-proxy-3.6.1-talend-20190819.jar"
|
||||
MVN="mvn:org.talend.components.lib/commons-net-ftps-proxy/3.6.1-talend-20190819"
|
||||
REQUIRED_IF="(SFTP == 'false') AND (USE_EXISTING_CONNECTION == 'false')" />
|
||||
<IMPORT NAME="talend-proxy" MODULE="talend-proxy-1.0.1.jar" MVN="mvn:org.talend.components.lib/talend-proxy/1.0.1" REQUIRED_IF="USE_EXISTING_CONNECTION == 'false'" />
|
||||
</IMPORTS>
|
||||
</CODEGENERATION>
|
||||
<RETURNS />
|
||||
|
||||
@@ -66,6 +66,8 @@ if ("true".equals(useExistingConn)) {
|
||||
} else {
|
||||
sftp = ("true").equals(ElementParameterParser.getValue(node, "__SFTP__"));
|
||||
ftps = ("true").equals(ElementParameterParser.getValue(node, "__FTPS__"));
|
||||
%>
|
||||
<%
|
||||
}
|
||||
%>
|
||||
int nb_file_<%=cid%> = 0;
|
||||
@@ -286,7 +288,7 @@ if (sftp) { // *** sftp *** //
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="../tFTPConnection/sftp_connect.javajet"%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/sftp_connect.javajet"%>
|
||||
|
||||
<%if(use_encoding) {%>
|
||||
c_<%=cid%>.setFilenameEncoding(<%=encoding%>);
|
||||
@@ -303,477 +305,247 @@ if (sftp) { // *** sftp *** //
|
||||
c_<%=cid%>.cd(remotedir_<%=cid %>);
|
||||
}
|
||||
<%
|
||||
} else if (!ftps) { // *** ftp *** //
|
||||
%>
|
||||
final com.enterprisedt.net.ftp.TransferCompleteStrings msg_<%=cid%> = new com.enterprisedt.net.ftp.TransferCompleteStrings();
|
||||
} else {
|
||||
%>
|
||||
abstract class FTPGetter_<%=cid%> {
|
||||
protected org.apache.commons.net.ftp.FTPClient ftpClient = null;
|
||||
protected int count = 0;
|
||||
|
||||
class FTPGetter_<%=cid%> {
|
||||
private com.enterprisedt.net.ftp.FTPClient ftpClient = null;
|
||||
private int count = 0;
|
||||
public void getAllFiles(String remoteDirectory, String localDirectory)
|
||||
throws IllegalStateException, IOException, java.io.FileNotFoundException {
|
||||
|
||||
public void getAllFiles(String remoteDirectory, String localDirectory) throws java.io.IOException,
|
||||
com.enterprisedt.net.ftp.FTPException, java.text.ParseException {
|
||||
chdir(remoteDirectory);
|
||||
String path = ftpClient.printWorkingDirectory();
|
||||
org.apache.commons.net.ftp.FTPFile[] ftpFiles = null;
|
||||
ftpFiles = ftpClient.listFiles();
|
||||
|
||||
chdir(remoteDirectory);
|
||||
String path = ftpClient.pwd();
|
||||
String[] ftpFileNames = null;
|
||||
com.enterprisedt.net.ftp.FTPFile[] ftpFiles = null;
|
||||
for (org.apache.commons.net.ftp.FTPFile ftpFile : ftpFiles) {
|
||||
|
||||
try{
|
||||
//use dir() for Bug9562 with FTP server in AS400
|
||||
ftpFileNames = ftpClient.dir(null, false);
|
||||
//Bug 13272, the same as getFiles().
|
||||
} catch (com.enterprisedt.net.ftp.FTPException e){
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - " + e.getMessage());
|
||||
<%}%>
|
||||
ftpFileNames = null;
|
||||
ftpFiles = ftpClient.dirDetails(".");
|
||||
}
|
||||
if (ftpFile.isDirectory()) {
|
||||
|
||||
//if dirDetails(...) doesn't work, then use dir(...), distinguish file type by FTPException
|
||||
if ((!(".").equals(ftpFile.getName())) && (!("..").equals(ftpFile.getName()))) {
|
||||
java.io.File localFile = new java.io.File(localDirectory + "/" + ftpFile.getName());
|
||||
|
||||
if ((ftpFiles == null) && (ftpFileNames != null)){
|
||||
//if the file is folder, catch the FTPException and recur
|
||||
for (String ftpFileName : ftpFileNames){
|
||||
try {
|
||||
downloadFile(localDirectory + "/" + ftpFileName,ftpFileName);
|
||||
} catch (com.enterprisedt.net.ftp.FTPException e) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - " + e.getMessage());
|
||||
<%}%>
|
||||
java.io.File localFile = new java.io.File(localDirectory + "/" + ftpFileName);
|
||||
if (!localFile.exists()) {
|
||||
localFile.mkdir();
|
||||
}
|
||||
getAllFiles(path + "/" + ftpFile.getName(), localDirectory + "/" + ftpFile.getName());
|
||||
chdir(path);
|
||||
}
|
||||
} else if (!ftpFile.isSymbolicLink()) {
|
||||
downloadFile(localDirectory + "/" + ftpFile.getName(),ftpFile.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!localFile.exists()) {
|
||||
localFile.mkdir();
|
||||
}
|
||||
getAllFiles(path + "/" + ftpFileName, localDirectory + "/" + ftpFileName);
|
||||
chdir(path);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
for (com.enterprisedt.net.ftp.FTPFile ftpFile : ftpFiles) {
|
||||
public void getFiles(String remoteDirectory, String localDirectory, String maskStr)
|
||||
throws IllegalStateException, IOException, java.io.FileNotFoundException {
|
||||
|
||||
if (ftpFile.isDir()) {
|
||||
if ((!(".").equals(ftpFile.getName())) && (!("..").equals(ftpFile.getName()))) {
|
||||
java.io.File localFile = new java.io.File(localDirectory + "/" + ftpFile.getName());
|
||||
chdir(remoteDirectory);
|
||||
org.apache.commons.net.ftp.FTPFile[] ftpFiles = null;
|
||||
ftpFiles = ftpClient.listFiles(".");
|
||||
|
||||
if (!localFile.exists()) {
|
||||
localFile.mkdir();
|
||||
}
|
||||
getAllFiles(path + "/" + ftpFile.getName(), localDirectory + "/" + ftpFile.getName());
|
||||
chdir(path);
|
||||
}
|
||||
} else if (!ftpFile.isLink()) {
|
||||
downloadFile(localDirectory + "/" + ftpFile.getName(),ftpFile.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for(org.apache.commons.net.ftp.FTPFile ftpFile : ftpFiles) {
|
||||
|
||||
public void getFiles(String remoteDirectory, String localDirectory, String maskStr) throws java.io.IOException,
|
||||
com.enterprisedt.net.ftp.FTPException, java.text.ParseException {
|
||||
chdir(remoteDirectory);
|
||||
String[] ftpFileNames = null;
|
||||
com.enterprisedt.net.ftp.FTPFile[] ftpFiles = null;
|
||||
if (ftpFile.isFile()) {
|
||||
String fileName = ftpFile.getName();
|
||||
|
||||
try {
|
||||
//use dir() for Bug9562 with FTP server in AS400 (the same way as getAllFiles())
|
||||
ftpFileNames = ftpClient.dir(null, false);
|
||||
//Bug 13272, if dir() throw exception, use dirDetails().
|
||||
} catch (com.enterprisedt.net.ftp.FTPException e){
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.warn("<%=cid%> - " + e.getMessage());
|
||||
if (fileName.matches(maskStr)) {
|
||||
downloadFile(localDirectory + "/" + fileName,fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void chdir(String path) throws IllegalStateException, IOException {
|
||||
if (!".".equals(path)) {
|
||||
ftpClient.changeWorkingDirectory(path);
|
||||
}
|
||||
}
|
||||
|
||||
public String pwd() throws IllegalStateException, IOException {
|
||||
return ftpClient.printWorkingDirectory();
|
||||
}
|
||||
|
||||
protected abstract void downloadFile(String localFileName, String remoteFileName)
|
||||
throws IllegalStateException, java.io.FileNotFoundException, IOException;
|
||||
}
|
||||
<%
|
||||
if (!ftps) { // *** ftp *** //
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPClient ftp_<%=cid %> = null;
|
||||
<%
|
||||
if (("true").equals(useExistingConn)) {
|
||||
String conn= "conn_" + connection;
|
||||
%>
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPClient) globalMap.get("<%=conn %>");
|
||||
<%if(!moveToCurrentDir){%>
|
||||
String rootDir_<%=cid %> = ftp_<%=cid %>.printWorkingDirectory();
|
||||
<%}%>
|
||||
ftpFileNames = null;
|
||||
ftpFiles = ftpClient.dirDetails(".");
|
||||
}
|
||||
//if dirDetails(...) doesn't work, then use dir(...), but can not distinguish file type
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Use an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteAddress().toString() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%
|
||||
} else {
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftp_connect.javajet"%>
|
||||
<%
|
||||
}
|
||||
|
||||
if ((ftpFiles == null) && (ftpFileNames != null)){
|
||||
for (String ftpFileName : ftpFileNames) {
|
||||
if (ftpFileName.matches(maskStr)) {
|
||||
downloadFile(localDirectory + "/" + ftpFileName,ftpFileName);
|
||||
}
|
||||
}
|
||||
} else{
|
||||
|
||||
for (com.enterprisedt.net.ftp.FTPFile ftpFile : ftpFiles) {
|
||||
|
||||
if (!ftpFile.isDir() && !ftpFile.isLink()) {
|
||||
String fileName = ftpFile.getName();
|
||||
|
||||
if (fileName.matches(maskStr)) {
|
||||
downloadFile(localDirectory + "/" + fileName,fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void chdir(String path) throws java.io.IOException, com.enterprisedt.net.ftp.FTPException{
|
||||
if (!".".equals(path)) {
|
||||
ftpClient.chdir(path);
|
||||
}
|
||||
}
|
||||
|
||||
public String pwd() throws java.io.IOException, com.enterprisedt.net.ftp.FTPException{
|
||||
return ftpClient.pwd();
|
||||
}
|
||||
|
||||
private void downloadFile(String localFileName, String remoteFileName) throws java.io.IOException, com.enterprisedt.net.ftp.FTPException {
|
||||
java.io.File localFile = new java.io.File(localFileName);
|
||||
|
||||
try {
|
||||
<%if (append) {%>
|
||||
java.io.FileOutputStream fout = new java.io.FileOutputStream(localFile, true);
|
||||
ftpClient.get(fout, remoteFileName);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Downloaded file " + (count +1) + " : '" + remoteFileName + "' successfully.");
|
||||
<%}%>
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%if (bPrintMsg) {%>
|
||||
System.out.println("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File transfer OK.");
|
||||
<%
|
||||
} else if ("never".equals(overwrite)){
|
||||
%>
|
||||
if (!localFile.exists()) {
|
||||
ftpClient.get(localFileName, remoteFileName);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Downloaded file " + (count +1) + " : '" + remoteFileName + "' successfully.");
|
||||
<%}%>
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%if (bPrintMsg) {%>
|
||||
System.out.println("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File transfer OK.");
|
||||
} else {
|
||||
if("binary".equalsIgnoreCase(ElementParameterParser.getValue(node, "__MODE__"))){
|
||||
%>
|
||||
ftp_<%=cid %>.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
ftp_<%=cid %>.setFileType(org.apache.commons.net.ftp.FTP.ASCII_FILE_TYPE);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
final java.util.List<String> msg_<%=cid%> = new java.util.ArrayList<String>();
|
||||
FTPGetter_<%=cid%> getter_<%=cid%> = new FTPGetter_<%=cid%>() {
|
||||
@Override
|
||||
protected void downloadFile(String localFileName, String remoteFileName)
|
||||
throws IllegalStateException, java.io.FileNotFoundException, IOException {
|
||||
java.io.File localFile = new java.io.File(localFileName);
|
||||
<%
|
||||
if (append) {
|
||||
%>
|
||||
try (java.io.FileOutputStream localFos = new java.io.FileOutputStream(localFileName, true)) {
|
||||
ftpClient.retrieveFile(remoteFileName, localFos);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%= cid %> - file ["+ remoteFileName +"] exit transmission.");
|
||||
log.debug("<%=cid%> - Downloaded file " + (count +1) + " : '" + remoteFileName + "' successfully.");
|
||||
<%}%>
|
||||
msg_<%=cid%>.add("file ["+ remoteFileName +"] exit transmission.");
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "No file transfered.");
|
||||
}
|
||||
<%
|
||||
} else if ("always".equals(overwrite)){
|
||||
%>
|
||||
ftpClient.get(localFileName, remoteFileName);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Downloaded file " + (count +1) + " : '" + remoteFileName + "' successfully.");
|
||||
<%}%>
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%if (bPrintMsg) {%>
|
||||
System.out.println("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%}%>
|
||||
<%
|
||||
} else if ("size_differ".equals(overwrite)) {
|
||||
%>
|
||||
if (localFile.exists()) {
|
||||
long ftpSize = ftpClient.size(remoteFileName);
|
||||
long localSize = localFile.length();
|
||||
|
||||
if (ftpSize != localSize) {
|
||||
ftpClient.get(localFileName, remoteFileName);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Downloaded file " + (count +1) + " : '" + remoteFileName + "' successfully.");
|
||||
<%}%>
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%if (bPrintMsg) {%>
|
||||
System.out.println("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File transfer OK.");
|
||||
} else {
|
||||
<%if(isLog4jEnabled){%>
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%if (bPrintMsg) {%>
|
||||
System.out.println("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File transfer OK.");
|
||||
count++;
|
||||
} catch (IOException e) {
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded unsuccessfully.");
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File transfer fail.");
|
||||
throw e;
|
||||
}
|
||||
<%
|
||||
} else if ("never".equals(overwrite)) {
|
||||
%>
|
||||
if (!localFile.exists()) {
|
||||
downloadFileWithOverwrite(localFileName, remoteFileName);
|
||||
} else {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%= cid %> - file ["+ remoteFileName +"] exit transmission.");
|
||||
<%}%>
|
||||
msg_<%=cid%>.add("file ["+ remoteFileName +"] exit transmission.");
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "No file transfered.");
|
||||
}
|
||||
<%
|
||||
} else if ("always".equals(overwrite)){
|
||||
%>
|
||||
downloadFileWithOverwrite(localFileName, remoteFileName);
|
||||
<%
|
||||
} else if ("size_differ".equals(overwrite)) {
|
||||
%>
|
||||
if (localFile.exists()) {
|
||||
long ftpSize = java.util.Arrays.stream(ftpClient.listFiles(remoteFileName)).findFirst().get().getSize();
|
||||
long localSize = localFile.length();
|
||||
if (ftpSize != localSize) {
|
||||
downloadFileWithOverwrite(localFileName, remoteFileName);
|
||||
} else {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%= cid %> - file ["+ remoteFileName +"] exit transmission.");
|
||||
<%}%>
|
||||
msg_<%=cid%>.add("file ["+ remoteFileName +"] exit transmission.");
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "No file transfered.");
|
||||
}
|
||||
} else {
|
||||
ftpClient.get(localFileName, remoteFileName);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Downloaded file " + (count +1) + " : '" + remoteFileName + "' successfully.");
|
||||
<%}%>
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%if (bPrintMsg) {%>
|
||||
System.out.println("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File transfer OK.");
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
} catch (com.enterprisedt.net.ftp.FTPException e) {
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded unsuccessfully.");
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File transfer fail.");
|
||||
throw e;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
msg_<%=cid%>.add("file ["+ remoteFileName +"] exit transmission.");
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "No file transfered.");
|
||||
}
|
||||
} else {
|
||||
downloadFileWithOverwrite(localFileName, remoteFileName);
|
||||
}
|
||||
<%
|
||||
}
|
||||
%>
|
||||
}
|
||||
|
||||
private void downloadFileWithOverwrite(String localFileName, String remoteFileName)
|
||||
throws IllegalStateException, java.io.FileNotFoundException, IOException {
|
||||
try (java.io.FileOutputStream localFos = new java.io.FileOutputStream(localFileName)) {
|
||||
ftpClient.retrieveFile(remoteFileName, localFos);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Downloaded file " + (count +1) + " : '" + remoteFileName + "' successfully.");
|
||||
<%}%>
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%if (bPrintMsg) {%>
|
||||
System.out.println("file [" + remoteFileName + "] downloaded successfully.");
|
||||
<%}%>
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File transfer OK.");
|
||||
count++;
|
||||
} catch (IOException e) {
|
||||
msg_<%=cid%>.add("file [" + remoteFileName + "] downloaded unsuccessfully.");
|
||||
globalMap.put("<%=cid %>_CURRENT_STATUS", "File transfer fail.");
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
};
|
||||
getter_<%=cid%>.ftpClient = ftp_<%=cid %>;
|
||||
<%
|
||||
} else { // *** ftps *** //
|
||||
%>
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> =null;
|
||||
<%
|
||||
if ("false".equals(useExistingConn)){
|
||||
%>
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/FTP/ftps_connect.javajet"%>
|
||||
<%
|
||||
} else {
|
||||
String conn= "conn_" + connection;
|
||||
%>
|
||||
<% /* get connection from globalMap*/ %>
|
||||
String rootDir_<%=cid %> = null;
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient)globalMap.get("<%=conn %>");
|
||||
<%
|
||||
if (!moveToCurrentDir) {
|
||||
%>
|
||||
rootDir_<%=cid %> = ftp_<%=cid %>.printWorkingDirectory();
|
||||
<%
|
||||
}
|
||||
|
||||
if(isLog4jEnabled) {
|
||||
%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Use an existing connection.Connection hostname: " + ftp_<%=cid %>.getRemoteAddress().toString() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
FTPGetter_<%=cid%> getter_<%=cid%> = new FTPGetter_<%=cid%>() {
|
||||
@Override
|
||||
protected void downloadFile(String localFileName, String remoteFileName)
|
||||
throws IllegalStateException, java.io.FileNotFoundException, IOException {
|
||||
try (java.io.FileOutputStream localFos = new java.io.FileOutputStream(localFileName)) {
|
||||
ftpClient.retrieveFile(remoteFileName, localFos);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Downloaded file " + (count +1) + " : '" + remoteFileName + "' successfully.");
|
||||
<%}%>
|
||||
count++;
|
||||
}
|
||||
}
|
||||
};
|
||||
getter_<%=cid%>.ftpClient = ftp_<%=cid %>;
|
||||
<%
|
||||
} //common code for ftp and ftps:
|
||||
%>
|
||||
String remotedir_<%=cid%> = <%=remotedir%>;
|
||||
if (!".".equals(remotedir_<%=cid %>)) {
|
||||
boolean cwdSuccess_<%=cid %> = ftp_<%=cid %>.changeWorkingDirectory(remotedir_<%=cid %>);
|
||||
|
||||
if (!cwdSuccess_<%=cid %>) {
|
||||
throw new RuntimeException("Failed to change remote directory. " + ftp_<%=cid %>.getReplyString());
|
||||
}
|
||||
}
|
||||
com.enterprisedt.net.ftp.FTPClient ftp_<%=cid %> = null;
|
||||
|
||||
<%
|
||||
if ("true".equals(useExistingConn)){
|
||||
String conn= "conn_" + connection;
|
||||
%>
|
||||
ftp_<%=cid %> = (com.enterprisedt.net.ftp.FTPClient)globalMap.get("<%=conn %>");
|
||||
<%if(!moveToCurrentDir){%>
|
||||
String rootDir_<%=cid %> = ftp_<%=cid %>.pwd();
|
||||
<%}%>
|
||||
<%if(isLog4jEnabled){%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Uses an existing connection. Connection hostname: " + ftp_<%=cid %>.getRemoteHost() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%}%>
|
||||
<%} else {%>
|
||||
ftp_<%=cid %> = new com.enterprisedt.net.ftp.FTPClient();
|
||||
ftp_<%=cid %>.setRemoteHost(<%=host %>);
|
||||
ftp_<%=cid %>.setRemotePort(<%=port %>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - " + <%=(("ACTIVE").equals(connectMode))?"\"Using the active mode.\"":"\"Using the passive mode.\""%>);
|
||||
<%}
|
||||
if (("ACTIVE").equals(connectMode)){
|
||||
%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.ACTIVE);
|
||||
<%
|
||||
}else{
|
||||
%>
|
||||
ftp_<%=cid %>.setConnectMode(com.enterprisedt.net.ftp.FTPConnectMode.PASV);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" +<%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect();
|
||||
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
<%} %>
|
||||
msg_<%=cid%>.clearAll();
|
||||
FTPGetter_<%=cid%> getter_<%=cid%> = new FTPGetter_<%=cid%>();
|
||||
getter_<%=cid%>.ftpClient = ftp_<%=cid %>;
|
||||
String remotedir_<%=cid %> = <%=remotedir%>;
|
||||
if (!".".equals(remotedir_<%=cid %>)) {
|
||||
ftp_<%=cid %>.chdir(remotedir_<%=cid %>);
|
||||
}
|
||||
<%
|
||||
} else { // *** ftps *** //
|
||||
%>
|
||||
class FTPSGetter_<%=cid%> {
|
||||
private org.apache.commons.net.ftp.FTPClient ftpClient = null;
|
||||
private int count = 0;
|
||||
|
||||
public void getAllFiles(String remoteDirectory, String localDirectory)
|
||||
throws IllegalStateException, IOException, java.io.FileNotFoundException {
|
||||
|
||||
chdir(remoteDirectory);
|
||||
String path = ftpClient.printWorkingDirectory();
|
||||
org.apache.commons.net.ftp.FTPFile[] ftpFiles = null;
|
||||
ftpFiles = ftpClient.listFiles();
|
||||
|
||||
for (org.apache.commons.net.ftp.FTPFile ftpFile : ftpFiles) {
|
||||
|
||||
if (ftpFile.isDirectory()) {
|
||||
|
||||
if ((!(".").equals(ftpFile.getName())) && (!("..").equals(ftpFile.getName()))) {
|
||||
java.io.File localFile = new java.io.File(localDirectory + "/" + ftpFile.getName());
|
||||
|
||||
if (!localFile.exists()) {
|
||||
localFile.mkdir();
|
||||
}
|
||||
getAllFiles(path + "/" + ftpFile.getName(), localDirectory + "/" + ftpFile.getName());
|
||||
chdir(path);
|
||||
}
|
||||
} else if (!ftpFile.isSymbolicLink()) {
|
||||
downloadFile(localDirectory + "/" + ftpFile.getName(),ftpFile.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void getFiles(String remoteDirectory, String localDirectory, String maskStr)
|
||||
throws IllegalStateException, IOException, java.io.FileNotFoundException {
|
||||
|
||||
chdir(remoteDirectory);
|
||||
org.apache.commons.net.ftp.FTPFile[] ftpFiles = null;
|
||||
ftpFiles = ftpClient.listFiles(".");
|
||||
|
||||
for(org.apache.commons.net.ftp.FTPFile ftpFile : ftpFiles) {
|
||||
|
||||
if (ftpFile.isFile()) {
|
||||
String fileName = ftpFile.getName();
|
||||
|
||||
if (fileName.matches(maskStr)) {
|
||||
downloadFile(localDirectory + "/" + fileName,fileName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void chdir(String path)
|
||||
throws IllegalStateException, IOException {
|
||||
if (!".".equals(path)) {
|
||||
ftpClient.changeWorkingDirectory(path);
|
||||
}
|
||||
}
|
||||
|
||||
public String pwd()
|
||||
throws IllegalStateException, IOException {
|
||||
return ftpClient.printWorkingDirectory();
|
||||
}
|
||||
|
||||
private void downloadFile(String localFileName, String remoteFileName)
|
||||
throws IllegalStateException, java.io.FileNotFoundException, IOException {
|
||||
try (java.io.FileOutputStream localFos = new java.io.FileOutputStream(localFileName)) {
|
||||
ftpClient.retrieveFile(remoteFileName, localFos);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.debug("<%=cid%> - Downloaded file " + (count +1) + " : '" + remoteFileName + "' successfully.");
|
||||
<%}%>
|
||||
count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
org.apache.commons.net.ftp.FTPSClient ftp_<%=cid %> =null;
|
||||
<%
|
||||
if ("false".equals(useExistingConn)){
|
||||
%>
|
||||
<% /* create connection */ %>
|
||||
<%@ include file="../templates/FTP/ftpsTrust.javajet"%>
|
||||
|
||||
javax.net.ssl.SSLContext sslContext_<%=cid%> = null;
|
||||
javax.net.ssl.TrustManager[] trustManager_<%=cid%> = null;
|
||||
javax.net.ssl.SSLSocketFactory sslSocketFactory_<%=cid%> = null;
|
||||
|
||||
MyTrust_<%=cid %> myTrust_<%=cid%> = null;
|
||||
|
||||
try {
|
||||
sslContext_<%=cid %> = javax.net.ssl.SSLContext.getInstance("SSL");
|
||||
myTrust_<%=cid%> = new MyTrust_<%=cid%>();
|
||||
trustManager_<%=cid %> = myTrust_<%=cid%>.getTrustManagers();
|
||||
sslContext_<%=cid %>.init(null, trustManager_<%=cid %>, new java.security.SecureRandom());
|
||||
sslSocketFactory_<%=cid %> = sslContext_<%=cid%>.getSocketFactory();
|
||||
boolean isHTTPProxyUsed = "true".equals(System.getProperty("http.proxySet"));
|
||||
if (isHTTPProxyUsed) {
|
||||
String httpProxyHost = System.getProperty("http.proxyHost");
|
||||
int httpProxyPort = Integer.getInteger("http.proxyPort");
|
||||
String httpProxyUser = System.getProperty("http.proxyUser");
|
||||
String httpProxyPass = System.getProperty("http.proxyPassword");
|
||||
|
||||
ftp_<%=cid %> = new org.talend.ftp.HTTPProxyFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>, httpProxyHost, httpProxyPort, httpProxyUser, httpProxyPass);
|
||||
} else {
|
||||
ftp_<%=cid %> = new org.talend.ftp.SSLSessionReuseFTPSClient(<%="IMPLICIT".equals(securityMode)%>, sslContext_<%=cid %>);
|
||||
}
|
||||
ftp_<%=cid %>.setControlEncoding(<%=encoding%>);
|
||||
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> -FTPS security Mode is <%=securityMode%>.");
|
||||
log.info("<%=cid%> - Attempt to connect to '" + <%=host %> + "' with username '" + <%=user %>+ "'.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.connect(<%=host %>,<%=ftpsPort %>);
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connect to '" + <%=host %> + "' has succeeded.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.setRemoteVerificationEnabled(<%=useRemoteVerification %>);
|
||||
<%
|
||||
passwordFieldName = "__PASSWORD__";
|
||||
%>
|
||||
|
||||
<%@ include file="@{org.talend.designer.components.localprovider}/components/templates/password.javajet"%>
|
||||
|
||||
boolean isLoginSuccessful_<%=cid %> = ftp_<%=cid %>.login(<%=user %>, decryptedPassword_<%=cid%>);
|
||||
|
||||
if (!isLoginSuccessful_<%=cid %>) {
|
||||
throw new RuntimeException("Login failed");
|
||||
}
|
||||
|
||||
ftp_<%=cid %>.setFileType(org.apache.commons.net.ftp.FTP.BINARY_FILE_TYPE);
|
||||
<%
|
||||
if (protectionBufferSize != null && !protectionBufferSize.isEmpty() ) {
|
||||
%>
|
||||
ftp_<%=cid %>.execPBSZ(<%=protectionBufferSize %>);
|
||||
<%
|
||||
}
|
||||
|
||||
if (protectionLevel != null && !protectionLevel.isEmpty()) {
|
||||
%>
|
||||
ftp_<%=cid %>.execPROT(<%=protectionLevel %>);
|
||||
<%
|
||||
}
|
||||
%>
|
||||
} catch (Exception e) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error("<%=cid%> - Can't create connection: " + e.getMessage());
|
||||
<%}%>
|
||||
<%
|
||||
if (dieOnError) {
|
||||
%>
|
||||
throw e;
|
||||
<%
|
||||
} else {
|
||||
%>
|
||||
e.printStackTrace();
|
||||
<%
|
||||
}
|
||||
%>
|
||||
}
|
||||
<%
|
||||
if ("PASSIVE".equals(connectMode)) {
|
||||
%>
|
||||
ftp_<%=cid %>.enterLocalPassiveMode();
|
||||
<%
|
||||
if (isLog4jEnabled) {
|
||||
%>
|
||||
log.debug("<%=cid%> - Using the passive mode.");
|
||||
<%
|
||||
}
|
||||
}
|
||||
} else {
|
||||
String conn= "conn_" + connection;
|
||||
%>
|
||||
<% /* get connection from globalMap*/ %>
|
||||
String rootDir_<%=cid %> = null;
|
||||
ftp_<%=cid %> = (org.apache.commons.net.ftp.FTPSClient)globalMap.get("<%=conn %>");
|
||||
<%
|
||||
if (!moveToCurrentDir) {
|
||||
%>
|
||||
rootDir_<%=cid %> = ftp_<%=cid %>.printWorkingDirectory();
|
||||
<%
|
||||
}
|
||||
if(isLog4jEnabled) {
|
||||
%>
|
||||
if(ftp_<%=cid %>!=null) {
|
||||
log.info("<%=cid%> - Use an existing connection.Connection hostname: " + ftp_<%=cid %>.getRemoteAddress().toString() + ", Connection port: " + ftp_<%=cid %>.getRemotePort() + ".");
|
||||
}
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
FTPSGetter_<%=cid%> getter_<%=cid%> = null;
|
||||
String remotedir_<%=cid%> = null;
|
||||
|
||||
getter_<%=cid%> = new FTPSGetter_<%=cid%>();
|
||||
getter_<%=cid%>.ftpClient = ftp_<%=cid %>;
|
||||
remotedir_<%=cid%> = <%=remotedir%>;
|
||||
if (!".".equals(remotedir_<%=cid %>)) {
|
||||
boolean cwdSuccess_<%=cid %> = ftp_<%=cid %>.changeWorkingDirectory(remotedir_<%=cid %>);
|
||||
|
||||
if (!cwdSuccess_<%=cid %>) {
|
||||
throw new RuntimeException("Failed to change remote directory. " + ftp_<%=cid %>.getReplyString());
|
||||
}
|
||||
}
|
||||
<%
|
||||
}
|
||||
// *** share code *** //
|
||||
@@ -783,22 +555,10 @@ java.util.List<String> maskList_<%=cid %> = new java.util.ArrayList<String>();
|
||||
<%
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
Map<String, String> line = files.get(i);
|
||||
%>
|
||||
maskList_<%=cid %>.add(<%= line.get("FILEMASK") %>);
|
||||
%>
|
||||
maskList_<%=cid %>.add(<%= line.get("FILEMASK") %>);
|
||||
<%
|
||||
}
|
||||
|
||||
if (!sftp && !ftps) { // *** ftp *** //
|
||||
if ("binary".equalsIgnoreCase(ElementParameterParser.getValue(node, "__MODE__"))) {
|
||||
%>
|
||||
ftp_<%=cid %>.setType(com.enterprisedt.net.ftp.FTPTransferType.BINARY);
|
||||
<%
|
||||
}else {
|
||||
%>
|
||||
ftp_<%=cid %>.setType(com.enterprisedt.net.ftp.FTPTransferType.ASCII);
|
||||
<%
|
||||
}
|
||||
}
|
||||
%>
|
||||
String localdir_<%=cid %> = <%=localdir%>;
|
||||
//create folder if local direcotry (assigned by property) not exists
|
||||
|
||||
@@ -54,8 +54,8 @@ nb_file_<%=cid%> = getter_<%=cid %>.count;
|
||||
<%}%>
|
||||
<%}%>
|
||||
<%} else if (!ftps) {%>
|
||||
msg_<%=cid%>.add(ftp_<%=cid%>.getDownloadCount() + " files have been downloaded.");
|
||||
String[] msgAll_<%=cid %> = msg_<%=cid%>.getAll();
|
||||
msg_<%=cid%>.add(getter_<%=cid%>.count + " files have been downloaded.");
|
||||
String[] msgAll_<%=cid %> = msg_<%=cid%>.toArray(new String[0]);
|
||||
StringBuffer sb_<%=cid %> = new StringBuffer();
|
||||
|
||||
if (msgAll_<%=cid %> != null) {
|
||||
@@ -74,13 +74,13 @@ nb_file_<%=cid%> = getter_<%=cid %>.count;
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
} catch(java.net.SocketException se_<%=cid%>) {
|
||||
} catch(java.io.IOException ioe_<%=cid%>) {
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.error("<%=cid%> - " + se_<%=cid%>.getMessage());
|
||||
log.error("<%=cid%> - " + ioe_<%=cid%>.getMessage());
|
||||
<%}%>
|
||||
//ignore failure
|
||||
}
|
||||
@@ -90,7 +90,7 @@ nb_file_<%=cid%> = getter_<%=cid %>.count;
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Closing the connection to the server.");
|
||||
<%}%>
|
||||
ftp_<%=cid %>.quit();
|
||||
ftp_<%=cid %>.disconnect();
|
||||
<%if(isLog4jEnabled){%>
|
||||
log.info("<%=cid%> - Connection to the server closed.");
|
||||
<%}%>
|
||||
@@ -99,7 +99,7 @@ nb_file_<%=cid%> = getter_<%=cid %>.count;
|
||||
}else{
|
||||
if(!moveToCurrentDir){
|
||||
%>
|
||||
ftp_<%=cid %>.chdir(rootDir_<%=cid %>);
|
||||
ftp_<%=cid %>.changeWorkingDirectory(rootDir_<%=cid %>);
|
||||
<%
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user