commit
5de7942272
|
@ -75,6 +75,12 @@
|
|||
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||
<version>1.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>com.vaadin.external.google</groupId>
|
||||
<artifactId>android-json</artifactId>
|
||||
<version>0.0.20131108.vaadin1</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package ch.unisg.tapastasks.tasks.adapter.in.web;
|
||||
|
||||
import ch.unisg.tapastasks.tasks.adapter.in.formats.TaskJsonRepresentation;
|
||||
import ch.unisg.tapastasks.tasks.application.port.in.CompleteTaskCommand;
|
||||
import ch.unisg.tapastasks.tasks.application.port.in.CompleteTaskUseCase;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -21,7 +23,7 @@ public class CompleteTaskWebController {
|
|||
this.completeTaskUseCase = completeTaskUseCase;
|
||||
}
|
||||
|
||||
@PostMapping(path = "/tasks/completeTask", consumes = {TaskMediaType.TASK_MEDIA_TYPE})
|
||||
@PostMapping(path = "/tasks/completeTask", consumes = {TaskJsonRepresentation.MEDIA_TYPE})
|
||||
public ResponseEntity<String> completeTask (@RequestBody Task task){
|
||||
|
||||
try {
|
||||
|
@ -32,9 +34,11 @@ public class CompleteTaskWebController {
|
|||
Task updateATask = completeTaskUseCase.completeTask(command);
|
||||
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskMediaType.TASK_MEDIA_TYPE);
|
||||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskJsonRepresentation.MEDIA_TYPE);
|
||||
|
||||
return new ResponseEntity<>(TaskMediaType.serialize(updateATask), responseHeaders, HttpStatus.ACCEPTED);
|
||||
return new ResponseEntity<>(TaskJsonRepresentation.serialize(updateATask), responseHeaders, HttpStatus.ACCEPTED);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||
} catch (ConstraintViolationException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package ch.unisg.tapastasks.tasks.adapter.in.web;
|
||||
|
||||
|
||||
import ch.unisg.tapastasks.tasks.adapter.in.formats.TaskJsonRepresentation;
|
||||
import ch.unisg.tapastasks.tasks.application.port.in.DeleteTaskCommand;
|
||||
import ch.unisg.tapastasks.tasks.application.port.in.DeleteTaskUseCase;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -23,25 +25,26 @@ public class DeleteTaskWebController {
|
|||
this.deleteClassUseCase = deleteClassUseCase;
|
||||
}
|
||||
|
||||
@PostMapping(path="/tasks/deleteTask", consumes = {TaskMediaType.TASK_MEDIA_TYPE})
|
||||
@PostMapping(path="/tasks/deleteTask", consumes = {TaskJsonRepresentation.MEDIA_TYPE})
|
||||
public ResponseEntity<String> deleteTask (@RequestBody Task task){
|
||||
try {
|
||||
DeleteTaskCommand command = new DeleteTaskCommand(task.getTaskId());
|
||||
DeleteTaskCommand command = new DeleteTaskCommand(task.getTaskId(), task.getOriginalTaskUri());
|
||||
|
||||
Optional<Task> deleteATask = deleteClassUseCase.deleteTask(command);
|
||||
|
||||
// Check if the task with the given identifier exists
|
||||
if (deleteATask.isEmpty()) {
|
||||
|
||||
// If not, through a 404 Not Found status code
|
||||
throw new ResponseStatusException(HttpStatus.NOT_FOUND);
|
||||
}
|
||||
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskMediaType.TASK_MEDIA_TYPE);
|
||||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskJsonRepresentation.MEDIA_TYPE);
|
||||
|
||||
|
||||
return new ResponseEntity<>(TaskMediaType.serialize(deleteATask.get()), responseHeaders, HttpStatus.ACCEPTED);
|
||||
return new ResponseEntity<>(TaskJsonRepresentation.serialize(deleteATask.get()), responseHeaders, HttpStatus.ACCEPTED);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||
} catch (ConstraintViolationException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
|
|
|
@ -1,8 +1,10 @@
|
|||
package ch.unisg.tapastasks.tasks.adapter.in.web;
|
||||
|
||||
import ch.unisg.tapastasks.tasks.adapter.in.formats.TaskJsonRepresentation;
|
||||
import ch.unisg.tapastasks.tasks.application.port.in.TaskAssignedCommand;
|
||||
import ch.unisg.tapastasks.tasks.application.port.in.TaskAssignedUseCase;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -21,7 +23,7 @@ public class TaskAssignedWebController {
|
|||
this.taskAssignedUseCase = taskAssignedUseCase;
|
||||
}
|
||||
|
||||
@PostMapping(path="/tasks/assignTask", consumes= {TaskMediaType.TASK_MEDIA_TYPE})
|
||||
@PostMapping(path="/tasks/assignTask", consumes= {TaskJsonRepresentation.MEDIA_TYPE})
|
||||
public ResponseEntity<String> assignTask(@RequestBody Task task){
|
||||
try{
|
||||
TaskAssignedCommand command = new TaskAssignedCommand(
|
||||
|
@ -31,9 +33,11 @@ public class TaskAssignedWebController {
|
|||
Task updateATask = taskAssignedUseCase.assignTask(command);
|
||||
|
||||
HttpHeaders responseHeaders = new HttpHeaders();
|
||||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskMediaType.TASK_MEDIA_TYPE);
|
||||
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskJsonRepresentation.MEDIA_TYPE);
|
||||
|
||||
return new ResponseEntity<>(TaskMediaType.serialize(updateATask), responseHeaders, HttpStatus.ACCEPTED);
|
||||
return new ResponseEntity<>(TaskJsonRepresentation.serialize(updateATask), responseHeaders, HttpStatus.ACCEPTED);
|
||||
} catch (JsonProcessingException e) {
|
||||
throw new ResponseStatusException(HttpStatus.INTERNAL_SERVER_ERROR, e.getMessage());
|
||||
} catch (ConstraintViolationException e) {
|
||||
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||
}
|
||||
|
|
|
@ -1,23 +0,0 @@
|
|||
package ch.unisg.tapastasks.tasks.adapter.in.web;
|
||||
|
||||
import ch.unisg.tapastasks.tasks.domain.Task;
|
||||
import ch.unisg.tapastasks.tasks.domain.TaskList;
|
||||
import org.json.JSONObject;
|
||||
|
||||
final public class TaskMediaType {
|
||||
public static final String TASK_MEDIA_TYPE = "application/json";
|
||||
|
||||
public static String serialize(Task task) {
|
||||
JSONObject payload = new JSONObject();
|
||||
|
||||
payload.put("taskId", task.getTaskId().getValue());
|
||||
payload.put("taskName", task.getTaskName().getValue());
|
||||
payload.put("taskType", task.getTaskType().getValue());
|
||||
payload.put("taskState", task.getTaskState().getValue());
|
||||
payload.put("taskListName", TaskList.getTapasTaskList().getTaskListName().getValue());
|
||||
payload.put("taskResult", task.getTaskResult().getValue());
|
||||
return payload.toString();
|
||||
}
|
||||
|
||||
private TaskMediaType() { }
|
||||
}
|
|
@ -0,0 +1,59 @@
|
|||
package ch.unisg.tapastasks.tasks.adapter.out.web;
|
||||
|
||||
|
||||
import ch.unisg.tapastasks.tasks.application.port.out.CanTaskBeDeletedPort;
|
||||
import ch.unisg.tapastasks.tasks.domain.DeleteTaskEvent;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import org.springframework.context.annotation.Primary;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpRequest;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.util.HashMap;
|
||||
|
||||
@Component
|
||||
@Primary
|
||||
public class CanTaskBeDeletedWebAdapter implements CanTaskBeDeletedPort {
|
||||
|
||||
// Base URI of the service interested in this event
|
||||
//Todo: Add the right IP address
|
||||
String server = null;
|
||||
|
||||
@Override
|
||||
public void canTaskBeDeletedEvent(DeleteTaskEvent event){
|
||||
|
||||
var values = new HashMap<> () {{
|
||||
put("taskId", event.taskId);
|
||||
put("taskUri", event.taskUri);
|
||||
}};
|
||||
|
||||
var objectMapper = new ObjectMapper();
|
||||
String requestBody = null;
|
||||
try {
|
||||
requestBody = objectMapper.writeValueAsString(values);
|
||||
} catch (JsonProcessingException e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
//Todo: Question: How do we include the URI from the DeleteTaskEvent? Do we even need it?
|
||||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server+"task"))
|
||||
.header("Content-Type", "application/task+json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
||||
.build();
|
||||
|
||||
//Todo: The following parameters probably need to be changed to get the right error code
|
||||
try {
|
||||
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
|
||||
} catch (IOException e){
|
||||
e.printStackTrace();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -42,7 +42,7 @@ public class PublishNewTaskAddedEventWebAdapter implements NewTaskAddedEventPort
|
|||
HttpClient client = HttpClient.newHttpClient();
|
||||
HttpRequest request = HttpRequest.newBuilder()
|
||||
.uri(URI.create(server+"/task"))
|
||||
.header("Content-Type", "application/json")
|
||||
.header("Content-Type", "application/task+json")
|
||||
.POST(HttpRequest.BodyPublishers.ofString(requestBody))
|
||||
.build();
|
||||
|
||||
|
|
|
@ -2,6 +2,7 @@ package ch.unisg.tapastasks.tasks.application.port.in;
|
|||
|
||||
import ch.unisg.tapastasks.common.SelfValidating;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task.TaskId;
|
||||
import ch.unisg.tapastasks.tasks.domain.Task.OriginalTaskUri;
|
||||
import lombok.Value;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
|
@ -11,8 +12,12 @@ public class DeleteTaskCommand extends SelfValidating<DeleteTaskCommand> {
|
|||
@NotNull
|
||||
private final TaskId taskId;
|
||||
|
||||
public DeleteTaskCommand(TaskId taskId){
|
||||
@NotNull
|
||||
private final OriginalTaskUri taskUri;
|
||||
|
||||
public DeleteTaskCommand(TaskId taskId, OriginalTaskUri taskUri){
|
||||
this.taskId=taskId;
|
||||
this.taskUri = taskUri;
|
||||
this.validateSelf();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
package ch.unisg.tapastasks.tasks.application.port.out;
|
||||
|
||||
import ch.unisg.tapastasks.tasks.domain.DeleteTaskEvent;
|
||||
|
||||
public interface CanTaskBeDeletedPort {
|
||||
void canTaskBeDeletedEvent(DeleteTaskEvent event);
|
||||
}
|
|
@ -19,17 +19,13 @@ public class CompleteTaskService implements CompleteTaskUseCase {
|
|||
|
||||
@Override
|
||||
public Task completeTask(CompleteTaskCommand command){
|
||||
// TODO Retrieve the task based on ID
|
||||
TaskList taskList = TaskList.getTapasTaskList();
|
||||
Optional<Task> updatedTask = taskList.retrieveTaskById(command.getTaskId());
|
||||
|
||||
// TODO Update the status and result (and save?)
|
||||
Task newTask = updatedTask.get();
|
||||
newTask.taskResult = new TaskResult(command.getTaskResult().getValue());
|
||||
newTask.taskState = new TaskState(Task.State.EXECUTED);
|
||||
newTask.taskStatus = new TaskStatus(Task.Status.EXECUTED);
|
||||
|
||||
|
||||
// TODO return the updated task
|
||||
return newTask;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,10 +19,15 @@ public class DeleteTaskService implements DeleteTaskUseCase {
|
|||
@Override
|
||||
public Optional<Task> deleteTask(DeleteTaskCommand command){
|
||||
|
||||
// TODO check with assignment service if we can delte
|
||||
|
||||
TaskList taskList = TaskList.getTapasTaskList();
|
||||
Optional<Task> updatedTask = taskList.retrieveTaskById(command.getTaskId());
|
||||
Task newTask = updatedTask.get();
|
||||
// TODO: Fill in the right condition into the if-statement and the else-statement
|
||||
if (/*the task can be deleted*/){
|
||||
return taskList.deleteTaskById(command.getTaskId());
|
||||
} else {
|
||||
/*send message back to TaskList that the task cannot be deleted*/
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,7 +24,7 @@ public class TaskAssignedService implements TaskAssignedUseCase {
|
|||
|
||||
// update the status to assigned
|
||||
Task updatedTask = task.get();
|
||||
updatedTask.taskState = new TaskState(State.ASSIGNED);
|
||||
updatedTask.taskStatus = new TaskStatus(Status.ASSIGNED);
|
||||
|
||||
return updatedTask;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,11 @@
|
|||
package ch.unisg.tapastasks.tasks.domain;
|
||||
|
||||
public class DeleteTaskEvent {
|
||||
public String taskId;
|
||||
public String taskUri;
|
||||
|
||||
public DeleteTaskEvent(String taskId, String taskUri){
|
||||
this.taskId = taskId;
|
||||
this.taskUri = taskUri;
|
||||
}
|
||||
}
|
|
@ -21,40 +21,33 @@ public class Task {
|
|||
@Getter
|
||||
private final TaskType taskType;
|
||||
|
||||
@Getter
|
||||
public TaskState taskState; // had to make public for CompleteTaskService
|
||||
@Getter @Setter
|
||||
public TaskStatus taskStatus; // had to make public for CompleteTaskService
|
||||
|
||||
@Getter
|
||||
public TaskResult taskResult; // same as above
|
||||
|
||||
// private final OriginalTaskUri originalTaskUri;
|
||||
@Getter
|
||||
private final OriginalTaskUri originalTaskUri;
|
||||
|
||||
// @Getter @Setter
|
||||
// private TaskStatus taskStatus;
|
||||
@Getter @Setter
|
||||
private ServiceProvider provider;
|
||||
|
||||
// @Getter @Setter
|
||||
// private ServiceProvider provider;
|
||||
@Getter @Setter
|
||||
private InputData inputData;
|
||||
|
||||
// @Getter @Setter
|
||||
// private InputData inputData;
|
||||
|
||||
// @Getter @Setter
|
||||
// private OutputData outputData;
|
||||
@Getter @Setter
|
||||
private OutputData outputData;
|
||||
|
||||
public Task(TaskName taskName, TaskType taskType, OriginalTaskUri taskUri) {
|
||||
this.taskId = new TaskId(UUID.randomUUID().toString());
|
||||
|
||||
this.taskName = taskName;
|
||||
this.taskType = taskType;
|
||||
this.taskState = new TaskState(State.OPEN);
|
||||
this.taskStatus = new TaskStatus(Status.OPEN);
|
||||
this.taskId = new TaskId(UUID.randomUUID().toString());
|
||||
this.taskResult = new TaskResult("");
|
||||
// this.originalTaskUri = taskUri;
|
||||
|
||||
// this.taskStatus = new TaskStatus(Status.OPEN);
|
||||
|
||||
// this.inputData = null;
|
||||
// this.outputData = null;
|
||||
this.originalTaskUri = taskUri;
|
||||
this.inputData = null;
|
||||
this.outputData = null;
|
||||
}
|
||||
|
||||
protected static Task createTaskWithNameAndType(TaskName name, TaskType type) {
|
||||
|
|
|
@ -75,41 +75,42 @@ public class TaskList {
|
|||
}
|
||||
|
||||
return Optional.empty();
|
||||
// public Task changeTaskStatusToAssigned(Task.TaskId id, Optional<Task.ServiceProvider> serviceProvider)
|
||||
// throws TaskNotFoundException {
|
||||
// return changeTaskStatus(id, new Task.TaskStatus(Task.Status.ASSIGNED), serviceProvider, Optional.empty());
|
||||
// }
|
||||
}
|
||||
public Task changeTaskStatusToAssigned(Task.TaskId id, Optional<Task.ServiceProvider> serviceProvider)
|
||||
throws TaskNotFoundException {
|
||||
return changeTaskStatus(id, new Task.TaskStatus(Task.Status.ASSIGNED), serviceProvider, Optional.empty());
|
||||
}
|
||||
|
||||
// public Task changeTaskStatusToRunning(Task.TaskId id, Optional<Task.ServiceProvider> serviceProvider)
|
||||
// throws TaskNotFoundException {
|
||||
// return changeTaskStatus(id, new Task.TaskStatus(Task.Status.RUNNING), serviceProvider, Optional.empty());
|
||||
// }
|
||||
public Task changeTaskStatusToRunning(Task.TaskId id, Optional<Task.ServiceProvider> serviceProvider)
|
||||
throws TaskNotFoundException {
|
||||
return changeTaskStatus(id, new Task.TaskStatus(Task.Status.RUNNING), serviceProvider, Optional.empty());
|
||||
}
|
||||
|
||||
// public Task changeTaskStatusToExecuted(Task.TaskId id, Optional<Task.ServiceProvider> serviceProvider,
|
||||
// Optional<Task.OutputData> outputData) throws TaskNotFoundException {
|
||||
// return changeTaskStatus(id, new Task.TaskStatus(Task.Status.EXECUTED), serviceProvider, outputData);
|
||||
// }
|
||||
public Task changeTaskStatusToExecuted(Task.TaskId id, Optional<Task.ServiceProvider> serviceProvider,
|
||||
Optional<Task.OutputData> outputData) throws TaskNotFoundException {
|
||||
return changeTaskStatus(id, new Task.TaskStatus(Task.Status.EXECUTED), serviceProvider, outputData);
|
||||
}
|
||||
|
||||
// private Task changeTaskStatus(Task.TaskId id, Task.TaskStatus status, Optional<Task.ServiceProvider> serviceProvider,
|
||||
// Optional<Task.OutputData> outputData) {
|
||||
// Optional<Task> taskOpt = retrieveTaskById(id);
|
||||
private Task changeTaskStatus(Task.TaskId id, Task.TaskStatus status, Optional<Task.ServiceProvider> serviceProvider,
|
||||
Optional<Task.OutputData> outputData) {
|
||||
Optional<Task> taskOpt = retrieveTaskById(id);
|
||||
|
||||
// if (taskOpt.isEmpty()) {
|
||||
// throw new TaskNotFoundException();
|
||||
// }
|
||||
if (taskOpt.isEmpty()) {
|
||||
throw new TaskNotFoundException();
|
||||
}
|
||||
|
||||
// Task task = taskOpt.get();
|
||||
// task.setTaskStatus(status);
|
||||
Task task = taskOpt.get();
|
||||
task.setTaskStatus(status);
|
||||
|
||||
// if (serviceProvider.isPresent()) {
|
||||
// task.setProvider(serviceProvider.get());
|
||||
// }
|
||||
if (serviceProvider.isPresent()) {
|
||||
task.setProvider(serviceProvider.get());
|
||||
}
|
||||
|
||||
// if (outputData.isPresent()) {
|
||||
// task.setOutputData(outputData.get());
|
||||
// }
|
||||
if (outputData.isPresent()) {
|
||||
task.setOutputData(outputData.get());
|
||||
}
|
||||
|
||||
// return task;
|
||||
return task;
|
||||
}
|
||||
|
||||
@Value
|
||||
|
|
Loading…
Reference in New Issue
Block a user