-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #504 from bcgov/1.3.1
1.3.1 - 1.3.2
- Loading branch information
Showing
73 changed files
with
3,932 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Hmcr.Api.Controllers.Base; | ||
using Hmcr.Domain.Services; | ||
using Hmcr.Model; | ||
using Hmcr.Model.Dtos.ActivityRule; | ||
using Hmcr.Model.Dtos.User; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
|
||
namespace Hmcr.Api.Controllers | ||
{ | ||
[ApiVersion("1.0")] | ||
[Route("api/activityrule")] | ||
[ApiController] | ||
public class ActivityRuleController : HmcrControllerBase | ||
{ | ||
private IActivityRuleService _activityRuleSvc; | ||
public ActivityRuleController(IActivityRuleService activityRuleSvc) | ||
{ | ||
_activityRuleSvc = activityRuleSvc; | ||
} | ||
|
||
[HttpGet("roadlength")] | ||
public async Task<ActionResult<IEnumerable<ActivityCodeRuleDto>>> GetRoadLengthRulesAsync() | ||
{ | ||
return Ok(await _activityRuleSvc.GetRoadLengthRulesAsync()); | ||
} | ||
|
||
[HttpGet("surfacetype")] | ||
public async Task<ActionResult<IEnumerable<ActivityCodeRuleDto>>> GetSurfaceTypeRulesAsync() | ||
{ | ||
return Ok(await _activityRuleSvc.GetSurfaceTypeRulesAsync()); | ||
} | ||
|
||
[HttpGet("roadclass")] | ||
public async Task<ActionResult<IEnumerable<ActivityCodeRuleDto>>> GetRoadClassRulesAsync() | ||
{ | ||
return Ok(await _activityRuleSvc.GetRoadClassRulesAsync()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
using Hmcr.Chris.Models; | ||
using Microsoft.Extensions.Configuration; | ||
using System.Collections.Generic; | ||
using System.Net.Http; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
|
||
namespace Hmcr.Chris | ||
{ | ||
public interface IInventoryApi | ||
{ | ||
Task<List<SurfaceType>> GetSurfaceTypeAssociatedWithLine(string lineStringCoordinates); | ||
Task<SurfaceType> GetSurfaceTypeAssociatedWithPoint(string lineStringCoordinates); | ||
|
||
//TODO: implement MC calls to CHRIS | ||
|
||
} | ||
|
||
public class InventoryApi : IInventoryApi | ||
{ | ||
private HttpClient _client; | ||
private InventoryQueries _queries; | ||
private IApi _api; | ||
private string _path; | ||
|
||
/// <summary> | ||
/// Chris Query typeName values, used to call the Get Inventory | ||
/// Assoc with Work Activity Query. | ||
/// </summary> | ||
public static class InventoryQueryTypeName | ||
{ | ||
public const string SURF_ASSOC_WITH_LINE = "SURF_ASSOCIATED_WITH_LINE"; | ||
public const string SURF_ASSOC_WITH_POINT = "SURF_ASSOCIATED_WITH_POINT"; | ||
public const string MC_ASSOC_WITH_LINE = "MC_ASSOCIATED_WITH_LINE"; | ||
public const string MC_ASSOC_WITH_POINT = "MC_ASSOCIATED_WITH_POINT"; | ||
} | ||
|
||
public InventoryApi(HttpClient client, IApi api, IConfiguration config) | ||
{ | ||
_client = client; | ||
_queries = new InventoryQueries(); | ||
_api = api; | ||
_path = config.GetValue<string>("CHRIS:OASPath"); | ||
} | ||
|
||
public async Task<SurfaceType> GetSurfaceTypeAssociatedWithPoint(string lineStringCoordinates) | ||
{ | ||
var body = string.Format(_queries.SurfaceTypeAssocWithPointQuery, lineStringCoordinates, InventoryQueryTypeName.SURF_ASSOC_WITH_POINT); | ||
|
||
var contents = await (await _api.PostWithRetry(_client, _path, body)).Content.ReadAsStringAsync(); | ||
|
||
var results = JsonSerializer.Deserialize<FeatureCollection<object>>(contents); | ||
|
||
SurfaceType surfaceType = new SurfaceType(); | ||
if (results.features.Length > 0) | ||
{ | ||
surfaceType.Type = results.features[0].properties.SURFACE_TYPE; | ||
} | ||
|
||
return surfaceType; | ||
} | ||
|
||
public async Task<List<SurfaceType>> GetSurfaceTypeAssociatedWithLine(string lineStringCoordinates) | ||
{ | ||
var body = string.Format(_queries.SurfaceTypeAssocWithLineQuery, lineStringCoordinates, InventoryQueryTypeName.SURF_ASSOC_WITH_LINE); | ||
|
||
var contents = await (await _api.PostWithRetry(_client, _path, body)).Content.ReadAsStringAsync(); | ||
|
||
var results = JsonSerializer.Deserialize<FeatureCollection<object>>(contents); | ||
|
||
var surfaceTypes = new List<SurfaceType>(); | ||
|
||
foreach (var feature in results.features) | ||
{ | ||
SurfaceType surfaceType = new SurfaceType(); | ||
surfaceType.Length = feature.properties.CLIPPED_LENGTH_KM; | ||
surfaceType.Type = feature.properties.SURFACE_TYPE; | ||
|
||
surfaceTypes.Add(surfaceType); | ||
} | ||
|
||
return surfaceTypes; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
using System.IO; | ||
using System.Reflection; | ||
|
||
namespace Hmcr.Chris | ||
{ | ||
public class InventoryQueries | ||
{ | ||
private string _surfaceTypeAssocWithLineQuery; | ||
private string _surfaceTypeAssocWithPointQuery; | ||
|
||
public string SurfaceTypeAssocWithLineQuery | ||
{ | ||
get | ||
{ | ||
var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "XmlTemplates"); | ||
return _surfaceTypeAssocWithLineQuery ?? (_surfaceTypeAssocWithLineQuery = File.ReadAllText(Path.Combine(folder, "GetInventoryAssocWithWorkActivity.xml"))); | ||
} | ||
} | ||
|
||
public string SurfaceTypeAssocWithPointQuery | ||
{ | ||
get | ||
{ | ||
var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "XmlTemplates"); | ||
return _surfaceTypeAssocWithPointQuery ?? (_surfaceTypeAssocWithPointQuery = File.ReadAllText(Path.Combine(folder, "GetInventoryAssocWithWorkActivity.xml"))); | ||
} | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace Hmcr.Chris.Models | ||
{ | ||
public class SurfaceType | ||
{ | ||
|
||
public Geometry geometry { get; set; } | ||
/// <summary> | ||
/// Length in Meters | ||
/// </summary> | ||
public double Length { get; set; } | ||
|
||
public string Type { get; set; } | ||
|
||
} | ||
public class SurfaceType<T> | ||
{ | ||
|
||
public Geometry geometry { get; set; } | ||
/// <summary> | ||
/// Length in Meters | ||
/// </summary> | ||
public double Length { get; set; } | ||
|
||
public string Type { get; set; } | ||
|
||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
api/Hmcr.Chris/XmlTemplates/GetInventoryAssocWithWorkActivity.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<wfs:GetFeature service="WFS" | ||
version="1.1.0" | ||
outputFormat="json" | ||
maxFeatures="50" | ||
viewParams="epsg:4326;coordinates:{0}" | ||
xmlns:topp="http://www.openplans.org/topp" | ||
xmlns:wfs="http://www.opengis.net/wfs" | ||
xmlns="http://www.opengis.net/ogc" | ||
xmlns:gml="http://www.opengis.net/gml" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.opengis.net/wfs | ||
http://schemas.opengis.net/wfs/1.1.0/WFS-basic.xsd"> | ||
<wfs:Query typeName="cwr:{1}" srsName="EPSG:3005"/> | ||
</wfs:GetFeature> |
Oops, something went wrong.