Skip to content

Commit f3d1e06

Browse files
committed
Add constants
1 parent 54a87d6 commit f3d1e06

File tree

4 files changed

+33
-7
lines changed

4 files changed

+33
-7
lines changed

component/src/main/java/io/siddhi/extension/util/Constant.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,7 @@ public class Constant {
2727
public static final String CREATE_FOLDER = "create-folder";
2828
public static final String LAST_MODIFIED_DATETIME_FORMAT = "MM/dd/yyyy HH:mm:ss";
2929
public static final String CREATE = "create";
30+
public static final String SFTP_SCHEME_FILE_OPTION = "sftp";
31+
public static final String VFS_SCHEME_KEY = "VFS_SCHEME";
32+
public static final String FTP_SCHEME_FILE_OPTION = "ftp";
3033
}

component/src/main/java/io/siddhi/extension/util/Utils.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
import java.util.Map;
3636
import java.util.Properties;
3737

38+
import static io.siddhi.extension.util.Constant.FTP_SCHEME_FILE_OPTION;
39+
import static io.siddhi.extension.util.Constant.SFTP_SCHEME_FILE_OPTION;
40+
import static io.siddhi.extension.util.Constant.VFS_SCHEME_KEY;
41+
3842
/**
3943
* Util Class.
4044
*/
@@ -58,7 +62,7 @@ public static FileObject getFileObject(String filePathUri) {
5862
} catch (FileSystemException e) {
5963
throw new SiddhiAppRuntimeException("Exception occurred when getting VFS manager", e);
6064
}
61-
if (sourceOptions != null && "ftp".equals(sourceOptions.get("VFS_SCHEME"))) {
65+
if (sourceOptions != null && FTP_SCHEME_FILE_OPTION.equals(sourceOptions.get(VFS_SCHEME_KEY))) {
6266
FtpFileSystemConfigBuilder.getInstance().setPassiveMode(sourceFso, true);
6367
}
6468
try {
@@ -101,18 +105,18 @@ private static Map<String, String> parseSchemeFileOptions(String fileURI, Proper
101105
return null;
102106
} else {
103107
HashMap<String, String> schemeFileOptions = new HashMap();
104-
schemeFileOptions.put("VFS_SCHEME", scheme);
108+
schemeFileOptions.put(VFS_SCHEME_KEY, scheme);
105109
addOptions(scheme, schemeFileOptions, properties);
106110
return schemeFileOptions;
107111
}
108112
}
109113

110114
private static void addOptions(String scheme, Map<String, String> schemeFileOptions, Properties properties) {
111-
if (scheme.equals("sftp")) {
115+
if (scheme.equals(SFTP_SCHEME_FILE_OPTION)) {
112116
Constants.SftpFileOption[] sftpFileOptions = Constants.SftpFileOption.values();
113117
for (Constants.SftpFileOption option : sftpFileOptions) {
114-
String strValue = (String) properties.get("sftp" + option.toString());
115-
if (strValue != null && !strValue.equals("")) {
118+
String strValue = (String) properties.get(SFTP_SCHEME_FILE_OPTION + option.toString());
119+
if (strValue != null && !strValue.isEmpty()) {
116120
schemeFileOptions.put(option.toString(), strValue);
117121
}
118122
}

component/src/test/java/io/siddhi/extension/io/file/FileFunctionsTestCase.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,21 @@
1+
/*
2+
* Copyright (c) 2019, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
3+
*
4+
* WSO2 Inc. licenses this file to you under the Apache License,
5+
* Version 2.0 (the "License"); you may not use this file except
6+
* in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing,
12+
* software distributed under the License is distributed on an
13+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
* KIND, either express or implied. See the License for the
15+
* specific language governing permissions and limitations
16+
* under the License.
17+
*/
18+
119
package io.siddhi.extension.io.file;
220

321
import io.siddhi.core.SiddhiAppRuntime;
@@ -1113,7 +1131,7 @@ private boolean isFileExist(String filePathUri, boolean isDirectory) {
11131131
return fileObj.isFolder();
11141132
}
11151133
} catch (FileSystemException e) {
1116-
throw new SiddhiAppRuntimeException("Exception occurred when checking type of file in path: " +
1134+
throw new SiddhiAppRuntimeException("Exception occurred when checking existence for path: " +
11171135
filePathUri, e);
11181136
}
11191137
}

pom.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@
125125
<dependency>
126126
<groupId>org.apache.commons</groupId>
127127
<artifactId>commons-compress</artifactId>
128-
<version>1.14</version>
128+
<version>${org.apache.commons-compress.version}</version>
129129
</dependency>
130130
<dependency>
131131
<groupId>io.siddhi.extension.execution.list</groupId>
@@ -140,6 +140,7 @@
140140
<siddhi.version>5.1.5</siddhi.version>
141141
<siddhi.version.range>[5.0.0,6.0.0)</siddhi.version.range>
142142
<wso2.transport.file.version>6.0.60</wso2.transport.file.version>
143+
<org.apache.commons-compress.version>1.14</org.apache.commons-compress.version>
143144
<testng.version>6.8</testng.version>
144145
<siddhi.map.json.version>5.0.2</siddhi.map.json.version>
145146
<siddhi.map.xml.version>5.0.2</siddhi.map.xml.version>

0 commit comments

Comments
 (0)