tidy GetChatResponse
This commit is contained in:
parent
c90af45c6b
commit
6e703bca2e
@ -1,23 +0,0 @@
|
||||
package com.r3.developers.csdetemplate.utilities;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Callable;
|
||||
import java.util.function.Predicate;
|
||||
import java.util.stream.Collectors;
|
||||
//
|
||||
//public final class CorDappHelpers {
|
||||
// public static <T> T findAndExpectExactlyOne(Collection<T> collection, Predicate<? super T> filterFn, String exceptionMsg)
|
||||
// {
|
||||
// Collection<T> results = collection.stream().filter(filterFn).collect(Collectors.toList());
|
||||
// if(results.size() != 1){
|
||||
// throw new RuntimeException(exceptionMsg);
|
||||
// }
|
||||
// return results.iterator().next();
|
||||
// }
|
||||
//
|
||||
// public static <T> T findAndExpectExactlyOne(Collection<T> collection, String exceptionMsg) {
|
||||
// return findAndExpectExactlyOne(collection, e -> true, exceptionMsg);
|
||||
// }
|
||||
//}
|
@ -1,11 +1,7 @@
|
||||
package com.r3.developers.csdetemplate.utxoexample.workflows;
|
||||
|
||||
import net.corda.v5.base.annotations.ConstructorForDeserialization;
|
||||
import net.corda.v5.base.annotations.CordaSerializable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
//@CordaSerializable
|
||||
public class ChatStateResults {
|
||||
|
||||
private UUID id;
|
||||
@ -15,7 +11,6 @@ public class ChatStateResults {
|
||||
|
||||
public ChatStateResults() {}
|
||||
|
||||
// @ConstructorForDeserialization
|
||||
public ChatStateResults(UUID id, String chatName, String messageFromName, String message) {
|
||||
this.id = id;
|
||||
this.chatName = chatName;
|
||||
@ -27,34 +22,15 @@ public class ChatStateResults {
|
||||
return id;
|
||||
}
|
||||
|
||||
// public void setId(UUID id) {
|
||||
// this.id = id;
|
||||
// }
|
||||
|
||||
public String getChatName() {
|
||||
return chatName;
|
||||
}
|
||||
|
||||
// public void setChatName(String chatName) {
|
||||
// this.chatName = chatName;
|
||||
// }
|
||||
|
||||
public String getMessageFromName() {
|
||||
return messageFromName;
|
||||
}
|
||||
|
||||
// public void setMessageFromName(String messageFromName) {
|
||||
// this.messageFromName = messageFromName;
|
||||
// }
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
// public void setMessage(String message) {
|
||||
// this.message = message;
|
||||
// }
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -15,7 +15,6 @@ import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction;
|
||||
import net.corda.v5.ledger.utxo.transaction.UtxoTransactionBuilder;
|
||||
import net.corda.v5.membership.MemberInfo;
|
||||
import net.corda.v5.membership.NotaryInfo;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
@ -28,7 +27,6 @@ import java.util.UUID;
|
||||
|
||||
import static java.util.Objects.*;
|
||||
|
||||
//@InitiatingFlow(protocol = "create-chat-protocol")
|
||||
public class CreateNewChatFlow implements RPCStartableFlow {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(CreateNewChatFlow.class);
|
||||
@ -51,10 +49,9 @@ public class CreateNewChatFlow implements RPCStartableFlow {
|
||||
|
||||
@Suspendable
|
||||
@Override
|
||||
// public String call(@NotNull RPCRequestData requestBody) throws IllegalArgumentException {
|
||||
public String call( RPCRequestData requestBody) {
|
||||
log.info("CreateNewChatFlow.call() called");
|
||||
|
||||
log.info("CreateNewChatFlow.call() called");
|
||||
|
||||
try {
|
||||
CreateNewChatFlowArgs flowArgs = requestBody.getRequestBodyAs(jsonMarshallingService, CreateNewChatFlowArgs.class);
|
||||
@ -74,23 +71,7 @@ public class CreateNewChatFlow implements RPCStartableFlow {
|
||||
);
|
||||
|
||||
NotaryInfo notary = notaryLookup.getNotaryServices().iterator().next();
|
||||
/*
|
||||
// Lambda have problems see https://r3-cev.atlassian.net/browse/CORE-8983
|
||||
|
||||
// Lambda here.
|
||||
Predicate<MemberInfo> myPred = memberInfo -> Objects.equals(
|
||||
memberInfo.getMemberProvidedContext().get("corda.notary.service.name"),
|
||||
notary.getName().toString()
|
||||
);
|
||||
|
||||
List<MemberInfo> lmi = memberLookup.lookup();
|
||||
MemberInfo thing = lmi.stream().filter(myPred).iterator().next();
|
||||
PublicKey notaryKey = thing.getLedgerKeys().get(0);
|
||||
|
||||
*/
|
||||
|
||||
// Quasar checkpointing has a bugs handling lambdas in flows.
|
||||
// This is being worked upon.
|
||||
PublicKey notaryKey = null;
|
||||
for(MemberInfo memberInfo: memberLookup.lookup()){
|
||||
if(Objects.equals(
|
||||
@ -105,16 +86,6 @@ public class CreateNewChatFlow implements RPCStartableFlow {
|
||||
throw new CordaRuntimeException("No notary PublicKey found");
|
||||
}
|
||||
|
||||
// This exception would never be reached because if 'notaryLookup.getNotaryServices().iterator().next()'
|
||||
// didn't return a value, it would have thrown a NoSuchElementException
|
||||
// if(notary == null) {
|
||||
// throw new NullPointerException("No notary found");
|
||||
// }
|
||||
|
||||
// log.info("notary.getName()=" + notary.getName());
|
||||
// log.info("chatState = " + chatState);
|
||||
// log.info("chatState.getParticipants().size() = " + chatState.getParticipants().size());
|
||||
|
||||
UtxoTransactionBuilder txBuilder = ledgerService.getTransactionBuilder()
|
||||
.setNotary(new Party(notary.getName(), notaryKey))
|
||||
.setTimeWindowBetween(Instant.now(), Instant.now().plusMillis(Duration.ofDays(1).toMillis()))
|
||||
@ -122,13 +93,9 @@ public class CreateNewChatFlow implements RPCStartableFlow {
|
||||
.addCommand(new ChatContract.Create())
|
||||
.addSignatories(chatState.getParticipants());
|
||||
|
||||
|
||||
// log.info("Before UtxoSignedTransaction signedTransaction = txBuilder.toSignedTransaction(myInfo.getLedgerKeys().get(0));");
|
||||
// log.info("myInfo.getLedgerKeys().size() = " + myInfo.getLedgerKeys().size());
|
||||
// log.info("myInfo.getLedgerKeys().get(0) = " + myInfo.getLedgerKeys().get(0));
|
||||
@SuppressWarnings("DEPRECATION")
|
||||
UtxoSignedTransaction signedTransaction = txBuilder.toSignedTransaction(myInfo.getLedgerKeys().get(0));
|
||||
// log.info("After UtxoSignedTransaction signedTransaction = txBuilder.toSignedTransaction(myInfo.getLedgerKeys().get(0));");
|
||||
|
||||
return flowEngine.subFlow(new FinalizeChatSubFlow(signedTransaction, otherMember.getName()));
|
||||
}
|
||||
catch (Exception e) {
|
||||
@ -138,7 +105,6 @@ public class CreateNewChatFlow implements RPCStartableFlow {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
RequestBody for triggering the flow via http-rpc:
|
||||
{
|
||||
|
@ -1,9 +1,5 @@
|
||||
package com.r3.developers.csdetemplate.utxoexample.workflows;
|
||||
|
||||
import net.corda.v5.base.annotations.ConstructorForDeserialization;
|
||||
import net.corda.v5.base.annotations.CordaSerializable;
|
||||
|
||||
//@CordaSerializable - we're not sending it down the wire so we don't need this.
|
||||
public class CreateNewChatFlowArgs{
|
||||
|
||||
// Serialisation service requires a default constructor
|
||||
@ -13,8 +9,6 @@ public class CreateNewChatFlowArgs{
|
||||
private String message;
|
||||
private String otherMember;
|
||||
|
||||
|
||||
// @ConstructorForDeserialization // don't appear to need this
|
||||
public CreateNewChatFlowArgs(String chatName, String message, String otherMember) {
|
||||
this.chatName = chatName;
|
||||
this.message = message;
|
||||
@ -25,25 +19,11 @@ public class CreateNewChatFlowArgs{
|
||||
return chatName;
|
||||
}
|
||||
|
||||
// public void setChatName(String chatName) {
|
||||
// this.chatName = chatName;
|
||||
// }
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
// public void setMessage(String message) {
|
||||
// this.message = message;
|
||||
// }
|
||||
|
||||
public String getOtherMember() {
|
||||
return otherMember;
|
||||
}
|
||||
|
||||
// public void setOtherMember(String otherMember) {
|
||||
// this.otherMember = otherMember;
|
||||
// }
|
||||
|
||||
|
||||
}
|
@ -10,16 +10,12 @@ import net.corda.v5.base.types.MemberX500Name;
|
||||
import net.corda.v5.ledger.utxo.UtxoLedgerService;
|
||||
import net.corda.v5.ledger.utxo.transaction.UtxoSignedTransaction;
|
||||
import net.corda.v5.ledger.utxo.transaction.UtxoTransactionValidator;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
//import static com.r3.developers.csdetemplate.utxoexample.workflows.ResponderValidationHelpers.checkForBannedWords;
|
||||
//import static com.r3.developers.csdetemplate.utxoexample.workflows.ResponderValidationHelpers.checkMessageFromMatchesCounterparty;
|
||||
|
||||
@InitiatedBy(protocol = "finalize-chat-protocol")
|
||||
public class FinalizeChatResponderFlow implements ResponderFlow {
|
||||
private final static Logger log = LoggerFactory.getLogger(FinalizeChatResponderFlow.class);
|
||||
@ -42,7 +38,6 @@ public class FinalizeChatResponderFlow implements ResponderFlow {
|
||||
log.info("Verified the transaction - " + ledgerTransaction.getId());
|
||||
};
|
||||
|
||||
// This is not a problem.
|
||||
UtxoSignedTransaction finalizedSignedTransaction = utxoLedgerService.receiveFinality(session, txValidator);
|
||||
log.info("Finished responder flow - " + finalizedSignedTransaction.getId());
|
||||
}
|
||||
|
@ -16,16 +16,7 @@ import java.util.List;
|
||||
@InitiatingFlow(protocol = "finalize-chat-protocol")
|
||||
public class FinalizeChatSubFlow implements SubFlow<String> {
|
||||
|
||||
// these need to be private + good practice is to declare them at the start of the class
|
||||
// java code conventions:
|
||||
/*
|
||||
* According to Code Conventions for the Java Programming Language, the parts of a class or interface declaration should appear in the following order:
|
||||
* Class (static) variables. First the public class variables, then protected, then package level (no access modifier), and then private.
|
||||
* Instance variables. First the public class variables, then protected, then package level (no access modifier), and then private.
|
||||
* Constructors
|
||||
* Methods
|
||||
* */
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(FinalizeChatSubFlow.class);
|
||||
private final UtxoSignedTransaction signedTransaction;
|
||||
private final MemberX500Name otherMember;
|
||||
|
||||
@ -34,8 +25,6 @@ public class FinalizeChatSubFlow implements SubFlow<String> {
|
||||
this.otherMember = otherMember;
|
||||
}
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(FinalizeChatSubFlow.class);
|
||||
|
||||
@CordaInject
|
||||
public UtxoLedgerService ledgerService;
|
||||
|
||||
@ -47,13 +36,12 @@ public class FinalizeChatSubFlow implements SubFlow<String> {
|
||||
public String call() {
|
||||
|
||||
log.info("FinalizeChatFlow.call() called");
|
||||
// log.info("otherMember = " + otherMember);
|
||||
|
||||
FlowSession session = flowMessaging.initiateFlow(otherMember);
|
||||
|
||||
String result;
|
||||
try {
|
||||
List<FlowSession> sessionsList = Arrays.asList(session);
|
||||
// log.info("sessionList.size()=" + sessionsList.size());
|
||||
|
||||
UtxoSignedTransaction finalizedSignedTransaction = ledgerService.finalize(
|
||||
signedTransaction,
|
||||
@ -62,31 +50,12 @@ public class FinalizeChatSubFlow implements SubFlow<String> {
|
||||
|
||||
result = finalizedSignedTransaction.getId().toString();
|
||||
log.info("Success! Response: " + result);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.warn("Finality failed", e);
|
||||
result = "Finality failed, " + e.getMessage();
|
||||
}
|
||||
// log.info("FinalizeChatSubFlow call returns=" + retVal);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// We don't need getters and setters as the properties should be private
|
||||
|
||||
// public UtxoSignedTransaction getSignedTransaction() {
|
||||
// return signedTransaction;
|
||||
// }
|
||||
//
|
||||
// public void setSignedTransaction(UtxoSignedTransaction signedTransaction) {
|
||||
// this.signedTransaction = signedTransaction;
|
||||
// }
|
||||
//
|
||||
// public MemberX500Name getOtherMember() {
|
||||
// return otherMember;
|
||||
// }
|
||||
//
|
||||
// public void setOtherMember(MemberX500Name otherMember) {
|
||||
// this.otherMember = otherMember;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
@ -16,8 +16,6 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
//import static com.r3.developers.csdetemplate.utilities.CorDappHelpers.findAndExpectExactlyOne;
|
||||
import static java.util.Objects.*;
|
||||
import static java.util.stream.Collectors.toList;
|
||||
|
||||
@ -44,17 +42,6 @@ public class GetChatFlow implements RPCStartableFlow {
|
||||
if (chatStateAndRefsWithId.size() != 1) throw new CordaRuntimeException("Multiple or zero Chat states with id " + flowArgs.getId() + " found");
|
||||
StateAndRef<ChatState> chatStateAndRef = chatStateAndRefsWithId.get(0);
|
||||
|
||||
|
||||
// log.info("GetChatFlow Number of stateAndRefs = " + stateAndRefs.size());
|
||||
// log.info("GetChatFlow stateAndRefs = " + stateAndRefs);
|
||||
|
||||
// StateAndRef<ChatState> state = findAndExpectExactlyOne(stateAndRefs,
|
||||
// stateAndRef -> stateAndRef.getState().getContractState().getId().equals(flowArgs.getId()),
|
||||
// "did not find an unique ChatState"
|
||||
// );
|
||||
|
||||
|
||||
|
||||
return jsonMarshallingService.format(resolveMessagesFromBackchain(chatStateAndRef, flowArgs.getNumberOfRecords() ));
|
||||
}
|
||||
|
||||
@ -77,11 +64,6 @@ public class GetChatFlow implements RPCStartableFlow {
|
||||
"Transaction " + transactionId + " not found."
|
||||
);
|
||||
|
||||
// ChatState output = findAndExpectExactlyOne(
|
||||
// transaction.getOutputStates(ChatState.class),
|
||||
// "Expecting one and only one ChatState output for transaction " + transactionId
|
||||
// );
|
||||
|
||||
List<ChatState> chatStates = transaction.getOutputStates(ChatState.class);
|
||||
if (chatStates.size() != 1) throw new CordaRuntimeException(
|
||||
"Expecting one and only one ChatState output for transaction " + transactionId + ".");
|
||||
|
@ -1,18 +1,13 @@
|
||||
package com.r3.developers.csdetemplate.utxoexample.workflows;
|
||||
|
||||
import net.corda.v5.base.annotations.ConstructorForDeserialization;
|
||||
import net.corda.v5.base.annotations.CordaSerializable;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
//@CordaSerializable
|
||||
public class GetChatFlowArgs {
|
||||
|
||||
private UUID id;
|
||||
private int numberOfRecords;
|
||||
public GetChatFlowArgs() {}
|
||||
|
||||
// @ConstructorForDeserialization
|
||||
public GetChatFlowArgs(UUID id, int numberOfRecords ) {
|
||||
this.id = id;
|
||||
this.numberOfRecords = numberOfRecords;
|
||||
@ -22,18 +17,7 @@ public class GetChatFlowArgs {
|
||||
return id;
|
||||
}
|
||||
|
||||
// public void setId(UUID id) {
|
||||
// this.id = id;
|
||||
// }
|
||||
|
||||
|
||||
public int getNumberOfRecords() {
|
||||
return numberOfRecords;
|
||||
}
|
||||
|
||||
// public void setNumberOfRecords(int numberOfRecords) {
|
||||
// this.numberOfRecords = numberOfRecords;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,11 +3,14 @@ package com.r3.developers.csdetemplate.utxoexample.workflows;
|
||||
import net.corda.v5.base.annotations.ConstructorForDeserialization;
|
||||
import net.corda.v5.base.annotations.CordaSerializable;
|
||||
|
||||
@CordaSerializable
|
||||
//@CordaSerializable
|
||||
public class GetChatResponse {
|
||||
|
||||
private String messageFrom;
|
||||
private String message;
|
||||
public GetChatResponse() {}
|
||||
|
||||
@ConstructorForDeserialization
|
||||
// @ConstructorForDeserialization
|
||||
public GetChatResponse(String messageFrom, String message) {
|
||||
this.messageFrom = messageFrom;
|
||||
this.message = message;
|
||||
@ -17,18 +20,17 @@ public class GetChatResponse {
|
||||
return messageFrom;
|
||||
}
|
||||
|
||||
public void setMessageFrom(String messageFrom) {
|
||||
this.messageFrom = messageFrom;
|
||||
}
|
||||
// public void setMessageFrom(String messageFrom) {
|
||||
// this.messageFrom = messageFrom;
|
||||
// }
|
||||
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
// public void setMessage(String message) {
|
||||
// this.message = message;
|
||||
// }
|
||||
|
||||
|
||||
public String messageFrom;
|
||||
public String message;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user