Skip to content
This repository was archived by the owner on Feb 13, 2024. It is now read-only.

Commit 5f74793

Browse files
Merge pull request #561 from parc-jason/feature/activity-refactor
Activity/Task - persistence and events from backend to frontend notifications.
2 parents 52f1624 + c691054 commit 5f74793

File tree

61 files changed

+1793
-668
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+1793
-668
lines changed

backend/business-partner-agent/src/main/java/org/hyperledger/bpa/config/ActivityLogConfig.java

Lines changed: 47 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,17 @@
1717
*/
1818
package org.hyperledger.bpa.config;
1919

20-
import lombok.NoArgsConstructor;
20+
import lombok.Getter;
2121
import org.hyperledger.aries.api.connection.ConnectionState;
2222
import org.hyperledger.aries.api.present_proof.PresentationExchangeState;
2323

2424
import javax.inject.Inject;
2525
import javax.inject.Singleton;
26+
import java.util.ArrayList;
2627
import java.util.List;
2728

2829
@Singleton
29-
@NoArgsConstructor
30+
@Getter
3031
public class ActivityLogConfig {
3132
/*
3233
* For now, we are not sure what to do with this configuration. Will each
@@ -35,58 +36,64 @@ public class ActivityLogConfig {
3536
* AcaPyConfig, which flags are set to auto respond...
3637
*/
3738

38-
@Inject
39-
AcaPyConfig acaPyConfig;
39+
private static List<ConnectionState> CONNECTION_STATES_TASKS = List.of(ConnectionState.REQUEST);
4040

41-
public List<ConnectionState> getConnectionStatesForActivities() {
42-
return connectionStates(ConnectionState.REQUEST, ConnectionState.INVITATION, ConnectionState.ACTIVE,
43-
ConnectionState.RESPONSE);
44-
}
41+
private static List<ConnectionState> CONNECTION_STATES_COMPLETED = List.of(ConnectionState.ACTIVE,
42+
ConnectionState.RESPONSE,
43+
ConnectionState.COMPLETED,
44+
ConnectionState.PING_RESPONSE,
45+
ConnectionState.PING_NO_RESPONSE);
4546

46-
public List<ConnectionState> getConnectionStatesForTasks() {
47-
if (this.isConnectionRequestTask()) {
48-
return connectionStates(ConnectionState.REQUEST);
49-
}
50-
return List.of();
51-
}
47+
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_TASKS = List.of(PresentationExchangeState.REQUEST_RECEIVED);
5248

53-
public List<ConnectionState> getConnectionStatesCompleted() {
54-
return connectionStates(ConnectionState.ACTIVE, ConnectionState.RESPONSE);
55-
}
49+
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_COMPLETED = List.of(PresentationExchangeState.VERIFIED,
50+
PresentationExchangeState.PRESENTATION_ACKED);
5651

57-
public boolean isConnectionRequestTask() {
58-
return !acaPyConfig.getAutoAcceptRequests();
59-
}
52+
private List<ConnectionState> connectionStatesForActivities;
53+
private List<ConnectionState> connectionStatesForCompleted;
54+
private List<ConnectionState> connectionStatesForTasks;
55+
private List<PresentationExchangeState> presentationExchangeStatesForActivities;
56+
private List<PresentationExchangeState> presentationExchangeStatesForCompleted;
57+
private List<PresentationExchangeState> presentationExchangeStatesForTasks;
6058

61-
public List<PresentationExchangeState> getPresentationExchangeStatesForActivities() {
62-
return presentationExchangeStates(PresentationExchangeState.REQUEST_RECEIVED,
63-
PresentationExchangeState.REQUEST_SENT,
64-
PresentationExchangeState.VERIFIED,
65-
PresentationExchangeState.PRESENTATION_ACKED);
66-
}
59+
private AcaPyConfig acaPyConfig;
60+
61+
@Inject
62+
ActivityLogConfig(AcaPyConfig acaPyConfig) {
63+
this.acaPyConfig = acaPyConfig;
64+
// 1. set the tasks lists first as they depend on aca py configuration
65+
connectionStatesForTasks = this.isConnectionRequestTask() ? CONNECTION_STATES_TASKS : List.of();
66+
presentationExchangeStatesForTasks = this.isPresentationExchangeTask() ? PRESENTATION_EXCHANGE_STATES_TASKS : List.of();
67+
68+
// 2. set the completed state lists
69+
connectionStatesForCompleted = CONNECTION_STATES_COMPLETED;
70+
presentationExchangeStatesForCompleted = PRESENTATION_EXCHANGE_STATES_COMPLETED;
6771

68-
public List<PresentationExchangeState> getPresentationExchangeStatesForTasks() {
69-
if (this.isPresentationExchangeTask()) {
70-
return presentationExchangeStates(PresentationExchangeState.REQUEST_RECEIVED);
71-
}
72-
return List.of();
72+
// 3. build the activity lists based on task and completed lists
73+
connectionStatesForActivities = this.buildConnectionStatesForActivities();
74+
presentationExchangeStatesForActivities = this.buildPresentationExchangeStatesForActivities();
7375
}
7476

75-
public List<PresentationExchangeState> getPresentationExchangeStatesCompleted() {
76-
return presentationExchangeStates(PresentationExchangeState.VERIFIED,
77-
PresentationExchangeState.PRESENTATION_ACKED);
77+
private List<ConnectionState> buildConnectionStatesForActivities() {
78+
List<ConnectionState> results = new ArrayList<>(this.getConnectionStatesForCompleted());
79+
results.addAll(this.getConnectionStatesForTasks());
80+
results.add(ConnectionState.INVITATION);
81+
return List.copyOf(results);
7882
}
7983

80-
public boolean isPresentationExchangeTask() {
81-
return !acaPyConfig.getAutoRespondPresentationRequest();
84+
private boolean isConnectionRequestTask() {
85+
return !this.acaPyConfig.getAutoAcceptRequests();
8286
}
8387

84-
private List<ConnectionState> connectionStates(ConnectionState... states) {
85-
return List.of(states);
88+
public List<PresentationExchangeState> buildPresentationExchangeStatesForActivities() {
89+
List<PresentationExchangeState> results = new ArrayList<>(this.getPresentationExchangeStatesForCompleted());
90+
results.addAll(this.getPresentationExchangeStatesForTasks());
91+
results.add(PresentationExchangeState.REQUEST_SENT);
92+
return List.copyOf(results);
8693
}
8794

88-
private List<PresentationExchangeState> presentationExchangeStates(PresentationExchangeState... states) {
89-
return List.of(states);
95+
private boolean isPresentationExchangeTask() {
96+
return !this.acaPyConfig.getAutoRespondPresentationRequest();
9097
}
9198

9299
}

backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/ActivitiesController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
import io.swagger.v3.oas.annotations.tags.Tag;
2929
import org.hyperledger.bpa.controller.api.activity.ActivityItem;
3030
import org.hyperledger.bpa.controller.api.activity.ActivitySearchParameters;
31-
import org.hyperledger.bpa.impl.ActivitiesManager;
31+
import org.hyperledger.bpa.impl.ActivityManager;
3232

3333
import javax.inject.Inject;
3434
import javax.validation.Valid;
@@ -41,7 +41,7 @@
4141
public class ActivitiesController {
4242

4343
@Inject
44-
ActivitiesManager activitiesManager;
44+
ActivityManager activityManager;
4545

4646
/**
4747
* List Items, if no filters return all
@@ -51,7 +51,7 @@ public class ActivitiesController {
5151
*/
5252
@Get
5353
public HttpResponse<List<ActivityItem>> listActivities(@RequestBean @Valid ActivitySearchParameters parameters) {
54-
return HttpResponse.ok(activitiesManager.getItems(parameters));
54+
return HttpResponse.ok(activityManager.getItems(parameters));
5555
}
5656

5757
}

backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/WebSocketMessageBody.java

Lines changed: 32 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
*/
1818
package org.hyperledger.bpa.controller.api;
1919

20+
import io.micronaut.core.annotation.Nullable;
2021
import lombok.*;
2122
import org.hyperledger.aries.api.message.BasicMessage;
2223
import org.hyperledger.bpa.api.PartnerAPI;
23-
import org.hyperledger.bpa.api.aries.AriesCredential;
24-
import org.hyperledger.bpa.api.aries.AriesProofExchange;
2524

2625
/**
2726
* Websocket events
@@ -44,81 +43,50 @@ public class WebSocketMessageBody {
4443
@Builder
4544
public static final class WebSocketMessage {
4645
private WebSocketMessageType type;
47-
private WebSocketMessageState state;
4846
private String linkId;
4947
private Object info;
48+
private PartnerAPI partner;
5049
}
5150

5251
public enum WebSocketMessageType {
53-
CONNECTION_REQUEST,
54-
CREDENTIAL,
55-
PARTNER,
56-
PROOF,
57-
PROOFREQUEST,
58-
NOTIFICATION,
59-
MESSAGE
52+
ON_MESSAGE_RECEIVED,
53+
ON_CREDENTIAL_ADDED,
54+
ON_PARTNER_REQUEST_COMPLETED,
55+
ON_PARTNER_REQUEST_RECEIVED,
56+
ON_PARTNER_ADDED,
57+
ON_PARTNER_ACCEPTED,
58+
ON_PARTNER_REMOVED,
59+
ON_PRESENTATION_VERIFIED,
60+
ON_PRESENTATION_PROVED,
61+
ON_PRESENTATION_REQUEST_DECLINED,
62+
ON_PRESENTATION_REQUEST_DELETED,
63+
ON_PRESENTATION_REQUEST_RECEIVED,
64+
ON_PRESENTATION_REQUEST_SENT,
65+
TASK_ADDED,
66+
TASK_COMPLETED
6067
}
6168

62-
public enum WebSocketMessageState {
63-
RECEIVED,
64-
UPDATED,
65-
SENT,
66-
NEW,
67-
COMPLETED
68-
}
69-
70-
public static WebSocketMessageBody partnerReceived(PartnerAPI partner) {
71-
return WebSocketMessageBody.of(WebSocketMessage
72-
.builder()
73-
.type(WebSocketMessageType.PARTNER)
74-
.state(WebSocketMessageState.RECEIVED)
75-
.linkId(partner.getId())
76-
.info(partner)
77-
.build());
78-
}
79-
80-
public static WebSocketMessageBody credentialReceived(AriesCredential credential) {
81-
return WebSocketMessageBody.of(WebSocketMessage
82-
.builder()
83-
.type(WebSocketMessageType.CREDENTIAL)
84-
.state(WebSocketMessageState.RECEIVED)
85-
.linkId(credential.getId().toString())
86-
.info(credential)
87-
.build());
69+
public static WebSocketMessageBody message(PartnerAPI partner, BasicMessage message) {
70+
return notificationEvent(WebSocketMessageType.ON_MESSAGE_RECEIVED,
71+
partner.getId(),
72+
PartnerMessage.builder()
73+
.partnerId(partner.getId())
74+
.messageId(message.getMessageId())
75+
.content(message.getContent())
76+
.build(),
77+
partner);
8878
}
8979

90-
public static WebSocketMessageBody proof(
91-
@NonNull WebSocketMessageState state,
92-
@NonNull WebSocketMessageType type,
93-
@NonNull AriesProofExchange proof) {
80+
public static WebSocketMessageBody notificationEvent(@NonNull WebSocketMessageType type,
81+
@Nullable String linkId,
82+
@Nullable Object info,
83+
@Nullable PartnerAPI partner) {
9484
return WebSocketMessageBody.of(WebSocketMessage
9585
.builder()
9686
.type(type)
97-
.state(state)
98-
.linkId(proof.getId().toString())
99-
.info(proof)
100-
.build());
101-
}
102-
103-
public static WebSocketMessageBody notification(Object info, Boolean completed) {
104-
return WebSocketMessageBody.of(WebSocketMessage
105-
.builder()
106-
.type(WebSocketMessageType.NOTIFICATION)
107-
.state(completed ? WebSocketMessageState.COMPLETED : WebSocketMessageState.NEW)
10887
.info(info)
109-
.build());
110-
}
111-
112-
public static WebSocketMessageBody message(PartnerAPI partner, BasicMessage message) {
113-
return WebSocketMessageBody.of(WebSocketMessage
114-
.builder()
115-
.type(WebSocketMessageType.MESSAGE)
116-
.state(WebSocketMessageState.RECEIVED)
117-
.info(PartnerMessage.builder()
118-
.partnerId(partner.getId())
119-
.messageId(message.getMessageId())
120-
.content(message.getContent())
121-
.build())
88+
.partner(partner)
89+
.linkId(linkId)
12290
.build());
12391
}
12492

backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/activity/ActivityItem.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,12 @@
2929
@Builder
3030
public class ActivityItem {
3131

32+
private String id;
3233
private ActivityRole role;
3334
private ActivityState state;
3435
private ActivityType type;
3536
private Long updatedAt;
3637
private String linkId;
3738
private PartnerAPI partner;
38-
private Boolean task;
39+
private Boolean completed;
3940
}

backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/activity/ActivityRole.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,5 +29,5 @@ public enum ActivityRole {
2929
@JsonProperty("presentation_exchange_prover")
3030
PRESENTATION_EXCHANGE_PROVER,
3131
@JsonProperty("presentation_exchange_verifier")
32-
PRESENTATION_EXCHANGE_VERIFIER
32+
PRESENTATION_EXCHANGE_VERIFIER,
3333
}

backend/business-partner-agent/src/main/java/org/hyperledger/bpa/controller/api/activity/ActivityState.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,8 @@ public enum ActivityState {
3333
@JsonProperty("presentation_exchange_received")
3434
PRESENTATION_EXCHANGE_RECEIVED,
3535
@JsonProperty("presentation_exchange_accepted")
36-
PRESENTATION_EXCHANGE_ACCEPTED
36+
PRESENTATION_EXCHANGE_ACCEPTED,
37+
@JsonProperty("presentation_exchange_declined")
38+
PRESENTATION_EXCHANGE_DECLINED,
39+
3740
}

backend/business-partner-agent/src/main/java/org/hyperledger/bpa/impl/ActivitiesEventHandler.java

Lines changed: 0 additions & 86 deletions
This file was deleted.

0 commit comments

Comments
 (0)