fehlermeldungen vereinfacht
This commit is contained in:
parent
0aff9266d6
commit
99f9748de3
@ -45,12 +45,14 @@ public class CacheConstructionUtil {
|
|||||||
public static ResponseEntity createCacheUtil(Cache cache) {
|
public static ResponseEntity createCacheUtil(Cache cache) {
|
||||||
|
|
||||||
// Stationen werden in die Datenbank eingetragen
|
// Stationen werden in die Datenbank eingetragen
|
||||||
|
int position = 1;
|
||||||
for (Station station : cache.getStationen()) {
|
for (Station station : cache.getStationen()) {
|
||||||
ResponseEntity response = createStationUtil(station);
|
ResponseEntity response = createStationUtil(station, position);
|
||||||
if (response.getStatusCodeValue() == 400) {
|
if (response.getStatusCodeValue() == 400) {
|
||||||
deleteStationenUtil(cache);
|
deleteStationenUtil(cache);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
position++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Caches werden in die Datenbank eingetragen
|
// Caches werden in die Datenbank eingetragen
|
||||||
@ -81,18 +83,19 @@ public class CacheConstructionUtil {
|
|||||||
return ResponseEntity.status(200).body(new Gson().toJson(cache));
|
return ResponseEntity.status(200).body(new Gson().toJson(cache));
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ResponseEntity createStationUtil(Station station) {
|
public static ResponseEntity createStationUtil(Station station, int position) {
|
||||||
|
|
||||||
if (station.getDescription().length() == 0 /*|| station.getSolution().length() == 0*/) {
|
if (station.getDescription().length() == 0 /*|| station.getSolution().length() == 0*/) {
|
||||||
return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt werden!");
|
return ResponseEntity.status(400).body("Alle Felder müssen ausgefüllt werden!");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (station.getLattitude() < 49 || station.getLattitude() > 50) {
|
if (station.getLattitude() < 49 || station.getLattitude() > 50) {
|
||||||
return ResponseEntity.status(400).body("Der Breitengrad einer Station ist außerhalb der Bundesgartenschau");
|
|
||||||
|
return ResponseEntity.status(400).body("Der Breitengrad der Station " + position + " ist außerhalb der Bundesgartenschau. Dieser muss zwischen 49 und 50 liegen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (station.getLongitude() < 9 || station.getLongitude() > 10) {
|
if (station.getLongitude() < 9 || station.getLongitude() > 10) {
|
||||||
return ResponseEntity.status(400).body("Der Längengrad einer Station ist außerhalb der Bundesgartenschau");
|
return ResponseEntity.status(400).body("Der Längengrad der Station " + position + " ist außerhalb der Bundesgartenschau. Dieser muss zwischen 9 und 10 liegen.");
|
||||||
}
|
}
|
||||||
|
|
||||||
Random r = new Random();
|
Random r = new Random();
|
||||||
@ -135,12 +138,13 @@ public class CacheConstructionUtil {
|
|||||||
|
|
||||||
ResponseEntity response = new ResponseEntity(HttpStatus.ACCEPTED);
|
ResponseEntity response = new ResponseEntity(HttpStatus.ACCEPTED);
|
||||||
List<Station> newCreatedStationList = new ArrayList<Station>();
|
List<Station> newCreatedStationList = new ArrayList<Station>();
|
||||||
|
int position = 1;
|
||||||
for (Station station : cache.getStationen()) {
|
for (Station station : cache.getStationen()) {
|
||||||
boolean stationIsNew = true;
|
boolean stationIsNew = true;
|
||||||
for (Station oldStation : oldCache.getStationen()) {
|
for (Station oldStation : oldCache.getStationen()) {
|
||||||
// wenn Station schon vorher vorhanden war, wird diese mit den neuen Daten geupdatet
|
// wenn Station schon vorher vorhanden war, wird diese mit den neuen Daten geupdatet
|
||||||
if (oldStation.getId() == station.getId()) {
|
if (oldStation.getId() == station.getId()) {
|
||||||
response = createStationUtil(station);
|
response = createStationUtil(station, position);
|
||||||
stationIsNew = false;
|
stationIsNew = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@ -148,7 +152,7 @@ public class CacheConstructionUtil {
|
|||||||
|
|
||||||
// wenn Station neu hinzugefügt wurde, wirdcd die Station zusätzlich in die Datenbank gespeichert
|
// wenn Station neu hinzugefügt wurde, wirdcd die Station zusätzlich in die Datenbank gespeichert
|
||||||
if (stationIsNew) {
|
if (stationIsNew) {
|
||||||
response = createStationUtil(station);
|
response = createStationUtil(station, position);
|
||||||
if (response.getStatusCodeValue() == 200) {
|
if (response.getStatusCodeValue() == 200) {
|
||||||
newCreatedStationList.add(station);
|
newCreatedStationList.add(station);
|
||||||
}
|
}
|
||||||
@ -163,6 +167,7 @@ public class CacheConstructionUtil {
|
|||||||
deleteNewCreatedStationsUtil(newCreatedStationList);
|
deleteNewCreatedStationsUtil(newCreatedStationList);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
position++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// überprüft den Cache nach validen Daten
|
// überprüft den Cache nach validen Daten
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user