generated from kestra-io/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 1
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
9ed5930
commit 5a5e1d2
Showing
3 changed files
with
44 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package io.kestra.storage.s3; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.regex.Pattern; | ||
|
||
public class MetadataUtils { | ||
private static final Pattern METADATA_KEY_WORD_SEPARATOR = Pattern.compile("_([a-z])"); | ||
private static final Pattern UPPERCASE = Pattern.compile("([A-Z])"); | ||
|
||
public static Map<String, String> toStoredMetadata(Map<String, String> metadata) { | ||
if (metadata == null) { | ||
return null; | ||
} | ||
return metadata.entrySet().stream() | ||
.map(entry -> Map.entry(UPPERCASE.matcher(entry.getKey()).replaceAll("_$1").toLowerCase(), entry.getValue())) | ||
.collect(HashMap::new, (m, v) -> m.put(v.getKey(), v.getValue()), HashMap::putAll); | ||
} | ||
|
||
public static Map<String, String> toRetrievedMetadata(Map<String, String> metadata) { | ||
if (metadata == null) { | ||
return null; | ||
} | ||
return metadata.entrySet().stream() | ||
.map(entry -> Map.entry( | ||
METADATA_KEY_WORD_SEPARATOR.matcher(entry.getKey()) | ||
.replaceAll(matchResult -> matchResult.group(1).toUpperCase()), | ||
entry.getValue() | ||
)).collect(HashMap::new, (m, v) -> m.put(v.getKey(), v.getValue()), HashMap::putAll); | ||
} | ||
} |
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