From c5b146fd6a5d4c7a1a031f4393b2312e1dccf5b4 Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Fri, 11 Jun 2021 16:51:58 +0200 Subject: [PATCH 01/15] POC to check how difficult it is to plug rules with some logic into the aca-py event handler Signed-off-by: Philipp Etschel --- backend/business-partner-agent/pom.xml | 5 ++ .../bpa/impl/rules/EventObserver.java | 86 +++++++++++++++++++ .../bpa/impl/rules/TaskService.java | 49 +++++++++++ .../definitions/AssertVerifiedConnection.java | 84 ++++++++++++++++++ .../impl/rules/definitions/EventContext.java | 34 ++++++++ .../bpa/model/BPACredentialDefinition.java | 1 + .../bpa/model/BPACredentialExchange.java | 2 +- .../java/org/hyperledger/ModelBuilder.java | 27 ++++++ .../bpa/impl/rules/RuleBookTest.java | 68 +++++++++++++++ 9 files changed, 355 insertions(+), 1 deletion(-) create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/EventContext.java create mode 100644 backend/business-partner-agent/src/test/java/org/hyperledger/ModelBuilder.java create mode 100644 backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java diff --git a/backend/business-partner-agent/pom.xml b/backend/business-partner-agent/pom.xml index e9287d008..aeb17f733 100644 --- a/backend/business-partner-agent/pom.xml +++ b/backend/business-partner-agent/pom.xml @@ -161,6 +161,11 @@ spring-security-crypto 5.5.0 + + com.deliveredtechnologies + rulebook-core + 0.12 + diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java new file mode 100644 index 000000000..e77d7edff --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java @@ -0,0 +1,86 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rules; + +import com.deliveredtechnologies.rulebook.FactMap; +import com.deliveredtechnologies.rulebook.NameValueReferableMap; +import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; +import io.micronaut.context.ApplicationContext; +import lombok.extern.slf4j.Slf4j; +import org.hyperledger.aries.api.connection.ConnectionRecord; +import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; +import org.hyperledger.aries.webhook.EventHandler; +import org.hyperledger.bpa.impl.rules.definitions.EventContext; +import org.hyperledger.bpa.model.Partner; +import org.hyperledger.bpa.repository.PartnerRepository; + +import javax.inject.Inject; +import javax.inject.Singleton; + +@Slf4j +@Singleton +public class EventObserver extends EventHandler { + + @Inject + TaskService ts; + + @Inject + PartnerRepository pr; + + @Inject + ApplicationContext appCtx; + + @Override + public void handleConnection(ConnectionRecord connection) { + pr.findByConnectionId(connection.getConnectionId()).ifPresent(p -> ts.getActive(p.getId()).ifPresent(t -> { + NameValueReferableMap facts = new FactMap<>(); + facts.setValue("connection", EventContext + .builder() + .partner(p) + .connRec(connection) + .ctx(appCtx) + .build()); + runAndHandleResult(p, t, facts); + })); + } + + @Override + public void handleProof(PresentationExchangeRecord presEx) { + pr.findByConnectionId(presEx.getConnectionId()).ifPresent(p -> ts.getActive(p.getId()).ifPresent(t -> { + NameValueReferableMap facts = new FactMap<>(); + facts.setValue("presentation", EventContext + .builder() + .partner(p) + .presEx(presEx) + .ctx(appCtx) + .build()); + runAndHandleResult(p, t, facts); + })); + } + + private void runAndHandleResult(Partner p, CoRRuleBook t, NameValueReferableMap facts) { + log.debug("Checking rules for partner: {}", p); + t.run(facts); + t.getResult().ifPresentOrElse(result -> { + log.debug("Result: " + result); + if (result.getValue()) { + ts.removeIfDone(p.getId()); + } + }, () -> log.warn("Task did return a result")); + } +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java new file mode 100644 index 000000000..f5ab3a16b --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rules; + +import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; + +import javax.inject.Singleton; +import java.util.Map; +import java.util.Optional; +import java.util.UUID; +import java.util.concurrent.ConcurrentHashMap; + +@Slf4j +@Singleton +public class TaskService { + + private final Map> tasks = new ConcurrentHashMap<>(); + + void register(@NonNull UUID id, @NonNull CoRRuleBook task) { + log.debug("Adding task for partner: {}", id); + tasks.put(id, task); + } + + Optional> getActive(@NonNull UUID id) { + return Optional.ofNullable(tasks.get(id)); + } + + void removeIfDone(@NonNull UUID id) { + log.debug("Removing task for partner: {}", id); + tasks.remove(id); + } +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java new file mode 100644 index 000000000..2db6d3624 --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rules.definitions; + +import com.deliveredtechnologies.rulebook.NameValueReferableTypeConvertibleMap; +import com.deliveredtechnologies.rulebook.lang.RuleBuilder; +import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; +import lombok.Data; +import lombok.EqualsAndHashCode; +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; +import org.hyperledger.aries.api.connection.ConnectionState; + +import java.util.UUID; + +@Slf4j +@Data +@EqualsAndHashCode(callSuper = true) +public class AssertVerifiedConnection extends CoRRuleBook { + + private final UUID partnerId; + private final UUID proofTemplateId; + + public AssertVerifiedConnection(@NonNull UUID partnerId, @NonNull UUID proofTemplateId) { + this.partnerId = partnerId; + this.proofTemplateId = proofTemplateId; + this.setDefaultResult(Boolean.FALSE); + } + + @Override + public void defineRules() { + addRule(RuleBuilder.create().withFactType(EventContext.class).withResultType(Boolean.class) + .when(facts -> isConnection(facts)) + .then((facts, result) -> { + // load template + // send proof request + log.debug("Is connection"); + result.setValue(Boolean.FALSE); + }) + .stop() + .build()); + addRule(RuleBuilder.create().withFactType(EventContext.class).withResultType(Boolean.class) + .when(facts -> isPresentationExchange(facts)) + .then((facts, result) -> { + // check valid + // set label + log.debug("Is presentation"); + result.reset(); + result.setValue(Boolean.TRUE); + }) + .stop() + .build()); + } + + private boolean isConnection(NameValueReferableTypeConvertibleMap facts) { + EventContext f = facts.getOne(); + return f.getConnRec() != null + && ConnectionState.REQUEST.equals(f.getConnRec().getState()) + && f.getPartner() != null + && partnerId.equals(f.getPartner().getId()); + } + + private static boolean isPresentationExchange(NameValueReferableTypeConvertibleMap facts) { + EventContext f = facts.getOne(); + return f.getPresEx() != null; + } + +} + diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/EventContext.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/EventContext.java new file mode 100644 index 000000000..348f18130 --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/EventContext.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rules.definitions; + +import io.micronaut.context.ApplicationContext; +import lombok.Builder; +import lombok.Data; +import org.hyperledger.aries.api.connection.ConnectionRecord; +import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; +import org.hyperledger.bpa.model.Partner; + +@Data +@Builder +public class EventContext { + private Partner partner; + private PresentationExchangeRecord presEx; + private ConnectionRecord connRec; + private ApplicationContext ctx; +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/BPACredentialDefinition.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/BPACredentialDefinition.java index 257ced0ec..60d15f1c2 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/BPACredentialDefinition.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/BPACredentialDefinition.java @@ -53,6 +53,7 @@ public class BPACredentialDefinition { private String tag; + @Builder.Default private Boolean isSupportRevocation = Boolean.FALSE; private Integer revocationRegistrySize; diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/BPACredentialExchange.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/BPACredentialExchange.java index d6feae12b..59cae618a 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/BPACredentialExchange.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/BPACredentialExchange.java @@ -17,6 +17,7 @@ */ package org.hyperledger.bpa.model; +import io.micronaut.core.annotation.Nullable; import io.micronaut.data.annotation.AutoPopulated; import io.micronaut.data.annotation.DateCreated; import io.micronaut.data.annotation.TypeDef; @@ -29,7 +30,6 @@ import org.hyperledger.aries.api.issue_credential_v1.CredentialExchangeState; import org.hyperledger.bpa.api.CredentialType; -import javax.annotation.Nullable; import javax.persistence.*; import java.time.Instant; import java.util.Map; diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/ModelBuilder.java b/backend/business-partner-agent/src/test/java/org/hyperledger/ModelBuilder.java new file mode 100644 index 000000000..9c8139159 --- /dev/null +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/ModelBuilder.java @@ -0,0 +1,27 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger; + +import org.hyperledger.bpa.model.Partner; + +public class ModelBuilder { + + public static Partner buildDefaultPartner() { + return Partner.builder().did("did:dummy:1234").alias("alias").ariesSupport(Boolean.FALSE).build(); + } +} diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java new file mode 100644 index 000000000..c5e247c26 --- /dev/null +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rules; + +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import org.hyperledger.ModelBuilder; +import org.hyperledger.aries.api.connection.ConnectionRecord; +import org.hyperledger.aries.api.connection.ConnectionState; +import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; +import org.hyperledger.bpa.impl.rules.definitions.AssertVerifiedConnection; +import org.hyperledger.bpa.model.Partner; +import org.hyperledger.bpa.repository.PartnerRepository; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.inject.Inject; +import java.util.UUID; + +@MicronautTest +public class RuleBookTest { + + @Inject + TaskService ts; + + @Inject + EventObserver eo; + + @Inject + PartnerRepository pr; + + @Test + void testSimpleRule() { + String connectionId = "123"; + + Partner p = ModelBuilder.buildDefaultPartner().setConnectionId(connectionId); + p = pr.save(p); + + AssertVerifiedConnection rule = new AssertVerifiedConnection(p.getId(), UUID.randomUUID()); + ts.register(p.getId(), rule); + Assertions.assertTrue(ts.getActive(p.getId()).isPresent()); + + ConnectionRecord rec = new ConnectionRecord(); + rec.setConnectionId(connectionId); + rec.setState(ConnectionState.REQUEST); + eo.handleConnection(rec); + + PresentationExchangeRecord ex = new PresentationExchangeRecord(); + ex.setConnectionId(connectionId); + eo.handleProof(ex); + + Assertions.assertFalse(ts.getActive(p.getId()).isPresent()); + } + } From 60f15b43ffecf743b3fea65bfb0f3da5e07e9306 Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Fri, 11 Jun 2021 17:08:07 +0200 Subject: [PATCH 02/15] license fix Signed-off-by: Philipp Etschel --- backend/business-partner-agent/pom.xml | 15 +++++++++++++++ .../definitions/AssertVerifiedConnection.java | 1 - .../hyperledger/bpa/impl/rules/RuleBookTest.java | 2 +- 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/business-partner-agent/pom.xml b/backend/business-partner-agent/pom.xml index aeb17f733..65d5a9ae6 100644 --- a/backend/business-partner-agent/pom.xml +++ b/backend/business-partner-agent/pom.xml @@ -165,6 +165,21 @@ com.deliveredtechnologies rulebook-core 0.12 + + + + org.javassist + javassist + + + com.google.code.findbugs + annotations + + + org.reflections + reflections + + diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java index 2db6d3624..906361ea7 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java @@ -81,4 +81,3 @@ private static boolean isPresentationExchange(NameValueReferableTypeConvertibleM } } - diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java index c5e247c26..bae46a063 100644 --- a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java @@ -65,4 +65,4 @@ void testSimpleRule() { Assertions.assertFalse(ts.getActive(p.getId()).isPresent()); } - } +} From 3cda8ca7e976ef5cc373af3d33b06b1bf847a6fe Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Mon, 14 Jun 2021 15:56:24 +0200 Subject: [PATCH 03/15] allow multiple tasks per id. Signed-off-by: Philipp Etschel --- .../bpa/impl/rules/EventObserver.java | 22 ++++++----- .../bpa/impl/rules/TaskService.java | 38 +++++++++++++------ .../definitions/AssertVerifiedConnection.java | 16 ++++---- .../impl/rules/definitions/BaseAriesTask.java | 18 +++++++++ 4 files changed, 65 insertions(+), 29 deletions(-) create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseAriesTask.java diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java index e77d7edff..3fb2cb7c7 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java @@ -19,18 +19,19 @@ import com.deliveredtechnologies.rulebook.FactMap; import com.deliveredtechnologies.rulebook.NameValueReferableMap; -import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; import io.micronaut.context.ApplicationContext; import lombok.extern.slf4j.Slf4j; import org.hyperledger.aries.api.connection.ConnectionRecord; import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; import org.hyperledger.aries.webhook.EventHandler; +import org.hyperledger.bpa.impl.rules.definitions.BaseAriesTask; import org.hyperledger.bpa.impl.rules.definitions.EventContext; import org.hyperledger.bpa.model.Partner; import org.hyperledger.bpa.repository.PartnerRepository; import javax.inject.Inject; import javax.inject.Singleton; +import java.util.List; @Slf4j @Singleton @@ -73,14 +74,17 @@ public void handleProof(PresentationExchangeRecord presEx) { })); } - private void runAndHandleResult(Partner p, CoRRuleBook t, NameValueReferableMap facts) { + private void runAndHandleResult( + Partner p, List tasks, NameValueReferableMap facts) { log.debug("Checking rules for partner: {}", p); - t.run(facts); - t.getResult().ifPresentOrElse(result -> { - log.debug("Result: " + result); - if (result.getValue()) { - ts.removeIfDone(p.getId()); - } - }, () -> log.warn("Task did return a result")); + tasks.parallelStream().forEach(t -> { + t.run(facts); + t.getResult().ifPresentOrElse(result -> { + log.debug("Task: {}, Result: {}", t.getTaskId(), result.getValue()); + if (result.getValue()) { + ts.removeIfDone(p.getId(), t.getTaskId()); + } + }, () -> log.warn("Task did return a result")); + }); } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java index f5ab3a16b..5f0207c06 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java @@ -17,33 +17,49 @@ */ package org.hyperledger.bpa.impl.rules; -import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; +import io.micronaut.core.util.CollectionUtils; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; +import org.hyperledger.bpa.impl.rules.definitions.BaseAriesTask; import javax.inject.Singleton; -import java.util.Map; -import java.util.Optional; -import java.util.UUID; +import java.util.*; import java.util.concurrent.ConcurrentHashMap; +import java.util.stream.Collectors; @Slf4j @Singleton public class TaskService { - private final Map> tasks = new ConcurrentHashMap<>(); + private final Map> tasks = new ConcurrentHashMap<>(); - void register(@NonNull UUID id, @NonNull CoRRuleBook task) { + void register(@NonNull UUID id, @NonNull BaseAriesTask task) { log.debug("Adding task for partner: {}", id); - tasks.put(id, task); + List scheduled = tasks.get(id); + if (scheduled == null) { + tasks.put(id, new ArrayList<>(List.of(task))); + } else { + scheduled.add(task); + } } - Optional> getActive(@NonNull UUID id) { + Optional> getActive(@NonNull UUID id) { return Optional.ofNullable(tasks.get(id)); } - void removeIfDone(@NonNull UUID id) { - log.debug("Removing task for partner: {}", id); - tasks.remove(id); + synchronized void removeIfDone(@NonNull UUID id, @NonNull UUID taskId) { + List scheduled = tasks.get(id); + if (scheduled != null) { + log.debug("Removing task for partner: {}", id); + List filtered = scheduled + .stream() + .filter(t -> !t.getTaskId().equals(taskId)) + .collect(Collectors.toList()); + if (CollectionUtils.isNotEmpty(filtered)) { + tasks.put(id, filtered); + } else { + tasks.remove(id); + } + } } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java index 906361ea7..ab94a4296 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java @@ -19,7 +19,6 @@ import com.deliveredtechnologies.rulebook.NameValueReferableTypeConvertibleMap; import com.deliveredtechnologies.rulebook.lang.RuleBuilder; -import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NonNull; @@ -29,23 +28,22 @@ import java.util.UUID; @Slf4j -@Data -@EqualsAndHashCode(callSuper = true) -public class AssertVerifiedConnection extends CoRRuleBook { +@Data @EqualsAndHashCode(callSuper = true) +public class AssertVerifiedConnection extends BaseAriesTask { private final UUID partnerId; private final UUID proofTemplateId; public AssertVerifiedConnection(@NonNull UUID partnerId, @NonNull UUID proofTemplateId) { + super(UUID.randomUUID()); this.partnerId = partnerId; this.proofTemplateId = proofTemplateId; - this.setDefaultResult(Boolean.FALSE); } @Override public void defineRules() { - addRule(RuleBuilder.create().withFactType(EventContext.class).withResultType(Boolean.class) - .when(facts -> isConnection(facts)) + addRule(RuleBuilder.create().withFactType(EventContext.class) + .when(this::isConnection) .then((facts, result) -> { // load template // send proof request @@ -54,8 +52,8 @@ public void defineRules() { }) .stop() .build()); - addRule(RuleBuilder.create().withFactType(EventContext.class).withResultType(Boolean.class) - .when(facts -> isPresentationExchange(facts)) + addRule(RuleBuilder.create().withFactType(EventContext.class) + .when(AssertVerifiedConnection::isPresentationExchange) .then((facts, result) -> { // check valid // set label diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseAriesTask.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseAriesTask.java new file mode 100644 index 000000000..c99ca48fe --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseAriesTask.java @@ -0,0 +1,18 @@ +package org.hyperledger.bpa.impl.rules.definitions; + +import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.UUID; + +@Data @NoArgsConstructor +public abstract class BaseAriesTask extends CoRRuleBook { + + private UUID taskId; + + public BaseAriesTask(UUID taskId) { + this.taskId = taskId; + super.setDefaultResult(Boolean.FALSE); + } +} From 9ed4100dfac4f6bb8f7f3949865ee25d912a5236 Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Mon, 14 Jun 2021 16:49:18 +0200 Subject: [PATCH 04/15] renamed classes Signed-off-by: Philipp Etschel --- ...EventObserver.java => RulesEventHandler.java} | 8 ++++---- .../{TaskService.java => RulesService.java} | 16 ++++++++-------- .../definitions/AssertVerifiedConnection.java | 2 +- .../{BaseAriesTask.java => BaseRule.java} | 4 ++-- .../hyperledger/bpa/impl/rules/RuleBookTest.java | 4 ++-- 5 files changed, 17 insertions(+), 17 deletions(-) rename backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/{EventObserver.java => RulesEventHandler.java} (93%) rename backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/{TaskService.java => RulesService.java} (79%) rename backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/{BaseAriesTask.java => BaseRule.java} (76%) diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java similarity index 93% rename from backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java rename to backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java index 3fb2cb7c7..8730394e6 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventObserver.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java @@ -24,7 +24,7 @@ import org.hyperledger.aries.api.connection.ConnectionRecord; import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; import org.hyperledger.aries.webhook.EventHandler; -import org.hyperledger.bpa.impl.rules.definitions.BaseAriesTask; +import org.hyperledger.bpa.impl.rules.definitions.BaseRule; import org.hyperledger.bpa.impl.rules.definitions.EventContext; import org.hyperledger.bpa.model.Partner; import org.hyperledger.bpa.repository.PartnerRepository; @@ -35,10 +35,10 @@ @Slf4j @Singleton -public class EventObserver extends EventHandler { +public class RulesEventHandler extends EventHandler { @Inject - TaskService ts; + RulesService ts; @Inject PartnerRepository pr; @@ -75,7 +75,7 @@ public void handleProof(PresentationExchangeRecord presEx) { } private void runAndHandleResult( - Partner p, List tasks, NameValueReferableMap facts) { + Partner p, List tasks, NameValueReferableMap facts) { log.debug("Checking rules for partner: {}", p); tasks.parallelStream().forEach(t -> { t.run(facts); diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java similarity index 79% rename from backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java rename to backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java index 5f0207c06..2f2cd2533 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/TaskService.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java @@ -20,7 +20,7 @@ import io.micronaut.core.util.CollectionUtils; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; -import org.hyperledger.bpa.impl.rules.definitions.BaseAriesTask; +import org.hyperledger.bpa.impl.rules.definitions.BaseRule; import javax.inject.Singleton; import java.util.*; @@ -29,13 +29,13 @@ @Slf4j @Singleton -public class TaskService { +public class RulesService { - private final Map> tasks = new ConcurrentHashMap<>(); + private final Map> tasks = new ConcurrentHashMap<>(); - void register(@NonNull UUID id, @NonNull BaseAriesTask task) { + void register(@NonNull UUID id, @NonNull BaseRule task) { log.debug("Adding task for partner: {}", id); - List scheduled = tasks.get(id); + List scheduled = tasks.get(id); if (scheduled == null) { tasks.put(id, new ArrayList<>(List.of(task))); } else { @@ -43,15 +43,15 @@ void register(@NonNull UUID id, @NonNull BaseAriesTask task) { } } - Optional> getActive(@NonNull UUID id) { + Optional> getActive(@NonNull UUID id) { return Optional.ofNullable(tasks.get(id)); } synchronized void removeIfDone(@NonNull UUID id, @NonNull UUID taskId) { - List scheduled = tasks.get(id); + List scheduled = tasks.get(id); if (scheduled != null) { log.debug("Removing task for partner: {}", id); - List filtered = scheduled + List filtered = scheduled .stream() .filter(t -> !t.getTaskId().equals(taskId)) .collect(Collectors.toList()); diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java index ab94a4296..14d063e1b 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java @@ -29,7 +29,7 @@ @Slf4j @Data @EqualsAndHashCode(callSuper = true) -public class AssertVerifiedConnection extends BaseAriesTask { +public class AssertVerifiedConnection extends BaseRule { private final UUID partnerId; private final UUID proofTemplateId; diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseAriesTask.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java similarity index 76% rename from backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseAriesTask.java rename to backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java index c99ca48fe..d7d8621be 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseAriesTask.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java @@ -7,11 +7,11 @@ import java.util.UUID; @Data @NoArgsConstructor -public abstract class BaseAriesTask extends CoRRuleBook { +public abstract class BaseRule extends CoRRuleBook { private UUID taskId; - public BaseAriesTask(UUID taskId) { + public BaseRule(UUID taskId) { this.taskId = taskId; super.setDefaultResult(Boolean.FALSE); } diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java index bae46a063..e0a93159f 100644 --- a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java @@ -35,10 +35,10 @@ public class RuleBookTest { @Inject - TaskService ts; + RulesService ts; @Inject - EventObserver eo; + RulesEventHandler eo; @Inject PartnerRepository pr; From 16243005d5720f989a7e47eb2f0d837965058228 Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Mon, 14 Jun 2021 17:41:17 +0200 Subject: [PATCH 05/15] simplified again, rules run once or multiple times and are not linked to a partner Signed-off-by: Philipp Etschel --- .../bpa/impl/rules/RulesEventHandler.java | 24 +++++------ .../bpa/impl/rules/RulesService.java | 43 +++++++------------ .../definitions/AssertVerifiedConnection.java | 2 +- .../bpa/impl/rules/definitions/BaseRule.java | 9 +++- .../bpa/impl/rules/RuleBookTest.java | 6 +-- 5 files changed, 39 insertions(+), 45 deletions(-) diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java index 8730394e6..2f1356992 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java @@ -26,7 +26,6 @@ import org.hyperledger.aries.webhook.EventHandler; import org.hyperledger.bpa.impl.rules.definitions.BaseRule; import org.hyperledger.bpa.impl.rules.definitions.EventContext; -import org.hyperledger.bpa.model.Partner; import org.hyperledger.bpa.repository.PartnerRepository; import javax.inject.Inject; @@ -48,7 +47,7 @@ public class RulesEventHandler extends EventHandler { @Override public void handleConnection(ConnectionRecord connection) { - pr.findByConnectionId(connection.getConnectionId()).ifPresent(p -> ts.getActive(p.getId()).ifPresent(t -> { + pr.findByConnectionId(connection.getConnectionId()).ifPresent(p -> { NameValueReferableMap facts = new FactMap<>(); facts.setValue("connection", EventContext .builder() @@ -56,13 +55,13 @@ public void handleConnection(ConnectionRecord connection) { .connRec(connection) .ctx(appCtx) .build()); - runAndHandleResult(p, t, facts); - })); + runAndHandleResult(facts); + }); } @Override public void handleProof(PresentationExchangeRecord presEx) { - pr.findByConnectionId(presEx.getConnectionId()).ifPresent(p -> ts.getActive(p.getId()).ifPresent(t -> { + pr.findByConnectionId(presEx.getConnectionId()).ifPresent(p -> { NameValueReferableMap facts = new FactMap<>(); facts.setValue("presentation", EventContext .builder() @@ -70,19 +69,20 @@ public void handleProof(PresentationExchangeRecord presEx) { .presEx(presEx) .ctx(appCtx) .build()); - runAndHandleResult(p, t, facts); - })); + runAndHandleResult(facts); + }); } - private void runAndHandleResult( - Partner p, List tasks, NameValueReferableMap facts) { - log.debug("Checking rules for partner: {}", p); + private void runAndHandleResult(NameValueReferableMap facts) { + List tasks = ts.getActive(); + log.debug("Checking {} rules", tasks.size()); tasks.parallelStream().forEach(t -> { t.run(facts); t.getResult().ifPresentOrElse(result -> { log.debug("Task: {}, Result: {}", t.getTaskId(), result.getValue()); - if (result.getValue()) { - ts.removeIfDone(p.getId(), t.getTaskId()); + if (result.getValue() && BaseRule.Run.ONCE.equals(t.getRun())) { + log.debug("Tasks runs: {}, scheduling for removal", t.getRun()); + ts.removeIfDone(t.getTaskId()); } }, () -> log.warn("Task did return a result")); }); diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java index 2f2cd2533..4e82061eb 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java @@ -17,49 +17,36 @@ */ package org.hyperledger.bpa.impl.rules; -import io.micronaut.core.util.CollectionUtils; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.hyperledger.bpa.impl.rules.definitions.BaseRule; import javax.inject.Singleton; -import java.util.*; -import java.util.concurrent.ConcurrentHashMap; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import java.util.stream.Collectors; @Slf4j @Singleton public class RulesService { - private final Map> tasks = new ConcurrentHashMap<>(); + private List tasks = new ArrayList<>(); - void register(@NonNull UUID id, @NonNull BaseRule task) { - log.debug("Adding task for partner: {}", id); - List scheduled = tasks.get(id); - if (scheduled == null) { - tasks.put(id, new ArrayList<>(List.of(task))); - } else { - scheduled.add(task); - } + void register(@NonNull BaseRule task) { + log.debug("Adding task: {}", task); + tasks.add(task); } - Optional> getActive(@NonNull UUID id) { - return Optional.ofNullable(tasks.get(id)); + List getActive() { + return tasks; } - synchronized void removeIfDone(@NonNull UUID id, @NonNull UUID taskId) { - List scheduled = tasks.get(id); - if (scheduled != null) { - log.debug("Removing task for partner: {}", id); - List filtered = scheduled - .stream() - .filter(t -> !t.getTaskId().equals(taskId)) - .collect(Collectors.toList()); - if (CollectionUtils.isNotEmpty(filtered)) { - tasks.put(id, filtered); - } else { - tasks.remove(id); - } - } + synchronized void removeIfDone(@NonNull UUID taskId) { + log.debug("Removing task with id: {}", taskId); + tasks = tasks + .stream() + .filter(t -> !t.getTaskId().equals(taskId)) + .collect(Collectors.toList()); } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java index 14d063e1b..a6fe747db 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java @@ -35,7 +35,7 @@ public class AssertVerifiedConnection extends BaseRule { private final UUID proofTemplateId; public AssertVerifiedConnection(@NonNull UUID partnerId, @NonNull UUID proofTemplateId) { - super(UUID.randomUUID()); + super(UUID.randomUUID(), Run.ONCE); this.partnerId = partnerId; this.proofTemplateId = proofTemplateId; } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java index d7d8621be..a9b886686 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java @@ -10,9 +10,16 @@ public abstract class BaseRule extends CoRRuleBook { private UUID taskId; + private Run run; - public BaseRule(UUID taskId) { + public BaseRule(UUID taskId, Run run) { this.taskId = taskId; + this.run = run; super.setDefaultResult(Boolean.FALSE); } + + public enum Run { + ONCE, + MULTI + } } diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java index e0a93159f..2d7b424d2 100644 --- a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java @@ -51,8 +51,8 @@ void testSimpleRule() { p = pr.save(p); AssertVerifiedConnection rule = new AssertVerifiedConnection(p.getId(), UUID.randomUUID()); - ts.register(p.getId(), rule); - Assertions.assertTrue(ts.getActive(p.getId()).isPresent()); + ts.register(rule); + Assertions.assertTrue(ts.getActive().size() > 0); ConnectionRecord rec = new ConnectionRecord(); rec.setConnectionId(connectionId); @@ -63,6 +63,6 @@ void testSimpleRule() { ex.setConnectionId(connectionId); eo.handleProof(ex); - Assertions.assertFalse(ts.getActive(p.getId()).isPresent()); + Assertions.assertFalse(ts.getActive().size() > 0); } } From 14e8834c49b6d7078b925321e7b10742d0a10e29 Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Mon, 14 Jun 2021 17:55:35 +0200 Subject: [PATCH 06/15] more deletions Signed-off-by: Philipp Etschel --- .../hyperledger/bpa/impl/rules/RulesEventHandler.java | 4 ++-- .../org/hyperledger/bpa/impl/rules/RulesService.java | 9 ++++----- .../impl/rules/definitions/AssertVerifiedConnection.java | 7 ++----- .../org/hyperledger/bpa/impl/rules/RuleBookTest.java | 6 +++--- 4 files changed, 11 insertions(+), 15 deletions(-) diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java index 2f1356992..f602964b7 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java @@ -74,7 +74,7 @@ public void handleProof(PresentationExchangeRecord presEx) { } private void runAndHandleResult(NameValueReferableMap facts) { - List tasks = ts.getActive(); + List tasks = ts.getTasks(); log.debug("Checking {} rules", tasks.size()); tasks.parallelStream().forEach(t -> { t.run(facts); @@ -82,7 +82,7 @@ private void runAndHandleResult(NameValueReferableMap facts) { log.debug("Task: {}, Result: {}", t.getTaskId(), result.getValue()); if (result.getValue() && BaseRule.Run.ONCE.equals(t.getRun())) { log.debug("Tasks runs: {}, scheduling for removal", t.getRun()); - ts.removeIfDone(t.getTaskId()); + ts.remove(t.getTaskId()); } }, () -> log.warn("Task did return a result")); }); diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java index 4e82061eb..66f771da8 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java @@ -17,6 +17,8 @@ */ package org.hyperledger.bpa.impl.rules; +import lombok.AccessLevel; +import lombok.Getter; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.hyperledger.bpa.impl.rules.definitions.BaseRule; @@ -31,6 +33,7 @@ @Singleton public class RulesService { + @Getter(AccessLevel.PACKAGE) private List tasks = new ArrayList<>(); void register(@NonNull BaseRule task) { @@ -38,11 +41,7 @@ void register(@NonNull BaseRule task) { tasks.add(task); } - List getActive() { - return tasks; - } - - synchronized void removeIfDone(@NonNull UUID taskId) { + synchronized void remove(@NonNull UUID taskId) { log.debug("Removing task with id: {}", taskId); tasks = tasks .stream() diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java index a6fe747db..353f868e5 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java @@ -31,12 +31,10 @@ @Data @EqualsAndHashCode(callSuper = true) public class AssertVerifiedConnection extends BaseRule { - private final UUID partnerId; private final UUID proofTemplateId; - public AssertVerifiedConnection(@NonNull UUID partnerId, @NonNull UUID proofTemplateId) { + public AssertVerifiedConnection(@NonNull UUID proofTemplateId) { super(UUID.randomUUID(), Run.ONCE); - this.partnerId = partnerId; this.proofTemplateId = proofTemplateId; } @@ -69,8 +67,7 @@ private boolean isConnection(NameValueReferableTypeConvertibleMap EventContext f = facts.getOne(); return f.getConnRec() != null && ConnectionState.REQUEST.equals(f.getConnRec().getState()) - && f.getPartner() != null - && partnerId.equals(f.getPartner().getId()); + && f.getPartner() != null; } private static boolean isPresentationExchange(NameValueReferableTypeConvertibleMap facts) { diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java index 2d7b424d2..5a1284357 100644 --- a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java @@ -50,9 +50,9 @@ void testSimpleRule() { Partner p = ModelBuilder.buildDefaultPartner().setConnectionId(connectionId); p = pr.save(p); - AssertVerifiedConnection rule = new AssertVerifiedConnection(p.getId(), UUID.randomUUID()); + AssertVerifiedConnection rule = new AssertVerifiedConnection(UUID.randomUUID()); ts.register(rule); - Assertions.assertTrue(ts.getActive().size() > 0); + Assertions.assertTrue(ts.getTasks().size() > 0); ConnectionRecord rec = new ConnectionRecord(); rec.setConnectionId(connectionId); @@ -63,6 +63,6 @@ void testSimpleRule() { ex.setConnectionId(connectionId); eo.handleProof(ex); - Assertions.assertFalse(ts.getActive().size() > 0); + Assertions.assertFalse(ts.getTasks().size() > 0); } } From 6b485bfae4ae216fb06a2085521873002a17aabf Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Mon, 14 Jun 2021 18:02:48 +0200 Subject: [PATCH 07/15] does not matter right now Signed-off-by: Philipp Etschel --- .../main/java/org/hyperledger/bpa/impl/rules/RulesService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java index 66f771da8..93553cdc8 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java @@ -41,7 +41,7 @@ void register(@NonNull BaseRule task) { tasks.add(task); } - synchronized void remove(@NonNull UUID taskId) { + void remove(@NonNull UUID taskId) { log.debug("Removing task with id: {}", taskId); tasks = tasks .stream() From e0a3bddcfe6e57371f6904a8ee849b1d80f2b1fb Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Mon, 14 Jun 2021 18:09:49 +0200 Subject: [PATCH 08/15] formatter and header Signed-off-by: Philipp Etschel --- .../bpa/impl/activity/DidResolver.java | 4 ++-- .../definitions/AssertVerifiedConnection.java | 3 ++- .../bpa/impl/rules/definitions/BaseRule.java | 20 ++++++++++++++++++- 3 files changed, 23 insertions(+), 4 deletions(-) diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/activity/DidResolver.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/activity/DidResolver.java index 769eeb88f..afd6cf47e 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/activity/DidResolver.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/activity/DidResolver.java @@ -62,8 +62,8 @@ public class DidResolver { WebhookService webhook; /** - * Tries to resolve the partners public profile based on the did contained withn - * a commercial register credential. + * Tries to resolve the partners public profile based on the did contained + * within a commercial register credential. * * @param pp {@link PartnerProof} */ diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java index 353f868e5..0743b85d7 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java @@ -28,7 +28,8 @@ import java.util.UUID; @Slf4j -@Data @EqualsAndHashCode(callSuper = true) +@Data +@EqualsAndHashCode(callSuper = true) public class AssertVerifiedConnection extends BaseRule { private final UUID proofTemplateId; diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java index a9b886686..0452d1c6e 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java @@ -1,3 +1,20 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package org.hyperledger.bpa.impl.rules.definitions; import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; @@ -6,7 +23,8 @@ import java.util.UUID; -@Data @NoArgsConstructor +@Data +@NoArgsConstructor public abstract class BaseRule extends CoRRuleBook { private UUID taskId; From 6591a841769b7136e504d8e4e4b71bea9639f6a4 Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Thu, 17 Jun 2021 12:59:29 +0200 Subject: [PATCH 09/15] rules without rule book impl Signed-off-by: Philipp Etschel --- .../controller/AriesWebhookController.java | 11 +- .../bpa/impl/aries/ConnectionManager.java | 15 +- .../bpa/impl/aries/ProofManager.java | 2 +- .../rules/{definitions => }/EventContext.java | 2 +- .../hyperledger/bpa/impl/rules/RulesData.java | 130 ++++++++++++++++++ .../bpa/impl/rules/RulesEventHandler.java | 37 ++--- .../bpa/impl/rules/RulesService.java | 40 ++++-- .../bpa/impl/rulesold/RulesEventHandler.java | 89 ++++++++++++ .../bpa/impl/rulesold/RulesService.java | 53 +++++++ .../definitions/AssertVerifiedConnection.java | 34 ++++- .../definitions/BaseRule.java | 2 +- .../rulesold/definitions/EventContext.java | 34 +++++ .../hyperledger/bpa/model/ActiveRules.java | 60 ++++++++ .../bpa/repository/RulesRepository.java | 30 ++++ .../V1.14__add-active-rules-table.sql | 7 + .../hyperledger/bpa/impl/rules/RulesTest.java | 58 ++++++++ .../{rules => rulesold}/RuleBookTest.java | 6 +- .../bpa/repository/RulesRepositoryTest.java | 45 ++++++ backend/pom.xml | 8 +- 19 files changed, 603 insertions(+), 60 deletions(-) rename backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/{definitions => }/EventContext.java (95%) create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesEventHandler.java create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesService.java rename backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/{rules => rulesold}/definitions/AssertVerifiedConnection.java (70%) rename backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/{rules => rulesold}/definitions/BaseRule.java (95%) create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/EventContext.java create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/ActiveRules.java create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/repository/RulesRepository.java create mode 100644 backend/business-partner-agent/src/main/resources/databasemigrations/V1.14__add-active-rules-table.sql create mode 100644 backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java rename backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/{rules => rulesold}/RuleBookTest.java (92%) create mode 100644 backend/business-partner-agent/src/test/java/org/hyperledger/bpa/repository/RulesRepositoryTest.java diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/AriesWebhookController.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/AriesWebhookController.java index 37eb0550b..b469ae04e 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/AriesWebhookController.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/AriesWebhookController.java @@ -31,6 +31,7 @@ import org.hyperledger.aries.webhook.EventHandler; import javax.inject.Inject; +import javax.inject.Named; /** * Handles incoming aca-py webhook events @@ -46,7 +47,12 @@ public class AriesWebhookController { public static final String WEBHOOK_CONTROLLER_PATH = "/log/topic"; @Inject - EventHandler handler; + @Named("aries") + EventHandler coreHandler; + + @Inject + @Named("rules") + EventHandler rulesHandler; @Post(WEBHOOK_CONTROLLER_PATH + "/{eventType}") public void logEvent( @@ -55,6 +61,7 @@ public void logEvent( log.info("Webhook received, type: {}", eventType); - handler.handleEvent(eventType, eventBody); + coreHandler.handleEvent(eventType, eventBody); + rulesHandler.handleEvent(eventType, eventBody); } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/aries/ConnectionManager.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/aries/ConnectionManager.java index bf9657dbe..a8953a618 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/aries/ConnectionManager.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/aries/ConnectionManager.java @@ -247,15 +247,12 @@ private void resolveAndSend(ConnectionRecord record, Partner p) { // only incoming connections in state request if (ConnectionState.REQUEST.equals(record.getState())) { didResolver.lookupIncoming(p); - sendConnectionEvent(record, conv.toAPIObject(p)); - } - } - - private void sendConnectionEvent(@NonNull ConnectionRecord record, @NonNull PartnerAPI p) { - // TODO both or either? - messageService.sendMessage(WebSocketMessageBody.partnerReceived(p)); - if (isConnectionRequest(record)) { - messageService.sendMessage(WebSocketMessageBody.partnerConnectionRequest(p)); + // TODO both or either? + PartnerAPI pApi = conv.toAPIObject(p); + messageService.sendMessage(WebSocketMessageBody.partnerReceived(pApi)); + if (isConnectionRequest(record)) { + messageService.sendMessage(WebSocketMessageBody.partnerConnectionRequest(pApi)); + } } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/aries/ProofManager.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/aries/ProofManager.java index 5daf5996d..6815c76f8 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/aries/ProofManager.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/aries/ProofManager.java @@ -300,7 +300,7 @@ private AriesProofExchange toApiProof(@NonNull PartnerProof p) { return proof; } - private void sendPresentProofProblemReport(@NotNull String PresentationExchangeId, @NotNull String problemString) + private void sendPresentProofProblemReport(@NonNull String PresentationExchangeId, @NonNull String problemString) throws IOException { PresentationProblemReportRequest request = PresentationProblemReportRequest.builder() .explainLtxt(problemString) diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/EventContext.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventContext.java similarity index 95% rename from backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/EventContext.java rename to backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventContext.java index 348f18130..c6b708c72 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/EventContext.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/EventContext.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.hyperledger.bpa.impl.rules.definitions; +package org.hyperledger.bpa.impl.rules; import io.micronaut.context.ApplicationContext; import lombok.Builder; diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java new file mode 100644 index 000000000..8dad33c85 --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rules; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.*; +import lombok.extern.slf4j.Slf4j; +import org.hyperledger.aries.api.connection.ConnectionState; +import org.hyperledger.aries.api.connection.ConnectionTheirRole; + +import java.util.UUID; + +@Slf4j +@Data +@Builder +public class RulesData { + + private UUID ruleId; + private Trigger trigger; + private Action action; + + public RulesData(Trigger trigger, Action action) { + this.trigger = trigger; + this.action = action; + } + + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + property = "type") + @JsonSubTypes({ + @JsonSubTypes.Type(value = Trigger.ConnectionTrigger.class, name = Trigger.CONNECTION_TRIGGER_NAME), + @JsonSubTypes.Type(value = Trigger.ProofReceivedTrigger.class, name = Trigger.PROOF_RECEIVED_TRIGGER_NAME) + }) + @NoArgsConstructor + public abstract static class Trigger { + + public static final String CONNECTION_TRIGGER_NAME = "connection"; + public static final String PROOF_RECEIVED_TRIGGER_NAME = "proof_received"; + + abstract boolean apply(EventContext ctx); + + @SuppressWarnings("unused") + private String type; + + @JsonTypeName(Trigger.CONNECTION_TRIGGER_NAME) + @Builder @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor + public static class ConnectionTrigger extends Trigger { + private ConnectionTheirRole role; + private String tag; + private String goalCode; + + @Override + public boolean apply(EventContext ctx) { + return ctx.getConnRec() != null && ConnectionState.REQUEST.equals(ctx.getConnRec().getState()); + } + } + + @JsonTypeName(Trigger.PROOF_RECEIVED_TRIGGER_NAME) + @Builder @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor + public static class ProofReceivedTrigger extends Trigger { + private String tag; + private UUID proofTemplateId; + + @Override + public boolean apply(EventContext ctx) { + return false; + } + } + } + + @JsonTypeInfo( + use = JsonTypeInfo.Id.NAME, + property = "type") + @JsonSubTypes({ + @JsonSubTypes.Type(value = Action.TagConnection.class, name = Action.TAG_CONNECTION_ACTION_NAME), + @JsonSubTypes.Type(value = Action.SendProofRequest.class, name = Action.SEND_PROOF_REQUEST_ACTION_NAME) + }) + @NoArgsConstructor + public abstract static class Action { + + public static final String TAG_CONNECTION_ACTION_NAME = "tag_connection"; + public static final String SEND_PROOF_REQUEST_ACTION_NAME = "send_proof_request"; + + abstract void run(EventContext ctx); + + @SuppressWarnings("unused") + private String type; + + @JsonTypeName(Action.TAG_CONNECTION_ACTION_NAME) + @Builder @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor + public static class TagConnection extends Action { + private String connectionId; + private String tag; + + @Override + void run(EventContext ctx) { + log.debug("tag: {}", tag); + } + } + + @JsonTypeName(Action.SEND_PROOF_REQUEST_ACTION_NAME) + @Builder @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor + public static class SendProofRequest extends Action{ + private String connectionId; + private UUID proofTemplateId; + + @Override + void run(EventContext ctx) { + + } + } + } +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java index f602964b7..37e638d9a 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java @@ -17,15 +17,11 @@ */ package org.hyperledger.bpa.impl.rules; -import com.deliveredtechnologies.rulebook.FactMap; -import com.deliveredtechnologies.rulebook.NameValueReferableMap; import io.micronaut.context.ApplicationContext; import lombok.extern.slf4j.Slf4j; import org.hyperledger.aries.api.connection.ConnectionRecord; import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; import org.hyperledger.aries.webhook.EventHandler; -import org.hyperledger.bpa.impl.rules.definitions.BaseRule; -import org.hyperledger.bpa.impl.rules.definitions.EventContext; import org.hyperledger.bpa.repository.PartnerRepository; import javax.inject.Inject; @@ -48,43 +44,36 @@ public class RulesEventHandler extends EventHandler { @Override public void handleConnection(ConnectionRecord connection) { pr.findByConnectionId(connection.getConnectionId()).ifPresent(p -> { - NameValueReferableMap facts = new FactMap<>(); - facts.setValue("connection", EventContext + runRule(EventContext .builder() .partner(p) .connRec(connection) .ctx(appCtx) - .build()); - runAndHandleResult(facts); + .build()) + ; }); } @Override public void handleProof(PresentationExchangeRecord presEx) { pr.findByConnectionId(presEx.getConnectionId()).ifPresent(p -> { - NameValueReferableMap facts = new FactMap<>(); - facts.setValue("presentation", EventContext + runRule(EventContext .builder() .partner(p) .presEx(presEx) .ctx(appCtx) - .build()); - runAndHandleResult(facts); + .build()) + ; }); } - private void runAndHandleResult(NameValueReferableMap facts) { - List tasks = ts.getTasks(); - log.debug("Checking {} rules", tasks.size()); - tasks.parallelStream().forEach(t -> { - t.run(facts); - t.getResult().ifPresentOrElse(result -> { - log.debug("Task: {}, Result: {}", t.getTaskId(), result.getValue()); - if (result.getValue() && BaseRule.Run.ONCE.equals(t.getRun())) { - log.debug("Tasks runs: {}, scheduling for removal", t.getRun()); - ts.remove(t.getTaskId()); - } - }, () -> log.warn("Task did return a result")); + public void runRule(EventContext ctx) { + List rules = ts.getRules(); + log.debug("Checking {} rules", rules.size()); + rules.parallelStream().forEach(r -> { + if (r.getTrigger().apply(ctx)) { + r.getAction().run(ctx); + } }); } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java index 93553cdc8..21bf0a6c4 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java @@ -21,8 +21,11 @@ import lombok.Getter; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; -import org.hyperledger.bpa.impl.rules.definitions.BaseRule; +import org.hyperledger.bpa.model.ActiveRules; +import org.hyperledger.bpa.repository.RulesRepository; +import javax.inject.Inject; +import javax.inject.Named; import javax.inject.Singleton; import java.util.ArrayList; import java.util.List; @@ -31,21 +34,34 @@ @Slf4j @Singleton +@Named("rules2") public class RulesService { - @Getter(AccessLevel.PACKAGE) - private List tasks = new ArrayList<>(); + @Inject + RulesRepository rr; - void register(@NonNull BaseRule task) { - log.debug("Adding task: {}", task); - tasks.add(task); + void register(@NonNull RulesData rule) { + log.debug("Adding rule: {}", rule); + rr.save(ActiveRules + .builder() + .trigger(rule.getTrigger()) + .action(rule.getAction()) + .build()); } - void remove(@NonNull UUID taskId) { - log.debug("Removing task with id: {}", taskId); - tasks = tasks - .stream() - .filter(t -> !t.getTaskId().equals(taskId)) - .collect(Collectors.toList()); + public List getRules() { + List result = new ArrayList<>(); + rr.findAll().forEach(active -> result.add(RulesData + .builder() + .ruleId(active.getId()) + .trigger(active.getTrigger()) + .action(active.getAction()) + .build())); + return result; + } + + void remove(@NonNull UUID ruleId) { + log.debug("Removing rule with id: {}", ruleId); + rr.deleteById(ruleId); } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesEventHandler.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesEventHandler.java new file mode 100644 index 000000000..e09321fbb --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesEventHandler.java @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rulesold; + +import com.deliveredtechnologies.rulebook.FactMap; +import com.deliveredtechnologies.rulebook.NameValueReferableMap; +import io.micronaut.context.ApplicationContext; +import lombok.extern.slf4j.Slf4j; +import org.hyperledger.aries.api.connection.ConnectionRecord; +import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; +import org.hyperledger.aries.webhook.EventHandler; +import org.hyperledger.bpa.impl.rulesold.definitions.BaseRule; +import org.hyperledger.bpa.impl.rulesold.definitions.EventContext; +import org.hyperledger.bpa.repository.PartnerRepository; + +import javax.inject.Inject; +import java.util.List; + +@Slf4j +// @Singleton +public class RulesEventHandler extends EventHandler { + + @Inject + RulesService ts; + + @Inject + PartnerRepository pr; + + @Inject + ApplicationContext appCtx; + + @Override + public void handleConnection(ConnectionRecord connection) { + pr.findByConnectionId(connection.getConnectionId()).ifPresent(p -> { + NameValueReferableMap facts = new FactMap<>(); + facts.setValue("connection", EventContext + .builder() + .partner(p) + .connRec(connection) + .ctx(appCtx) + .build()); + runAndHandleResult(facts); + }); + } + + @Override + public void handleProof(PresentationExchangeRecord presEx) { + pr.findByConnectionId(presEx.getConnectionId()).ifPresent(p -> { + NameValueReferableMap facts = new FactMap<>(); + facts.setValue("presentation", EventContext + .builder() + .partner(p) + .presEx(presEx) + .ctx(appCtx) + .build()); + runAndHandleResult(facts); + }); + } + + private void runAndHandleResult(NameValueReferableMap facts) { + List tasks = ts.getTasks(); + log.debug("Checking {} rules", tasks.size()); + tasks.parallelStream().forEach(t -> { + t.run(facts); + t.getResult().ifPresentOrElse(result -> { + log.debug("Task: {}, Result: {}", t.getTaskId(), result.getValue()); + if (result.getValue() && BaseRule.Run.ONCE.equals(t.getRun())) { + log.debug("Tasks runs: {}, scheduling for removal", t.getRun()); + ts.remove(t.getTaskId()); + } + }, () -> log.warn("Task did return a result")); + }); + } +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesService.java new file mode 100644 index 000000000..357ec1cc1 --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesService.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rulesold; + +import lombok.AccessLevel; +import lombok.Getter; +import lombok.NonNull; +import lombok.extern.slf4j.Slf4j; +import org.hyperledger.bpa.impl.rulesold.definitions.BaseRule; + +import javax.inject.Named; +import javax.inject.Singleton; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import java.util.stream.Collectors; + +@Slf4j +//@Singleton +//@Named("rules1") +public class RulesService { + + @Getter(AccessLevel.PACKAGE) + private List tasks = new ArrayList<>(); + + void register(@NonNull BaseRule task) { + log.debug("Adding task: {}", task); + tasks.add(task); + } + + void remove(@NonNull UUID taskId) { + log.debug("Removing task with id: {}", taskId); + tasks = tasks + .stream() + .filter(t -> !t.getTaskId().equals(taskId)) + .collect(Collectors.toList()); + } +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/AssertVerifiedConnection.java similarity index 70% rename from backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java rename to backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/AssertVerifiedConnection.java index 0743b85d7..eba8bd1dd 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/AssertVerifiedConnection.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/AssertVerifiedConnection.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.hyperledger.bpa.impl.rules.definitions; +package org.hyperledger.bpa.impl.rulesold.definitions; import com.deliveredtechnologies.rulebook.NameValueReferableTypeConvertibleMap; import com.deliveredtechnologies.rulebook.lang.RuleBuilder; @@ -33,16 +33,35 @@ public class AssertVerifiedConnection extends BaseRule { private final UUID proofTemplateId; + private final UUID partnerId; + // todo keep state of connection request, and proof request + + /** + * Rule that is not assigned to a partner/connection and therefore is always active + * @param proofTemplateId {@link UUID} + */ public AssertVerifiedConnection(@NonNull UUID proofTemplateId) { + super(UUID.randomUUID(), Run.MULTI); + this.proofTemplateId = proofTemplateId; + this.partnerId = null; + } + + /** + * Rule that is assigned to a partner and can be removed once it's been fulfilled. + * @param proofTemplateId {@link UUID} + * @param partnerId {@link UUID} + */ + public AssertVerifiedConnection(@NonNull UUID proofTemplateId, @NonNull UUID partnerId) { super(UUID.randomUUID(), Run.ONCE); this.proofTemplateId = proofTemplateId; + this.partnerId = partnerId; } @Override public void defineRules() { addRule(RuleBuilder.create().withFactType(EventContext.class) - .when(this::isConnection) + .when(this::shouldHandleConnection) .then((facts, result) -> { // load template // send proof request @@ -64,11 +83,18 @@ public void defineRules() { .build()); } + private boolean shouldHandleConnection(NameValueReferableTypeConvertibleMap facts) { + EventContext f = facts.getOne(); + if (this.partnerId != null) { + return f.getPartner() != null && f.getPartner().getId().equals(partnerId) && isConnection(facts); + } + return isConnection(facts); + } + private boolean isConnection(NameValueReferableTypeConvertibleMap facts) { EventContext f = facts.getOne(); return f.getConnRec() != null - && ConnectionState.REQUEST.equals(f.getConnRec().getState()) - && f.getPartner() != null; + && ConnectionState.REQUEST.equals(f.getConnRec().getState()); } private static boolean isPresentationExchange(NameValueReferableTypeConvertibleMap facts) { diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/BaseRule.java similarity index 95% rename from backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java rename to backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/BaseRule.java index 0452d1c6e..1db1621a2 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/definitions/BaseRule.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/BaseRule.java @@ -15,7 +15,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.hyperledger.bpa.impl.rules.definitions; +package org.hyperledger.bpa.impl.rulesold.definitions; import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; import lombok.Data; diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/EventContext.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/EventContext.java new file mode 100644 index 000000000..c05ce9390 --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/EventContext.java @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rulesold.definitions; + +import io.micronaut.context.ApplicationContext; +import lombok.Builder; +import lombok.Data; +import org.hyperledger.aries.api.connection.ConnectionRecord; +import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; +import org.hyperledger.bpa.model.Partner; + +@Data +@Builder +public class EventContext { + private Partner partner; + private PresentationExchangeRecord presEx; + private ConnectionRecord connRec; + private ApplicationContext ctx; +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/ActiveRules.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/ActiveRules.java new file mode 100644 index 000000000..f91991406 --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/ActiveRules.java @@ -0,0 +1,60 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.model; + +import io.micronaut.data.annotation.AutoPopulated; +import io.micronaut.data.annotation.DateCreated; +import io.micronaut.data.annotation.DateUpdated; +import io.micronaut.data.annotation.TypeDef; +import io.micronaut.data.model.DataType; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hyperledger.bpa.impl.rules.RulesData; + +import javax.persistence.Entity; +import javax.persistence.Id; +import javax.persistence.Table; +import java.time.Instant; +import java.util.UUID; + +@Data +@NoArgsConstructor +@AllArgsConstructor +@Builder +@Entity +@Table(name = "active_rules") +public class ActiveRules { + + @Id + @AutoPopulated + private UUID id; + + @DateCreated + private Instant createdAt; + + @DateUpdated + private Instant updatedAt; + + @TypeDef(type = DataType.JSON) + private RulesData.Trigger trigger; + + @TypeDef(type = DataType.JSON) + private RulesData.Action action; +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/repository/RulesRepository.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/repository/RulesRepository.java new file mode 100644 index 000000000..7f7b741f7 --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/repository/RulesRepository.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.repository; + +import io.micronaut.data.jdbc.annotation.JdbcRepository; +import io.micronaut.data.model.query.builder.sql.Dialect; +import io.micronaut.data.repository.CrudRepository; +import org.hyperledger.bpa.model.ActiveRules; + +import java.util.UUID; + +@JdbcRepository(dialect = Dialect.POSTGRES) +public interface RulesRepository extends CrudRepository { + // +} diff --git a/backend/business-partner-agent/src/main/resources/databasemigrations/V1.14__add-active-rules-table.sql b/backend/business-partner-agent/src/main/resources/databasemigrations/V1.14__add-active-rules-table.sql new file mode 100644 index 000000000..306a54ea0 --- /dev/null +++ b/backend/business-partner-agent/src/main/resources/databasemigrations/V1.14__add-active-rules-table.sql @@ -0,0 +1,7 @@ +CREATE TABLE active_rules ( + id uuid PRIMARY KEY, + created_at timestamp without time zone, + updated_at timestamp without time zone, + trigger jsonb, + action jsonb +); \ No newline at end of file diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java new file mode 100644 index 000000000..31817475f --- /dev/null +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.impl.rules; + +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import org.hyperledger.ModelBuilder; +import org.hyperledger.aries.api.connection.ConnectionRecord; +import org.hyperledger.aries.api.connection.ConnectionState; +import org.hyperledger.bpa.model.Partner; +import org.hyperledger.bpa.repository.PartnerRepository; +import org.junit.jupiter.api.Test; + +import javax.inject.Inject; + +@MicronautTest +public class RulesTest { + + @Inject + RulesService rs; + + @Inject + RulesEventHandler handler; + + @Inject + PartnerRepository pr; + + @Test + void testRunRule() { + String connectionId = "123"; + + Partner p = ModelBuilder.buildDefaultPartner().setConnectionId(connectionId); + pr.save(p); + + RulesData rd = new RulesData(new RulesData.Trigger.ConnectionTrigger(), new RulesData.Action.TagConnection()); + rs.register(rd); + + ConnectionRecord rec = new ConnectionRecord(); + rec.setConnectionId(connectionId); + rec.setState(ConnectionState.REQUEST); + + handler.handleConnection(rec); + } +} diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rulesold/RuleBookTest.java similarity index 92% rename from backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java rename to backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rulesold/RuleBookTest.java index 5a1284357..118003cf4 100644 --- a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RuleBookTest.java +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rulesold/RuleBookTest.java @@ -15,26 +15,28 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package org.hyperledger.bpa.impl.rules; +package org.hyperledger.bpa.impl.rulesold; import io.micronaut.test.extensions.junit5.annotation.MicronautTest; import org.hyperledger.ModelBuilder; import org.hyperledger.aries.api.connection.ConnectionRecord; import org.hyperledger.aries.api.connection.ConnectionState; import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; -import org.hyperledger.bpa.impl.rules.definitions.AssertVerifiedConnection; +import org.hyperledger.bpa.impl.rulesold.definitions.AssertVerifiedConnection; import org.hyperledger.bpa.model.Partner; import org.hyperledger.bpa.repository.PartnerRepository; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import javax.inject.Inject; +import javax.inject.Named; import java.util.UUID; @MicronautTest public class RuleBookTest { @Inject + @Named("rules1") RulesService ts; @Inject diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/repository/RulesRepositoryTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/repository/RulesRepositoryTest.java new file mode 100644 index 000000000..1c60e99d5 --- /dev/null +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/repository/RulesRepositoryTest.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.repository; + +import io.micronaut.test.extensions.junit5.annotation.MicronautTest; +import org.hyperledger.bpa.impl.rules.RulesData; +import org.hyperledger.bpa.model.ActiveRules; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import javax.inject.Inject; + +@MicronautTest +public class RulesRepositoryTest { + + @Inject + RulesRepository rr; + + @Test + void testSaveRule() { + ActiveRules ar = ActiveRules.builder() + .trigger(RulesData.Trigger.ConnectionTrigger.builder().tag("tag").build()) + .action(RulesData.Action.TagConnection.builder().tag("verified tag").build()) + .build(); + ActiveRules active = rr.save(ar); + Assertions.assertEquals(1, rr.count()); + + System.out.println(rr.findById(active.getId())); + } +} diff --git a/backend/pom.xml b/backend/pom.xml index 8fb8bb814..016052968 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -54,11 +54,11 @@ 2.14.1 1.18.20 - 2.5.5 - 2.4.3 + 2.5.6 + 2.4.4 2.5.0 2.4.2 - 3.10.0 + 3.11.1 6.35.0 4.2.3 1.15.3 @@ -121,7 +121,7 @@ org.flywaydb flyway-core - 7.9.1 + 7.10.0 org.testcontainers From 337c8b800fb03ba342efe609c8b2a4faa628f312 Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Thu, 17 Jun 2021 15:15:39 +0200 Subject: [PATCH 10/15] added rest controller and crud methods Signed-off-by: Philipp Etschel --- .../bpa/controller/RulesController.java | 104 ++++++++++++++++++ .../bpa/controller/api/rules/RuleRequest.java | 29 +++++ .../hyperledger/bpa/impl/rules/RulesData.java | 9 ++ .../bpa/impl/rules/RulesEventHandler.java | 3 +- .../bpa/impl/rules/RulesService.java | 43 +++++--- .../hyperledger/bpa/model/ActiveRules.java | 7 +- .../hyperledger/bpa/impl/rules/RulesTest.java | 3 +- 7 files changed, 178 insertions(+), 20 deletions(-) create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/RulesController.java create mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/rules/RuleRequest.java diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/RulesController.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/RulesController.java new file mode 100644 index 000000000..0ff968295 --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/RulesController.java @@ -0,0 +1,104 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.controller; + +import io.micronaut.http.HttpResponse; +import io.micronaut.http.annotation.*; +import io.micronaut.scheduling.TaskExecutors; +import io.micronaut.scheduling.annotation.ExecuteOn; +import io.micronaut.security.annotation.Secured; +import io.micronaut.security.rules.SecurityRule; +import io.swagger.v3.oas.annotations.tags.Tag; +import org.hyperledger.bpa.controller.api.rules.RuleRequest; +import org.hyperledger.bpa.impl.rules.RulesData; +import org.hyperledger.bpa.impl.rules.RulesService; + +import javax.inject.Inject; +import java.util.List; +import java.util.Optional; +import java.util.UUID; + +@Controller("/api/rules") +@Tag(name = "Rules") +@Secured(SecurityRule.IS_AUTHENTICATED) +@ExecuteOn(TaskExecutors.IO) +public class RulesController { + + @Inject + RulesService rules; + + /** + * Add new rule with trigger and action + * @param ruleRequest {@link RuleRequest} + * @return {@link RulesData} + */ + @Post + public HttpResponse addRule(@Body RuleRequest ruleRequest) { + return HttpResponse.ok(rules.register(ruleRequest.getTrigger(), ruleRequest.getAction())); + } + + /** + * Update rule + * @param id {@link UUID} rule id + * @param ruleRequest {@link RuleRequest} + * @return {@link RulesData} + */ + @Put("/{id}") + public HttpResponse updateRule(@PathVariable String id, @Body RuleRequest ruleRequest) { + Optional updated = rules.update( + UUID.fromString(id), ruleRequest.getTrigger(), ruleRequest.getAction()); + if (updated.isPresent()) { + return HttpResponse.ok(updated.get()); + } + return HttpResponse.notFound(); + } + + /** + * Dele rule by id + * @param id {@link UUID} rule id + * @return {@link HttpResponse} + */ + @Delete("/{id}") + public HttpResponse deleteRule(@PathVariable String id) { + rules.remove(UUID.fromString(id)); + return HttpResponse.ok(); + } + + /** + * List configured rules + * @return list of {@link RulesData} + */ + @Get + public HttpResponse> listRules() { + return HttpResponse.ok(rules.getRules()); + } + + /** + * Get configured rule by id + * @param id {@UUID} rule id + * @return {@link RulesData} + */ + @Get("/{id}") + public HttpResponse getById(@PathVariable String id) { + Optional rule = rules.getById(UUID.fromString(id)); + if (rule.isPresent()) { + return HttpResponse.ok(rule.get()); + } + return HttpResponse.notFound(); + } +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/rules/RuleRequest.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/rules/RuleRequest.java new file mode 100644 index 000000000..569cf042f --- /dev/null +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/rules/RuleRequest.java @@ -0,0 +1,29 @@ +/* + * Copyright (c) 2020-2021 - for information on the respective copyright owner + * see the NOTICE file and/or the repository at + * https://github.com/hyperledger-labs/business-partner-agent + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.hyperledger.bpa.controller.api.rules; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hyperledger.bpa.impl.rules.RulesData; + +@Data @NoArgsConstructor @AllArgsConstructor +public class RuleRequest { + private RulesData.Trigger trigger; + private RulesData.Action action; +} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java index 8dad33c85..e7f4ad139 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java @@ -24,6 +24,7 @@ import lombok.extern.slf4j.Slf4j; import org.hyperledger.aries.api.connection.ConnectionState; import org.hyperledger.aries.api.connection.ConnectionTheirRole; +import org.hyperledger.bpa.model.ActiveRules; import java.util.UUID; @@ -127,4 +128,12 @@ void run(EventContext ctx) { } } } + + public static RulesData fromActive(@NonNull ActiveRules ar) { + return RulesData.builder() + .ruleId(ar.getId()) + .trigger(ar.getTrigger()) + .action(ar.getAction()) + .build(); + } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java index 37e638d9a..73a7678d4 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java @@ -69,9 +69,10 @@ public void handleProof(PresentationExchangeRecord presEx) { public void runRule(EventContext ctx) { List rules = ts.getRules(); - log.debug("Checking {} rules", rules.size()); + log.debug("Running event against {} active rules", rules.size()); rules.parallelStream().forEach(r -> { if (r.getTrigger().apply(ctx)) { + log.debug("Run rule with id: {}", r.getRuleId()); r.getAction().run(ctx); } }); diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java index 21bf0a6c4..3e7597c2e 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java @@ -29,38 +29,55 @@ import javax.inject.Singleton; import java.util.ArrayList; import java.util.List; +import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @Slf4j @Singleton -@Named("rules2") public class RulesService { @Inject RulesRepository rr; - void register(@NonNull RulesData rule) { - log.debug("Adding rule: {}", rule); - rr.save(ActiveRules + public RulesData register(@NonNull RulesData.Trigger trigger, RulesData.Action action) { + log.debug("Add rule - trigger: {}, action: {}", trigger, action); + ActiveRules ar = rr.save(ActiveRules .builder() - .trigger(rule.getTrigger()) - .action(rule.getAction()) + .trigger(trigger) + .action(action) .build()); + return RulesData.fromActive(ar); + } + + public Optional update(@NonNull UUID id, @NonNull RulesData.Trigger trigger, RulesData.Action action) { + log.debug("Update rule - id: {}, trigger: {}, action: {}", id, trigger, action); + Optional dbRule = rr.findById(id); + if (dbRule.isPresent()) { + return Optional.of( + RulesData.fromActive( + rr.update(dbRule.get().setAction(action).setTrigger(trigger)) + ) + ); + } + return Optional.empty(); } public List getRules() { List result = new ArrayList<>(); - rr.findAll().forEach(active -> result.add(RulesData - .builder() - .ruleId(active.getId()) - .trigger(active.getTrigger()) - .action(active.getAction()) - .build())); + rr.findAll().forEach(active -> result.add(RulesData.fromActive(active))); return result; } - void remove(@NonNull UUID ruleId) { + public Optional getById(@NonNull UUID ruleId) { + Optional dbRule = rr.findById(ruleId); + if (dbRule.isPresent()) { + return Optional.of(RulesData.fromActive(dbRule.get())); + } + return Optional.empty(); + } + + public void remove(@NonNull UUID ruleId) { log.debug("Removing rule with id: {}", ruleId); rr.deleteById(ruleId); } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/ActiveRules.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/ActiveRules.java index f91991406..14e4729a2 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/ActiveRules.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/model/ActiveRules.java @@ -22,10 +22,8 @@ import io.micronaut.data.annotation.DateUpdated; import io.micronaut.data.annotation.TypeDef; import io.micronaut.data.model.DataType; -import lombok.AllArgsConstructor; -import lombok.Builder; -import lombok.Data; -import lombok.NoArgsConstructor; +import lombok.*; +import lombok.experimental.Accessors; import org.hyperledger.bpa.impl.rules.RulesData; import javax.persistence.Entity; @@ -40,6 +38,7 @@ @Builder @Entity @Table(name = "active_rules") +@Accessors(chain = true) public class ActiveRules { @Id diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java index 31817475f..436990e30 100644 --- a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java @@ -46,8 +46,7 @@ void testRunRule() { Partner p = ModelBuilder.buildDefaultPartner().setConnectionId(connectionId); pr.save(p); - RulesData rd = new RulesData(new RulesData.Trigger.ConnectionTrigger(), new RulesData.Action.TagConnection()); - rs.register(rd); + rs.register(new RulesData.Trigger.ConnectionTrigger(), new RulesData.Action.TagConnection()); ConnectionRecord rec = new ConnectionRecord(); rec.setConnectionId(connectionId); From 03df18252f129fe1445d85aa10427bcf200409fc Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Thu, 17 Jun 2021 16:11:33 +0200 Subject: [PATCH 11/15] cleaning up Signed-off-by: Philipp Etschel --- backend/README.md | 5 +- .../controller/AriesWebhookController.java | 8 +- .../bpa/controller/RulesController.java | 17 ++- .../bpa/controller/api/rules/RuleRequest.java | 4 +- .../hyperledger/bpa/impl/rules/RulesData.java | 31 ++++-- .../bpa/impl/rules/RulesEventHandler.java | 33 +++--- .../bpa/impl/rules/RulesService.java | 32 ++---- .../bpa/impl/rulesold/RulesEventHandler.java | 89 --------------- .../bpa/impl/rulesold/RulesService.java | 53 --------- .../definitions/AssertVerifiedConnection.java | 105 ------------------ .../impl/rulesold/definitions/BaseRule.java | 43 ------- .../rulesold/definitions/EventContext.java | 34 ------ .../{RulesTest.java => RunRulesTest.java} | 4 +- .../bpa/impl/rulesold/RuleBookTest.java | 70 ------------ .../bpa/repository/RulesRepositoryTest.java | 8 +- 15 files changed, 74 insertions(+), 462 deletions(-) delete mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesEventHandler.java delete mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesService.java delete mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/AssertVerifiedConnection.java delete mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/BaseRule.java delete mode 100644 backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/EventContext.java rename backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/{RulesTest.java => RunRulesTest.java} (93%) delete mode 100644 backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rulesold/RuleBookTest.java diff --git a/backend/README.md b/backend/README.md index 11d0fa8c8..8ca4b7103 100644 --- a/backend/README.md +++ b/backend/README.md @@ -45,7 +45,7 @@ Depending on the docker version the .env file either needs to reside in the root 3. Start dependent services ```s # e.g. run from the root directory -docker-compose -f scripts/docker-compose.yml up aca-py +docker-compose -f scripts/docker-compose.yml up postgres aca-py ``` 4. Set VM Options @@ -56,9 +56,10 @@ IntelliJ: Run/Edit Configurations This assumes you kept the default usernames and passwords from the .env example. ``` --Dmicronaut.environments=dev +-Dmicronaut.security.enabled=false -Dbpa.host= -Dbpa.acapy.endpoint= +-Dmicronaut.config.files=classpath:application.yml,classpath:schemas.yml ``` Depending on your set up, the values for `BPA_HOST` and `ACAPY_ENDPOINT` are either set in the .env file, or the output of the start-with-tunnels.sh script. diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/AriesWebhookController.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/AriesWebhookController.java index b469ae04e..024be72e3 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/AriesWebhookController.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/AriesWebhookController.java @@ -48,11 +48,11 @@ public class AriesWebhookController { @Inject @Named("aries") - EventHandler coreHandler; + EventHandler ariesEventHandler; @Inject @Named("rules") - EventHandler rulesHandler; + EventHandler rulesEventHandler; @Post(WEBHOOK_CONTROLLER_PATH + "/{eventType}") public void logEvent( @@ -61,7 +61,7 @@ public void logEvent( log.info("Webhook received, type: {}", eventType); - coreHandler.handleEvent(eventType, eventBody); - rulesHandler.handleEvent(eventType, eventBody); + ariesEventHandler.handleEvent(eventType, eventBody); + rulesEventHandler.handleEvent(eventType, eventBody); // rules always run after } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/RulesController.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/RulesController.java index 0ff968295..c42483dc8 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/RulesController.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/RulesController.java @@ -44,17 +44,19 @@ public class RulesController { /** * Add new rule with trigger and action + * * @param ruleRequest {@link RuleRequest} * @return {@link RulesData} */ @Post public HttpResponse addRule(@Body RuleRequest ruleRequest) { - return HttpResponse.ok(rules.register(ruleRequest.getTrigger(), ruleRequest.getAction())); + return HttpResponse.ok(rules.add(ruleRequest.getTrigger(), ruleRequest.getAction())); } /** * Update rule - * @param id {@link UUID} rule id + * + * @param id {@link UUID} rule id * @param ruleRequest {@link RuleRequest} * @return {@link RulesData} */ @@ -70,32 +72,35 @@ public HttpResponse updateRule(@PathVariable String id, @Body RuleReq /** * Dele rule by id + * * @param id {@link UUID} rule id * @return {@link HttpResponse} */ @Delete("/{id}") public HttpResponse deleteRule(@PathVariable String id) { - rules.remove(UUID.fromString(id)); + rules.delete(UUID.fromString(id)); return HttpResponse.ok(); } /** * List configured rules + * * @return list of {@link RulesData} */ @Get public HttpResponse> listRules() { - return HttpResponse.ok(rules.getRules()); + return HttpResponse.ok(rules.getAll()); } /** * Get configured rule by id - * @param id {@UUID} rule id + * + * @param id {@link UUID} rule id * @return {@link RulesData} */ @Get("/{id}") public HttpResponse getById(@PathVariable String id) { - Optional rule = rules.getById(UUID.fromString(id)); + Optional rule = rules.get(UUID.fromString(id)); if (rule.isPresent()) { return HttpResponse.ok(rule.get()); } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/rules/RuleRequest.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/rules/RuleRequest.java index 569cf042f..59eaf1ed9 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/rules/RuleRequest.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/rules/RuleRequest.java @@ -22,7 +22,9 @@ import lombok.NoArgsConstructor; import org.hyperledger.bpa.impl.rules.RulesData; -@Data @NoArgsConstructor @AllArgsConstructor +@Data +@NoArgsConstructor +@AllArgsConstructor public class RuleRequest { private RulesData.Trigger trigger; private RulesData.Action action; diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java index e7f4ad139..2e2816ef6 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java @@ -37,11 +37,6 @@ public class RulesData { private Trigger trigger; private Action action; - public RulesData(Trigger trigger, Action action) { - this.trigger = trigger; - this.action = action; - } - @JsonTypeInfo( use = JsonTypeInfo.Id.NAME, property = "type") @@ -61,7 +56,11 @@ public abstract static class Trigger { private String type; @JsonTypeName(Trigger.CONNECTION_TRIGGER_NAME) - @Builder @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor + @Builder + @Data + @EqualsAndHashCode(callSuper = true) + @NoArgsConstructor + @AllArgsConstructor public static class ConnectionTrigger extends Trigger { private ConnectionTheirRole role; private String tag; @@ -74,7 +73,11 @@ public boolean apply(EventContext ctx) { } @JsonTypeName(Trigger.PROOF_RECEIVED_TRIGGER_NAME) - @Builder @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor + @Builder + @Data + @EqualsAndHashCode(callSuper = true) + @NoArgsConstructor + @AllArgsConstructor public static class ProofReceivedTrigger extends Trigger { private String tag; private UUID proofTemplateId; @@ -105,7 +108,11 @@ public abstract static class Action { private String type; @JsonTypeName(Action.TAG_CONNECTION_ACTION_NAME) - @Builder @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor + @Builder + @Data + @EqualsAndHashCode(callSuper = true) + @NoArgsConstructor + @AllArgsConstructor public static class TagConnection extends Action { private String connectionId; private String tag; @@ -117,8 +124,12 @@ void run(EventContext ctx) { } @JsonTypeName(Action.SEND_PROOF_REQUEST_ACTION_NAME) - @Builder @Data @EqualsAndHashCode(callSuper = true) @NoArgsConstructor @AllArgsConstructor - public static class SendProofRequest extends Action{ + @Builder + @Data + @EqualsAndHashCode(callSuper = true) + @NoArgsConstructor + @AllArgsConstructor + public static class SendProofRequest extends Action { private String connectionId; private UUID proofTemplateId; diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java index 73a7678d4..410d3b933 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java @@ -25,6 +25,7 @@ import org.hyperledger.bpa.repository.PartnerRepository; import javax.inject.Inject; +import javax.inject.Named; import javax.inject.Singleton; import java.util.List; @@ -43,32 +44,26 @@ public class RulesEventHandler extends EventHandler { @Override public void handleConnection(ConnectionRecord connection) { - pr.findByConnectionId(connection.getConnectionId()).ifPresent(p -> { - runRule(EventContext - .builder() - .partner(p) - .connRec(connection) - .ctx(appCtx) - .build()) - ; - }); + pr.findByConnectionId(connection.getConnectionId()).ifPresent(p -> runRule(EventContext + .builder() + .partner(p) + .connRec(connection) + .ctx(appCtx) + .build())); } @Override public void handleProof(PresentationExchangeRecord presEx) { - pr.findByConnectionId(presEx.getConnectionId()).ifPresent(p -> { - runRule(EventContext - .builder() - .partner(p) - .presEx(presEx) - .ctx(appCtx) - .build()) - ; - }); + pr.findByConnectionId(presEx.getConnectionId()).ifPresent(p -> runRule(EventContext + .builder() + .partner(p) + .presEx(presEx) + .ctx(appCtx) + .build())); } public void runRule(EventContext ctx) { - List rules = ts.getRules(); + List rules = ts.getAll(); log.debug("Running event against {} active rules", rules.size()); rules.parallelStream().forEach(r -> { if (r.getTrigger().apply(ctx)) { diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java index 3e7597c2e..a509d3f9d 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesService.java @@ -17,21 +17,17 @@ */ package org.hyperledger.bpa.impl.rules; -import lombok.AccessLevel; -import lombok.Getter; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import org.hyperledger.bpa.model.ActiveRules; import org.hyperledger.bpa.repository.RulesRepository; import javax.inject.Inject; -import javax.inject.Named; import javax.inject.Singleton; import java.util.ArrayList; import java.util.List; import java.util.Optional; import java.util.UUID; -import java.util.stream.Collectors; @Slf4j @Singleton @@ -40,7 +36,7 @@ public class RulesService { @Inject RulesRepository rr; - public RulesData register(@NonNull RulesData.Trigger trigger, RulesData.Action action) { + public RulesData add(@NonNull RulesData.Trigger trigger, RulesData.Action action) { log.debug("Add rule - trigger: {}, action: {}", trigger, action); ActiveRules ar = rr.save(ActiveRules .builder() @@ -50,35 +46,27 @@ public RulesData register(@NonNull RulesData.Trigger trigger, RulesData.Action a return RulesData.fromActive(ar); } - public Optional update(@NonNull UUID id, @NonNull RulesData.Trigger trigger, RulesData.Action action) { + public Optional update( + @NonNull UUID id, @NonNull RulesData.Trigger trigger, @NonNull RulesData.Action action) { log.debug("Update rule - id: {}, trigger: {}, action: {}", id, trigger, action); Optional dbRule = rr.findById(id); - if (dbRule.isPresent()) { - return Optional.of( - RulesData.fromActive( - rr.update(dbRule.get().setAction(action).setTrigger(trigger)) - ) - ); - } - return Optional.empty(); + return dbRule.map(activeRules -> RulesData.fromActive( + rr.update(activeRules.setAction(action).setTrigger(trigger)))); } - public List getRules() { + public List getAll() { List result = new ArrayList<>(); rr.findAll().forEach(active -> result.add(RulesData.fromActive(active))); return result; } - public Optional getById(@NonNull UUID ruleId) { + public Optional get(@NonNull UUID ruleId) { Optional dbRule = rr.findById(ruleId); - if (dbRule.isPresent()) { - return Optional.of(RulesData.fromActive(dbRule.get())); - } - return Optional.empty(); + return dbRule.map(RulesData::fromActive); } - public void remove(@NonNull UUID ruleId) { - log.debug("Removing rule with id: {}", ruleId); + public void delete(@NonNull UUID ruleId) { + log.debug("Delete rule with id: {}", ruleId); rr.deleteById(ruleId); } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesEventHandler.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesEventHandler.java deleted file mode 100644 index e09321fbb..000000000 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesEventHandler.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2020-2021 - for information on the respective copyright owner - * see the NOTICE file and/or the repository at - * https://github.com/hyperledger-labs/business-partner-agent - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.hyperledger.bpa.impl.rulesold; - -import com.deliveredtechnologies.rulebook.FactMap; -import com.deliveredtechnologies.rulebook.NameValueReferableMap; -import io.micronaut.context.ApplicationContext; -import lombok.extern.slf4j.Slf4j; -import org.hyperledger.aries.api.connection.ConnectionRecord; -import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; -import org.hyperledger.aries.webhook.EventHandler; -import org.hyperledger.bpa.impl.rulesold.definitions.BaseRule; -import org.hyperledger.bpa.impl.rulesold.definitions.EventContext; -import org.hyperledger.bpa.repository.PartnerRepository; - -import javax.inject.Inject; -import java.util.List; - -@Slf4j -// @Singleton -public class RulesEventHandler extends EventHandler { - - @Inject - RulesService ts; - - @Inject - PartnerRepository pr; - - @Inject - ApplicationContext appCtx; - - @Override - public void handleConnection(ConnectionRecord connection) { - pr.findByConnectionId(connection.getConnectionId()).ifPresent(p -> { - NameValueReferableMap facts = new FactMap<>(); - facts.setValue("connection", EventContext - .builder() - .partner(p) - .connRec(connection) - .ctx(appCtx) - .build()); - runAndHandleResult(facts); - }); - } - - @Override - public void handleProof(PresentationExchangeRecord presEx) { - pr.findByConnectionId(presEx.getConnectionId()).ifPresent(p -> { - NameValueReferableMap facts = new FactMap<>(); - facts.setValue("presentation", EventContext - .builder() - .partner(p) - .presEx(presEx) - .ctx(appCtx) - .build()); - runAndHandleResult(facts); - }); - } - - private void runAndHandleResult(NameValueReferableMap facts) { - List tasks = ts.getTasks(); - log.debug("Checking {} rules", tasks.size()); - tasks.parallelStream().forEach(t -> { - t.run(facts); - t.getResult().ifPresentOrElse(result -> { - log.debug("Task: {}, Result: {}", t.getTaskId(), result.getValue()); - if (result.getValue() && BaseRule.Run.ONCE.equals(t.getRun())) { - log.debug("Tasks runs: {}, scheduling for removal", t.getRun()); - ts.remove(t.getTaskId()); - } - }, () -> log.warn("Task did return a result")); - }); - } -} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesService.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesService.java deleted file mode 100644 index 357ec1cc1..000000000 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/RulesService.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright (c) 2020-2021 - for information on the respective copyright owner - * see the NOTICE file and/or the repository at - * https://github.com/hyperledger-labs/business-partner-agent - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.hyperledger.bpa.impl.rulesold; - -import lombok.AccessLevel; -import lombok.Getter; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import org.hyperledger.bpa.impl.rulesold.definitions.BaseRule; - -import javax.inject.Named; -import javax.inject.Singleton; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; -import java.util.stream.Collectors; - -@Slf4j -//@Singleton -//@Named("rules1") -public class RulesService { - - @Getter(AccessLevel.PACKAGE) - private List tasks = new ArrayList<>(); - - void register(@NonNull BaseRule task) { - log.debug("Adding task: {}", task); - tasks.add(task); - } - - void remove(@NonNull UUID taskId) { - log.debug("Removing task with id: {}", taskId); - tasks = tasks - .stream() - .filter(t -> !t.getTaskId().equals(taskId)) - .collect(Collectors.toList()); - } -} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/AssertVerifiedConnection.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/AssertVerifiedConnection.java deleted file mode 100644 index eba8bd1dd..000000000 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/AssertVerifiedConnection.java +++ /dev/null @@ -1,105 +0,0 @@ -/* - * Copyright (c) 2020-2021 - for information on the respective copyright owner - * see the NOTICE file and/or the repository at - * https://github.com/hyperledger-labs/business-partner-agent - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.hyperledger.bpa.impl.rulesold.definitions; - -import com.deliveredtechnologies.rulebook.NameValueReferableTypeConvertibleMap; -import com.deliveredtechnologies.rulebook.lang.RuleBuilder; -import lombok.Data; -import lombok.EqualsAndHashCode; -import lombok.NonNull; -import lombok.extern.slf4j.Slf4j; -import org.hyperledger.aries.api.connection.ConnectionState; - -import java.util.UUID; - -@Slf4j -@Data -@EqualsAndHashCode(callSuper = true) -public class AssertVerifiedConnection extends BaseRule { - - private final UUID proofTemplateId; - private final UUID partnerId; - - // todo keep state of connection request, and proof request - - /** - * Rule that is not assigned to a partner/connection and therefore is always active - * @param proofTemplateId {@link UUID} - */ - public AssertVerifiedConnection(@NonNull UUID proofTemplateId) { - super(UUID.randomUUID(), Run.MULTI); - this.proofTemplateId = proofTemplateId; - this.partnerId = null; - } - - /** - * Rule that is assigned to a partner and can be removed once it's been fulfilled. - * @param proofTemplateId {@link UUID} - * @param partnerId {@link UUID} - */ - public AssertVerifiedConnection(@NonNull UUID proofTemplateId, @NonNull UUID partnerId) { - super(UUID.randomUUID(), Run.ONCE); - this.proofTemplateId = proofTemplateId; - this.partnerId = partnerId; - } - - @Override - public void defineRules() { - addRule(RuleBuilder.create().withFactType(EventContext.class) - .when(this::shouldHandleConnection) - .then((facts, result) -> { - // load template - // send proof request - log.debug("Is connection"); - result.setValue(Boolean.FALSE); - }) - .stop() - .build()); - addRule(RuleBuilder.create().withFactType(EventContext.class) - .when(AssertVerifiedConnection::isPresentationExchange) - .then((facts, result) -> { - // check valid - // set label - log.debug("Is presentation"); - result.reset(); - result.setValue(Boolean.TRUE); - }) - .stop() - .build()); - } - - private boolean shouldHandleConnection(NameValueReferableTypeConvertibleMap facts) { - EventContext f = facts.getOne(); - if (this.partnerId != null) { - return f.getPartner() != null && f.getPartner().getId().equals(partnerId) && isConnection(facts); - } - return isConnection(facts); - } - - private boolean isConnection(NameValueReferableTypeConvertibleMap facts) { - EventContext f = facts.getOne(); - return f.getConnRec() != null - && ConnectionState.REQUEST.equals(f.getConnRec().getState()); - } - - private static boolean isPresentationExchange(NameValueReferableTypeConvertibleMap facts) { - EventContext f = facts.getOne(); - return f.getPresEx() != null; - } - -} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/BaseRule.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/BaseRule.java deleted file mode 100644 index 1db1621a2..000000000 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/BaseRule.java +++ /dev/null @@ -1,43 +0,0 @@ -/* - * Copyright (c) 2020-2021 - for information on the respective copyright owner - * see the NOTICE file and/or the repository at - * https://github.com/hyperledger-labs/business-partner-agent - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.hyperledger.bpa.impl.rulesold.definitions; - -import com.deliveredtechnologies.rulebook.model.rulechain.cor.CoRRuleBook; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.UUID; - -@Data -@NoArgsConstructor -public abstract class BaseRule extends CoRRuleBook { - - private UUID taskId; - private Run run; - - public BaseRule(UUID taskId, Run run) { - this.taskId = taskId; - this.run = run; - super.setDefaultResult(Boolean.FALSE); - } - - public enum Run { - ONCE, - MULTI - } -} diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/EventContext.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/EventContext.java deleted file mode 100644 index c05ce9390..000000000 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rulesold/definitions/EventContext.java +++ /dev/null @@ -1,34 +0,0 @@ -/* - * Copyright (c) 2020-2021 - for information on the respective copyright owner - * see the NOTICE file and/or the repository at - * https://github.com/hyperledger-labs/business-partner-agent - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.hyperledger.bpa.impl.rulesold.definitions; - -import io.micronaut.context.ApplicationContext; -import lombok.Builder; -import lombok.Data; -import org.hyperledger.aries.api.connection.ConnectionRecord; -import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; -import org.hyperledger.bpa.model.Partner; - -@Data -@Builder -public class EventContext { - private Partner partner; - private PresentationExchangeRecord presEx; - private ConnectionRecord connRec; - private ApplicationContext ctx; -} diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RunRulesTest.java similarity index 93% rename from backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java rename to backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RunRulesTest.java index 436990e30..6d28a613b 100644 --- a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RulesTest.java +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rules/RunRulesTest.java @@ -28,7 +28,7 @@ import javax.inject.Inject; @MicronautTest -public class RulesTest { +public class RunRulesTest { @Inject RulesService rs; @@ -46,7 +46,7 @@ void testRunRule() { Partner p = ModelBuilder.buildDefaultPartner().setConnectionId(connectionId); pr.save(p); - rs.register(new RulesData.Trigger.ConnectionTrigger(), new RulesData.Action.TagConnection()); + rs.add(new RulesData.Trigger.ConnectionTrigger(), new RulesData.Action.TagConnection()); ConnectionRecord rec = new ConnectionRecord(); rec.setConnectionId(connectionId); diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rulesold/RuleBookTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rulesold/RuleBookTest.java deleted file mode 100644 index 118003cf4..000000000 --- a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/impl/rulesold/RuleBookTest.java +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (c) 2020-2021 - for information on the respective copyright owner - * see the NOTICE file and/or the repository at - * https://github.com/hyperledger-labs/business-partner-agent - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.hyperledger.bpa.impl.rulesold; - -import io.micronaut.test.extensions.junit5.annotation.MicronautTest; -import org.hyperledger.ModelBuilder; -import org.hyperledger.aries.api.connection.ConnectionRecord; -import org.hyperledger.aries.api.connection.ConnectionState; -import org.hyperledger.aries.api.present_proof.PresentationExchangeRecord; -import org.hyperledger.bpa.impl.rulesold.definitions.AssertVerifiedConnection; -import org.hyperledger.bpa.model.Partner; -import org.hyperledger.bpa.repository.PartnerRepository; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -import javax.inject.Inject; -import javax.inject.Named; -import java.util.UUID; - -@MicronautTest -public class RuleBookTest { - - @Inject - @Named("rules1") - RulesService ts; - - @Inject - RulesEventHandler eo; - - @Inject - PartnerRepository pr; - - @Test - void testSimpleRule() { - String connectionId = "123"; - - Partner p = ModelBuilder.buildDefaultPartner().setConnectionId(connectionId); - p = pr.save(p); - - AssertVerifiedConnection rule = new AssertVerifiedConnection(UUID.randomUUID()); - ts.register(rule); - Assertions.assertTrue(ts.getTasks().size() > 0); - - ConnectionRecord rec = new ConnectionRecord(); - rec.setConnectionId(connectionId); - rec.setState(ConnectionState.REQUEST); - eo.handleConnection(rec); - - PresentationExchangeRecord ex = new PresentationExchangeRecord(); - ex.setConnectionId(connectionId); - eo.handleProof(ex); - - Assertions.assertFalse(ts.getTasks().size() > 0); - } -} diff --git a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/repository/RulesRepositoryTest.java b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/repository/RulesRepositoryTest.java index 1c60e99d5..edfddb4b3 100644 --- a/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/repository/RulesRepositoryTest.java +++ b/backend/business-partner-agent/src/test/java/org/hyperledger/bpa/repository/RulesRepositoryTest.java @@ -24,6 +24,7 @@ import org.junit.jupiter.api.Test; import javax.inject.Inject; +import java.util.Optional; @MicronautTest public class RulesRepositoryTest { @@ -37,9 +38,12 @@ void testSaveRule() { .trigger(RulesData.Trigger.ConnectionTrigger.builder().tag("tag").build()) .action(RulesData.Action.TagConnection.builder().tag("verified tag").build()) .build(); - ActiveRules active = rr.save(ar); + ActiveRules saved = rr.save(ar); Assertions.assertEquals(1, rr.count()); - System.out.println(rr.findById(active.getId())); + Optional reloaded = rr.findById(saved.getId()); + Assertions.assertTrue(reloaded.isPresent()); + Assertions.assertTrue(reloaded.get().getTrigger() instanceof RulesData.Trigger.ConnectionTrigger); + Assertions.assertTrue(reloaded.get().getAction() instanceof RulesData.Action.TagConnection); } } From 9e59b53ad5285fe1044b411b1d201fd07f310bd3 Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Thu, 17 Jun 2021 16:45:46 +0200 Subject: [PATCH 12/15] pmd and apply check Signed-off-by: Philipp Etschel --- .../java/org/hyperledger/bpa/impl/rules/RulesData.java | 8 +++++++- .../org/hyperledger/bpa/impl/rules/RulesEventHandler.java | 1 - 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java index 2e2816ef6..26edf1626 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesData.java @@ -22,6 +22,7 @@ import com.fasterxml.jackson.annotation.JsonTypeName; import lombok.*; import lombok.extern.slf4j.Slf4j; +import org.hyperledger.aries.api.connection.ConnectionRecord; import org.hyperledger.aries.api.connection.ConnectionState; import org.hyperledger.aries.api.connection.ConnectionTheirRole; import org.hyperledger.bpa.model.ActiveRules; @@ -68,7 +69,12 @@ public static class ConnectionTrigger extends Trigger { @Override public boolean apply(EventContext ctx) { - return ctx.getConnRec() != null && ConnectionState.REQUEST.equals(ctx.getConnRec().getState()); + ConnectionRecord connRec = ctx.getConnRec(); + boolean apply = connRec != null && ConnectionState.REQUEST.equals(connRec.getState()); + if (role != null) { + apply = apply && role.equals(connRec.getTheirRole()); + } + return apply; } } diff --git a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java index 410d3b933..7b6826bf6 100644 --- a/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java +++ b/backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/rules/RulesEventHandler.java @@ -25,7 +25,6 @@ import org.hyperledger.bpa.repository.PartnerRepository; import javax.inject.Inject; -import javax.inject.Named; import javax.inject.Singleton; import java.util.List; From 329901e8a7f172057aab6d87ce246583386d902d Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Thu, 17 Jun 2021 17:15:40 +0200 Subject: [PATCH 13/15] removed rulebook dependency Signed-off-by: Philipp Etschel --- backend/business-partner-agent/pom.xml | 22 +--------------------- 1 file changed, 1 insertion(+), 21 deletions(-) diff --git a/backend/business-partner-agent/pom.xml b/backend/business-partner-agent/pom.xml index 645230f58..2c9d235ae 100644 --- a/backend/business-partner-agent/pom.xml +++ b/backend/business-partner-agent/pom.xml @@ -157,26 +157,6 @@ spring-security-crypto 5.5.0 - - com.deliveredtechnologies - rulebook-core - 0.12 - - - - org.javassist - javassist - - - com.google.code.findbugs - annotations - - - org.reflections - reflections - - - @@ -406,7 +386,7 @@ - v14.17.0 + v14.17.1 6.14.13 From 00bcf3ab5da8814a193d6147d42e3a3f55fd8b5f Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Thu, 1 Jul 2021 17:51:36 +0200 Subject: [PATCH 14/15] renamed migration Signed-off-by: Philipp Etschel --- ...d-active-rules-table.sql => V1.16__add-active-rules-table.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename backend/business-partner-agent/src/main/resources/databasemigrations/{V1.14__add-active-rules-table.sql => V1.16__add-active-rules-table.sql} (100%) diff --git a/backend/business-partner-agent/src/main/resources/databasemigrations/V1.14__add-active-rules-table.sql b/backend/business-partner-agent/src/main/resources/databasemigrations/V1.16__add-active-rules-table.sql similarity index 100% rename from backend/business-partner-agent/src/main/resources/databasemigrations/V1.14__add-active-rules-table.sql rename to backend/business-partner-agent/src/main/resources/databasemigrations/V1.16__add-active-rules-table.sql From 2e6bcdacf85ef17cef35c9732e03d4dcfb422f08 Mon Sep 17 00:00:00 2001 From: Philipp Etschel Date: Mon, 9 Aug 2021 17:58:44 +0200 Subject: [PATCH 15/15] renamed migration Signed-off-by: Philipp Etschel --- ...d-active-rules-table.sql => V1.19__add-active-rules-table.sql} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename backend/business-partner-agent/src/main/resources/databasemigrations/{V1.16__add-active-rules-table.sql => V1.19__add-active-rules-table.sql} (100%) diff --git a/backend/business-partner-agent/src/main/resources/databasemigrations/V1.16__add-active-rules-table.sql b/backend/business-partner-agent/src/main/resources/databasemigrations/V1.19__add-active-rules-table.sql similarity index 100% rename from backend/business-partner-agent/src/main/resources/databasemigrations/V1.16__add-active-rules-table.sql rename to backend/business-partner-agent/src/main/resources/databasemigrations/V1.19__add-active-rules-table.sql