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

Commit

Permalink
Merge pull request #561 from parc-jason/feature/activity-refactor
Browse files Browse the repository at this point in the history
Activity/Task - persistence and events from backend to frontend notifications.
  • Loading branch information
usingtechnology authored Aug 5, 2021
2 parents 52f1624 + c691054 commit 5f74793
Show file tree
Hide file tree
Showing 61 changed files with 1,793 additions and 668 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
*/
package org.hyperledger.bpa.config;

import lombok.NoArgsConstructor;
import lombok.Getter;
import org.hyperledger.aries.api.connection.ConnectionState;
import org.hyperledger.aries.api.present_proof.PresentationExchangeState;

import javax.inject.Inject;
import javax.inject.Singleton;
import java.util.ArrayList;
import java.util.List;

@Singleton
@NoArgsConstructor
@Getter
public class ActivityLogConfig {
/*
* For now, we are not sure what to do with this configuration. Will each
Expand All @@ -35,58 +36,64 @@ public class ActivityLogConfig {
* AcaPyConfig, which flags are set to auto respond...
*/

@Inject
AcaPyConfig acaPyConfig;
private static List<ConnectionState> CONNECTION_STATES_TASKS = List.of(ConnectionState.REQUEST);

public List<ConnectionState> getConnectionStatesForActivities() {
return connectionStates(ConnectionState.REQUEST, ConnectionState.INVITATION, ConnectionState.ACTIVE,
ConnectionState.RESPONSE);
}
private static List<ConnectionState> CONNECTION_STATES_COMPLETED = List.of(ConnectionState.ACTIVE,
ConnectionState.RESPONSE,
ConnectionState.COMPLETED,
ConnectionState.PING_RESPONSE,
ConnectionState.PING_NO_RESPONSE);

public List<ConnectionState> getConnectionStatesForTasks() {
if (this.isConnectionRequestTask()) {
return connectionStates(ConnectionState.REQUEST);
}
return List.of();
}
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_TASKS = List.of(PresentationExchangeState.REQUEST_RECEIVED);

public List<ConnectionState> getConnectionStatesCompleted() {
return connectionStates(ConnectionState.ACTIVE, ConnectionState.RESPONSE);
}
private static List<PresentationExchangeState> PRESENTATION_EXCHANGE_STATES_COMPLETED = List.of(PresentationExchangeState.VERIFIED,
PresentationExchangeState.PRESENTATION_ACKED);

public boolean isConnectionRequestTask() {
return !acaPyConfig.getAutoAcceptRequests();
}
private List<ConnectionState> connectionStatesForActivities;
private List<ConnectionState> connectionStatesForCompleted;
private List<ConnectionState> connectionStatesForTasks;
private List<PresentationExchangeState> presentationExchangeStatesForActivities;
private List<PresentationExchangeState> presentationExchangeStatesForCompleted;
private List<PresentationExchangeState> presentationExchangeStatesForTasks;

public List<PresentationExchangeState> getPresentationExchangeStatesForActivities() {
return presentationExchangeStates(PresentationExchangeState.REQUEST_RECEIVED,
PresentationExchangeState.REQUEST_SENT,
PresentationExchangeState.VERIFIED,
PresentationExchangeState.PRESENTATION_ACKED);
}
private AcaPyConfig acaPyConfig;

@Inject
ActivityLogConfig(AcaPyConfig acaPyConfig) {
this.acaPyConfig = acaPyConfig;
// 1. set the tasks lists first as they depend on aca py configuration
connectionStatesForTasks = this.isConnectionRequestTask() ? CONNECTION_STATES_TASKS : List.of();
presentationExchangeStatesForTasks = this.isPresentationExchangeTask() ? PRESENTATION_EXCHANGE_STATES_TASKS : List.of();

// 2. set the completed state lists
connectionStatesForCompleted = CONNECTION_STATES_COMPLETED;
presentationExchangeStatesForCompleted = PRESENTATION_EXCHANGE_STATES_COMPLETED;

public List<PresentationExchangeState> getPresentationExchangeStatesForTasks() {
if (this.isPresentationExchangeTask()) {
return presentationExchangeStates(PresentationExchangeState.REQUEST_RECEIVED);
}
return List.of();
// 3. build the activity lists based on task and completed lists
connectionStatesForActivities = this.buildConnectionStatesForActivities();
presentationExchangeStatesForActivities = this.buildPresentationExchangeStatesForActivities();
}

public List<PresentationExchangeState> getPresentationExchangeStatesCompleted() {
return presentationExchangeStates(PresentationExchangeState.VERIFIED,
PresentationExchangeState.PRESENTATION_ACKED);
private List<ConnectionState> buildConnectionStatesForActivities() {
List<ConnectionState> results = new ArrayList<>(this.getConnectionStatesForCompleted());
results.addAll(this.getConnectionStatesForTasks());
results.add(ConnectionState.INVITATION);
return List.copyOf(results);
}

public boolean isPresentationExchangeTask() {
return !acaPyConfig.getAutoRespondPresentationRequest();
private boolean isConnectionRequestTask() {
return !this.acaPyConfig.getAutoAcceptRequests();
}

private List<ConnectionState> connectionStates(ConnectionState... states) {
return List.of(states);
public List<PresentationExchangeState> buildPresentationExchangeStatesForActivities() {
List<PresentationExchangeState> results = new ArrayList<>(this.getPresentationExchangeStatesForCompleted());
results.addAll(this.getPresentationExchangeStatesForTasks());
results.add(PresentationExchangeState.REQUEST_SENT);
return List.copyOf(results);
}

private List<PresentationExchangeState> presentationExchangeStates(PresentationExchangeState... states) {
return List.of(states);
private boolean isPresentationExchangeTask() {
return !this.acaPyConfig.getAutoRespondPresentationRequest();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import io.swagger.v3.oas.annotations.tags.Tag;
import org.hyperledger.bpa.controller.api.activity.ActivityItem;
import org.hyperledger.bpa.controller.api.activity.ActivitySearchParameters;
import org.hyperledger.bpa.impl.ActivitiesManager;
import org.hyperledger.bpa.impl.ActivityManager;

import javax.inject.Inject;
import javax.validation.Valid;
Expand All @@ -41,7 +41,7 @@
public class ActivitiesController {

@Inject
ActivitiesManager activitiesManager;
ActivityManager activityManager;

/**
* List Items, if no filters return all
Expand All @@ -51,7 +51,7 @@ public class ActivitiesController {
*/
@Get
public HttpResponse<List<ActivityItem>> listActivities(@RequestBean @Valid ActivitySearchParameters parameters) {
return HttpResponse.ok(activitiesManager.getItems(parameters));
return HttpResponse.ok(activityManager.getItems(parameters));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,10 @@
*/
package org.hyperledger.bpa.controller.api;

import io.micronaut.core.annotation.Nullable;
import lombok.*;
import org.hyperledger.aries.api.message.BasicMessage;
import org.hyperledger.bpa.api.PartnerAPI;
import org.hyperledger.bpa.api.aries.AriesCredential;
import org.hyperledger.bpa.api.aries.AriesProofExchange;

/**
* Websocket events
Expand All @@ -44,81 +43,50 @@ public class WebSocketMessageBody {
@Builder
public static final class WebSocketMessage {
private WebSocketMessageType type;
private WebSocketMessageState state;
private String linkId;
private Object info;
private PartnerAPI partner;
}

public enum WebSocketMessageType {
CONNECTION_REQUEST,
CREDENTIAL,
PARTNER,
PROOF,
PROOFREQUEST,
NOTIFICATION,
MESSAGE
ON_MESSAGE_RECEIVED,
ON_CREDENTIAL_ADDED,
ON_PARTNER_REQUEST_COMPLETED,
ON_PARTNER_REQUEST_RECEIVED,
ON_PARTNER_ADDED,
ON_PARTNER_ACCEPTED,
ON_PARTNER_REMOVED,
ON_PRESENTATION_VERIFIED,
ON_PRESENTATION_PROVED,
ON_PRESENTATION_REQUEST_DECLINED,
ON_PRESENTATION_REQUEST_DELETED,
ON_PRESENTATION_REQUEST_RECEIVED,
ON_PRESENTATION_REQUEST_SENT,
TASK_ADDED,
TASK_COMPLETED
}

public enum WebSocketMessageState {
RECEIVED,
UPDATED,
SENT,
NEW,
COMPLETED
}

public static WebSocketMessageBody partnerReceived(PartnerAPI partner) {
return WebSocketMessageBody.of(WebSocketMessage
.builder()
.type(WebSocketMessageType.PARTNER)
.state(WebSocketMessageState.RECEIVED)
.linkId(partner.getId())
.info(partner)
.build());
}

public static WebSocketMessageBody credentialReceived(AriesCredential credential) {
return WebSocketMessageBody.of(WebSocketMessage
.builder()
.type(WebSocketMessageType.CREDENTIAL)
.state(WebSocketMessageState.RECEIVED)
.linkId(credential.getId().toString())
.info(credential)
.build());
public static WebSocketMessageBody message(PartnerAPI partner, BasicMessage message) {
return notificationEvent(WebSocketMessageType.ON_MESSAGE_RECEIVED,
partner.getId(),
PartnerMessage.builder()
.partnerId(partner.getId())
.messageId(message.getMessageId())
.content(message.getContent())
.build(),
partner);
}

public static WebSocketMessageBody proof(
@NonNull WebSocketMessageState state,
@NonNull WebSocketMessageType type,
@NonNull AriesProofExchange proof) {
public static WebSocketMessageBody notificationEvent(@NonNull WebSocketMessageType type,
@Nullable String linkId,
@Nullable Object info,
@Nullable PartnerAPI partner) {
return WebSocketMessageBody.of(WebSocketMessage
.builder()
.type(type)
.state(state)
.linkId(proof.getId().toString())
.info(proof)
.build());
}

public static WebSocketMessageBody notification(Object info, Boolean completed) {
return WebSocketMessageBody.of(WebSocketMessage
.builder()
.type(WebSocketMessageType.NOTIFICATION)
.state(completed ? WebSocketMessageState.COMPLETED : WebSocketMessageState.NEW)
.info(info)
.build());
}

public static WebSocketMessageBody message(PartnerAPI partner, BasicMessage message) {
return WebSocketMessageBody.of(WebSocketMessage
.builder()
.type(WebSocketMessageType.MESSAGE)
.state(WebSocketMessageState.RECEIVED)
.info(PartnerMessage.builder()
.partnerId(partner.getId())
.messageId(message.getMessageId())
.content(message.getContent())
.build())
.partner(partner)
.linkId(linkId)
.build());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,12 @@
@Builder
public class ActivityItem {

private String id;
private ActivityRole role;
private ActivityState state;
private ActivityType type;
private Long updatedAt;
private String linkId;
private PartnerAPI partner;
private Boolean task;
private Boolean completed;
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ public enum ActivityRole {
@JsonProperty("presentation_exchange_prover")
PRESENTATION_EXCHANGE_PROVER,
@JsonProperty("presentation_exchange_verifier")
PRESENTATION_EXCHANGE_VERIFIER
PRESENTATION_EXCHANGE_VERIFIER,
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ public enum ActivityState {
@JsonProperty("presentation_exchange_received")
PRESENTATION_EXCHANGE_RECEIVED,
@JsonProperty("presentation_exchange_accepted")
PRESENTATION_EXCHANGE_ACCEPTED
PRESENTATION_EXCHANGE_ACCEPTED,
@JsonProperty("presentation_exchange_declined")
PRESENTATION_EXCHANGE_DECLINED,

}

This file was deleted.

Loading

0 comments on commit 5f74793

Please sign in to comment.