Skip to content

Commit 13bf673

Browse files
authored
Merge pull request #1165 from bcgov/test
UAT Release - IS23
2 parents fa26356 + d039819 commit 13bf673

File tree

363 files changed

+86619
-1606
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

363 files changed

+86619
-1606
lines changed

backend/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
ARG BUILD_CONFIGURATION=Release
2-
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
2+
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
33
WORKDIR /app
44
EXPOSE 443 8080
55

66
# Copy csproj and restore as distinct layers
7-
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
7+
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
88
WORKDIR /src
99
COPY *.sln .
1010
COPY Directory.Build.props .

backend/api/Areas/Admin/Mapping/AccessRequest/AccessRequestMap.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Mapster;
2-
using System.Linq;
32
using Entity = Pims.Dal.Entities;
43
using Model = Pims.Api.Areas.Admin.Models.AccessRequest;
54

backend/api/Areas/Keycloak/Mapping/AccessRequest/AccessRequestMap.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using Mapster;
2-
using System.Linq;
32
using Entity = Pims.Dal.Entities;
43
using Model = Pims.Api.Areas.Keycloak.Models.AccessRequest;
54

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
using Microsoft.AspNetCore.Authorization;
2+
using Microsoft.AspNetCore.Http;
3+
using Microsoft.AspNetCore.Mvc;
4+
using Pims.Api.Policies;
5+
using Pims.Api.Services;
6+
using Pims.Dal.Security;
7+
using Swashbuckle.AspNetCore.Annotations;
8+
9+
namespace Pims.Api.Controllers
10+
{
11+
/// <summary>
12+
/// DocumentController class, provides endpoints to handle document requests.
13+
/// </summary>
14+
[Authorize]
15+
[ApiController]
16+
[ApiVersion("1.0")]
17+
[Route("v{version:apiVersion}/documents/")]
18+
[Route("/documents")]
19+
public class DocumentController : ControllerBase
20+
{
21+
#region Variables
22+
private readonly IDocumentService _documentService;
23+
#endregion
24+
25+
#region Constructors
26+
/// <summary>
27+
/// Creates a new instance of a ErrorController class.
28+
/// </summary>
29+
/// <param name="documentService"></param>
30+
public DocumentController(IDocumentService documentService)
31+
{
32+
_documentService = documentService;
33+
}
34+
#endregion
35+
36+
#region Endpoints
37+
/// <summary>
38+
/// Retrieves a list of documents.
39+
/// </summary>
40+
[HttpGet]
41+
[HasPermission(Permissions.PropertyAdd)]
42+
[Produces("application/json")]
43+
[ProducesResponseType(typeof(string), 200)]
44+
[SwaggerOperation(Tags = new[] { "documents" })]
45+
public IActionResult GetDocumentList()
46+
{
47+
var ast = _documentService.GetDocumentList();
48+
return new JsonResult(ast);
49+
}
50+
51+
/// <summary>
52+
/// Downloads the file for the correspoding file and document id.
53+
/// </summary>
54+
[HttpGet("{documentId}/files/{fileId}/download")]
55+
[HasPermission(Permissions.PropertyAdd)]
56+
[ProducesResponseType(typeof(string), 200)]
57+
[SwaggerOperation(Tags = new[] { "documents" })]
58+
public IActionResult DownloadFile(int documentId, int fileId)
59+
{
60+
var ast = _documentService.DownloadFile(documentId, fileId);
61+
return new JsonResult(ast);
62+
}
63+
64+
/// <summary>
65+
/// Uploads the passed document.
66+
/// </summary>
67+
[HttpPost]
68+
[HasPermission(Permissions.PropertyAdd)]
69+
[ProducesResponseType(typeof(string), 200)]
70+
[SwaggerOperation(Tags = new[] { "documents" })]
71+
public IActionResult UploadDocument([FromForm] IFormFile file)
72+
{
73+
var ast = _documentService.UploadDocument(1, file);
74+
return new JsonResult(ast);
75+
}
76+
77+
#endregion
78+
}
79+
}

backend/api/Handlers/LogginHandler.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
using System.Net.Http;
2+
using System.Threading;
3+
using System.Threading.Tasks;
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace Pims.Api.Handlers
7+
{
8+
public class LoggingHandler : DelegatingHandler
9+
{
10+
private readonly ILogger _logger;
11+
12+
public LoggingHandler(ILogger<LoggingHandler> logger)
13+
{
14+
_logger = logger;
15+
}
16+
17+
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
18+
{
19+
_logger.LogTrace("Request:");
20+
_logger.LogTrace("{request}", request.ToString());
21+
if (request.Content != null)
22+
{
23+
_logger.LogTrace("{cancellationToken}", await request.Content.ReadAsStringAsync(cancellationToken));
24+
}
25+
26+
HttpResponseMessage response = await base.SendAsync(request, cancellationToken);
27+
28+
_logger.LogTrace("Response:");
29+
_logger.LogTrace("{response}", response.ToString());
30+
if (response.Content != null)
31+
{
32+
_logger.LogTrace("{cancellationToken}", await response.Content.ReadAsStringAsync(cancellationToken));
33+
}
34+
35+
return response;
36+
}
37+
}
38+
}

backend/api/Helpers/Logging/LoggerExtension.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
13
using Microsoft.Extensions.Configuration;
24
using Microsoft.Extensions.DependencyInjection;
35
using Serilog;
4-
using System;
5-
using System.Diagnostics.CodeAnalysis;
66

77
namespace Pims.Api.Helpers.Logging
88
{
@@ -14,7 +14,7 @@ public static IServiceCollection AddSerilogging(
1414
)
1515
{
1616
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
17-
if (environment != null && !environment.EndsWith("Local"))
17+
if (environment != null)
1818
{
1919

2020
Log.Logger = new LoggerConfiguration()

backend/api/Helpers/Middleware/LogRequestMiddleware.cs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1+
using System;
2+
using System.Diagnostics.CodeAnalysis;
3+
using System.IO;
4+
using System.Threading.Tasks;
15
using Microsoft.AspNetCore.Http;
26
using Microsoft.Extensions.Logging;
37
using Microsoft.IO;
48
using Pims.Core.Extensions;
59
using Serilog;
6-
using System;
7-
using System.Diagnostics.CodeAnalysis;
8-
using System.IO;
9-
using System.Threading.Tasks;
1010

1111
namespace Pims.Api.Helpers.Middleware
1212
{
@@ -55,10 +55,15 @@ public async Task Invoke(HttpContext context)
5555
body = streamReader.ReadToEnd();
5656
}
5757

58-
using (_logger.BeginScope("HTTP Response"))
58+
using (_logger.BeginScope("HTTP Request"))
5959
{
60-
if (!Log.IsEnabled(Serilog.Events.LogEventLevel.Debug)) _logger.LogInformation($"HTTP Request {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}");
61-
_logger.LogDebug($"HTTP Request {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}" + (String.IsNullOrEmpty(body) ? String.Empty : $"{System.Environment.NewLine}Body: {body}"));
60+
if (!Log.IsEnabled(Serilog.Events.LogEventLevel.Debug))
61+
{
62+
_logger.LogInformation($"HTTP Request {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}");
63+
}
64+
65+
_logger.LogDebug($"HTTP Request {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}");
66+
_logger.LogTrace(string.IsNullOrEmpty(body) ? string.Empty : $"{System.Environment.NewLine}Body: {body}");
6267
}
6368

6469

backend/api/Helpers/Middleware/LogResponseMiddleware.cs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,12 @@ private async Task LogResponse(HttpContext context)
6767

6868
using (_logger.BeginScope("HTTP Response"))
6969
{
70-
if (!Log.IsEnabled(Serilog.Events.LogEventLevel.Debug)) _logger.LogInformation($"HTTP Response {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}{System.Environment.NewLine}");
71-
_logger.LogDebug($"HTTP Response {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}" + (String.IsNullOrEmpty(body) ? String.Empty : $"{System.Environment.NewLine}Body: {body}"));
70+
if (!Log.IsEnabled(Serilog.Events.LogEventLevel.Debug))
71+
{
72+
_logger.LogInformation($"HTTP Response {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}{System.Environment.NewLine}");
73+
}
74+
_logger.LogDebug($"HTTP Response {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}");
75+
_logger.LogTrace(string.IsNullOrEmpty(body) ? string.Empty : $"{System.Environment.NewLine}Body: {body}");
7276
}
7377

7478
await responseBody.CopyToAsync(originalBodyStream);

backend/api/Mapping/AccessRequest/AccessRequestMap.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
using System.Linq;
21
using Mapster;
32
using Entity = Pims.Dal.Entities;
43
using Model = Pims.Api.Models.AccessRequest;
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using System;
2+
3+
namespace Pims.Api.Models.Config
4+
{
5+
public class MayanConfig
6+
{
7+
public Uri BaseUri { get; set; }
8+
public string ConnectionUser { get; set; }
9+
public string ConnectionPassword { get; set; }
10+
}
11+
}

backend/api/Models/ExternalResult.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
namespace Pims.Api.Models
2+
{
3+
/// <summary>
4+
/// Defines the results comming back from an external resource.
5+
/// </summary>
6+
public class ExternalResult<T>
7+
{
8+
/// <summary>
9+
/// get/set - Result status.
10+
/// </summary>
11+
public ExternalResultStatus Status { get; set; }
12+
13+
/// <summary>
14+
/// get/set - Additional message for the result.
15+
/// </summary>
16+
public string Message { get; set; }
17+
18+
/// <summary>
19+
/// get/set - A description of the type.
20+
/// </summary>
21+
public T Payload { get; set; }
22+
}
23+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System.Runtime.Serialization;
2+
using System.Text.Json.Serialization;
3+
4+
namespace Pims.Api.Models
5+
{
6+
/// <summary>
7+
/// Status of an external call.
8+
/// </summary>
9+
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
10+
public enum ExternalResultStatus
11+
{
12+
/// <summary>
13+
/// The call was successfull.
14+
/// </summary>
15+
[EnumMember(Value = "success")]
16+
Success,
17+
18+
/// <summary>
19+
/// Error occured.
20+
/// </summary>
21+
[EnumMember(Value = "error")]
22+
Error,
23+
}
24+
}
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
using System;
2+
using System.Text.Json.Serialization;
3+
4+
namespace Pims.Api.Models.Mayan.Document
5+
{
6+
/// <summary>
7+
/// Represents the document result information. Note, this does not contain the stored document.
8+
/// </summary>
9+
public class DocumentDetail
10+
{
11+
/// <summary>
12+
/// get/set - The document id.
13+
/// </summary>
14+
[JsonPropertyName("id")]
15+
public int Id { get; set; }
16+
17+
/// <summary>
18+
/// get/set - Document label.
19+
/// </summary>
20+
[JsonPropertyName("label")]
21+
public string Label { get; set; }
22+
23+
/// <summary>
24+
/// get/set - Total number of results.
25+
/// </summary>
26+
[JsonPropertyName("datetime_created")]
27+
public DateTime DatetimeCreated { get; set; }
28+
29+
/// <summary>
30+
/// get/set - The results of the query.
31+
/// </summary>
32+
[JsonPropertyName("description")]
33+
public string Description { get; set; }
34+
35+
/// <summary>
36+
/// get/set - The results of the query.
37+
/// </summary>
38+
[JsonPropertyName("file_latest")]
39+
public FileLatest FileLatest { get; set; }
40+
41+
42+
}
43+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
namespace Pims.Api.Models.Mayan.Document
2+
{
3+
/// <summary>
4+
/// Represents a file download result.
5+
/// </summary>
6+
public class FileDownload
7+
{
8+
/// <summary>
9+
/// get/set - The file contents. Could be encoded.
10+
/// </summary>
11+
public byte[] FilePayload { get; set; }
12+
13+
/// <summary>
14+
/// get/set - The file size
15+
/// </summary>
16+
public int Size { get; set; }
17+
18+
/// <summary>
19+
/// get/set - Name of the file.
20+
/// </summary>
21+
public string FileName { get; set; }
22+
23+
/// <summary>
24+
/// get/set - THe Mime-Type that the file uses.
25+
/// </summary>
26+
public string Mimetype { get; set; }
27+
}
28+
}

0 commit comments

Comments
 (0)