Skip to content

Commit

Permalink
Merge pull request #1165 from bcgov/test
Browse files Browse the repository at this point in the history
UAT Release - IS23
  • Loading branch information
asanchezr authored Mar 31, 2022
2 parents fa26356 + d039819 commit 13bf673
Show file tree
Hide file tree
Showing 363 changed files with 86,619 additions and 1,606 deletions.
4 changes: 2 additions & 2 deletions backend/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
ARG BUILD_CONFIGURATION=Release
FROM mcr.microsoft.com/dotnet/aspnet:5.0 AS base
FROM mcr.microsoft.com/dotnet/aspnet:6.0 AS base
WORKDIR /app
EXPOSE 443 8080

# Copy csproj and restore as distinct layers
FROM mcr.microsoft.com/dotnet/sdk:5.0 AS build
FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build
WORKDIR /src
COPY *.sln .
COPY Directory.Build.props .
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mapster;
using System.Linq;
using Entity = Pims.Dal.Entities;
using Model = Pims.Api.Areas.Admin.Models.AccessRequest;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Mapster;
using System.Linq;
using Entity = Pims.Dal.Entities;
using Model = Pims.Api.Areas.Keycloak.Models.AccessRequest;

Expand Down
79 changes: 79 additions & 0 deletions backend/api/Controllers/DocumentController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Pims.Api.Policies;
using Pims.Api.Services;
using Pims.Dal.Security;
using Swashbuckle.AspNetCore.Annotations;

namespace Pims.Api.Controllers
{
/// <summary>
/// DocumentController class, provides endpoints to handle document requests.
/// </summary>
[Authorize]
[ApiController]
[ApiVersion("1.0")]
[Route("v{version:apiVersion}/documents/")]
[Route("/documents")]
public class DocumentController : ControllerBase
{
#region Variables
private readonly IDocumentService _documentService;
#endregion

#region Constructors
/// <summary>
/// Creates a new instance of a ErrorController class.
/// </summary>
/// <param name="documentService"></param>
public DocumentController(IDocumentService documentService)
{
_documentService = documentService;
}
#endregion

#region Endpoints
/// <summary>
/// Retrieves a list of documents.
/// </summary>
[HttpGet]
[HasPermission(Permissions.PropertyAdd)]
[Produces("application/json")]
[ProducesResponseType(typeof(string), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public IActionResult GetDocumentList()
{
var ast = _documentService.GetDocumentList();
return new JsonResult(ast);
}

/// <summary>
/// Downloads the file for the correspoding file and document id.
/// </summary>
[HttpGet("{documentId}/files/{fileId}/download")]
[HasPermission(Permissions.PropertyAdd)]
[ProducesResponseType(typeof(string), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public IActionResult DownloadFile(int documentId, int fileId)
{
var ast = _documentService.DownloadFile(documentId, fileId);
return new JsonResult(ast);
}

/// <summary>
/// Uploads the passed document.
/// </summary>
[HttpPost]
[HasPermission(Permissions.PropertyAdd)]
[ProducesResponseType(typeof(string), 200)]
[SwaggerOperation(Tags = new[] { "documents" })]
public IActionResult UploadDocument([FromForm] IFormFile file)
{
var ast = _documentService.UploadDocument(1, file);
return new JsonResult(ast);
}

#endregion
}
}
38 changes: 38 additions & 0 deletions backend/api/Handlers/LogginHandler.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace Pims.Api.Handlers
{
public class LoggingHandler : DelegatingHandler
{
private readonly ILogger _logger;

public LoggingHandler(ILogger<LoggingHandler> logger)
{
_logger = logger;
}

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
_logger.LogTrace("Request:");
_logger.LogTrace("{request}", request.ToString());
if (request.Content != null)
{
_logger.LogTrace("{cancellationToken}", await request.Content.ReadAsStringAsync(cancellationToken));
}

HttpResponseMessage response = await base.SendAsync(request, cancellationToken);

_logger.LogTrace("Response:");
_logger.LogTrace("{response}", response.ToString());
if (response.Content != null)
{
_logger.LogTrace("{cancellationToken}", await response.Content.ReadAsStringAsync(cancellationToken));
}

return response;
}
}
}
6 changes: 3 additions & 3 deletions backend/api/Helpers/Logging/LoggerExtension.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Serilog;
using System;
using System.Diagnostics.CodeAnalysis;

namespace Pims.Api.Helpers.Logging
{
Expand All @@ -14,7 +14,7 @@ public static IServiceCollection AddSerilogging(
)
{
var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");
if (environment != null && !environment.EndsWith("Local"))
if (environment != null)
{

Log.Logger = new LoggerConfiguration()
Expand Down
19 changes: 12 additions & 7 deletions backend/api/Helpers/Middleware/LogRequestMiddleware.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.IO;
using Pims.Core.Extensions;
using Serilog;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Threading.Tasks;

namespace Pims.Api.Helpers.Middleware
{
Expand Down Expand Up @@ -55,10 +55,15 @@ public async Task Invoke(HttpContext context)
body = streamReader.ReadToEnd();
}

using (_logger.BeginScope("HTTP Response"))
using (_logger.BeginScope("HTTP Request"))
{
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}");
_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}"));
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}");
}

_logger.LogDebug($"HTTP Request {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}");
_logger.LogTrace(string.IsNullOrEmpty(body) ? string.Empty : $"{System.Environment.NewLine}Body: {body}");
}


Expand Down
8 changes: 6 additions & 2 deletions backend/api/Helpers/Middleware/LogResponseMiddleware.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,12 @@ private async Task LogResponse(HttpContext context)

using (_logger.BeginScope("HTTP Response"))
{
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}");
_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}"));
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}");
}
_logger.LogDebug($"HTTP Response {context.Request.Method} user:{context.User.GetDisplayName()} {context.Request.Scheme}://{context.Request.Host}{context.Request.Path}{context.Request.QueryString}");
_logger.LogTrace(string.IsNullOrEmpty(body) ? string.Empty : $"{System.Environment.NewLine}Body: {body}");
}

await responseBody.CopyToAsync(originalBodyStream);
Expand Down
1 change: 0 additions & 1 deletion backend/api/Mapping/AccessRequest/AccessRequestMap.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Linq;
using Mapster;
using Entity = Pims.Dal.Entities;
using Model = Pims.Api.Models.AccessRequest;
Expand Down
11 changes: 11 additions & 0 deletions backend/api/Models/Configuration/MayanConfig.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
using System;

namespace Pims.Api.Models.Config
{
public class MayanConfig
{
public Uri BaseUri { get; set; }
public string ConnectionUser { get; set; }
public string ConnectionPassword { get; set; }
}
}
23 changes: 23 additions & 0 deletions backend/api/Models/ExternalResult.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace Pims.Api.Models
{
/// <summary>
/// Defines the results comming back from an external resource.
/// </summary>
public class ExternalResult<T>
{
/// <summary>
/// get/set - Result status.
/// </summary>
public ExternalResultStatus Status { get; set; }

/// <summary>
/// get/set - Additional message for the result.
/// </summary>
public string Message { get; set; }

/// <summary>
/// get/set - A description of the type.
/// </summary>
public T Payload { get; set; }
}
}
24 changes: 24 additions & 0 deletions backend/api/Models/ExternalResultStatus.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace Pims.Api.Models
{
/// <summary>
/// Status of an external call.
/// </summary>
[JsonConverter(typeof(JsonStringEnumMemberConverter))]
public enum ExternalResultStatus
{
/// <summary>
/// The call was successfull.
/// </summary>
[EnumMember(Value = "success")]
Success,

/// <summary>
/// Error occured.
/// </summary>
[EnumMember(Value = "error")]
Error,
}
}
43 changes: 43 additions & 0 deletions backend/api/Models/Mayan/Document/DocumentDetail.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
using System;
using System.Text.Json.Serialization;

namespace Pims.Api.Models.Mayan.Document
{
/// <summary>
/// Represents the document result information. Note, this does not contain the stored document.
/// </summary>
public class DocumentDetail
{
/// <summary>
/// get/set - The document id.
/// </summary>
[JsonPropertyName("id")]
public int Id { get; set; }

/// <summary>
/// get/set - Document label.
/// </summary>
[JsonPropertyName("label")]
public string Label { get; set; }

/// <summary>
/// get/set - Total number of results.
/// </summary>
[JsonPropertyName("datetime_created")]
public DateTime DatetimeCreated { get; set; }

/// <summary>
/// get/set - The results of the query.
/// </summary>
[JsonPropertyName("description")]
public string Description { get; set; }

/// <summary>
/// get/set - The results of the query.
/// </summary>
[JsonPropertyName("file_latest")]
public FileLatest FileLatest { get; set; }


}
}
28 changes: 28 additions & 0 deletions backend/api/Models/Mayan/Document/FileDownload.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
namespace Pims.Api.Models.Mayan.Document
{
/// <summary>
/// Represents a file download result.
/// </summary>
public class FileDownload
{
/// <summary>
/// get/set - The file contents. Could be encoded.
/// </summary>
public byte[] FilePayload { get; set; }

/// <summary>
/// get/set - The file size
/// </summary>
public int Size { get; set; }

/// <summary>
/// get/set - Name of the file.
/// </summary>
public string FileName { get; set; }

/// <summary>
/// get/set - THe Mime-Type that the file uses.
/// </summary>
public string Mimetype { get; set; }
}
}
Loading

0 comments on commit 13bf673

Please sign in to comment.