From af2240e41679beb7e85a73b0894050de0044e427 Mon Sep 17 00:00:00 2001 From: "Woerner Dominic (RBCH/PJ-IOT)" Date: Wed, 23 Jun 2021 23:43:42 +0200 Subject: [PATCH] Init tags from config Signed-off-by: Woerner Dominic (RBCH/PJ-IOT) --- .../org/hyperledger/bpa/config/TagConfig.java | 15 +++++--------- .../org/hyperledger/bpa/impl/TagService.java | 20 ++++++++++--------- .../src/main/resources/schemas.yml | 3 +++ 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/config/TagConfig.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/config/TagConfig.java index 0ad53cdaf..d63ba31d4 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/config/TagConfig.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/config/TagConfig.java @@ -18,20 +18,15 @@ */ package org.hyperledger.bpa.config; -import io.micronaut.context.annotation.EachProperty; -import io.micronaut.context.annotation.Parameter; +import io.micronaut.context.annotation.ConfigurationProperties; import lombok.Data; -@EachProperty("bpa.tags") +import java.util.List; + @Data +@ConfigurationProperties("bpa") public class TagConfig { - /** - * Bean name - */ - private String name; + private List tags; - public TagConfig(@Parameter String name) { - this.name = name; - } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/TagService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/TagService.java index 0ab393c07..a9fd4f65e 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/TagService.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/TagService.java @@ -39,7 +39,7 @@ public class TagService { TagRepository tagRepo; @Inject - List configuredTags; + TagConfig configuredTags; public @Nullable TagAPI addTag(@NonNull String name) { return addTag(name, Boolean.FALSE); @@ -90,14 +90,16 @@ public void deleteTag(@NonNull UUID id) { public void resetWriteOnlyTags() { long deleted = tagRepo.deleteByIsReadOnly(); log.debug("Removed {} preconfigured tags", deleted); + if (configuredTags.getTags() != null) { + configuredTags.getTags().forEach(t -> { + try { + TagAPI tagAPI = addTag(t, Boolean.TRUE); + log.debug("Added preconfigured tag with name: {}", tagAPI.getName()); + } catch (DataAccessException e) { + log.warn("Tag with name {} will not be added", t, e); + } + }); + } - configuredTags.forEach(t -> { - try { - TagAPI tagAPI = addTag(t.getName(), Boolean.TRUE); - log.debug("Added preconfigured tag with name: {}", tagAPI.getName()); - } catch (DataAccessException e) { - log.warn("Tag with name {} will not be added", t.getName(), e); - } - }); } } diff --git a/backend/business-partner-agent/src/main/resources/schemas.yml b/backend/business-partner-agent/src/main/resources/schemas.yml index 8a01fd373..dd4b101f8 100644 --- a/backend/business-partner-agent/src/main/resources/schemas.yml +++ b/backend/business-partner-agent/src/main/resources/schemas.yml @@ -16,3 +16,6 @@ bpa: restrictions: - issuerDid: "${bpa.did.prefix}5mwQSWnRePrZ3oF67C4KqD" label: "Commercial Register" + tags: + - "myInitTag" + - "myOtherInitTag"