diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java index aee3142..64b6d23 100644 --- a/executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/application/service/NotifyExecutorPoolService.java @@ -1,4 +1,4 @@ -package ch.unisg.executorbase.executor.application.service; +package ch.unisg.executorBase.executor.application.service; import ch.unisg.common.valueobject.ExecutorURI; import ch.unisg.executorbase.executor.application.port.out.NotifyExecutorPoolPort; diff --git a/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java index ca9533a..8905baa 100644 --- a/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java +++ b/executor-base/src/main/java/ch/unisg/executorBase/executor/domain/ExecutorType.java @@ -1,11 +1,11 @@ package ch.unisg.executorbase.executor.domain; public enum ExecutorType { - ADDITION, ROBOT; + ADDITION, ROBOT, HUMIDITY; /** * Checks if the give executor type exists. - * @return Wheter the given executor type exists + * @return Whether the given executor type exists **/ public static boolean contains(String test) { diff --git a/executor-humidity/pom.xml b/executor-humidity/pom.xml new file mode 100644 index 0000000..3c07d0c --- /dev/null +++ b/executor-humidity/pom.xml @@ -0,0 +1,36 @@ + + + 4.0.0 + + org.example + executor-miro + 1.0-SNAPSHOT + + + org.springframework.boot + spring-boot-autoconfigure + 2.5.5 + compile + + + org.springframework.boot + spring-boot-autoconfigure + 2.5.5 + compile + + + ch.unisg + executor-base + 0.0.1-SNAPSHOT + compile + + + + + 16 + 16 + + + diff --git a/executor-humidity/src/main/java/ch/unisg/executorhumidity/ExecutorhumidityApplication.java b/executor-humidity/src/main/java/ch/unisg/executorhumidity/ExecutorhumidityApplication.java new file mode 100644 index 0000000..181cfeb --- /dev/null +++ b/executor-humidity/src/main/java/ch/unisg/executorhumidity/ExecutorhumidityApplication.java @@ -0,0 +1,16 @@ +package ch.unisg.executorhumidity; + + +import ch.unisg.executorhumidity.executor.domain.Executor; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class ExecutorhumidityApplication { + + public static void main(String[] args) { + SpringApplication.run(ExecutorhumidityApplication.class, args); + Executor.getExecutor(); + } + +} diff --git a/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/adapter/in/web/TaskAvailableController.java b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/adapter/in/web/TaskAvailableController.java new file mode 100644 index 0000000..be85ab8 --- /dev/null +++ b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/adapter/in/web/TaskAvailableController.java @@ -0,0 +1,38 @@ +package ch.unisg.executorhumidity.executor.adapter.in.web; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PathVariable; +import org.springframework.web.bind.annotation.RestController; + +import ch.unisg.executorbase.executor.application.port.in.TaskAvailableCommand; +import ch.unisg.executorbase.executor.application.port.in.TaskAvailableUseCase; +import ch.unisg.executorbase.executor.domain.ExecutorType; + +import java.util.concurrent.CompletableFuture; + +@RestController +public class TaskAvailableController { + private final TaskAvailableUseCase taskAvailableUseCase; + + public TaskAvailableController(TaskAvailableUseCase taskAvailableUseCase) { + this.taskAvailableUseCase = taskAvailableUseCase; + } + + @GetMapping(path="/newtask/{taskType}") + public ResponseEntity retrieveTaskfromTaskList(@PathVariable("taskType") String taskType) { + + if (ExecutorType.contains(taskType.toUpperCase())) { + TaskAvailableCommand command = new TaskAvailableCommand( + ExecutorType.valueOf(taskType.toUpperCase())); + CompletableFuture.runAsync(() -> taskAvailableUseCase.newTaskAvailable(command); + } + + // Add the content type as a response header + HttpHeaders responseHeaders = new HttpHeaders(); + + return new ResponseEntity<>("OK", responseHeaders, HttpStatus.OK); + } +} diff --git a/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/adapter/out/GetHumidityAdapter.java b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/adapter/out/GetHumidityAdapter.java new file mode 100644 index 0000000..88f440d --- /dev/null +++ b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/adapter/out/GetHumidityAdapter.java @@ -0,0 +1,17 @@ +package ch.unisg.executorhumidity.executor.adapter.out; + +import ch.unisg.executorhumidity.executor.application.port.out.GetHumidityPort; +import org.springframework.context.annotation.Primary; +import org.springframework.stereotype.Component; + +@Component +@Primary +public class GetHumidityAdapter implements GetHumidityPort { + + @Override + public boolean getHumidity(String key) { + + CoapClient client1 = new CoapClient("coap://130.82.171.10:5683/humidity") + + } +} diff --git a/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/application/port/out/GetHumidityPort.java b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/application/port/out/GetHumidityPort.java new file mode 100644 index 0000000..b865cfd --- /dev/null +++ b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/application/port/out/GetHumidityPort.java @@ -0,0 +1,5 @@ +package ch.unisg.executorhumidity.executor.application.port.out; + +public interface GetHumidityPort { + boolean getHumidity(String key); +} diff --git a/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/application/service/TaskAvailableService.java b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/application/service/TaskAvailableService.java new file mode 100644 index 0000000..0e467c4 --- /dev/null +++ b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/application/service/TaskAvailableService.java @@ -0,0 +1,27 @@ +package ch.unisg.executorhumidity.executor.application.service; + +import ch.unisg.executorbase.executor.domain.ExecutorStatus; +import ch.unisg.executorhumidity.executor.domain.Executor; +import org.springframework.stereotype.Component; +import ch.unisg.executorbase.executor.application.port.in.TaskAvailableCommand; +import ch.unisg.executorbase.executor.application.port.in.TaskAvailableUseCase; +import lombok.RequiredArgsConstructor; + +import javax.transaction.Transactional; + +@RequiredArgsConstructor +@Component +@Transactional +public class TaskAvailableService implements TaskAvailableUseCase { + + @Override + public void newTaskAvailable(TaskAvailableCommand command) { + + Executor executor = Executor.getExecutor(); + + if(executor.getExecutorType() == command.getTaskType() && + executor.getStatus() == ExecutorStatus.IDLING) { + executor.getAssignment(); + } + } +} diff --git a/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/domain/Executor.java b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/domain/Executor.java new file mode 100644 index 0000000..2a8cd3c --- /dev/null +++ b/executor-humidity/src/main/java/ch/unisg/executorhumidity/executor/domain/Executor.java @@ -0,0 +1,22 @@ +package ch.unisg.executorhumidity.executor.domain; + +import ch.unisg.executorbase.executor.domain.ExecutorBase; +import ch.unisg.executorbase.executor.domain.ExecutorType; + +public class Executor extends ExecutorBase{ + + private static final Executor executor = new Exec(ExecutorType.HUMIDITY); + // TODO: Add the necessary ports + + + private Executor(ExecutorType executorType) {super(executorType);} + + public static Executor getExecutor() {return executor;} + + + @Override + protected + String execution(String input) { + //TODO: Fill + } +}