Skip to content

Commit

Permalink
Merge branch 'master' into 1.3.1
Browse files Browse the repository at this point in the history
  • Loading branch information
AdvSol-Darrel authored Feb 11, 2021
2 parents d748e7f + 5da4f4d commit 31f4f93
Show file tree
Hide file tree
Showing 17 changed files with 81 additions and 32 deletions.
8 changes: 4 additions & 4 deletions COMPLIANCE.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ description: |
compliance.
spec:
- name: PIA
status: in-progress
last-updated: '2020-01-29T00:04:31.849Z'
status: Completed - TRAN19022
last-updated: '2019-12-10T00:00:00.000Z'
- name: STRA
status: in-progress
last-updated: '2020-01-29T00:04:31.849Z'
status: Completed - STAR2019013
last-updated: '2020-04-09T00:00:00.000Z'
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
![img](https://img.shields.io/badge/Lifecycle-Stable-97ca00)

# HMCR

As part of the Highway Maintenance Contract Renewal (HMCR) process the business area defined the reporting requirements for the Maintenance Contractors (MCs). The contracts outlined the fields that have to be reported on and the format that it needs to be reported in.
Expand Down
9 changes: 0 additions & 9 deletions api/Hmcr.Api/Extensions/IApplicationBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,6 @@ namespace Hmcr.Api.Extensions
{
public static class IApplicationBuilderExtensions
{
public static void UseHmcrCors(this IApplicationBuilder app)
{
app.UseCors(builder => builder
.AllowAnyOrigin()
.AllowAnyMethod()
.AllowAnyHeader()
.WithExposedHeaders("Content-Disposition"));
}

public static void UseExceptionMiddleware(this IApplicationBuilder app)
{
app.UseMiddleware<ExceptionMiddleware>();
Expand Down
15 changes: 15 additions & 0 deletions api/Hmcr.Api/Extensions/IServiceCollectionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,20 @@ public static void AddHmcrHealthCheck(this IServiceCollection services, string c
services.AddHealthChecks()
.AddSqlServer(connectionString, name: "HMCR-DB-Check", failureStatus: HealthStatus.Degraded, tags: new string[] { "sql", "db" });
}

public static void AddHmcrCors(this IServiceCollection services)
{
services.AddCors(options =>
{
options.AddPolicy(name: Constants.HmcrOrigins,
builder =>
{
builder.WithOrigins("https://dev-hmcr.th.gov.bc.ca", "https://tst-hmcr.th.gov.bc.ca", "https://uat-hmcr.th.gov.bc.ca", "https://hmcr.th.gov.bc.ca")
.AllowAnyHeader()
.AllowAnyMethod()
.WithExposedHeaders("Content-Disposition");
});
});
}
}
}
8 changes: 5 additions & 3 deletions api/Hmcr.Api/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Hmcr.Data.Repositories;
using Hmcr.Domain.Hangfire;
using Hmcr.Domain.Services;
using Hmcr.Model;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
Expand Down Expand Up @@ -31,7 +32,7 @@ public void ConfigureServices(IServiceCollection services)
services.AddHttpContextAccessor();
services.AddHmcrAuthentication(Configuration);
services.AddHmcrDbContext(connectionString);
services.AddCors();
services.AddHmcrCors();
services.AddHmcrControllers();
services.AddHmcrAutoMapper();
services.AddHmcrApiVersioning();
Expand All @@ -51,9 +52,10 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISubmiss

app.UseExceptionMiddleware();
app.UseHmcrHealthCheck();
app.UseAuthorization();
app.UseAuthentication();
app.UseRouting();
app.UseCors(Constants.HmcrOrigins);
app.UseAuthentication();
app.UseAuthorization();
app.UseHmcrEndpoints();
app.UseHmcrSwagger(env, Configuration.GetSection("Constants:SwaggerApiUrl").Value);

Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Api/appsettings.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"AllowedHosts": "*",
"Constants": {
"Version": "1.2.5.0",
"Version": "1.2.7.0",
"SwaggerApiUrl": "/swagger/v1/swagger.json"
},
"Serilog": {
Expand Down
18 changes: 17 additions & 1 deletion api/Hmcr.Domain/Services/Base/ReportServiceBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Hmcr.Model.Dtos.SubmissionRow;
using Hmcr.Model.Dtos.SubmissionStream;
using Hmcr.Model.Utils;
using Microsoft.Extensions.Logging;
using System;
using System.Collections.Generic;
using System.IO;
Expand All @@ -20,6 +21,7 @@ public abstract class ReportServiceBase
protected IUnitOfWork _unitOfWork;
protected IFieldValidatorService _validator;
protected IServiceAreaService _saService;
private ILogger _logger;
protected ISubmissionStreamService _streamService;
protected ISubmissionObjectRepository _submissionRepo;
protected ISumbissionRowRepository _rowRepo;
Expand All @@ -46,7 +48,7 @@ public abstract class ReportServiceBase
public ReportServiceBase(IUnitOfWork unitOfWork,
ISubmissionStreamService streamService, ISubmissionObjectRepository submissionRepo, ISumbissionRowRepository rowRepo,
IContractTermRepository contractRepo, ISubmissionStatusService statusService, IFieldValidatorService validator,
IServiceAreaService saService)
IServiceAreaService saService, ILogger logger)
{
_unitOfWork = unitOfWork;
_streamService = streamService;
Expand All @@ -56,14 +58,21 @@ public ReportServiceBase(IUnitOfWork unitOfWork,
_statusService = statusService;
_validator = validator;
_saService = saService;
_logger = logger;
}
public async Task<(Dictionary<string, List<string>> errors, List<string> resubmittedRecordNumbers)> CheckResubmitAsync(FileUploadDto upload)
{
if (!HasRowIdentifier)
return (new Dictionary<string, List<string>>(), null);

var instance = Guid.NewGuid();

_logger.LogInformation($"[Api] {instance} Checking resubmit started.");

var (errors, submission) = await ValidateAndLogReportErrorAsync(upload);

_logger.LogInformation($"[Api] {instance} Checking resubmit finished.");

//if there are any errors, just log it and report them to the user.
if (errors.Count > 0)
return (errors, null);
Expand All @@ -75,16 +84,23 @@ public ReportServiceBase(IUnitOfWork unitOfWork,

public async Task<(decimal submissionObjectId, Dictionary<string, List<string>> errors)> CreateReportAsync(FileUploadDto upload)
{
var instance = Guid.NewGuid();

_logger.LogInformation($"[Api] {instance} Creating report started.");

var (errors, submission) = await ValidateAndLogReportErrorAsync(upload);

if (errors.Count > 0)
{
_logger.LogInformation($"[Api] {instance} Creating report finished with errors.");
return (0, errors);
}

var submissionEntity = await _submissionRepo.CreateSubmissionObjectAsync(submission);
_unitOfWork.Commit();

_logger.LogInformation($"[Api] {instance} Creating report finished - submission #: {submissionEntity.SubmissionObjectId}");

return (submissionEntity.SubmissionObjectId, errors);
}

Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Domain/Services/RockfallReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public RockfallReportService(IUnitOfWork unitOfWork,
ISubmissionStreamService streamService, ISubmissionObjectRepository submissionRepo, ISumbissionRowRepository rowRepo,
IContractTermRepository contractRepo, ISubmissionStatusService statusService, IRockfallReportRepository rockfallRepo, IFieldValidatorService validator,
ILogger<RockfallReportService> logger, IServiceAreaService saService)
: base(unitOfWork, streamService, submissionRepo, rowRepo, contractRepo, statusService, validator, saService)
: base(unitOfWork, streamService, submissionRepo, rowRepo, contractRepo, statusService, validator, saService, logger)
{
TableName = TableNames.RockfallReport;
HasRowIdentifier = true;
Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Domain/Services/WildlifeReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public WildlifeReportService(IUnitOfWork unitOfWork,
ISubmissionStreamService streamService, ISubmissionObjectRepository submissionRepo, ISumbissionRowRepository rowRepo,
IContractTermRepository contractRepo, ISubmissionStatusService statusService, IWildlifeReportRepository wildlifeRepo, IFieldValidatorService validator,
ILogger<WildlifeReportService> logger, IServiceAreaService saService)
: base(unitOfWork, streamService, submissionRepo, rowRepo, contractRepo, statusService, validator, saService)
: base(unitOfWork, streamService, submissionRepo, rowRepo, contractRepo, statusService, validator, saService, logger)
{
TableName = TableNames.WildlifeReport;
HasRowIdentifier = false;
Expand Down
2 changes: 1 addition & 1 deletion api/Hmcr.Domain/Services/WorkReportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public WorkReportService(IUnitOfWork unitOfWork,
ISubmissionStreamService streamService, ISubmissionObjectRepository submissionRepo, ISumbissionRowRepository rowRepo,
IContractTermRepository contractRepo, ISubmissionStatusService statusService, IWorkReportRepository workRptRepo, IFieldValidatorService validator,
ILogger<WorkReportService> logger, IServiceAreaService saService)
: base(unitOfWork, streamService, submissionRepo, rowRepo, contractRepo, statusService, validator, saService)
: base(unitOfWork, streamService, submissionRepo, rowRepo, contractRepo, statusService, validator, saService, logger)
{
TableName = TableNames.WorkReport;
HasRowIdentifier = true;
Expand Down
1 change: 1 addition & 0 deletions api/Hmcr.Model/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public static class Constants
public const string VancouverTimeZone = "America/Vancouver";
public const string PacificTimeZone = "Pacific Standard Time";
public const string SystemAdmin = "SYSTEM_ADMIN";
public const string HmcrOrigins = "HmcrOrigins";
}

public static class Reports
Expand Down
7 changes: 4 additions & 3 deletions client/.env.development
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
BROWSER=none
REACT_APP_API_HOST=http://localhost:27238
REACT_APP_API_HOST=localhost:27238
REACT_APP_CLIENT_ORIGIN=localhost:3000
REACT_APP_SSO_CLIENT=hmcr-public-dev
REACT_APP_SSO_REALM=fygf50pt
REACT_APP_SSO_HOST=https://sso-dev.pathfinder.gov.bc.ca/auth
REACT_APP_SSO_HOST=https://dev.oidc.gov.bc.ca/auth
REACT_APP_DEFAULT_PAGE_SIZE_OPTIONS=25,50,100,200
REACT_APP_DEFAULT_PAGE_SIZE=25
REACT_APP_DEFAULT_PAGE_SIZE=25
6 changes: 4 additions & 2 deletions client/src/js/Api.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ import { buildApiErrorObject } from './utils';
import * as Constants from './Constants';

export const instance = axios.create({
baseURL: '/api',
headers: { 'Access-Control-Allow-Origin': '*', Pragma: 'no-cache' },
baseURL: `${Constants.API_URL}`,
headers: {
Pragma: 'no-cache',
},
});

instance.interceptors.response.use(
Expand Down
6 changes: 3 additions & 3 deletions client/src/js/Constants.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const API_URL = window.RUNTIME_REACT_APP_API_HOST
? `${window.location.protocol}//${window.RUNTIME_REACT_APP_API_HOST}/api`
: process.env.REACT_APP_API_HOST;
export const API_URL = window.RUNTIME_REACT_APP_API_HOST //In non-dev environments, start.sh makes sure the runtime variables are popluated using host environment variables.
? `${window.location.protocol}//${window.RUNTIME_REACT_APP_API_HOST}/api` //For non-dev environments, CORS is enabled to HMCR urls.
: `${window.location.protocol}//${process.env.REACT_APP_CLIENT_ORIGIN}/api`; //For dev environment, proxy (setupProxy.js) is set up to avoid the same origin policy

const CODE_LOOKUP = '/codelookup';
const ACTIVITY_RULE = '/activityrule';
Expand Down
4 changes: 2 additions & 2 deletions client/src/setupProxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@ module.exports = function (app) {
app.use(
'/api',
createProxyMiddleware({
target: process.env.REACT_APP_API_HOST || 'http://localhost:27238',
target: 'http://' + process.env.REACT_APP_API_HOST,
changeOrigin: true,
})
),
app.use(
'/swagger',
createProxyMiddleware({
target: process.env.REACT_APP_API_HOST || 'http://localhost:27238',
target: 'http://' + process.env.REACT_APP_API_HOST,
changeOrigin: true,
})
);
Expand Down
19 changes: 19 additions & 0 deletions openshift/api-deploy-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,25 @@ objects:
targetPort: 8080
selector:
deploymentconfig: ${NAME}${SUFFIX}
- apiVersion: route.openshift.io/v1
kind: Route
metadata:
annotations:
haproxy.router.openshift.io/timeout: 1h
creationTimestamp: null
name: ${NAME}${SUFFIX}
spec:
host: api-${HOST}
path: "/"
port:
targetPort: web
tls:
termination: edge
to:
kind: Service
name: ${NAME}${SUFFIX}
weight: 100
wildcardPolicy: None
parameters:
- description: Name of the project (HMCR)
displayName: PROJECT_NAME
Expand Down
2 changes: 1 addition & 1 deletion openshift/client-deploy-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ objects:
name: sso-configs-${ENV}
key: CLIENT_SSO_CLIENTID
- name: REACT_APP_API_HOST
value: ${HOST}
value: api-${HOST}
- name: HMCR_DEPLOY_SUFFIX
value: ${SUFFIX}
test: false
Expand Down

0 comments on commit 31f4f93

Please sign in to comment.