Skip to content

Commit

Permalink
Added delete command and add command.
Browse files Browse the repository at this point in the history
Co-authored-by: Elshimaa Betah <79271594+ShimaaBetah@users.noreply.github.com>
Co-authored-by: Ziad Othman <ziadsadek999@gmail.com>
  • Loading branch information
3 people committed May 18, 2024
1 parent 2372d42 commit 2940919
Show file tree
Hide file tree
Showing 12 changed files with 762 additions and 231 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,83 +40,157 @@ public class RabbitMQListener {
@Async
public CompletableFuture<InitiateContractResponse> receive(InitiateContractRequest in)
throws Exception {
InitiateContractResponse response =
(InitiateContractResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("InitiateContract")).Run(in);
return CompletableFuture.completedFuture(response);
try {
InitiateContractResponse response =
(InitiateContractResponse)
((Command<CommandRequest, ?>) 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<ContractTerminationResponse> receive(ContractTerminationRequest in)
throws Exception {
return CompletableFuture.completedFuture(
(ContractTerminationResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("RequestContractTermination"))
.Run(in));
try {
return CompletableFuture.completedFuture(
(ContractTerminationResponse)
((Command<CommandRequest, ?>) 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<HandleTerminationResponse> receive(HandleTerminationRequest in)
throws Exception {
return CompletableFuture.completedFuture(
(HandleTerminationResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("HandleTerminationRequest"))
.Run(in));
try {
return CompletableFuture.completedFuture(
(HandleTerminationResponse)
((Command<CommandRequest, ?>) 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<MarkPaymentCompletedResponse> receive(MarkPaymentCompletedRequest in)
throws Exception {
return CompletableFuture.completedFuture(
(MarkPaymentCompletedResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("MarkMilestoneAsPaid")).Run(in));
try {
return CompletableFuture.completedFuture(
(MarkPaymentCompletedResponse)
((Command<CommandRequest, ?>) 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<ViewContractMilestonesResponse> receive(ViewContractMilestonesRequest in)
throws Exception {
return CompletableFuture.completedFuture(
(ViewContractMilestonesResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("ViewContractMilestones")).Run(in));
try {
return CompletableFuture.completedFuture(
(ViewContractMilestonesResponse)
((Command<CommandRequest, ?>) 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<GetContractResponse> receive(GetContractRequest in) throws Exception {
return CompletableFuture.completedFuture(
(GetContractResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("GetContract")).Run(in));
try {
return CompletableFuture.completedFuture(
(GetContractResponse)
((Command<CommandRequest, ?>) 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<EvaluateMilestoneResponse> receive(EvaluateMilestoneRequest in)
throws Exception {
return CompletableFuture.completedFuture(
(EvaluateMilestoneResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("EvaluateMilestone")).Run(in));
try {
return CompletableFuture.completedFuture(
(EvaluateMilestoneResponse)
((Command<CommandRequest, ?>) 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<ProgressMilestoneResponse> receive(ProgressMilestoneRequest in)
throws Exception {
return CompletableFuture.completedFuture(
(ProgressMilestoneResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("ProgressMilestone")).Run(in));
try {
return CompletableFuture.completedFuture(
(ProgressMilestoneResponse)
((Command<CommandRequest, ?>) 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<GetPendingTerminationsResponse> receive(GetPendingTerminationsRequest in)
throws Exception {
return CompletableFuture.completedFuture(
(GetPendingTerminationsResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("GetPendingTerminations")).Run(in));
try {
return CompletableFuture.completedFuture(
(GetPendingTerminationsResponse)
((Command<CommandRequest, ?>) commandMap.getCommand("GetPendingTerminations"))
.Run(in));
} catch (Exception ex) {
return CompletableFuture.completedFuture(
GetPendingTerminationsResponse.builder()
.withErrorMessage("Not Implemented.")
.withStatusCode(HttpStatusCode.NOT_IMPLEMENTED)
.build());
}
}
// NEW_COMMAND_BOILERPLATE

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
Loading

0 comments on commit 2940919

Please sign in to comment.