Skip to content

Commit

Permalink
Sprint release 09 (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
Corgam authored Jun 26, 2024
2 parents d6c18e0 + 889e576 commit ecaa6a5
Show file tree
Hide file tree
Showing 142 changed files with 1,164 additions and 352 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/deploy_production.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,6 @@ jobs:
scp ./docker-compose.yml ${{secrets.PROD_ENV_SSH_USER}}@${{secrets.PROD_ENV_SSH_HOST}}:/var/lib/bie
scp ./.env.production ${{secrets.PROD_ENV_SSH_USER}}@${{secrets.PROD_ENV_SSH_HOST}}:/var/lib/bie/.env
- name: Connect and Pull
run: ssh ${{secrets.PROD_ENV_SSH_USER}}@${{secrets.PROD_ENV_SSH_HOST}} "cd /var/lib/bie && docker compose down --remove-orphans && docker compose pull && docker compose up -d --remove-orphans && exit"
run: ssh ${{secrets.PROD_ENV_SSH_USER}}@${{secrets.PROD_ENV_SSH_HOST}} "cd /var/lib/bie && docker compose pull && docker compose up -d --remove-orphans --force-recreate && exit"
- name: Cleanup
run: rm -rf ~/.ssh
2 changes: 1 addition & 1 deletion .github/workflows/deploy_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ jobs:
scp ./.env.test ${{ secrets.TEST_ENV_SSH_USER }}@${{ secrets.TEST_ENV_SSH_HOST }}:/var/lib/bie/.env
- name: Connect and Pull
run: ssh ${{ secrets.TEST_ENV_SSH_USER }}@${{ secrets.TEST_ENV_SSH_HOST }} "cd /var/lib/bie && docker compose down --remove-orphans && docker compose pull && docker compose up -d --remove-orphans && exit"
run: ssh ${{ secrets.TEST_ENV_SSH_USER }}@${{ secrets.TEST_ENV_SSH_HOST }} "cd /var/lib/bie && docker compose pull && docker compose up -d --remove-orphans --force-recreate && exit"

- name: Cleanup
run: rm -rf ~/.ssh
86 changes: 48 additions & 38 deletions backend/api-gateway/Controllers/APIGatewayController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using System.Net.Mime;
using System.Text;

namespace BIE.Core.API.Controllers
{
Expand All @@ -31,7 +33,7 @@ public APIGatewayController(HttpClient httpClient, ILogger<APIGatewayController>
/// </summary>
/// <returns>A list of available datasets</returns>
[HttpGet("getDatasetList")]
[ProducesResponseType(typeof(List<DatasetBasicData>), 200)]
[ProducesResponseType(typeof(List<MetadataObject.BasicData>), 200)]
[ProducesResponseType(400)]
public async Task<IActionResult> GetDataSetList()
{
Expand All @@ -42,18 +44,18 @@ public async Task<IActionResult> GetDataSetList()

var collection = _mongoDBService.GetDatasetsCollection();
var datasets = await collection.Find(_ => true).ToListAsync();
var datasetBasicDataList = datasets.Select(d => d.BasicData).ToList();
var datasetBasicDataList = datasets.Select(d => d.basicData).ToList();

return Ok(datasetBasicDataList);
}

/// <summary>
/// Gets the metadata for the given dataset. Contains things like Icon, visualization types
/// Gets the metadata for the given dataset. Contains things like Icon, visualization types and max zoom level
/// </summary>
/// <param name="datasetID">The ID of the dataset</param>
/// <returns>Metadata for the specified dataset</returns>
[HttpGet("getDatasetMetadata")]
[ProducesResponseType(typeof(DatasetMetadata), 200)]
[ProducesResponseType(typeof(MetadataObject), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(404)]
public async Task<IActionResult> GetDatasetMetadata([FromQuery, Required] string datasetID)
Expand All @@ -64,18 +66,18 @@ public async Task<IActionResult> GetDatasetMetadata([FromQuery, Required] string
}

var collection = _mongoDBService.GetDatasetsCollection();
var dataset = await collection.Find(d => d.BasicData.DatasetId == datasetID).FirstOrDefaultAsync();
var dataset = await collection.Find(d => d.basicData.DatasetId == datasetID).FirstOrDefaultAsync();

if (dataset == null)
{
return NotFound($"Dataset with ID {datasetID} not found.");
}

return Ok(dataset.MetaData);
return Ok(dataset.additionalData);
}

/// <summary>
/// Loads the location data for the given point or polygon.
/// Loads the location data for the given point or polygon.
/// </summary>
/// <param name="request">Contains the current dataset id and the list of coordinates.
/// In case of a single point a list with a single element.</param>
Expand All @@ -84,7 +86,7 @@ public async Task<IActionResult> GetDatasetMetadata([FromQuery, Required] string
[ProducesResponseType(typeof(LocationDataResponse), 200)]
[ProducesResponseType(400)]
[ProducesResponseType(500)]
public IActionResult LoadLocationData([FromBody, Required] LocationDataRequest request)
public async Task<IActionResult> LoadLocationData([FromBody, Required] LocationDataRequest request)
{
if (!ModelState.IsValid)
{
Expand All @@ -93,22 +95,46 @@ public IActionResult LoadLocationData([FromBody, Required] LocationDataRequest r

_logger.LogInformation($"Fetching data for DatasetID: {request.DatasetId}");

// Generate mock data for the current dataset
var currentDatasetData = GenerateMockData("charging_stations", 3);

// Generate mock data for general data from other datasets
var generalData = GenerateMockData("house_footprints", 3);
// Get the first coordinate from the list for now
var coordinate = request.Location.FirstOrDefault();
if (coordinate == null)
{
return BadRequest("No coordinates provided.");
}

var extraRows = GenerateMockData("extra_dataset", 1);
// Construct the target URL with query parameters

var response = new LocationDataResponse
try
{
CurrentDatasetData = currentDatasetData,
GeneralData = generalData,
ExtraRows = extraRows
};
var request1 = new HttpRequestMessage
{
Method = HttpMethod.Put,
RequestUri = new Uri("http://api-composer:80/api/v1.0/Dataset/loadLocationData"),
Content = new StringContent(
JsonSerializer.Serialize(request),
Encoding.UTF8,
MediaTypeNames.Application.Json), // or "application/json" in older versions
};

var response = await _httpClient.SendAsync(request1);
response.EnsureSuccessStatusCode(); // Throw if not a success code.

return Ok(response);
var content = await response.Content.ReadAsStringAsync();
var locationDataResponse = JsonSerializer.Deserialize<LocationDataResponse>(content);

return Ok(locationDataResponse);
}
catch (HttpRequestException ex)
{
_logger.LogError(ex, "Error fetching data from the target service.");
return StatusCode(500, "Error fetching data from the target service.");
}
catch (Exception ex)
{
_logger.LogError(ex, "An unexpected error occurred.");
return StatusCode(500, "An unexpected error occurred.");
}

}

// Helper method to generate mock data
Expand Down Expand Up @@ -161,30 +187,14 @@ public async Task<IActionResult> GetDatasetViewportData(

_logger.LogInformation($"Fetching data for DatasetID: {datasetID}, ZoomLevel: {zoomLevel}, Viewport: [{BottomLat}, {BottomLong}] to [{TopLat}, {TopLong}]");

string targetUrl;
if (datasetID == "charging_stations")
{
targetUrl = $"http://api-composer:80/api/v1.0/Dataset/1/data?ZoomLevel={zoomLevel}&BottomLat={BottomLat}&BottomLong={BottomLong}&TopLat={TopLat}&TopLong={TopLong}";
}
else if (datasetID == "house_footprints")
{
return Ok(MockData.MockHouseFootprints);
//targetUrl = $"http://api-composer:80/api/v1.0/Dataset/2/data?ZoomLevel={zoomLevel}&BottomLat={BottomLat}&BottomLong={BottomLong}&TopLat={TopLat}&TopLong={TopLong}";
}
else
{
_logger.LogError($"Unsupported dataset ID of {datasetID}");
return StatusCode(400, $"Unsupported dataset ID of {datasetID}");
}
string targetUrl = $"http://api-composer:80/api/v1.0/Dataset/getDatasetViewportData?Id={datasetID}&ZoomLevel={zoomLevel}&BottomLat={BottomLat}&BottomLong={BottomLong}&TopLat={TopLat}&TopLong={TopLong}";

try
{
var response = await _httpClient.GetAsync(targetUrl);
response.EnsureSuccessStatusCode(); // Throw if not a success code.
var content = await response.Content.ReadAsStringAsync();
var geoJsonResponse = JsonSerializer.Deserialize<GeoJsonResponse>(content);

return Ok(geoJsonResponse);
return Ok(content);
}
catch (HttpRequestException ex)
{
Expand Down
10 changes: 0 additions & 10 deletions backend/api-gateway/Models/DatasetBasicData.cs

This file was deleted.

18 changes: 0 additions & 18 deletions backend/api-gateway/Models/DatasetData.cs

This file was deleted.

18 changes: 0 additions & 18 deletions backend/api-gateway/Models/DatasetMetadata.cs

This file was deleted.

16 changes: 8 additions & 8 deletions backend/api-gateway/Models/GeoJsonResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,25 @@ namespace APIGateway.Models

public class GeoJsonResponse
{
public string type { get; set; }
public List<Feature> features { get; set; }
public string type { get; set; } = string.Empty;
public List<Feature> features { get; set; } = new List<Feature>();
}

public class Feature
{
public string type { get; set; }
public Geometry geometry { get; set; }
public Properties properties { get; set; }
public string type { get; set; } = string.Empty;
public Geometry geometry { get; set; } = new Geometry();
public Properties properties { get; set; } = new Properties();
}

public class Geometry
{
public string type { get; set; }
public List<float> coordinates { get; set; }
public string type { get; set; } = string.Empty;
public List<float> coordinates { get; set; } = new List<float>();
}

public class Properties
{
public string name { get; set; }
public string name { get; set; } = string.Empty;
}
}
21 changes: 10 additions & 11 deletions backend/api-gateway/Models/LocationData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,29 @@
{
public class LocationDataRequest
{
public string DatasetId { get; set; }
public List<Coordinate> Location { get; set; }
public string DatasetId { get; set; } = string.Empty;
public List<Coordinate> Location { get; set; } = new List<Coordinate>();
}

public class Coordinate
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public double Latitude { get; set; } = 0;
public double Longitude { get; set; } = 0;
}

public class LocationDataResponse
{
public List<DatasetItem> CurrentDatasetData { get; set; }
public List<DatasetItem> GeneralData { get; set; }
public object ExtraRows { get; internal set; }
public List<DatasetItem> CurrentDatasetData { get; set; } = new List<DatasetItem>();
public List<DatasetItem> GeneralData { get; set; } = new List<DatasetItem>();
}

public class DatasetItem
{
public string Id { get; set; }
public string Id { get; set; } = string.Empty;

public string Key { get; set; }
public string Value { get; set; }
public string MapId { get; set; } // Optional -> for "open in map" functionality
public string Key { get; set; } = string.Empty;
public string Value { get; set; } = string.Empty;
public string MapId { get; set; } = string.Empty; // Optional -> for "open in map" functionality
}


Expand Down
55 changes: 55 additions & 0 deletions backend/api-gateway/Models/MetadataObject.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
using MongoDB.Bson;
using MongoDB.Bson.Serialization.Attributes;

namespace APIGateway.Models;

public class MetadataObject
{
[BsonRepresentation(BsonType.ObjectId)]
public string _id { get; set; } = string.Empty;

[BsonElement("basicData")]
public BasicData basicData { get; set; } = new BasicData();

[BsonElement("additionalData")]
public AdditionalData additionalData { get; set; } = new AdditionalData();

// The general and most important data about a dataset.
public class BasicData
{
public string DatasetId { get; set; } = string.Empty;
public string Name { get; set; } = string.Empty;
public string ShortDescription { get; set; } = string.Empty;
public string Icon { get; set; } = string.Empty;
}

// The additional data for each of the datasets, queried at a request.
public class AdditionalData
{
public string Icon { get; set; } = string.Empty;
public string Type { get; set; } = string.Empty;

public string LongDescription { get; set; } = string.Empty;

// Zoom level is higher the closer you look at something. If current zoom level is below this, it shouldn't display any value.
public int MinZoomLevel { get; set; } = 0;

// The zoom threshold where areas start to turn into markers
public int MarkersThreshold { get; set; } = 0;

// The display property is the property that should be shown in a popup.
public string DisplayProperty { get; set; } = string.Empty;

// Table data populated by the data pipeline. Contains the name and the size of the all .yaml files correlated to that specific dataset.
public List<TableData> Tables { get; set; } = new List<TableData>();
}

// Table data populated by the data pipeline. Contains the name and the size of the all .yaml files correlated to that specific dataset.
public class TableData
{
// The name of the .yaml file
public string Name { get; set; } = string.Empty;
// The number of lines of data in that file.
public int NumberOfLines { get; set; } = 0;
}
}
4 changes: 2 additions & 2 deletions backend/api-gateway/Services/MongoDBService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ public MongoDBService(IConfiguration configuration)
_database = client.GetDatabase("bci-metadata");
}

public IMongoCollection<DatasetData> GetDatasetsCollection()
public IMongoCollection<MetadataObject> GetDatasetsCollection()
{
return _database.GetCollection<DatasetData>("datasets");
return _database.GetCollection<MetadataObject>("datasets");
}
}
}
Loading

0 comments on commit ecaa6a5

Please sign in to comment.