Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 37 additions & 44 deletions core/src/main/java/org/apache/hop/core/row/ValueDataUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.zip.Adler32;
import java.util.zip.CRC32;
import java.util.zip.CheckedInputStream;
import lombok.experimental.UtilityClass;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.EncoderException;
import org.apache.commons.codec.language.DoubleMetaphone;
Expand All @@ -52,6 +53,7 @@
import org.apache.hop.core.vfs.HopVfs;
import org.apache.hop.core.xml.XmlCheck;

@UtilityClass
public class ValueDataUtil {

private static final Log log = LogFactory.getLog(ValueDataUtil.class);
Expand Down Expand Up @@ -124,7 +126,8 @@ private static int readRound2Mode() {
private static void throwsErrorOnFileNotFound(FileObject file)
throws HopFileNotFoundException, FileSystemException {
if (file == null || !file.exists()) {
throw new HopFileNotFoundException("File not found", file.getName().getPath());
throw new HopFileNotFoundException(
"File not found", file != null ? file.getName().getPath() : "null");
}
}

Expand All @@ -133,8 +136,7 @@ private static void throwsErrorOnFileNotFound(FileObject file)
* refer to as the source string (s) and the target string (t). The distance is the number of
* deletions, insertions, or substitutions required to transform s into t.
*/
public static Long getLevenshtein_Distance(
IValueMeta metaA, Object dataA, IValueMeta metaB, Object dataB) {
public static Long getLevenshteinDistance(Object dataA, Object dataB) {
if (dataA == null || dataB == null) {
return null;
}
Expand All @@ -146,8 +148,7 @@ public static Long getLevenshtein_Distance(
* refer to as the source string (s) and the target string (t). The distance is the number of
* deletions, insertions, or substitutions required to transform s into t.
*/
public static Long getDamerauLevenshtein_Distance(
IValueMeta metaA, Object dataA, IValueMeta metaB, Object dataB) {
public static Long getDamerauLevenshteinDistance(Object dataA, Object dataB) {
if (dataA == null || dataB == null) {
return null;
}
Expand All @@ -158,8 +159,7 @@ public static Long getDamerauLevenshtein_Distance(
* Jaro similitude is a measure of the similarity between two strings, which we will refer to as
* the source string (s) and the target string (t).
*/
public static Double getJaro_Similitude(
IValueMeta metaA, Object dataA, IValueMeta metaB, Object dataB) {
public static Double getJaroSimilitude(Object dataA, Object dataB) {
if (dataA == null || dataB == null) {
return null;
}
Expand All @@ -172,8 +172,7 @@ public static Double getJaro_Similitude(
* JaroWinkler similitude is a measure of the similarity between two strings, which we will refer
* to as the source string (s) and the target string (t).
*/
public static Double getJaroWinkler_Similitude(
IValueMeta metaA, Object dataA, IValueMeta metaB, Object dataB) {
public static Double getJaroWinklerSimilitude(Object dataA, Object dataB) {
if (dataA == null || dataB == null) {
return null;
}
Expand All @@ -182,156 +181,154 @@ public static Double getJaroWinkler_Similitude(
return pjwd.getJaroWinklerDistance();
}

public static String get_Metaphone(IValueMeta metaA, Object dataA) {
public static String getMetaphone(Object dataA) {
if (dataA == null) {
return null;
}
return (new Metaphone()).metaphone(dataA.toString());
}

public static String get_Double_Metaphone(IValueMeta metaA, Object dataA) {
public static String getDoubleMetaphone(Object dataA) {
if (dataA == null) {
return null;
}
return (new DoubleMetaphone()).doubleMetaphone(dataA.toString());
}

public static String get_SoundEx(IValueMeta metaA, Object dataA) {
public static String getSoundEx(Object dataA) {
if (dataA == null) {
return null;
}
return (new Soundex()).encode(dataA.toString());
}

public static String get_RefinedSoundEx(IValueMeta metaA, Object dataA) {
public static String getRefinedSoundEx(Object dataA) {
if (dataA == null) {
return null;
}
return (new RefinedSoundex()).encode(dataA.toString());
}

public static String initCap(IValueMeta metaA, Object dataA) {
public static String initCap(Object dataA) {
if (dataA == null) {
return null;
}
return WordUtils.capitalizeFully(dataA.toString(), new char[] {' ', '_', ',', ':', ';', '-'});
}

public static String upperCase(IValueMeta metaA, Object dataA) {
public static String upperCase(Object dataA) {
if (dataA == null) {
return null;
}
return dataA.toString().toUpperCase();
}

public static String lowerCase(IValueMeta metaA, Object dataA) {
public static String lowerCase(Object dataA) {
if (dataA == null) {
return null;
}
return dataA.toString().toLowerCase();
}

public static String escapeXml(IValueMeta metaA, Object dataA) {
public static String escapeXml(Object dataA) {
if (dataA == null) {
return null;
}
return Const.escapeXml(dataA.toString());
}

public static String unEscapeXml(IValueMeta metaA, Object dataA) {
public static String unEscapeXml(Object dataA) {
if (dataA == null) {
return null;
}
return Const.unEscapeXml(dataA.toString());
}

public static String escapeHtml(IValueMeta metaA, Object dataA) {
public static String escapeHtml(Object dataA) {
if (dataA == null) {
return null;
}
return Const.escapeHtml(dataA.toString());
}

public static String unEscapeHtml(IValueMeta metaA, Object dataA) {
public static String unEscapeHtml(Object dataA) {
if (dataA == null) {
return null;
}
return Const.unEscapeHtml(dataA.toString());
}

public static String escapeSql(IValueMeta metaA, Object dataA) {
public static String escapeSql(Object dataA) {
if (dataA == null) {
return null;
}
return Const.escapeSql(dataA.toString());
}

public static String useCDATA(IValueMeta metaA, Object dataA) {
public static String useCDATA(Object dataA) {
if (dataA == null) {
return null;
}
return "<![CDATA[" + dataA + "]]>";
}

public static String removeCR(IValueMeta metaA, Object dataA) {
public static String removeCR(Object dataA) {
if (dataA == null) {
return null;
}
return Const.removeCR(dataA.toString());
}

public static String removeLF(IValueMeta metaA, Object dataA) {
public static String removeLF(Object dataA) {
if (dataA == null) {
return null;
}
return Const.removeLF(dataA.toString());
}

public static String removeCRLF(IValueMeta metaA, Object dataA) {
public static String removeCRLF(Object dataA) {
if (dataA == null) {
return null;
}
return Const.removeCRLF(dataA.toString());
}

public static String removeTAB(IValueMeta metaA, Object dataA) {
public static String removeTAB(Object dataA) {
if (dataA == null) {
return null;
}
return Const.removeTAB(dataA.toString());
}

public static String getDigits(IValueMeta metaA, Object dataA) {
public static String getDigits(Object dataA) {
if (dataA == null) {
return null;
}
return Const.getDigitsOnly(dataA.toString());
}

public static String removeDigits(IValueMeta metaA, Object dataA) {
public static String removeDigits(Object dataA) {
if (dataA == null) {
return null;
}
return Const.removeDigits(dataA.toString());
}

public static long stringLen(IValueMeta metaA, Object dataA) {
public static long stringLen(Object dataA) {
if (dataA == null) {
return 0;
}
return dataA.toString().length();
}

/**
* @param metaA The IValueMeta
* @param dataA Filename
* @param type Algorithm to be used when computing the checksum (MD5 or SHA-1)
* @param failIfNoFile Indicates if the pipeline should fail if no file is found
* @return File's checksum
* @throws HopFileNotFoundException
*/
public static String createChecksum(
IValueMeta metaA, Object dataA, String type, boolean failIfNoFile)
public static String createChecksum(Object dataA, String type, boolean failIfNoFile)
throws HopFileNotFoundException {
if (dataA == null) {
return null;
Expand Down Expand Up @@ -372,13 +369,12 @@ public static String createChecksum(
}

/**
* @param metaA The IValueMeta
* @param dataA Filename
* @param failIfNoFile Indicates if the pipeline should fail if no file is found
* @return File's CRC32 checksum
* @throws HopFileNotFoundException
*/
public static Long checksumCRC32(IValueMeta metaA, Object dataA, boolean failIfNoFile)
public static Long checksumCRC32(Object dataA, boolean failIfNoFile)
throws HopFileNotFoundException {
long checksum = 0;

Expand Down Expand Up @@ -417,13 +413,12 @@ public static Long checksumCRC32(IValueMeta metaA, Object dataA, boolean failIfN
}

/**
* @param metaA The IValueMeta
* @param dataA Filename
* @param failIfNoFile Indicates if the pipeline should fail if no file is found
* @return File's Adler32 checksum
* @throws HopFileNotFoundException
*/
public static Long checksumAdler32(IValueMeta metaA, Object dataA, boolean failIfNoFile)
public static Long checksumAdler32(Object dataA, boolean failIfNoFile)
throws HopFileNotFoundException {
long checksum = 0;

Expand Down Expand Up @@ -570,14 +565,13 @@ public static Object sum(IValueMeta metaA, Object dataA, IValueMeta metaB, Objec
}

/**
* @param metaA The IValueMeta
* @param dataA Filename
* @param failIfNoFile Indicates if the pipeline should fail if no file is found
* @return File's content in binary
* @throws HopValueException
* @throws HopFileNotFoundException
*/
public static byte[] loadFileContentInBinary(IValueMeta metaA, Object dataA, boolean failIfNoFile)
public static byte[] loadFileContentInBinary(Object dataA, boolean failIfNoFile)
throws HopValueException, HopFileNotFoundException {
if (dataA == null) {
return null;
Expand Down Expand Up @@ -1303,7 +1297,7 @@ public static Object addMonths(IValueMeta metaA, Object dataA, IValueMeta metaB,
* @return Number of days
* @throws HopValueException
*/
public static Object DateDiff(
public static Object dateDiff(
IValueMeta metaA, Object dataA, IValueMeta metaB, Object dataB, String resultType)
throws HopValueException {

Expand Down Expand Up @@ -1344,7 +1338,7 @@ public static Object DateDiff(
}
}

public static Object DateWorkingDiff(
public static Object dateWorkingDiff(
IValueMeta metaA, Object dataA, IValueMeta metaB, Object dataB) throws HopValueException {
if (dataA != null && dataB != null) {
Date fromDate = metaB.getDate(dataB);
Expand Down Expand Up @@ -1819,13 +1813,12 @@ public static boolean onlySpaces(String str) {
/**
* Checks an xml file is well formed.
*
* @param metaA The IValueMeta
* @param dataA The value (filename)
* @param failIfNoFile Indicates if the pipeline should fail if no file is found
* @return true if the file is well formed.
* @throws HopFileNotFoundException
*/
public static boolean isXmlFileWellFormed(IValueMeta metaA, Object dataA, boolean failIfNoFile)
public static boolean isXmlFileWellFormed(Object dataA, boolean failIfNoFile)
throws HopFileNotFoundException {
if (dataA == null) {
return false;
Expand Down Expand Up @@ -1928,7 +1921,7 @@ public static Object getZeroForValueMetaType(IValueMeta type) throws HopValueExc
};
}

public static String urlEncode(IValueMeta metaA, Object dataA) {
public static String urlEncode(Object dataA) {
if (dataA == null) {
return null;
}
Expand All @@ -1939,7 +1932,7 @@ public static String urlEncode(IValueMeta metaA, Object dataA) {
}
}

public static String urlDecode(IValueMeta metaA, Object dataA) {
public static String urlDecode(Object dataA) {
if (dataA == null) {
return null;
}
Expand Down
Loading