This commit is contained in:
2021-11-16 19:09:38 +01:00
parent bce3619638
commit 44cc0929bd
27 changed files with 307 additions and 95 deletions

View File

@@ -31,7 +31,8 @@ public class NewTaskController {
logger.info("New task with id:" + task.getTaskID());
NewTaskCommand command = new NewTaskCommand(task.getTaskID(), task.getTaskType());
NewTaskCommand command = new NewTaskCommand(task.getTaskID(), task.getTaskType(),
task.getInputData());
boolean success = newTaskUseCase.addNewTaskToQueue(command);

View File

@@ -25,9 +25,9 @@ public class TaskCompletedController {
**/
@PostMapping(path = "/task/completed", consumes = {"application/json"})
public ResponseEntity<Void> addNewTaskTaskToTaskList(@RequestBody Task task) {
System.out.println("TEST");
TaskCompletedCommand command = new TaskCompletedCommand(task.getTaskID(),
task.getStatus(), task.getResult());
task.getStatus(), task.getOutputData());
taskCompletedUseCase.taskCompleted(command);

View File

@@ -32,26 +32,26 @@ public class PublishTaskAssignedEventAdapter implements TaskAssignedEventPort {
@Override
public void publishTaskAssignedEvent(TaskAssignedEvent event) {
String body = new JSONObject()
.put("taskId", event.taskID)
.toString();
// String body = new JSONObject()
// .put("taskId", event.taskID)
// .toString();
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(server + "/tasks/assignTask"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
// HttpClient client = HttpClient.newHttpClient();
// HttpRequest request = HttpRequest.newBuilder()
// .uri(URI.create(server + "/tasks/assignTask"))
// .header("Content-Type", "application/task+json")
// .POST(HttpRequest.BodyPublishers.ofString(body))
// .build();
try {
client.send(request, HttpResponse.BodyHandlers.ofString());
} catch (InterruptedException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
Thread.currentThread().interrupt();
} catch (IOException e) {
logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
}
// try {
// client.send(request, HttpResponse.BodyHandlers.ofString());
// } catch (InterruptedException e) {
// logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
// Thread.currentThread().interrupt();
// } catch (IOException e) {
// logger.log(Level.SEVERE, e.getLocalizedMessage(), e);
// }
}
}

View File

@@ -32,17 +32,22 @@ public class PublishTaskCompletedEventAdapter implements TaskCompletedEventPort
@Override
public void publishTaskCompleted(TaskCompletedEvent event) {
System.out.println("PublishTaskCompletedEventAdapter.publishTaskCompleted()");
System.out.print(server);
String body = new JSONObject()
.put("taskId", event.taskID)
.put("status", event.status)
.put("taskResult", event.result)
.put("outputData", event.result)
.toString();
System.out.println(event.taskID);
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(server + "/tasks/completeTask"))
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.uri(URI.create(server + "/tasks/completeTask/" + event.taskID))
.header("Content-Type", "application/task+json")
.GET()
.build();

View File

@@ -17,9 +17,13 @@ public class NewTaskCommand extends SelfValidating<NewTaskCommand> {
@NotNull
private final ExecutorType taskType;
public NewTaskCommand(String taskID, ExecutorType taskType) {
@NotNull
private final String inputData;
public NewTaskCommand(String taskID, ExecutorType taskType, String inputData) {
this.taskID = taskID;
this.taskType = taskType;
this.inputData = inputData;
this.validateSelf();
}
}

View File

@@ -34,7 +34,7 @@ public class NewTaskService implements NewTaskUseCase {
return false;
}
Task task = new Task(command.getTaskID(), command.getTaskType());
Task task = new Task(command.getTaskID(), command.getTaskType(), command.getInputData());
Roster.getInstance().addTaskToQueue(task);

View File

@@ -14,7 +14,11 @@ public class Task {
@Getter
@Setter
private String result;
private String inputData;
@Getter
@Setter
private String outputData;
@Getter
@Setter
@@ -30,6 +34,12 @@ public class Task {
this.taskType = taskType;
}
public Task(String taskID, ExecutorType taskType, String inputData) {
this.taskID = taskID;
this.taskType = taskType;
this.inputData = inputData;
}
public Task() {}
}