Added Update flow checks and bugs fixes
This commit is contained in:
parent
e9c1139bfd
commit
f3951ae0b0
@ -11,19 +11,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import java.security.PublicKey;
|
||||
import java.util.*;
|
||||
|
||||
/*
|
||||
@BelongsToContract(ChatContract::class)
|
||||
data class ChatState(
|
||||
val id : UUID = UUID.randomUUID(),
|
||||
val chatName: String,
|
||||
val messageFrom: MemberX500Name,
|
||||
val message: String,
|
||||
override val participants: List<PublicKey>) : ContractState {
|
||||
|
||||
fun updateMessage(messageFrom: MemberX500Name, message: String) = copy(messageFrom = messageFrom, message = message)
|
||||
}
|
||||
*/
|
||||
|
||||
@CordaSerializable
|
||||
@BelongsToContract(ChatContract.class)
|
||||
public class ChatState implements ContractState {
|
||||
@ -105,7 +92,7 @@ public class ChatState implements ContractState {
|
||||
public List<PublicKey> participants;
|
||||
|
||||
public ChatState updateMessage(MemberX500Name name, String message) {
|
||||
return new ChatState(chatName, name, message, participants);
|
||||
return new ChatState(id, chatName, name, message, participants);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -36,8 +36,11 @@ public class GetChatFlow implements RPCStartableFlow {
|
||||
GetChatFlowArgs flowArgs = requestBody.getRequestBodyAs(jsonMarshallingService, GetChatFlowArgs.class);
|
||||
List<StateAndRef<ChatState>> stateAndRefs = ledgerService.findUnconsumedStatesByType(ChatState.class);
|
||||
|
||||
log.info("GetChatFlow Number of stateAndRefs = " + stateAndRefs.size());
|
||||
log.info("GetChatFlow stateAndRefs = " + stateAndRefs);
|
||||
|
||||
StateAndRef<ChatState> state = findAndExpectExactlyOne(stateAndRefs,
|
||||
stateAndRef -> stateAndRef.getState().getContractState().getId() == flowArgs.getId(),
|
||||
stateAndRef -> stateAndRef.getState().getContractState().getId().equals(flowArgs.getId()),
|
||||
"did not find an unique ChatState"
|
||||
);
|
||||
|
||||
|
@ -60,10 +60,11 @@ public class UpdateChatFlow implements RPCStartableFlow {
|
||||
try {
|
||||
UpdateChatFlowArgs flowArgs = requestBody.getRequestBodyAs(jsonMarshallingService, UpdateChatFlowArgs.class);
|
||||
|
||||
// look up state (this is very inefficient)
|
||||
// Look up state (this is very inefficient)
|
||||
// Can get the error when you forget to update the ID.
|
||||
StateAndRef<ChatState> stateAndRef = findAndExpectExactlyOne(
|
||||
ledgerService.findUnconsumedStatesByType(ChatState.class),
|
||||
sAndR -> sAndR.getState().getContractState().getId() == flowArgs.getId(),
|
||||
sAndR -> sAndR.getState().getContractState().getId().equals(flowArgs.getId()),
|
||||
"Multiple or zero Chat states with id " + flowArgs.getId() + " found"
|
||||
);
|
||||
|
||||
@ -74,15 +75,11 @@ public class UpdateChatFlow implements RPCStartableFlow {
|
||||
it -> requireNonNull(memberLookup.lookup(it), "Member not found from Key")
|
||||
).collect(Collectors.toList());
|
||||
|
||||
|
||||
// Now we want to check that there is only
|
||||
/*
|
||||
val otherMember = (members - myInfo).singleOrNull()
|
||||
?: throw Exception("Should be only one participant other than the initiator")
|
||||
|
||||
*/
|
||||
// NEED TO ADD CHECKS
|
||||
// Now we want to check that there is only one member other than ourselves in the chat.
|
||||
members.remove(myInfo);
|
||||
if(members.size() != 1) {
|
||||
throw new IllegalArgumentException("Should be only one participant other than the initiator");
|
||||
}
|
||||
MemberInfo otherMember = members.get(0);
|
||||
|
||||
// This needs to be a deep copy?
|
||||
@ -114,7 +111,7 @@ RequestBody for triggering the flow via http-rpc:
|
||||
"clientRequestId": "update-1",
|
||||
"flowClassName": "com.r3.developers.csdetemplate.utxoexample.workflows.UpdateChatFlow",
|
||||
"requestData": {
|
||||
"id":" ** chat id **",
|
||||
"id":" ** fill in id **",
|
||||
"message": "How are you today?"
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user