Deployment 0.0.1 #25
|
@ -0,0 +1,41 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.adapter.in.web;
|
||||||
|
|
||||||
|
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 org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class CompleteTaskWebController {
|
||||||
|
private final CompleteTaskUseCase completeTaskUseCase;
|
||||||
|
|
||||||
|
public CompleteTaskWebController(CompleteTaskUseCase completeTaskUseCase){
|
||||||
|
this.completeTaskUseCase = completeTaskUseCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(path = "/tasks/completeTask", consumes = {TaskMediaType.TASK_MEDIA_TYPE})
|
||||||
|
public ResponseEntity<String> completeTask (@RequestBody Task task){
|
||||||
|
try {
|
||||||
|
CompleteTaskCommand command = new CompleteTaskCommand(
|
||||||
|
task.getTaskId(), task.getTaskResult()
|
||||||
|
);
|
||||||
|
|
||||||
|
Task updateATask = completeTaskUseCase.completeTask(command);
|
||||||
|
|
||||||
|
HttpHeaders responseHeaders = new HttpHeaders();
|
||||||
|
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskMediaType.TASK_MEDIA_TYPE);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(TaskMediaType.serialize(updateATask), responseHeaders, HttpStatus.ACCEPTED);
|
||||||
|
} catch(ConstraintViolationException e){
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,48 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.adapter.in.web;
|
||||||
|
|
||||||
|
|
||||||
|
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 org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class DeleteTaskWebController {
|
||||||
|
private final DeleteTaskUseCase deleteClassUseCase;
|
||||||
|
|
||||||
|
public DeleteTaskWebController(DeleteTaskUseCase deleteClassUseCase){
|
||||||
|
this.deleteClassUseCase = deleteClassUseCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(path="/tasks/deleteTask", consumes = {TaskMediaType.TASK_MEDIA_TYPE})
|
||||||
|
public ResponseEntity<String> deleteTask (@RequestBody Task task){
|
||||||
|
try {
|
||||||
|
DeleteTaskCommand command = new DeleteTaskCommand(task.getTaskId());
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
return new ResponseEntity<>(TaskMediaType.serialize(deleteATask.get()), responseHeaders, HttpStatus.ACCEPTED);
|
||||||
|
} catch(ConstraintViolationException e){
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,42 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.adapter.in.web;
|
||||||
|
|
||||||
|
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 org.springframework.http.HttpHeaders;
|
||||||
|
import org.springframework.http.HttpStatus;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
|
import javax.validation.ConstraintViolationException;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
public class TaskAssignedWebController {
|
||||||
|
private final TaskAssignedUseCase taskAssignedUseCase;
|
||||||
|
|
||||||
|
public TaskAssignedWebController(TaskAssignedUseCase taskAssignedUseCase){
|
||||||
|
this.taskAssignedUseCase = taskAssignedUseCase;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping(path="/tasks/assignTask", consumes= {TaskMediaType.TASK_MEDIA_TYPE})
|
||||||
|
public ResponseEntity<String> assignTask(@RequestBody Task task){
|
||||||
|
try{
|
||||||
|
TaskAssignedCommand command = new TaskAssignedCommand(
|
||||||
|
task.getTaskId()
|
||||||
|
);
|
||||||
|
|
||||||
|
Task updateATask = taskAssignedUseCase.assignTask(command);
|
||||||
|
|
||||||
|
HttpHeaders responseHeaders = new HttpHeaders();
|
||||||
|
responseHeaders.add(HttpHeaders.CONTENT_TYPE, TaskMediaType.TASK_MEDIA_TYPE);
|
||||||
|
|
||||||
|
return new ResponseEntity<>(TaskMediaType.serialize(updateATask), responseHeaders, HttpStatus.ACCEPTED);
|
||||||
|
} catch (ConstraintViolationException e){
|
||||||
|
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -15,7 +15,7 @@ final public class TaskMediaType {
|
||||||
payload.put("taskType", task.getTaskType().getValue());
|
payload.put("taskType", task.getTaskType().getValue());
|
||||||
payload.put("taskState", task.getTaskState().getValue());
|
payload.put("taskState", task.getTaskState().getValue());
|
||||||
payload.put("taskListName", TaskList.getTapasTaskList().getTaskListName().getValue());
|
payload.put("taskListName", TaskList.getTapasTaskList().getTaskListName().getValue());
|
||||||
|
payload.put("taskResult", task.getTaskResult().getValue());
|
||||||
return payload.toString();
|
return payload.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -29,6 +29,8 @@ public class PublishNewTaskAddedEventWebAdapter implements NewTaskAddedEventPort
|
||||||
var values = new HashMap<String, String>() {{
|
var values = new HashMap<String, String>() {{
|
||||||
put("taskname",event.taskName);
|
put("taskname",event.taskName);
|
||||||
put("tasklist",event.taskListName);
|
put("tasklist",event.taskListName);
|
||||||
|
put("taskId", event.taskId);
|
||||||
|
put("taskType", event.taskType);
|
||||||
}};
|
}};
|
||||||
|
|
||||||
var objectMapper = new ObjectMapper();
|
var objectMapper = new ObjectMapper();
|
||||||
|
|
|
@ -0,0 +1,23 @@
|
||||||
|
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.TaskResult;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Value
|
||||||
|
public class CompleteTaskCommand extends SelfValidating<CompleteTaskCommand> {
|
||||||
|
@NotNull
|
||||||
|
private final TaskId taskId;
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private final TaskResult taskResult;
|
||||||
|
|
||||||
|
public CompleteTaskCommand(TaskId taskId, TaskResult taskResult){
|
||||||
|
this.taskId = taskId;
|
||||||
|
this.taskResult = taskResult;
|
||||||
|
this.validateSelf();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.application.port.in;
|
||||||
|
|
||||||
|
import ch.unisg.tapastasks.tasks.domain.Task;
|
||||||
|
|
||||||
|
public interface CompleteTaskUseCase {
|
||||||
|
Task completeTask(CompleteTaskCommand command);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.application.port.in;
|
||||||
|
|
||||||
|
import ch.unisg.tapastasks.common.SelfValidating;
|
||||||
|
import ch.unisg.tapastasks.tasks.domain.Task.TaskId;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Value
|
||||||
|
public class DeleteTaskCommand extends SelfValidating<DeleteTaskCommand> {
|
||||||
|
@NotNull
|
||||||
|
private final TaskId taskId;
|
||||||
|
|
||||||
|
public DeleteTaskCommand(TaskId taskId){
|
||||||
|
this.taskId=taskId;
|
||||||
|
this.validateSelf();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.application.port.in;
|
||||||
|
|
||||||
|
import ch.unisg.tapastasks.tasks.domain.Task;
|
||||||
|
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
public interface DeleteTaskUseCase {
|
||||||
|
Optional<Task> deleteTask(DeleteTaskCommand command);
|
||||||
|
}
|
|
@ -0,0 +1,18 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.application.port.in;
|
||||||
|
|
||||||
|
import ch.unisg.tapastasks.common.SelfValidating;
|
||||||
|
import ch.unisg.tapastasks.tasks.domain.Task.TaskId;
|
||||||
|
import lombok.Value;
|
||||||
|
|
||||||
|
import javax.validation.constraints.NotNull;
|
||||||
|
|
||||||
|
@Value
|
||||||
|
public class TaskAssignedCommand extends SelfValidating<TaskAssignedCommand> {
|
||||||
|
@NotNull
|
||||||
|
private final TaskId taskId;
|
||||||
|
|
||||||
|
public TaskAssignedCommand(TaskId taskId){
|
||||||
|
this.taskId=taskId;
|
||||||
|
this.validateSelf();
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.application.port.in;
|
||||||
|
|
||||||
|
import ch.unisg.tapastasks.tasks.domain.Task;
|
||||||
|
|
||||||
|
public interface TaskAssignedUseCase {
|
||||||
|
Task assignTask(TaskAssignedCommand command);
|
||||||
|
}
|
|
@ -30,7 +30,7 @@ public class AddNewTaskToTaskListService implements AddNewTaskToTaskListUseCase
|
||||||
//the core and then the integration event in the application layer.
|
//the core and then the integration event in the application layer.
|
||||||
if (newTask != null) {
|
if (newTask != null) {
|
||||||
NewTaskAddedEvent newTaskAdded = new NewTaskAddedEvent(newTask.getTaskName().getValue(),
|
NewTaskAddedEvent newTaskAdded = new NewTaskAddedEvent(newTask.getTaskName().getValue(),
|
||||||
taskList.getTaskListName().getValue());
|
taskList.getTaskListName().getValue(), newTask.getTaskId().getValue(), newTask.getTaskType().getValue());
|
||||||
newTaskAddedEventPort.publishNewTaskAddedEvent(newTaskAdded);
|
newTaskAddedEventPort.publishNewTaskAddedEvent(newTaskAdded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,35 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.application.service;
|
||||||
|
|
||||||
|
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 ch.unisg.tapastasks.tasks.domain.Task.*;
|
||||||
|
import ch.unisg.tapastasks.tasks.domain.TaskList;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Component
|
||||||
|
@Transactional
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
|
// TODO return the updated task
|
||||||
|
return newTask;
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,25 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.application.service;
|
||||||
|
|
||||||
|
|
||||||
|
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 ch.unisg.tapastasks.tasks.domain.TaskList;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Component
|
||||||
|
@Transactional
|
||||||
|
public class DeleteTaskService implements DeleteTaskUseCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Optional<Task> deleteTask(DeleteTaskCommand command){
|
||||||
|
TaskList taskList = TaskList.getTapasTaskList();
|
||||||
|
return taskList.deleteTaskById(command.getTaskId());
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package ch.unisg.tapastasks.tasks.application.service;
|
||||||
|
|
||||||
|
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 ch.unisg.tapastasks.tasks.domain.Task.*;
|
||||||
|
import ch.unisg.tapastasks.tasks.domain.TaskList;
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
|
||||||
|
import javax.transaction.Transactional;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
@Component
|
||||||
|
@Transactional
|
||||||
|
public class TaskAssignedService implements TaskAssignedUseCase {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Task assignTask(TaskAssignedCommand command) {
|
||||||
|
// retrieve the task based on ID
|
||||||
|
TaskList taskList = TaskList.getTapasTaskList();
|
||||||
|
Optional<Task> task = taskList.retrieveTaskById(command.getTaskId());
|
||||||
|
|
||||||
|
// update the status to assigned
|
||||||
|
Task updatedTask = task.get();
|
||||||
|
updatedTask.taskState = new TaskState(State.ASSIGNED);
|
||||||
|
|
||||||
|
return updatedTask;
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,9 +4,14 @@ package ch.unisg.tapastasks.tasks.domain;
|
||||||
public class NewTaskAddedEvent {
|
public class NewTaskAddedEvent {
|
||||||
public String taskName;
|
public String taskName;
|
||||||
public String taskListName;
|
public String taskListName;
|
||||||
|
public String taskId;
|
||||||
|
public String taskType;
|
||||||
|
|
||||||
public NewTaskAddedEvent(String taskName, String taskListName) {
|
public NewTaskAddedEvent(String taskName, String taskListName, String taskId, String taskType) {
|
||||||
this.taskName = taskName;
|
this.taskName = taskName;
|
||||||
this.taskListName = taskListName;
|
this.taskListName = taskListName;
|
||||||
|
this.taskId = taskId;
|
||||||
|
this.taskType = taskType;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,13 +22,18 @@ public class Task {
|
||||||
private final TaskType taskType;
|
private final TaskType taskType;
|
||||||
|
|
||||||
@Getter
|
@Getter
|
||||||
private TaskState taskState;
|
public TaskState taskState; // had to make public for CompleteTaskService
|
||||||
|
|
||||||
|
@Getter
|
||||||
|
public TaskResult taskResult; // same as above
|
||||||
|
|
||||||
|
|
||||||
public Task(TaskName taskName, TaskType taskType) {
|
public Task(TaskName taskName, TaskType taskType) {
|
||||||
this.taskName = taskName;
|
this.taskName = taskName;
|
||||||
this.taskType = taskType;
|
this.taskType = taskType;
|
||||||
this.taskState = new TaskState(State.OPEN);
|
this.taskState = new TaskState(State.OPEN);
|
||||||
this.taskId = new TaskId(UUID.randomUUID().toString());
|
this.taskId = new TaskId(UUID.randomUUID().toString());
|
||||||
|
this.taskResult = new TaskResult("");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Task createTaskWithNameAndType(TaskName name, TaskType type) {
|
protected static Task createTaskWithNameAndType(TaskName name, TaskType type) {
|
||||||
|
@ -56,4 +61,9 @@ public class Task {
|
||||||
public static class TaskType {
|
public static class TaskType {
|
||||||
private String value;
|
private String value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Value
|
||||||
|
public static class TaskResult{
|
||||||
|
private String value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,7 @@ public class TaskList {
|
||||||
|
|
||||||
//Note: We do not care about the management of task lists, there is only one within this service
|
//Note: We do not care about the management of task lists, there is only one within this service
|
||||||
//--> using the Singleton pattern here to make lives easy; we will later load it from a repo
|
//--> using the Singleton pattern here to make lives easy; we will later load it from a repo
|
||||||
//TODO change "tutors" to your group name ("groupx")
|
private static final TaskList taskList = new TaskList(new TaskListName("tapas-tasks-group1"));
|
||||||
private static final TaskList taskList = new TaskList(new TaskListName("tapas-tasks-tutors"));
|
|
||||||
|
|
||||||
private TaskList(TaskListName taskListName) {
|
private TaskList(TaskListName taskListName) {
|
||||||
this.taskListName = taskListName;
|
this.taskListName = taskListName;
|
||||||
|
@ -55,6 +54,17 @@ public class TaskList {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Optional<Task> deleteTaskById(Task.TaskId id) {
|
||||||
|
for (Task task: listOfTasks.value){
|
||||||
|
if(task.getTaskId().getValue().equalsIgnoreCase(id.getValue())){
|
||||||
|
listOfTasks.value.remove(task);
|
||||||
|
return Optional.of(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Value
|
@Value
|
||||||
public static class TaskListName {
|
public static class TaskListName {
|
||||||
private String value;
|
private String value;
|
||||||
|
|
Loading…
Reference in New Issue
Block a user