Commit 62b747c9 authored by Pascal Porta's avatar Pascal Porta

added support for error flags and car models in restful

parent e925381d
/target/*
**/target/*
.settings/*
.project
.classpath
......@@ -7,4 +7,5 @@
.idea/*
/target
*.pyc
*.DS_Store
\ No newline at end of file
*.DS_Store
*.iml
\ No newline at end of file
......@@ -13,7 +13,7 @@
<groupId>montisim</groupId>
<artifactId>restful</artifactId>
<version>2.0.0</version>
<version>2.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
......@@ -31,11 +31,26 @@
</repositories>
<dependencies>
<dependency>
<groupId>montisim</groupId>
<artifactId>rpc</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
<!--<exclusions>
<exclusion>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</exclusion>
</exclusions>-->
</dependency>
<!-- we need at least version 23 but we can not have version 28 (which rpc has as a dependency, but 23 seems to work fine as well) -->
<!-- there seems to be a bug in monticore or se-commons with the newer versions of guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>23.6.1-jre</version>
</dependency>
<dependency>
......@@ -58,11 +73,11 @@
<scope>compile</scope>
</dependency>
<!-- SimLong -->
<!-- SimLang -->
<dependency>
<groupId>de.monticore.lang.montisim</groupId>
<artifactId>SimLang</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
......@@ -74,7 +89,7 @@
<dependency>
<groupId>de.monticore.lang.montisim</groupId>
<artifactId>Util</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
......@@ -86,7 +101,7 @@
<dependency>
<groupId>de.monticore.lang.montisim</groupId>
<artifactId>Weather</artifactId>
<version>1.0.1</version>
<version>1.1.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
......@@ -223,6 +238,27 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<goals>
<goal>jar</goal>
</goals>
<phase>package</phase>
<configuration>
<!--to be imported on other projects-->
<classifier>rest-models</classifier>
<includes>
<include>**/model/*</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<!--<finalName>restful</finalName>-->
</build>
......
package server.restful;
import de.monticore.lang.montisim.simlang.SimLangTool;
import de.monticore.lang.montisim.simlang.adapter.SimLangContainer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Import;
import org.springframework.web.bind.annotation.RestController;
import server.restful.view.CarView;
import server.restful.view.MapView;
import server.restful.view.ScenarioView;
import server.restful.view.SimulationView;
import java.nio.file.Paths;
@SpringBootApplication
@Import({MapView.class, ScenarioView.class, SimulationView.class})
@Import({MapView.class, ScenarioView.class, SimulationView.class, CarView.class})
@RestController
public class Server {
......
package server.restful.dao;
import server.restful.model.CarModel;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
public class CarDAO extends BaseDAO {
public static int create(String name, String path){
int carId = -1;
Connection c = getConnection();
PreparedStatement stmt;
try {
stmt = c.prepareStatement("INSERT INTO car (name, path) VALUES (?, ?)");
stmt.setString(1, name);
stmt.setString(2, path);
carId = executeInsert(c, stmt);
c.commit();
c.close();
} catch (SQLException e) {
e.printStackTrace();
}
return carId;
}
public static CarModel getByID(int id) {
CarModel result = null;
Connection c = getConnection();
PreparedStatement stmt;
try {
stmt = c.prepareStatement("SELECT name, path FROM car where id=(?)");
stmt.setInt(1, id);
ResultSet rs = stmt.executeQuery();
if (rs.next()){
result = new CarModel(
id,
rs.getString("name"),
rs.getString("path")
);
}
stmt.close();
c.close();
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}
public static List<CarModel> getAll(){
List<CarModel> result = new ArrayList<>();
Connection c = getConnection();
PreparedStatement stmt;
try {
stmt = c.prepareStatement("SELECT id, name, path FROM car");
ResultSet rs = stmt.executeQuery();
while (rs.next()){
result.add(new CarModel(
rs.getInt("id"),
rs.getString("name"),
rs.getString("path")
));
}
stmt.close();
c.close();
} catch (SQLException e) {
e.printStackTrace();
}
return result;
}
}
package server.restful.model;
import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class CarModel {
int id;
String name;
String path;
public CarModel(int id, String name, String path) {
this.id = id;
this.name = name;
this.path = path;
}
public CarModel() { }
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
}
......@@ -18,6 +18,8 @@ public class Dataframe {
private double deltaTime;
private double totalTime;
private boolean[] errorFlags;
public double getPosX() {
return posX;
}
......@@ -106,4 +108,11 @@ public class Dataframe {
this.totalTime = totalTime;
}
public boolean[] getErrorFlags() {
return errorFlags;
}
public void setErrorFlags(boolean[] errorFlags) {
this.errorFlags = errorFlags;
}
}
......@@ -22,6 +22,8 @@ public class MapModel {
this.streetSign = streetSign;
}
public Node() { }
public long getId() {
return id;
}
......@@ -41,6 +43,26 @@ public class MapModel {
public StreetSign getStreetSign() {
return streetSign;
}
public void setId(long id) {
this.id = id;
}
public void setLongitude(double longitude) {
this.longitude = longitude;
}
public void setLatitude(double latitude) {
this.latitude = latitude;
}
public void setAltitude(double altitude) {
this.altitude = altitude;
}
public void setStreetSign(StreetSign streetSign) {
this.streetSign = streetSign;
}
}
public static class StreetSign{
......@@ -68,6 +90,8 @@ public class MapModel {
this.z2 = z2;
}
public StreetSign() { }
public long getId() {
return id;
}
......@@ -108,6 +132,45 @@ public class MapModel {
return z2;
}
public void setId(long id) {
this.id = id;
}
public void setType(String type) {
this.type = type;
}
public void setOne(boolean one) {
this.one = one;
}
public void setTwo(boolean two) {
this.two = two;
}
public void setX1(double x1) {
this.x1 = x1;
}
public void setX2(double x2) {
this.x2 = x2;
}
public void setY1(double y1) {
this.y1 = y1;
}
public void setY2(double y2) {
this.y2 = y2;
}
public void setZ1(double z1) {
this.z1 = z1;
}
public void setZ2(double z2) {
this.z2 = z2;
}
}
public static class Street{
......@@ -131,6 +194,9 @@ public class MapModel {
this.speedLimit = speedLimit;
}
public Street() {
}
public long getId() {
return id;
}
......@@ -162,6 +228,38 @@ public class MapModel {
public double getSpeedLimit() {
return speedLimit;
}
public void setId(long id) {
this.id = id;
}
public void setWidth(double width) {
this.width = width;
}
public void setNodes(List<Node> nodes) {
this.nodes = nodes;
}
public void setIntersections(List<Node> intersections) {
this.intersections = intersections;
}
public void setType(String type) {
this.type = type;
}
public void setOneWay(boolean oneWay) {
isOneWay = oneWay;
}
public void setStreetPavements(String streetPavements) {
this.streetPavements = streetPavements;
}
public void setSpeedLimit(double speedLimit) {
this.speedLimit = speedLimit;
}
}
public static class Bound{
......@@ -181,6 +279,9 @@ public class MapModel {
this.maxZ = maxZ;
}
public Bound() {
}
public double getMinX() {
return minX;
}
......@@ -205,6 +306,29 @@ public class MapModel {
return maxZ;
}
public void setMinX(double minX) {
this.minX = minX;
}
public void setMinY(double minY) {
this.minY = minY;
}
public void setMinZ(double minZ) {
this.minZ = minZ;
}
public void setMaxX(double maxX) {
this.maxX = maxX;
}
public void setMaxY(double maxY) {
this.maxY = maxY;
}
public void setMaxZ(double maxZ) {
this.maxZ = maxZ;
}
}
public static class EnvironmentObject{
......@@ -216,6 +340,9 @@ public class MapModel {
this.type = type;
}
public EnvironmentObject() {
}
public List<Node> getNodes() {
return nodes;
}
......@@ -223,18 +350,34 @@ public class MapModel {
public String getType() {
return type;
}
public void setNodes(List<Node> nodes) {
this.nodes = nodes;
}
public void setType(String type) {
this.type = type;
}
}
public static class Building extends EnvironmentObject {
public Building(List<Node> nodes, String type) {
super(nodes, type);
}
public Building() {
super();
}
}
public static class Waterway extends Building{
public Waterway(List<Node> nodes, String type) {
super(nodes, type);
}
public Waterway() {
super();
}
}
public static class HeightMap {
......@@ -256,6 +399,9 @@ public class MapModel {
this.heightMapMaxY = heightMapMaxY;
}
public HeightMap() {
}
public double[][] getData() {
return data;
}
......@@ -283,6 +429,34 @@ public class MapModel {
public double getHeightMapMaxY() {
return heightMapMaxY;
}
public void setData(double[][] data) {
this.data = data;
}
public void setHeightMapDeltaX(double heightMapDeltaX) {
this.heightMapDeltaX = heightMapDeltaX;
}
public void setHeightMapDeltaY(double heightMapDeltaY) {
this.heightMapDeltaY = heightMapDeltaY;
}
public void setHeightMapMinX(double heightMapMinX) {
this.heightMapMinX = heightMapMinX;
}
public void setHeightMapMinY(double heightMapMinY) {
this.heightMapMinY = heightMapMinY;
}
public void setHeightMapMaxX(double heightMapMaxX) {
this.heightMapMaxX = heightMapMaxX;
}
public void setHeightMapMaxY(double heightMapMaxY) {
this.heightMapMaxY = heightMapMaxY;
}
}
......
......@@ -4,6 +4,7 @@ import com.fasterxml.jackson.annotation.JsonInclude;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ScenarioModel {
int id;
String name;
String path;
......@@ -14,6 +15,7 @@ public class ScenarioModel {
this.path = path;
}
public ScenarioModel() { }
public String getPath() {
return path;
......@@ -27,4 +29,15 @@ public class ScenarioModel {
return name;
}
public void setId(int id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
public void setPath(String path) {
this.path = path;
}
}
package server.restful.service;
import server.restful.dao.CarDAO;
import server.restful.model.CarModel;
import server.restful.util.Util;
import java.io.InputStream;
public class CarService {
public static String CAR_BASE_DIR = ScenarioService.SCENARIO_BASE_DIR;
public static CarModel saveCar(InputStream inputStream, String fileName) {
String path = CAR_BASE_DIR + "/" + fileName;
String name = fileName.replace(".car", "");
int id = CarDAO.create(name, path);
Util.writeToFile(inputStream, path);
return new CarModel(id, name, path);
}
}
......@@ -10,10 +10,10 @@ public class ScenarioService {
public static String SCENARIO_BASE_DIR = Util.getWorkDir();
public static ScenarioModel saveScenario(InputStream inputStream, String fileName){
String path = SCENARIO_BASE_DIR + "/" + fileName;
String path = SCENARIO_BASE_DIR;// + "/" + fileName;
String name = fileName.replace(".sim", "");
int id = ScenarioDAO.create(name, path);
Util.writeToFile(inputStream, path);
Util.writeToFile(inputStream, path + "/" + fileName);
return new ScenarioModel(id, name, path);
}
}
......@@ -2,6 +2,7 @@ package server.restful.service;
import de.monticore.lang.montisim.simlang.SimLangTool;
import de.monticore.lang.montisim.simlang.adapter.SLMontiSimAdapter;
import de.monticore.lang.montisim.simlang.adapter.SimLangContainer;
import de.monticore.lang.montisim.util.types.ExplicitVehicle;
import de.monticore.lang.montisim.util.types.Path2D;
import org.slf4j.Logger;
......@@ -18,6 +19,7 @@ import server.restful.registry.ServiceRegistry;
import server.restful.util.Util;
import java.io.File;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutorService;
......@@ -66,6 +68,8 @@ public class SimulationService implements Runnable {
*/
synchronized public void startSimulation(ServiceRegistry registry) throws Exception {