added executor-humidity
This commit is contained in:
parent
32bf461026
commit
c87a732e2a
|
@ -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.common.valueobject.ExecutorURI;
|
||||||
import ch.unisg.executorbase.executor.application.port.out.NotifyExecutorPoolPort;
|
import ch.unisg.executorbase.executor.application.port.out.NotifyExecutorPoolPort;
|
||||||
|
|
|
@ -1,11 +1,11 @@
|
||||||
package ch.unisg.executorbase.executor.domain;
|
package ch.unisg.executorbase.executor.domain;
|
||||||
|
|
||||||
public enum ExecutorType {
|
public enum ExecutorType {
|
||||||
ADDITION, ROBOT;
|
ADDITION, ROBOT, HUMIDITY;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks if the give executor type exists.
|
* 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) {
|
public static boolean contains(String test) {
|
||||||
|
|
||||||
|
|
36
executor-humidity/pom.xml
Normal file
36
executor-humidity/pom.xml
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>org.example</groupId>
|
||||||
|
<artifactId>executor-miro</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||||
|
<version>2.5.5</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-autoconfigure</artifactId>
|
||||||
|
<version>2.5.5</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>ch.unisg</groupId>
|
||||||
|
<artifactId>executor-base</artifactId>
|
||||||
|
<version>0.0.1-SNAPSHOT</version>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<maven.compiler.source>16</maven.compiler.source>
|
||||||
|
<maven.compiler.target>16</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
</project>
|
|
@ -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();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -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<String> 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);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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")
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,5 @@
|
||||||
|
package ch.unisg.executorhumidity.executor.application.port.out;
|
||||||
|
|
||||||
|
public interface GetHumidityPort {
|
||||||
|
boolean getHumidity(String key);
|
||||||
|
}
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user