-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a636dc6
commit 750dc98
Showing
12 changed files
with
162 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
cdc-core/src/main/java/vn/dataplatform/core/common/JsonPathUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,61 @@ | ||
package vn.dataplatform.core.common; | ||
|
||
import com.google.gson.Gson; | ||
import com.google.gson.GsonBuilder; | ||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonElement; | ||
import com.jayway.jsonpath.Configuration; | ||
import com.jayway.jsonpath.DocumentContext; | ||
import com.jayway.jsonpath.JsonPath; | ||
import com.jayway.jsonpath.Option; | ||
import com.jayway.jsonpath.spi.json.GsonJsonProvider; | ||
import java.util.Collections; | ||
import java.util.HashSet; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.StreamSupport; | ||
|
||
/** | ||
* @author tuan.nguyen3 | ||
*/ | ||
public class JsonPathUtils { | ||
public static Gson gson = new GsonBuilder().disableHtmlEscaping().serializeNulls().create(); | ||
|
||
public static GsonJsonProvider gsonJsonProvider = new GsonJsonProvider(gson); | ||
|
||
public static final Configuration jConf = | ||
Configuration.builder().jsonProvider(gsonJsonProvider).options(Option.DEFAULT_PATH_LEAF_TO_NULL, Option.SUPPRESS_EXCEPTIONS).build(); | ||
|
||
public static final Configuration jPathConf = Configuration.builder().jsonProvider(gsonJsonProvider) | ||
.options(Option.DEFAULT_PATH_LEAF_TO_NULL, Option.SUPPRESS_EXCEPTIONS, Option.AS_PATH_LIST, Option.ALWAYS_RETURN_LIST).build(); | ||
|
||
public static Map<String, String> pathToValueMap(String json, List<String> paths) { | ||
if (json == null || json.trim().isEmpty() || paths.isEmpty()) { | ||
return Collections.emptyMap(); | ||
} | ||
|
||
DocumentContext jVals = JsonPath.using(jConf).parse(json); | ||
DocumentContext jPaths = JsonPath.using(jPathConf).parse(json); | ||
|
||
return new HashSet<>(paths).stream() // Make sure that keys are unique | ||
.flatMap(p -> StreamSupport.stream(jPaths.read(p, JsonArray.class).spliterator(), false).map(JsonElement::getAsString)) | ||
.collect(Collectors.toMap(p -> p, p -> { | ||
JsonElement e = jVals.read(p, JsonElement.class); | ||
if (e.isJsonArray()) { | ||
return gson.toJson(e.getAsJsonArray()); | ||
} | ||
return e.isJsonNull() ? "" : e.getAsString(); | ||
})).entrySet().stream().filter(kv -> !kv.getValue().trim().isEmpty()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); | ||
} | ||
|
||
public static <T> String setJsonValues(String json, Map<String, T> updatedPaths) { | ||
if (json == null || updatedPaths == null || json.trim().isEmpty() || updatedPaths.isEmpty()) { | ||
return json; | ||
} | ||
|
||
DocumentContext doc = JsonPath.using(jConf).parse(json); | ||
updatedPaths.forEach((path, newVal) -> doc.map(path, (val, conf) -> newVal)); | ||
return doc.jsonString(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
cdc-core/src/main/java/vn/dataplatform/core/common/StringUtils.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,55 @@ | ||
package vn.dataplatform.core.common; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* @author tuan.nguyen3 | ||
*/ | ||
public class StringUtils { | ||
public static final String EMPTY = ""; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY = new String[0]; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL = new String[]{null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY = new String[]{EMPTY}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY_AND_NULL = new String[]{EMPTY, null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL_AND_EMPTY = new String[]{null, EMPTY}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL_AND_NULL = new String[]{null, null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY_AND_EMPTY = new String[]{EMPTY, EMPTY}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY_AND_NULL_AND_EMPTY = new String[]{EMPTY, null, EMPTY}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL_AND_EMPTY_AND_NULL = new String[]{null, EMPTY, null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL_AND_NULL_AND_NULL = new String[]{null, null, null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY_AND_EMPTY_AND_EMPTY = new String[]{EMPTY, EMPTY, EMPTY}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY_AND_NULL_AND_NULL = new String[]{EMPTY, null, null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL_AND_EMPTY_AND_EMPTY = new String[]{null, EMPTY, EMPTY}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL_AND_NULL_AND_EMPTY = new String[]{null, null, EMPTY}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY_AND_EMPTY_AND_NULL = new String[]{EMPTY, EMPTY, null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY_AND_NULL_AND_EMPTY_AND_NULL = new String[]{EMPTY, null, EMPTY, null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL_AND_EMPTY_AND_NULL_AND_EMPTY = new String[]{null, EMPTY, null, EMPTY}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL_AND_NULL_AND_NULL_AND_NULL = new String[]{null, null, null, null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY_AND_EMPTY_AND_EMPTY_AND_EMPTY = new String[]{EMPTY, EMPTY, EMPTY, EMPTY}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_EMPTY_AND_NULL_AND_NULL_AND_NULL = new String[]{EMPTY, null, null, null}; | ||
|
||
public static final String[] EMPTY_STRING_ARRAY_WITH_NULL_AND_EMPTY_AND_NULL_AND_NULL = new String[]{null, EMPTY, null, null}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1 change: 0 additions & 1 deletion
1
cdc-debezium-sinks/src/main/resources/application.example.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters