diff --git a/README.md b/README.md index 9bca03bc5..40de7c2c9 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,11 @@ dependencies { ## Release notes +### 3.33.1 + ++ Added ability to read dictionary by alias as file ++ 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/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java b/src/main/java/com/exactpro/th2/common/schema/factory/AbstractCommonFactory.java index b311b4a41..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 @@ -529,12 +529,21 @@ public T getCustomConfiguration(Class confClass) { */ public abstract InputStream loadSingleDictionary(); + /** + * @param alias name of dictionary + * @return Dictionary as {@link Path} + * @throws IllegalStateException if can not read dictionary + */ + public abstract Path getDictionaryPath(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..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,7 +546,7 @@ public Set getDictionaryAliases() { } @Override - public InputStream loadDictionary(String alias) { + public Path getDictionaryPath(String alias) { Path dictionaryFolder = getPathToDictionaryAliasesDir(); try { LOGGER.debug("Loading dictionary by alias ({}) from folder: {}", alias, dictionaryFolder); @@ -567,12 +567,22 @@ 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); } } + @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); 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) {