From 29409191bff873ea26a5a05a5f61d5b7a38a5eeb Mon Sep 17 00:00:00 2001 From: Ahmed Elwasefi Date: Sat, 18 May 2024 18:56:49 +0300 Subject: [PATCH] Added delete command and add command. Co-authored-by: Elshimaa Betah <79271594+ShimaaBetah@users.noreply.github.com> Co-authored-by: Ziad Othman --- .../com/workup/controller/CLIHandler.java | 6 + .../contracts/ControllerMQListener.java | 4 +- .../workup/contracts/RabbitMQListener.java | 135 +++-- .../com/workup/jobs/ControllerMQListener.java | 4 +- .../com/workup/jobs/RabbitMQListener.java | 131 +++-- .../workup/jobs/ContractsMockingListener.java | 18 +- .../workup/payments/ControllerMQListener.java | 4 +- .../com/workup/payments/RabbitMQListener.java | 195 +++++-- .../workup/users/ControllerMQListener.java | 4 +- .../com/workup/users/RabbitMQListener.java | 479 ++++++++++++++---- .../workup/users/PaymentMockingListener.java | 12 +- .../controller/UpdateCommandRequest.java | 1 + 12 files changed, 762 insertions(+), 231 deletions(-) diff --git a/controller/src/main/java/com/workup/controller/CLIHandler.java b/controller/src/main/java/com/workup/controller/CLIHandler.java index 10834a3f..e0ee7dd7 100644 --- a/controller/src/main/java/com/workup/controller/CLIHandler.java +++ b/controller/src/main/java/com/workup/controller/CLIHandler.java @@ -55,6 +55,11 @@ public String maxdb(String app, int maxDBConn) { return "Command Sent!"; } + @Command(description = "Adds a new command") + public String addCommand(String app, String commandName, String className) throws Exception { + return updateCommand(app, commandName, className); + } + @Command(description = "starts a specific app") public String start(String app) { app = app.toLowerCase(); @@ -102,6 +107,7 @@ public String updateCommand(String app, String commandName, String className) th "", UpdateCommandRequest.builder() .withCommandName(commandName) + .withClassName(className) .withByteCode(byteArray) .build()); } catch (Exception ex) { diff --git a/services/contracts/src/main/java/com/workup/contracts/ControllerMQListener.java b/services/contracts/src/main/java/com/workup/contracts/ControllerMQListener.java index 776161de..d59baecf 100644 --- a/services/contracts/src/main/java/com/workup/contracts/ControllerMQListener.java +++ b/services/contracts/src/main/java/com/workup/contracts/ControllerMQListener.java @@ -86,11 +86,11 @@ public void receive(ContinueRequest in) throws Exception { @RabbitHandler public void receive(UpdateCommandRequest in) throws Exception { try { - String className = commandMap.getCommand(in.getCommandName()).getClass().getName(); byte[] byteArray = in.getByteCode(); Class clazz = (Class) - (new MyClassLoader(this.getClass().getClassLoader()).loadClass(byteArray, className)); + (new MyClassLoader(this.getClass().getClassLoader()) + .loadClass(byteArray, in.getClassName())); commandMap.replaceCommand( in.getCommandName(), diff --git a/services/contracts/src/main/java/com/workup/contracts/RabbitMQListener.java b/services/contracts/src/main/java/com/workup/contracts/RabbitMQListener.java index 10732eed..d8a305cf 100644 --- a/services/contracts/src/main/java/com/workup/contracts/RabbitMQListener.java +++ b/services/contracts/src/main/java/com/workup/contracts/RabbitMQListener.java @@ -21,6 +21,7 @@ import com.workup.shared.commands.contracts.responses.MarkPaymentCompletedResponse; import com.workup.shared.commands.contracts.responses.ProgressMilestoneResponse; import com.workup.shared.commands.contracts.responses.ViewContractMilestonesResponse; +import com.workup.shared.enums.HttpStatusCode; import com.workup.shared.enums.ServiceQueueNames; import java.util.concurrent.CompletableFuture; import org.springframework.amqp.rabbit.annotation.RabbitHandler; @@ -39,83 +40,157 @@ public class RabbitMQListener { @Async public CompletableFuture receive(InitiateContractRequest in) throws Exception { - InitiateContractResponse response = - (InitiateContractResponse) - ((Command) commandMap.getCommand("InitiateContract")).Run(in); - return CompletableFuture.completedFuture(response); + try { + InitiateContractResponse response = + (InitiateContractResponse) + ((Command) commandMap.getCommand("InitiateContract")).Run(in); + return CompletableFuture.completedFuture(response); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + InitiateContractResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(ContractTerminationRequest in) throws Exception { - return CompletableFuture.completedFuture( - (ContractTerminationResponse) - ((Command) commandMap.getCommand("RequestContractTermination")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (ContractTerminationResponse) + ((Command) commandMap.getCommand("RequestContractTermination")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + ContractTerminationResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(HandleTerminationRequest in) throws Exception { - return CompletableFuture.completedFuture( - (HandleTerminationResponse) - ((Command) commandMap.getCommand("HandleTerminationRequest")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (HandleTerminationResponse) + ((Command) commandMap.getCommand("HandleTerminationRequest")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + HandleTerminationResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(MarkPaymentCompletedRequest in) throws Exception { - return CompletableFuture.completedFuture( - (MarkPaymentCompletedResponse) - ((Command) commandMap.getCommand("MarkMilestoneAsPaid")).Run(in)); + try { + return CompletableFuture.completedFuture( + (MarkPaymentCompletedResponse) + ((Command) commandMap.getCommand("MarkMilestoneAsPaid")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + MarkPaymentCompletedResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(ViewContractMilestonesRequest in) throws Exception { - return CompletableFuture.completedFuture( - (ViewContractMilestonesResponse) - ((Command) commandMap.getCommand("ViewContractMilestones")).Run(in)); + try { + return CompletableFuture.completedFuture( + (ViewContractMilestonesResponse) + ((Command) commandMap.getCommand("ViewContractMilestones")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + ViewContractMilestonesResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetContractRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetContractResponse) - ((Command) commandMap.getCommand("GetContract")).Run(in)); + try { + return CompletableFuture.completedFuture( + (GetContractResponse) + ((Command) commandMap.getCommand("GetContract")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetContractResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(EvaluateMilestoneRequest in) throws Exception { - return CompletableFuture.completedFuture( - (EvaluateMilestoneResponse) - ((Command) commandMap.getCommand("EvaluateMilestone")).Run(in)); + try { + return CompletableFuture.completedFuture( + (EvaluateMilestoneResponse) + ((Command) commandMap.getCommand("EvaluateMilestone")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + EvaluateMilestoneResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(ProgressMilestoneRequest in) throws Exception { - return CompletableFuture.completedFuture( - (ProgressMilestoneResponse) - ((Command) commandMap.getCommand("ProgressMilestone")).Run(in)); + try { + return CompletableFuture.completedFuture( + (ProgressMilestoneResponse) + ((Command) commandMap.getCommand("ProgressMilestone")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + ProgressMilestoneResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetPendingTerminationsRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetPendingTerminationsResponse) - ((Command) commandMap.getCommand("GetPendingTerminations")).Run(in)); + try { + return CompletableFuture.completedFuture( + (GetPendingTerminationsResponse) + ((Command) commandMap.getCommand("GetPendingTerminations")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetPendingTerminationsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } // NEW_COMMAND_BOILERPLATE diff --git a/services/jobs/src/main/java/com/workup/jobs/ControllerMQListener.java b/services/jobs/src/main/java/com/workup/jobs/ControllerMQListener.java index b546ec7a..b4ae802b 100644 --- a/services/jobs/src/main/java/com/workup/jobs/ControllerMQListener.java +++ b/services/jobs/src/main/java/com/workup/jobs/ControllerMQListener.java @@ -83,11 +83,11 @@ public void receive(ContinueRequest in) throws Exception { @RabbitHandler public void receive(UpdateCommandRequest in) throws Exception { try { - String className = commandMap.getCommand(in.getCommandName()).getClass().getName(); byte[] byteArray = in.getByteCode(); Class clazz = (Class) - (new MyClassLoader(this.getClass().getClassLoader()).loadClass(byteArray, className)); + (new MyClassLoader(this.getClass().getClassLoader()) + .loadClass(byteArray, in.getClassName())); commandMap.replaceCommand( in.getCommandName(), diff --git a/services/jobs/src/main/java/com/workup/jobs/RabbitMQListener.java b/services/jobs/src/main/java/com/workup/jobs/RabbitMQListener.java index 21d38611..fd5c8beb 100644 --- a/services/jobs/src/main/java/com/workup/jobs/RabbitMQListener.java +++ b/services/jobs/src/main/java/com/workup/jobs/RabbitMQListener.java @@ -19,6 +19,7 @@ import com.workup.shared.commands.jobs.responses.GetJobByIdResponse; import com.workup.shared.commands.jobs.responses.GetMyJobsResponse; import com.workup.shared.commands.jobs.responses.SearchJobsResponse; +import com.workup.shared.enums.HttpStatusCode; import com.workup.shared.enums.ServiceQueueNames; import java.util.concurrent.CompletableFuture; import org.springframework.amqp.rabbit.annotation.RabbitHandler; @@ -36,77 +37,141 @@ public class RabbitMQListener { @RabbitHandler @Async public CompletableFuture receive(CreateJobRequest in) throws Exception { - CreateJobResponse resp = - (CreateJobResponse) - ((Command) commandMap.getCommand("CreateJob")).Run(in); - return CompletableFuture.completedFuture(resp); + try { + CreateJobResponse resp = + (CreateJobResponse) + ((Command) commandMap.getCommand("CreateJob")).Run(in); + return CompletableFuture.completedFuture(resp); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + CreateJobResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(CreateProposalRequest in) throws Exception { - CreateProposalResponse response = - (CreateProposalResponse) - ((Command) commandMap.getCommand("CreateProposal")).Run(in); - return CompletableFuture.completedFuture(response); + try { + CreateProposalResponse response = + (CreateProposalResponse) + ((Command) commandMap.getCommand("CreateProposal")).Run(in); + return CompletableFuture.completedFuture(response); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + CreateProposalResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetJobByIdRequest request) throws Exception { - GetJobByIdResponse response = - (GetJobByIdResponse) - ((Command) commandMap.getCommand("GetJobById")).Run(request); - return CompletableFuture.completedFuture(response); + try { + GetJobByIdResponse response = + (GetJobByIdResponse) + ((Command) commandMap.getCommand("GetJobById")).Run(request); + return CompletableFuture.completedFuture(response); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetJobByIdResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(SearchJobsRequest request) throws Exception { - SearchJobsResponse response = - (SearchJobsResponse) - ((Command) commandMap.getCommand("SearchJobs")).Run(request); - return CompletableFuture.completedFuture(response); + try { + SearchJobsResponse response = + (SearchJobsResponse) + ((Command) commandMap.getCommand("SearchJobs")).Run(request); + return CompletableFuture.completedFuture(response); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + SearchJobsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetMyJobsRequest request) throws Exception { - GetMyJobsResponse response = - (GetMyJobsResponse) - ((Command) commandMap.getCommand("GetMyJobs")).Run(request); - return CompletableFuture.completedFuture(response); + try { + GetMyJobsResponse response = + (GetMyJobsResponse) + ((Command) commandMap.getCommand("GetMyJobs")).Run(request); + return CompletableFuture.completedFuture(response); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetMyJobsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(AcceptProposalRequest request) throws Exception { - AcceptProposalResponse response = - (AcceptProposalResponse) - ((Command) commandMap.getCommand("AcceptProposal")).Run(request); - return CompletableFuture.completedFuture(response); + try { + AcceptProposalResponse response = + (AcceptProposalResponse) + ((Command) commandMap.getCommand("AcceptProposal")).Run(request); + return CompletableFuture.completedFuture(response); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + AcceptProposalResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetProposalsByJobIdRequest request) throws Exception { - GetProposalsByJobIdResponse response = - (GetProposalsByJobIdResponse) - ((Command) commandMap.getCommand("GetProposalsByJobId")) - .Run(request); - return CompletableFuture.completedFuture(response); + try { + GetProposalsByJobIdResponse response = + (GetProposalsByJobIdResponse) + ((Command) commandMap.getCommand("GetProposalsByJobId")) + .Run(request); + return CompletableFuture.completedFuture(response); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetProposalsByJobIdResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetMyProposalsRequest request) throws Exception { - GetMyProposalsResponse response = - (GetMyProposalsResponse) - ((Command) commandMap.getCommand("GetMyProposals")).Run(request); - return CompletableFuture.completedFuture(response); + try { + GetMyProposalsResponse response = + (GetMyProposalsResponse) + ((Command) commandMap.getCommand("GetMyProposals")).Run(request); + return CompletableFuture.completedFuture(response); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetMyProposalsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } } diff --git a/services/jobs/src/test/java/com/workup/jobs/ContractsMockingListener.java b/services/jobs/src/test/java/com/workup/jobs/ContractsMockingListener.java index a466ec3c..28ce74bb 100644 --- a/services/jobs/src/test/java/com/workup/jobs/ContractsMockingListener.java +++ b/services/jobs/src/test/java/com/workup/jobs/ContractsMockingListener.java @@ -21,10 +21,18 @@ public class ContractsMockingListener { @Async public CompletableFuture receive(InitiateContractRequest in) throws Exception { - return CompletableFuture.completedFuture( - InitiateContractResponse.builder() - .withContractId(contractIdToBeReturned) - .withStatusCode(statusCodeToBeReturned) - .build()); + try { + return CompletableFuture.completedFuture( + InitiateContractResponse.builder() + .withContractId(contractIdToBeReturned) + .withStatusCode(statusCodeToBeReturned) + .build()); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + InitiateContractResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } } diff --git a/services/payments/src/main/java/com/workup/payments/ControllerMQListener.java b/services/payments/src/main/java/com/workup/payments/ControllerMQListener.java index eebb1f77..8877f6e4 100644 --- a/services/payments/src/main/java/com/workup/payments/ControllerMQListener.java +++ b/services/payments/src/main/java/com/workup/payments/ControllerMQListener.java @@ -85,11 +85,11 @@ public void receive(ContinueRequest in) throws Exception { @RabbitHandler public void receive(UpdateCommandRequest in) throws Exception { try { - String className = commandMap.getCommand(in.getCommandName()).getClass().getName(); byte[] byteArray = in.getByteCode(); Class clazz = (Class) - (new MyClassLoader(this.getClass().getClassLoader()).loadClass(byteArray, className)); + (new MyClassLoader(this.getClass().getClassLoader()) + .loadClass(byteArray, in.getClassName())); commandMap.replaceCommand( in.getCommandName(), diff --git a/services/payments/src/main/java/com/workup/payments/RabbitMQListener.java b/services/payments/src/main/java/com/workup/payments/RabbitMQListener.java index 742f8bbf..a130bea1 100644 --- a/services/payments/src/main/java/com/workup/payments/RabbitMQListener.java +++ b/services/payments/src/main/java/com/workup/payments/RabbitMQListener.java @@ -22,6 +22,7 @@ import com.workup.shared.commands.payments.wallettransaction.responses.GetWalletTransactionResponse; import com.workup.shared.commands.payments.wallettransaction.responses.GetWalletTransactionsResponse; import com.workup.shared.commands.payments.wallettransaction.responses.WithdrawFromWalletResponse; +import com.workup.shared.enums.HttpStatusCode; import com.workup.shared.enums.ServiceQueueNames; import java.util.concurrent.CompletableFuture; import org.springframework.amqp.rabbit.annotation.RabbitHandler; @@ -40,119 +41,225 @@ public class RabbitMQListener { @Async public CompletableFuture receive(CreatePaymentRequestRequest in) throws Exception { - return CompletableFuture.completedFuture( - (CreatePaymentRequestResponse) - ((Command) commandMap.getCommand("CreatePaymentRequest")).Run(in)); + try { + return CompletableFuture.completedFuture( + (CreatePaymentRequestResponse) + ((Command) commandMap.getCommand("CreatePaymentRequest")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + CreatePaymentRequestResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( CreateWalletTransactionRequest in) throws Exception { - return CompletableFuture.completedFuture( - (CreateWalletTransactionResponse) - ((Command) commandMap.getCommand("CreateWalletTransaction")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (CreateWalletTransactionResponse) + ((Command) commandMap.getCommand("CreateWalletTransaction")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + CreateWalletTransactionResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( GetClientPaymentRequestsRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetClientPaymentRequestsResponse) - ((Command) commandMap.getCommand("GetClientPaymentRequests")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (GetClientPaymentRequestsResponse) + ((Command) commandMap.getCommand("GetClientPaymentRequests")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetClientPaymentRequestsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetWalletTransactionRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetWalletTransactionResponse) - ((Command) commandMap.getCommand("GetWalletTransaction")).Run(in)); + try { + return CompletableFuture.completedFuture( + (GetWalletTransactionResponse) + ((Command) commandMap.getCommand("GetWalletTransaction")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetWalletTransactionResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetWalletTransactionsRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetWalletTransactionsResponse) - ((Command) commandMap.getCommand("GetWalletTransactions")).Run(in)); + try { + return CompletableFuture.completedFuture( + (GetWalletTransactionsResponse) + ((Command) commandMap.getCommand("GetWalletTransactions")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetWalletTransactionsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(WithdrawFromWalletRequest in) throws Exception { - return CompletableFuture.completedFuture( - (WithdrawFromWalletResponse) - ((Command) commandMap.getCommand("WithdrawFromWallet")).Run(in)); + try { + return CompletableFuture.completedFuture( + (WithdrawFromWalletResponse) + ((Command) commandMap.getCommand("WithdrawFromWallet")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + WithdrawFromWalletResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( GetFreelancerPaymentRequestsRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetFreelancerPaymentRequestsResponse) - ((Command) commandMap.getCommand("GetFreelancerPaymentRequests")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (GetFreelancerPaymentRequestsResponse) + ((Command) commandMap.getCommand("GetFreelancerPaymentRequests")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetFreelancerPaymentRequestsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetPaymentRequestRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetPaymentRequestResponse) - ((Command) commandMap.getCommand("GetPaymentRequest")).Run(in)); + try { + return CompletableFuture.completedFuture( + (GetPaymentRequestResponse) + ((Command) commandMap.getCommand("GetPaymentRequest")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetPaymentRequestResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(PayPaymentRequestRequest in) throws Exception { - return CompletableFuture.completedFuture( - (PayPaymentRequestResponse) - ((Command) commandMap.getCommand("PayPaymentRequest")).Run(in)); + try { + return CompletableFuture.completedFuture( + (PayPaymentRequestResponse) + ((Command) commandMap.getCommand("PayPaymentRequest")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + PayPaymentRequestResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(CreateWalletRequest in) throws Exception { - return CompletableFuture.completedFuture( - (CreateWalletResponse) - ((Command) commandMap.getCommand("CreateWallet")).Run(in)); + try { + return CompletableFuture.completedFuture( + (CreateWalletResponse) + ((Command) commandMap.getCommand("CreateWallet")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + CreateWalletResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetWalletRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetWalletResponse) - ((Command) commandMap.getCommand("GetWallet")).Run(in)); + try { + return CompletableFuture.completedFuture( + (GetWalletResponse) + ((Command) commandMap.getCommand("GetWallet")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetWalletResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( GetClientPaymentTransactionsRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetClientPaymentTransactionsResponse) - ((Command) commandMap.getCommand("GetClientPaymentTransactions")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (GetClientPaymentTransactionsResponse) + ((Command) commandMap.getCommand("GetClientPaymentTransactions")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetClientPaymentTransactionsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( GetFreelancerPaymentTransactionsRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetFreelancerPaymentTransactionsResponse) - ((Command) commandMap.getCommand("GetFreelancerPaymentTransactions")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (GetFreelancerPaymentTransactionsResponse) + ((Command) + commandMap.getCommand("GetFreelancerPaymentTransactions")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetFreelancerPaymentTransactionsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } } diff --git a/services/users/src/main/java/com/workup/users/ControllerMQListener.java b/services/users/src/main/java/com/workup/users/ControllerMQListener.java index 862e6fd7..2abacd2a 100644 --- a/services/users/src/main/java/com/workup/users/ControllerMQListener.java +++ b/services/users/src/main/java/com/workup/users/ControllerMQListener.java @@ -89,11 +89,11 @@ public void receive(ContinueRequest in) throws Exception { @RabbitHandler public void receive(UpdateCommandRequest in) throws Exception { try { - String className = commandMap.getCommand(in.getCommandName()).getClass().getName(); byte[] byteArray = in.getByteCode(); Class clazz = (Class) - (new MyClassLoader(this.getClass().getClassLoader()).loadClass(byteArray, className)); + (new MyClassLoader(this.getClass().getClassLoader()) + .loadClass(byteArray, in.getClassName())); commandMap.replaceCommand( in.getCommandName(), diff --git a/services/users/src/main/java/com/workup/users/RabbitMQListener.java b/services/users/src/main/java/com/workup/users/RabbitMQListener.java index 3f9273ed..dd13ab0f 100644 --- a/services/users/src/main/java/com/workup/users/RabbitMQListener.java +++ b/services/users/src/main/java/com/workup/users/RabbitMQListener.java @@ -4,6 +4,7 @@ import com.workup.shared.commands.CommandRequest; import com.workup.shared.commands.users.requests.*; import com.workup.shared.commands.users.responses.*; +import com.workup.shared.enums.HttpStatusCode; import com.workup.shared.enums.ServiceQueueNames; import com.workup.users.commands.*; import com.workup.users.commands.UserCommandMap; @@ -24,298 +25,558 @@ public class RabbitMQListener { @Async public CompletableFuture receive( FreelancerGetProfileBriefRequest in) throws Exception { - return CompletableFuture.completedFuture( - (FreelancerGetProfileBriefResponse) - ((Command) commandMap.getCommand("FreelancerGetProfileBrief")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (FreelancerGetProfileBriefResponse) + ((Command) commandMap.getCommand("FreelancerGetProfileBrief")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + FreelancerGetProfileBriefResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(FreelancerGetProfileRequest in) throws Exception { - return CompletableFuture.completedFuture( - (FreelancerGetProfileResponse) - ((Command) commandMap.getCommand("FreelancerGetProfile")).Run(in)); + try { + return CompletableFuture.completedFuture( + (FreelancerGetProfileResponse) + ((Command) commandMap.getCommand("FreelancerGetProfile")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + FreelancerGetProfileResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(FreelancerGetResumeRequest in) throws Exception { - return CompletableFuture.completedFuture( - (FreelancerGetResumeResponse) - ((Command) commandMap.getCommand("FreelancerGetResume")).Run(in)); + try { + return CompletableFuture.completedFuture( + (FreelancerGetResumeResponse) + ((Command) commandMap.getCommand("FreelancerGetResume")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + FreelancerGetResumeResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(FreelancerSetPhotoRequest in) throws Exception { - return CompletableFuture.completedFuture( - (FreelancerSetPhotoResponse) - ((Command) commandMap.getCommand("FreelancerSetPhoto")).Run(in)); + try { + return CompletableFuture.completedFuture( + (FreelancerSetPhotoResponse) + ((Command) commandMap.getCommand("FreelancerSetPhoto")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + FreelancerSetPhotoResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(FreelancerSetProfileRequest in) throws Exception { - return CompletableFuture.completedFuture( - (FreelancerSetProfileResponse) - ((Command) commandMap.getCommand("FreelancerSetProfile")).Run(in)); + try { + return CompletableFuture.completedFuture( + (FreelancerSetProfileResponse) + ((Command) commandMap.getCommand("FreelancerSetProfile")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + FreelancerSetProfileResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(FreelancerSetResumeRequest in) throws Exception { - return CompletableFuture.completedFuture( - (FreelancerSetResumeResponse) - ((Command) commandMap.getCommand("FreelancerSetResume")).Run(in)); + try { + return CompletableFuture.completedFuture( + (FreelancerSetResumeResponse) + ((Command) commandMap.getCommand("FreelancerSetResume")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + FreelancerSetResumeResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(FreelancerGetPhotoRequest in) throws Exception { - return CompletableFuture.completedFuture( - (FreelancerGetPhotoResponse) - ((Command) commandMap.getCommand("FreelancerGetPhoto")).Run(in)); + try { + return CompletableFuture.completedFuture( + (FreelancerGetPhotoResponse) + ((Command) commandMap.getCommand("FreelancerGetPhoto")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + FreelancerGetPhotoResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(ClientSetProfileRequest in) throws Exception { - return CompletableFuture.completedFuture( - (ClientSetProfileResponse) - ((Command) commandMap.getCommand("ClientSetProfile")).Run(in)); + try { + return CompletableFuture.completedFuture( + (ClientSetProfileResponse) + ((Command) commandMap.getCommand("ClientSetProfile")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + ClientSetProfileResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(ClientGetProfileRequest in) throws Exception { - return CompletableFuture.completedFuture( - (ClientGetProfileResponse) - ((Command) commandMap.getCommand("ClientGetProfile")).Run(in)); + try { + return CompletableFuture.completedFuture( + (ClientGetProfileResponse) + ((Command) commandMap.getCommand("ClientGetProfile")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + ClientGetProfileResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(ClientSetPhotoRequest in) throws Exception { - return CompletableFuture.completedFuture( - (ClientSetPhotoResponse) - ((Command) commandMap.getCommand("ClientSetPhoto")).Run(in)); + try { + return CompletableFuture.completedFuture( + (ClientSetPhotoResponse) + ((Command) commandMap.getCommand("ClientSetPhoto")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + ClientSetPhotoResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(ClientGetPhotoRequest in) throws Exception { - return CompletableFuture.completedFuture( - (ClientGetPhotoResponse) - ((Command) commandMap.getCommand("ClientGetPhoto")).Run(in)); + try { + return CompletableFuture.completedFuture( + (ClientGetPhotoResponse) + ((Command) commandMap.getCommand("ClientGetPhoto")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + ClientGetPhotoResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( AddFreelancerAchievementRequest in) throws Exception { - return CompletableFuture.completedFuture( - (AddFreelancerAchievementResponse) - ((Command) commandMap.getCommand("AddFreelancerAchievement")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (AddFreelancerAchievementResponse) + ((Command) commandMap.getCommand("AddFreelancerAchievement")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + AddFreelancerAchievementResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(AddFreelancerEducationRequest in) throws Exception { - return CompletableFuture.completedFuture( - (AddFreelancerEducationResponse) - ((Command) commandMap.getCommand("AddFreelancerEducation")).Run(in)); + try { + return CompletableFuture.completedFuture( + (AddFreelancerEducationResponse) + ((Command) commandMap.getCommand("AddFreelancerEducation")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + AddFreelancerEducationResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( AddFreelancerExperienceRequest in) throws Exception { - return CompletableFuture.completedFuture( - (AddFreelancerExperienceResponse) - ((Command) commandMap.getCommand("AddFreelancerExperience")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (AddFreelancerExperienceResponse) + ((Command) commandMap.getCommand("AddFreelancerExperience")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + AddFreelancerExperienceResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(AddFreelancerSkillRequest in) throws Exception { - return CompletableFuture.completedFuture( - (AddFreelancerSkillResponse) - ((Command) commandMap.getCommand("AddFreelancerSkill")).Run(in)); + try { + return CompletableFuture.completedFuture( + (AddFreelancerSkillResponse) + ((Command) commandMap.getCommand("AddFreelancerSkill")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + AddFreelancerSkillResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(AddFreelancerLanguageRequest in) throws Exception { - return CompletableFuture.completedFuture( - (AddFreelancerLanguageResponse) - ((Command) commandMap.getCommand("AddFreelancerLanguage")).Run(in)); + try { + return CompletableFuture.completedFuture( + (AddFreelancerLanguageResponse) + ((Command) commandMap.getCommand("AddFreelancerLanguage")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + AddFreelancerLanguageResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( GetFreelancerAchievementsRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetFreelancerAchievementsResponse) - ((Command) commandMap.getCommand("GetFreelancerAchievements")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (GetFreelancerAchievementsResponse) + ((Command) commandMap.getCommand("GetFreelancerAchievements")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetFreelancerAchievementsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( GetFreelancerEducationsRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetFreelancerEducationsResponse) - ((Command) commandMap.getCommand("GetFreelancerEducations")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (GetFreelancerEducationsResponse) + ((Command) commandMap.getCommand("GetFreelancerEducations")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetFreelancerEducationsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( GetFreelancerExperiencesRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetFreelancerExperiencesResponse) - ((Command) commandMap.getCommand("GetFreelancerExperiences")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (GetFreelancerExperiencesResponse) + ((Command) commandMap.getCommand("GetFreelancerExperiences")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetFreelancerExperiencesResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetFreelancerSkillsRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetFreelancerSkillsResponse) - ((Command) commandMap.getCommand("GetFreelancerSkills")).Run(in)); + try { + return CompletableFuture.completedFuture( + (GetFreelancerSkillsResponse) + ((Command) commandMap.getCommand("GetFreelancerSkills")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetFreelancerSkillsResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(GetFreelancerLanguagesRequest in) throws Exception { - return CompletableFuture.completedFuture( - (GetFreelancerLanguagesResponse) - ((Command) commandMap.getCommand("GetFreelancerLanguages")).Run(in)); + try { + return CompletableFuture.completedFuture( + (GetFreelancerLanguagesResponse) + ((Command) commandMap.getCommand("GetFreelancerLanguages")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + GetFreelancerLanguagesResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( UpdateFreelancerAchievementRequest in) throws Exception { - return CompletableFuture.completedFuture( - (UpdateFreelancerAchievementResponse) - ((Command) commandMap.getCommand("UpdateFreelancerAchievement")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (UpdateFreelancerAchievementResponse) + ((Command) commandMap.getCommand("UpdateFreelancerAchievement")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + UpdateFreelancerAchievementResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( UpdateFreelancerEducationRequest in) throws Exception { - return CompletableFuture.completedFuture( - (UpdateFreelancerEducationResponse) - ((Command) commandMap.getCommand("UpdateFreelancerEducation")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (UpdateFreelancerEducationResponse) + ((Command) commandMap.getCommand("UpdateFreelancerEducation")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + UpdateFreelancerEducationResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( UpdateFreelancerExperienceRequest in) throws Exception { - return CompletableFuture.completedFuture( - (UpdateFreelancerExperienceResponse) - ((Command) commandMap.getCommand("UpdateFreelancerExperience")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (UpdateFreelancerExperienceResponse) + ((Command) commandMap.getCommand("UpdateFreelancerExperience")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + UpdateFreelancerExperienceResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( RemoveFreelancerAchievementRequest in) throws Exception { - return CompletableFuture.completedFuture( - (RemoveFreelancerAchievementResponse) - ((Command) commandMap.getCommand("RemoveFreelancerAchievement")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (RemoveFreelancerAchievementResponse) + ((Command) commandMap.getCommand("RemoveFreelancerAchievement")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + RemoveFreelancerAchievementResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( RemoveFreelancerEducationRequest in) throws Exception { - return CompletableFuture.completedFuture( - (RemoveFreelancerEducationResponse) - ((Command) commandMap.getCommand("RemoveFreelancerEducation")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (RemoveFreelancerEducationResponse) + ((Command) commandMap.getCommand("RemoveFreelancerEducation")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + RemoveFreelancerEducationResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( RemoveFreelancerExperienceRequest in) throws Exception { - return CompletableFuture.completedFuture( - (RemoveFreelancerExperienceResponse) - ((Command) commandMap.getCommand("RemoveFreelancerExperience")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (RemoveFreelancerExperienceResponse) + ((Command) commandMap.getCommand("RemoveFreelancerExperience")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + RemoveFreelancerExperienceResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(RemoveFreelancerSkillRequest in) throws Exception { - return CompletableFuture.completedFuture( - (RemoveFreelancerSkillResponse) - ((Command) commandMap.getCommand("RemoveFreelancerSkill")).Run(in)); + try { + return CompletableFuture.completedFuture( + (RemoveFreelancerSkillResponse) + ((Command) commandMap.getCommand("RemoveFreelancerSkill")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + RemoveFreelancerSkillResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive( RemoveFreelancerLanguageRequest in) throws Exception { - return CompletableFuture.completedFuture( - (RemoveFreelancerLanguageResponse) - ((Command) commandMap.getCommand("RemoveFreelancerLanguage")) - .Run(in)); + try { + return CompletableFuture.completedFuture( + (RemoveFreelancerLanguageResponse) + ((Command) commandMap.getCommand("RemoveFreelancerLanguage")) + .Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + RemoveFreelancerLanguageResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(LoginRequest in) throws Exception { - return CompletableFuture.completedFuture( - (SignUpAndInResponse) - ((Command) commandMap.getCommand("Login")).Run(in)); + try { + return CompletableFuture.completedFuture( + (SignUpAndInResponse) + ((Command) commandMap.getCommand("Login")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + SignUpAndInResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(FreelancerRegisterRequest in) throws Exception { - return CompletableFuture.completedFuture( - (SignUpAndInResponse) - ((Command) commandMap.getCommand("FreelancerRegister")).Run(in)); + try { + return CompletableFuture.completedFuture( + (SignUpAndInResponse) + ((Command) commandMap.getCommand("FreelancerRegister")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + SignUpAndInResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } @RabbitHandler @Async public CompletableFuture receive(ClientRegisterRequest in) throws Exception { - return CompletableFuture.completedFuture( - (SignUpAndInResponse) - ((Command) commandMap.getCommand("ClientRegister")).Run(in)); + try { + return CompletableFuture.completedFuture( + (SignUpAndInResponse) + ((Command) commandMap.getCommand("ClientRegister")).Run(in)); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + SignUpAndInResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } } diff --git a/services/users/src/test/java/com/workup/users/PaymentMockingListener.java b/services/users/src/test/java/com/workup/users/PaymentMockingListener.java index ed973a87..225346cc 100644 --- a/services/users/src/test/java/com/workup/users/PaymentMockingListener.java +++ b/services/users/src/test/java/com/workup/users/PaymentMockingListener.java @@ -19,7 +19,15 @@ public class PaymentMockingListener { @RabbitHandler @Async public CompletableFuture receive(CreateWalletRequest in) throws Exception { - return CompletableFuture.completedFuture( - CreateWalletResponse.builder().withStatusCode(statusCodeToBeReturned).build()); + try { + return CompletableFuture.completedFuture( + CreateWalletResponse.builder().withStatusCode(statusCodeToBeReturned).build()); + } catch (Exception ex) { + return CompletableFuture.completedFuture( + CreateWalletResponse.builder() + .withErrorMessage("Not Implemented.") + .withStatusCode(HttpStatusCode.NOT_IMPLEMENTED) + .build()); + } } } diff --git a/shared/src/main/java/com/workup/shared/commands/controller/UpdateCommandRequest.java b/shared/src/main/java/com/workup/shared/commands/controller/UpdateCommandRequest.java index b8c01ed0..5597353e 100644 --- a/shared/src/main/java/com/workup/shared/commands/controller/UpdateCommandRequest.java +++ b/shared/src/main/java/com/workup/shared/commands/controller/UpdateCommandRequest.java @@ -10,5 +10,6 @@ @Jacksonized public class UpdateCommandRequest { String commandName; + String className; byte[] byteCode; }