From c295e19a26e24a06b4dba8681774c6d72e3880c2 Mon Sep 17 00:00:00 2001 From: "nikita.smirnov" Date: Sun, 6 Feb 2022 12:05:20 +0300 Subject: [PATCH 1/4] Corrected logging for configuration files --- README.md | 6 +++++- gradle.properties | 2 +- .../th2/common/schema/configuration/ConfigurationManager.kt | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 9bca03bc5..51bf5cbce 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# th2 common library (Java) (3.33.0) +# th2 common library (Java) (3.33.1) ## Usage @@ -288,6 +288,10 @@ dependencies { ## Release notes +### 3.33.1 + ++ Corrected logging for configuration files + ### 3.33.0 + Added ability to read dictionaries by aliases and as group of all available aliases diff --git a/gradle.properties b/gradle.properties index 3d838c7a2..e7543c545 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ # limitations under the License. # -release_version=3.33.0 +release_version=3.33.1 description = 'th2 common library (Java)' diff --git a/src/main/kotlin/com/exactpro/th2/common/schema/configuration/ConfigurationManager.kt b/src/main/kotlin/com/exactpro/th2/common/schema/configuration/ConfigurationManager.kt index 94becb407..cebcad3db 100644 --- a/src/main/kotlin/com/exactpro/th2/common/schema/configuration/ConfigurationManager.kt +++ b/src/main/kotlin/com/exactpro/th2/common/schema/configuration/ConfigurationManager.kt @@ -40,7 +40,7 @@ class ConfigurationManager(private val configurationPath: Map, Path>) { } val sourceContent = String(Files.readAllBytes(configPath)) - LOGGER.info("Configuration path {} source content {}", configPath, sourceContent) + LOGGER.info { "Configuration path $configClass source content $sourceContent" } val content: String = stringSubstitutor.replace(sourceContent) return objectMapper.readerFor(configClass).readValue(content) } catch (e: IOException) { From cf19cd42acaeeb371cfd1838501da5af8eba2f52 Mon Sep 17 00:00:00 2001 From: Nikita Shaposhnikov Date: Thu, 10 Feb 2022 22:42:09 +0300 Subject: [PATCH 2/4] Load dictionary as file --- .../schema/factory/AbstractCommonFactory.java | 9 +++++++++ .../th2/common/schema/factory/CommonFactory.java | 16 +++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java index b311b4a41..26291a3cf 100644 --- a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java +++ b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java @@ -529,12 +529,21 @@ public T getCustomConfiguration(Class confClass) { */ public abstract InputStream loadSingleDictionary(); + /** + * @param alias name of dictionary + * @return Dictionary as {@link File} + * @throws IllegalStateException if can not read dictionary + */ + public abstract File loadDictionaryFile(String alias); + + /** * @return list of available dictionary aliases or an empty list * @throws IllegalStateException if can not read dictionary */ public abstract Set getDictionaryAliases(); + /** * @param alias name of dictionary * @return Dictionary as {@link InputStream} diff --git a/src/main/java/com/exactpro/th2/common/schema/factory/CommonFactory.java b/src/main/java/com/exactpro/th2/common/schema/factory/CommonFactory.java index 2f01a9275..0aae46bb0 100644 --- a/src/main/java/com/exactpro/th2/common/schema/factory/CommonFactory.java +++ b/src/main/java/com/exactpro/th2/common/schema/factory/CommonFactory.java @@ -545,8 +545,22 @@ public Set getDictionaryAliases() { } } + @Override + public File loadDictionaryFile(String alias) { + return getDictionaryPath(alias).toFile(); + } + @Override public InputStream loadDictionary(String alias) { + Path dictionaryPath = getDictionaryPath(alias); + try { + return new ByteArrayInputStream(getGzipBase64StringDecoder().decode(Files.readString(dictionaryPath))); + } catch (IOException e) { + throw new IllegalStateException("Can not read dictionary '" + alias + "' from path: " + dictionaryPath, e); + } + } + + private Path getDictionaryPath(String alias) { Path dictionaryFolder = getPathToDictionaryAliasesDir(); try { LOGGER.debug("Loading dictionary by alias ({}) from folder: {}", alias, dictionaryFolder); @@ -567,7 +581,7 @@ public InputStream loadDictionary(String alias) { throw new IllegalStateException("Found several dictionaries by alias '" + alias + "' at path: " + dictionaryFolder.toAbsolutePath()); } - return new ByteArrayInputStream(getGzipBase64StringDecoder().decode(Files.readString(dictionaries.get(0)))); + return dictionaries.get(0); } catch (IOException e) { throw new IllegalStateException("Can not read dictionary '" + alias + "' from path: " + dictionaryFolder.toAbsolutePath(), e); } From becd5b6a115108e0406997caade10632195306d2 Mon Sep 17 00:00:00 2001 From: Nikita Shaposhnikov Date: Thu, 10 Feb 2022 22:44:15 +0300 Subject: [PATCH 3/4] readme update --- README.md | 6 +++++- gradle.properties | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 9bca03bc5..12d4e15e8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# th2 common library (Java) (3.33.0) +# th2 common library (Java) (3.33.1) ## Usage @@ -288,6 +288,10 @@ dependencies { ## Release notes +### 3.33.1 + ++ Added ability to read dictionary by alias as file + ### 3.33.0 + Added ability to read dictionaries by aliases and as group of all available aliases diff --git a/gradle.properties b/gradle.properties index 3d838c7a2..e7543c545 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,7 +13,7 @@ # limitations under the License. # -release_version=3.33.0 +release_version=3.33.1 description = 'th2 common library (Java)' From 22355e64fcfca0e25737258062302c86d96174fa Mon Sep 17 00:00:00 2001 From: Nikita Shaposhnikov Date: Thu, 10 Mar 2022 11:56:53 +0400 Subject: [PATCH 4/4] Switched from file to path --- .../schema/factory/AbstractCommonFactory.java | 4 +-- .../common/schema/factory/CommonFactory.java | 26 ++++++++----------- 2 files changed, 13 insertions(+), 17 deletions(-) diff --git a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java index 26291a3cf..11e7f4d81 100644 --- a/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java +++ b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java @@ -531,10 +531,10 @@ public T getCustomConfiguration(Class confClass) { /** * @param alias name of dictionary - * @return Dictionary as {@link File} + * @return Dictionary as {@link Path} * @throws IllegalStateException if can not read dictionary */ - public abstract File loadDictionaryFile(String alias); + public abstract Path getDictionaryPath(String alias); /** diff --git a/src/main/java/com/exactpro/th2/common/schema/factory/CommonFactory.java b/src/main/java/com/exactpro/th2/common/schema/factory/CommonFactory.java index 0aae46bb0..5b473afb7 100644 --- a/src/main/java/com/exactpro/th2/common/schema/factory/CommonFactory.java +++ b/src/main/java/com/exactpro/th2/common/schema/factory/CommonFactory.java @@ -546,21 +546,7 @@ public Set getDictionaryAliases() { } @Override - public File loadDictionaryFile(String alias) { - return getDictionaryPath(alias).toFile(); - } - - @Override - public InputStream loadDictionary(String alias) { - Path dictionaryPath = getDictionaryPath(alias); - try { - return new ByteArrayInputStream(getGzipBase64StringDecoder().decode(Files.readString(dictionaryPath))); - } catch (IOException e) { - throw new IllegalStateException("Can not read dictionary '" + alias + "' from path: " + dictionaryPath, e); - } - } - - private Path getDictionaryPath(String alias) { + public Path getDictionaryPath(String alias) { Path dictionaryFolder = getPathToDictionaryAliasesDir(); try { LOGGER.debug("Loading dictionary by alias ({}) from folder: {}", alias, dictionaryFolder); @@ -587,6 +573,16 @@ private Path getDictionaryPath(String alias) { } } + @Override + public InputStream loadDictionary(String alias) { + Path dictionaryPath = getDictionaryPath(alias); + try { + return new ByteArrayInputStream(getGzipBase64StringDecoder().decode(Files.readString(dictionaryPath))); + } catch (IOException e) { + throw new IllegalStateException("Can not read dictionary '" + alias + "' from path: " + dictionaryPath, e); + } + } + @Override public InputStream readDictionary() { return readDictionary(DictionaryType.MAIN);