made changes to executor-humidity

This commit is contained in:
julius.lautz 2021-12-11 19:09:34 +01:00
parent c87a732e2a
commit aaffb0371e
6 changed files with 75 additions and 10 deletions

View File

@ -1,5 +1,6 @@
package ch.unisg.executorbase.executor.domain;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -88,6 +89,6 @@ public abstract class ExecutorBase {
* Implementation of the actual execution method of an executor
* @return the execution result
**/
protected abstract String execution(String input);
protected abstract String execution(String input) throws ConnectorException, IOException, ConnectorException;
}

View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>executor-miro</artifactId>
<artifactId>executor-humidity</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
@ -15,9 +15,9 @@
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-autoconfigure</artifactId>
<version>2.5.5</version>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>5.3.10</version>
<scope>compile</scope>
</dependency>
<dependency>
@ -26,6 +26,11 @@
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.eclipse.californium</groupId>
<artifactId>californium-core</artifactId>
<version>3.0.0</version>
</dependency>
</dependencies>
<properties>

View File

@ -1,17 +1,32 @@
package ch.unisg.executorhumidity.executor.adapter.out;
import ch.unisg.executorhumidity.executor.application.port.out.GetHumidityPort;
import org.eclipse.californium.core.CoapClient;
import org.eclipse.californium.elements.exception.ConnectorException;
import org.springframework.context.annotation.Primary;
import org.springframework.stereotype.Component;
import java.io.IOException;
@Component
@Primary
public class GetHumidityAdapter implements GetHumidityPort {
@Override
public boolean getHumidity(String key) {
public String getHumidity() {
CoapClient client1 = new CoapClient("coap://130.82.171.10:5683/humidity")
CoapClient client1 = new CoapClient("coap://130.82.171.10:5683/humidity");
String result = null;
try {
result = client1.get().getResponseText();
} catch (ConnectorException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return result;
}
}

View File

@ -1,5 +1,9 @@
package ch.unisg.executorhumidity.executor.application.port.out;
import org.eclipse.californium.elements.exception.ConnectorException;
import java.io.IOException;
public interface GetHumidityPort {
boolean getHumidity(String key);
String getHumidity();
}

View File

@ -2,11 +2,17 @@ package ch.unisg.executorhumidity.executor.domain;
import ch.unisg.executorbase.executor.domain.ExecutorBase;
import ch.unisg.executorbase.executor.domain.ExecutorType;
import ch.unisg.executorhumidity.executor.adapter.out.GetHumidityAdapter;
import ch.unisg.executorhumidity.executor.application.port.out.GetHumidityPort;
import org.eclipse.californium.elements.exception.ConnectorException;
import java.io.IOException;
public class Executor extends ExecutorBase{
private static final Executor executor = new Exec(ExecutorType.HUMIDITY);
private static final Executor executor = new Executor(ExecutorType.HUMIDITY);
// TODO: Add the necessary ports
private final GetHumidityPort getHumidityPort = new GetHumidityAdapter();
private Executor(ExecutorType executorType) {super(executorType);}
@ -18,5 +24,9 @@ public class Executor extends ExecutorBase{
protected
String execution(String input) {
//TODO: Fill
String result = getHumidityPort.getHumidity();
return result;
}
}

View File

@ -45,7 +45,37 @@
<artifactId>executor-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<dependency>
<groupId>ch.unisg</groupId>
<artifactId>executor-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.unisg</groupId>
<artifactId>executor-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.unisg</groupId>
<artifactId>executor-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>ch.unisg</groupId>
<artifactId>executor-base</artifactId>
<version>0.0.1-SNAPSHOT</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>
<build>
<plugins>