From 881326acd885c725c1134b2529bf1840e950a093 Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Thu, 1 Oct 2020 16:24:43 -0700 Subject: [PATCH 01/46] Created ActivityRule controller and dto Updated UI to include new dropdowns for rules. --- .../Controllers/ActivityRuleController.cs | 55 +++++++++++++++++++ .../Repositories/ActivityCodeRepository.cs | 15 +++++ .../Services/ActivityCodeService.cs | 1 + .../ActivityCode/ActivityCodeCreateDto.cs | 2 + .../Dtos/ActivityCode/ActivityCodeDto.cs | 3 + .../ActivityCode/ActivityCodeSearchDto.cs | 2 + .../ActivityCode/ActivityCodeUpdateDto.cs | 2 + .../Dtos/ActivityRule/ActivityRuleDto.cs | 18 ++++++ client/src/js/Api.js | 4 ++ client/src/js/Constants.js | 4 ++ client/src/js/actions/codeLookupsActions.js | 24 ++++++++ client/src/js/actions/types.js | 4 ++ client/src/js/components/Main.js | 12 ++++ .../forms/EditActivityFormFields.js | 30 ++++++++++ client/src/js/reducers/codeLookupsReducer.js | 12 ++++ 15 files changed, 188 insertions(+) create mode 100644 api/Hmcr.Api/Controllers/ActivityRuleController.cs create mode 100644 api/Hmcr.Model/Dtos/ActivityRule/ActivityRuleDto.cs diff --git a/api/Hmcr.Api/Controllers/ActivityRuleController.cs b/api/Hmcr.Api/Controllers/ActivityRuleController.cs new file mode 100644 index 00000000..86129505 --- /dev/null +++ b/api/Hmcr.Api/Controllers/ActivityRuleController.cs @@ -0,0 +1,55 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using Hmcr.Api.Controllers.Base; +using Hmcr.Model.Dtos.ActivityRule; +using Microsoft.AspNetCore.Mvc; + +namespace Hmcr.Api.Controllers +{ + [ApiVersion("1.0")] + [Route("api/activityrule")] + [ApiController] + public class ActivityRuleController : HmcrControllerBase + { + [HttpGet("roadlength")] + public ActionResult> GetRoadLengthRules() + { + ActivityRuleDto[] activityRules = new ActivityRuleDto[3] + { + new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Length Rule 1" }, + new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Length Rule 2" }, + new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Length Rule 3" } + }; + + return activityRules; + } + + [HttpGet("surfacetype")] + public ActionResult> GetSurfaceTypeRules() + { + ActivityRuleDto[] activityRules = new ActivityRuleDto[3] + { + new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Surface Type Rule 1" }, + new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Surface Type Rule 2" }, + new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Surface Type Rule 3" } + }; + + return activityRules; + } + + [HttpGet("roadclass")] + public ActionResult> GetRoadClassRules() + { + ActivityRuleDto[] activityRules = new ActivityRuleDto[3] + { + new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Class Rule 1" }, + new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Class Rule 2" }, + new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Class Rule 3" } + }; + + return activityRules; + } + } +} diff --git a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs index 80090bab..3e804a0c 100644 --- a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs @@ -65,6 +65,10 @@ public async Task CreateActivityCodeAsync(ActivityCodeCreateDto Mapper.Map(activityCode, activityCodeEntity); + //TODO: add in saving of Activity Rules + + //TODO: add in saving of Service Areas + await DbSet.AddAsync(activityCodeEntity); return activityCodeEntity; @@ -82,6 +86,14 @@ public async Task GetActivityCodeAsync(decimal id) activityCode.IsReferenced = await _workReportRepo.IsActivityNumberInUseAsync(activityCode.ActivityNumber); + //TODO: pull the activity rules + var activityRules = new List(); + activityRules.Add(1); + activityRules.Add(3); + activityCode.ActivityRuleIds = activityRules; + + //TODO: pull the service areas + return activityCode; } @@ -143,6 +155,9 @@ public async Task UpdateActivityCodeAsync(ActivityCodeUpdateDto activityCode) activityCode.EndDate = activityCode.EndDate?.Date; Mapper.Map(activityCode, activityCodeEntity); + + //TODO: call function to sync activity rule changes + //TODO: call function to sync service area changes } public async Task DeleteActivityCodeAsync(decimal id) diff --git a/api/Hmcr.Domain/Services/ActivityCodeService.cs b/api/Hmcr.Domain/Services/ActivityCodeService.cs index 5816538c..8bc56a00 100644 --- a/api/Hmcr.Domain/Services/ActivityCodeService.cs +++ b/api/Hmcr.Domain/Services/ActivityCodeService.cs @@ -64,6 +64,7 @@ public ActivityCodeService(IActivityCodeRepository activityCodeRepo, IFieldValid activityCode.FeatureType = null; activityCode.SpThresholdLevel = null; activityCode.IsSiteNumRequired = false; + activityCode.ActivityRuleIds = []; } if (errors.Count > 0) diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs index e72f9176..4d7a157e 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; namespace Hmcr.Model.Dtos.ActivityCode { @@ -13,5 +14,6 @@ public class ActivityCodeCreateDto public string SpThresholdLevel { get; set; } public bool IsSiteNumRequired { get; set; } public DateTime? EndDate { get; set; } + public virtual IList ActivityRuleIds { get; set; } } } \ No newline at end of file diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs index 99de416a..06f9d8f5 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs @@ -1,5 +1,6 @@ using Hmcr.Model.Dtos.LocationCode; using System; +using System.Collections.Generic; using System.Text.Json.Serialization; namespace Hmcr.Model.Dtos.ActivityCode @@ -21,6 +22,8 @@ public class ActivityCodeDto public bool IsActive => EndDate == null || EndDate > DateTime.Today; public LocationCodeDto LocationCode { get; set; } + + public virtual IList ActivityRuleIds { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs index b81b5b0f..b2de5655 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Text.Json.Serialization; namespace Hmcr.Model.Dtos.ActivityCode @@ -19,5 +20,6 @@ public class ActivityCodeSearchDto public DateTime? EndDate { get; set; } public bool IsActive => EndDate == null || EndDate > DateTime.Today; public bool IsReferenced { get; set; } + public virtual IList ActivityRuleIds { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs index 77bf714d..356cfd50 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Text.Json.Serialization; namespace Hmcr.Model.Dtos.ActivityCode @@ -13,5 +14,6 @@ public class ActivityCodeUpdateDto public string SpThresholdLevel { get; set; } public bool IsSiteNumRequired { get; set; } public DateTime? EndDate { get; set; } + public virtual IList ActivityRuleIds { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityRule/ActivityRuleDto.cs b/api/Hmcr.Model/Dtos/ActivityRule/ActivityRuleDto.cs new file mode 100644 index 00000000..00233c95 --- /dev/null +++ b/api/Hmcr.Model/Dtos/ActivityRule/ActivityRuleDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Text.Json.Serialization; + +namespace Hmcr.Model.Dtos.ActivityRule +{ + public class ActivityRuleDto + { + [JsonPropertyName("id")] + public decimal ActivityRuleId { get; set; } + [JsonPropertyName("name")] + public string ActivityRuleName { get; set; } + public string ActivityRuleSet { get; set; } + public string ActivityRuleExecName { get; set; } + public decimal DisplayOrder { get; set; } + public DateTime? EndDate { get; set; } + + } +} diff --git a/client/src/js/Api.js b/client/src/js/Api.js index b1880bf8..7da618d0 100644 --- a/client/src/js/Api.js +++ b/client/src/js/Api.js @@ -65,6 +65,10 @@ export const postActivityCode = (data) => instance.post(Constants.API_PATHS.ACTI export const putActivityCode = (id, data) => instance.put(`${Constants.API_PATHS.ACTIVITY_CODES}/${id}`, data); export const deleteActivityCode = (id) => instance.delete(`${Constants.API_PATHS.ACTIVITY_CODES}/${id}`); +export const getRoadLengthRules = () => instance.get(Constants.API_PATHS.RULE_ROAD_LENGTH); +export const getSurfaceTypeRules = () => instance.get(Constants.API_PATHS.RULE_SURFACE_TYPE); +export const getRoadClassRules = () => instance.get(Constants.API_PATHS.RULE_ROAD_CLASS); + export const getReportExport = (params) => instance.get(Constants.API_PATHS.REPORT_EXPORT, { params: { ...params } }); export const getExportSupportedFormats = () => instance.get(Constants.API_PATHS.SUPPORTED_FORMATS); diff --git a/client/src/js/Constants.js b/client/src/js/Constants.js index db8602b4..61e59429 100644 --- a/client/src/js/Constants.js +++ b/client/src/js/Constants.js @@ -3,10 +3,14 @@ export const API_URL = window.RUNTIME_REACT_APP_API_HOST : process.env.REACT_APP_API_HOST; const CODE_LOOKUP = '/codelookup'; +const ACTIVITY_RULE = '/activityrule'; export const API_PATHS = { ACTIVITY_CODES: '/activitycodes', ACTIVITY_CODES_LITE: '/activitycodes/lite', + RULE_ROAD_LENGTH: `${ACTIVITY_RULE}/roadlength`, + RULE_SURFACE_TYPE: `${ACTIVITY_RULE}/surfacetype`, + RULE_ROAD_CLASS: `${ACTIVITY_RULE}/roadclass`, CODE_LOOKUP: CODE_LOOKUP, MAINTENANCE_TYPES: `${CODE_LOOKUP}/maintenancetypes`, UNIT_OF_MEASURES: `${CODE_LOOKUP}/unitofmeasures`, diff --git a/client/src/js/actions/codeLookupsActions.js b/client/src/js/actions/codeLookupsActions.js index 4a0b97d2..88a1e087 100644 --- a/client/src/js/actions/codeLookupsActions.js +++ b/client/src/js/actions/codeLookupsActions.js @@ -5,10 +5,34 @@ import { FETCH_LOCATION_CODES, FETCH_ACTIVITY_CODES_DROPDOWN, FETCH_THRESHOLD_LEVELS, + FETCH_ROAD_LENGTH_RULES, + FETCH_SURFACE_TYPE_RULES, + FETCH_ROAD_CLASS_RULES } from './types'; import * as api from '../Api'; +export const fetchRoadLengthRules = () => (dispatch) => { + return api.getRoadLengthRules().then((response) => { + const data = response.data; + dispatch({ type: FETCH_ROAD_LENGTH_RULES, payload: data }); + }); +}; + +export const fetchSurfaceTypeRules = () => (dispatch) => { + return api.getSurfaceTypeRules().then((response) => { + const data = response.data; + dispatch({ type: FETCH_SURFACE_TYPE_RULES, payload: data }); + }); +}; + +export const fetchRoadClassRules = () => (dispatch) => { + return api.getRoadClassRules().then((response) => { + const data = response.data; + dispatch({ type: FETCH_ROAD_CLASS_RULES, payload: data }); + }); +}; + export const fetchMaintenanceTypes = () => (dispatch) => { return api.getMaintenanceTypes().then((response) => { const data = response.data; diff --git a/client/src/js/actions/types.js b/client/src/js/actions/types.js index bd71183a..380c2086 100644 --- a/client/src/js/actions/types.js +++ b/client/src/js/actions/types.js @@ -14,6 +14,10 @@ export const FETCH_THRESHOLD_LEVELS = 'FETCH_THRESHOLD_LEVELS'; export const FETCH_SUBMISSION_STREAMS = 'FETCH_SUBMISSION_STREAMS'; export const FETCH_SUBMISSION_STATUSES = 'FETCH_SUBMISSION_STATUSES'; +export const FETCH_ROAD_LENGTH_RULES = 'FETCH_ROAD_LENGTH_RULES'; +export const FETCH_SURFACE_TYPE_RULES = 'FETCH_SURFACE_TYPE_RULES'; +export const FETCH_ROAD_CLASS_RULES = 'FETCH_ROAD_CLASS_RULES'; + // Global Error Dialog export const SHOW_ERROR_DIALOG_MODAL = 'SHOW_ERROR_DIALOG_MODAL'; export const HIDE_ERROR_DIALOG_MODAL = 'HIDE_ERROR_DIALOG_MODAL'; diff --git a/client/src/js/components/Main.js b/client/src/js/components/Main.js index 6c71ca58..8ccba6cf 100644 --- a/client/src/js/components/Main.js +++ b/client/src/js/components/Main.js @@ -16,6 +16,9 @@ import { fetchSubmissionStatuses, fetchSubmissionStreams, fetchThresholdLevels, + fetchRoadLengthRules, + fetchSurfaceTypeRules, + fetchRoadClassRules } from '../actions'; const Main = ({ @@ -32,6 +35,9 @@ const Main = ({ fetchSubmissionStatuses, fetchSubmissionStreams, fetchThresholdLevels, + fetchRoadLengthRules, + fetchSurfaceTypeRules, + fetchRoadClassRules }) => { const [loading, setLoading] = useState(true); @@ -48,6 +54,9 @@ const Main = ({ fetchSubmissionStatuses(), fetchSubmissionStreams(), fetchThresholdLevels(), + fetchRoadLengthRules(), + fetchSurfaceTypeRules(), + fetchRoadClassRules() ]).then(() => setLoading(false)); // eslint-disable-next-line react-hooks/exhaustive-deps }, []); @@ -78,4 +87,7 @@ export default connect(mapStateToProps, { fetchSubmissionStatuses, fetchSubmissionStreams, fetchThresholdLevels, + fetchRoadLengthRules, + fetchSurfaceTypeRules, + fetchRoadClassRules })(Main); diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 321c59e9..37ecd75e 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -19,6 +19,9 @@ const defaultValues = { locationCodeId: '', featureType: '', spThresholdLevel: '', + roadLengthRules: '', + surfaceTypeRules: '', + roadClassRules: '', isSiteNumRequired: false, endDate: null, }; @@ -46,6 +49,9 @@ const EditActivityFormFields = ({ locationCodes, featureTypes, thresholdLevels, + roadLengthRules, + surfaceTypeRules, + roadClassRules }) => { const [loading, setLoading] = useState(true); const [validLocationCodeValues, setValidLocationCodeValues] = useState(locationCodes); @@ -179,6 +185,27 @@ const EditActivityFormFields = ({ name="spThresholdLevel" /> + + + + + + + + + @@ -198,6 +225,9 @@ const mapStateToProps = (state) => { locationCodes: state.codeLookups.locationCodes, featureTypes: state.codeLookups.featureTypes, thresholdLevels: state.codeLookups.thresholdLevels, + roadLengthRules: state.codeLookups.roadLengthRules, + surfaceTypeRules: state.codeLookups.surfaceTypeRules, + roadClassRules: state.codeLookups.roadClassRules, }; }; diff --git a/client/src/js/reducers/codeLookupsReducer.js b/client/src/js/reducers/codeLookupsReducer.js index 26b4c98b..a052e603 100644 --- a/client/src/js/reducers/codeLookupsReducer.js +++ b/client/src/js/reducers/codeLookupsReducer.js @@ -7,6 +7,9 @@ import { FETCH_LOCATION_CODES, FETCH_ACTIVITY_CODES_DROPDOWN, FETCH_THRESHOLD_LEVELS, + FETCH_ROAD_LENGTH_RULES, + FETCH_SURFACE_TYPE_RULES, + FETCH_ROAD_CLASS_RULES } from '../actions/types'; const defaultState = { @@ -16,6 +19,9 @@ const defaultState = { locationCodes: [], activityCodes: [], thresholdLevels: [], + roadLengthRules: [], + surfaceTypeRules: [], + roadClassRules: [], }; export default (state = defaultState, action) => { @@ -32,6 +38,12 @@ export default (state = defaultState, action) => { return { ...state, activityCodes: action.payload }; case FETCH_THRESHOLD_LEVELS: return { ...state, thresholdLevels: action.payload }; + case FETCH_ROAD_LENGTH_RULES: + return { ...state, roadLengthRules: _.orderBy(action.payload, ['displayOrder']) }; + case FETCH_SURFACE_TYPE_RULES: + return { ...state, surfaceTypeRules: _.orderBy(action.payload, ['displayOrder']) }; + case FETCH_ROAD_CLASS_RULES: + return { ...state, roadClassRules: _.orderBy(action.payload, ['displayOrder']) }; default: return state; } From b577c68eaca5df11a49ca79c752b0ae456be1f9c Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Fri, 2 Oct 2020 22:58:03 -0700 Subject: [PATCH 02/46] Added ActivityRule service and repository with fake data populate the 3 dropdown Added ServiceArea dropdown --- .../Controllers/ActivityRuleController.cs | 43 ++++------ .../Mappings/ModelToEntityProfile.cs | 4 +- .../Repositories/ActivityCodeRepository.cs | 23 ++++- .../Repositories/ActivityRuleRepository.cs | 84 +++++++++++++++++++ .../Services/ActivityCodeService.cs | 2 +- .../Services/ActivityRuleService.cs | 43 ++++++++++ .../ActivityCode/ActivityCodeCreateDto.cs | 1 + .../Dtos/ActivityCode/ActivityCodeDto.cs | 4 + .../ActivityCode/ActivityCodeSearchDto.cs | 4 + .../ActivityCode/ActivityCodeUpdateDto.cs | 1 + .../Dtos/ActivityRule/RoadLengthRuleDto.cs | 18 ++++ client/src/js/components/ActivityAdmin.js | 2 +- .../forms/EditActivityFormFields.js | 29 ++++--- 13 files changed, 212 insertions(+), 46 deletions(-) create mode 100644 api/Hmcr.Data/Repositories/ActivityRuleRepository.cs create mode 100644 api/Hmcr.Domain/Services/ActivityRuleService.cs create mode 100644 api/Hmcr.Model/Dtos/ActivityRule/RoadLengthRuleDto.cs diff --git a/api/Hmcr.Api/Controllers/ActivityRuleController.cs b/api/Hmcr.Api/Controllers/ActivityRuleController.cs index 86129505..2ee41544 100644 --- a/api/Hmcr.Api/Controllers/ActivityRuleController.cs +++ b/api/Hmcr.Api/Controllers/ActivityRuleController.cs @@ -3,7 +3,11 @@ 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 @@ -13,43 +17,28 @@ namespace Hmcr.Api.Controllers [ApiController] public class ActivityRuleController : HmcrControllerBase { - [HttpGet("roadlength")] - public ActionResult> GetRoadLengthRules() + private IActivityRuleService _activityRuleSvc; + public ActivityRuleController(IActivityRuleService activityRuleSvc) { - ActivityRuleDto[] activityRules = new ActivityRuleDto[3] - { - new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Length Rule 1" }, - new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Length Rule 2" }, - new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Length Rule 3" } - }; + _activityRuleSvc = activityRuleSvc; + } - return activityRules; + [HttpGet("roadlength")] + public async Task>> GetRoadLengthRulesAsync() + { + return Ok(await _activityRuleSvc.GetRoadLengthRulesAsync()); } [HttpGet("surfacetype")] - public ActionResult> GetSurfaceTypeRules() + public async Task>> GetSurfaceTypeRulesAsync() { - ActivityRuleDto[] activityRules = new ActivityRuleDto[3] - { - new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Surface Type Rule 1" }, - new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Surface Type Rule 2" }, - new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Surface Type Rule 3" } - }; - - return activityRules; + return Ok(await _activityRuleSvc.GetSurfaceTypeRulesAsync()); } [HttpGet("roadclass")] - public ActionResult> GetRoadClassRules() + public async Task>> GetRoadClassRulesAsync() { - ActivityRuleDto[] activityRules = new ActivityRuleDto[3] - { - new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Class Rule 1" }, - new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Class Rule 2" }, - new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Class Rule 3" } - }; - - return activityRules; + return Ok(await _activityRuleSvc.GetRoadClassRulesAsync()); } } } diff --git a/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs b/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs index 510b2d26..bcff296c 100644 --- a/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs +++ b/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs @@ -30,8 +30,8 @@ public class ModelToEntityProfile : Profile { public ModelToEntityProfile() { - SourceMemberNamingConvention = new PascalCaseNamingConvention(); - DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention(); + //SourceMemberNamingConvention = new PascalCaseNamingConvention(); + //DestinationMemberNamingConvention = new LowerUnderscoreNamingConvention(); SourceMemberNamingConvention = new LowerUnderscoreNamingConvention(); DestinationMemberNamingConvention = new PascalCaseNamingConvention(); diff --git a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs index 3e804a0c..9563641b 100644 --- a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs @@ -77,6 +77,9 @@ public async Task CreateActivityCodeAsync(ActivityCodeCreateDto public async Task GetActivityCodeAsync(decimal id) { var activityCodeEntity = await DbSet.AsNoTracking() + //todo ServiceArea and activity rules + //.Include(x => x.HmrServiceAreaRules) //new table + //.Include(x => x.HmrRules) //new table .FirstOrDefaultAsync(ac => ac.ActivityCodeId == id); if (activityCodeEntity == null) @@ -87,12 +90,24 @@ public async Task GetActivityCodeAsync(decimal id) activityCode.IsReferenced = await _workReportRepo.IsActivityNumberInUseAsync(activityCode.ActivityNumber); //TODO: pull the activity rules - var activityRules = new List(); - activityRules.Add(1); - activityRules.Add(3); + //var activityRules = + // activityCodeEntity + // .HmrServiceRules //new table + // .Select(s => s.ActivityRuleId) + // .ToList(); + var activityRules = new List { 1, 3 }; activityCode.ActivityRuleIds = activityRules; - + activityCode.RoadLengthRule = 2; + activityCode.SurfaceTypeRule = 3; + activityCode.RoadClassRule = 1; //TODO: pull the service areas + //var serviceAreasNumbers = + // activityCodeEntity + // .HmrServiceAreaRules //new table + // .Select(s => s.ServiceAreaNumber) + // .ToList(); + var serviceAreasNumbers = new List { 1, 9 }; + activityCode.ServiceAreaNumbers = serviceAreasNumbers; return activityCode; } diff --git a/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs new file mode 100644 index 00000000..c3a0b103 --- /dev/null +++ b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs @@ -0,0 +1,84 @@ +using AutoMapper; +using Hmcr.Data.Database.Entities; +using Hmcr.Data.Repositories.Base; +using Hmcr.Model.Dtos.ActivityRule; +using Microsoft.EntityFrameworkCore; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Linq.Dynamic.Core; +using System.Threading.Tasks; + +namespace Hmcr.Data.Repositories +{ + public interface IActivityRuleRepository + { + Task> GetRoadLengthRulesAsync(); + Task> GetSurfaceTypeRulesAsync(); + Task> GetRoadClassRulesAsync(); + } + + public class ActivityRuleRepository : HmcrRepositoryBase, IActivityRuleRepository //TODO + { + public ActivityRuleRepository(AppDbContext dbContext, IMapper mapper) + : base(dbContext, mapper) + { + } + + public async Task> GetRoadLengthRulesAsync() + { + //TODO + //var activityRules = await DbSet.AsNoTracking() + // .Where(s => s.HmrActivityRules.Any(sa => sa.TYPE == "RoadLengthRules")) + // .ToListAsync(); + + //return Mapper.Map>(activityRules); + + //fake data + ActivityRuleDto[] activityRules = new ActivityRuleDto[3] + { + new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Length Rule 1" }, + new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Length Rule 2" }, + new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Length Rule 3" } + }; + await Task.Delay(1); + return activityRules; + } + public async Task> GetSurfaceTypeRulesAsync() + { + //var activityRules = await DbSet.AsNoTracking() + // .Where(s => s.HmrActivityRules.Any(sa => sa.TYPE == "SurfaceTypeRules")) + // .ToListAsync(); + + //return Mapper.Map>(activityRules); + + //fake data + ActivityRuleDto[] activityRules = new ActivityRuleDto[3] + { + new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Surface Type Rule 1" }, + new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Surface Type Rule 2" }, + new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Surface Type Rule 3" } + }; + await Task.Delay(1); + return activityRules; + } + public async Task> GetRoadClassRulesAsync() + { + //var activityRules = await DbSet.AsNoTracking() + // .Where(s => s.HmrActivityRules.Any(sa => sa.TYPE == "RoadClass")) + // .ToListAsync(); + + //return Mapper.Map>(activityRules); + + //fake data + ActivityRuleDto[] activityRules = new ActivityRuleDto[3] + { + new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Class Rule 1" }, + new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Class Rule 2" }, + new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Class Rule 3" } + }; + await Task.Delay(1); + return activityRules; + } + } +} diff --git a/api/Hmcr.Domain/Services/ActivityCodeService.cs b/api/Hmcr.Domain/Services/ActivityCodeService.cs index 8bc56a00..f583b651 100644 --- a/api/Hmcr.Domain/Services/ActivityCodeService.cs +++ b/api/Hmcr.Domain/Services/ActivityCodeService.cs @@ -64,7 +64,7 @@ public ActivityCodeService(IActivityCodeRepository activityCodeRepo, IFieldValid activityCode.FeatureType = null; activityCode.SpThresholdLevel = null; activityCode.IsSiteNumRequired = false; - activityCode.ActivityRuleIds = []; + activityCode.ActivityRuleIds = null; } if (errors.Count > 0) diff --git a/api/Hmcr.Domain/Services/ActivityRuleService.cs b/api/Hmcr.Domain/Services/ActivityRuleService.cs new file mode 100644 index 00000000..0dc14997 --- /dev/null +++ b/api/Hmcr.Domain/Services/ActivityRuleService.cs @@ -0,0 +1,43 @@ +using Hmcr.Data.Database; +using Hmcr.Data.Repositories; +using Hmcr.Model.Dtos.ActivityRule; +using System.Collections.Generic; +using System.Threading.Tasks; + +namespace Hmcr.Domain.Services +{ + public interface IActivityRuleService + { + Task> GetRoadLengthRulesAsync(); + Task> GetSurfaceTypeRulesAsync(); + Task> GetRoadClassRulesAsync(); + } + + public class ActivityRuleService : IActivityRuleService + { + private IActivityRuleRepository _activityRuleRepo; + private IUnitOfWork _unitOfWork; + + public ActivityRuleService(IActivityRuleRepository activityRuleRepo, IUnitOfWork unitOfWork) + { + _activityRuleRepo = activityRuleRepo; + _unitOfWork = unitOfWork; + } + + public async Task> GetRoadLengthRulesAsync() + { + return await _activityRuleRepo.GetRoadLengthRulesAsync(); + } + + public async Task> GetSurfaceTypeRulesAsync() + { + return await _activityRuleRepo.GetSurfaceTypeRulesAsync(); + } + + public async Task> GetRoadClassRulesAsync() + { + return await _activityRuleRepo.GetRoadClassRulesAsync(); + } + + } +} diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs index 4d7a157e..12ed955c 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs @@ -15,5 +15,6 @@ public class ActivityCodeCreateDto public bool IsSiteNumRequired { get; set; } public DateTime? EndDate { get; set; } public virtual IList ActivityRuleIds { get; set; } + public virtual IList ServiceAreaNumbers { get; set; } } } \ No newline at end of file diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs index 06f9d8f5..86d51296 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs @@ -24,6 +24,10 @@ public class ActivityCodeDto public LocationCodeDto LocationCode { get; set; } public virtual IList ActivityRuleIds { get; set; } + public decimal? RoadLengthRule { get; set; } + public decimal? SurfaceTypeRule { get; set; } + public decimal? RoadClassRule { get; set; } + public virtual IList ServiceAreaNumbers { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs index b2de5655..03b37f57 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs @@ -21,5 +21,9 @@ public class ActivityCodeSearchDto public bool IsActive => EndDate == null || EndDate > DateTime.Today; public bool IsReferenced { get; set; } public virtual IList ActivityRuleIds { get; set; } + public decimal? RoadLengthRule { get; set; } + public decimal? SurfaceTypeRule { get; set; } + public decimal? RoadClassRule { get; set; } + public virtual IList ServiceAreaNumbers { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs index 356cfd50..c7c31740 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs @@ -15,5 +15,6 @@ public class ActivityCodeUpdateDto public bool IsSiteNumRequired { get; set; } public DateTime? EndDate { get; set; } public virtual IList ActivityRuleIds { get; set; } + public virtual IList ServiceAreaNumbers { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityRule/RoadLengthRuleDto.cs b/api/Hmcr.Model/Dtos/ActivityRule/RoadLengthRuleDto.cs new file mode 100644 index 00000000..b071786f --- /dev/null +++ b/api/Hmcr.Model/Dtos/ActivityRule/RoadLengthRuleDto.cs @@ -0,0 +1,18 @@ +using System; +using System.Text.Json.Serialization; + +namespace Hmcr.Model.Dtos.ActivityRule +{ + public class RoadLengthRuleDto + { + [JsonPropertyName("id")] + public decimal RoadLengthRuleId { get; set; } + [JsonPropertyName("name")] + public string RoadLengthRuleName { get; set; } + public string ActivityRuleSet { get; set; } + public string ActivityRuleExecName { get; set; } + public decimal DisplayOrder { get; set; } + public DateTime? EndDate { get; set; } + + } +} diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index 1d41420f..5416cacf 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -41,7 +41,7 @@ const tableColumns = [ { heading: 'Active', key: 'isActive', nosort: true }, ]; -const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures, showValidationErrorDialog }) => { +const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showValidationErrorDialog }) => { const location = useLocation(); const searchData = useSearchData(defaultSearchOptions); const [searchInitialValues, setSearchInitialValues] = useState(defaultSearchFormValues); diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 37ecd75e..33041d23 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -4,6 +4,7 @@ import * as Yup from 'yup'; import moment from 'moment'; import SingleDateField from '../ui/SingleDateField'; +import MultiSelect from '../ui/MultiSelect'; import SingleDropdownField from '../ui/SingleDropdownField'; import PageSpinner from '../ui/PageSpinner'; import { FormRow, FormInput, FormCheckboxInput } from './FormInputs'; @@ -19,10 +20,11 @@ const defaultValues = { locationCodeId: '', featureType: '', spThresholdLevel: '', - roadLengthRules: '', - surfaceTypeRules: '', - roadClassRules: '', + roadLengthRule: '', + surfaceTypeRule: '', + roadClassRule: '', isSiteNumRequired: false, + serviceAreaNumbers: [], endDate: null, }; @@ -51,7 +53,8 @@ const EditActivityFormFields = ({ thresholdLevels, roadLengthRules, surfaceTypeRules, - roadClassRules + roadClassRules, + serviceAreas, }) => { const [loading, setLoading] = useState(true); const [validLocationCodeValues, setValidLocationCodeValues] = useState(locationCodes); @@ -135,7 +138,7 @@ const EditActivityFormFields = ({ }, []); if (loading || formValues === null) return ; - + return ( @@ -185,25 +188,25 @@ const EditActivityFormFields = ({ name="spThresholdLevel" /> - + - + - + @@ -211,6 +214,9 @@ const EditActivityFormFields = ({ )} + + + @@ -228,6 +234,7 @@ const mapStateToProps = (state) => { roadLengthRules: state.codeLookups.roadLengthRules, surfaceTypeRules: state.codeLookups.surfaceTypeRules, roadClassRules: state.codeLookups.roadClassRules, + serviceAreas: Object.values(state.serviceAreas), }; }; From ce5896b05a45faee8c10166c3a922cc713cd213d Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Mon, 5 Oct 2020 12:24:11 -0700 Subject: [PATCH 03/46] Scaffold DB Entity changes --- .../Database/Entities/AppDbContext.cs | 200 +++++++++++++++++- .../Database/Entities/HmrActivityCode.cs | 6 + .../Database/Entities/HmrActivityCodeRule.cs | 20 ++ .../Database/Entities/HmrActivityRule.cs | 27 +++ .../Database/Entities/HmrRockfallReportVw.cs | 4 + .../Database/Entities/HmrWildlifeReportVw.cs | 4 +- .../Database/Entities/HmrWorkReportVw.cs | 3 +- 7 files changed, 251 insertions(+), 13 deletions(-) create mode 100644 api/Hmcr.Data/Database/Entities/HmrActivityCodeRule.cs create mode 100644 api/Hmcr.Data/Database/Entities/HmrActivityRule.cs diff --git a/api/Hmcr.Data/Database/Entities/AppDbContext.cs b/api/Hmcr.Data/Database/Entities/AppDbContext.cs index db60b222..4c480521 100644 --- a/api/Hmcr.Data/Database/Entities/AppDbContext.cs +++ b/api/Hmcr.Data/Database/Entities/AppDbContext.cs @@ -17,6 +17,8 @@ public AppDbContext(DbContextOptions options) public virtual DbSet HmrActivityCodes { get; set; } public virtual DbSet HmrActivityCodeHists { get; set; } + public virtual DbSet HmrActivityCodeRules { get; set; } + public virtual DbSet HmrActivityRules { get; set; } public virtual DbSet HmrCodeLookups { get; set; } public virtual DbSet HmrCodeLookupHists { get; set; } public virtual DbSet HmrContractTerms { get; set; } @@ -61,7 +63,7 @@ public AppDbContext(DbContextOptions options) public virtual DbSet HmrWorkReports { get; set; } public virtual DbSet HmrWorkReportHists { get; set; } public virtual DbSet HmrWorkReportVws { get; set; } - + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => @@ -368,6 +370,145 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .IsUnicode(false); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ActivityCodeRuleId) + .HasName("PK__HMR_ACTI__E4140F7DCE60BEDD"); + + entity.ToTable("HMR_ACTIVITY_CODE_RULE"); + + entity.HasIndex(e => e.ActivityCodeId) + .HasName("HMR_ACT_CD_RL_ACTV_CD_ID_FK_I"); + + entity.HasIndex(e => e.ActivityRuleId) + .HasName("HMR_ACT_CD_RL_ACTV_RL_ID_FK_I"); + + entity.HasIndex(e => new { e.ActivityRuleId, e.ActivityCodeId }) + .HasName("UQ__HMR_ACTI__FAB2688C30F75933") + .IsUnique(); + + entity.Property(e => e.ActivityCodeRuleId) + .HasColumnName("ACTIVITY_CODE_RULE_ID") + .HasColumnType("numeric(9, 0)") + .HasDefaultValueSql("(NEXT VALUE FOR [HMR_ACTIVITY_RULE_ID_SEQ])"); + + entity.Property(e => e.ActivityCodeId) + .HasColumnName("ACTIVITY_CODE_ID") + .HasColumnType("numeric(9, 0)"); + + entity.Property(e => e.ActivityRuleId) + .HasColumnName("ACTIVITY_RULE_ID") + .HasColumnType("numeric(9, 0)"); + + entity.Property(e => e.ConcurrencyControlNumber) + .HasColumnName("CONCURRENCY_CONTROL_NUMBER") + .HasDefaultValueSql("((1))"); + + entity.Property(e => e.DbAuditCreateTimestamp) + .HasColumnName("DB_AUDIT_CREATE_TIMESTAMP") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + + entity.Property(e => e.DbAuditCreateUserid) + .IsRequired() + .HasColumnName("DB_AUDIT_CREATE_USERID") + .HasMaxLength(30) + .IsUnicode(false) + .HasDefaultValueSql("(user_name())"); + + entity.Property(e => e.DbAuditLastUpdateTimestamp) + .HasColumnName("DB_AUDIT_LAST_UPDATE_TIMESTAMP") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + + entity.Property(e => e.DbAuditLastUpdateUserid) + .IsRequired() + .HasColumnName("DB_AUDIT_LAST_UPDATE_USERID") + .HasMaxLength(30) + .IsUnicode(false) + .HasDefaultValueSql("(user_name())"); + + entity.HasOne(d => d.ActivityCode) + .WithMany(p => p.HmrActivityCodeRules) + .HasForeignKey(d => d.ActivityCodeId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK__HMR_ACTIV__ACTIV__407A839F"); + + entity.HasOne(d => d.ActivityRule) + .WithMany(p => p.HmrActivityCodeRules) + .HasForeignKey(d => d.ActivityRuleId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK__HMR_ACTIV__ACTIV__3F865F66"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ActivityRuleId) + .HasName("PK__HMR_ACTI__1F8CFB4801F64DAA"); + + entity.ToTable("HMR_ACTIVITY_RULE"); + + entity.Property(e => e.ActivityRuleId) + .HasColumnName("ACTIVITY_RULE_ID") + .HasColumnType("numeric(9, 0)") + .HasDefaultValueSql("(NEXT VALUE FOR [HMR_ACTIVITY_RULE_CODE_ID_SEQ])"); + + entity.Property(e => e.ActivityRuleExecName) + .IsRequired() + .HasColumnName("ACTIVITY_RULE_EXEC_NAME") + .HasMaxLength(150) + .IsUnicode(false); + + entity.Property(e => e.ActivityRuleName) + .IsRequired() + .HasColumnName("ACTIVITY_RULE_NAME") + .HasMaxLength(150) + .IsUnicode(false); + + entity.Property(e => e.ActivityRuleSet) + .IsRequired() + .HasColumnName("ACTIVITY_RULE_SET") + .HasMaxLength(20) + .IsUnicode(false); + + entity.Property(e => e.ConcurrencyControlNumber) + .HasColumnName("CONCURRENCY_CONTROL_NUMBER") + .HasDefaultValueSql("((1))"); + + entity.Property(e => e.DbAuditCreateTimestamp) + .HasColumnName("DB_AUDIT_CREATE_TIMESTAMP") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + + entity.Property(e => e.DbAuditCreateUserid) + .IsRequired() + .HasColumnName("DB_AUDIT_CREATE_USERID") + .HasMaxLength(30) + .IsUnicode(false) + .HasDefaultValueSql("(user_name())"); + + entity.Property(e => e.DbAuditLastUpdateTimestamp) + .HasColumnName("DB_AUDIT_LAST_UPDATE_TIMESTAMP") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + + entity.Property(e => e.DbAuditLastUpdateUserid) + .IsRequired() + .HasColumnName("DB_AUDIT_LAST_UPDATE_USERID") + .HasMaxLength(30) + .IsUnicode(false) + .HasDefaultValueSql("(user_name())"); + + entity.Property(e => e.DisplayOrder) + .HasColumnName("DISPLAY_ORDER") + .HasColumnType("numeric(3, 0)"); + + entity.Property(e => e.EndDate) + .HasColumnName("END_DATE") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.CodeLookupId) @@ -550,8 +691,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { entity.HasKey(e => e.ContractTermId) - .HasName("HMR_CNRT_TRM_PK") - .IsClustered(false); + .HasName("HMR_CNRT_TRM_PK"); entity.ToTable("HMR_CONTRACT_TERM"); @@ -2319,6 +2459,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasColumnName("END_OFFSET") .HasColumnType("numeric(7, 3)"); + entity.Property(e => e.EndVariance) + .HasColumnName("END_VARIANCE") + .HasColumnType("numeric(25, 20)"); + entity.Property(e => e.EstimatedRockfallDate) .HasColumnName("ESTIMATED_ROCKFALL_DATE") .HasColumnType("date"); @@ -2358,6 +2502,12 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMaxLength(255) .IsUnicode(false); + entity.Property(e => e.IsOverSpThreshold) + .IsRequired() + .HasColumnName("IS_OVER_SP_THRESHOLD") + .HasMaxLength(1) + .IsUnicode(false); + entity.Property(e => e.Landmark) .HasColumnName("LANDMARK") .HasMaxLength(8) @@ -2440,6 +2590,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasColumnName("START_OFFSET") .HasColumnType("numeric(7, 3)"); + entity.Property(e => e.StartVariance) + .HasColumnName("START_VARIANCE") + .HasColumnType("numeric(25, 20)"); + entity.Property(e => e.SubmissionObjectId) .HasColumnName("SUBMISSION_OBJECT_ID") .HasColumnType("numeric(9, 0)"); @@ -2458,6 +2612,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasColumnName("VEHICLE_DAMAGE") .HasMaxLength(1) .IsUnicode(false); + + entity.Property(e => e.WarningSpThreshold) + .HasColumnName("WARNING_SP_THRESHOLD") + .HasColumnType("numeric(12, 6)"); }); modelBuilder.Entity(entity => @@ -5610,9 +5768,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMaxLength(255) .IsUnicode(false); - entity.Property(e => e.IsOverSpTolerance) + entity.Property(e => e.IsOverSpThreshold) .IsRequired() - .HasColumnName("IS_OVER_SP_TOLERANCE") + .HasColumnName("IS_OVER_SP_THRESHOLD") .HasMaxLength(1) .IsUnicode(false); @@ -5666,6 +5824,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMaxLength(1) .IsUnicode(false); + entity.Property(e => e.SpatialVariance) + .HasColumnName("SPATIAL_VARIANCE") + .HasColumnType("numeric(25, 20)"); + entity.Property(e => e.Species) .HasColumnName("SPECIES") .HasColumnType("numeric(2, 0)"); @@ -5684,6 +5846,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMaxLength(30) .IsUnicode(false); + entity.Property(e => e.WarningSpThreshold) + .HasColumnName("WARNING_SP_THRESHOLD") + .HasColumnType("numeric(12, 6)"); + entity.Property(e => e.WildlifeRecordId) .HasColumnName("WILDLIFE_RECORD_ID") .HasColumnType("numeric(9, 0)"); @@ -5892,7 +6058,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasColumnName("SITE_NUMBER") .HasMaxLength(8) .IsUnicode(false) - .HasComment("Contains a site type code followed by a The Ministry site number. Site types are provided by the Province, are four to six digits preceded by: A – Avalanche B – Arrestor Bed/Dragnet Barrier D – Debris and/or Rockfall L – Landscape R – Rest Area S – Signalized Intersection T – Traffic Patrol W – Weather Station X – Railway Crossing"); + .HasComment("Contains a site type code followed by a The Ministry site number. Site types are provided by the Province, are four to six digits preceded by: A � Avalanche B � Arrestor Bed/Dragnet Barrier D � Debris and/or Rockfall L � Landscape R � Rest Area S � Signalized Intersection T � Traffic Patrol W � Weather Station X � Railway Crossing"); entity.Property(e => e.StartDate) .HasColumnName("START_DATE") @@ -5916,7 +6082,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.StructureNumber) .HasColumnName("STRUCTURE_NUMBER") - .HasMaxLength(30) + .HasMaxLength(5) .IsUnicode(false) .HasComment("From list of Bridge Structure Road (BSR) structures provided by the Province. Is only applicable at defined BSR structures. BSR structures include; bridges, culverts over 3m, retaining walls."); @@ -6160,7 +6326,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.StructureNumber) .HasColumnName("STRUCTURE_NUMBER") - .HasMaxLength(30) + .HasMaxLength(5) .IsUnicode(false); entity.Property(e => e.SubmissionObjectId) @@ -6270,9 +6436,9 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMaxLength(255) .IsUnicode(false); - entity.Property(e => e.IsOverSpTolerance) + entity.Property(e => e.IsOverSpThreshold) .IsRequired() - .HasColumnName("IS_OVER_SP_TOLERANCE") + .HasColumnName("IS_OVER_SP_THRESHOLD") .HasMaxLength(1) .IsUnicode(false); @@ -6336,7 +6502,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.StructureNumber) .HasColumnName("STRUCTURE_NUMBER") - .HasMaxLength(30) + .HasMaxLength(5) .IsUnicode(false); entity.Property(e => e.SubmissionObjectId) @@ -6362,6 +6528,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasColumnName("VALUE_OF_WORK") .HasColumnType("numeric(9, 2)"); + entity.Property(e => e.WarningSpThreshold) + .HasColumnName("WARNING_SP_THRESHOLD") + .HasColumnType("numeric(12, 6)"); + entity.Property(e => e.WorkLength) .HasColumnName("WORK_LENGTH") .HasColumnType("numeric(25, 20)"); @@ -6383,6 +6553,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMin(1) .HasMax(2147483647); + modelBuilder.HasSequence("HMR_ACTIVITY_RULE_CODE_ID_SEQ") + .HasMin(1) + .HasMax(999999999); + + modelBuilder.HasSequence("HMR_ACTIVITY_RULE_ID_SEQ") + .HasMin(1) + .HasMax(999999999); + modelBuilder.HasSequence("HMR_CNT_TRM_ID_SEQ") .HasMin(1) .HasMax(999999999); diff --git a/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs b/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs index 11571e03..831a3525 100644 --- a/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs +++ b/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs @@ -5,6 +5,11 @@ namespace Hmcr.Data.Database.Entities { public partial class HmrActivityCode { + public HmrActivityCode() + { + HmrActivityCodeRules = new HashSet(); + } + public decimal ActivityCodeId { get; set; } public string ActivityNumber { get; set; } public string ActivityName { get; set; } @@ -31,5 +36,6 @@ public partial class HmrActivityCode public DateTime DbAuditLastUpdateTimestamp { get; set; } public virtual HmrLocationCode LocationCode { get; set; } + public virtual ICollection HmrActivityCodeRules { get; set; } } } diff --git a/api/Hmcr.Data/Database/Entities/HmrActivityCodeRule.cs b/api/Hmcr.Data/Database/Entities/HmrActivityCodeRule.cs new file mode 100644 index 00000000..d3471f3d --- /dev/null +++ b/api/Hmcr.Data/Database/Entities/HmrActivityCodeRule.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; + +namespace Hmcr.Data.Database.Entities +{ + public partial class HmrActivityCodeRule + { + public decimal ActivityCodeRuleId { get; set; } + public decimal ActivityCodeId { get; set; } + public decimal ActivityRuleId { get; set; } + public long ConcurrencyControlNumber { get; set; } + public string DbAuditCreateUserid { get; set; } + public DateTime DbAuditCreateTimestamp { get; set; } + public string DbAuditLastUpdateUserid { get; set; } + public DateTime DbAuditLastUpdateTimestamp { get; set; } + + public virtual HmrActivityCode ActivityCode { get; set; } + public virtual HmrActivityRule ActivityRule { get; set; } + } +} diff --git a/api/Hmcr.Data/Database/Entities/HmrActivityRule.cs b/api/Hmcr.Data/Database/Entities/HmrActivityRule.cs new file mode 100644 index 00000000..c3c11fc3 --- /dev/null +++ b/api/Hmcr.Data/Database/Entities/HmrActivityRule.cs @@ -0,0 +1,27 @@ +using System; +using System.Collections.Generic; + +namespace Hmcr.Data.Database.Entities +{ + public partial class HmrActivityRule + { + public HmrActivityRule() + { + HmrActivityCodeRules = new HashSet(); + } + + public decimal ActivityRuleId { get; set; } + public string ActivityRuleSet { get; set; } + public string ActivityRuleName { get; set; } + public string ActivityRuleExecName { get; set; } + public decimal? DisplayOrder { get; set; } + public DateTime? EndDate { get; set; } + public long ConcurrencyControlNumber { get; set; } + public string DbAuditCreateUserid { get; set; } + public DateTime DbAuditCreateTimestamp { get; set; } + public string DbAuditLastUpdateUserid { get; set; } + public DateTime DbAuditLastUpdateTimestamp { get; set; } + + public virtual ICollection HmrActivityCodeRules { get; set; } + } +} diff --git a/api/Hmcr.Data/Database/Entities/HmrRockfallReportVw.cs b/api/Hmcr.Data/Database/Entities/HmrRockfallReportVw.cs index 96fd73ea..c8546df9 100644 --- a/api/Hmcr.Data/Database/Entities/HmrRockfallReportVw.cs +++ b/api/Hmcr.Data/Database/Entities/HmrRockfallReportVw.cs @@ -15,8 +15,12 @@ public partial class HmrRockfallReportVw public TimeSpan? EstimatedRockfallTime { get; set; } public decimal? StartLatitude { get; set; } public decimal? StartLongitude { get; set; } + public decimal? StartVariance { get; set; } public decimal? EndLatitude { get; set; } public decimal? EndLongitude { get; set; } + public decimal? EndVariance { get; set; } + public decimal? WarningSpThreshold { get; set; } + public string IsOverSpThreshold { get; set; } public string HighwayUnique { get; set; } public string HighwayUniqueName { get; set; } public decimal? HighwayUniqueLength { get; set; } diff --git a/api/Hmcr.Data/Database/Entities/HmrWildlifeReportVw.cs b/api/Hmcr.Data/Database/Entities/HmrWildlifeReportVw.cs index 281a5745..072de368 100644 --- a/api/Hmcr.Data/Database/Entities/HmrWildlifeReportVw.cs +++ b/api/Hmcr.Data/Database/Entities/HmrWildlifeReportVw.cs @@ -14,7 +14,9 @@ public partial class HmrWildlifeReportVw public string TimeOfKill { get; set; } public decimal? Latitude { get; set; } public decimal? Longitude { get; set; } - public string IsOverSpTolerance { get; set; } + public decimal? SpatialVariance { get; set; } + public decimal? WarningSpThreshold { get; set; } + public string IsOverSpThreshold { get; set; } public string HighwayUnique { get; set; } public string HighwayUniqueName { get; set; } public decimal? HighwayUniqueLength { get; set; } diff --git a/api/Hmcr.Data/Database/Entities/HmrWorkReportVw.cs b/api/Hmcr.Data/Database/Entities/HmrWorkReportVw.cs index b1e128eb..f76087bd 100644 --- a/api/Hmcr.Data/Database/Entities/HmrWorkReportVw.cs +++ b/api/Hmcr.Data/Database/Entities/HmrWorkReportVw.cs @@ -31,8 +31,9 @@ public partial class HmrWorkReportVw public decimal? EndLatitude { get; set; } public decimal? EndLongitude { get; set; } public decimal? EndVariance { get; set; } + public decimal? WarningSpThreshold { get; set; } public decimal? WorkLength { get; set; } - public string IsOverSpTolerance { get; set; } + public string IsOverSpThreshold { get; set; } public string StructureNumber { get; set; } public string SiteNumber { get; set; } public decimal? ValueOfWork { get; set; } From 8716a0d532af668df719b6cfc4f4b2ab4e6bd99e Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Mon, 5 Oct 2020 15:00:47 -0700 Subject: [PATCH 04/46] Created model to entity relationships Updated Repository classes for Activity Code/Rule --- .../Mappings/EntityToModelProfile.cs | 4 +- .../Mappings/ModelToEntityProfile.cs | 3 + .../Repositories/ActivityCodeRepository.cs | 57 +++++++++++++++---- .../Repositories/ActivityRuleRepository.cs | 39 +++++++------ 4 files changed, 70 insertions(+), 33 deletions(-) diff --git a/api/Hmcr.Data/Mappings/EntityToModelProfile.cs b/api/Hmcr.Data/Mappings/EntityToModelProfile.cs index d54df836..a3a8f4d1 100644 --- a/api/Hmcr.Data/Mappings/EntityToModelProfile.cs +++ b/api/Hmcr.Data/Mappings/EntityToModelProfile.cs @@ -2,6 +2,7 @@ using Hmcr.Data.Database.Entities; using Hmcr.Model; using Hmcr.Model.Dtos.ActivityCode; +using Hmcr.Model.Dtos.ActivityRule; using Hmcr.Model.Dtos.CodeLookup; using Hmcr.Model.Dtos.ContractTerm; using Hmcr.Model.Dtos.District; @@ -111,7 +112,8 @@ public EntityToModelProfile() CreateMap(); CreateMap(); - + CreateMap(); + } } } diff --git a/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs b/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs index bcff296c..7cc9de4f 100644 --- a/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs +++ b/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs @@ -23,6 +23,7 @@ using Hmcr.Model.Dtos.WildlifeReport; using Hmcr.Model.Dtos.WorkReport; using Hmcr.Model.Dtos.ActivityCode; +using Hmcr.Model.Dtos.ActivityRule; namespace Hmcr.Data.Mappings { @@ -96,6 +97,8 @@ public ModelToEntityProfile() CreateMap(); CreateMap(); + + CreateMap(); } } } diff --git a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs index 9563641b..6ac77542 100644 --- a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs @@ -65,7 +65,15 @@ public async Task CreateActivityCodeAsync(ActivityCodeCreateDto Mapper.Map(activityCode, activityCodeEntity); - //TODO: add in saving of Activity Rules + + foreach (var ruleId in activityCode.ActivityRuleIds) + { + activityCodeEntity.HmrActivityCodeRules + .Add(new HmrActivityCodeRule + { + ActivityRuleId = ruleId + }); + } //TODO: add in saving of Service Areas @@ -77,9 +85,9 @@ public async Task CreateActivityCodeAsync(ActivityCodeCreateDto public async Task GetActivityCodeAsync(decimal id) { var activityCodeEntity = await DbSet.AsNoTracking() - //todo ServiceArea and activity rules + //todo ServiceArea //.Include(x => x.HmrServiceAreaRules) //new table - //.Include(x => x.HmrRules) //new table + .Include(x => x.HmrActivityCodeRules) //new table .FirstOrDefaultAsync(ac => ac.ActivityCodeId == id); if (activityCodeEntity == null) @@ -88,18 +96,18 @@ public async Task GetActivityCodeAsync(decimal id) var activityCode = Mapper.Map(activityCodeEntity); activityCode.IsReferenced = await _workReportRepo.IsActivityNumberInUseAsync(activityCode.ActivityNumber); + + var activityRules = activityCodeEntity + .HmrActivityCodeRules + .Select(s => s.ActivityCodeRuleId) + .ToList(); - //TODO: pull the activity rules - //var activityRules = - // activityCodeEntity - // .HmrServiceRules //new table - // .Select(s => s.ActivityRuleId) - // .ToList(); - var activityRules = new List { 1, 3 }; + /*var activityRules = new List { 1, 3 }; activityCode.ActivityRuleIds = activityRules; activityCode.RoadLengthRule = 2; activityCode.SurfaceTypeRule = 3; - activityCode.RoadClassRule = 1; + activityCode.RoadClassRule = 1;*/ + //TODO: pull the service areas //var serviceAreasNumbers = // activityCodeEntity @@ -171,7 +179,8 @@ public async Task UpdateActivityCodeAsync(ActivityCodeUpdateDto activityCode) Mapper.Map(activityCode, activityCodeEntity); - //TODO: call function to sync activity rule changes + SyncActivityRules(activityCode, activityCodeEntity); + //TODO: call function to sync service area changes } @@ -196,5 +205,29 @@ private async IAsyncEnumerable FindActivityNumbersInUseAync(IEnumerable< yield return activityNumber; } } + + private void SyncActivityRules(ActivityCodeUpdateDto activityUpdateDto, HmrActivityCode activityCodeEntity) + { + var rulesToDelete = + activityCodeEntity.HmrActivityCodeRules.Where(r => !activityUpdateDto.ActivityRuleIds.Contains(r.ActivityRuleId)).ToList(); + + for (var i = rulesToDelete.Count() - 1; i >= 0; i--) + { + DbContext.Remove(rulesToDelete[i]); + } + + var existingRuleIds = activityCodeEntity.HmrActivityCodeRules.Select(r => r.ActivityRuleId); + + var newRuleIds = activityUpdateDto.ActivityRuleIds.Where(r => !existingRuleIds.Contains(r)); + + foreach (var ruleId in newRuleIds) + { + activityCodeEntity.HmrActivityCodeRules + .Add(new HmrActivityCodeRule + { + ActivityRuleId = ruleId + }); + } + } } } diff --git a/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs index c3a0b103..58fff961 100644 --- a/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs @@ -18,7 +18,7 @@ public interface IActivityRuleRepository Task> GetRoadClassRulesAsync(); } - public class ActivityRuleRepository : HmcrRepositoryBase, IActivityRuleRepository //TODO + public class ActivityRuleRepository : HmcrRepositoryBase, IActivityRuleRepository { public ActivityRuleRepository(AppDbContext dbContext, IMapper mapper) : base(dbContext, mapper) @@ -27,58 +27,57 @@ public ActivityRuleRepository(AppDbContext dbContext, IMapper mapper) public async Task> GetRoadLengthRulesAsync() { - //TODO - //var activityRules = await DbSet.AsNoTracking() - // .Where(s => s.HmrActivityRules.Any(sa => sa.TYPE == "RoadLengthRules")) - // .ToListAsync(); + var activityRules = await DbSet.AsNoTracking() + .Where(s => s.ActivityRuleSet.ToUpper() == "ROAD_LENGTH") + .ToListAsync(); - //return Mapper.Map>(activityRules); + return Mapper.Map>(activityRules); //fake data - ActivityRuleDto[] activityRules = new ActivityRuleDto[3] + /*ActivityRuleDto[] activityRules = new ActivityRuleDto[3] { new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Length Rule 1" }, new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Length Rule 2" }, new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Length Rule 3" } }; await Task.Delay(1); - return activityRules; + return activityRules;*/ } public async Task> GetSurfaceTypeRulesAsync() { - //var activityRules = await DbSet.AsNoTracking() - // .Where(s => s.HmrActivityRules.Any(sa => sa.TYPE == "SurfaceTypeRules")) - // .ToListAsync(); + var activityRules = await DbSet.AsNoTracking() + .Where(s => s.ActivityRuleSet.ToUpper() == "SURFACE_TYPE") + .ToListAsync(); - //return Mapper.Map>(activityRules); + return Mapper.Map>(activityRules); //fake data - ActivityRuleDto[] activityRules = new ActivityRuleDto[3] + /*ActivityRuleDto[] activityRules = new ActivityRuleDto[3] { new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Surface Type Rule 1" }, new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Surface Type Rule 2" }, new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Surface Type Rule 3" } }; await Task.Delay(1); - return activityRules; + return activityRules;*/ } public async Task> GetRoadClassRulesAsync() { - //var activityRules = await DbSet.AsNoTracking() - // .Where(s => s.HmrActivityRules.Any(sa => sa.TYPE == "RoadClass")) - // .ToListAsync(); + var activityRules = await DbSet.AsNoTracking() + .Where(s => s.ActivityRuleSet.ToUpper() == "ROAD_CLASS") + .ToListAsync(); - //return Mapper.Map>(activityRules); + return Mapper.Map>(activityRules); //fake data - ActivityRuleDto[] activityRules = new ActivityRuleDto[3] + /*ActivityRuleDto[] activityRules = new ActivityRuleDto[3] { new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Class Rule 1" }, new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Class Rule 2" }, new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Class Rule 3" } }; await Task.Delay(1); - return activityRules; + return activityRules;*/ } } } From fb06dad95e65164e1c53b400b0a1f47e836b8c2a Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Tue, 6 Oct 2020 10:41:57 -0700 Subject: [PATCH 05/46] Database scripts for 2.0 changes - Alter DB to create new tables - Add Activity Rule types to Code Lookup - Add Actviity Rules --- database/V24.0/1. Alter HMR_V2.0.sql | 601 ++++++++++++++++++ database/V24.0/2. Insert HMR_CODE_LOOKUP.sql | 10 + .../V24.0/3. Insert HMR_ACTIVITY_RULE.sql | 137 ++++ 3 files changed, 748 insertions(+) create mode 100644 database/V24.0/1. Alter HMR_V2.0.sql create mode 100644 database/V24.0/2. Insert HMR_CODE_LOOKUP.sql create mode 100644 database/V24.0/3. Insert HMR_ACTIVITY_RULE.sql diff --git a/database/V24.0/1. Alter HMR_V2.0.sql b/database/V24.0/1. Alter HMR_V2.0.sql new file mode 100644 index 00000000..471e3241 --- /dev/null +++ b/database/V24.0/1. Alter HMR_V2.0.sql @@ -0,0 +1,601 @@ +// Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Thu Oct 01 16:38:26 PDT 2020 +// Execute this script on: +// HMR_1.3/dbo - This database/schema will be modified +// to synchronize it with MS SQL Server 2016: +// HMR_1.3 Dezign/dbo + +// We recommend backing up the database prior to executing the script. + +SET XACT_ABORT ON +GO +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE +GO +BEGIN TRANSACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Drop trigger dbo.HMR_ACT_CODE_A_S_IUD_TR +PRINT N'Drop trigger dbo.HMR_ACT_CODE_A_S_IUD_TR' +GO +DROP TRIGGER [dbo].[HMR_ACT_CODE_A_S_IUD_TR] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Drop view dbo.HMR_WILDLIFE_REPORT_VW +PRINT N'Drop view dbo.HMR_WILDLIFE_REPORT_VW' +GO +DROP VIEW [dbo].[HMR_WILDLIFE_REPORT_VW] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Drop view dbo.HMR_ROCKFALL_REPORT_VW +PRINT N'Drop view dbo.HMR_ROCKFALL_REPORT_VW' +GO +DROP VIEW [dbo].[HMR_ROCKFALL_REPORT_VW] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Drop view dbo.HMR_WORK_REPORT_VW +PRINT N'Drop view dbo.HMR_WORK_REPORT_VW' +GO +DROP VIEW [dbo].[HMR_WORK_REPORT_VW] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Drop procedure dbo.hmr_error_handling +PRINT N'Drop procedure dbo.hmr_error_handling' +GO +DROP PROCEDURE [dbo].[hmr_error_handling] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create table dbo.HMRX_TableDefinitions +PRINT N'Create table dbo.HMRX_TableDefinitions' +GO +CREATE TABLE [dbo].[HMRX_TableDefinitions] ( + [TABLE_NAME] nvarchar(255) NULL, + [TABLE_ALIAS] nvarchar(255) NULL, + [HIST] nvarchar(1) NULL, + [DESCRIPTION] nvarchar(max) NULL + ) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ +PRINT N'Create sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ' +GO +CREATE SEQUENCE [dbo].[HMR_ACTIVITY_RULE_ID_SEQ] + AS bigint + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 999999999 + NO CYCLE + CACHE 50 +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ +PRINT N'Create sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ' +GO +CREATE SEQUENCE [dbo].[HMR_ACTIVITY_RULE_CODE_ID_SEQ] + AS bigint + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 999999999 + NO CYCLE + CACHE 50 +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create table dbo.HMR_ACTIVITY_RULE +PRINT N'Create table dbo.HMR_ACTIVITY_RULE' +GO +CREATE TABLE [dbo].[HMR_ACTIVITY_RULE] ( + [ACTIVITY_RULE_ID] numeric(9,0) NOT NULL DEFAULT (NEXT VALUE FOR [HMR_ACTIVITY_RULE_CODE_ID_SEQ]), + [ACTIVITY_RULE_SET] varchar(20) NOT NULL, + [ACTIVITY_RULE_NAME] varchar(150) NOT NULL, + [ACTIVITY_RULE_EXEC_NAME] varchar(150) NOT NULL, + [DISPLAY_ORDER] numeric(3,0) NULL, + [END_DATE] datetime NULL DEFAULT (getutcdate()), + [CONCURRENCY_CONTROL_NUMBER] bigint NOT NULL DEFAULT ((1)), + [DB_AUDIT_CREATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), + [DB_AUDIT_CREATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), + [DB_AUDIT_LAST_UPDATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), + [DB_AUDIT_LAST_UPDATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), + PRIMARY KEY CLUSTERED([ACTIVITY_RULE_ID]) + ON [PRIMARY]) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create table dbo.HMR_ACTIVITY_CODE_RULE +PRINT N'Create table dbo.HMR_ACTIVITY_CODE_RULE' +GO +CREATE TABLE [dbo].[HMR_ACTIVITY_CODE_RULE] ( + [ACTIVITY_CODE_RULE_ID] numeric(9,0) NOT NULL DEFAULT (NEXT VALUE FOR [HMR_ACTIVITY_RULE_ID_SEQ]), + [ACTIVITY_CODE_ID] numeric(9,0) NOT NULL, + [ACTIVITY_RULE_ID] numeric(9,0) NOT NULL, + [CONCURRENCY_CONTROL_NUMBER] bigint NOT NULL DEFAULT ((1)), + [DB_AUDIT_CREATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), + [DB_AUDIT_CREATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), + [DB_AUDIT_LAST_UPDATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), + [DB_AUDIT_LAST_UPDATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), + PRIMARY KEY CLUSTERED([ACTIVITY_CODE_RULE_ID]) + ON [PRIMARY]) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create unique constraint dbo.HMR_ACT_CD_RL_UK +PRINT N'Create unique constraint dbo.HMR_ACT_CD_RL_UK' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_RULE] + ADD UNIQUE ([ACTIVITY_RULE_ID], [ACTIVITY_CODE_ID]) + WITH ( + DATA_COMPRESSION = NONE + ) ON [PRIMARY] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create procedure dbo.hmr_error_handling +PRINT N'Create procedure dbo.hmr_error_handling' +GO +/* ---------------------------------------------------------------------- */ +/* Add procedures */ +/* ---------------------------------------------------------------------- */ + +CREATE PROCEDURE [dbo].[hmr_error_handling] AS + + begin + DECLARE @errmsg nvarchar(2048), + @severity tinyint, + @state tinyint, + @errno int, + @proc sysname, + @lineno int + + SELECT @errmsg = error_message(), @severity = error_severity(), + @state = error_state(), @errno = error_number(), + @proc = error_procedure(), @lineno = error_line() + + IF @errmsg NOT LIKE '***%' + BEGIN + SELECT @errmsg = '*** ' + coalesce(quotename(@proc), '') + + ', Line ' + ltrim(str(@lineno)) + '. Errno ' + + ltrim(str(@errno)) + ': ' + @errmsg + END + + RAISERROR('%s', @severity, @state, @errmsg) + end +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create view dbo.HMR_WORK_REPORT_VW +PRINT N'Create view dbo.HMR_WORK_REPORT_VW' +GO +/* ---------------------------------------------------------------------- */ +/* Add views */ +/* ---------------------------------------------------------------------- */ + +/* Update 23/04/2020 + +i) Added spatial warning thresholds + +*/ + + +CREATE VIEW [dbo].[HMR_WORK_REPORT_VW] AS + SELECT + wrkrpt.WORK_REPORT_ID + ,'WORK_REPORT' AS REPORT_TYPE + ,wrkrpt.RECORD_TYPE + ,CAST(wrkrpt.[SERVICE_AREA] AS numeric) AS SERVICE_AREA + ,wrkrpt.RECORD_NUMBER + ,wrkrpt.TASK_NUMBER + ,wrkrpt.ACTIVITY_NUMBER + ,actcode.ACTIVITY_NAME + ,wrkrpt.START_DATE + ,wrkrpt.END_DATE + ,wrkrpt.ACCOMPLISHMENT + ,wrkrpt.UNIT_OF_MEASURE + ,wrkrpt.POSTED_DATE + ,wrkrpt.HIGHWAY_UNIQUE + ,wrkrpt.HIGHWAY_UNIQUE_NAME + ,wrkrpt.HIGHWAY_UNIQUE_LENGTH + ,wrkrpt.LANDMARK + ,wrkrpt.START_OFFSET + ,wrkrpt.END_OFFSET + ,wrkrpt.START_LATITUDE + ,wrkrpt.START_LONGITUDE + ,subm_rw.START_VARIANCE + ,wrkrpt.END_LATITUDE + ,wrkrpt.END_LONGITUDE + ,subm_rw.END_VARIANCE + ,subm_rw.WARNING_SP_THRESHOLD + ,wrkrpt.WORK_LENGTH + ,CASE + WHEN ISNULL(subm_rw.START_VARIANCE,0) > ISNULL(subm_rw.WARNING_SP_THRESHOLD,0) + OR ISNULL(subm_rw.END_VARIANCE,0) > ISNULL(subm_rw.WARNING_SP_THRESHOLD,0) + THEN 'Y' ELSE 'N' + END IS_OVER_SP_THRESHOLD + ,wrkrpt.STRUCTURE_NUMBER + ,wrkrpt.SITE_NUMBER + ,wrkrpt.VALUE_OF_WORK + ,wrkrpt.COMMENTS + ,wrkrpt.GEOMETRY + ,wrkrpt.SUBMISSION_OBJECT_ID + ,CAST(subm_obj.[FILE_NAME] AS varchar) AS FILE_NAME + ,wrkrpt.ROW_NUM + ,CAST(subm_stat.[STATUS_CODE] + ' - ' + subm_stat.[DESCRIPTION] AS varchar) AS VALIDATION_STATUS + ,CAST(wrkrpt.APP_CREATE_TIMESTAMP AS datetime) AS APP_CREATE_TIMESTAMP_UTC + ,CAST(wrkrpt.APP_LAST_UPDATE_TIMESTAMP AS datetime) AS APP_LAST_UPDATE_TIMESTAMP_UTC + FROM HMR_WORK_REPORT wrkrpt + INNER JOIN HMR_SUBMISSION_OBJECT subm_obj ON wrkrpt.SUBMISSION_OBJECT_ID = subm_obj.SUBMISSION_OBJECT_ID + LEFT OUTER JOIN HMR_ACTIVITY_CODE actcode ON wrkrpt.ACTIVITY_NUMBER = actcode.ACTIVITY_NUMBER + LEFT OUTER JOIN HMR_SUBMISSION_ROW subm_rw ON wrkrpt.ROW_ID = subm_rw.ROW_ID + LEFT OUTER JOIN HMR_SUBMISSION_STATUS subm_stat ON subm_rw.ROW_STATUS_ID = subm_stat.STATUS_ID +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create view dbo.HMR_ROCKFALL_REPORT_VW +PRINT N'Create view dbo.HMR_ROCKFALL_REPORT_VW' +GO +/* Update 23/04/2020 + +i) Added spatial warning thresholds + +*/ + + +CREATE VIEW [dbo].[HMR_ROCKFALL_REPORT_VW] AS +SELECT + rckflrpt.[ROCKFALL_REPORT_ID] + ,'ROCKFALL_REPORT' AS REPORT_TYPE + ,CAST(rckflrpt.[RECORD_TYPE] AS varchar) AS RECORD_TYPE + ,CAST(rckflrpt.[SERVICE_AREA] AS numeric) AS SERVICE_AREA + ,rckflrpt.[MCRR_INCIDENT_NUMBER] + ,rckflrpt.[ESTIMATED_ROCKFALL_DATE] + ,rckflrpt.[ESTIMATED_ROCKFALL_TIME] + ,rckflrpt.[START_LATITUDE] + ,rckflrpt.[START_LONGITUDE] + ,subm_rw.[START_VARIANCE] + ,rckflrpt.[END_LATITUDE] + ,rckflrpt.[END_LONGITUDE] + ,subm_rw.[END_VARIANCE] + ,subm_rw.[WARNING_SP_THRESHOLD] + ,CASE + WHEN ISNULL(subm_rw.START_VARIANCE,0) > ISNULL(subm_rw.WARNING_SP_THRESHOLD,0) + OR ISNULL(subm_rw.END_VARIANCE,0) > ISNULL(subm_rw.WARNING_SP_THRESHOLD,0) + THEN 'Y' ELSE 'N' + END IS_OVER_SP_THRESHOLD + ,rckflrpt.[HIGHWAY_UNIQUE] + ,rckflrpt.[HIGHWAY_UNIQUE_NAME] + ,rckflrpt.[HIGHWAY_UNIQUE_LENGTH] + ,rckflrpt.[LANDMARK] + ,rckflrpt.[LANDMARK_NAME] + ,rckflrpt.[START_OFFSET] + ,rckflrpt.[END_OFFSET] + ,rckflrpt.[DIRECTION_FROM_LANDMARK] + ,rckflrpt.[LOCATION_DESCRIPTION] + ,rckflrpt.[TRAVELLED_LANES_VOLUME] + ,rckflrpt.[OTHER_TRAVELLED_LANES_VOLUME] + ,rckflrpt.[DITCH_VOLUME] + ,rckflrpt.[OTHER_DITCH_VOLUME] + ,rckflrpt.[HEAVY_PRECIP] + ,rckflrpt.[FREEZE_THAW] + ,rckflrpt.[DITCH_SNOW_ICE] + ,rckflrpt.[VEHICLE_DAMAGE] + ,rckflrpt.[COMMENTS] + ,rckflrpt.[REPORTER_NAME] + ,rckflrpt.[MC_PHONE_NUMBER] + ,usr.[BUSINESS_LEGAL_NAME] AS MC_NAME + ,rckflrpt.[REPORT_DATE] + ,rckflrpt.[GEOMETRY] + ,rckflrpt.SUBMISSION_OBJECT_ID + ,CAST(subm_obj.[FILE_NAME] AS varchar) AS FILE_NAME + ,rckflrpt.[ROW_NUM] + ,CAST(subm_stat.[STATUS_CODE] + ' - ' + subm_stat.[DESCRIPTION] AS varchar) AS VALIDATION_STATUS + ,CAST(rckflrpt.APP_CREATE_TIMESTAMP AS datetime) AS APP_CREATE_TIMESTAMP_UTC + ,CAST(rckflrpt.APP_LAST_UPDATE_TIMESTAMP AS datetime) AS APP_LAST_UPDATE_TIMESTAMP_UTC + FROM HMR_ROCKFALL_REPORT rckflrpt + INNER JOIN HMR_SUBMISSION_OBJECT subm_obj ON rckflrpt.SUBMISSION_OBJECT_ID = subm_obj.SUBMISSION_OBJECT_ID + LEFT OUTER JOIN HMR_SUBMISSION_ROW subm_rw ON rckflrpt.ROW_ID = subm_rw.ROW_ID + LEFT OUTER JOIN HMR_SUBMISSION_STATUS subm_stat ON subm_rw.ROW_STATUS_ID = subm_stat.STATUS_ID + LEFT OUTER JOIN HMR_SYSTEM_USER usr ON rckflrpt.APP_CREATE_USER_GUID = usr.APP_CREATE_USER_GUID +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create view dbo.HMR_WILDLIFE_REPORT_VW +PRINT N'Create view dbo.HMR_WILDLIFE_REPORT_VW' +GO +/* Update 23/04/2020 + +i) Added spatial warning thresholds + +*/ + +CREATE VIEW [dbo].[HMR_WILDLIFE_REPORT_VW] AS + SELECT + wldlfrpt.[WILDLIFE_RECORD_ID] + ,'WILDLIFE_REPORT' AS REPORT_TYPE + ,wldlfrpt.[RECORD_TYPE] + ,CAST(wldlfrpt.[SERVICE_AREA] AS numeric) AS SERVICE_AREA + ,wldlfrpt.[ACCIDENT_DATE] + ,wldlfrpt.[TIME_OF_KILL] + ,wldlfrpt.[LATITUDE] + ,wldlfrpt.[LONGITUDE] + ,subm_rw.[START_VARIANCE] AS SPATIAL_VARIANCE + ,subm_rw.[WARNING_SP_THRESHOLD] + ,CASE + WHEN ISNULL(subm_rw.START_VARIANCE,0) > ISNULL(subm_rw.WARNING_SP_THRESHOLD,0) + OR ISNULL(subm_rw.END_VARIANCE,0) > ISNULL(subm_rw.WARNING_SP_THRESHOLD,0) + THEN 'Y' ELSE 'N' + END IS_OVER_SP_THRESHOLD + ,wldlfrpt.[HIGHWAY_UNIQUE] + ,wldlfrpt.[HIGHWAY_UNIQUE_NAME] + ,wldlfrpt.[HIGHWAY_UNIQUE_LENGTH] + ,wldlfrpt.[LANDMARK] + ,wldlfrpt.[OFFSET] + ,wldlfrpt.[NEAREST_TOWN] + ,wldlfrpt.[WILDLIFE_SIGN] + ,wldlfrpt.[QUANTITY] + ,wldlfrpt.[SPECIES] + ,wldlfrpt.[SEX] + ,wldlfrpt.[AGE] + ,wldlfrpt.[COMMENT] + ,wldlfrpt.[GEOMETRY] + ,CAST(wldlfrpt.[SUBMISSION_OBJECT_ID] AS numeric) AS SUBMISSION_OBJECT_ID + ,CAST(subm_obj.[FILE_NAME] AS varchar) AS FILE_NAME + ,wldlfrpt.[ROW_NUM] + ,CAST(subm_stat.[STATUS_CODE] + ' - ' + subm_stat.[DESCRIPTION] AS varchar) AS VALIDATION_STATUS + ,CAST(wldlfrpt.APP_CREATE_TIMESTAMP AS datetime) AS APP_CREATE_TIMESTAMP_UTC + ,CAST(wldlfrpt.APP_LAST_UPDATE_TIMESTAMP AS datetime) AS APP_LAST_UPDATE_TIMESTAMP_UTC + FROM [dbo].[HMR_WILDLIFE_REPORT] wldlfrpt + INNER JOIN HMR_SUBMISSION_OBJECT subm_obj ON wldlfrpt.SUBMISSION_OBJECT_ID = subm_obj.SUBMISSION_OBJECT_ID + LEFT OUTER JOIN HMR_SUBMISSION_ROW subm_rw ON wldlfrpt.ROW_ID = subm_rw.ROW_ID + LEFT OUTER JOIN HMR_SUBMISSION_STATUS subm_stat ON subm_rw.ROW_STATUS_ID = subm_stat.STATUS_ID +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create index dbo.HMR_ACT_CD_RL_ACTV_RL_ID_FK_I +PRINT N'Create index dbo.HMR_ACT_CD_RL_ACTV_RL_ID_FK_I' +GO +CREATE NONCLUSTERED INDEX [HMR_ACT_CD_RL_ACTV_RL_ID_FK_I] + ON [dbo].[HMR_ACTIVITY_CODE_RULE]([ACTIVITY_RULE_ID]) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create index dbo.HMR_ACT_CD_RL_ACTV_CD_ID_FK_I +PRINT N'Create index dbo.HMR_ACT_CD_RL_ACTV_CD_ID_FK_I' +GO +CREATE NONCLUSTERED INDEX [HMR_ACT_CD_RL_ACTV_CD_ID_FK_I] + ON [dbo].[HMR_ACTIVITY_CODE_RULE]([ACTIVITY_CODE_ID]) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create foreign key constraint dbo.HMR_ACT_CD_RL_ACT_RUL_FK +PRINT N'Create foreign key constraint dbo.HMR_ACT_CD_RL_ACT_RUL_FK' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_RULE] + ADD FOREIGN KEY([ACTIVITY_RULE_ID]) + REFERENCES [dbo].[HMR_ACTIVITY_RULE]([ACTIVITY_RULE_ID]) + ON DELETE NO ACTION + ON UPDATE NO ACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create foreign key constraint dbo.HMR_ACT_CODE_ACT_CD_RL_FK +PRINT N'Create foreign key constraint dbo.HMR_ACT_CODE_ACT_CD_RL_FK' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_RULE] + ADD FOREIGN KEY([ACTIVITY_CODE_ID]) + REFERENCES [dbo].[HMR_ACTIVITY_CODE]([ACTIVITY_CODE_ID]) + ON DELETE NO ACTION + ON UPDATE NO ACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create trigger dbo.HMR_ACT_RUL_I_S_U_TR +PRINT N'Create trigger dbo.HMR_ACT_RUL_I_S_U_TR' +GO +CREATE TRIGGER [dbo].[HMR_ACT_RUL_I_S_U_TR] ON HMR_ACTIVITY_RULE INSTEAD OF UPDATE AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- validate concurrency control + if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACTIVITY_RULE_ID = deleted.ACTIVITY_RULE_ID) + raiserror('CONCURRENCY FAILURE.',16,1) + + + -- update statement + update HMR_ACTIVITY_RULE + set "ACTIVITY_RULE_ID" = inserted."ACTIVITY_RULE_ID", + "ACTIVITY_RULE_SET" = inserted."ACTIVITY_RULE_SET", + "ACTIVITY_RULE_NAME" = inserted."ACTIVITY_RULE_NAME", + "ACTIVITY_RULE_EXEC_NAME" = inserted."ACTIVITY_RULE_EXEC_NAME", + "DISPLAY_ORDER" = inserted."DISPLAY_ORDER", + "END_DATE" = inserted."END_DATE", + "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER" + , DB_AUDIT_LAST_UPDATE_TIMESTAMP = getutcdate() + , DB_AUDIT_LAST_UPDATE_USERID = user_name() + from HMR_ACTIVITY_RULE + inner join inserted + on (HMR_ACTIVITY_RULE.ACTIVITY_RULE_ID = inserted.ACTIVITY_RULE_ID); + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create trigger dbo.HMR_ACT_CODE_A_S_IUD_TR +PRINT N'Create trigger dbo.HMR_ACT_CODE_A_S_IUD_TR' +GO +/* ---------------------------------------------------------------------- */ +/* Add triggers */ +/* ---------------------------------------------------------------------- */ + +CREATE TRIGGER [dbo].[HMR_ACT_CODE_A_S_IUD_TR] ON HMR_ACTIVITY_CODE FOR INSERT, UPDATE, DELETE AS +SET NOCOUNT ON +BEGIN TRY +DECLARE @curr_date datetime; +SET @curr_date = getutcdate(); + IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- historical + IF EXISTS(SELECT * FROM deleted) + update HMR_ACTIVITY_CODE_HIST set END_DATE_HIST = @curr_date where ACTIVITY_CODE_ID in (select ACTIVITY_CODE_ID from deleted) and END_DATE_HIST is null; + + IF EXISTS(SELECT * FROM inserted) + insert into HMR_ACTIVITY_CODE_HIST ([ACTIVITY_CODE_ID], [ACTIVITY_NUMBER], [ACTIVITY_NAME], [UNIT_OF_MEASURE], [MAINTENANCE_TYPE], [LOCATION_CODE_ID], [FEATURE_TYPE], [SP_THRESHOLD_LEVEL], [IS_SITE_NUM_REQUIRED], [ACTIVITY_APPLICATION], [END_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], ACTIVITY_CODE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST) + select [ACTIVITY_CODE_ID], [ACTIVITY_NUMBER], [ACTIVITY_NAME], [UNIT_OF_MEASURE], [MAINTENANCE_TYPE], [LOCATION_CODE_ID], [FEATURE_TYPE], [SP_THRESHOLD_LEVEL], [IS_SITE_NUM_REQUIRED], [ACTIVITY_APPLICATION], [END_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], (next value for [dbo].[HMR_ACTIVITY_CODE_H_ID_SEQ]) as [ACTIVITY_CODE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create trigger dbo.HMR_ACT_CD_RL_I_S_U_TR +PRINT N'Create trigger dbo.HMR_ACT_CD_RL_I_S_U_TR' +GO +CREATE TRIGGER [dbo].[HMR_ACT_CD_RL_I_S_U_TR] ON HMR_ACTIVITY_CODE_RULE INSTEAD OF UPDATE AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- validate concurrency control + if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACTIVITY_CODE_RULE_ID = deleted.ACTIVITY_CODE_RULE_ID) + raiserror('CONCURRENCY FAILURE.',16,1) + + + -- update statement + update HMR_ACTIVITY_CODE_RULE + set "ACTIVITY_CODE_RULE_ID" = inserted."ACTIVITY_CODE_RULE_ID", + "ACTIVITY_CODE_ID" = inserted."ACTIVITY_CODE_ID", + "ACTIVITY_RULE_ID" = inserted."ACTIVITY_RULE_ID", + "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER" + , DB_AUDIT_LAST_UPDATE_TIMESTAMP = getutcdate() + , DB_AUDIT_LAST_UPDATE_USERID = user_name() + from HMR_ACTIVITY_CODE_RULE + inner join inserted + on (HMR_ACTIVITY_CODE_RULE.ACTIVITY_CODE_RULE_ID = inserted.ACTIVITY_CODE_RULE_ID); + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create trigger dbo.HMR_ACT_RUL_I_S_I_TR +PRINT N'Create trigger dbo.HMR_ACT_RUL_I_S_I_TR' +GO +CREATE TRIGGER [dbo].[HMR_ACT_RUL_I_S_I_TR] ON HMR_ACTIVITY_RULE INSTEAD OF INSERT AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM inserted) + RETURN; + + + insert into HMR_ACTIVITY_RULE ( + "ACTIVITY_RULE_ID", + "ACTIVITY_RULE_SET", + "ACTIVITY_RULE_NAME", + "ACTIVITY_RULE_EXEC_NAME", + "DISPLAY_ORDER", + "END_DATE", + "CONCURRENCY_CONTROL_NUMBER") + select "ACTIVITY_RULE_ID", + "ACTIVITY_RULE_SET", + "ACTIVITY_RULE_NAME", + "ACTIVITY_RULE_EXEC_NAME", + "DISPLAY_ORDER", + "END_DATE", + "CONCURRENCY_CONTROL_NUMBER" + from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +// Create trigger dbo.HMR_ACT_CD_RL_I_S_I_TR +PRINT N'Create trigger dbo.HMR_ACT_CD_RL_I_S_I_TR' +GO +CREATE TRIGGER [dbo].[HMR_ACT_CD_RL_I_S_I_TR] ON HMR_ACTIVITY_CODE_RULE INSTEAD OF INSERT AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM inserted) + RETURN; + + + insert into HMR_ACTIVITY_CODE_RULE ( + "ACTIVITY_CODE_RULE_ID", + "ACTIVITY_CODE_ID", + "ACTIVITY_RULE_ID", + "CONCURRENCY_CONTROL_NUMBER") + select "ACTIVITY_CODE_RULE_ID", + "ACTIVITY_CODE_ID", + "ACTIVITY_RULE_ID", + "CONCURRENCY_CONTROL_NUMBER" + from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +COMMIT TRANSACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO +DECLARE @Success AS BIT +SET @Success = 1 +SET NOEXEC OFF +IF (@Success = 1) PRINT 'The database update succeeded' +ELSE BEGIN + IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION + PRINT 'The database update failed' +END +GO diff --git a/database/V24.0/2. Insert HMR_CODE_LOOKUP.sql b/database/V24.0/2. Insert HMR_CODE_LOOKUP.sql new file mode 100644 index 00000000..8259f358 --- /dev/null +++ b/database/V24.0/2. Insert HMR_CODE_LOOKUP.sql @@ -0,0 +1,10 @@ +// ************************************************************** +// Insert the Activity Rule codes into the HMR_CODE_LOOKUP table. +// ************************************************************** + +INSERT INTO [dbo].[HMR_CODE_LOOKUP]([CODE_SET], [CODE_NAME], [CODE_VALUE_TEXT], [CODE_VALUE_FORMAT]) VALUES('ACTIVITY_RULE', 'ROAD_LENGTH', 'Road Length', 'STRING'); +GO +INSERT INTO [dbo].[HMR_CODE_LOOKUP]([CODE_SET], [CODE_NAME], [CODE_VALUE_TEXT], [CODE_VALUE_FORMAT]) VALUES('ACTIVITY_RULE', 'SURFACE_TYPE', 'Surface Type', 'STRING'); +GO +INSERT INTO [dbo].[HMR_CODE_LOOKUP]([CODE_SET], [CODE_NAME], [CODE_VALUE_TEXT], [CODE_VALUE_FORMAT]) VALUES('ACTIVITY_RULE', 'ROAD_CLASS', 'Road Class', 'STRING'); +GO diff --git a/database/V24.0/3. Insert HMR_ACTIVITY_RULE.sql b/database/V24.0/3. Insert HMR_ACTIVITY_RULE.sql new file mode 100644 index 00000000..dff21151 --- /dev/null +++ b/database/V24.0/3. Insert HMR_ACTIVITY_RULE.sql @@ -0,0 +1,137 @@ +USE [HMR_DEV] +GO + + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH','Not Applicable','NOT_APPLICABLE',1) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [TBD Application Rate] * [Lane KM]','RATE_LANE_KM',2) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [2.0] * [Lane KM] * [3.5]','RATE_LANE_KM_35',3) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [3.0] * [Lane KM] * [6.0]','RATE_LANE_KM_60', 4) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Lane KM * 1000.0] * [3.5]','LANE_METERS_35',5) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Road KM Non-Paved]','ROAD_KM_NONPAVED',6) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Lane KM Paved] * 2.0','LANE_KM_PAVED_20',7) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Road KM] * 2.0','ROAD_KM_20',8) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Road KM * 1000.0] * 2.0','ROAD_METERS_20',9) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Road KM] * 2.0','ROAD_KM_20',10) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Road KM]','ROAD_KM',11) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Road KM * 1000.0]','ROAD_METERS',12) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Lane KM]','LANE_KM',13) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Lane KM * 1000.0]','LANE_METERS',14) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_LENGTH',N'[Qty] ≤ [Barrier Length * 1000.0]','BARRIER_LEN_METERS',15) +GO + + + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('SURFACE_TYPE','Not Applicable','NOT_APPLICABLE',1) +GO +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('SURFACE_TYPE','GPS on Paved Surface/within 100m of Structure','GPS_PAVED_STRUCTURE',2) +GO +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('SURFACE_TYPE','GPS on Paved Surface','GPS_PAVED_SURFACE',3) +GO +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('SURFACE_TYPE','GPS on Non-Paved Surface','GPS_NON_PAVED_SURFACE',4) +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_CLASS','Not Applicable','NOT_APPLICABLE',1) +GO +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_CLASS','Class 8 or F Only','CLASS_8_OR_F',2) +GO +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_CLASS','Not Class 8 or F','NOT_CLASS_8_OR_F',3) +GO +INSERT INTO [dbo].[HMR_ACTIVITY_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('ROAD_CLASS','All Classes','ALL_CLASSES',4) +GO \ No newline at end of file From b14480f7c1e93c955aa4aca7dc33c2142197f98f Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Tue, 6 Oct 2020 16:22:09 -0700 Subject: [PATCH 06/46] Updates to Activity Code Rule database changes --- .../Repositories/ActivityCodeRepository.cs | 35 --------------- .../Repositories/ActivityRuleRepository.cs | 38 ++++------------ .../Services/ActivityCodeService.cs | 44 +++++++++++++++++-- .../ActivityCode/ActivityCodeCreateDto.cs | 4 +- .../Dtos/ActivityCode/ActivityCodeDto.cs | 7 ++- .../ActivityCode/ActivityCodeSearchDto.cs | 8 ++-- .../ActivityCode/ActivityCodeUpdateDto.cs | 4 +- client/src/js/components/ActivityAdmin.js | 5 ++- 8 files changed, 66 insertions(+), 79 deletions(-) diff --git a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs index 6ac77542..8cb73ca5 100644 --- a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs @@ -64,17 +64,7 @@ public async Task CreateActivityCodeAsync(ActivityCodeCreateDto var activityCodeEntity = new HmrActivityCode(); Mapper.Map(activityCode, activityCodeEntity); - - foreach (var ruleId in activityCode.ActivityRuleIds) - { - activityCodeEntity.HmrActivityCodeRules - .Add(new HmrActivityCodeRule - { - ActivityRuleId = ruleId - }); - } - //TODO: add in saving of Service Areas await DbSet.AddAsync(activityCodeEntity); @@ -179,8 +169,6 @@ public async Task UpdateActivityCodeAsync(ActivityCodeUpdateDto activityCode) Mapper.Map(activityCode, activityCodeEntity); - SyncActivityRules(activityCode, activityCodeEntity); - //TODO: call function to sync service area changes } @@ -206,28 +194,5 @@ private async IAsyncEnumerable FindActivityNumbersInUseAync(IEnumerable< } } - private void SyncActivityRules(ActivityCodeUpdateDto activityUpdateDto, HmrActivityCode activityCodeEntity) - { - var rulesToDelete = - activityCodeEntity.HmrActivityCodeRules.Where(r => !activityUpdateDto.ActivityRuleIds.Contains(r.ActivityRuleId)).ToList(); - - for (var i = rulesToDelete.Count() - 1; i >= 0; i--) - { - DbContext.Remove(rulesToDelete[i]); - } - - var existingRuleIds = activityCodeEntity.HmrActivityCodeRules.Select(r => r.ActivityRuleId); - - var newRuleIds = activityUpdateDto.ActivityRuleIds.Where(r => !existingRuleIds.Contains(r)); - - foreach (var ruleId in newRuleIds) - { - activityCodeEntity.HmrActivityCodeRules - .Add(new HmrActivityCodeRule - { - ActivityRuleId = ruleId - }); - } - } } } diff --git a/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs index 58fff961..2e511bac 100644 --- a/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs @@ -16,6 +16,7 @@ public interface IActivityRuleRepository Task> GetRoadLengthRulesAsync(); Task> GetSurfaceTypeRulesAsync(); Task> GetRoadClassRulesAsync(); + Task> GetDefaultRules(); } public class ActivityRuleRepository : HmcrRepositoryBase, IActivityRuleRepository @@ -32,16 +33,6 @@ public async Task> GetRoadLengthRulesAsync() .ToListAsync(); return Mapper.Map>(activityRules); - - //fake data - /*ActivityRuleDto[] activityRules = new ActivityRuleDto[3] - { - new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Length Rule 1" }, - new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Length Rule 2" }, - new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Length Rule 3" } - }; - await Task.Delay(1); - return activityRules;*/ } public async Task> GetSurfaceTypeRulesAsync() { @@ -50,16 +41,6 @@ public async Task> GetSurfaceTypeRulesAsync() .ToListAsync(); return Mapper.Map>(activityRules); - - //fake data - /*ActivityRuleDto[] activityRules = new ActivityRuleDto[3] - { - new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Surface Type Rule 1" }, - new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Surface Type Rule 2" }, - new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Surface Type Rule 3" } - }; - await Task.Delay(1); - return activityRules;*/ } public async Task> GetRoadClassRulesAsync() { @@ -68,16 +49,15 @@ public async Task> GetRoadClassRulesAsync() .ToListAsync(); return Mapper.Map>(activityRules); + } + + public async Task> GetDefaultRules() + { + var activityRules = await DbSet.AsNoTracking() + .Where(s => s.ActivityRuleName.ToUpper() == "NOT APPLICABLE") + .ToListAsync(); - //fake data - /*ActivityRuleDto[] activityRules = new ActivityRuleDto[3] - { - new ActivityRuleDto{ ActivityRuleId = 1, ActivityRuleName = "Road Class Rule 1" }, - new ActivityRuleDto{ ActivityRuleId = 2, ActivityRuleName = "Road Class Rule 2" }, - new ActivityRuleDto{ ActivityRuleId = 3, ActivityRuleName = "Road Class Rule 3" } - }; - await Task.Delay(1); - return activityRules;*/ + return Mapper.Map>(activityRules); } } } diff --git a/api/Hmcr.Domain/Services/ActivityCodeService.cs b/api/Hmcr.Domain/Services/ActivityCodeService.cs index f583b651..b37bbf5c 100644 --- a/api/Hmcr.Domain/Services/ActivityCodeService.cs +++ b/api/Hmcr.Domain/Services/ActivityCodeService.cs @@ -3,6 +3,7 @@ using Hmcr.Model; using Hmcr.Model.Dtos; using Hmcr.Model.Dtos.ActivityCode; +using Hmcr.Model.Dtos.ActivityRule; using Hmcr.Model.Utils; using System.Collections.Generic; using System.Threading.Tasks; @@ -26,15 +27,17 @@ public class ActivityCodeService : IActivityCodeService private IUnitOfWork _unitOfWork; private IWorkReportRepository _workReportRepo; private ILocationCodeRepository _locationCodeRepo; + private IActivityRuleRepository _activityRuleRepo; public ActivityCodeService(IActivityCodeRepository activityCodeRepo, IFieldValidatorService validatorService, IUnitOfWork unitOfWork, - IWorkReportRepository workReportRepo, ILocationCodeRepository locationCodeRepo) + IWorkReportRepository workReportRepo, ILocationCodeRepository locationCodeRepo, IActivityRuleRepository activityRuleRepo) { _activityCodeRepo = activityCodeRepo; _validatorService = validatorService; _unitOfWork = unitOfWork; _workReportRepo = workReportRepo; _locationCodeRepo = locationCodeRepo; + _activityRuleRepo = activityRuleRepo; } public async Task<(decimal id, Dictionary> Errors)> CreateActivityCodeAsync(ActivityCodeCreateDto activityCode) @@ -52,7 +55,7 @@ public ActivityCodeService(IActivityCodeRepository activityCodeRepo, IFieldValid } var newLocationCode = (await _locationCodeRepo.GetLocationCode(activityCode.LocationCodeId)).LocationCode; - + var entityName = GetEntityName(newLocationCode); _validatorService.Validate(entityName, activityCode, errors); @@ -61,10 +64,26 @@ public ActivityCodeService(IActivityCodeRepository activityCodeRepo, IFieldValid // location code is A or B, FeatureType is forced to null and SiteNumRequired is forced to false if (newLocationCode != "C") { + IEnumerable activityRuleDefaults = await _activityRuleRepo.GetDefaultRules(); + activityCode.FeatureType = null; activityCode.SpThresholdLevel = null; activityCode.IsSiteNumRequired = false; - activityCode.ActivityRuleIds = null; + foreach (ActivityRuleDto activityRule in activityRuleDefaults) + { + if (activityRule.ActivityRuleSet == "ROAD_LENGTH") + { + activityCode.RoadLengthRule = activityRule.ActivityRuleId; + } + else if (activityRule.ActivityRuleSet == "ROAD_CLASS") + { + activityCode.RoadClassRule = activityRule.ActivityRuleId; + } + else if (activityRule.ActivityRuleSet == "SURFACE_TYPE") + { + activityCode.SurfaceTypeRule = activityRule.ActivityRuleId; + } + } } if (errors.Count > 0) @@ -143,7 +162,7 @@ public async Task> GetActivityCodesAsync(string[ { errors.AddItem(Fields.LocationCodeId, $"LocationCode can only be changed to A"); } - + var entityName = GetEntityName(newLocationCode); _validatorService.Validate(entityName, activityCode, errors); @@ -152,9 +171,26 @@ public async Task> GetActivityCodesAsync(string[ // location code is A or B, FeatureType is forced to null and SiteNumRequired is forced to false if (newLocationCode != "C") { + IEnumerable activityRuleDefaults = await _activityRuleRepo.GetDefaultRules(); + activityCode.FeatureType = null; activityCode.SpThresholdLevel = null; activityCode.IsSiteNumRequired = false; + foreach (ActivityRuleDto activityRule in activityRuleDefaults) + { + if (activityRule.ActivityRuleSet == "ROAD_LENGTH") + { + activityCode.RoadLengthRule = activityRule.ActivityRuleId; + } + else if (activityRule.ActivityRuleSet == "ROAD_CLASS") + { + activityCode.RoadClassRule = activityRule.ActivityRuleId; + } + else if (activityRule.ActivityRuleSet == "SURFACE_TYPE") + { + activityCode.SurfaceTypeRule = activityRule.ActivityRuleId; + } + } } if (errors.Count > 0) diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs index 12ed955c..4c50decb 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs @@ -14,7 +14,9 @@ public class ActivityCodeCreateDto public string SpThresholdLevel { get; set; } public bool IsSiteNumRequired { get; set; } public DateTime? EndDate { get; set; } - public virtual IList ActivityRuleIds { get; set; } + public decimal RoadLengthRule { get; set; } + public decimal SurfaceTypeRule { get; set; } + public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } } } \ No newline at end of file diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs index 86d51296..815b63f4 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs @@ -23,10 +23,9 @@ public class ActivityCodeDto public LocationCodeDto LocationCode { get; set; } - public virtual IList ActivityRuleIds { get; set; } - public decimal? RoadLengthRule { get; set; } - public decimal? SurfaceTypeRule { get; set; } - public decimal? RoadClassRule { get; set; } + public decimal RoadLengthRule { get; set; } + public decimal SurfaceTypeRule { get; set; } + public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs index 03b37f57..905c85be 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs @@ -20,10 +20,10 @@ public class ActivityCodeSearchDto public DateTime? EndDate { get; set; } public bool IsActive => EndDate == null || EndDate > DateTime.Today; public bool IsReferenced { get; set; } - public virtual IList ActivityRuleIds { get; set; } - public decimal? RoadLengthRule { get; set; } - public decimal? SurfaceTypeRule { get; set; } - public decimal? RoadClassRule { get; set; } + + public decimal RoadLengthRule { get; set; } + public decimal SurfaceTypeRule { get; set; } + public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs index c7c31740..b2e8a7ec 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs @@ -14,7 +14,9 @@ public class ActivityCodeUpdateDto public string SpThresholdLevel { get; set; } public bool IsSiteNumRequired { get; set; } public DateTime? EndDate { get; set; } - public virtual IList ActivityRuleIds { get; set; } + public decimal RoadLengthRule { get; set; } + public decimal SurfaceTypeRule { get; set; } + public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } } } diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index 5416cacf..114d73d5 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -105,8 +105,11 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal values.featureType = null; values.isSiteNumRequired = false; values.thresholdLevels = null; + values.roadClassRule = 0; + values.roadLengthRule = 0; + values.surfaceTypeRule = 0; } - + if (formType === Constants.FORM_TYPE.ADD) { api .postActivityCode(values) From 476acac1b21764950547dd185790bcb823a1497d Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Wed, 7 Oct 2020 12:00:36 -0700 Subject: [PATCH 07/46] Updates to Database The relationship between Activity Code to Code Rule was simplified. --- ...1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql} | 309 ++++++------------ ...ERT_HMR_ACTIVITY_CODE_RULES_V24_IS2.1.sql} | 56 ++-- ...R_ACTIVITY_CODE_FOREIGN_KEYS_V24_IS2.1.sql | 41 +++ ..._LOOKUP_ACTIVITY_RULE_TYPES_V24_IS2.1.sql} | 12 +- 4 files changed, 190 insertions(+), 228 deletions(-) rename database/V24.0/{1. Alter HMR_V2.0.sql => 1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql} (74%) rename database/V24.0/{3. Insert HMR_ACTIVITY_RULE.sql => 2_HMR_PDM-dml_INSERT_HMR_ACTIVITY_CODE_RULES_V24_IS2.1.sql} (76%) create mode 100644 database/V24.0/3_HMR_PDM-ddl_ALTER_ACTIVITY_CODE_FOREIGN_KEYS_V24_IS2.1.sql rename database/V24.0/{2. Insert HMR_CODE_LOOKUP.sql => 4_HMR_PDM-dml_HMR_CODE_LOOKUP_ACTIVITY_RULE_TYPES_V24_IS2.1.sql} (64%) diff --git a/database/V24.0/1. Alter HMR_V2.0.sql b/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql similarity index 74% rename from database/V24.0/1. Alter HMR_V2.0.sql rename to database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql index 471e3241..80de272a 100644 --- a/database/V24.0/1. Alter HMR_V2.0.sql +++ b/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql @@ -1,10 +1,16 @@ -// Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Thu Oct 01 16:38:26 PDT 2020 -// Execute this script on: -// HMR_1.3/dbo - This database/schema will be modified -// to synchronize it with MS SQL Server 2016: -// HMR_1.3 Dezign/dbo +-- Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Wed Oct 07 10:51:32 PDT 2020 +-- Execute this script on: +-- HMR_DEV/dbo - This database/schema will be modified +-- to synchronize it with MS SQL Server 2016: +-- HMR V24.0/dbo -// We recommend backing up the database prior to executing the script. +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; +GO + +-- We recommend backing up the database prior to executing the script. SET XACT_ABORT ON GO @@ -15,7 +21,7 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Drop trigger dbo.HMR_ACT_CODE_A_S_IUD_TR +-- Drop trigger dbo.HMR_ACT_CODE_A_S_IUD_TR PRINT N'Drop trigger dbo.HMR_ACT_CODE_A_S_IUD_TR' GO DROP TRIGGER [dbo].[HMR_ACT_CODE_A_S_IUD_TR] @@ -23,7 +29,7 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Drop view dbo.HMR_WILDLIFE_REPORT_VW +-- Drop view dbo.HMR_WILDLIFE_REPORT_VW PRINT N'Drop view dbo.HMR_WILDLIFE_REPORT_VW' GO DROP VIEW [dbo].[HMR_WILDLIFE_REPORT_VW] @@ -31,7 +37,7 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Drop view dbo.HMR_ROCKFALL_REPORT_VW +-- Drop view dbo.HMR_ROCKFALL_REPORT_VW PRINT N'Drop view dbo.HMR_ROCKFALL_REPORT_VW' GO DROP VIEW [dbo].[HMR_ROCKFALL_REPORT_VW] @@ -39,7 +45,7 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Drop view dbo.HMR_WORK_REPORT_VW +-- Drop view dbo.HMR_WORK_REPORT_VW PRINT N'Drop view dbo.HMR_WORK_REPORT_VW' GO DROP VIEW [dbo].[HMR_WORK_REPORT_VW] @@ -47,7 +53,7 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Drop procedure dbo.hmr_error_handling +-- Drop procedure dbo.hmr_error_handling PRINT N'Drop procedure dbo.hmr_error_handling' GO DROP PROCEDURE [dbo].[hmr_error_handling] @@ -55,7 +61,22 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create table dbo.HMRX_TableDefinitions +-- Create sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ +PRINT N'Create sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ' +GO +CREATE SEQUENCE [dbo].[HMR_ACTIVITY_RULE_CODE_ID_SEQ] + AS bigint + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 999999999 + NO CYCLE + CACHE 50 +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create table dbo.HMRX_TableDefinitions PRINT N'Create table dbo.HMRX_TableDefinitions' GO CREATE TABLE [dbo].[HMRX_TableDefinitions] ( @@ -68,7 +89,7 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ +-- Create sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ PRINT N'Create sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ' GO CREATE SEQUENCE [dbo].[HMR_ACTIVITY_RULE_ID_SEQ] @@ -83,10 +104,48 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ -PRINT N'Create sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ' +-- Create procedure dbo.hmr_error_handling +PRINT N'Create procedure dbo.hmr_error_handling' GO -CREATE SEQUENCE [dbo].[HMR_ACTIVITY_RULE_CODE_ID_SEQ] +/* ---------------------------------------------------------------------- */ +/* Add procedures */ +/* ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +/* Add procedures */ +/* ---------------------------------------------------------------------- */ + +CREATE PROCEDURE [dbo].[hmr_error_handling] AS + + begin + DECLARE @errmsg nvarchar(2048), + @severity tinyint, + @state tinyint, + @errno int, + @proc sysname, + @lineno int + + SELECT @errmsg = error_message(), @severity = error_severity(), + @state = error_state(), @errno = error_number(), + @proc = error_procedure(), @lineno = error_line() + + IF @errmsg NOT LIKE '***%' + BEGIN + SELECT @errmsg = '*** ' + coalesce(quotename(@proc), '') + + ', Line ' + ltrim(str(@lineno)) + '. Errno ' + + ltrim(str(@errno)) + ': ' + @errmsg + END + + RAISERROR('%s', @severity, @state, @errmsg) + end +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create sequence dbo.HMR_ACTIVITY_CODE_RULE_ID_SEQ +PRINT N'Create sequence dbo.HMR_ACTIVITY_CODE_RULE_ID_SEQ' +GO +CREATE SEQUENCE [dbo].[HMR_ACTIVITY_CODE_RULE_ID_SEQ] AS bigint START WITH 1 INCREMENT BY 1 @@ -98,13 +157,13 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create table dbo.HMR_ACTIVITY_RULE -PRINT N'Create table dbo.HMR_ACTIVITY_RULE' +-- Create table dbo.HMR_ACTIVITY_CODE_RULE +PRINT N'Create table dbo.HMR_ACTIVITY_CODE_RULE' GO -CREATE TABLE [dbo].[HMR_ACTIVITY_RULE] ( - [ACTIVITY_RULE_ID] numeric(9,0) NOT NULL DEFAULT (NEXT VALUE FOR [HMR_ACTIVITY_RULE_CODE_ID_SEQ]), +CREATE TABLE [dbo].[HMR_ACTIVITY_CODE_RULE] ( + [ACTIVITY_CODE_RULE_ID] numeric(9,0) NOT NULL DEFAULT (NEXT VALUE FOR [HMR_ACTIVITY_CODE_RULE_ID_SEQ]), [ACTIVITY_RULE_SET] varchar(20) NOT NULL, - [ACTIVITY_RULE_NAME] varchar(150) NOT NULL, + [ACTIVITY_RULE_NAME] nvarchar(150) NOT NULL, [ACTIVITY_RULE_EXEC_NAME] varchar(150) NOT NULL, [DISPLAY_ORDER] numeric(3,0) NULL, [END_DATE] datetime NULL DEFAULT (getutcdate()), @@ -113,79 +172,30 @@ CREATE TABLE [dbo].[HMR_ACTIVITY_RULE] ( [DB_AUDIT_CREATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), [DB_AUDIT_LAST_UPDATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), [DB_AUDIT_LAST_UPDATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), - PRIMARY KEY CLUSTERED([ACTIVITY_RULE_ID]) - ON [PRIMARY]) -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - -// Create table dbo.HMR_ACTIVITY_CODE_RULE -PRINT N'Create table dbo.HMR_ACTIVITY_CODE_RULE' -GO -CREATE TABLE [dbo].[HMR_ACTIVITY_CODE_RULE] ( - [ACTIVITY_CODE_RULE_ID] numeric(9,0) NOT NULL DEFAULT (NEXT VALUE FOR [HMR_ACTIVITY_RULE_ID_SEQ]), - [ACTIVITY_CODE_ID] numeric(9,0) NOT NULL, - [ACTIVITY_RULE_ID] numeric(9,0) NOT NULL, - [CONCURRENCY_CONTROL_NUMBER] bigint NOT NULL DEFAULT ((1)), - [DB_AUDIT_CREATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), - [DB_AUDIT_CREATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), - [DB_AUDIT_LAST_UPDATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), - [DB_AUDIT_LAST_UPDATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), PRIMARY KEY CLUSTERED([ACTIVITY_CODE_RULE_ID]) ON [PRIMARY]) GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create unique constraint dbo.HMR_ACT_CD_RL_UK -PRINT N'Create unique constraint dbo.HMR_ACT_CD_RL_UK' +-- Alter table dbo.HMR_ACTIVITY_CODE +PRINT N'Alter table dbo.HMR_ACTIVITY_CODE' GO -ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_RULE] - ADD UNIQUE ([ACTIVITY_RULE_ID], [ACTIVITY_CODE_ID]) - WITH ( - DATA_COMPRESSION = NONE - ) ON [PRIMARY] +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE] + ADD [ROAD_CLASS_RULE] numeric(9,0) NOT NULL DEFAULT ((0)), + [ROAD_LENGTH_RULE] numeric(9,0) NOT NULL DEFAULT ((0)), + [SURFACE_TYPE_RULE] numeric(9,0) NOT NULL DEFAULT ((0)) GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create procedure dbo.hmr_error_handling -PRINT N'Create procedure dbo.hmr_error_handling' +-- Create view dbo.HMR_WORK_REPORT_VW +PRINT N'Create view dbo.HMR_WORK_REPORT_VW' GO /* ---------------------------------------------------------------------- */ -/* Add procedures */ +/* Add views */ /* ---------------------------------------------------------------------- */ -CREATE PROCEDURE [dbo].[hmr_error_handling] AS - - begin - DECLARE @errmsg nvarchar(2048), - @severity tinyint, - @state tinyint, - @errno int, - @proc sysname, - @lineno int - - SELECT @errmsg = error_message(), @severity = error_severity(), - @state = error_state(), @errno = error_number(), - @proc = error_procedure(), @lineno = error_line() - - IF @errmsg NOT LIKE '***%' - BEGIN - SELECT @errmsg = '*** ' + coalesce(quotename(@proc), '') + - ', Line ' + ltrim(str(@lineno)) + '. Errno ' + - ltrim(str(@errno)) + ': ' + @errmsg - END - - RAISERROR('%s', @severity, @state, @errmsg) - end -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - -// Create view dbo.HMR_WORK_REPORT_VW -PRINT N'Create view dbo.HMR_WORK_REPORT_VW' -GO /* ---------------------------------------------------------------------- */ /* Add views */ /* ---------------------------------------------------------------------- */ @@ -251,7 +261,7 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create view dbo.HMR_ROCKFALL_REPORT_VW +-- Create view dbo.HMR_ROCKFALL_REPORT_VW PRINT N'Create view dbo.HMR_ROCKFALL_REPORT_VW' GO /* Update 23/04/2020 @@ -320,7 +330,7 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create view dbo.HMR_WILDLIFE_REPORT_VW +-- Create view dbo.HMR_WILDLIFE_REPORT_VW PRINT N'Create view dbo.HMR_WILDLIFE_REPORT_VW' GO /* Update 23/04/2020 @@ -373,93 +383,17 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create index dbo.HMR_ACT_CD_RL_ACTV_RL_ID_FK_I -PRINT N'Create index dbo.HMR_ACT_CD_RL_ACTV_RL_ID_FK_I' -GO -CREATE NONCLUSTERED INDEX [HMR_ACT_CD_RL_ACTV_RL_ID_FK_I] - ON [dbo].[HMR_ACTIVITY_CODE_RULE]([ACTIVITY_RULE_ID]) -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - -// Create index dbo.HMR_ACT_CD_RL_ACTV_CD_ID_FK_I -PRINT N'Create index dbo.HMR_ACT_CD_RL_ACTV_CD_ID_FK_I' -GO -CREATE NONCLUSTERED INDEX [HMR_ACT_CD_RL_ACTV_CD_ID_FK_I] - ON [dbo].[HMR_ACTIVITY_CODE_RULE]([ACTIVITY_CODE_ID]) -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - -// Create foreign key constraint dbo.HMR_ACT_CD_RL_ACT_RUL_FK -PRINT N'Create foreign key constraint dbo.HMR_ACT_CD_RL_ACT_RUL_FK' -GO -ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_RULE] - ADD FOREIGN KEY([ACTIVITY_RULE_ID]) - REFERENCES [dbo].[HMR_ACTIVITY_RULE]([ACTIVITY_RULE_ID]) - ON DELETE NO ACTION - ON UPDATE NO ACTION -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - -// Create foreign key constraint dbo.HMR_ACT_CODE_ACT_CD_RL_FK -PRINT N'Create foreign key constraint dbo.HMR_ACT_CODE_ACT_CD_RL_FK' -GO -ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_RULE] - ADD FOREIGN KEY([ACTIVITY_CODE_ID]) - REFERENCES [dbo].[HMR_ACTIVITY_CODE]([ACTIVITY_CODE_ID]) - ON DELETE NO ACTION - ON UPDATE NO ACTION -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - -// Create trigger dbo.HMR_ACT_RUL_I_S_U_TR -PRINT N'Create trigger dbo.HMR_ACT_RUL_I_S_U_TR' -GO -CREATE TRIGGER [dbo].[HMR_ACT_RUL_I_S_U_TR] ON HMR_ACTIVITY_RULE INSTEAD OF UPDATE AS -SET NOCOUNT ON -BEGIN TRY - IF NOT EXISTS(SELECT * FROM deleted) - RETURN; - - -- validate concurrency control - if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACTIVITY_RULE_ID = deleted.ACTIVITY_RULE_ID) - raiserror('CONCURRENCY FAILURE.',16,1) - - - -- update statement - update HMR_ACTIVITY_RULE - set "ACTIVITY_RULE_ID" = inserted."ACTIVITY_RULE_ID", - "ACTIVITY_RULE_SET" = inserted."ACTIVITY_RULE_SET", - "ACTIVITY_RULE_NAME" = inserted."ACTIVITY_RULE_NAME", - "ACTIVITY_RULE_EXEC_NAME" = inserted."ACTIVITY_RULE_EXEC_NAME", - "DISPLAY_ORDER" = inserted."DISPLAY_ORDER", - "END_DATE" = inserted."END_DATE", - "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER" - , DB_AUDIT_LAST_UPDATE_TIMESTAMP = getutcdate() - , DB_AUDIT_LAST_UPDATE_USERID = user_name() - from HMR_ACTIVITY_RULE - inner join inserted - on (HMR_ACTIVITY_RULE.ACTIVITY_RULE_ID = inserted.ACTIVITY_RULE_ID); - -END TRY -BEGIN CATCH - IF @@trancount > 0 ROLLBACK TRANSACTION - EXEC hmr_error_handling -END CATCH; -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - -// Create trigger dbo.HMR_ACT_CODE_A_S_IUD_TR +-- Create trigger dbo.HMR_ACT_CODE_A_S_IUD_TR PRINT N'Create trigger dbo.HMR_ACT_CODE_A_S_IUD_TR' GO /* ---------------------------------------------------------------------- */ /* Add triggers */ /* ---------------------------------------------------------------------- */ +/* ---------------------------------------------------------------------- */ +/* Add triggers */ +/* ---------------------------------------------------------------------- */ + CREATE TRIGGER [dbo].[HMR_ACT_CODE_A_S_IUD_TR] ON HMR_ACTIVITY_CODE FOR INSERT, UPDATE, DELETE AS SET NOCOUNT ON BEGIN TRY @@ -485,7 +419,7 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create trigger dbo.HMR_ACT_CD_RL_I_S_U_TR +-- Create trigger dbo.HMR_ACT_CD_RL_I_S_U_TR PRINT N'Create trigger dbo.HMR_ACT_CD_RL_I_S_U_TR' GO CREATE TRIGGER [dbo].[HMR_ACT_CD_RL_I_S_U_TR] ON HMR_ACTIVITY_CODE_RULE INSTEAD OF UPDATE AS @@ -502,8 +436,11 @@ BEGIN TRY -- update statement update HMR_ACTIVITY_CODE_RULE set "ACTIVITY_CODE_RULE_ID" = inserted."ACTIVITY_CODE_RULE_ID", - "ACTIVITY_CODE_ID" = inserted."ACTIVITY_CODE_ID", - "ACTIVITY_RULE_ID" = inserted."ACTIVITY_RULE_ID", + "ACTIVITY_RULE_SET" = inserted."ACTIVITY_RULE_SET", + "ACTIVITY_RULE_NAME" = inserted."ACTIVITY_RULE_NAME", + "ACTIVITY_RULE_EXEC_NAME" = inserted."ACTIVITY_RULE_EXEC_NAME", + "DISPLAY_ORDER" = inserted."DISPLAY_ORDER", + "END_DATE" = inserted."END_DATE", "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER" , DB_AUDIT_LAST_UPDATE_TIMESTAMP = getutcdate() , DB_AUDIT_LAST_UPDATE_USERID = user_name() @@ -520,25 +457,25 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create trigger dbo.HMR_ACT_RUL_I_S_I_TR -PRINT N'Create trigger dbo.HMR_ACT_RUL_I_S_I_TR' +-- Create trigger dbo.HMR_ACT_CD_RL_I_S_I_TR +PRINT N'Create trigger dbo.HMR_ACT_CD_RL_I_S_I_TR' GO -CREATE TRIGGER [dbo].[HMR_ACT_RUL_I_S_I_TR] ON HMR_ACTIVITY_RULE INSTEAD OF INSERT AS +CREATE TRIGGER [dbo].[HMR_ACT_CD_RL_I_S_I_TR] ON HMR_ACTIVITY_CODE_RULE INSTEAD OF INSERT AS SET NOCOUNT ON BEGIN TRY IF NOT EXISTS(SELECT * FROM inserted) RETURN; - insert into HMR_ACTIVITY_RULE ( - "ACTIVITY_RULE_ID", + insert into HMR_ACTIVITY_CODE_RULE ( + "ACTIVITY_CODE_RULE_ID", "ACTIVITY_RULE_SET", "ACTIVITY_RULE_NAME", "ACTIVITY_RULE_EXEC_NAME", "DISPLAY_ORDER", "END_DATE", "CONCURRENCY_CONTROL_NUMBER") - select "ACTIVITY_RULE_ID", + select "ACTIVITY_CODE_RULE_ID", "ACTIVITY_RULE_SET", "ACTIVITY_RULE_NAME", "ACTIVITY_RULE_EXEC_NAME", @@ -556,36 +493,6 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO -// Create trigger dbo.HMR_ACT_CD_RL_I_S_I_TR -PRINT N'Create trigger dbo.HMR_ACT_CD_RL_I_S_I_TR' -GO -CREATE TRIGGER [dbo].[HMR_ACT_CD_RL_I_S_I_TR] ON HMR_ACTIVITY_CODE_RULE INSTEAD OF INSERT AS -SET NOCOUNT ON -BEGIN TRY - IF NOT EXISTS(SELECT * FROM inserted) - RETURN; - - - insert into HMR_ACTIVITY_CODE_RULE ( - "ACTIVITY_CODE_RULE_ID", - "ACTIVITY_CODE_ID", - "ACTIVITY_RULE_ID", - "CONCURRENCY_CONTROL_NUMBER") - select "ACTIVITY_CODE_RULE_ID", - "ACTIVITY_CODE_ID", - "ACTIVITY_RULE_ID", - "CONCURRENCY_CONTROL_NUMBER" - from inserted; - -END TRY -BEGIN CATCH - IF @@trancount > 0 ROLLBACK TRANSACTION - EXEC hmr_error_handling -END CATCH; -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - COMMIT TRANSACTION GO IF @@ERROR <> 0 SET NOEXEC ON diff --git a/database/V24.0/3. Insert HMR_ACTIVITY_RULE.sql b/database/V24.0/2_HMR_PDM-dml_INSERT_HMR_ACTIVITY_CODE_RULES_V24_IS2.1.sql similarity index 76% rename from database/V24.0/3. Insert HMR_ACTIVITY_RULE.sql rename to database/V24.0/2_HMR_PDM-dml_INSERT_HMR_ACTIVITY_CODE_RULES_V24_IS2.1.sql index dff21151..e9bc2673 100644 --- a/database/V24.0/3. Insert HMR_ACTIVITY_RULE.sql +++ b/database/V24.0/2_HMR_PDM-dml_INSERT_HMR_ACTIVITY_CODE_RULES_V24_IS2.1.sql @@ -1,92 +1,100 @@ -USE [HMR_DEV] +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; GO +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] + ([ACTIVITY_CODE_RULE_ID], [ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + (0, '','Default','DEFAULT',0) +GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH','Not Applicable','NOT_APPLICABLE',1) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [TBD Application Rate] * [Lane KM]','RATE_LANE_KM',2) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [2.0] * [Lane KM] * [3.5]','RATE_LANE_KM_35',3) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [3.0] * [Lane KM] * [6.0]','RATE_LANE_KM_60', 4) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Lane KM * 1000.0] * [3.5]','LANE_METERS_35',5) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Road KM Non-Paved]','ROAD_KM_NONPAVED',6) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Lane KM Paved] * 2.0','LANE_KM_PAVED_20',7) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Road KM] * 2.0','ROAD_KM_20',8) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Road KM * 1000.0] * 2.0','ROAD_METERS_20',9) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Road KM] * 2.0','ROAD_KM_20',10) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Road KM]','ROAD_KM',11) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Road KM * 1000.0]','ROAD_METERS',12) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Lane KM]','LANE_KM',13) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Lane KM * 1000.0]','LANE_METERS',14) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_LENGTH',N'[Qty] ≤ [Barrier Length * 1000.0]','BARRIER_LEN_METERS',15) @@ -94,43 +102,43 @@ GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('SURFACE_TYPE','Not Applicable','NOT_APPLICABLE',1) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('SURFACE_TYPE','GPS on Paved Surface/within 100m of Structure','GPS_PAVED_STRUCTURE',2) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('SURFACE_TYPE','GPS on Paved Surface','GPS_PAVED_SURFACE',3) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('SURFACE_TYPE','GPS on Non-Paved Surface','GPS_NON_PAVED_SURFACE',4) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_CLASS','Not Applicable','NOT_APPLICABLE',1) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_CLASS','Class 8 or F Only','CLASS_8_OR_F',2) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_CLASS','Not Class 8 or F','NOT_CLASS_8_OR_F',3) GO -INSERT INTO [dbo].[HMR_ACTIVITY_RULE] +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) VALUES ('ROAD_CLASS','All Classes','ALL_CLASSES',4) diff --git a/database/V24.0/3_HMR_PDM-ddl_ALTER_ACTIVITY_CODE_FOREIGN_KEYS_V24_IS2.1.sql b/database/V24.0/3_HMR_PDM-ddl_ALTER_ACTIVITY_CODE_FOREIGN_KEYS_V24_IS2.1.sql new file mode 100644 index 00000000..b6e42ae1 --- /dev/null +++ b/database/V24.0/3_HMR_PDM-ddl_ALTER_ACTIVITY_CODE_FOREIGN_KEYS_V24_IS2.1.sql @@ -0,0 +1,41 @@ +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; +GO + +-- Create foreign key constraint dbo.HMR_ACT_CD_RL_RD_CLSS_FK +PRINT N'Create foreign key constraint dbo.HMR_ACT_CD_RL_RD_CLSS_FK' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE] + ADD FOREIGN KEY([ROAD_CLASS_RULE]) + REFERENCES [dbo].[HMR_ACTIVITY_CODE_RULE]([ACTIVITY_CODE_RULE_ID]) + ON DELETE NO ACTION + ON UPDATE NO ACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create foreign key constraint dbo.HMR_ACT_CD_RL_RD_LNGTH_FK +PRINT N'Create foreign key constraint dbo.HMR_ACT_CD_RL_RD_LNGTH_FK' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE] + ADD FOREIGN KEY([ROAD_LENGTH_RULE]) + REFERENCES [dbo].[HMR_ACTIVITY_CODE_RULE]([ACTIVITY_CODE_RULE_ID]) + ON DELETE NO ACTION + ON UPDATE NO ACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create foreign key constraint dbo.HMR_ACT_CD_RL_SRFC_TYP_FK +PRINT N'Create foreign key constraint dbo.HMR_ACT_CD_RL_SRFC_TYP_FK' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE] + ADD FOREIGN KEY([SURFACE_TYPE_RULE]) + REFERENCES [dbo].[HMR_ACTIVITY_CODE_RULE]([ACTIVITY_CODE_RULE_ID]) + ON DELETE NO ACTION + ON UPDATE NO ACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO \ No newline at end of file diff --git a/database/V24.0/2. Insert HMR_CODE_LOOKUP.sql b/database/V24.0/4_HMR_PDM-dml_HMR_CODE_LOOKUP_ACTIVITY_RULE_TYPES_V24_IS2.1.sql similarity index 64% rename from database/V24.0/2. Insert HMR_CODE_LOOKUP.sql rename to database/V24.0/4_HMR_PDM-dml_HMR_CODE_LOOKUP_ACTIVITY_RULE_TYPES_V24_IS2.1.sql index 8259f358..5c84aa49 100644 --- a/database/V24.0/2. Insert HMR_CODE_LOOKUP.sql +++ b/database/V24.0/4_HMR_PDM-dml_HMR_CODE_LOOKUP_ACTIVITY_RULE_TYPES_V24_IS2.1.sql @@ -1,6 +1,12 @@ -// ************************************************************** -// Insert the Activity Rule codes into the HMR_CODE_LOOKUP table. -// ************************************************************** +-- ************************************************************** +-- Insert the Activity Rule codes into the HMR_CODE_LOOKUP table. +-- ************************************************************** + +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; +GO INSERT INTO [dbo].[HMR_CODE_LOOKUP]([CODE_SET], [CODE_NAME], [CODE_VALUE_TEXT], [CODE_VALUE_FORMAT]) VALUES('ACTIVITY_RULE', 'ROAD_LENGTH', 'Road Length', 'STRING'); GO From 902fe1859f8babe87c0f629c150bba77ad55c1b5 Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Wed, 7 Oct 2020 16:56:04 -0700 Subject: [PATCH 08/46] Updates to Entity Model and cascaded changes thru the Service, Repo and Controller --- .../Controllers/ActivityRuleController.cs | 6 +- .../Database/Entities/AppDbContext.cs | 137 +++++++-------- .../Database/Entities/HmrActivityCode.cs | 12 +- .../Database/Entities/HmrActivityCodeRule.cs | 19 ++- .../Database/Entities/HmrActivityRule.cs | 27 --- .../Mappings/EntityToModelProfile.cs | 2 +- .../Mappings/ModelToEntityProfile.cs | 2 +- .../Repositories/ActivityCodeRepository.cs | 7 +- .../Repositories/ActivityRuleRepository.cs | 26 +-- .../Services/ActivityCodeService.cs | 20 +-- .../Services/ActivityRuleService.cs | 12 +- .../ActivityCodeRuleDto.cs} | 4 +- .../Dtos/ActivityRule/RoadLengthRuleDto.cs | 18 -- .../1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql | 156 +++++++++++++++++- 14 files changed, 267 insertions(+), 181 deletions(-) delete mode 100644 api/Hmcr.Data/Database/Entities/HmrActivityRule.cs rename api/Hmcr.Model/Dtos/{ActivityRule/ActivityRuleDto.cs => ActivityCodeRule/ActivityCodeRuleDto.cs} (82%) delete mode 100644 api/Hmcr.Model/Dtos/ActivityRule/RoadLengthRuleDto.cs diff --git a/api/Hmcr.Api/Controllers/ActivityRuleController.cs b/api/Hmcr.Api/Controllers/ActivityRuleController.cs index 2ee41544..fc0349c4 100644 --- a/api/Hmcr.Api/Controllers/ActivityRuleController.cs +++ b/api/Hmcr.Api/Controllers/ActivityRuleController.cs @@ -24,19 +24,19 @@ public ActivityRuleController(IActivityRuleService activityRuleSvc) } [HttpGet("roadlength")] - public async Task>> GetRoadLengthRulesAsync() + public async Task>> GetRoadLengthRulesAsync() { return Ok(await _activityRuleSvc.GetRoadLengthRulesAsync()); } [HttpGet("surfacetype")] - public async Task>> GetSurfaceTypeRulesAsync() + public async Task>> GetSurfaceTypeRulesAsync() { return Ok(await _activityRuleSvc.GetSurfaceTypeRulesAsync()); } [HttpGet("roadclass")] - public async Task>> GetRoadClassRulesAsync() + public async Task>> GetRoadClassRulesAsync() { return Ok(await _activityRuleSvc.GetRoadClassRulesAsync()); } diff --git a/api/Hmcr.Data/Database/Entities/AppDbContext.cs b/api/Hmcr.Data/Database/Entities/AppDbContext.cs index 4c480521..d080b2dd 100644 --- a/api/Hmcr.Data/Database/Entities/AppDbContext.cs +++ b/api/Hmcr.Data/Database/Entities/AppDbContext.cs @@ -18,7 +18,6 @@ public AppDbContext(DbContextOptions options) public virtual DbSet HmrActivityCodes { get; set; } public virtual DbSet HmrActivityCodeHists { get; set; } public virtual DbSet HmrActivityCodeRules { get; set; } - public virtual DbSet HmrActivityRules { get; set; } public virtual DbSet HmrCodeLookups { get; set; } public virtual DbSet HmrCodeLookupHists { get; set; } public virtual DbSet HmrContractTerms { get; set; } @@ -63,7 +62,8 @@ public AppDbContext(DbContextOptions options) public virtual DbSet HmrWorkReports { get; set; } public virtual DbSet HmrWorkReportHists { get; set; } public virtual DbSet HmrWorkReportVws { get; set; } - + public virtual DbSet HmrxTableDefinitions { get; set; } + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => @@ -214,12 +214,24 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .IsUnicode(false) .HasComment(" Classification of maintenance activities which specifies detail of submission or reporting requirements (ie: Routine, Quantified, Additional). Routine - reoccuring maintenace activities that require less detailed reporting Quantified - maintenance activities that require more detailed reporting Additional - activities that exceed agreement threasholds"); + entity.Property(e => e.RoadClassRule) + .HasColumnName("ROAD_CLASS_RULE") + .HasColumnType("numeric(9, 0)"); + + entity.Property(e => e.RoadLengthRule) + .HasColumnName("ROAD_LENGTH_RULE") + .HasColumnType("numeric(9, 0)"); + entity.Property(e => e.SpThresholdLevel) .HasColumnName("SP_THRESHOLD_LEVEL") .HasMaxLength(30) .IsUnicode(false) .HasComment("Determines the tolerated spatial variance allowed when comparing submitted activity coordinates vs the related Highway Unique road segment. Each level is defined within the CODE_LOOKUP table under the THRSHLD_SP_VAR code"); + entity.Property(e => e.SurfaceTypeRule) + .HasColumnName("SURFACE_TYPE_RULE") + .HasColumnType("numeric(9, 0)"); + entity.Property(e => e.UnitOfMeasure) .IsRequired() .HasColumnName("UNIT_OF_MEASURE") @@ -232,6 +244,24 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasForeignKey(d => d.LocationCodeId) .OnDelete(DeleteBehavior.ClientSetNull) .HasConstraintName("HMR_ACT_CODE_LOC_CODE_FK"); + + entity.HasOne(d => d.RoadClassRuleNavigation) + .WithMany(p => p.HmrActivityCodeRoadClassRuleNavigations) + .HasForeignKey(d => d.RoadClassRule) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK__HMR_ACTIV__ROAD___17786E0C"); + + entity.HasOne(d => d.RoadLengthRuleNavigation) + .WithMany(p => p.HmrActivityCodeRoadLengthRuleNavigations) + .HasForeignKey(d => d.RoadLengthRule) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK__HMR_ACTIV__ROAD___186C9245"); + + entity.HasOne(d => d.SurfaceTypeRuleNavigation) + .WithMany(p => p.HmrActivityCodeSurfaceTypeRuleNavigations) + .HasForeignKey(d => d.SurfaceTypeRule) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK__HMR_ACTIV__SURFA__1960B67E"); }); modelBuilder.Entity(entity => @@ -373,85 +403,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { entity.HasKey(e => e.ActivityCodeRuleId) - .HasName("PK__HMR_ACTI__E4140F7DCE60BEDD"); + .HasName("PK__HMR_ACTI__E4140F7DF4DEC3AC"); entity.ToTable("HMR_ACTIVITY_CODE_RULE"); - entity.HasIndex(e => e.ActivityCodeId) - .HasName("HMR_ACT_CD_RL_ACTV_CD_ID_FK_I"); - - entity.HasIndex(e => e.ActivityRuleId) - .HasName("HMR_ACT_CD_RL_ACTV_RL_ID_FK_I"); - - entity.HasIndex(e => new { e.ActivityRuleId, e.ActivityCodeId }) - .HasName("UQ__HMR_ACTI__FAB2688C30F75933") - .IsUnique(); - entity.Property(e => e.ActivityCodeRuleId) .HasColumnName("ACTIVITY_CODE_RULE_ID") .HasColumnType("numeric(9, 0)") - .HasDefaultValueSql("(NEXT VALUE FOR [HMR_ACTIVITY_RULE_ID_SEQ])"); - - entity.Property(e => e.ActivityCodeId) - .HasColumnName("ACTIVITY_CODE_ID") - .HasColumnType("numeric(9, 0)"); - - entity.Property(e => e.ActivityRuleId) - .HasColumnName("ACTIVITY_RULE_ID") - .HasColumnType("numeric(9, 0)"); - - entity.Property(e => e.ConcurrencyControlNumber) - .HasColumnName("CONCURRENCY_CONTROL_NUMBER") - .HasDefaultValueSql("((1))"); - - entity.Property(e => e.DbAuditCreateTimestamp) - .HasColumnName("DB_AUDIT_CREATE_TIMESTAMP") - .HasColumnType("datetime") - .HasDefaultValueSql("(getutcdate())"); - - entity.Property(e => e.DbAuditCreateUserid) - .IsRequired() - .HasColumnName("DB_AUDIT_CREATE_USERID") - .HasMaxLength(30) - .IsUnicode(false) - .HasDefaultValueSql("(user_name())"); - - entity.Property(e => e.DbAuditLastUpdateTimestamp) - .HasColumnName("DB_AUDIT_LAST_UPDATE_TIMESTAMP") - .HasColumnType("datetime") - .HasDefaultValueSql("(getutcdate())"); - - entity.Property(e => e.DbAuditLastUpdateUserid) - .IsRequired() - .HasColumnName("DB_AUDIT_LAST_UPDATE_USERID") - .HasMaxLength(30) - .IsUnicode(false) - .HasDefaultValueSql("(user_name())"); - - entity.HasOne(d => d.ActivityCode) - .WithMany(p => p.HmrActivityCodeRules) - .HasForeignKey(d => d.ActivityCodeId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("FK__HMR_ACTIV__ACTIV__407A839F"); - - entity.HasOne(d => d.ActivityRule) - .WithMany(p => p.HmrActivityCodeRules) - .HasForeignKey(d => d.ActivityRuleId) - .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("FK__HMR_ACTIV__ACTIV__3F865F66"); - }); - - modelBuilder.Entity(entity => - { - entity.HasKey(e => e.ActivityRuleId) - .HasName("PK__HMR_ACTI__1F8CFB4801F64DAA"); - - entity.ToTable("HMR_ACTIVITY_RULE"); - - entity.Property(e => e.ActivityRuleId) - .HasColumnName("ACTIVITY_RULE_ID") - .HasColumnType("numeric(9, 0)") - .HasDefaultValueSql("(NEXT VALUE FOR [HMR_ACTIVITY_RULE_CODE_ID_SEQ])"); + .HasDefaultValueSql("(NEXT VALUE FOR [HMR_ACTIVITY_CODE_RULE_ID_SEQ])"); entity.Property(e => e.ActivityRuleExecName) .IsRequired() @@ -462,8 +421,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.ActivityRuleName) .IsRequired() .HasColumnName("ACTIVITY_RULE_NAME") - .HasMaxLength(150) - .IsUnicode(false); + .HasMaxLength(150); entity.Property(e => e.ActivityRuleSet) .IsRequired() @@ -6541,6 +6499,27 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasColumnType("numeric(9, 0)"); }); + modelBuilder.Entity(entity => + { + entity.HasNoKey(); + + entity.ToTable("HMRX_TableDefinitions"); + + entity.Property(e => e.Description).HasColumnName("DESCRIPTION"); + + entity.Property(e => e.Hist) + .HasColumnName("HIST") + .HasMaxLength(1); + + entity.Property(e => e.TableAlias) + .HasColumnName("TABLE_ALIAS") + .HasMaxLength(255); + + entity.Property(e => e.TableName) + .HasColumnName("TABLE_NAME") + .HasMaxLength(255); + }); + modelBuilder.HasSequence("FDBK_MSG_ID_SEQ") .HasMin(1) .HasMax(999999999); @@ -6553,6 +6532,10 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMin(1) .HasMax(2147483647); + modelBuilder.HasSequence("HMR_ACTIVITY_CODE_RULE_ID_SEQ") + .HasMin(1) + .HasMax(999999999); + modelBuilder.HasSequence("HMR_ACTIVITY_RULE_CODE_ID_SEQ") .HasMin(1) .HasMax(999999999); diff --git a/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs b/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs index 831a3525..2b63daf6 100644 --- a/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs +++ b/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs @@ -5,11 +5,6 @@ namespace Hmcr.Data.Database.Entities { public partial class HmrActivityCode { - public HmrActivityCode() - { - HmrActivityCodeRules = new HashSet(); - } - public decimal ActivityCodeId { get; set; } public string ActivityNumber { get; set; } public string ActivityName { get; set; } @@ -34,8 +29,13 @@ public HmrActivityCode() public DateTime DbAuditCreateTimestamp { get; set; } public string DbAuditLastUpdateUserid { get; set; } public DateTime DbAuditLastUpdateTimestamp { get; set; } + public decimal RoadClassRule { get; set; } + public decimal RoadLengthRule { get; set; } + public decimal SurfaceTypeRule { get; set; } public virtual HmrLocationCode LocationCode { get; set; } - public virtual ICollection HmrActivityCodeRules { get; set; } + public virtual HmrActivityCodeRule RoadClassRuleNavigation { get; set; } + public virtual HmrActivityCodeRule RoadLengthRuleNavigation { get; set; } + public virtual HmrActivityCodeRule SurfaceTypeRuleNavigation { get; set; } } } diff --git a/api/Hmcr.Data/Database/Entities/HmrActivityCodeRule.cs b/api/Hmcr.Data/Database/Entities/HmrActivityCodeRule.cs index d3471f3d..06757583 100644 --- a/api/Hmcr.Data/Database/Entities/HmrActivityCodeRule.cs +++ b/api/Hmcr.Data/Database/Entities/HmrActivityCodeRule.cs @@ -5,16 +5,27 @@ namespace Hmcr.Data.Database.Entities { public partial class HmrActivityCodeRule { + public HmrActivityCodeRule() + { + HmrActivityCodeRoadClassRuleNavigations = new HashSet(); + HmrActivityCodeRoadLengthRuleNavigations = new HashSet(); + HmrActivityCodeSurfaceTypeRuleNavigations = new HashSet(); + } + public decimal ActivityCodeRuleId { get; set; } - public decimal ActivityCodeId { get; set; } - public decimal ActivityRuleId { get; set; } + public string ActivityRuleSet { get; set; } + public string ActivityRuleName { get; set; } + public string ActivityRuleExecName { get; set; } + public decimal? DisplayOrder { get; set; } + public DateTime? EndDate { get; set; } public long ConcurrencyControlNumber { get; set; } public string DbAuditCreateUserid { get; set; } public DateTime DbAuditCreateTimestamp { get; set; } public string DbAuditLastUpdateUserid { get; set; } public DateTime DbAuditLastUpdateTimestamp { get; set; } - public virtual HmrActivityCode ActivityCode { get; set; } - public virtual HmrActivityRule ActivityRule { get; set; } + public virtual ICollection HmrActivityCodeRoadClassRuleNavigations { get; set; } + public virtual ICollection HmrActivityCodeRoadLengthRuleNavigations { get; set; } + public virtual ICollection HmrActivityCodeSurfaceTypeRuleNavigations { get; set; } } } diff --git a/api/Hmcr.Data/Database/Entities/HmrActivityRule.cs b/api/Hmcr.Data/Database/Entities/HmrActivityRule.cs deleted file mode 100644 index c3c11fc3..00000000 --- a/api/Hmcr.Data/Database/Entities/HmrActivityRule.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; - -namespace Hmcr.Data.Database.Entities -{ - public partial class HmrActivityRule - { - public HmrActivityRule() - { - HmrActivityCodeRules = new HashSet(); - } - - public decimal ActivityRuleId { get; set; } - public string ActivityRuleSet { get; set; } - public string ActivityRuleName { get; set; } - public string ActivityRuleExecName { get; set; } - public decimal? DisplayOrder { get; set; } - public DateTime? EndDate { get; set; } - public long ConcurrencyControlNumber { get; set; } - public string DbAuditCreateUserid { get; set; } - public DateTime DbAuditCreateTimestamp { get; set; } - public string DbAuditLastUpdateUserid { get; set; } - public DateTime DbAuditLastUpdateTimestamp { get; set; } - - public virtual ICollection HmrActivityCodeRules { get; set; } - } -} diff --git a/api/Hmcr.Data/Mappings/EntityToModelProfile.cs b/api/Hmcr.Data/Mappings/EntityToModelProfile.cs index a3a8f4d1..63d37cfc 100644 --- a/api/Hmcr.Data/Mappings/EntityToModelProfile.cs +++ b/api/Hmcr.Data/Mappings/EntityToModelProfile.cs @@ -112,7 +112,7 @@ public EntityToModelProfile() CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); } } diff --git a/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs b/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs index 7cc9de4f..2732b8a4 100644 --- a/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs +++ b/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs @@ -98,7 +98,7 @@ public ModelToEntityProfile() CreateMap(); CreateMap(); - CreateMap(); + CreateMap(); } } } diff --git a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs index 8cb73ca5..179d7a24 100644 --- a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs @@ -77,7 +77,6 @@ public async Task GetActivityCodeAsync(decimal id) var activityCodeEntity = await DbSet.AsNoTracking() //todo ServiceArea //.Include(x => x.HmrServiceAreaRules) //new table - .Include(x => x.HmrActivityCodeRules) //new table .FirstOrDefaultAsync(ac => ac.ActivityCodeId == id); if (activityCodeEntity == null) @@ -86,13 +85,13 @@ public async Task GetActivityCodeAsync(decimal id) var activityCode = Mapper.Map(activityCodeEntity); activityCode.IsReferenced = await _workReportRepo.IsActivityNumberInUseAsync(activityCode.ActivityNumber); - - var activityRules = activityCodeEntity + + /*var activityRules = activityCodeEntity .HmrActivityCodeRules .Select(s => s.ActivityCodeRuleId) .ToList(); - /*var activityRules = new List { 1, 3 }; + var activityRules = new List { 1, 3 }; activityCode.ActivityRuleIds = activityRules; activityCode.RoadLengthRule = 2; activityCode.SurfaceTypeRule = 3; diff --git a/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs index 2e511bac..01825a34 100644 --- a/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs @@ -13,51 +13,51 @@ namespace Hmcr.Data.Repositories { public interface IActivityRuleRepository { - Task> GetRoadLengthRulesAsync(); - Task> GetSurfaceTypeRulesAsync(); - Task> GetRoadClassRulesAsync(); - Task> GetDefaultRules(); + Task> GetRoadLengthRulesAsync(); + Task> GetSurfaceTypeRulesAsync(); + Task> GetRoadClassRulesAsync(); + Task> GetDefaultRules(); } - public class ActivityRuleRepository : HmcrRepositoryBase, IActivityRuleRepository + public class ActivityRuleRepository : HmcrRepositoryBase, IActivityRuleRepository { public ActivityRuleRepository(AppDbContext dbContext, IMapper mapper) : base(dbContext, mapper) { } - public async Task> GetRoadLengthRulesAsync() + public async Task> GetRoadLengthRulesAsync() { var activityRules = await DbSet.AsNoTracking() .Where(s => s.ActivityRuleSet.ToUpper() == "ROAD_LENGTH") .ToListAsync(); - return Mapper.Map>(activityRules); + return Mapper.Map>(activityRules); } - public async Task> GetSurfaceTypeRulesAsync() + public async Task> GetSurfaceTypeRulesAsync() { var activityRules = await DbSet.AsNoTracking() .Where(s => s.ActivityRuleSet.ToUpper() == "SURFACE_TYPE") .ToListAsync(); - return Mapper.Map>(activityRules); + return Mapper.Map>(activityRules); } - public async Task> GetRoadClassRulesAsync() + public async Task> GetRoadClassRulesAsync() { var activityRules = await DbSet.AsNoTracking() .Where(s => s.ActivityRuleSet.ToUpper() == "ROAD_CLASS") .ToListAsync(); - return Mapper.Map>(activityRules); + return Mapper.Map>(activityRules); } - public async Task> GetDefaultRules() + public async Task> GetDefaultRules() { var activityRules = await DbSet.AsNoTracking() .Where(s => s.ActivityRuleName.ToUpper() == "NOT APPLICABLE") .ToListAsync(); - return Mapper.Map>(activityRules); + return Mapper.Map>(activityRules); } } } diff --git a/api/Hmcr.Domain/Services/ActivityCodeService.cs b/api/Hmcr.Domain/Services/ActivityCodeService.cs index b37bbf5c..b379af81 100644 --- a/api/Hmcr.Domain/Services/ActivityCodeService.cs +++ b/api/Hmcr.Domain/Services/ActivityCodeService.cs @@ -64,24 +64,24 @@ public ActivityCodeService(IActivityCodeRepository activityCodeRepo, IFieldValid // location code is A or B, FeatureType is forced to null and SiteNumRequired is forced to false if (newLocationCode != "C") { - IEnumerable activityRuleDefaults = await _activityRuleRepo.GetDefaultRules(); + IEnumerable activityRuleDefaults = await _activityRuleRepo.GetDefaultRules(); activityCode.FeatureType = null; activityCode.SpThresholdLevel = null; activityCode.IsSiteNumRequired = false; - foreach (ActivityRuleDto activityRule in activityRuleDefaults) + foreach (ActivityCodeRuleDto activityRule in activityRuleDefaults) { if (activityRule.ActivityRuleSet == "ROAD_LENGTH") { - activityCode.RoadLengthRule = activityRule.ActivityRuleId; + activityCode.RoadLengthRule = activityRule.ActivityCodeRuleId; } else if (activityRule.ActivityRuleSet == "ROAD_CLASS") { - activityCode.RoadClassRule = activityRule.ActivityRuleId; + activityCode.RoadClassRule = activityRule.ActivityCodeRuleId; } else if (activityRule.ActivityRuleSet == "SURFACE_TYPE") { - activityCode.SurfaceTypeRule = activityRule.ActivityRuleId; + activityCode.SurfaceTypeRule = activityRule.ActivityCodeRuleId; } } } @@ -171,24 +171,24 @@ public async Task> GetActivityCodesAsync(string[ // location code is A or B, FeatureType is forced to null and SiteNumRequired is forced to false if (newLocationCode != "C") { - IEnumerable activityRuleDefaults = await _activityRuleRepo.GetDefaultRules(); + IEnumerable activityRuleDefaults = await _activityRuleRepo.GetDefaultRules(); activityCode.FeatureType = null; activityCode.SpThresholdLevel = null; activityCode.IsSiteNumRequired = false; - foreach (ActivityRuleDto activityRule in activityRuleDefaults) + foreach (ActivityCodeRuleDto activityRule in activityRuleDefaults) { if (activityRule.ActivityRuleSet == "ROAD_LENGTH") { - activityCode.RoadLengthRule = activityRule.ActivityRuleId; + activityCode.RoadLengthRule = activityRule.ActivityCodeRuleId; } else if (activityRule.ActivityRuleSet == "ROAD_CLASS") { - activityCode.RoadClassRule = activityRule.ActivityRuleId; + activityCode.RoadClassRule = activityRule.ActivityCodeRuleId; } else if (activityRule.ActivityRuleSet == "SURFACE_TYPE") { - activityCode.SurfaceTypeRule = activityRule.ActivityRuleId; + activityCode.SurfaceTypeRule = activityRule.ActivityCodeRuleId; } } } diff --git a/api/Hmcr.Domain/Services/ActivityRuleService.cs b/api/Hmcr.Domain/Services/ActivityRuleService.cs index 0dc14997..9e8d95f3 100644 --- a/api/Hmcr.Domain/Services/ActivityRuleService.cs +++ b/api/Hmcr.Domain/Services/ActivityRuleService.cs @@ -8,9 +8,9 @@ namespace Hmcr.Domain.Services { public interface IActivityRuleService { - Task> GetRoadLengthRulesAsync(); - Task> GetSurfaceTypeRulesAsync(); - Task> GetRoadClassRulesAsync(); + Task> GetRoadLengthRulesAsync(); + Task> GetSurfaceTypeRulesAsync(); + Task> GetRoadClassRulesAsync(); } public class ActivityRuleService : IActivityRuleService @@ -24,17 +24,17 @@ public ActivityRuleService(IActivityRuleRepository activityRuleRepo, IUnitOfWork _unitOfWork = unitOfWork; } - public async Task> GetRoadLengthRulesAsync() + public async Task> GetRoadLengthRulesAsync() { return await _activityRuleRepo.GetRoadLengthRulesAsync(); } - public async Task> GetSurfaceTypeRulesAsync() + public async Task> GetSurfaceTypeRulesAsync() { return await _activityRuleRepo.GetSurfaceTypeRulesAsync(); } - public async Task> GetRoadClassRulesAsync() + public async Task> GetRoadClassRulesAsync() { return await _activityRuleRepo.GetRoadClassRulesAsync(); } diff --git a/api/Hmcr.Model/Dtos/ActivityRule/ActivityRuleDto.cs b/api/Hmcr.Model/Dtos/ActivityCodeRule/ActivityCodeRuleDto.cs similarity index 82% rename from api/Hmcr.Model/Dtos/ActivityRule/ActivityRuleDto.cs rename to api/Hmcr.Model/Dtos/ActivityCodeRule/ActivityCodeRuleDto.cs index 00233c95..9099814d 100644 --- a/api/Hmcr.Model/Dtos/ActivityRule/ActivityRuleDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCodeRule/ActivityCodeRuleDto.cs @@ -3,10 +3,10 @@ namespace Hmcr.Model.Dtos.ActivityRule { - public class ActivityRuleDto + public class ActivityCodeRuleDto { [JsonPropertyName("id")] - public decimal ActivityRuleId { get; set; } + public decimal ActivityCodeRuleId { get; set; } [JsonPropertyName("name")] public string ActivityRuleName { get; set; } public string ActivityRuleSet { get; set; } diff --git a/api/Hmcr.Model/Dtos/ActivityRule/RoadLengthRuleDto.cs b/api/Hmcr.Model/Dtos/ActivityRule/RoadLengthRuleDto.cs deleted file mode 100644 index b071786f..00000000 --- a/api/Hmcr.Model/Dtos/ActivityRule/RoadLengthRuleDto.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Text.Json.Serialization; - -namespace Hmcr.Model.Dtos.ActivityRule -{ - public class RoadLengthRuleDto - { - [JsonPropertyName("id")] - public decimal RoadLengthRuleId { get; set; } - [JsonPropertyName("name")] - public string RoadLengthRuleName { get; set; } - public string ActivityRuleSet { get; set; } - public string ActivityRuleExecName { get; set; } - public decimal DisplayOrder { get; set; } - public DateTime? EndDate { get; set; } - - } -} diff --git a/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql b/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql index 80de272a..b4e4a9ee 100644 --- a/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql +++ b/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql @@ -1,15 +1,9 @@ --- Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Wed Oct 07 10:51:32 PDT 2020 +-- Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Wed Oct 07 16:12:21 PDT 2020 -- Execute this script on: -- HMR_DEV/dbo - This database/schema will be modified -- to synchronize it with MS SQL Server 2016: -- HMR V24.0/dbo -USE HMR_DEV; -- uncomment appropriate instance ---USE HMR_TST; ---USE HMR_UAT; ---USE HMR_PRD; -GO - -- We recommend backing up the database prior to executing the script. SET XACT_ABORT ON @@ -29,6 +23,22 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Drop trigger dbo.HMR_ACT_CODE_I_S_I_TR +PRINT N'Drop trigger dbo.HMR_ACT_CODE_I_S_I_TR' +GO +DROP TRIGGER [dbo].[HMR_ACT_CODE_I_S_I_TR] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Drop trigger dbo.HMR_ACT_CODE_I_S_U_TR +PRINT N'Drop trigger dbo.HMR_ACT_CODE_I_S_U_TR' +GO +DROP TRIGGER [dbo].[HMR_ACT_CODE_I_S_U_TR] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Drop view dbo.HMR_WILDLIFE_REPORT_VW PRINT N'Drop view dbo.HMR_WILDLIFE_REPORT_VW' GO @@ -189,6 +199,17 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Alter table dbo.HMR_ACTIVITY_CODE_HIST +PRINT N'Alter table dbo.HMR_ACTIVITY_CODE_HIST' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_HIST] + ADD [ROAD_CLASS_RULE] numeric(9,0) NOT NULL DEFAULT ((0)), + [ROAD_LENGTH_RULE] numeric(9,0) NOT NULL DEFAULT ((0)), + [SURFACE_TYPE_RULE] numeric(9,0) NOT NULL DEFAULT ((0)) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Create view dbo.HMR_WORK_REPORT_VW PRINT N'Create view dbo.HMR_WORK_REPORT_VW' GO @@ -383,6 +404,123 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Create trigger dbo.HMR_ACT_CODE_I_S_U_TR +PRINT N'Create trigger dbo.HMR_ACT_CODE_I_S_U_TR' +GO +CREATE TRIGGER [dbo].[HMR_ACT_CODE_I_S_U_TR] ON HMR_ACTIVITY_CODE INSTEAD OF UPDATE AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- validate concurrency control + if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACTIVITY_CODE_ID = deleted.ACTIVITY_CODE_ID) + raiserror('CONCURRENCY FAILURE.',16,1) + + + -- update statement + update HMR_ACTIVITY_CODE + set "ACTIVITY_CODE_ID" = inserted."ACTIVITY_CODE_ID", + "ACTIVITY_NUMBER" = inserted."ACTIVITY_NUMBER", + "ACTIVITY_NAME" = inserted."ACTIVITY_NAME", + "UNIT_OF_MEASURE" = inserted."UNIT_OF_MEASURE", + "MAINTENANCE_TYPE" = inserted."MAINTENANCE_TYPE", + "LOCATION_CODE_ID" = inserted."LOCATION_CODE_ID", + "FEATURE_TYPE" = inserted."FEATURE_TYPE", + "SP_THRESHOLD_LEVEL" = inserted."SP_THRESHOLD_LEVEL", + "IS_SITE_NUM_REQUIRED" = inserted."IS_SITE_NUM_REQUIRED", + "ACTIVITY_APPLICATION" = inserted."ACTIVITY_APPLICATION", + "END_DATE" = inserted."END_DATE", + "ROAD_CLASS_RULE" = inserted."ROAD_CLASS_RULE", + "ROAD_LENGTH_RULE" = inserted."ROAD_LENGTH_RULE", + "SURFACE_TYPE_RULE" = inserted."SURFACE_TYPE_RULE", + "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER", + "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID", + "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP", + "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID", + "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY" + , DB_AUDIT_LAST_UPDATE_TIMESTAMP = getutcdate() + , DB_AUDIT_LAST_UPDATE_USERID = user_name() + from HMR_ACTIVITY_CODE + inner join inserted + on (HMR_ACTIVITY_CODE.ACTIVITY_CODE_ID = inserted.ACTIVITY_CODE_ID); + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create trigger dbo.HMR_ACT_CODE_I_S_I_TR +PRINT N'Create trigger dbo.HMR_ACT_CODE_I_S_I_TR' +GO +CREATE TRIGGER [dbo].[HMR_ACT_CODE_I_S_I_TR] ON HMR_ACTIVITY_CODE INSTEAD OF INSERT AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM inserted) + RETURN; + + + insert into HMR_ACTIVITY_CODE ("ACTIVITY_CODE_ID", + "ACTIVITY_NUMBER", + "ACTIVITY_NAME", + "UNIT_OF_MEASURE", + "MAINTENANCE_TYPE", + "LOCATION_CODE_ID", + "FEATURE_TYPE", + "SP_THRESHOLD_LEVEL", + "IS_SITE_NUM_REQUIRED", + "ACTIVITY_APPLICATION", + "END_DATE", + "ROAD_CLASS_RULE", + "ROAD_LENGTH_RULE", + "SURFACE_TYPE_RULE", + "CONCURRENCY_CONTROL_NUMBER", + "APP_CREATE_USERID", + "APP_CREATE_TIMESTAMP", + "APP_CREATE_USER_GUID", + "APP_CREATE_USER_DIRECTORY", + "APP_LAST_UPDATE_USERID", + "APP_LAST_UPDATE_TIMESTAMP", + "APP_LAST_UPDATE_USER_GUID", + "APP_LAST_UPDATE_USER_DIRECTORY") + select "ACTIVITY_CODE_ID", + "ACTIVITY_NUMBER", + "ACTIVITY_NAME", + "UNIT_OF_MEASURE", + "MAINTENANCE_TYPE", + "LOCATION_CODE_ID", + "FEATURE_TYPE", + "SP_THRESHOLD_LEVEL", + "IS_SITE_NUM_REQUIRED", + "ACTIVITY_APPLICATION", + "END_DATE", + "ROAD_CLASS_RULE", + "ROAD_LENGTH_RULE", + "SURFACE_TYPE_RULE", + "CONCURRENCY_CONTROL_NUMBER", + "APP_CREATE_USERID", + "APP_CREATE_TIMESTAMP", + "APP_CREATE_USER_GUID", + "APP_CREATE_USER_DIRECTORY", + "APP_LAST_UPDATE_USERID", + "APP_LAST_UPDATE_TIMESTAMP", + "APP_LAST_UPDATE_USER_GUID", + "APP_LAST_UPDATE_USER_DIRECTORY" + from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Create trigger dbo.HMR_ACT_CODE_A_S_IUD_TR PRINT N'Create trigger dbo.HMR_ACT_CODE_A_S_IUD_TR' GO @@ -407,8 +545,8 @@ SET @curr_date = getutcdate(); update HMR_ACTIVITY_CODE_HIST set END_DATE_HIST = @curr_date where ACTIVITY_CODE_ID in (select ACTIVITY_CODE_ID from deleted) and END_DATE_HIST is null; IF EXISTS(SELECT * FROM inserted) - insert into HMR_ACTIVITY_CODE_HIST ([ACTIVITY_CODE_ID], [ACTIVITY_NUMBER], [ACTIVITY_NAME], [UNIT_OF_MEASURE], [MAINTENANCE_TYPE], [LOCATION_CODE_ID], [FEATURE_TYPE], [SP_THRESHOLD_LEVEL], [IS_SITE_NUM_REQUIRED], [ACTIVITY_APPLICATION], [END_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], ACTIVITY_CODE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST) - select [ACTIVITY_CODE_ID], [ACTIVITY_NUMBER], [ACTIVITY_NAME], [UNIT_OF_MEASURE], [MAINTENANCE_TYPE], [LOCATION_CODE_ID], [FEATURE_TYPE], [SP_THRESHOLD_LEVEL], [IS_SITE_NUM_REQUIRED], [ACTIVITY_APPLICATION], [END_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], (next value for [dbo].[HMR_ACTIVITY_CODE_H_ID_SEQ]) as [ACTIVITY_CODE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted; + insert into HMR_ACTIVITY_CODE_HIST ([ACTIVITY_CODE_ID], [ACTIVITY_NUMBER], [ACTIVITY_NAME], [UNIT_OF_MEASURE], [MAINTENANCE_TYPE], [LOCATION_CODE_ID], [FEATURE_TYPE], [SP_THRESHOLD_LEVEL], [IS_SITE_NUM_REQUIRED], [ACTIVITY_APPLICATION], [END_DATE], [ROAD_CLASS_RULE], [ROAD_LENGTH_RULE], [SURFACE_TYPE_RULE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], ACTIVITY_CODE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST) + select [ACTIVITY_CODE_ID], [ACTIVITY_NUMBER], [ACTIVITY_NAME], [UNIT_OF_MEASURE], [MAINTENANCE_TYPE], [LOCATION_CODE_ID], [FEATURE_TYPE], [SP_THRESHOLD_LEVEL], [IS_SITE_NUM_REQUIRED], [ACTIVITY_APPLICATION], [END_DATE], [ROAD_CLASS_RULE], [ROAD_LENGTH_RULE], [SURFACE_TYPE_RULE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], (next value for [dbo].[HMR_ACTIVITY_CODE_H_ID_SEQ]) as [ACTIVITY_CODE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted; END TRY BEGIN CATCH From e966b91868c606eb301a705d21faa9d4d262dbf8 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Wed, 7 Oct 2020 17:04:22 -0700 Subject: [PATCH 09/46] activity front end --- client/src/js/components/ActivityAdmin.js | 2 +- .../forms/EditActivityFormFields.js | 154 ++++++++++++------ .../src/js/components/hooks/useFormModal.js | 6 +- 3 files changed, 108 insertions(+), 54 deletions(-) diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index 114d73d5..73828e03 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -132,7 +132,7 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal } }; - const formModal = useFormModal('Activity', , handleEditFormSubmit); + const formModal = useFormModal('Activity', , handleEditFormSubmit,'xl'); const data = searchData.data.map((item) => ({ ...item, diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 33041d23..51cf2b5a 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -11,6 +11,7 @@ import { FormRow, FormInput, FormCheckboxInput } from './FormInputs'; import * as api from '../../Api'; import * as Constants from '../../Constants'; +import { Row,Col} from 'reactstrap'; const defaultValues = { activityNumber: '', @@ -141,53 +142,95 @@ const EditActivityFormFields = ({ return ( - - - - - - - - - - - - - - - - {formValues.locationCodeId === locationCodeCId && ( - - - + + + + + + + + + + + + + + + + - + + + + + + + + + + + + +
+ Analytical Validation + + + + + + + + + +
+ +
+ + + + + + {formValues.locationCodeId === locationCodeCId && ( + + + + + + + + + )} + + + {formValues.locationCodeId === locationCodeCId && ( + + + + + )} + + + + + {formValues.locationCodeId === locationCodeCId && ( + - +
)} - - - - - - + + + + + + + +
); }; diff --git a/client/src/js/components/hooks/useFormModal.js b/client/src/js/components/hooks/useFormModal.js index e18362de..a64f8bf7 100644 --- a/client/src/js/components/hooks/useFormModal.js +++ b/client/src/js/components/hooks/useFormModal.js @@ -6,7 +6,7 @@ import SubmitButton from '../ui/SubmitButton'; import * as Constants from '../../Constants'; -const useFormModal = (formTitle, formFieldsChildElement, handleFormSubmit) => { +const useFormModal = (formTitle, formFieldsChildElement, handleFormSubmit,modSize) => { // This is needed until Formik fixes its own setSubmitting function const [submitting, setSubmitting] = useState(false); const [initialValues, setInitialValues] = useState(null); @@ -31,10 +31,10 @@ const useFormModal = (formTitle, formFieldsChildElement, handleFormSubmit) => { const onFormSubmit = (values) => handleFormSubmit(values, formType); const title = formType === Constants.FORM_TYPE.ADD ? `Add ${formTitle}` : `Edit ${formTitle}`; - + modSize = modSize===null?'sm':modSize; const formModal = () => { return ( - + {title} Date: Thu, 8 Oct 2020 08:30:01 -0700 Subject: [PATCH 10/46] updates to entity framework, removed HMRX_TableDefinition and updated HmrActivityCodeHist --- .../Database/Entities/AppDbContext.cs | 44 +++++++------------ .../Database/Entities/HmrActivityCodeHist.cs | 3 ++ 2 files changed, 20 insertions(+), 27 deletions(-) diff --git a/api/Hmcr.Data/Database/Entities/AppDbContext.cs b/api/Hmcr.Data/Database/Entities/AppDbContext.cs index d080b2dd..4292627c 100644 --- a/api/Hmcr.Data/Database/Entities/AppDbContext.cs +++ b/api/Hmcr.Data/Database/Entities/AppDbContext.cs @@ -62,8 +62,7 @@ public AppDbContext(DbContextOptions options) public virtual DbSet HmrWorkReports { get; set; } public virtual DbSet HmrWorkReportHists { get; set; } public virtual DbSet HmrWorkReportVws { get; set; } - public virtual DbSet HmrxTableDefinitions { get; set; } - + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => @@ -249,19 +248,19 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(p => p.HmrActivityCodeRoadClassRuleNavigations) .HasForeignKey(d => d.RoadClassRule) .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("FK__HMR_ACTIV__ROAD___17786E0C"); + .HasConstraintName("FK__HMR_ACTIV__ROAD___1C3D2329"); entity.HasOne(d => d.RoadLengthRuleNavigation) .WithMany(p => p.HmrActivityCodeRoadLengthRuleNavigations) .HasForeignKey(d => d.RoadLengthRule) .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("FK__HMR_ACTIV__ROAD___186C9245"); + .HasConstraintName("FK__HMR_ACTIV__ROAD___1D314762"); entity.HasOne(d => d.SurfaceTypeRuleNavigation) .WithMany(p => p.HmrActivityCodeSurfaceTypeRuleNavigations) .HasForeignKey(d => d.SurfaceTypeRule) .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("FK__HMR_ACTIV__SURFA__1960B67E"); + .HasConstraintName("FK__HMR_ACTIV__SURFA__1E256B9B"); }); modelBuilder.Entity(entity => @@ -388,11 +387,23 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMaxLength(12) .IsUnicode(false); + entity.Property(e => e.RoadClassRule) + .HasColumnName("ROAD_CLASS_RULE") + .HasColumnType("numeric(9, 0)"); + + entity.Property(e => e.RoadLengthRule) + .HasColumnName("ROAD_LENGTH_RULE") + .HasColumnType("numeric(9, 0)"); + entity.Property(e => e.SpThresholdLevel) .HasColumnName("SP_THRESHOLD_LEVEL") .HasMaxLength(30) .IsUnicode(false); + entity.Property(e => e.SurfaceTypeRule) + .HasColumnName("SURFACE_TYPE_RULE") + .HasColumnType("numeric(9, 0)"); + entity.Property(e => e.UnitOfMeasure) .IsRequired() .HasColumnName("UNIT_OF_MEASURE") @@ -403,7 +414,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { entity.HasKey(e => e.ActivityCodeRuleId) - .HasName("PK__HMR_ACTI__E4140F7DF4DEC3AC"); + .HasName("PK__HMR_ACTI__E4140F7D39105D95"); entity.ToTable("HMR_ACTIVITY_CODE_RULE"); @@ -6499,27 +6510,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasColumnType("numeric(9, 0)"); }); - modelBuilder.Entity(entity => - { - entity.HasNoKey(); - - entity.ToTable("HMRX_TableDefinitions"); - - entity.Property(e => e.Description).HasColumnName("DESCRIPTION"); - - entity.Property(e => e.Hist) - .HasColumnName("HIST") - .HasMaxLength(1); - - entity.Property(e => e.TableAlias) - .HasColumnName("TABLE_ALIAS") - .HasMaxLength(255); - - entity.Property(e => e.TableName) - .HasColumnName("TABLE_NAME") - .HasMaxLength(255); - }); - modelBuilder.HasSequence("FDBK_MSG_ID_SEQ") .HasMin(1) .HasMax(999999999); diff --git a/api/Hmcr.Data/Database/Entities/HmrActivityCodeHist.cs b/api/Hmcr.Data/Database/Entities/HmrActivityCodeHist.cs index 8b5e7d2e..41337626 100644 --- a/api/Hmcr.Data/Database/Entities/HmrActivityCodeHist.cs +++ b/api/Hmcr.Data/Database/Entities/HmrActivityCodeHist.cs @@ -32,5 +32,8 @@ public partial class HmrActivityCodeHist public DateTime DbAuditCreateTimestamp { get; set; } public string DbAuditLastUpdateUserid { get; set; } public DateTime DbAuditLastUpdateTimestamp { get; set; } + public decimal RoadClassRule { get; set; } + public decimal RoadLengthRule { get; set; } + public decimal SurfaceTypeRule { get; set; } } } From 94976e12696de73bcffa32e8ea25d5c0c8e8c0c0 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Thu, 8 Oct 2020 16:57:53 -0700 Subject: [PATCH 11/46] two column layout with additional fields --- .../forms/EditActivityFormFields.js | 34 ++++++++++++++++--- .../src/js/components/hooks/useFormModal.js | 2 +- client/src/js/components/ui/MultiSelect.js | 8 +++-- client/src/scss/_forms.scss | 26 ++++++++++++++ 4 files changed, 61 insertions(+), 9 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 51cf2b5a..7f2741fb 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -21,6 +21,9 @@ const defaultValues = { locationCodeId: '', featureType: '', spThresholdLevel: '', + minimumValue: '', + maximumValue:'', + reportingFrequency: '', roadLengthRule: '', surfaceTypeRule: '', roadClassRule: '', @@ -39,8 +42,29 @@ const validationSchema = Yup.object({ unitOfMeasure: Yup.string().required('Required').max(12), maintenanceType: Yup.string().required('Required').max(12), locationCodeId: Yup.number().required('Required'), -}); + serviceAreaNumbers: Yup.array().required('At least one Service Area must be selected'), + minimumValue: Yup.number() + .min(0) + .typeError('Must be number') + .when('unitOfMeasure', { + is:'site', + then:Yup.number().integer(), + }), + maximumValue: Yup.number() + .min(0) + .typeError('Must be number') + .when('unitOfMeasure', { + is:'site', + then:Yup.number().integer(), + }), + reportingFrequency: Yup.number() + .min(0) + .max(365) + .typeError('Must be number') + .integer(), + +}); const EditActivityFormFields = ({ setInitialValues, formValues, @@ -182,14 +206,14 @@ const EditActivityFormFields = ({ - + - + -
- Analytical Validation +
+ Analytical Validation diff --git a/client/src/js/components/hooks/useFormModal.js b/client/src/js/components/hooks/useFormModal.js index a64f8bf7..5d76331e 100644 --- a/client/src/js/components/hooks/useFormModal.js +++ b/client/src/js/components/hooks/useFormModal.js @@ -31,7 +31,7 @@ const useFormModal = (formTitle, formFieldsChildElement, handleFormSubmit,modSiz const onFormSubmit = (values) => handleFormSubmit(values, formType); const title = formType === Constants.FORM_TYPE.ADD ? `Add ${formTitle}` : `Edit ${formTitle}`; - modSize = modSize===null?'sm':modSize; + modSize = (modSize===null )?'sm':modSize; const formModal = () => { return ( diff --git a/client/src/js/components/ui/MultiSelect.js b/client/src/js/components/ui/MultiSelect.js index ddbdf49c..6f8d6aac 100644 --- a/client/src/js/components/ui/MultiSelect.js +++ b/client/src/js/components/ui/MultiSelect.js @@ -3,12 +3,14 @@ import { CustomInput, FormFeedback } from 'reactstrap'; import { FieldArray, useField, useFormikContext } from 'formik'; const MultiSelect = (props) => { - const { items, name, handleBlur, showSelectAll } = props; + const { items, name, handleBlur, showSelectAll,selectClass } = props; // eslint-disable-next-line const [field, meta] = useField(props); + const selectClassName= (selectClass===null ||selectClass===undefined||selectClass==='')?"form-control multi-select":selectClass; + const { values, setFieldValue } = useFormikContext(); const selectedValues = values[name]; - + const [selectAll, setSelectAll] = useState(false); const handleItemSelected = (checked, itemId, push, remove) => { @@ -38,7 +40,7 @@ const MultiSelect = (props) => { return (
diff --git a/client/src/scss/_forms.scss b/client/src/scss/_forms.scss index 406c975b..9c2fbf65 100644 --- a/client/src/scss/_forms.scss +++ b/client/src/scss/_forms.scss @@ -29,3 +29,29 @@ overflow: hidden; } } + +.form-control.fieldset{ + border: 1px solid; + padding: 0.375rem 0.75rem; + height: auto; + margin-bottom: 2.25rem; +} +.form-control.legend{ + border: none; +} +.col.colmargin1{ + margin-top:1.25rem +} +.form-control.servicearea-large { + background-color: #fff; + background-clip: padding-box; + border: 1px solid #ced4da; + border-radius: 0.25rem; + height: unset; + max-height: 225px; + overflow-y: auto; + padding: 0.375rem 0.75rem; +} +.form-control.servicearea-large.is-invalid { + border-color: #d93e45; +} \ No newline at end of file From c59baf49776240b0f057ab7a3fa6c292f5641abe Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Fri, 9 Oct 2020 08:50:02 -0700 Subject: [PATCH 12/46] Implemented validations for additional fields and adjusted layout --- .../forms/EditActivityFormFields.js | 201 +++++++++++------- client/src/js/components/ui/FieldSet.js | 12 ++ client/src/scss/_forms.scss | 2 +- 3 files changed, 140 insertions(+), 75 deletions(-) create mode 100644 client/src/js/components/ui/FieldSet.js diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 7f2741fb..48b38ba5 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -7,11 +7,14 @@ import SingleDateField from '../ui/SingleDateField'; import MultiSelect from '../ui/MultiSelect'; import SingleDropdownField from '../ui/SingleDropdownField'; import PageSpinner from '../ui/PageSpinner'; +import FieldSet from '../ui/FieldSet'; + import { FormRow, FormInput, FormCheckboxInput } from './FormInputs'; import * as api from '../../Api'; import * as Constants from '../../Constants'; import { Row,Col} from 'reactstrap'; +import { isInteger } from 'lodash'; const defaultValues = { activityNumber: '', @@ -46,17 +49,75 @@ const validationSchema = Yup.object({ minimumValue: Yup.number() .min(0) .typeError('Must be number') - .when('unitOfMeasure', { - is:'site', - then:Yup.number().integer(), - }), + .test( + 'datamin', + function() { + if (this.parent.minimumValue === null || this.parent.minimumValue ===undefined) + { + return true; + } + if(this.parent.maximumValue !== null || this.parent.maximumValue !==undefined) + { + if(this.parent.maximumValue >0 && this.parent.maximumValue < this.parent.minimumValue) + { + return this.createError({ + message: 'Minimum value must be less than or equal to the Minimum value', + path: 'minimumValue', + }); + } + } + if ( + this.parent.unitOfMeasure === 'site' + ||this.parent.unitOfMeasure === 'num' + ||this.parent.unitOfMeasure === 'ea') + { + if(!isInteger(this.parent.minimumValue)) + { + return this.createError({ + message: 'Minimum value must be whole number', + path: 'minimumValue', + }); + } + } + return true; + } + ), maximumValue: Yup.number() .min(0) .typeError('Must be number') - .when('unitOfMeasure', { - is:'site', - then:Yup.number().integer(), - }), + .test( + 'datamax', + function() { + if (this.parent.maximumValue === null || this.parent.maximumValue ===undefined) + { + return true; + } + if (this.parent.minimumValue !== null || this.parent.minimumValue !==undefined) + { + if(this.parent.maximumValue >0 && this.parent.maximumValue < this.parent.minimumValue) + { + return this.createError({ + message: 'Maximum value must be greater than or equal to the Minimum value', + path: 'maximumValue', + }); + } + } + if ( + this.parent.unitOfMeasure === 'site' + ||this.parent.unitOfMeasure === 'num' + ||this.parent.unitOfMeasure === 'ea') + { + if(!isInteger(this.parent.maximumValue)) + { + return this.createError({ + message: 'Maximum value must be whole number', + path: 'maximumValue', + }); + } + } + return true; + } + ), reportingFrequency: Yup.number() .min(0) .max(365) @@ -208,36 +269,35 @@ const EditActivityFormFields = ({ - + + + + -
- Analytical Validation +
- + - + -
+
- - - - - - {formValues.locationCodeId === locationCodeCId && ( - + {formValues.locationCodeId === locationCodeCId && ( + + + @@ -248,56 +308,49 @@ const EditActivityFormFields = ({ name="spThresholdLevel" /> - - )} - - - {formValues.locationCodeId === locationCodeCId && ( - + + + + + +
+ + + + + + + + + +
+ +
- - - - - - - - - - - - )} - - - - - {formValues.locationCodeId === locationCodeCId && ( - - - - - )} - - - - - - - - + )} + + + + + + + + + + ); }; diff --git a/client/src/js/components/ui/FieldSet.js b/client/src/js/components/ui/FieldSet.js new file mode 100644 index 00000000..991833af --- /dev/null +++ b/client/src/js/components/ui/FieldSet.js @@ -0,0 +1,12 @@ +import React from 'react'; + +const FieldSet = ({ legendname,children }) => { + return ( +
+ {legendname} + {children} +
+ ); +}; + +export default FieldSet; diff --git a/client/src/scss/_forms.scss b/client/src/scss/_forms.scss index 9c2fbf65..74adfc0e 100644 --- a/client/src/scss/_forms.scss +++ b/client/src/scss/_forms.scss @@ -48,7 +48,7 @@ border: 1px solid #ced4da; border-radius: 0.25rem; height: unset; - max-height: 225px; + max-height: 174px; overflow-y: auto; padding: 0.375rem 0.75rem; } From bb4f2b2c9ad8f660f3f94e10dafbd2c2ecbfbf49 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Fri, 9 Oct 2020 09:15:25 -0700 Subject: [PATCH 13/46] fixed small typo --- .../js/components/forms/EditActivityFormFields.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 48b38ba5..ef552394 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -52,13 +52,13 @@ const validationSchema = Yup.object({ .test( 'datamin', function() { - if (this.parent.minimumValue === null || this.parent.minimumValue ===undefined) + if (this.parent.minimumValue === null || this.parent.minimumValue === undefined || this.parent.minimumValue === '') { return true; } - if(this.parent.maximumValue !== null || this.parent.maximumValue !==undefined) + if(this.parent.maximumValue !== null || this.parent.maximumValue !== undefined || this.parent.maximumValue !== '') { - if(this.parent.maximumValue >0 && this.parent.maximumValue < this.parent.minimumValue) + if(this.parent.maximumValue > 0 && this.parent.maximumValue < this.parent.minimumValue) { return this.createError({ message: 'Minimum value must be less than or equal to the Minimum value', @@ -88,13 +88,13 @@ const validationSchema = Yup.object({ .test( 'datamax', function() { - if (this.parent.maximumValue === null || this.parent.maximumValue ===undefined) + if (this.parent.maximumValue === null || this.parent.maximumValue === undefined || this.parent.maximumValue === '') { return true; } - if (this.parent.minimumValue !== null || this.parent.minimumValue !==undefined) + if (this.parent.minimumValue !== null || this.parent.minimumValue !== undefined || this.parent.minimumValue === '') { - if(this.parent.maximumValue >0 && this.parent.maximumValue < this.parent.minimumValue) + if(this.parent.maximumValue > 0 && this.parent.maximumValue < this.parent.minimumValue) { return this.createError({ message: 'Maximum value must be greater than or equal to the Minimum value', From 307959840914d4edc86ef9e61789674e0bd5239b Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Fri, 9 Oct 2020 13:23:05 -0700 Subject: [PATCH 14/46] fixed null field issue --- api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs | 4 ++++ api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs | 4 ++++ client/src/js/components/forms/EditActivityFormFields.js | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs index 815b63f4..fe103126 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs @@ -28,5 +28,9 @@ public class ActivityCodeDto public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } + public decimal? MinimumValue { get; set; } + public decimal? MaximumValue { get; set; } + public decimal? ReportingFrequency { get; set; } + } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs index 905c85be..0d448394 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs @@ -25,5 +25,9 @@ public class ActivityCodeSearchDto public decimal SurfaceTypeRule { get; set; } public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } + + public decimal? MinimumValue { get; set; } + public decimal? MaximumValue { get; set; } + public decimal? ReportingFrequency { get; set; } } } diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index ef552394..98947259 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -171,7 +171,6 @@ const EditActivityFormFields = ({ }); setValidationSchema(defaultValidationSchema); - setLoading(true); if (formType === Constants.FORM_TYPE.ADD) { @@ -182,6 +181,9 @@ const EditActivityFormFields = ({ setInitialValues({ ...response.data, endDate: response.data.endDate ? moment(response.data.endDate) : null, + minimumValue: response.data.minimumValue ? moment(response.data.minimumValue):'', + maximumValue: response.data.maximumValue? moment(response.data.maximumValue):'', + reportingFrequency: response.data.reportingFrequency? moment(response.data.reportingFrequency):'', }); setValidLocationCodeValues(() => { @@ -366,6 +368,9 @@ const mapStateToProps = (state) => { surfaceTypeRules: state.codeLookups.surfaceTypeRules, roadClassRules: state.codeLookups.roadClassRules, serviceAreas: Object.values(state.serviceAreas), + minimumValue: state.codeLookups.minimumValue, + maximumValue: state.codeLookups.maximumValue, + reportingFrequency: state.codeLookups.maximumValue, }; }; From effdc3d950abb82a1ade7dd06a3c7111cc3cdb88 Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Wed, 14 Oct 2020 09:43:12 -0700 Subject: [PATCH 15/46] new sprint version --- openshift/configmaps/api-appsettings.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openshift/configmaps/api-appsettings.yaml b/openshift/configmaps/api-appsettings.yaml index 67923f68..a75275d9 100644 --- a/openshift/configmaps/api-appsettings.yaml +++ b/openshift/configmaps/api-appsettings.yaml @@ -9,7 +9,7 @@ objects: { "AllowedHosts": "*", "Constants": { - "Version": "1.3.1.0", + "Version": "1.3.2.0", "SwaggerApiUrl": "/swagger/v1/swagger.json" }, "Serilog": { From ba3935f20f86c5dce4809cefe9adec97a9c76198 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Wed, 14 Oct 2020 13:14:54 -0700 Subject: [PATCH 16/46] Fixed Not Applicable Fixed fieldset css Fixed title Highway Attribute Validation --- .../js/components/forms/EditActivityFormFields.js | 13 +++++++++---- client/src/scss/_forms.scss | 1 + 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 98947259..d8265ec7 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -147,6 +147,9 @@ const EditActivityFormFields = ({ const [disableLocationCodeEdit, setDisableLocationCodeEdit] = useState(false); const [validFeatureTypeValues, setValidFeatureTypeValues] = useState(featureTypes); const locationCodeCId = locationCodes.find((code) => code.name === 'C').id; + const roadLengthRuleDefaultId = roadLengthRules.find((rlr) => rlr.name === 'Not Applicable').id; + const surfaceTypeRuleDefaultId = surfaceTypeRules.find((str) => str.name === 'Not Applicable').id; + const roadClassRuleDefaultId =roadClassRules.find((rcr) => rcr.name === 'Not Applicable').id; useEffect(() => { // Add validation for point line feature when location code is C. @@ -169,11 +172,13 @@ const EditActivityFormFields = ({ then: Yup.boolean().required('Required'), }), }); - setValidationSchema(defaultValidationSchema); setLoading(true); if (formType === Constants.FORM_TYPE.ADD) { + defaultValues.roadLengthRule = roadLengthRuleDefaultId; + defaultValues.surfaceTypeRule = surfaceTypeRuleDefaultId; + defaultValues.roadClassRule = roadClassRuleDefaultId; setInitialValues(defaultValues); setLoading(false); } else { @@ -194,7 +199,7 @@ const EditActivityFormFields = ({ return locationCodes; }); - + setDisableLocationCodeEdit(() => { if (formType === Constants.FORM_TYPE.EDIT) { if (response.data.locationCodeId === locationCodes.find((code) => code.name === 'A').id) return true; @@ -291,7 +296,7 @@ const EditActivityFormFields = ({ - +
@@ -315,7 +320,7 @@ const EditActivityFormFields = ({ -
+
Date: Wed, 14 Oct 2020 14:26:00 -0700 Subject: [PATCH 17/46] database updates V25 - Added table HMR_SERVICE_AREA_ACTIVITY - Added table HMR_SERVICE_AREA_ACTIVITY_HIST - Altered HMR_CODE_LOOKUP - Added column IS_INTEGER_ONLY - Altered table HMR_ACTIVITY_CODE - Added column MIN_VALUE - Added column MAX_VALUE - Added column REPORTING_FREQUENCY --- .../Database/Entities/AppDbContext.cs | 242 +++++++++++- .../Database/Entities/HmrActivityCode.cs | 9 + .../Database/Entities/HmrCodeLookup.cs | 1 + .../Database/Entities/HmrServiceArea.cs | 2 + .../Entities/HmrServiceAreaActivity.cs | 29 ++ .../Entities/HmrServiceAreaActivityHist.cs | 29 ++ .../1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql | 348 ++++++++++++++++++ 7 files changed, 652 insertions(+), 8 deletions(-) create mode 100644 api/Hmcr.Data/Database/Entities/HmrServiceAreaActivity.cs create mode 100644 api/Hmcr.Data/Database/Entities/HmrServiceAreaActivityHist.cs create mode 100644 database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql diff --git a/api/Hmcr.Data/Database/Entities/AppDbContext.cs b/api/Hmcr.Data/Database/Entities/AppDbContext.cs index 4292627c..448528da 100644 --- a/api/Hmcr.Data/Database/Entities/AppDbContext.cs +++ b/api/Hmcr.Data/Database/Entities/AppDbContext.cs @@ -40,6 +40,8 @@ public AppDbContext(DbContextOptions options) public virtual DbSet HmrRolePermissions { get; set; } public virtual DbSet HmrRolePermissionHists { get; set; } public virtual DbSet HmrServiceAreas { get; set; } + public virtual DbSet HmrServiceAreaActivities { get; set; } + public virtual DbSet HmrServiceAreaActivityHists { get; set; } public virtual DbSet HmrServiceAreaHists { get; set; } public virtual DbSet HmrServiceAreaUsers { get; set; } public virtual DbSet HmrServiceAreaUserHists { get; set; } @@ -213,6 +215,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .IsUnicode(false) .HasComment(" Classification of maintenance activities which specifies detail of submission or reporting requirements (ie: Routine, Quantified, Additional). Routine - reoccuring maintenace activities that require less detailed reporting Quantified - maintenance activities that require more detailed reporting Additional - activities that exceed agreement threasholds"); + entity.Property(e => e.MaxValue) + .HasColumnName("MAX_VALUE") + .HasColumnType("numeric(11, 2)"); + + entity.Property(e => e.MinValue) + .HasColumnName("MIN_VALUE") + .HasColumnType("numeric(11, 2)"); + + entity.Property(e => e.ReportingFrequency).HasColumnName("REPORTING_FREQUENCY"); + entity.Property(e => e.RoadClassRule) .HasColumnName("ROAD_CLASS_RULE") .HasColumnType("numeric(9, 0)"); @@ -572,6 +584,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasColumnName("END_DATE") .HasColumnType("datetime") .HasComment("The latest date submissions will be accepted."); + + entity.Property(e => e.IsIntegerOnly).HasColumnName("IS_INTEGER_ONLY"); }); modelBuilder.Entity(entity => @@ -3121,6 +3135,218 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasConstraintName("HMR_SRV_AREA_DISTRICT_FK"); }); + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ServiceAreaActivityId) + .HasName("PK__HMR_SERV__56CBEAED34A3F264"); + + entity.ToTable("HMR_SERVICE_AREA_ACTIVITY"); + + entity.HasIndex(e => e.ActivityCodeId) + .HasName("IDX_HMR_SVC_AR_ACT_ACT_CD"); + + entity.HasIndex(e => e.ServiceAreaNumber) + .HasName("IDX_HMR_SVC_AR_ACT_SVC_AREA"); + + entity.HasIndex(e => new { e.ServiceAreaNumber, e.ActivityCodeId }) + .HasName("UQ__HMR_SERV__307B5DE25CCB5D28") + .IsUnique(); + + entity.Property(e => e.ServiceAreaActivityId) + .HasColumnName("SERVICE_AREA_ACTIVITY_ID") + .HasColumnType("numeric(9, 0)") + .HasDefaultValueSql("(NEXT VALUE FOR [HMR_SERVICE_AREA_ACTIVITY_ID_SEQ])"); + + entity.Property(e => e.ActivityCodeId) + .HasColumnName("ACTIVITY_CODE_ID") + .HasColumnType("numeric(9, 0)"); + + entity.Property(e => e.AppCreateTimestamp) + .HasColumnName("APP_CREATE_TIMESTAMP") + .HasColumnType("datetime"); + + entity.Property(e => e.AppCreateUserDirectory) + .IsRequired() + .HasColumnName("APP_CREATE_USER_DIRECTORY") + .HasMaxLength(12) + .IsUnicode(false); + + entity.Property(e => e.AppCreateUserGuid).HasColumnName("APP_CREATE_USER_GUID"); + + entity.Property(e => e.AppCreateUserid) + .IsRequired() + .HasColumnName("APP_CREATE_USERID") + .HasMaxLength(30) + .IsUnicode(false); + + entity.Property(e => e.AppLastUpdateTimestamp) + .HasColumnName("APP_LAST_UPDATE_TIMESTAMP") + .HasColumnType("datetime"); + + entity.Property(e => e.AppLastUpdateUserDirectory) + .IsRequired() + .HasColumnName("APP_LAST_UPDATE_USER_DIRECTORY") + .HasMaxLength(12) + .IsUnicode(false); + + entity.Property(e => e.AppLastUpdateUserGuid).HasColumnName("APP_LAST_UPDATE_USER_GUID"); + + entity.Property(e => e.AppLastUpdateUserid) + .IsRequired() + .HasColumnName("APP_LAST_UPDATE_USERID") + .HasMaxLength(30) + .IsUnicode(false); + + entity.Property(e => e.ConcurrencyControlNumber) + .HasColumnName("CONCURRENCY_CONTROL_NUMBER") + .HasDefaultValueSql("((1))"); + + entity.Property(e => e.DbAuditCreateTimestamp) + .HasColumnName("DB_AUDIT_CREATE_TIMESTAMP") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + + entity.Property(e => e.DbAuditCreateUserid) + .IsRequired() + .HasColumnName("DB_AUDIT_CREATE_USERID") + .HasMaxLength(30) + .IsUnicode(false) + .HasDefaultValueSql("(user_name())"); + + entity.Property(e => e.DbAuditLastUpdateTimestamp) + .HasColumnName("DB_AUDIT_LAST_UPDATE_TIMESTAMP") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + + entity.Property(e => e.DbAuditLastUpdateUserid) + .IsRequired() + .HasColumnName("DB_AUDIT_LAST_UPDATE_USERID") + .HasMaxLength(30) + .IsUnicode(false) + .HasDefaultValueSql("(user_name())"); + + entity.Property(e => e.EndDate) + .HasColumnName("END_DATE") + .HasColumnType("datetime"); + + entity.Property(e => e.ServiceAreaNumber) + .HasColumnName("SERVICE_AREA_NUMBER") + .HasColumnType("numeric(9, 0)"); + + entity.HasOne(d => d.ActivityCode) + .WithMany(p => p.HmrServiceAreaActivities) + .HasForeignKey(d => d.ActivityCodeId) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK__HMR_SERVI__ACTIV__65AC084E"); + + entity.HasOne(d => d.ServiceAreaNumberNavigation) + .WithMany(p => p.HmrServiceAreaActivities) + .HasForeignKey(d => d.ServiceAreaNumber) + .OnDelete(DeleteBehavior.ClientSetNull) + .HasConstraintName("FK__HMR_SERVI__SERVI__64B7E415"); + }); + + modelBuilder.Entity(entity => + { + entity.HasKey(e => e.ServiceAreaActivityHistId) + .HasName("PK__HMR_SERV__08C5944CC6D91E3A"); + + entity.ToTable("HMR_SERVICE_AREA_ACTIVITY_HIST"); + + entity.Property(e => e.ServiceAreaActivityHistId) + .HasColumnName("SERVICE_AREA_ACTIVITY_HIST_ID") + .HasDefaultValueSql("(NEXT VALUE FOR [HMR_SERVICE_AREA_ACTIVITY_H_ID_SEQ])"); + + entity.Property(e => e.ActivityCodeId) + .HasColumnName("ACTIVITY_CODE_ID") + .HasColumnType("numeric(9, 0)"); + + entity.Property(e => e.AppCreateTimestamp) + .HasColumnName("APP_CREATE_TIMESTAMP") + .HasColumnType("datetime"); + + entity.Property(e => e.AppCreateUserDirectory) + .IsRequired() + .HasColumnName("APP_CREATE_USER_DIRECTORY") + .HasMaxLength(12) + .IsUnicode(false); + + entity.Property(e => e.AppCreateUserGuid).HasColumnName("APP_CREATE_USER_GUID"); + + entity.Property(e => e.AppCreateUserid) + .IsRequired() + .HasColumnName("APP_CREATE_USERID") + .HasMaxLength(30) + .IsUnicode(false); + + entity.Property(e => e.AppLastUpdateTimestamp) + .HasColumnName("APP_LAST_UPDATE_TIMESTAMP") + .HasColumnType("datetime"); + + entity.Property(e => e.AppLastUpdateUserDirectory) + .IsRequired() + .HasColumnName("APP_LAST_UPDATE_USER_DIRECTORY") + .HasMaxLength(12) + .IsUnicode(false); + + entity.Property(e => e.AppLastUpdateUserGuid).HasColumnName("APP_LAST_UPDATE_USER_GUID"); + + entity.Property(e => e.AppLastUpdateUserid) + .IsRequired() + .HasColumnName("APP_LAST_UPDATE_USERID") + .HasMaxLength(30) + .IsUnicode(false); + + entity.Property(e => e.ConcurrencyControlNumber) + .HasColumnName("CONCURRENCY_CONTROL_NUMBER") + .HasDefaultValueSql("((1))"); + + entity.Property(e => e.DbAuditCreateTimestamp) + .HasColumnName("DB_AUDIT_CREATE_TIMESTAMP") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + + entity.Property(e => e.DbAuditCreateUserid) + .IsRequired() + .HasColumnName("DB_AUDIT_CREATE_USERID") + .HasMaxLength(30) + .IsUnicode(false) + .HasDefaultValueSql("(user_name())"); + + entity.Property(e => e.DbAuditLastUpdateTimestamp) + .HasColumnName("DB_AUDIT_LAST_UPDATE_TIMESTAMP") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + + entity.Property(e => e.DbAuditLastUpdateUserid) + .IsRequired() + .HasColumnName("DB_AUDIT_LAST_UPDATE_USERID") + .HasMaxLength(30) + .IsUnicode(false) + .HasDefaultValueSql("(user_name())"); + + entity.Property(e => e.EffectiveDateHist) + .HasColumnName("EFFECTIVE_DATE_HIST") + .HasColumnType("datetime") + .HasDefaultValueSql("(getutcdate())"); + + entity.Property(e => e.EndDate) + .HasColumnName("END_DATE") + .HasColumnType("datetime"); + + entity.Property(e => e.EndDateHist) + .HasColumnName("END_DATE_HIST") + .HasColumnType("datetime"); + + entity.Property(e => e.ServiceAreaActivityId) + .HasColumnName("SERVICE_AREA_ACTIVITY_ID") + .HasColumnType("numeric(9, 0)"); + + entity.Property(e => e.ServiceAreaNumber) + .HasColumnName("SERVICE_AREA_NUMBER") + .HasColumnType("numeric(9, 0)"); + }); + modelBuilder.Entity(entity => { entity.HasKey(e => e.ServiceAreaHistId) @@ -6526,14 +6752,6 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMin(1) .HasMax(999999999); - modelBuilder.HasSequence("HMR_ACTIVITY_RULE_CODE_ID_SEQ") - .HasMin(1) - .HasMax(999999999); - - modelBuilder.HasSequence("HMR_ACTIVITY_RULE_ID_SEQ") - .HasMin(1) - .HasMax(999999999); - modelBuilder.HasSequence("HMR_CNT_TRM_ID_SEQ") .HasMin(1) .HasMax(999999999); @@ -6610,6 +6828,14 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMin(1) .HasMax(2147483647); + modelBuilder.HasSequence("HMR_SERVICE_AREA_ACTIVITY_H_ID_SEQ") + .HasMin(1) + .HasMax(999999999); + + modelBuilder.HasSequence("HMR_SERVICE_AREA_ACTIVITY_ID_SEQ") + .HasMin(1) + .HasMax(999999999); + modelBuilder.HasSequence("HMR_SERVICE_AREA_H_ID_SEQ") .HasMin(1) .HasMax(2147483647); diff --git a/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs b/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs index 2b63daf6..a5f5605e 100644 --- a/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs +++ b/api/Hmcr.Data/Database/Entities/HmrActivityCode.cs @@ -5,6 +5,11 @@ namespace Hmcr.Data.Database.Entities { public partial class HmrActivityCode { + public HmrActivityCode() + { + HmrServiceAreaActivities = new HashSet(); + } + public decimal ActivityCodeId { get; set; } public string ActivityNumber { get; set; } public string ActivityName { get; set; } @@ -32,10 +37,14 @@ public partial class HmrActivityCode public decimal RoadClassRule { get; set; } public decimal RoadLengthRule { get; set; } public decimal SurfaceTypeRule { get; set; } + public decimal? MinValue { get; set; } + public decimal? MaxValue { get; set; } + public int? ReportingFrequency { get; set; } public virtual HmrLocationCode LocationCode { get; set; } public virtual HmrActivityCodeRule RoadClassRuleNavigation { get; set; } public virtual HmrActivityCodeRule RoadLengthRuleNavigation { get; set; } public virtual HmrActivityCodeRule SurfaceTypeRuleNavigation { get; set; } + public virtual ICollection HmrServiceAreaActivities { get; set; } } } diff --git a/api/Hmcr.Data/Database/Entities/HmrCodeLookup.cs b/api/Hmcr.Data/Database/Entities/HmrCodeLookup.cs index 96473433..6cca393c 100644 --- a/api/Hmcr.Data/Database/Entities/HmrCodeLookup.cs +++ b/api/Hmcr.Data/Database/Entities/HmrCodeLookup.cs @@ -18,5 +18,6 @@ public partial class HmrCodeLookup public DateTime DbAuditCreateTimestamp { get; set; } public string DbAuditLastUpdateUserid { get; set; } public DateTime DbAuditLastUpdateTimestamp { get; set; } + public bool IsIntegerOnly { get; set; } } } diff --git a/api/Hmcr.Data/Database/Entities/HmrServiceArea.cs b/api/Hmcr.Data/Database/Entities/HmrServiceArea.cs index 8ced7ca7..da8b3580 100644 --- a/api/Hmcr.Data/Database/Entities/HmrServiceArea.cs +++ b/api/Hmcr.Data/Database/Entities/HmrServiceArea.cs @@ -9,6 +9,7 @@ public HmrServiceArea() { HmrContractTerms = new HashSet(); HmrRockfallReports = new HashSet(); + HmrServiceAreaActivities = new HashSet(); HmrServiceAreaUsers = new HashSet(); HmrSubmissionObjects = new HashSet(); HmrWildlifeReports = new HashSet(); @@ -29,6 +30,7 @@ public HmrServiceArea() public virtual HmrDistrict DistrictNumberNavigation { get; set; } public virtual ICollection HmrContractTerms { get; set; } public virtual ICollection HmrRockfallReports { get; set; } + public virtual ICollection HmrServiceAreaActivities { get; set; } public virtual ICollection HmrServiceAreaUsers { get; set; } public virtual ICollection HmrSubmissionObjects { get; set; } public virtual ICollection HmrWildlifeReports { get; set; } diff --git a/api/Hmcr.Data/Database/Entities/HmrServiceAreaActivity.cs b/api/Hmcr.Data/Database/Entities/HmrServiceAreaActivity.cs new file mode 100644 index 00000000..9ee42b74 --- /dev/null +++ b/api/Hmcr.Data/Database/Entities/HmrServiceAreaActivity.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace Hmcr.Data.Database.Entities +{ + public partial class HmrServiceAreaActivity + { + public decimal ServiceAreaActivityId { get; set; } + public decimal ActivityCodeId { get; set; } + public decimal ServiceAreaNumber { get; set; } + public DateTime? EndDate { get; set; } + public long ConcurrencyControlNumber { get; set; } + public string AppCreateUserid { get; set; } + public DateTime AppCreateTimestamp { get; set; } + public Guid AppCreateUserGuid { get; set; } + public string AppCreateUserDirectory { get; set; } + public string AppLastUpdateUserid { get; set; } + public DateTime AppLastUpdateTimestamp { get; set; } + public Guid AppLastUpdateUserGuid { get; set; } + public string AppLastUpdateUserDirectory { get; set; } + public string DbAuditCreateUserid { get; set; } + public DateTime DbAuditCreateTimestamp { get; set; } + public string DbAuditLastUpdateUserid { get; set; } + public DateTime DbAuditLastUpdateTimestamp { get; set; } + + public virtual HmrActivityCode ActivityCode { get; set; } + public virtual HmrServiceArea ServiceAreaNumberNavigation { get; set; } + } +} diff --git a/api/Hmcr.Data/Database/Entities/HmrServiceAreaActivityHist.cs b/api/Hmcr.Data/Database/Entities/HmrServiceAreaActivityHist.cs new file mode 100644 index 00000000..38848d92 --- /dev/null +++ b/api/Hmcr.Data/Database/Entities/HmrServiceAreaActivityHist.cs @@ -0,0 +1,29 @@ +using System; +using System.Collections.Generic; + +namespace Hmcr.Data.Database.Entities +{ + public partial class HmrServiceAreaActivityHist + { + public long ServiceAreaActivityHistId { get; set; } + public DateTime EffectiveDateHist { get; set; } + public DateTime? EndDateHist { get; set; } + public decimal ServiceAreaActivityId { get; set; } + public decimal ActivityCodeId { get; set; } + public decimal ServiceAreaNumber { get; set; } + public DateTime? EndDate { get; set; } + public long ConcurrencyControlNumber { get; set; } + public string AppCreateUserid { get; set; } + public DateTime AppCreateTimestamp { get; set; } + public Guid AppCreateUserGuid { get; set; } + public string AppCreateUserDirectory { get; set; } + public string AppLastUpdateUserid { get; set; } + public DateTime AppLastUpdateTimestamp { get; set; } + public Guid AppLastUpdateUserGuid { get; set; } + public string AppLastUpdateUserDirectory { get; set; } + public string DbAuditCreateUserid { get; set; } + public DateTime DbAuditCreateTimestamp { get; set; } + public string DbAuditLastUpdateUserid { get; set; } + public DateTime DbAuditLastUpdateTimestamp { get; set; } + } +} diff --git a/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql b/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql new file mode 100644 index 00000000..26a51ce1 --- /dev/null +++ b/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql @@ -0,0 +1,348 @@ +-- Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Tue Oct 13 13:43:48 PDT 2020 +-- Execute this script on: +-- HMR V24.0/dbo - This database/schema will be modified +-- to synchronize it with MS SQL Server 2016: +-- HMR V25.0/dbo + +-- We recommend backing up the database prior to executing the script. + +SET XACT_ABORT ON +GO +SET TRANSACTION ISOLATION LEVEL SERIALIZABLE +GO +BEGIN TRANSACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Drop sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ +PRINT N'Drop sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ' +GO +DROP SEQUENCE [dbo].[HMR_ACTIVITY_RULE_ID_SEQ] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Drop sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ +PRINT N'Drop sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ' +GO +DROP SEQUENCE [dbo].[HMR_ACTIVITY_RULE_CODE_ID_SEQ] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create sequence dbo.HMR_SERVICE_AREA_ACTIVITY_ID_SEQ +PRINT N'Create sequence dbo.HMR_SERVICE_AREA_ACTIVITY_ID_SEQ' +GO +CREATE SEQUENCE [dbo].[HMR_SERVICE_AREA_ACTIVITY_ID_SEQ] + AS bigint + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 999999999 + NO CYCLE + CACHE 50 +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Alter table dbo.HMR_ACTIVITY_CODE +PRINT N'Alter table dbo.HMR_ACTIVITY_CODE' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE] + ADD [MIN_VALUE] numeric(11,2) NULL, + [MAX_VALUE] numeric(11,2) NULL, + [REPORTING_FREQUENCY] int NULL +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create check constraint dbo.CC_HMR_ACTIVITY_CODE_REPORTING_FREQUENCY +PRINT N'Create check constraint dbo.CC_HMR_ACTIVITY_CODE_REPORTING_FREQUENCY' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE] + ADD CHECK ([REPORTING_FREQUENCY]>=(0) AND [REPORTING_FREQUENCY]<=(366)) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create check constraint dbo.CC_HMR_ACTIVITY_CODE_MIN_VALUE +PRINT N'Create check constraint dbo.CC_HMR_ACTIVITY_CODE_MIN_VALUE' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE] + ADD CHECK ([MIN_VALUE]>=(0) AND [MIN_VALUE]<=(999999999.99)) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create check constraint dbo.CC_HMR_ACTIVITY_CODE_MAX_VALUE +PRINT N'Create check constraint dbo.CC_HMR_ACTIVITY_CODE_MAX_VALUE' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE] + ADD CHECK ([MAX_VALUE]>=(0) AND [MAX_VALUE]<=(999999999.99)) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create table dbo.HMR_SERVICE_AREA_ACTIVITY +PRINT N'Create table dbo.HMR_SERVICE_AREA_ACTIVITY' +GO +CREATE TABLE [dbo].[HMR_SERVICE_AREA_ACTIVITY] ( + [SERVICE_AREA_ACTIVITY_ID] numeric(9,0) NOT NULL DEFAULT (NEXT VALUE FOR [HMR_SERVICE_AREA_ACTIVITY_ID_SEQ]), + [ACTIVITY_CODE_ID] numeric(9,0) NOT NULL, + [SERVICE_AREA_NUMBER] numeric(9,0) NOT NULL, + [END_DATE] datetime NULL, + [CONCURRENCY_CONTROL_NUMBER] bigint NOT NULL DEFAULT ((1)), + [APP_CREATE_USERID] varchar(30) NOT NULL, + [APP_CREATE_TIMESTAMP] datetime NOT NULL, + [APP_CREATE_USER_GUID] uniqueidentifier NOT NULL, + [APP_CREATE_USER_DIRECTORY] varchar(12) NOT NULL, + [APP_LAST_UPDATE_USERID] varchar(30) NOT NULL, + [APP_LAST_UPDATE_TIMESTAMP] datetime NOT NULL, + [APP_LAST_UPDATE_USER_GUID] uniqueidentifier NOT NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] varchar(12) NOT NULL, + [DB_AUDIT_CREATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), + [DB_AUDIT_CREATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), + [DB_AUDIT_LAST_UPDATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), + [DB_AUDIT_LAST_UPDATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), + PRIMARY KEY CLUSTERED([SERVICE_AREA_ACTIVITY_ID]) + ON [PRIMARY]) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create unique constraint dbo.TUC_HMR_SERVICE_AREA_ACTIVITY_1 +PRINT N'Create unique constraint dbo.TUC_HMR_SERVICE_AREA_ACTIVITY_1' +GO +ALTER TABLE [dbo].[HMR_SERVICE_AREA_ACTIVITY] + ADD UNIQUE ([SERVICE_AREA_NUMBER], [ACTIVITY_CODE_ID]) + WITH ( + DATA_COMPRESSION = NONE + ) ON [PRIMARY] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create sequence dbo.HMR_SERVICE_AREA_ACTIVITY_H_ID_SEQ +PRINT N'Create sequence dbo.HMR_SERVICE_AREA_ACTIVITY_H_ID_SEQ' +GO +CREATE SEQUENCE [dbo].[HMR_SERVICE_AREA_ACTIVITY_H_ID_SEQ] + AS bigint + START WITH 1 + INCREMENT BY 1 + MINVALUE 1 + MAXVALUE 999999999 + NO CYCLE + CACHE 50 +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create table dbo.HMR_SERVICE_AREA_ACTIVITY_HIST +PRINT N'Create table dbo.HMR_SERVICE_AREA_ACTIVITY_HIST' +GO +CREATE TABLE [dbo].[HMR_SERVICE_AREA_ACTIVITY_HIST] ( + [SERVICE_AREA_ACTIVITY_HIST_ID] bigint NOT NULL DEFAULT (NEXT VALUE FOR [HMR_SERVICE_AREA_ACTIVITY_H_ID_SEQ]), + [EFFECTIVE_DATE_HIST] datetime NOT NULL DEFAULT (getutcdate()), + [END_DATE_HIST] datetime NULL, + [SERVICE_AREA_ACTIVITY_ID] numeric(9,0) NOT NULL, + [ACTIVITY_CODE_ID] numeric(9,0) NOT NULL, + [SERVICE_AREA_NUMBER] numeric(9,0) NOT NULL, + [END_DATE] datetime NULL, + [CONCURRENCY_CONTROL_NUMBER] bigint NOT NULL DEFAULT ((1)), + [APP_CREATE_USERID] varchar(30) NOT NULL, + [APP_CREATE_TIMESTAMP] datetime NOT NULL, + [APP_CREATE_USER_GUID] uniqueidentifier NOT NULL, + [APP_CREATE_USER_DIRECTORY] varchar(12) NOT NULL, + [APP_LAST_UPDATE_USERID] varchar(30) NOT NULL, + [APP_LAST_UPDATE_TIMESTAMP] datetime NOT NULL, + [APP_LAST_UPDATE_USER_GUID] uniqueidentifier NOT NULL, + [APP_LAST_UPDATE_USER_DIRECTORY] varchar(12) NOT NULL, + [DB_AUDIT_CREATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), + [DB_AUDIT_CREATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), + [DB_AUDIT_LAST_UPDATE_USERID] varchar(30) NOT NULL DEFAULT (user_name()), + [DB_AUDIT_LAST_UPDATE_TIMESTAMP] datetime NOT NULL DEFAULT (getutcdate()), + PRIMARY KEY CLUSTERED([SERVICE_AREA_ACTIVITY_HIST_ID]) + ON [PRIMARY]) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Alter table dbo.HMR_CODE_LOOKUP +PRINT N'Alter table dbo.HMR_CODE_LOOKUP' +GO +ALTER TABLE [dbo].[HMR_CODE_LOOKUP] + ADD [IS_INTEGER_ONLY] bit NOT NULL DEFAULT ((0)) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create index dbo.IDX_HMR_SVC_AR_ACT_ACT_CD +PRINT N'Create index dbo.IDX_HMR_SVC_AR_ACT_ACT_CD' +GO +CREATE NONCLUSTERED INDEX [IDX_HMR_SVC_AR_ACT_ACT_CD] + ON [dbo].[HMR_SERVICE_AREA_ACTIVITY]([ACTIVITY_CODE_ID]) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create index dbo.IDX_HMR_SVC_AR_ACT_SVC_AREA +PRINT N'Create index dbo.IDX_HMR_SVC_AR_ACT_SVC_AREA' +GO +CREATE NONCLUSTERED INDEX [IDX_HMR_SVC_AR_ACT_SVC_AREA] + ON [dbo].[HMR_SERVICE_AREA_ACTIVITY]([SERVICE_AREA_NUMBER]) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create foreign key constraint dbo.HMR_SERVICE_AREA_HMR_SERVICE_AREA_ACTIVITY +PRINT N'Create foreign key constraint dbo.HMR_SERVICE_AREA_HMR_SERVICE_AREA_ACTIVITY' +GO +ALTER TABLE [dbo].[HMR_SERVICE_AREA_ACTIVITY] + ADD FOREIGN KEY([SERVICE_AREA_NUMBER]) + REFERENCES [dbo].[HMR_SERVICE_AREA]([SERVICE_AREA_NUMBER]) + ON DELETE NO ACTION + ON UPDATE NO ACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create foreign key constraint dbo.HMR_ACTIVITY_CODE_HMR_SERVICE_AREA_ACTIVITY +PRINT N'Create foreign key constraint dbo.HMR_ACTIVITY_CODE_HMR_SERVICE_AREA_ACTIVITY' +GO +ALTER TABLE [dbo].[HMR_SERVICE_AREA_ACTIVITY] + ADD FOREIGN KEY([ACTIVITY_CODE_ID]) + REFERENCES [dbo].[HMR_ACTIVITY_CODE]([ACTIVITY_CODE_ID]) + ON DELETE NO ACTION + ON UPDATE NO ACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create trigger dbo.HMR_SVC_AR_ACT_A_S_IUD_TR +PRINT N'Create trigger dbo.HMR_SVC_AR_ACT_A_S_IUD_TR' +GO +CREATE TRIGGER [dbo].[HMR_SVC_AR_ACT_A_S_IUD_TR] ON HMR_SERVICE_AREA_ACTIVITY FOR INSERT, UPDATE, DELETE AS +SET NOCOUNT ON +BEGIN TRY +DECLARE @curr_date datetime; +SET @curr_date = getutcdate(); + IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- historical + IF EXISTS(SELECT * FROM deleted) + update HMR_SERVICE_AREA_ACTIVITY_HIST set END_DATE_HIST = @curr_date where SERVICE_AREA_ACTIVITY_ID in (select SERVICE_AREA_ACTIVITY_ID from deleted) and END_DATE_HIST is null; + + IF EXISTS(SELECT * FROM inserted) + insert into HMR_SERVICE_AREA_ACTIVITY_HIST ([SERVICE_AREA_ACTIVITY_ID], [ACTIVITY_CODE_ID], [SERVICE_AREA_NUMBER], [END_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], SERVICE_AREA_ACTIVITY_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST) + select [SERVICE_AREA_ACTIVITY_ID], [ACTIVITY_CODE_ID], [SERVICE_AREA_NUMBER], [END_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], (next value for [dbo].[HMR_SERVICE_AREA_ACTIVITY_HIST_ID_SEQ]) as [SERVICE_AREA_ACTIVITY_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create trigger dbo.HMR_SVC_AR_ACT_I_S_I_TR +PRINT N'Create trigger dbo.HMR_SVC_AR_ACT_I_S_I_TR' +GO +CREATE TRIGGER [dbo].[HMR_SVC_AR_ACT_I_S_I_TR] ON HMR_SERVICE_AREA_ACTIVITY INSTEAD OF INSERT AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM inserted) + RETURN; + + insert into HMR_SERVICE_AREA_ACTIVITY ("SERVICE_AREA_ACTIVITY_ID", + "ACTIVITY_CODE_ID", + "SERVICE_AREA_NUMBER", + "END_DATE", + "CONCURRENCY_CONTROL_NUMBER", + "APP_CREATE_USERID", + "APP_CREATE_TIMESTAMP", + "APP_CREATE_USER_GUID", + "APP_CREATE_USER_DIRECTORY", + "APP_LAST_UPDATE_USERID", + "APP_LAST_UPDATE_TIMESTAMP", + "APP_LAST_UPDATE_USER_GUID", + "APP_LAST_UPDATE_USER_DIRECTORY") + select "SERVICE_AREA_ACTIVITY_ID", + "ACTIVITY_CODE_ID", + "SERVICE_AREA_NUMBER", + "END_DATE", + "CONCURRENCY_CONTROL_NUMBER", + "APP_CREATE_USERID", + "APP_CREATE_TIMESTAMP", + "APP_CREATE_USER_GUID", + "APP_CREATE_USER_DIRECTORY", + "APP_LAST_UPDATE_USERID", + "APP_LAST_UPDATE_TIMESTAMP", + "APP_LAST_UPDATE_USER_GUID", + "APP_LAST_UPDATE_USER_DIRECTORY" + from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create trigger dbo.HMR_SVC_AR_ACT_I_S_U_TR +PRINT N'Create trigger dbo.HMR_SVC_AR_ACT_I_S_U_TR' +GO +CREATE TRIGGER [dbo].[HMR_SVC_AR_ACT_I_S_U_TR] ON HMR_SERVICE_AREA_ACTIVITY INSTEAD OF UPDATE AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- validate concurrency control + if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.SERVICE_AREA_ACTIVITY_ID = deleted.SERVICE_AREA_ACTIVITY_ID) + raiserror('CONCURRENCY FAILURE.',16,1) + + + -- update statement + update HMR_SERVICE_AREA_ACTIVITY + set "SERVICE_AREA_ACTIVITY_ID" = inserted."SERVICE_AREA_ACTIVITY_ID", + "ACTIVITY_CODE_ID" = inserted."ACTIVITY_CODE_ID", + "SERVICE_AREA_NUMBER" = inserted."SERVICE_AREA_NUMBER", + "END_DATE" = inserted."END_DATE", + "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER", + "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID", + "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP", + "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID", + "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY" + , DB_AUDIT_LAST_UPDATE_TIMESTAMP = getutcdate() + , DB_AUDIT_LAST_UPDATE_USERID = user_name() + from HMR_SERVICE_AREA_ACTIVITY + inner join inserted + on (HMR_SERVICE_AREA_ACTIVITY.SERVICE_AREA_ACTIVITY_ID = inserted.SERVICE_AREA_ACTIVITY_ID); + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +COMMIT TRANSACTION +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO +DECLARE @Success AS BIT +SET @Success = 1 +SET NOEXEC OFF +IF (@Success = 1) PRINT 'The database update succeeded' +ELSE BEGIN + IF @@TRANCOUNT > 0 ROLLBACK TRANSACTION + PRINT 'The database update failed' +END +GO From 6f0e52edb5ca55dab2fc0431d2e8f9bc6cb6ed7d Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Thu, 15 Oct 2020 09:57:58 -0700 Subject: [PATCH 18/46] Fixes: HMCR-738 HMCR-739 HMCR-741 --- .../forms/EditActivityFormFields.js | 27 ++++++++++--------- client/src/js/components/ui/FieldSet.js | 26 +++++++++++++----- client/src/scss/_forms.scss | 13 +++++++++ 3 files changed, 48 insertions(+), 18 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index d8265ec7..b0da94c0 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -16,6 +16,9 @@ import * as Constants from '../../Constants'; import { Row,Col} from 'reactstrap'; import { isInteger } from 'lodash'; +const tipAnalyticalValidation = "Analytical Validation Help"; +const tipHighwayAttributeValidation = "Highway Attribute Validation Help"; + const defaultValues = { activityNumber: '', activityName: '', @@ -47,7 +50,7 @@ const validationSchema = Yup.object({ locationCodeId: Yup.number().required('Required'), serviceAreaNumbers: Yup.array().required('At least one Service Area must be selected'), minimumValue: Yup.number() - .min(0) + .min(0,'Must be greater than or equal to 0') .typeError('Must be number') .test( 'datamin', @@ -61,7 +64,7 @@ const validationSchema = Yup.object({ if(this.parent.maximumValue > 0 && this.parent.maximumValue < this.parent.minimumValue) { return this.createError({ - message: 'Minimum value must be less than or equal to the Minimum value', + message: 'Must be less than or equal to the Maximum value', path: 'minimumValue', }); } @@ -74,7 +77,7 @@ const validationSchema = Yup.object({ if(!isInteger(this.parent.minimumValue)) { return this.createError({ - message: 'Minimum value must be whole number', + message: 'Must be whole number', path: 'minimumValue', }); } @@ -83,7 +86,7 @@ const validationSchema = Yup.object({ } ), maximumValue: Yup.number() - .min(0) + .min(0,'Must be greater than or equal to 0') .typeError('Must be number') .test( 'datamax', @@ -97,7 +100,7 @@ const validationSchema = Yup.object({ if(this.parent.maximumValue > 0 && this.parent.maximumValue < this.parent.minimumValue) { return this.createError({ - message: 'Maximum value must be greater than or equal to the Minimum value', + message: 'Must be greater than or equal to the Minimum value', path: 'maximumValue', }); } @@ -110,7 +113,7 @@ const validationSchema = Yup.object({ if(!isInteger(this.parent.maximumValue)) { return this.createError({ - message: 'Maximum value must be whole number', + message: 'Must be whole number', path: 'maximumValue', }); } @@ -119,10 +122,10 @@ const validationSchema = Yup.object({ } ), reportingFrequency: Yup.number() - .min(0) - .max(365) - .typeError('Must be number') - .integer(), + .min(0,'Must be greater than or equal to 0') + .max(365,'Must be less than or equal to 365') + .typeError('Must be whole number') + .integer('Must be whole number'), }); @@ -288,7 +291,7 @@ const EditActivityFormFields = ({ -
+
@@ -320,7 +323,7 @@ const EditActivityFormFields = ({ -
+
; + +const FieldSet = (props) => { + const { legendname,children,targetId,tips } = props; + const tipId = (targetId===undefined||targetId===null||targetId==='')?'TooltipForFieldsetId':targetId; + const [tooltipOpen, setTooltipOpen] = useState(false); + + const toggle = () => setTooltipOpen(!tooltipOpen); -const FieldSet = ({ legendname,children }) => { return (
- {legendname} + {legendname} + {helpicon} + {tips} + + {children}
- ); -}; -export default FieldSet; + ); +} +export default FieldSet; \ No newline at end of file diff --git a/client/src/scss/_forms.scss b/client/src/scss/_forms.scss index ca392378..c7c1d51a 100644 --- a/client/src/scss/_forms.scss +++ b/client/src/scss/_forms.scss @@ -55,4 +55,17 @@ } .form-control.servicearea-large.is-invalid { border-color: #d93e45; +} +.fieldset-tooltip [class$="inner"] { + background-color: #ffffca; + border: 1px solid #737373; + max-width: 160px; + color:black; + font-size: 12px; + text-align: left; +} + +.fieldset-tooltip [class$="arrow"] { + border-top: 5px solid #ffffca !important; + background-color: #737373; } \ No newline at end of file From a644d58d0ede7e5822a1b3dd7ca1634a0e5ce9f2 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Thu, 15 Oct 2020 17:06:38 -0700 Subject: [PATCH 19/46] 1.3.2 --- .../ActivityCode/ActivityCodeCreateDto.cs | 3 + .../Dtos/ActivityCode/ActivityCodeDto.cs | 4 +- .../ActivityCode/ActivityCodeSearchDto.cs | 4 +- .../ActivityCode/ActivityCodeUpdateDto.cs | 4 ++ client/src/js/components/ActivityAdmin.js | 2 +- .../forms/EditActivityFormFields.js | 67 ++++++++++--------- 6 files changed, 47 insertions(+), 37 deletions(-) diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs index 4c50decb..c5bad2ef 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs @@ -18,5 +18,8 @@ public class ActivityCodeCreateDto public decimal SurfaceTypeRule { get; set; } public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } + public decimal? MinValue { get; set; } + public decimal? MaxValue { get; set; } + public decimal? ReportingFrequency { get; set; } } } \ No newline at end of file diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs index fe103126..b758317b 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs @@ -28,8 +28,8 @@ public class ActivityCodeDto public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } - public decimal? MinimumValue { get; set; } - public decimal? MaximumValue { get; set; } + public decimal? MinValue { get; set; } + public decimal? MaxValue { get; set; } public decimal? ReportingFrequency { get; set; } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs index 0d448394..ed890b6f 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs @@ -26,8 +26,8 @@ public class ActivityCodeSearchDto public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } - public decimal? MinimumValue { get; set; } - public decimal? MaximumValue { get; set; } + public decimal? MinValue { get; set; } + public decimal? MaxValue { get; set; } public decimal? ReportingFrequency { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs index b2e8a7ec..794b78bb 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs @@ -18,5 +18,9 @@ public class ActivityCodeUpdateDto public decimal SurfaceTypeRule { get; set; } public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } + + public decimal? MinValue { get; set; } + public decimal? MaxValue { get; set; } + public decimal? ReportingFrequency { get; set; } } } diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index 73828e03..8f81b955 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -109,7 +109,7 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal values.roadLengthRule = 0; values.surfaceTypeRule = 0; } - + console.log(values); if (formType === Constants.FORM_TYPE.ADD) { api .postActivityCode(values) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index b0da94c0..ccd40ec2 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -27,8 +27,8 @@ const defaultValues = { locationCodeId: '', featureType: '', spThresholdLevel: '', - minimumValue: '', - maximumValue:'', + minValue: '', + maxValue: '', reportingFrequency: '', roadLengthRule: '', surfaceTypeRule: '', @@ -49,59 +49,61 @@ const validationSchema = Yup.object({ maintenanceType: Yup.string().required('Required').max(12), locationCodeId: Yup.number().required('Required'), serviceAreaNumbers: Yup.array().required('At least one Service Area must be selected'), - minimumValue: Yup.number() + minValue: Yup.number() .min(0,'Must be greater than or equal to 0') + .nullable() .typeError('Must be number') .test( 'datamin', function() { - if (this.parent.minimumValue === null || this.parent.minimumValue === undefined || this.parent.minimumValue === '') + if (this.parent.minValue === null || this.parent.minValue === undefined || this.parent.minValue === '') { return true; } - if(this.parent.maximumValue !== null || this.parent.maximumValue !== undefined || this.parent.maximumValue !== '') + if(this.parent.maxValue !== null || this.parent.maxValue !== undefined || this.parent.maxValue !== '') { - if(this.parent.maximumValue > 0 && this.parent.maximumValue < this.parent.minimumValue) - { - return this.createError({ - message: 'Must be less than or equal to the Maximum value', - path: 'minimumValue', - }); - } + if(this.parent.maxValue < this.parent.minValue) + { + return this.createError({ + message: 'Must be less than or equal to the Maximum value', + path: 'minValue', + }); + } } if ( this.parent.unitOfMeasure === 'site' ||this.parent.unitOfMeasure === 'num' ||this.parent.unitOfMeasure === 'ea') { - if(!isInteger(this.parent.minimumValue)) + if(!isInteger(this.parent.minValue)) { return this.createError({ message: 'Must be whole number', - path: 'minimumValue', + path: 'minValue', }); } } return true; } ), - maximumValue: Yup.number() + maxValue: Yup.number() .min(0,'Must be greater than or equal to 0') + .nullable() .typeError('Must be number') .test( 'datamax', function() { - if (this.parent.maximumValue === null || this.parent.maximumValue === undefined || this.parent.maximumValue === '') + if (this.parent.maxValue === null || this.parent.maxValue === undefined || this.parent.maxValue === '') { return true; } - if (this.parent.minimumValue !== null || this.parent.minimumValue !== undefined || this.parent.minimumValue === '') + if (this.parent.minValue !== null || this.parent.minValue !== undefined || this.parent.minValue !== '') { - if(this.parent.maximumValue > 0 && this.parent.maximumValue < this.parent.minimumValue) + if(this.parent.maxValue < this.parent.minValue) { return this.createError({ message: 'Must be greater than or equal to the Minimum value', - path: 'maximumValue', + path: 'maxValue', }); } } @@ -110,11 +112,11 @@ const validationSchema = Yup.object({ ||this.parent.unitOfMeasure === 'num' ||this.parent.unitOfMeasure === 'ea') { - if(!isInteger(this.parent.maximumValue)) + if(!isInteger(this.parent.maxValue)) { return this.createError({ message: 'Must be whole number', - path: 'maximumValue', + path: 'maxValue', }); } } @@ -124,6 +126,7 @@ const validationSchema = Yup.object({ reportingFrequency: Yup.number() .min(0,'Must be greater than or equal to 0') .max(365,'Must be less than or equal to 365') + .nullable() .typeError('Must be whole number') .integer('Must be whole number'), @@ -188,10 +191,10 @@ const EditActivityFormFields = ({ api.getActivityCode(activityId).then((response) => { setInitialValues({ ...response.data, - endDate: response.data.endDate ? moment(response.data.endDate) : null, - minimumValue: response.data.minimumValue ? moment(response.data.minimumValue):'', - maximumValue: response.data.maximumValue? moment(response.data.maximumValue):'', - reportingFrequency: response.data.reportingFrequency? moment(response.data.reportingFrequency):'', + endDate: response.data.endDate ? moment(response.data.endDate): null, + minValue: response.data.minValue ? moment(response.data.minValue): '', + maxValue: response.data.maxValue ? moment(response.data.maxValue): '', + reportingFrequency: response.data.reportingFrequency ? moment(response.data.reportingFrequency): '', }); setValidLocationCodeValues(() => { @@ -292,11 +295,11 @@ const EditActivityFormFields = ({
- - + + - - + + @@ -376,9 +379,9 @@ const mapStateToProps = (state) => { surfaceTypeRules: state.codeLookups.surfaceTypeRules, roadClassRules: state.codeLookups.roadClassRules, serviceAreas: Object.values(state.serviceAreas), - minimumValue: state.codeLookups.minimumValue, - maximumValue: state.codeLookups.maximumValue, - reportingFrequency: state.codeLookups.maximumValue, + minValue: state.codeLookups.minValue, + maxValue: state.codeLookups.maxValue, + reportingFrequency: state.codeLookups.reportingFrequency, }; }; From 6349c09037d46a7ecb02c321f911227263de331d Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Thu, 15 Oct 2020 17:12:39 -0700 Subject: [PATCH 20/46] fixed small typo --- client/src/js/components/forms/EditActivityFormFields.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index b0da94c0..78774fd6 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -61,7 +61,7 @@ const validationSchema = Yup.object({ } if(this.parent.maximumValue !== null || this.parent.maximumValue !== undefined || this.parent.maximumValue !== '') { - if(this.parent.maximumValue > 0 && this.parent.maximumValue < this.parent.minimumValue) + if(this.parent.maximumValue < this.parent.minimumValue) { return this.createError({ message: 'Must be less than or equal to the Maximum value', @@ -95,9 +95,9 @@ const validationSchema = Yup.object({ { return true; } - if (this.parent.minimumValue !== null || this.parent.minimumValue !== undefined || this.parent.minimumValue === '') + if (this.parent.minimumValue !== null || this.parent.minimumValue !== undefined || this.parent.minimumValue !== '') { - if(this.parent.maximumValue > 0 && this.parent.maximumValue < this.parent.minimumValue) + if(this.parent.maximumValue < this.parent.minimumValue) { return this.createError({ message: 'Must be greater than or equal to the Minimum value', From a04b0a7976e494368f2c6a04d71b97980f64f145 Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Fri, 16 Oct 2020 13:07:32 -0700 Subject: [PATCH 21/46] Updates to V24 to create GeoServer read only role --- ...ALTER_PDM-ddl-ROLE_APP_PROXY-V24_IS2.1.sql | 184 ++++++++++++++++++ ..._ALTER_PDM-ddl-ROLE_GIS_READ-V24_IS2.1.sql | 31 +++ ...ALTER_PDM-ddl-ROLE_READ_ONLY-V24_IS2.1.sql | 74 +++++++ 3 files changed, 289 insertions(+) create mode 100644 database/V24.0/5_HMR_ALTER_PDM-ddl-ROLE_APP_PROXY-V24_IS2.1.sql create mode 100644 database/V24.0/6_HMR_ALTER_PDM-ddl-ROLE_GIS_READ-V24_IS2.1.sql create mode 100644 database/V24.0/7_HMR_ALTER_PDM-ddl-ROLE_READ_ONLY-V24_IS2.1.sql diff --git a/database/V24.0/5_HMR_ALTER_PDM-ddl-ROLE_APP_PROXY-V24_IS2.1.sql b/database/V24.0/5_HMR_ALTER_PDM-ddl-ROLE_APP_PROXY-V24_IS2.1.sql new file mode 100644 index 00000000..20af0acd --- /dev/null +++ b/database/V24.0/5_HMR_ALTER_PDM-ddl-ROLE_APP_PROXY-V24_IS2.1.sql @@ -0,0 +1,184 @@ +-- ============================================= +-- Author: Ben Driver +-- Create date: 2020-03-02 +-- Updates: +-- +-- +-- Description: +-- - Role creation for APPLICATION_PROXY role +-- ============================================= + +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; +GO + +-- Create ROLE + +if not exists (select 1 from sys.database_principals where name='HMR_APPLICATION_PROXY' and Type = 'R') + begin + CREATE ROLE HMR_APPLICATION_PROXY AUTHORIZATION db_securityadmin; + end +GO + +GRANT select ON dbo.HMR_ACTIVITY_CODE TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_ACTIVITY_CODE_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_CODE_LOOKUP TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_CODE_LOOKUP_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_CONTRACT_TERM TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_CONTRACT_TERM_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_DISTRICT TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_FEEDBACK_MESSAGE TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_LOCATION_CODE TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_LOCATION_CODE_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_MIME_TYPE TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_PARTY TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_PARTY_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_PERMISSION TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_PERMISSION_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_REGION TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_ROCKFALL_REPORT TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_ROCKFALL_REPORT_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_ROLE TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_ROLE_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_ROLE_PERMISSION TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_ROLE_PERMISSION_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SERVICE_AREA TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SERVICE_AREA_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SERVICE_AREA_USER TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SERVICE_AREA_USER_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_STREAM_ELEMENT TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_STREAM_ELEMENT_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SUBMISSION_OBJECT TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SUBMISSION_ROW TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SUBMISSION_ROW_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SUBMISSION_STATUS TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SUBMISSION_STREAM TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SUBMISSION_STREAM_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SYSTEM_USER TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SYSTEM_USER_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_SYSTEM_VALIDATION TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_USER_ROLE TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_USER_ROLE_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_WILDLIFE_REPORT TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_WILDLIFE_REPORT_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_WORK_REPORT TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_WORK_REPORT_HIST TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_ROCKFALL_REPORT_VW TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_WILDLIFE_REPORT_VW TO HMR_APPLICATION_PROXY; +GRANT select ON dbo.HMR_WORK_REPORT_VW TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_ACTIVITY_CODE TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_ACTIVITY_CODE_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_CODE_LOOKUP TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_CODE_LOOKUP_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_CONTRACT_TERM TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_CONTRACT_TERM_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_DISTRICT TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_FEEDBACK_MESSAGE TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_LOCATION_CODE TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_LOCATION_CODE_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_MIME_TYPE TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_PARTY TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_PARTY_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_PERMISSION TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_PERMISSION_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_REGION TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_ROCKFALL_REPORT TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_ROCKFALL_REPORT_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_ROLE TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_ROLE_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_ROLE_PERMISSION TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_ROLE_PERMISSION_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SERVICE_AREA TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SERVICE_AREA_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SERVICE_AREA_USER TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SERVICE_AREA_USER_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_STREAM_ELEMENT TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_STREAM_ELEMENT_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SUBMISSION_OBJECT TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SUBMISSION_ROW TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SUBMISSION_ROW_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SUBMISSION_STATUS TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SUBMISSION_STREAM TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SUBMISSION_STREAM_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SYSTEM_USER TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SYSTEM_USER_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_SYSTEM_VALIDATION TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_USER_ROLE TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_USER_ROLE_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_WILDLIFE_REPORT TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_WILDLIFE_REPORT_HIST TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_WORK_REPORT TO HMR_APPLICATION_PROXY; +GRANT insert, update ON dbo.HMR_WORK_REPORT_HIST TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_ACTIVITY_CODE TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_CODE_LOOKUP TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_CONTRACT_TERM TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_DISTRICT TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_FEEDBACK_MESSAGE TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_LOCATION_CODE TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_MIME_TYPE TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_PARTY TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_PERMISSION TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_REGION TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_ROCKFALL_REPORT TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_ROLE TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_ROLE_PERMISSION TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_SERVICE_AREA TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_SERVICE_AREA_USER TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_STREAM_ELEMENT TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_SUBMISSION_OBJECT TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_SUBMISSION_ROW TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_SUBMISSION_STATUS TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_SUBMISSION_STREAM TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_SYSTEM_USER TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_SYSTEM_VALIDATION TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_USER_ROLE TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_WILDLIFE_REPORT TO HMR_APPLICATION_PROXY; +GRANT delete ON dbo.HMR_WORK_REPORT TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.FDBK_MSG_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_ACT_CODE_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_ACTIVITY_CODE_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_CNT_TRM_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_CODE_LKUP_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_CODE_LOOKUP_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_CONTRACT_TERM_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_DIST_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_LOC_CODE_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_LOCATION_CODE_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_MIME_TYPE_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_PARTY_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_PERM_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_PERMISSION_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_PRTY_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_RCKF_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_REG_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_RL_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_RL_PERM_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_ROCKFALL_REPORT_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_ROLE_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_ROLE_PERMISSION_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SERVICE_AREA_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SERVICE_AREA_USER_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SRV_ARA_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SRV_AREA_USR_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_STR_ELMT_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_STREAM_ELEMENT_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SUBM_OBJ_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SUBM_RW_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SUBM_STAT_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SUBM_STR_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SUBMISSION_ROW_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SUBMISSION_STREAM_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_SYSTEM_USER_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_USER_ROLE_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_USR_RL_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_WILDLIFE_REPORT_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_WLDLF_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_WORK_REPORT_H_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.HMR_WRK_RPT_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.SYS_USR_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT update ON dbo.SYS_VLD_ID_SEQ TO HMR_APPLICATION_PROXY; +GRANT execute ON dbo.hmr_error_handling TO HMR_APPLICATION_PROXY; + +GO diff --git a/database/V24.0/6_HMR_ALTER_PDM-ddl-ROLE_GIS_READ-V24_IS2.1.sql b/database/V24.0/6_HMR_ALTER_PDM-ddl-ROLE_GIS_READ-V24_IS2.1.sql new file mode 100644 index 00000000..fd325f25 --- /dev/null +++ b/database/V24.0/6_HMR_ALTER_PDM-ddl-ROLE_GIS_READ-V24_IS2.1.sql @@ -0,0 +1,31 @@ +-- ============================================= +-- Author: Ben Driver +-- Create date: 2020-03-02 +-- Updates: +-- +-- +-- Description: +-- - Role creation for GIS_READ role +-- ============================================= + +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; +GO + +-- Create ROLE + +if not exists (select 1 from sys.database_principals where name='HMR_GIS_READ' and Type = 'R') + begin + CREATE ROLE HMR_GIS_READ AUTHORIZATION db_securityadmin; + end + +-- GRANT select on views + +GRANT select ON dbo.HMR_ROCKFALL_REPORT_VW TO HMR_GIS_READ; +GRANT select ON dbo.HMR_WILDLIFE_REPORT_VW TO HMR_GIS_READ; +GRANT select ON dbo.HMR_WORK_REPORT_VW TO HMR_GIS_READ; + +GO + diff --git a/database/V24.0/7_HMR_ALTER_PDM-ddl-ROLE_READ_ONLY-V24_IS2.1.sql b/database/V24.0/7_HMR_ALTER_PDM-ddl-ROLE_READ_ONLY-V24_IS2.1.sql new file mode 100644 index 00000000..360688d1 --- /dev/null +++ b/database/V24.0/7_HMR_ALTER_PDM-ddl-ROLE_READ_ONLY-V24_IS2.1.sql @@ -0,0 +1,74 @@ +-- ============================================= +-- Author: Ben Driver +-- Create date: 2020-03-02 +-- Updates: +-- +-- +-- Description: +-- - Role creation for READ_ONLY role +-- ============================================= + +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; +GO + +-- Create ROLE + +if not exists (select 1 from sys.database_principals where name='HMR_READ_ONLY' and Type = 'R') + begin + CREATE ROLE HMR_READ_ONLY AUTHORIZATION db_securityadmin; + end + +-- GRANT select on tables + +GRANT select ON dbo.HMR_ACTIVITY_CODE TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_ACTIVITY_CODE_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_CODE_LOOKUP TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_CODE_LOOKUP_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_CONTRACT_TERM TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_CONTRACT_TERM_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_DISTRICT TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_FEEDBACK_MESSAGE TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_LOCATION_CODE TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_LOCATION_CODE_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_MIME_TYPE TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_PARTY TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_PARTY_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_PERMISSION TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_PERMISSION_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_REGION TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_ROCKFALL_REPORT TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_ROCKFALL_REPORT_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_ROLE TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_ROLE_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_ROLE_PERMISSION TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_ROLE_PERMISSION_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SERVICE_AREA TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SERVICE_AREA_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SERVICE_AREA_USER TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SERVICE_AREA_USER_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_STREAM_ELEMENT TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_STREAM_ELEMENT_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SUBMISSION_OBJECT TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SUBMISSION_ROW TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SUBMISSION_ROW_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SUBMISSION_STATUS TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SUBMISSION_STREAM TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SUBMISSION_STREAM_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SYSTEM_USER TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SYSTEM_USER_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_SYSTEM_VALIDATION TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_USER_ROLE TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_USER_ROLE_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_WILDLIFE_REPORT TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_WILDLIFE_REPORT_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_WORK_REPORT TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_WORK_REPORT_HIST TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_ROCKFALL_REPORT_VW TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_WILDLIFE_REPORT_VW TO HMR_READ_ONLY; +GRANT select ON dbo.HMR_WORK_REPORT_VW TO HMR_READ_ONLY; + +GO + From 0706beb1c022b8f181f53a21b17241cb9b3072aa Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Fri, 16 Oct 2020 13:28:16 -0700 Subject: [PATCH 22/46] HMCR-670 --- .../ActivityCode/ActivityCodeCreateDto.cs | 2 +- .../Dtos/ActivityCode/ActivityCodeDto.cs | 2 +- .../ActivityCode/ActivityCodeSearchDto.cs | 2 +- .../ActivityCode/ActivityCodeUpdateDto.cs | 2 +- client/src/js/components/ActivityAdmin.js | 14 ++++++++- .../forms/EditActivityFormFields.js | 30 ++++++++++++++----- 6 files changed, 39 insertions(+), 13 deletions(-) diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs index c5bad2ef..a1f7663f 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs @@ -20,6 +20,6 @@ public class ActivityCodeCreateDto public virtual IList ServiceAreaNumbers { get; set; } public decimal? MinValue { get; set; } public decimal? MaxValue { get; set; } - public decimal? ReportingFrequency { get; set; } + public int? ReportingFrequency { get; set; } } } \ No newline at end of file diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs index b758317b..285ce481 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs @@ -30,7 +30,7 @@ public class ActivityCodeDto public decimal? MinValue { get; set; } public decimal? MaxValue { get; set; } - public decimal? ReportingFrequency { get; set; } + public int? ReportingFrequency { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs index ed890b6f..90c1bd8c 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs @@ -28,6 +28,6 @@ public class ActivityCodeSearchDto public decimal? MinValue { get; set; } public decimal? MaxValue { get; set; } - public decimal? ReportingFrequency { get; set; } + public int? ReportingFrequency { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs index 794b78bb..a4384351 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs @@ -21,6 +21,6 @@ public class ActivityCodeUpdateDto public decimal? MinValue { get; set; } public decimal? MaxValue { get; set; } - public decimal? ReportingFrequency { get; set; } + public int? ReportingFrequency { get; set; } } } diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index 8f81b955..8782d090 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -109,11 +109,20 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal values.roadLengthRule = 0; values.surfaceTypeRule = 0; } - console.log(values); + values.minValue = (values.minValue) ? Number(values.minValue): null; + values.maxValue = (values.maxValue)? Number(values.maxValue): null; + values.reportingFrequency = (values.reportingFrequency)? Number(values.reportingFrequency): null; + if(values.minValue && values.maxValue === 0) + { + values.maxValue = 999999999.99; + } if (formType === Constants.FORM_TYPE.ADD) { api .postActivityCode(values) .then(() => { + values.minValue = (values.minValue) ? Number(values.minValue): ''; + values.maxValue = (values.maxValue)? Number(values.maxValue): ''; + values.reportingFrequency = (values.reportingFrequency)? Number(values.reportingFrequency): ''; formModal.closeForm(); searchData.refresh(); }) @@ -123,6 +132,9 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal api .putActivityCode(values.id, values) .then(() => { + values.minValue = (values.minValue) ? Number(values.minValue): ''; + values.maxValue = (values.maxValue)? Number(values.maxValue): ''; + values.reportingFrequency = (values.reportingFrequency)? Number(values.reportingFrequency): ''; formModal.closeForm(); searchData.refresh(); }) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index ccd40ec2..82d5a64a 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -56,13 +56,20 @@ const validationSchema = Yup.object({ .test( 'datamin', function() { - if (this.parent.minValue === null || this.parent.minValue === undefined || this.parent.minValue === '') + if (!this.parent.minValue) { return true; } - if(this.parent.maxValue !== null || this.parent.maxValue !== undefined || this.parent.maxValue !== '') + if(this.parent.minValue > 999999999.99) { - if(this.parent.maxValue < this.parent.minValue) + return this.createError({ + message: 'Must be less than or equal to 999999999.99', + path: 'minValue', + }); + } + if(this.parent.maxValue) + { + if(this.parent.maxValue !== 0 && this.parent.maxValue < this.parent.minValue) { return this.createError({ message: 'Must be less than or equal to the Maximum value', @@ -93,13 +100,20 @@ const validationSchema = Yup.object({ .test( 'datamax', function() { - if (this.parent.maxValue === null || this.parent.maxValue === undefined || this.parent.maxValue === '') + if (!this.parent.maxValue) { return true; } - if (this.parent.minValue !== null || this.parent.minValue !== undefined || this.parent.minValue !== '') + if(this.parent.maxValue > 999999999.99) { - if(this.parent.maxValue < this.parent.minValue) + return this.createError({ + message: 'Must be less than or equal to 999999999.99', + path: 'maxValue', + }); + } + if (this.parent.minValue) + { + if(this.parent.maxValue !== 0 && this.parent.maxValue < this.parent.minValue) { return this.createError({ message: 'Must be greater than or equal to the Minimum value', @@ -125,7 +139,7 @@ const validationSchema = Yup.object({ ), reportingFrequency: Yup.number() .min(0,'Must be greater than or equal to 0') - .max(365,'Must be less than or equal to 365') + .max(366,'Must be less than or equal to 366') .nullable() .typeError('Must be whole number') .integer('Must be whole number'), @@ -196,7 +210,7 @@ const EditActivityFormFields = ({ maxValue: response.data.maxValue ? moment(response.data.maxValue): '', reportingFrequency: response.data.reportingFrequency ? moment(response.data.reportingFrequency): '', }); - + setValidLocationCodeValues(() => { if (formType === Constants.FORM_TYPE.EDIT) { if (response.data.locationCodeId === locationCodes.find((code) => code.name === 'B').id) From ea12732e8872c2f8d087ae4c6e7e391d969fe385 Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Fri, 16 Oct 2020 13:40:23 -0700 Subject: [PATCH 23/46] Updates to Data Entity --- .../Database/Entities/AppDbContext.cs | 26 +- .../Database/Entities/HmrActivityCodeHist.cs | 3 + .../Database/Entities/HmrCodeLookupHist.cs | 1 + .../1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql | 377 +++++++++++++++++- ...DM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql | 20 + 5 files changed, 419 insertions(+), 8 deletions(-) create mode 100644 database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql diff --git a/api/Hmcr.Data/Database/Entities/AppDbContext.cs b/api/Hmcr.Data/Database/Entities/AppDbContext.cs index 448528da..1fa4d3bc 100644 --- a/api/Hmcr.Data/Database/Entities/AppDbContext.cs +++ b/api/Hmcr.Data/Database/Entities/AppDbContext.cs @@ -64,7 +64,7 @@ public AppDbContext(DbContextOptions options) public virtual DbSet HmrWorkReports { get; set; } public virtual DbSet HmrWorkReportHists { get; set; } public virtual DbSet HmrWorkReportVws { get; set; } - + protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder.Entity(entity => @@ -399,6 +399,16 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasMaxLength(12) .IsUnicode(false); + entity.Property(e => e.MaxValue) + .HasColumnName("MAX_VALUE") + .HasColumnType("numeric(11, 2)"); + + entity.Property(e => e.MinValue) + .HasColumnName("MIN_VALUE") + .HasColumnType("numeric(11, 2)"); + + entity.Property(e => e.ReportingFrequency).HasColumnName("REPORTING_FREQUENCY"); + entity.Property(e => e.RoadClassRule) .HasColumnName("ROAD_CLASS_RULE") .HasColumnType("numeric(9, 0)"); @@ -426,7 +436,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { entity.HasKey(e => e.ActivityCodeRuleId) - .HasName("PK__HMR_ACTI__E4140F7D39105D95"); + .HasName("PK__HMR_ACTI__E4140F7D40BB464E"); entity.ToTable("HMR_ACTIVITY_CODE_RULE"); @@ -669,6 +679,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) entity.Property(e => e.EndDateHist) .HasColumnName("END_DATE_HIST") .HasColumnType("datetime"); + + entity.Property(e => e.IsIntegerOnly).HasColumnName("IS_INTEGER_ONLY"); }); modelBuilder.Entity(entity => @@ -3138,7 +3150,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) modelBuilder.Entity(entity => { entity.HasKey(e => e.ServiceAreaActivityId) - .HasName("PK__HMR_SERV__56CBEAED34A3F264"); + .HasName("PK__HMR_SERV__56CBEAEDB516F420"); entity.ToTable("HMR_SERVICE_AREA_ACTIVITY"); @@ -3149,7 +3161,7 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .HasName("IDX_HMR_SVC_AR_ACT_SVC_AREA"); entity.HasIndex(e => new { e.ServiceAreaNumber, e.ActivityCodeId }) - .HasName("UQ__HMR_SERV__307B5DE25CCB5D28") + .HasName("UQ__HMR_SERV__307B5DE2F252A57E") .IsUnique(); entity.Property(e => e.ServiceAreaActivityId) @@ -3237,19 +3249,19 @@ protected override void OnModelCreating(ModelBuilder modelBuilder) .WithMany(p => p.HmrServiceAreaActivities) .HasForeignKey(d => d.ActivityCodeId) .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("FK__HMR_SERVI__ACTIV__65AC084E"); + .HasConstraintName("FK__HMR_SERVI__ACTIV__3AC1AA49"); entity.HasOne(d => d.ServiceAreaNumberNavigation) .WithMany(p => p.HmrServiceAreaActivities) .HasForeignKey(d => d.ServiceAreaNumber) .OnDelete(DeleteBehavior.ClientSetNull) - .HasConstraintName("FK__HMR_SERVI__SERVI__64B7E415"); + .HasConstraintName("FK__HMR_SERVI__SERVI__39CD8610"); }); modelBuilder.Entity(entity => { entity.HasKey(e => e.ServiceAreaActivityHistId) - .HasName("PK__HMR_SERV__08C5944CC6D91E3A"); + .HasName("PK__HMR_SERV__08C5944CE2D33CB5"); entity.ToTable("HMR_SERVICE_AREA_ACTIVITY_HIST"); diff --git a/api/Hmcr.Data/Database/Entities/HmrActivityCodeHist.cs b/api/Hmcr.Data/Database/Entities/HmrActivityCodeHist.cs index 41337626..3e13fc63 100644 --- a/api/Hmcr.Data/Database/Entities/HmrActivityCodeHist.cs +++ b/api/Hmcr.Data/Database/Entities/HmrActivityCodeHist.cs @@ -35,5 +35,8 @@ public partial class HmrActivityCodeHist public decimal RoadClassRule { get; set; } public decimal RoadLengthRule { get; set; } public decimal SurfaceTypeRule { get; set; } + public decimal? MinValue { get; set; } + public decimal? MaxValue { get; set; } + public int? ReportingFrequency { get; set; } } } diff --git a/api/Hmcr.Data/Database/Entities/HmrCodeLookupHist.cs b/api/Hmcr.Data/Database/Entities/HmrCodeLookupHist.cs index a7aa4dfa..97bc8c61 100644 --- a/api/Hmcr.Data/Database/Entities/HmrCodeLookupHist.cs +++ b/api/Hmcr.Data/Database/Entities/HmrCodeLookupHist.cs @@ -21,5 +21,6 @@ public partial class HmrCodeLookupHist public DateTime DbAuditCreateTimestamp { get; set; } public string DbAuditLastUpdateUserid { get; set; } public DateTime DbAuditLastUpdateTimestamp { get; set; } + public bool IsIntegerOnly { get; set; } } } diff --git a/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql b/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql index 26a51ce1..c74d39bf 100644 --- a/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql +++ b/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql @@ -1,4 +1,4 @@ --- Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Tue Oct 13 13:43:48 PDT 2020 +-- Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Fri Oct 16 09:53:14 PDT 2020 -- Execute this script on: -- HMR V24.0/dbo - This database/schema will be modified -- to synchronize it with MS SQL Server 2016: @@ -15,6 +15,54 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Drop trigger dbo.HMR_CODE_LKUP_A_S_IUD_TR +PRINT N'Drop trigger dbo.HMR_CODE_LKUP_A_S_IUD_TR' +GO +DROP TRIGGER [dbo].[HMR_CODE_LKUP_A_S_IUD_TR] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Drop trigger dbo.HMR_ACT_CODE_A_S_IUD_TR +PRINT N'Drop trigger dbo.HMR_ACT_CODE_A_S_IUD_TR' +GO +DROP TRIGGER [dbo].[HMR_ACT_CODE_A_S_IUD_TR] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Drop trigger dbo.HMR_ACT_CODE_I_S_I_TR +PRINT N'Drop trigger dbo.HMR_ACT_CODE_I_S_I_TR' +GO +DROP TRIGGER [dbo].[HMR_ACT_CODE_I_S_I_TR] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Drop trigger dbo.HMR_ACT_CODE_I_S_U_TR +PRINT N'Drop trigger dbo.HMR_ACT_CODE_I_S_U_TR' +GO +DROP TRIGGER [dbo].[HMR_ACT_CODE_I_S_U_TR] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Drop trigger dbo.HMR_CODE_LKUP_I_S_I_TR +PRINT N'Drop trigger dbo.HMR_CODE_LKUP_I_S_I_TR' +GO +DROP TRIGGER [dbo].[HMR_CODE_LKUP_I_S_I_TR] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Drop trigger dbo.HMR_CODE_LKUP_I_S_U_TR +PRINT N'Drop trigger dbo.HMR_CODE_LKUP_I_S_U_TR' +GO +DROP TRIGGER [dbo].[HMR_CODE_LKUP_I_S_U_TR] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Drop sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ PRINT N'Drop sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ' GO @@ -23,6 +71,14 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Drop table dbo.HMRX_TableDefinitions +PRINT N'Drop table dbo.HMRX_TableDefinitions' +GO +DROP TABLE [dbo].[HMRX_TableDefinitions] +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Drop sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ PRINT N'Drop sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ' GO @@ -177,6 +233,53 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Alter table dbo.HMR_ACTIVITY_CODE_HIST +PRINT N'Alter table dbo.HMR_ACTIVITY_CODE_HIST' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_HIST] + ADD [MIN_VALUE] numeric(11,2) NULL, + [MAX_VALUE] numeric(11,2) NULL, + [REPORTING_FREQUENCY] int NULL +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create check constraint dbo.CC_HMR_ACTIVITY_CODE_HIST_MAX_VALUE +PRINT N'Create check constraint dbo.CC_HMR_ACTIVITY_CODE_HIST_MAX_VALUE' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_HIST] + ADD CHECK ([MAX_VALUE]>=(0) AND [MAX_VALUE]<=(999999999.99)) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create check constraint dbo.CC_HMR_ACTIVITY_CODE_HIST_MIN_VALUE +PRINT N'Create check constraint dbo.CC_HMR_ACTIVITY_CODE_HIST_MIN_VALUE' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_HIST] + ADD CHECK ([MIN_VALUE]>=(0) AND [MIN_VALUE]<=(999999999.99)) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create check constraint dbo.CC_HMR_ACTIVITY_CODE_HIST_REPORTING_FREQUENCY +PRINT N'Create check constraint dbo.CC_HMR_ACTIVITY_CODE_HIST_REPORTING_FREQUENCY' +GO +ALTER TABLE [dbo].[HMR_ACTIVITY_CODE_HIST] + ADD CHECK ([REPORTING_FREQUENCY]>=(0) AND [REPORTING_FREQUENCY]<=(366)) +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Alter table dbo.HMR_CODE_LOOKUP_HIST +PRINT N'Alter table dbo.HMR_CODE_LOOKUP_HIST' +GO +ALTER TABLE [dbo].[HMR_CODE_LOOKUP_HIST] + ADD [IS_INTEGER_ONLY] bit NOT NULL DEFAULT 0 +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Create index dbo.IDX_HMR_SVC_AR_ACT_ACT_CD PRINT N'Create index dbo.IDX_HMR_SVC_AR_ACT_ACT_CD' GO @@ -247,6 +350,141 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Create trigger dbo.HMR_CODE_LKUP_I_S_U_TR +PRINT N'Create trigger dbo.HMR_CODE_LKUP_I_S_U_TR' +GO +CREATE TRIGGER [dbo].[HMR_CODE_LKUP_I_S_U_TR] ON HMR_CODE_LOOKUP INSTEAD OF UPDATE AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- validate concurrency control + if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.CODE_LOOKUP_ID = deleted.CODE_LOOKUP_ID) + raiserror('CONCURRENCY FAILURE.',16,1) + + + -- update statement + update HMR_CODE_LOOKUP + set "CODE_LOOKUP_ID" = inserted."CODE_LOOKUP_ID", + "CODE_SET" = inserted."CODE_SET", + "CODE_NAME" = inserted."CODE_NAME", + "CODE_VALUE_TEXT" = inserted."CODE_VALUE_TEXT", + "CODE_VALUE_NUM" = inserted."CODE_VALUE_NUM", + "CODE_VALUE_FORMAT" = inserted."CODE_VALUE_FORMAT", + "DISPLAY_ORDER" = inserted."DISPLAY_ORDER", + "END_DATE" = inserted."END_DATE", + "IS_INTEGER_ONLY" = inserted."IS_INTEGER_ONLY", + "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER" + , DB_AUDIT_LAST_UPDATE_TIMESTAMP = getutcdate() + , DB_AUDIT_LAST_UPDATE_USERID = user_name() + from HMR_CODE_LOOKUP + inner join inserted + on (HMR_CODE_LOOKUP.CODE_LOOKUP_ID = inserted.CODE_LOOKUP_ID); + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create trigger dbo.HMR_CODE_LKUP_I_S_I_TR +PRINT N'Create trigger dbo.HMR_CODE_LKUP_I_S_I_TR' +GO +CREATE TRIGGER [dbo].[HMR_CODE_LKUP_I_S_I_TR] ON HMR_CODE_LOOKUP INSTEAD OF INSERT AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM inserted) + RETURN; + + + insert into HMR_CODE_LOOKUP ("CODE_LOOKUP_ID", + "CODE_SET", + "CODE_NAME", + "CODE_VALUE_TEXT", + "CODE_VALUE_NUM", + "CODE_VALUE_FORMAT", + "DISPLAY_ORDER", + "END_DATE", + "IS_INTEGER_ONLY", + "CONCURRENCY_CONTROL_NUMBER") + select "CODE_LOOKUP_ID", + "CODE_SET", + "CODE_NAME", + "CODE_VALUE_TEXT", + "CODE_VALUE_NUM", + "CODE_VALUE_FORMAT", + "DISPLAY_ORDER", + "END_DATE", + "IS_INTEGER_ONLY", + "CONCURRENCY_CONTROL_NUMBER" + from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create trigger dbo.HMR_ACT_CODE_I_S_U_TR +PRINT N'Create trigger dbo.HMR_ACT_CODE_I_S_U_TR' +GO +CREATE TRIGGER [dbo].[HMR_ACT_CODE_I_S_U_TR] ON HMR_ACTIVITY_CODE INSTEAD OF UPDATE AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- validate concurrency control + if exists (select 1 from inserted, deleted where inserted.CONCURRENCY_CONTROL_NUMBER != deleted.CONCURRENCY_CONTROL_NUMBER+1 AND inserted.ACTIVITY_CODE_ID = deleted.ACTIVITY_CODE_ID) + raiserror('CONCURRENCY FAILURE.',16,1) + + + -- update statement + update HMR_ACTIVITY_CODE + set "ACTIVITY_CODE_ID" = inserted."ACTIVITY_CODE_ID", + "ACTIVITY_NUMBER" = inserted."ACTIVITY_NUMBER", + "ACTIVITY_NAME" = inserted."ACTIVITY_NAME", + "UNIT_OF_MEASURE" = inserted."UNIT_OF_MEASURE", + "MAINTENANCE_TYPE" = inserted."MAINTENANCE_TYPE", + "LOCATION_CODE_ID" = inserted."LOCATION_CODE_ID", + "FEATURE_TYPE" = inserted."FEATURE_TYPE", + "SP_THRESHOLD_LEVEL" = inserted."SP_THRESHOLD_LEVEL", + "IS_SITE_NUM_REQUIRED" = inserted."IS_SITE_NUM_REQUIRED", + "ACTIVITY_APPLICATION" = inserted."ACTIVITY_APPLICATION", + "END_DATE" = inserted."END_DATE", + "ROAD_CLASS_RULE" = inserted."ROAD_CLASS_RULE", + "ROAD_LENGTH_RULE" = inserted."ROAD_LENGTH_RULE", + "SURFACE_TYPE_RULE" = inserted."SURFACE_TYPE_RULE", + "MIN_VALUE" = inserted."MIN_VALUE", + "MAX_VALUE" = inserted."MAX_VALUE", + "REPORTING_FREQUENCY" = inserted."REPORTING_FREQUENCY", + "CONCURRENCY_CONTROL_NUMBER" = inserted."CONCURRENCY_CONTROL_NUMBER", + "APP_LAST_UPDATE_USERID" = inserted."APP_LAST_UPDATE_USERID", + "APP_LAST_UPDATE_TIMESTAMP" = inserted."APP_LAST_UPDATE_TIMESTAMP", + "APP_LAST_UPDATE_USER_GUID" = inserted."APP_LAST_UPDATE_USER_GUID", + "APP_LAST_UPDATE_USER_DIRECTORY" = inserted."APP_LAST_UPDATE_USER_DIRECTORY" + , DB_AUDIT_LAST_UPDATE_TIMESTAMP = getutcdate() + , DB_AUDIT_LAST_UPDATE_USERID = user_name() + from HMR_ACTIVITY_CODE + inner join inserted + on (HMR_ACTIVITY_CODE.ACTIVITY_CODE_ID = inserted.ACTIVITY_CODE_ID); + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Create trigger dbo.HMR_SVC_AR_ACT_I_S_I_TR PRINT N'Create trigger dbo.HMR_SVC_AR_ACT_I_S_I_TR' GO @@ -293,6 +531,143 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO +-- Create trigger dbo.HMR_ACT_CODE_I_S_I_TR +PRINT N'Create trigger dbo.HMR_ACT_CODE_I_S_I_TR' +GO +CREATE TRIGGER [dbo].[HMR_ACT_CODE_I_S_I_TR] ON HMR_ACTIVITY_CODE INSTEAD OF INSERT AS +SET NOCOUNT ON +BEGIN TRY + IF NOT EXISTS(SELECT * FROM inserted) + RETURN; + + + insert into HMR_ACTIVITY_CODE ("ACTIVITY_CODE_ID", + "ACTIVITY_NUMBER", + "ACTIVITY_NAME", + "UNIT_OF_MEASURE", + "MAINTENANCE_TYPE", + "LOCATION_CODE_ID", + "FEATURE_TYPE", + "SP_THRESHOLD_LEVEL", + "IS_SITE_NUM_REQUIRED", + "ACTIVITY_APPLICATION", + "END_DATE", + "ROAD_CLASS_RULE", + "ROAD_LENGTH_RULE", + "SURFACE_TYPE_RULE", + "MIN_VALUE", + "MAX_VALUE", + "REPORTING_FREQUENCY", + "CONCURRENCY_CONTROL_NUMBER", + "APP_CREATE_USERID", + "APP_CREATE_TIMESTAMP", + "APP_CREATE_USER_GUID", + "APP_CREATE_USER_DIRECTORY", + "APP_LAST_UPDATE_USERID", + "APP_LAST_UPDATE_TIMESTAMP", + "APP_LAST_UPDATE_USER_GUID", + "APP_LAST_UPDATE_USER_DIRECTORY") + select "ACTIVITY_CODE_ID", + "ACTIVITY_NUMBER", + "ACTIVITY_NAME", + "UNIT_OF_MEASURE", + "MAINTENANCE_TYPE", + "LOCATION_CODE_ID", + "FEATURE_TYPE", + "SP_THRESHOLD_LEVEL", + "IS_SITE_NUM_REQUIRED", + "ACTIVITY_APPLICATION", + "END_DATE", + "ROAD_CLASS_RULE", + "ROAD_LENGTH_RULE", + "SURFACE_TYPE_RULE", + "MIN_VALUE", + "MAX_VALUE", + "REPORTING_FREQUENCY", + "CONCURRENCY_CONTROL_NUMBER", + "APP_CREATE_USERID", + "APP_CREATE_TIMESTAMP", + "APP_CREATE_USER_GUID", + "APP_CREATE_USER_DIRECTORY", + "APP_LAST_UPDATE_USERID", + "APP_LAST_UPDATE_TIMESTAMP", + "APP_LAST_UPDATE_USER_GUID", + "APP_LAST_UPDATE_USER_DIRECTORY" + from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create trigger dbo.HMR_ACT_CODE_A_S_IUD_TR +PRINT N'Create trigger dbo.HMR_ACT_CODE_A_S_IUD_TR' +GO +/* ---------------------------------------------------------------------- */ +/* Add triggers */ +/* ---------------------------------------------------------------------- */ + +/* ---------------------------------------------------------------------- */ +/* Add triggers */ +/* ---------------------------------------------------------------------- */ + +CREATE TRIGGER [dbo].[HMR_ACT_CODE_A_S_IUD_TR] ON HMR_ACTIVITY_CODE FOR INSERT, UPDATE, DELETE AS +SET NOCOUNT ON +BEGIN TRY +DECLARE @curr_date datetime; +SET @curr_date = getutcdate(); + IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- historical + IF EXISTS(SELECT * FROM deleted) + update HMR_ACTIVITY_CODE_HIST set END_DATE_HIST = @curr_date where ACTIVITY_CODE_ID in (select ACTIVITY_CODE_ID from deleted) and END_DATE_HIST is null; + + IF EXISTS(SELECT * FROM inserted) + insert into HMR_ACTIVITY_CODE_HIST ([ACTIVITY_CODE_ID], [ACTIVITY_NUMBER], [ACTIVITY_NAME], [UNIT_OF_MEASURE], [MAINTENANCE_TYPE], [LOCATION_CODE_ID], [FEATURE_TYPE], [SP_THRESHOLD_LEVEL], [IS_SITE_NUM_REQUIRED], [ACTIVITY_APPLICATION], [END_DATE], [ROAD_CLASS_RULE], [ROAD_LENGTH_RULE], [SURFACE_TYPE_RULE], [MIN_VALUE], [MAX_VALUE], [REPORTING_FREQUENCY], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], ACTIVITY_CODE_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST) + select [ACTIVITY_CODE_ID], [ACTIVITY_NUMBER], [ACTIVITY_NAME], [UNIT_OF_MEASURE], [MAINTENANCE_TYPE], [LOCATION_CODE_ID], [FEATURE_TYPE], [SP_THRESHOLD_LEVEL], [IS_SITE_NUM_REQUIRED], [ACTIVITY_APPLICATION], [END_DATE], [ROAD_CLASS_RULE], [ROAD_LENGTH_RULE], [SURFACE_TYPE_RULE], [MIN_VALUE], [MAX_VALUE], [REPORTING_FREQUENCY], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], (next value for [dbo].[HMR_ACTIVITY_CODE_H_ID_SEQ]) as [ACTIVITY_CODE_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + +-- Create trigger dbo.HMR_CODE_LKUP_A_S_IUD_TR +PRINT N'Create trigger dbo.HMR_CODE_LKUP_A_S_IUD_TR' +GO +CREATE TRIGGER [dbo].[HMR_CODE_LKUP_A_S_IUD_TR] ON HMR_CODE_LOOKUP FOR INSERT, UPDATE, DELETE AS +SET NOCOUNT ON +BEGIN TRY +DECLARE @curr_date datetime; +SET @curr_date = getutcdate(); + IF NOT EXISTS(SELECT * FROM inserted) AND NOT EXISTS(SELECT * FROM deleted) + RETURN; + + -- historical + IF EXISTS(SELECT * FROM deleted) + update HMR_CODE_LOOKUP_HIST set END_DATE_HIST = @curr_date where CODE_LOOKUP_ID in (select CODE_LOOKUP_ID from deleted) and END_DATE_HIST is null; + + IF EXISTS(SELECT * FROM inserted) + insert into HMR_CODE_LOOKUP_HIST ([CODE_LOOKUP_ID], [CODE_SET], [CODE_NAME], [CODE_VALUE_TEXT], [CODE_VALUE_NUM], [CODE_VALUE_FORMAT], [DISPLAY_ORDER], [END_DATE], [IS_INTEGER_ONLY], [CONCURRENCY_CONTROL_NUMBER], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], CODE_LOOKUP_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST) + select [CODE_LOOKUP_ID], [CODE_SET], [CODE_NAME], [CODE_VALUE_TEXT], [CODE_VALUE_NUM], [CODE_VALUE_FORMAT], [DISPLAY_ORDER], [END_DATE], [IS_INTEGER_ONLY], [CONCURRENCY_CONTROL_NUMBER], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], (next value for [dbo].[HMR_CODE_LOOKUP_H_ID_SEQ]) as [CODE_LOOKUP_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted; + +END TRY +BEGIN CATCH + IF @@trancount > 0 ROLLBACK TRANSACTION + EXEC hmr_error_handling +END CATCH; +GO +IF @@ERROR <> 0 SET NOEXEC ON +GO + -- Create trigger dbo.HMR_SVC_AR_ACT_I_S_U_TR PRINT N'Create trigger dbo.HMR_SVC_AR_ACT_I_S_U_TR' GO diff --git a/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql b/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql new file mode 100644 index 00000000..f4f79b29 --- /dev/null +++ b/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql @@ -0,0 +1,20 @@ +-- ***************************************************************************** +-- Populate the HMR_SERVICE_AREA_ACTIVITY table by assigning all service areas +-- to all activity codes by default. +-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +-- Author Date Comment +-- ------------ ----------- -------------------------------------------------- +-- Doug Filteau 2020-Oct-14 Initial version. +-- ***************************************************************************** + +USE HMR_DEV; +GO + +INSERT INTO [dbo].[HMR_SERVICE_AREA_ACTIVITY] + (ACTIVITY_CODE_ID, SERVICE_AREA_NUMBER) + SELECT ACT.ACTIVITY_CODE_ID + , SVC.SERVICE_AREA_NUMBER + FROM [dbo].[HMR_ACTIVITY_CODE] ACT + , (SELECT SERVICE_AREA_NUMBER + FROM [dbo].[HMR_SERVICE_AREA]) SVC; +GO From 1d3cdc6dcbacfcd75ac03447a7a022a41e6f262e Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Fri, 16 Oct 2020 18:10:55 -0700 Subject: [PATCH 24/46] process null object --- client/src/js/components/ActivityAdmin.js | 18 +++++++++--------- .../components/forms/EditActivityFormFields.js | 14 +++++++------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index 8782d090..8857bdb3 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -109,9 +109,9 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal values.roadLengthRule = 0; values.surfaceTypeRule = 0; } - values.minValue = (values.minValue) ? Number(values.minValue): null; - values.maxValue = (values.maxValue)? Number(values.maxValue): null; - values.reportingFrequency = (values.reportingFrequency)? Number(values.reportingFrequency): null; + values.minValue = (values.minValue !== null || values.minValue !== undefined || values.minValue !== '') ? Number(values.minValue): null; + values.maxValue = (values.maxValue !== null || values.maxValue !== undefined || values.maxValue !== '') ? Number(values.maxValue): null; + values.reportingFrequency = (values.reportingFrequency !== null || values.reportingFrequency !== undefined || values.reportingFrequency !== '')? Number(values.reportingFrequency): null; if(values.minValue && values.maxValue === 0) { values.maxValue = 999999999.99; @@ -120,9 +120,9 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal api .postActivityCode(values) .then(() => { - values.minValue = (values.minValue) ? Number(values.minValue): ''; - values.maxValue = (values.maxValue)? Number(values.maxValue): ''; - values.reportingFrequency = (values.reportingFrequency)? Number(values.reportingFrequency): ''; + values.minValue = (values.minValue !== null || values.minValue !== undefined || values.minValue !== '') ? Number(values.minValue): ''; + values.maxValue = (values.maxValue !== null || values.maxValue !== undefined || values.maxValue !== '')? Number(values.maxValue): ''; + values.reportingFrequency = (values.reportingFrequency !== null || values.reportingFrequency !== undefined || values.reportingFrequency !== '')? Number(values.reportingFrequency): ''; formModal.closeForm(); searchData.refresh(); }) @@ -132,9 +132,9 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal api .putActivityCode(values.id, values) .then(() => { - values.minValue = (values.minValue) ? Number(values.minValue): ''; - values.maxValue = (values.maxValue)? Number(values.maxValue): ''; - values.reportingFrequency = (values.reportingFrequency)? Number(values.reportingFrequency): ''; + values.minValue = (values.minValue !== null || values.minValue !== undefined || values.minValue !== '') ? Number(values.minValue): ''; + values.maxValue = (values.maxValue !== null || values.maxValue !== undefined || values.maxValue !== '')? Number(values.maxValue): ''; + values.reportingFrequency = (values.reportingFrequency !== null || values.reportingFrequency !== undefined || values.reportingFrequency !== '')? Number(values.reportingFrequency): ''; formModal.closeForm(); searchData.refresh(); }) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 82d5a64a..7d0ed849 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -56,7 +56,7 @@ const validationSchema = Yup.object({ .test( 'datamin', function() { - if (!this.parent.minValue) + if (this.parent.minValue === null || this.parent.minValue === undefined || this.parent.minValue === '') { return true; } @@ -67,9 +67,9 @@ const validationSchema = Yup.object({ path: 'minValue', }); } - if(this.parent.maxValue) + if(this.parent.maxValue !== null || this.parent.maxValue !== undefined || this.parent.maxValue !== '') { - if(this.parent.maxValue !== 0 && this.parent.maxValue < this.parent.minValue) + if(Number(this.parent.maxValue) !== 0 && this.parent.maxValue < this.parent.minValue) { return this.createError({ message: 'Must be less than or equal to the Maximum value', @@ -100,20 +100,20 @@ const validationSchema = Yup.object({ .test( 'datamax', function() { - if (!this.parent.maxValue) + if (this.parent.maxValue === null || this.parent.maxValue === undefined || this.parent.maxValue === '') { return true; } - if(this.parent.maxValue > 999999999.99) + if(Number(this.parent.maxValue) > 999999999.99) { return this.createError({ message: 'Must be less than or equal to 999999999.99', path: 'maxValue', }); } - if (this.parent.minValue) + if (this.parent.minValue !== null || this.parent.minValue !== undefined || this.parent.minValue !== '') { - if(this.parent.maxValue !== 0 && this.parent.maxValue < this.parent.minValue) + if(Number(this.parent.maxValue) !== 0 && this.parent.maxValue < this.parent.minValue) { return this.createError({ message: 'Must be greater than or equal to the Minimum value', From fa8d35c966635b3c99a76a5c365940aa1305f4fe Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Fri, 16 Oct 2020 21:35:41 -0700 Subject: [PATCH 25/46] min/max front --- client/src/js/components/ActivityAdmin.js | 23 ++++---- .../forms/EditActivityFormFields.js | 58 +++++++++++++++++-- 2 files changed, 64 insertions(+), 17 deletions(-) diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index 8857bdb3..dd2bd97a 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -109,20 +109,17 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal values.roadLengthRule = 0; values.surfaceTypeRule = 0; } - values.minValue = (values.minValue !== null || values.minValue !== undefined || values.minValue !== '') ? Number(values.minValue): null; - values.maxValue = (values.maxValue !== null || values.maxValue !== undefined || values.maxValue !== '') ? Number(values.maxValue): null; - values.reportingFrequency = (values.reportingFrequency !== null || values.reportingFrequency !== undefined || values.reportingFrequency !== '')? Number(values.reportingFrequency): null; - if(values.minValue && values.maxValue === 0) - { - values.maxValue = 999999999.99; - } + values.minValue = (values.minValue !== null && values.minValue !== undefined && values.minValue !== '') ? Number(values.minValue): null; + values.maxValue = (values.maxValue !== null && values.maxValue !== undefined && values.maxValue !== '') ? Number(values.maxValue): null; + values.reportingFrequency = (values.reportingFrequency !== null && values.reportingFrequency !== undefined && values.reportingFrequency !== '')? Number(values.reportingFrequency): null; + if (formType === Constants.FORM_TYPE.ADD) { api .postActivityCode(values) .then(() => { - values.minValue = (values.minValue !== null || values.minValue !== undefined || values.minValue !== '') ? Number(values.minValue): ''; - values.maxValue = (values.maxValue !== null || values.maxValue !== undefined || values.maxValue !== '')? Number(values.maxValue): ''; - values.reportingFrequency = (values.reportingFrequency !== null || values.reportingFrequency !== undefined || values.reportingFrequency !== '')? Number(values.reportingFrequency): ''; + values.minValue = (values.minValue !== null && values.minValue !== undefined && values.minValue !== '') ? Number(values.minValue): ''; + values.maxValue = (values.maxValue !== null && values.maxValue !== undefined && values.maxValue !== '')? Number(values.maxValue): ''; + values.reportingFrequency = (values.reportingFrequency !== null && values.reportingFrequency !== undefined && values.reportingFrequency !== '')? Number(values.reportingFrequency): ''; formModal.closeForm(); searchData.refresh(); }) @@ -132,9 +129,9 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal api .putActivityCode(values.id, values) .then(() => { - values.minValue = (values.minValue !== null || values.minValue !== undefined || values.minValue !== '') ? Number(values.minValue): ''; - values.maxValue = (values.maxValue !== null || values.maxValue !== undefined || values.maxValue !== '')? Number(values.maxValue): ''; - values.reportingFrequency = (values.reportingFrequency !== null || values.reportingFrequency !== undefined || values.reportingFrequency !== '')? Number(values.reportingFrequency): ''; + values.minValue = (values.minValue !== null && values.minValue !== undefined && values.minValue !== '') ? Number(values.minValue): ''; + values.maxValue = (values.maxValue !== null && values.maxValue !== undefined && values.maxValue !== '')? Number(values.maxValue): ''; + values.reportingFrequency = (values.reportingFrequency !== null && values.reportingFrequency !== undefined && values.reportingFrequency !== '')? Number(values.reportingFrequency): ''; formModal.closeForm(); searchData.refresh(); }) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 7d0ed849..92a56ec4 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -1,4 +1,5 @@ import React, { useEffect, useState } from 'react'; +import { useFormikContext} from 'formik'; import { connect } from 'react-redux'; import * as Yup from 'yup'; import moment from 'moment'; @@ -67,7 +68,7 @@ const validationSchema = Yup.object({ path: 'minValue', }); } - if(this.parent.maxValue !== null || this.parent.maxValue !== undefined || this.parent.maxValue !== '') + if(this.parent.maxValue !== null && this.parent.maxValue !== undefined && this.parent.maxValue !== '') { if(Number(this.parent.maxValue) !== 0 && this.parent.maxValue < this.parent.minValue) { @@ -111,7 +112,7 @@ const validationSchema = Yup.object({ path: 'maxValue', }); } - if (this.parent.minValue !== null || this.parent.minValue !== undefined || this.parent.minValue !== '') + if (this.parent.minValue !== null && this.parent.minValue !== undefined && this.parent.minValue !== '') { if(Number(this.parent.maxValue) !== 0 && this.parent.maxValue < this.parent.minValue) { @@ -163,6 +164,7 @@ const EditActivityFormFields = ({ serviceAreas, }) => { const [loading, setLoading] = useState(true); + const { setFieldValue} = useFormikContext(); const [validLocationCodeValues, setValidLocationCodeValues] = useState(locationCodes); const [disableLocationCodeEdit, setDisableLocationCodeEdit] = useState(false); const [validFeatureTypeValues, setValidFeatureTypeValues] = useState(featureTypes); @@ -192,6 +194,8 @@ const EditActivityFormFields = ({ then: Yup.boolean().required('Required'), }), }); + + setValidationSchema(defaultValidationSchema); setLoading(true); @@ -252,6 +256,52 @@ const EditActivityFormFields = ({ if (loading || formValues === null) return ; + const handleOnBlurMinValue = (e) => { + const minval = e.target.value; + if(formValues) + { + let maxval = formValues.maxValue; + if (minval !== null + && minval !== undefined + && minval !== '' + && Number(minval) >=0 + && maxval !== null + && maxval !== undefined + && maxval !== '' + && Number(maxval)===0) + { + setFieldValue('maxValue', 999999999); + } + } + setFieldValue('minValue', minval); + }; + + const handleOnBlurMaxValue = (e) => { + const maxval = e.target.value; + if(formValues) + { + let minval = formValues.minValue; + if (minval !== null + && minval !== undefined + && minval !== '' + && Number(minval) >=0 + & maxval !== null + && maxval !== undefined + && maxval !== '' + && Number(maxval)===0) + { + setFieldValue('maxValue', 999999999); + } + else + { + setFieldValue('maxValue', maxval); + } + } + else{ + setFieldValue('maxValue', maxval); + } + }; + return ( @@ -310,10 +360,10 @@ const EditActivityFormFields = ({
- + - + From 5aff4b20fe40223cf3a18992339ca5499f7ad786 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Fri, 16 Oct 2020 22:31:58 -0700 Subject: [PATCH 26/46] updated tooltips with html tags --- .../components/forms/EditActivityFormFields.js | 9 +++++++-- client/src/js/components/ui/FieldSet.js | 17 ++++------------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 92a56ec4..e88f3553 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -17,8 +17,13 @@ import * as Constants from '../../Constants'; import { Row,Col} from 'reactstrap'; import { isInteger } from 'lodash'; -const tipAnalyticalValidation = "Analytical Validation Help"; -const tipHighwayAttributeValidation = "Highway Attribute Validation Help"; +const tipAnalyticalValidation = [
    +
  • For Maintenance Work Reporting this refers to the End Date
  • +
  • For Rockfall this refers to the Report Date
  • +
]; +const tipHighwayAttributeValidation = [
    +
  • Highway Attribute Validation Help
  • +
]; const defaultValues = { activityNumber: '', diff --git a/client/src/js/components/ui/FieldSet.js b/client/src/js/components/ui/FieldSet.js index 9f504c11..c62efd67 100644 --- a/client/src/js/components/ui/FieldSet.js +++ b/client/src/js/components/ui/FieldSet.js @@ -1,26 +1,17 @@ -import React, { useState } from 'react'; -import {FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import {Tooltip } from 'reactstrap'; - -const helpicon = ; +import React from 'react'; +import MouseoverTooltip from './MouseoverTooltip'; const FieldSet = (props) => { const { legendname,children,targetId,tips } = props; const tipId = (targetId===undefined||targetId===null||targetId==='')?'TooltipForFieldsetId':targetId; - const [tooltipOpen, setTooltipOpen] = useState(false); - - const toggle = () => setTooltipOpen(!tooltipOpen); - return (
{legendname} - {helpicon} - {tips} - + + {tips} {children}
- ); } export default FieldSet; \ No newline at end of file From 7b828a85762f69dcf04aac16d12e1bcefa21ae6f Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Mon, 19 Oct 2020 13:17:17 -0700 Subject: [PATCH 27/46] Fixed when value is 0. --- .../Dtos/ActivityCode/ActivityCodeDto.cs | 6 +- .../ActivityCode/ActivityCodeSearchDto.cs | 6 +- .../forms/EditActivityFormFields.js | 141 +++++++++++++----- client/src/js/components/ui/FieldSet.js | 17 +-- 4 files changed, 117 insertions(+), 53 deletions(-) diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs index fe103126..285ce481 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs @@ -28,9 +28,9 @@ public class ActivityCodeDto public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } - public decimal? MinimumValue { get; set; } - public decimal? MaximumValue { get; set; } - public decimal? ReportingFrequency { get; set; } + public decimal? MinValue { get; set; } + public decimal? MaxValue { get; set; } + public int? ReportingFrequency { get; set; } } } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs index 0d448394..90c1bd8c 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs @@ -26,8 +26,8 @@ public class ActivityCodeSearchDto public decimal RoadClassRule { get; set; } public virtual IList ServiceAreaNumbers { get; set; } - public decimal? MinimumValue { get; set; } - public decimal? MaximumValue { get; set; } - public decimal? ReportingFrequency { get; set; } + public decimal? MinValue { get; set; } + public decimal? MaxValue { get; set; } + public int? ReportingFrequency { get; set; } } } diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 78774fd6..7cc261cc 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -1,4 +1,5 @@ import React, { useEffect, useState } from 'react'; +import { useFormikContext} from 'formik'; import { connect } from 'react-redux'; import * as Yup from 'yup'; import moment from 'moment'; @@ -16,8 +17,13 @@ import * as Constants from '../../Constants'; import { Row,Col} from 'reactstrap'; import { isInteger } from 'lodash'; -const tipAnalyticalValidation = "Analytical Validation Help"; -const tipHighwayAttributeValidation = "Highway Attribute Validation Help"; +const tipAnalyticalValidation = [
    +
  • Analytical Validation Help 1
  • +
  • Analytical Validation Help 2
  • +
]; +const tipHighwayAttributeValidation = [
    +
  • Highway Attribute Validation Help
  • +
]; const defaultValues = { activityNumber: '', @@ -27,8 +33,8 @@ const defaultValues = { locationCodeId: '', featureType: '', spThresholdLevel: '', - minimumValue: '', - maximumValue:'', + minValue: '', + maxValue: '', reportingFrequency: '', roadLengthRule: '', surfaceTypeRule: '', @@ -49,59 +55,75 @@ const validationSchema = Yup.object({ maintenanceType: Yup.string().required('Required').max(12), locationCodeId: Yup.number().required('Required'), serviceAreaNumbers: Yup.array().required('At least one Service Area must be selected'), - minimumValue: Yup.number() + minValue: Yup.number() .min(0,'Must be greater than or equal to 0') + .nullable() .typeError('Must be number') .test( 'datamin', function() { - if (this.parent.minimumValue === null || this.parent.minimumValue === undefined || this.parent.minimumValue === '') + if (this.parent.minValue === null || this.parent.minValue === undefined || this.parent.minValue === '') { return true; } - if(this.parent.maximumValue !== null || this.parent.maximumValue !== undefined || this.parent.maximumValue !== '') - { - if(this.parent.maximumValue < this.parent.minimumValue) + if(this.parent.minValue > 999999999.99) { return this.createError({ - message: 'Must be less than or equal to the Maximum value', - path: 'minimumValue', + message: 'Must be less than or equal to 999999999.99', + path: 'minValue', }); } + if(this.parent.maxValue !== null && this.parent.maxValue !== undefined && this.parent.maxValue !== '') + { + if(Number(this.parent.maxValue) !== 0 && this.parent.maxValue < this.parent.minValue) + { + return this.createError({ + message: 'Must be less than or equal to the Maximum value', + path: 'minValue', + }); + } } if ( this.parent.unitOfMeasure === 'site' ||this.parent.unitOfMeasure === 'num' ||this.parent.unitOfMeasure === 'ea') { - if(!isInteger(this.parent.minimumValue)) + if(!isInteger(this.parent.minValue)) { return this.createError({ message: 'Must be whole number', - path: 'minimumValue', + path: 'minValue', }); } } return true; } ), - maximumValue: Yup.number() + maxValue: Yup.number() .min(0,'Must be greater than or equal to 0') + .nullable() .typeError('Must be number') .test( 'datamax', function() { - if (this.parent.maximumValue === null || this.parent.maximumValue === undefined || this.parent.maximumValue === '') + if (this.parent.maxValue === null || this.parent.maxValue === undefined || this.parent.maxValue === '') { return true; } - if (this.parent.minimumValue !== null || this.parent.minimumValue !== undefined || this.parent.minimumValue !== '') + if(Number(this.parent.maxValue) > 999999999.99) { - if(this.parent.maximumValue < this.parent.minimumValue) + return this.createError({ + message: 'Must be less than or equal to 999999999.99', + path: 'maxValue', + }); + } + if (this.parent.minValue !== null && this.parent.minValue !== undefined && this.parent.minValue !== '') + { + if(Number(this.parent.maxValue) !== 0 && this.parent.maxValue < this.parent.minValue) { return this.createError({ message: 'Must be greater than or equal to the Minimum value', - path: 'maximumValue', + path: 'maxValue', }); } } @@ -110,11 +132,11 @@ const validationSchema = Yup.object({ ||this.parent.unitOfMeasure === 'num' ||this.parent.unitOfMeasure === 'ea') { - if(!isInteger(this.parent.maximumValue)) + if(!isInteger(this.parent.maxValue)) { return this.createError({ message: 'Must be whole number', - path: 'maximumValue', + path: 'maxValue', }); } } @@ -123,7 +145,8 @@ const validationSchema = Yup.object({ ), reportingFrequency: Yup.number() .min(0,'Must be greater than or equal to 0') - .max(365,'Must be less than or equal to 365') + .max(366,'Must be less than or equal to 366') + .nullable() .typeError('Must be whole number') .integer('Must be whole number'), @@ -146,6 +169,7 @@ const EditActivityFormFields = ({ serviceAreas, }) => { const [loading, setLoading] = useState(true); + const {setFieldValue} = useFormikContext(); const [validLocationCodeValues, setValidLocationCodeValues] = useState(locationCodes); const [disableLocationCodeEdit, setDisableLocationCodeEdit] = useState(false); const [validFeatureTypeValues, setValidFeatureTypeValues] = useState(featureTypes); @@ -153,7 +177,6 @@ const EditActivityFormFields = ({ const roadLengthRuleDefaultId = roadLengthRules.find((rlr) => rlr.name === 'Not Applicable').id; const surfaceTypeRuleDefaultId = surfaceTypeRules.find((str) => str.name === 'Not Applicable').id; const roadClassRuleDefaultId =roadClassRules.find((rcr) => rcr.name === 'Not Applicable').id; - useEffect(() => { // Add validation for point line feature when location code is C. // Need to get the id value of location code C @@ -175,6 +198,8 @@ const EditActivityFormFields = ({ then: Yup.boolean().required('Required'), }), }); + + setValidationSchema(defaultValidationSchema); setLoading(true); @@ -188,12 +213,12 @@ const EditActivityFormFields = ({ api.getActivityCode(activityId).then((response) => { setInitialValues({ ...response.data, - endDate: response.data.endDate ? moment(response.data.endDate) : null, - minimumValue: response.data.minimumValue ? moment(response.data.minimumValue):'', - maximumValue: response.data.maximumValue? moment(response.data.maximumValue):'', - reportingFrequency: response.data.reportingFrequency? moment(response.data.reportingFrequency):'', + endDate: response.data.endDate ? moment(response.data.endDate): null, + minValue: response.data.minValue ? moment(response.data.minValue): '', + maxValue: response.data.maxValue ? moment(response.data.maxValue): '', + reportingFrequency: response.data.reportingFrequency ? moment(response.data.reportingFrequency): '', }); - + setValidLocationCodeValues(() => { if (formType === Constants.FORM_TYPE.EDIT) { if (response.data.locationCodeId === locationCodes.find((code) => code.name === 'B').id) @@ -235,6 +260,53 @@ const EditActivityFormFields = ({ if (loading || formValues === null) return ; + const convertMaxValue = (minval,maxval)=>{ + if (minval !== null + && minval !== undefined + && minval !== '' + && Number(minval) >=0 + && maxval !== null + && maxval !== undefined + && maxval !== '' + && Number(maxval)===0) + { + if ( + formValues.unitOfMeasure === 'site' + || formValues.unitOfMeasure === 'num' + || formValues.unitOfMeasure === 'ea') + { + return 999999999; + } + else + { + return 999999999.99; + } + } + return maxval; + }; + + const handleMinValue = (e) => { + const minval = e.target.value; + if(formValues) + { + let maxval = formValues.maxValue; + setFieldValue('maxValue',convertMaxValue(minval,maxval)); + } + setFieldValue('minValue', minval); + }; + + const handleMaxValue = (e) => { + const maxval = e.target.value; + if(formValues) + { + let minval = formValues.minValue; + setFieldValue('maxValue',convertMaxValue(minval,maxval)); + } + else{ + setFieldValue('maxValue', maxval); + } + }; + return ( @@ -292,11 +364,12 @@ const EditActivityFormFields = ({
- - + + - - + + @@ -376,9 +449,9 @@ const mapStateToProps = (state) => { surfaceTypeRules: state.codeLookups.surfaceTypeRules, roadClassRules: state.codeLookups.roadClassRules, serviceAreas: Object.values(state.serviceAreas), - minimumValue: state.codeLookups.minimumValue, - maximumValue: state.codeLookups.maximumValue, - reportingFrequency: state.codeLookups.maximumValue, + minValue: state.codeLookups.minValue, + maxValue: state.codeLookups.maxValue, + reportingFrequency: state.codeLookups.reportingFrequency, }; }; diff --git a/client/src/js/components/ui/FieldSet.js b/client/src/js/components/ui/FieldSet.js index 9f504c11..c62efd67 100644 --- a/client/src/js/components/ui/FieldSet.js +++ b/client/src/js/components/ui/FieldSet.js @@ -1,26 +1,17 @@ -import React, { useState } from 'react'; -import {FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import {Tooltip } from 'reactstrap'; - -const helpicon = ; +import React from 'react'; +import MouseoverTooltip from './MouseoverTooltip'; const FieldSet = (props) => { const { legendname,children,targetId,tips } = props; const tipId = (targetId===undefined||targetId===null||targetId==='')?'TooltipForFieldsetId':targetId; - const [tooltipOpen, setTooltipOpen] = useState(false); - - const toggle = () => setTooltipOpen(!tooltipOpen); - return (
{legendname} - {helpicon} - {tips} - + + {tips} {children}
- ); } export default FieldSet; \ No newline at end of file From 47cc8d2682d5259bf5fe5f11489b2ebcadb3d4d9 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Mon, 19 Oct 2020 13:22:33 -0700 Subject: [PATCH 28/46] fixed handler for 0 --- .../forms/EditActivityFormFields.js | 73 ++++++++++--------- 1 file changed, 37 insertions(+), 36 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index e88f3553..7cc261cc 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -18,8 +18,8 @@ import { Row,Col} from 'reactstrap'; import { isInteger } from 'lodash'; const tipAnalyticalValidation = [
    -
  • For Maintenance Work Reporting this refers to the End Date
  • -
  • For Rockfall this refers to the Report Date
  • +
  • Analytical Validation Help 1
  • +
  • Analytical Validation Help 2
]; const tipHighwayAttributeValidation = [
  • Highway Attribute Validation Help
  • @@ -169,7 +169,7 @@ const EditActivityFormFields = ({ serviceAreas, }) => { const [loading, setLoading] = useState(true); - const { setFieldValue} = useFormikContext(); + const {setFieldValue} = useFormikContext(); const [validLocationCodeValues, setValidLocationCodeValues] = useState(locationCodes); const [disableLocationCodeEdit, setDisableLocationCodeEdit] = useState(false); const [validFeatureTypeValues, setValidFeatureTypeValues] = useState(featureTypes); @@ -177,7 +177,6 @@ const EditActivityFormFields = ({ const roadLengthRuleDefaultId = roadLengthRules.find((rlr) => rlr.name === 'Not Applicable').id; const surfaceTypeRuleDefaultId = surfaceTypeRules.find((str) => str.name === 'Not Applicable').id; const roadClassRuleDefaultId =roadClassRules.find((rcr) => rcr.name === 'Not Applicable').id; - useEffect(() => { // Add validation for point line feature when location code is C. // Need to get the id value of location code C @@ -261,50 +260,51 @@ const EditActivityFormFields = ({ if (loading || formValues === null) return ; - const handleOnBlurMinValue = (e) => { + const convertMaxValue = (minval,maxval)=>{ + if (minval !== null + && minval !== undefined + && minval !== '' + && Number(minval) >=0 + && maxval !== null + && maxval !== undefined + && maxval !== '' + && Number(maxval)===0) + { + if ( + formValues.unitOfMeasure === 'site' + || formValues.unitOfMeasure === 'num' + || formValues.unitOfMeasure === 'ea') + { + return 999999999; + } + else + { + return 999999999.99; + } + } + return maxval; + }; + + const handleMinValue = (e) => { const minval = e.target.value; if(formValues) { let maxval = formValues.maxValue; - if (minval !== null - && minval !== undefined - && minval !== '' - && Number(minval) >=0 - && maxval !== null - && maxval !== undefined - && maxval !== '' - && Number(maxval)===0) - { - setFieldValue('maxValue', 999999999); - } + setFieldValue('maxValue',convertMaxValue(minval,maxval)); } setFieldValue('minValue', minval); }; - const handleOnBlurMaxValue = (e) => { - const maxval = e.target.value; + const handleMaxValue = (e) => { + const maxval = e.target.value; if(formValues) { let minval = formValues.minValue; - if (minval !== null - && minval !== undefined - && minval !== '' - && Number(minval) >=0 - & maxval !== null - && maxval !== undefined - && maxval !== '' - && Number(maxval)===0) - { - setFieldValue('maxValue', 999999999); - } - else - { - setFieldValue('maxValue', maxval); - } + setFieldValue('maxValue',convertMaxValue(minval,maxval)); } else{ setFieldValue('maxValue', maxval); - } + } }; return ( @@ -365,10 +365,11 @@ const EditActivityFormFields = ({
    - + - + From 0c62b3640ded5f950a3b77f7a28884595e524ad6 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Mon, 19 Oct 2020 15:52:15 -0700 Subject: [PATCH 29/46] wrapped functions --- client/src/js/components/ActivityAdmin.js | 31 ++++++------- .../forms/EditActivityFormFields.js | 46 ++++--------------- client/src/js/utils.js | 17 +++++++ 3 files changed, 41 insertions(+), 53 deletions(-) diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index f00be4f7..e32ae2c2 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -20,15 +20,11 @@ import { showValidationErrorDialog } from '../actions'; import * as Constants from '../Constants'; import * as api from '../Api'; -import { buildStatusIdArray } from '../utils'; +import { buildStatusIdArray,isValueNotEmpty,toNumberOrNull,toStringOrEmpty } from '../utils'; +import { toNumber } from 'lodash'; const defaultSearchFormValues = { searchText: '', maintenanceTypeIds: [], statusId: [Constants.ACTIVE_STATUS.ACTIVE] }; -const isValueNotEmpty=(v)=>{ - if(v !== null && v !== undefined && v !== '') return true; - return false; -} - const defaultSearchOptions = { searchText: '', maintenanceTypes: '', @@ -114,17 +110,20 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal values.roadLengthRule = 0; values.surfaceTypeRule = 0; } - values.minValue = isValueNotEmpty(values.minValue) ? Number(values.minValue): null; - values.maxValue = isValueNotEmpty(values.maxValue) ? Number(values.maxValue): null; - values.reportingFrequency = isValueNotEmpty(values.reportingFrequency)? Number(values.reportingFrequency): null; - + values.minValue = toNumberOrNull(values.minValue); + values.maxValue = toNumberOrNull(values.maxValue); + values.reportingFrequency = toNumberOrNull(values.reportingFrequency ); + if(isValueNotEmpty(values.minValue) && toNumber(values.maxValue) === 0) + { + values.maxValue = (['site','num','ea'].includes(values.unitOfMeasure)) ? 999999999.99:999999999; + } if (formType === Constants.FORM_TYPE.ADD) { api .postActivityCode(values) .then(() => { - values.minValue = isValueNotEmpty(values.minValue) ? Number(values.minValue): ''; - values.maxValue = isValueNotEmpty(values.maxValue)? Number(values.maxValue): ''; - values.reportingFrequency = isValueNotEmpty(values.reportingFrequency)? Number(values.reportingFrequency): ''; + values.minValue = toStringOrEmpty(values.minValue); + values.maxValue = toStringOrEmpty(values.maxValue); + values.reportingFrequency = toStringOrEmpty(values.reportingFrequency ); formModal.closeForm(); searchData.refresh(); }) @@ -134,9 +133,9 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal api .putActivityCode(values.id, values) .then(() => { - values.minValue = isValueNotEmpty(values.minValue) ? Number(values.minValue): ''; - values.maxValue = isValueNotEmpty(values.maxValue)? Number(values.maxValue): ''; - values.reportingFrequency = isValueNotEmpty(values.reportingFrequency)? Number(values.reportingFrequency): ''; + values.minValue = toStringOrEmpty(values.minValue); + values.maxValue = toStringOrEmpty(values.maxValue); + values.reportingFrequency = toStringOrEmpty(values.reportingFrequency ); formModal.closeForm(); searchData.refresh(); }) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index a04bbe6a..3478a2df 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -16,6 +16,7 @@ import * as api from '../../Api'; import * as Constants from '../../Constants'; import { Row,Col} from 'reactstrap'; import { isInteger, toString } from 'lodash'; +import {isValueEmpty,isValueNotEmpty,toStringOrEmpty} from '../../utils' const tipAnalyticalValidation = [
    • Analytical Validation Help 1
    • @@ -25,14 +26,6 @@ const tipHighwayAttributeValidation = [
        { - if(v !== null && v !== undefined && v !== '') return true; - return false; -} const defaultValues = { activityNumber: '', activityName: '', @@ -91,10 +84,7 @@ const validationSchema = Yup.object({ }); } } - if ( - this.parent.unitOfMeasure === 'site' - ||this.parent.unitOfMeasure === 'num' - ||this.parent.unitOfMeasure === 'ea') + if (['site','num','ea'].includes(this.parent.unitOfMeasure)) { if(!isInteger(this.parent.minValue)) { @@ -135,10 +125,7 @@ const validationSchema = Yup.object({ }); } } - if ( - this.parent.unitOfMeasure === 'site' - ||this.parent.unitOfMeasure === 'num' - ||this.parent.unitOfMeasure === 'ea') + if (['site','num','ea'].includes(this.parent.unitOfMeasure)) { if(!isInteger(this.parent.maxValue)) { @@ -157,8 +144,6 @@ const validationSchema = Yup.object({ .nullable() .typeError('Must be whole number') .integer('Must be whole number'), - - }); const EditActivityFormFields = ({ setInitialValues, @@ -222,9 +207,9 @@ const EditActivityFormFields = ({ setInitialValues({ ...response.data, endDate: response.data.endDate ? moment(response.data.endDate): null, - minValue: response.data.minValue ? toString(moment(response.data.minValue)): '', - maxValue: response.data.maxValue ? toString(moment(response.data.maxValue)): '', - reportingFrequency: response.data.reportingFrequency ? toString(moment(response.data.reportingFrequency)): '', + minValue: toStringOrEmpty(response.data.minValue), + maxValue: toStringOrEmpty(response.data.maxValue), + reportingFrequency: toStringOrEmpty(response.data.reportingFrequency), }); setValidLocationCodeValues(() => { @@ -271,24 +256,11 @@ const EditActivityFormFields = ({ const convertMaxValue = (minv,maxv)=>{ const minval = minv; const maxval = maxv; - if (isValueNotEmpty(minval) - && Number(minval) >=0 - && isValueNotEmpty(maxval) - && Number(maxval)===0) + if (isValueNotEmpty(minval) && Number(minval) >=0 && isValueNotEmpty(maxval) && Number(maxval) === 0) { - if ( - formValues.unitOfMeasure === 'site' - || formValues.unitOfMeasure === 'num' - || formValues.unitOfMeasure === 'ea') - { - return '999999999'; - } - else - { - return '999999999.99'; - } + return (['site','num','ea'].includes(formValues.unitOfMeasure)) ? '999999999': '999999999.99'; } - if(maxval === null || maxval === undefined || maxval === '') return ''; + if(isValueEmpty(maxval)) return ''; return toString(maxval); }; diff --git a/client/src/js/utils.js b/client/src/js/utils.js index 8e19c4dd..6cd0f9db 100644 --- a/client/src/js/utils.js +++ b/client/src/js/utils.js @@ -60,3 +60,20 @@ export const buildStatusIdArray = (isActive) => { return [Constants.ACTIVE_STATUS.ACTIVE, Constants.ACTIVE_STATUS.INACTIVE]; }; + +export const isValueEmpty=(v)=>{ + if(v === null || v === undefined || v === '') return true; + return false; +}; + +export const isValueNotEmpty=(v)=>{ + if(v !== null && v !== undefined && v !== '') return true; + return false; +}; + +export const toNumberOrNull=(v)=>{ + return isValueNotEmpty(v) ? _.toNumber(v): null; +}; +export const toStringOrEmpty=(v)=>{ + return isValueNotEmpty(v) ? _.toString(v): ''; +}; \ No newline at end of file From 80ee5c50e0f8e4c10c2d70d817c285fa6eb0fa9a Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Mon, 19 Oct 2020 19:53:03 -0700 Subject: [PATCH 30/46] ServiceAreaActivity - get/create --- .../Mappings/EntityToModelProfile.cs | 4 +- .../Mappings/ModelToEntityProfile.cs | 3 ++ .../Repositories/ActivityCodeRepository.cs | 38 ++++++++----------- .../ActivityCode/ActivityCodeCreateDto.cs | 2 +- .../Dtos/ActivityCode/ActivityCodeDto.cs | 2 +- .../ActivityCode/ActivityCodeSearchDto.cs | 2 +- .../ActivityCode/ActivityCodeUpdateDto.cs | 2 +- .../ServiceAreaActivityDto.cs | 18 +++++++++ 8 files changed, 44 insertions(+), 27 deletions(-) create mode 100644 api/Hmcr.Model/Dtos/ServiceAreaActivity/ServiceAreaActivityDto.cs diff --git a/api/Hmcr.Data/Mappings/EntityToModelProfile.cs b/api/Hmcr.Data/Mappings/EntityToModelProfile.cs index 63d37cfc..5ecba541 100644 --- a/api/Hmcr.Data/Mappings/EntityToModelProfile.cs +++ b/api/Hmcr.Data/Mappings/EntityToModelProfile.cs @@ -17,6 +17,7 @@ using Hmcr.Model.Dtos.RolePermission; using Hmcr.Model.Dtos.ServiceArea; using Hmcr.Model.Dtos.ServiceAreaUser; +using Hmcr.Model.Dtos.ServiceAreaActivity; using Hmcr.Model.Dtos.SubmissionObject; using Hmcr.Model.Dtos.SubmissionRow; using Hmcr.Model.Dtos.SubmissionStatus; @@ -113,7 +114,8 @@ public EntityToModelProfile() CreateMap(); CreateMap(); - + + CreateMap(); } } } diff --git a/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs b/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs index 2732b8a4..7115eed4 100644 --- a/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs +++ b/api/Hmcr.Data/Mappings/ModelToEntityProfile.cs @@ -14,6 +14,7 @@ using Hmcr.Model.Dtos.RolePermission; using Hmcr.Model.Dtos.ServiceArea; using Hmcr.Model.Dtos.ServiceAreaUser; +using Hmcr.Model.Dtos.ServiceAreaActivity; using Hmcr.Model.Dtos.SubmissionObject; using Hmcr.Model.Dtos.SubmissionRow; using Hmcr.Model.Dtos.SubmissionStatus; @@ -99,6 +100,8 @@ public ModelToEntityProfile() CreateMap(); CreateMap(); + + CreateMap (); } } } diff --git a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs index 179d7a24..de2a31b2 100644 --- a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs @@ -3,6 +3,7 @@ using Hmcr.Data.Repositories.Base; using Hmcr.Model.Dtos; using Hmcr.Model.Dtos.ActivityCode; +using Hmcr.Model.Dtos.ServiceArea; using Hmcr.Model.Utils; using Microsoft.EntityFrameworkCore; using System; @@ -64,19 +65,25 @@ public async Task CreateActivityCodeAsync(ActivityCodeCreateDto var activityCodeEntity = new HmrActivityCode(); Mapper.Map(activityCode, activityCodeEntity); - - //TODO: add in saving of Service Areas + //TODO: add in saving of Service Areas + foreach (var areaNumber in activityCode.ServiceAreaNumbers) + { + activityCodeEntity.HmrServiceAreaActivities + .Add(new HmrServiceAreaActivity + { + ServiceAreaNumber = areaNumber + }); + } await DbSet.AddAsync(activityCodeEntity); - + return activityCodeEntity; } public async Task GetActivityCodeAsync(decimal id) { var activityCodeEntity = await DbSet.AsNoTracking() - //todo ServiceArea - //.Include(x => x.HmrServiceAreaRules) //new table + .Include(x => x.HmrServiceAreaActivities) .FirstOrDefaultAsync(ac => ac.ActivityCodeId == id); if (activityCodeEntity == null) @@ -86,24 +93,11 @@ public async Task GetActivityCodeAsync(decimal id) activityCode.IsReferenced = await _workReportRepo.IsActivityNumberInUseAsync(activityCode.ActivityNumber); - /*var activityRules = activityCodeEntity - .HmrActivityCodeRules - .Select(s => s.ActivityCodeRuleId) + var serviceAreasNumbers = + activityCodeEntity + .HmrServiceAreaActivities //new table + .Select(s => s.ServiceAreaNumber) .ToList(); - - var activityRules = new List { 1, 3 }; - activityCode.ActivityRuleIds = activityRules; - activityCode.RoadLengthRule = 2; - activityCode.SurfaceTypeRule = 3; - activityCode.RoadClassRule = 1;*/ - - //TODO: pull the service areas - //var serviceAreasNumbers = - // activityCodeEntity - // .HmrServiceAreaRules //new table - // .Select(s => s.ServiceAreaNumber) - // .ToList(); - var serviceAreasNumbers = new List { 1, 9 }; activityCode.ServiceAreaNumbers = serviceAreasNumbers; return activityCode; diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs index a1f7663f..4698832f 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeCreateDto.cs @@ -17,7 +17,7 @@ public class ActivityCodeCreateDto public decimal RoadLengthRule { get; set; } public decimal SurfaceTypeRule { get; set; } public decimal RoadClassRule { get; set; } - public virtual IList ServiceAreaNumbers { get; set; } + public IList ServiceAreaNumbers { get; set; } public decimal? MinValue { get; set; } public decimal? MaxValue { get; set; } public int? ReportingFrequency { get; set; } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs index 285ce481..98073301 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeDto.cs @@ -26,7 +26,7 @@ public class ActivityCodeDto public decimal RoadLengthRule { get; set; } public decimal SurfaceTypeRule { get; set; } public decimal RoadClassRule { get; set; } - public virtual IList ServiceAreaNumbers { get; set; } + public IList ServiceAreaNumbers { get; set; } public decimal? MinValue { get; set; } public decimal? MaxValue { get; set; } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs index 90c1bd8c..acf339be 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeSearchDto.cs @@ -24,7 +24,7 @@ public class ActivityCodeSearchDto public decimal RoadLengthRule { get; set; } public decimal SurfaceTypeRule { get; set; } public decimal RoadClassRule { get; set; } - public virtual IList ServiceAreaNumbers { get; set; } + public IList ServiceAreaNumbers { get; set; } public decimal? MinValue { get; set; } public decimal? MaxValue { get; set; } diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs index a4384351..d64dd663 100644 --- a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeUpdateDto.cs @@ -17,7 +17,7 @@ public class ActivityCodeUpdateDto public decimal RoadLengthRule { get; set; } public decimal SurfaceTypeRule { get; set; } public decimal RoadClassRule { get; set; } - public virtual IList ServiceAreaNumbers { get; set; } + public IList ServiceAreaNumbers { get; set; } public decimal? MinValue { get; set; } public decimal? MaxValue { get; set; } diff --git a/api/Hmcr.Model/Dtos/ServiceAreaActivity/ServiceAreaActivityDto.cs b/api/Hmcr.Model/Dtos/ServiceAreaActivity/ServiceAreaActivityDto.cs new file mode 100644 index 00000000..b8f003c8 --- /dev/null +++ b/api/Hmcr.Model/Dtos/ServiceAreaActivity/ServiceAreaActivityDto.cs @@ -0,0 +1,18 @@ +using Hmcr.Model.Dtos.ServiceArea; +using Hmcr.Model.Dtos.ServiceAreaActivity; +using System; +using System.Collections.Generic; +using System.Text; +using System.Text.Json.Serialization; + +namespace Hmcr.Model.Dtos.ServiceAreaActivity +{ + public class ServiceAreaActivityDto + { + [JsonPropertyName("id")] + public decimal ServiceAreaActivityId { get; set; } + public decimal ActivityCodeId { get; set; } + public decimal ServiceAreaNumber { get; set; } + public DateTime? EndDate { get; set; } + } +} From 238bc332d9e281161b742cf0f6aab7568097c1d4 Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Tue, 20 Oct 2020 13:11:58 -0700 Subject: [PATCH 31/46] Updates to Alter Script, fix incorrect history table sequence name. --- .../1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql | 28 ++----------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql b/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql index c74d39bf..17721f8e 100644 --- a/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql +++ b/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql @@ -1,4 +1,4 @@ --- Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Fri Oct 16 09:53:14 PDT 2020 +-- Script generated by Aqua Data Studio Schema Synchronization for MS SQL Server 2016 on Tue Oct 20 10:33:19 PDT 2020 -- Execute this script on: -- HMR V24.0/dbo - This database/schema will be modified -- to synchronize it with MS SQL Server 2016: @@ -63,30 +63,6 @@ GO IF @@ERROR <> 0 SET NOEXEC ON GO --- Drop sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ -PRINT N'Drop sequence dbo.HMR_ACTIVITY_RULE_ID_SEQ' -GO -DROP SEQUENCE [dbo].[HMR_ACTIVITY_RULE_ID_SEQ] -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - --- Drop table dbo.HMRX_TableDefinitions -PRINT N'Drop table dbo.HMRX_TableDefinitions' -GO -DROP TABLE [dbo].[HMRX_TableDefinitions] -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - --- Drop sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ -PRINT N'Drop sequence dbo.HMR_ACTIVITY_RULE_CODE_ID_SEQ' -GO -DROP SEQUENCE [dbo].[HMR_ACTIVITY_RULE_CODE_ID_SEQ] -GO -IF @@ERROR <> 0 SET NOEXEC ON -GO - -- Create sequence dbo.HMR_SERVICE_AREA_ACTIVITY_ID_SEQ PRINT N'Create sequence dbo.HMR_SERVICE_AREA_ACTIVITY_ID_SEQ' GO @@ -339,7 +315,7 @@ SET @curr_date = getutcdate(); IF EXISTS(SELECT * FROM inserted) insert into HMR_SERVICE_AREA_ACTIVITY_HIST ([SERVICE_AREA_ACTIVITY_ID], [ACTIVITY_CODE_ID], [SERVICE_AREA_NUMBER], [END_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], SERVICE_AREA_ACTIVITY_HIST_ID, END_DATE_HIST, EFFECTIVE_DATE_HIST) - select [SERVICE_AREA_ACTIVITY_ID], [ACTIVITY_CODE_ID], [SERVICE_AREA_NUMBER], [END_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], (next value for [dbo].[HMR_SERVICE_AREA_ACTIVITY_HIST_ID_SEQ]) as [SERVICE_AREA_ACTIVITY_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted; + select [SERVICE_AREA_ACTIVITY_ID], [ACTIVITY_CODE_ID], [SERVICE_AREA_NUMBER], [END_DATE], [CONCURRENCY_CONTROL_NUMBER], [APP_CREATE_USERID], [APP_CREATE_TIMESTAMP], [APP_CREATE_USER_GUID], [APP_CREATE_USER_DIRECTORY], [APP_LAST_UPDATE_USERID], [APP_LAST_UPDATE_TIMESTAMP], [APP_LAST_UPDATE_USER_GUID], [APP_LAST_UPDATE_USER_DIRECTORY], [DB_AUDIT_CREATE_USERID], [DB_AUDIT_CREATE_TIMESTAMP], [DB_AUDIT_LAST_UPDATE_USERID], [DB_AUDIT_LAST_UPDATE_TIMESTAMP], (next value for [dbo].[HMR_SERVICE_AREA_ACTIVITY_H_ID_SEQ]) as [SERVICE_AREA_ACTIVITY_HIST_ID], null as [END_DATE_HIST], @curr_date as [EFFECTIVE_DATE_HIST] from inserted; END TRY BEGIN CATCH From 3528f94c77b4e83eac9938af90f0a9c13ba42917 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Tue, 20 Oct 2020 13:48:34 -0700 Subject: [PATCH 32/46] update service area controller max/min vaues new rules applied --- .../Repositories/ActivityCodeRepository.cs | 28 +++++++++++- .../Services/ActivityCodeService.cs | 2 +- client/src/js/components/ActivityAdmin.js | 7 ++- .../forms/EditActivityFormFields.js | 45 ++----------------- 4 files changed, 34 insertions(+), 48 deletions(-) diff --git a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs index de2a31b2..78ab887a 100644 --- a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs @@ -156,13 +156,14 @@ public async Task> GetActivityCodesAsync(string[ public async Task UpdateActivityCodeAsync(ActivityCodeUpdateDto activityCode) { var activityCodeEntity = await DbSet + .Include(x => x.HmrServiceAreaActivities) .FirstAsync(ac => ac.ActivityCodeId == activityCode.ActivityCodeId); activityCode.EndDate = activityCode.EndDate?.Date; Mapper.Map(activityCode, activityCodeEntity); - //TODO: call function to sync service area changes + SyncActivityCodeServiceAreas(activityCode, activityCodeEntity); } public async Task DeleteActivityCodeAsync(decimal id) @@ -187,5 +188,30 @@ private async IAsyncEnumerable FindActivityNumbersInUseAync(IEnumerable< } } + private void SyncActivityCodeServiceAreas(ActivityCodeUpdateDto activityCodeUpdateDto, HmrActivityCode activityCodeEntity) + { + var areasToDelete = + activityCodeEntity.HmrServiceAreaActivities.Where(s => !activityCodeUpdateDto.ServiceAreaNumbers.Contains(s.ServiceAreaNumber)).ToList(); + + for (var i = areasToDelete.Count() - 1; i >= 0; i--) + { + DbContext.Remove(areasToDelete[i]); + } + + var existingAreaNumbers = activityCodeEntity.HmrServiceAreaActivities.Select(s => s.ServiceAreaNumber); + + var newAreaNumbers = activityCodeUpdateDto.ServiceAreaNumbers.Where(r => !existingAreaNumbers.Contains(r)); + + foreach (var areaNumber in newAreaNumbers) + { + activityCodeEntity.HmrServiceAreaActivities + .Add(new HmrServiceAreaActivity + { + ServiceAreaNumber = areaNumber, + ActivityCodeId = activityCodeEntity.ActivityCodeId + }); + } + } + } } diff --git a/api/Hmcr.Domain/Services/ActivityCodeService.cs b/api/Hmcr.Domain/Services/ActivityCodeService.cs index b379af81..8eb6c821 100644 --- a/api/Hmcr.Domain/Services/ActivityCodeService.cs +++ b/api/Hmcr.Domain/Services/ActivityCodeService.cs @@ -196,7 +196,7 @@ public async Task> GetActivityCodesAsync(string[ if (errors.Count > 0) { return (false, errors); - } + } await _activityCodeRepo.UpdateActivityCodeAsync(activityCode); _unitOfWork.Commit(); diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index e32ae2c2..b1feffce 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -20,8 +20,7 @@ import { showValidationErrorDialog } from '../actions'; import * as Constants from '../Constants'; import * as api from '../Api'; -import { buildStatusIdArray,isValueNotEmpty,toNumberOrNull,toStringOrEmpty } from '../utils'; -import { toNumber } from 'lodash'; +import { buildStatusIdArray,isValueNotEmpty,toNumberOrNull,toStringOrEmpty,isValueEmpty } from '../utils'; const defaultSearchFormValues = { searchText: '', maintenanceTypeIds: [], statusId: [Constants.ACTIVE_STATUS.ACTIVE] }; @@ -113,9 +112,9 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal values.minValue = toNumberOrNull(values.minValue); values.maxValue = toNumberOrNull(values.maxValue); values.reportingFrequency = toNumberOrNull(values.reportingFrequency ); - if(isValueNotEmpty(values.minValue) && toNumber(values.maxValue) === 0) + if(isValueNotEmpty(values.minValue) && isValueEmpty(values.maxValue)) { - values.maxValue = (['site','num','ea'].includes(values.unitOfMeasure)) ? 999999999.99:999999999; + values.maxValue = (['site','num','ea'].includes(values.unitOfMeasure)) ? 999999999:999999999.99; } if (formType === Constants.FORM_TYPE.ADD) { api diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 3478a2df..65cfa429 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -1,5 +1,4 @@ import React, { useEffect, useState } from 'react'; -import { useFormikContext} from 'formik'; import { connect } from 'react-redux'; import * as Yup from 'yup'; import moment from 'moment'; @@ -15,7 +14,7 @@ import { FormRow, FormInput, FormCheckboxInput } from './FormInputs'; import * as api from '../../Api'; import * as Constants from '../../Constants'; import { Row,Col} from 'reactstrap'; -import { isInteger, toString } from 'lodash'; +import { isInteger} from 'lodash'; import {isValueEmpty,isValueNotEmpty,toStringOrEmpty} from '../../utils' const tipAnalyticalValidation = [
          @@ -162,7 +161,6 @@ const EditActivityFormFields = ({ serviceAreas, }) => { const [loading, setLoading] = useState(true); - const {setFieldValue} = useFormikContext(); const [validLocationCodeValues, setValidLocationCodeValues] = useState(locationCodes); const [disableLocationCodeEdit, setDisableLocationCodeEdit] = useState(false); const [validFeatureTypeValues, setValidFeatureTypeValues] = useState(featureTypes); @@ -192,7 +190,6 @@ const EditActivityFormFields = ({ }), }); - setValidationSchema(defaultValidationSchema); setLoading(true); @@ -217,7 +214,6 @@ const EditActivityFormFields = ({ if (response.data.locationCodeId === locationCodes.find((code) => code.name === 'B').id) return locationCodes.filter((location) => location.name !== 'C'); } - return locationCodes; }); @@ -240,7 +236,6 @@ const EditActivityFormFields = ({ (feature) => feature.id === pointLineType || feature.id === response.data.featureType ); } - return featureTypes; }); @@ -253,40 +248,6 @@ const EditActivityFormFields = ({ if (loading || formValues === null) return ; - const convertMaxValue = (minv,maxv)=>{ - const minval = minv; - const maxval = maxv; - if (isValueNotEmpty(minval) && Number(minval) >=0 && isValueNotEmpty(maxval) && Number(maxval) === 0) - { - return (['site','num','ea'].includes(formValues.unitOfMeasure)) ? '999999999': '999999999.99'; - } - if(isValueEmpty(maxval)) return ''; - return toString(maxval); - }; - - const handleMinValue = (e) => { - const minv = e.target.value; - if(formValues) - { - let maxv= formValues.maxValue; - maxv = convertMaxValue(minv,maxv); - setFieldValue('maxValue',maxv); - } - setFieldValue('minValue', minv); - }; - - const handleMaxValue = (e) => { - const maxval = e.target.value; - if(formValues) - { - let minval = formValues.minValue; - setFieldValue('maxValue',convertMaxValue(minval,maxval)); - } - else{ - setFieldValue('maxValue', maxval); - } - }; - return ( @@ -345,10 +306,10 @@ const EditActivityFormFields = ({
          - + - + From 8facafcb6725872e41a1e6ef8f6bb24b0786fc5c Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Tue, 20 Oct 2020 15:53:24 -0700 Subject: [PATCH 33/46] update controller --- .../forms/EditActivityFormFields.js | 14 ++++++++++---- client/src/js/components/ui/FieldSet.js | 19 +++++++++++++++---- .../src/js/components/ui/MouseoverTooltip.js | 2 +- client/src/js/utils.js | 2 +- client/src/scss/_forms.scss | 13 ++----------- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 65cfa429..9bdf1918 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -18,9 +18,15 @@ import { isInteger} from 'lodash'; import {isValueEmpty,isValueNotEmpty,toStringOrEmpty} from '../../utils' const tipAnalyticalValidation = [
            -
          • Analytical Validation Help 1
          • -
          • Analytical Validation Help 2
          • + Analytical Validations provide warnings when the activity accomplishment does not meet the defined parameters. +
          • Minimum Value and Maximum Value check the accomplishment for an activity is within numerical limits, as defined. + No tolerances are added to the Minimum Value or Maximum Value calculations.
          • +
          • Reporting Frequency checks if the activity was reported in the same location, with locational specificity based on the activity location code, + within the defined period. A tolerance of 100 metres is added to the start and end points for Location Code C activities to validate against previously + reported instances. No time-based tolerance is added to the Reporting Frequency calculation. Users can manually incorporate into the defined Reporting + Frequency a time-based tolerance (e.g. by setting the minimum number of days to ‘20’ for an activity that should be completed monthly).
          ]; + const tipHighwayAttributeValidation = [
          • Highway Attribute Validation Help
          ]; @@ -69,7 +75,7 @@ const validationSchema = Yup.object({ if(this.parent.minValue > 999999999.99) { return this.createError({ - message: 'Must be less than or equal to 999999999.99', + message: 'Must be less than or equal to 999,999,999.99', path: 'minValue', }); } @@ -110,7 +116,7 @@ const validationSchema = Yup.object({ if(Number(this.parent.maxValue) > 999999999.99) { return this.createError({ - message: 'Must be less than or equal to 999999999.99', + message: 'Must be less than or equal to 999,999,999.99', path: 'maxValue', }); } diff --git a/client/src/js/components/ui/FieldSet.js b/client/src/js/components/ui/FieldSet.js index c62efd67..9cd1e6d1 100644 --- a/client/src/js/components/ui/FieldSet.js +++ b/client/src/js/components/ui/FieldSet.js @@ -1,14 +1,25 @@ -import React from 'react'; -import MouseoverTooltip from './MouseoverTooltip'; - +import React,{ useState } from 'react'; +import { Popover, PopoverBody } from 'reactstrap'; +import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; const FieldSet = (props) => { const { legendname,children,targetId,tips } = props; const tipId = (targetId===undefined||targetId===null||targetId==='')?'TooltipForFieldsetId':targetId; + const [isOpen, setIsOpen] = useState(false); return (
          {legendname} - {tips} + setIsOpen(true)} + onMouseOut={() => setIsOpen(false)} + style={{ cursor: 'pointer' }} + /> + + {tips} + {children}
          diff --git a/client/src/js/components/ui/MouseoverTooltip.js b/client/src/js/components/ui/MouseoverTooltip.js index 6a151970..cfeae4a6 100644 --- a/client/src/js/components/ui/MouseoverTooltip.js +++ b/client/src/js/components/ui/MouseoverTooltip.js @@ -10,7 +10,7 @@ const MouseoverTooltip = (props) => { setIsOpen(true)} onMouseOut={() => setIsOpen(false)} style={{ cursor: 'pointer' }} diff --git a/client/src/js/utils.js b/client/src/js/utils.js index 6cd0f9db..c1468ae4 100644 --- a/client/src/js/utils.js +++ b/client/src/js/utils.js @@ -76,4 +76,4 @@ export const toNumberOrNull=(v)=>{ }; export const toStringOrEmpty=(v)=>{ return isValueNotEmpty(v) ? _.toString(v): ''; -}; \ No newline at end of file +}; diff --git a/client/src/scss/_forms.scss b/client/src/scss/_forms.scss index c7c1d51a..f9c10192 100644 --- a/client/src/scss/_forms.scss +++ b/client/src/scss/_forms.scss @@ -56,16 +56,7 @@ .form-control.servicearea-large.is-invalid { border-color: #d93e45; } -.fieldset-tooltip [class$="inner"] { - background-color: #ffffca; - border: 1px solid #737373; - max-width: 160px; - color:black; - font-size: 12px; - text-align: left; -} +.fieldset-tooltip{ + max-width: 600px; -.fieldset-tooltip [class$="arrow"] { - border-top: 5px solid #ffffca !important; - background-color: #737373; } \ No newline at end of file From c4f823ba3e8c0daa165ae45cda1b8ce90dce0b9d Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Tue, 20 Oct 2020 22:06:48 -0700 Subject: [PATCH 34/46] added tooltip text added scrollbar added commas conversion --- client/src/js/components/ActivityAdmin.js | 10 +++--- .../forms/EditActivityFormFields.js | 36 ++++++++++++++----- client/src/js/components/ui/FieldSet.js | 27 +++++++------- client/src/js/utils.js | 13 ++++++- client/src/scss/_forms.scss | 25 +++++++++++-- 5 files changed, 80 insertions(+), 31 deletions(-) diff --git a/client/src/js/components/ActivityAdmin.js b/client/src/js/components/ActivityAdmin.js index b1feffce..07d615e0 100644 --- a/client/src/js/components/ActivityAdmin.js +++ b/client/src/js/components/ActivityAdmin.js @@ -20,7 +20,7 @@ import { showValidationErrorDialog } from '../actions'; import * as Constants from '../Constants'; import * as api from '../Api'; -import { buildStatusIdArray,isValueNotEmpty,toNumberOrNull,toStringOrEmpty,isValueEmpty } from '../utils'; +import { buildStatusIdArray,isValueNotEmpty,toNumberOrNull,toStringOrEmpty,toStringWithCommasOrEmpty,isValueEmpty } from '../utils'; const defaultSearchFormValues = { searchText: '', maintenanceTypeIds: [], statusId: [Constants.ACTIVE_STATUS.ACTIVE] }; @@ -120,8 +120,8 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal api .postActivityCode(values) .then(() => { - values.minValue = toStringOrEmpty(values.minValue); - values.maxValue = toStringOrEmpty(values.maxValue); + values.minValue = toStringWithCommasOrEmpty(values.minValue); + values.maxValue = toStringWithCommasOrEmpty(values.maxValue); values.reportingFrequency = toStringOrEmpty(values.reportingFrequency ); formModal.closeForm(); searchData.refresh(); @@ -132,8 +132,8 @@ const ActivityAdmin = ({ maintenanceTypes, locationCodes, unitOfMeasures,showVal api .putActivityCode(values.id, values) .then(() => { - values.minValue = toStringOrEmpty(values.minValue); - values.maxValue = toStringOrEmpty(values.maxValue); + values.minValue = toStringWithCommasOrEmpty(values.minValue); + values.maxValue = toStringWithCommasOrEmpty(values.maxValue); values.reportingFrequency = toStringOrEmpty(values.reportingFrequency ); formModal.closeForm(); searchData.refresh(); diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 9bdf1918..bb205944 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -15,10 +15,10 @@ import * as api from '../../Api'; import * as Constants from '../../Constants'; import { Row,Col} from 'reactstrap'; import { isInteger} from 'lodash'; -import {isValueEmpty,isValueNotEmpty,toStringOrEmpty} from '../../utils' +import {isValueEmpty,isValueNotEmpty,toStringOrEmpty,toStringWithCommasOrEmpty} from '../../utils' -const tipAnalyticalValidation = [
            - Analytical Validations provide warnings when the activity accomplishment does not meet the defined parameters. +const tipAnalyticalValidation = [
              +
            • Analytical Validations provide warnings when the activity accomplishment does not meet the defined parameters.
            • Minimum Value and Maximum Value check the accomplishment for an activity is within numerical limits, as defined. No tolerances are added to the Minimum Value or Maximum Value calculations.
            • Reporting Frequency checks if the activity was reported in the same location, with locational specificity based on the activity location code, @@ -27,8 +27,27 @@ const tipAnalyticalValidation = [
              ]; -const tipHighwayAttributeValidation = [
                -
              • Highway Attribute Validation Help
              • +const tipHighwayAttributeValidation = [
                  +
                • Highway Attribute Validations provide warnings for Location Code C activities when the features of the reported + location and/or accomplishment do not meet the defined parameters.
                • +
                • Road Length checks the accomplishment against the road length (either Road KM or Lane KM), + or against Guardrail Length [NTD: to confirm Guardrail vs Barrier vernacular based on what types of + guardrail/barrier will be included], as defined in each individual rule. Several rules account for the road length + to be multiplied by one or more factors to accommodate non kilometre-based units of measure. Multiplying factors + include conversion factors (e.g. 1km=1,000m), application rates (e.g. 2.0 litres/m2) or lane width factors to calculate surface area + (e.g. lane width = 3.5m). A 10% tolerance is added to the Total Road KM (to a 200m maximum) and Total Lane KM (to a 500m maximum) + and Barrier Length (to a 200m maximum) for the validation calculations. Point items are calculated with + an estimated Road KM length of 40m (30m as permitted by the Reporting Manual and 10m tolerance), with Lane KM calculated based + on the number of lanes at the point.
                • +
                • Surface Type checks that the location of the record has the appropriate surface type based on the selected rule. + For point items, the surface type must match the point exactly and no tolerance is incorporated. For line items, + a tolerance of 80% is incorporated (i.e. if the rule is “GPS on Paved Surface” and 80% or more of the surface types + within the start and end GPS points are paved, then the record is accepted). Paved surfaces include CHRIS surface types 1-4; + non-paved surfaces include CHRIS surface types 5-6; unconstructed roads have a CHRIS surface type of E or F.
                • +
                • Road Class checks that the location of the record has the appropriate summer or winter road + classifications based on the selected rule. For point items, the classification must match exactly and no tolerance + is incorporated. For line items, a tolerance of 80% is incorporated (i.e. if the rule is “Not Class 8 or F” and 80% or + more of the maintenance class within the start and end GPS points are not 8 or F, then the record is accepted).
                ]; const defaultValues = { @@ -62,6 +81,7 @@ const validationSchema = Yup.object({ locationCodeId: Yup.number().required('Required'), serviceAreaNumbers: Yup.array().required('At least one Service Area must be selected'), minValue: Yup.number() + .transform((_value, originalValue) => Number(originalValue.replace(/,/g, ''))) .min(0,'Must be greater than or equal to 0') .nullable() .typeError('Must be number') @@ -103,9 +123,9 @@ const validationSchema = Yup.object({ } ), maxValue: Yup.number() + .transform((_value, originalValue) => Number(originalValue.replace(/,/g, ''))) .min(0,'Must be greater than or equal to 0') .nullable() - .typeError('Must be number') .test( 'datamax', function() { @@ -210,8 +230,8 @@ const EditActivityFormFields = ({ setInitialValues({ ...response.data, endDate: response.data.endDate ? moment(response.data.endDate): null, - minValue: toStringOrEmpty(response.data.minValue), - maxValue: toStringOrEmpty(response.data.maxValue), + minValue: toStringWithCommasOrEmpty(response.data.minValue), + maxValue: toStringWithCommasOrEmpty(response.data.maxValue), reportingFrequency: toStringOrEmpty(response.data.reportingFrequency), }); diff --git a/client/src/js/components/ui/FieldSet.js b/client/src/js/components/ui/FieldSet.js index 9cd1e6d1..4dfc8ef8 100644 --- a/client/src/js/components/ui/FieldSet.js +++ b/client/src/js/components/ui/FieldSet.js @@ -1,25 +1,22 @@ import React,{ useState } from 'react'; -import { Popover, PopoverBody } from 'reactstrap'; +import { Tooltip } from 'reactstrap'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; + const FieldSet = (props) => { const { legendname,children,targetId,tips } = props; const tipId = (targetId===undefined||targetId===null||targetId==='')?'TooltipForFieldsetId':targetId; - const [isOpen, setIsOpen] = useState(false); + const [tooltipOpen, setTooltipOpen] = useState(false); + const toggle = () => setTooltipOpen(!tooltipOpen); return ( -
                - {legendname} - - + {legendname} + setIsOpen(true)} - onMouseOut={() => setIsOpen(false)} - style={{ cursor: 'pointer' }} - /> - - {tips} - + className="fa-color-primary ml-1 mr-1"/> + + +
                {tips}
                {children}
                diff --git a/client/src/js/utils.js b/client/src/js/utils.js index c1468ae4..db7f3025 100644 --- a/client/src/js/utils.js +++ b/client/src/js/utils.js @@ -72,8 +72,19 @@ export const isValueNotEmpty=(v)=>{ }; export const toNumberOrNull=(v)=>{ - return isValueNotEmpty(v) ? _.toNumber(v): null; + return isValueNotEmpty(v) ? _.toNumber(v.replace(/,/g, '')): null; }; export const toStringOrEmpty=(v)=>{ return isValueNotEmpty(v) ? _.toString(v): ''; }; +export const toStringWithCommasOrEmpty=(v)=>{ + return isValueNotEmpty(v) ? _.toString(addCommasToNumber(v)): ''; +}; +export const addCommasToNumber=(n) =>{ + if(isValueEmpty(n)) return n; + let s = n.toString().replace(/,/g, '').split('.'); + if (s[0].length >= 4) { + s[0] = s[0].replace(/(\d)(?=(\d{3})+$)/g, '$1,'); + } + return s.join('.'); +} diff --git a/client/src/scss/_forms.scss b/client/src/scss/_forms.scss index f9c10192..76243928 100644 --- a/client/src/scss/_forms.scss +++ b/client/src/scss/_forms.scss @@ -56,7 +56,28 @@ .form-control.servicearea-large.is-invalid { border-color: #d93e45; } -.fieldset-tooltip{ - max-width: 600px; +.fieldset-tooltip [class$="inner"] { + padding:0.5rem 0.75rem; + background-color: #fff; + border: 1px solid #737373; + color:black; + max-width: 400px; + height: 160px; + font-family:Myriad-Pro,Calibri,Arial,sans serif; + font-size: 0.875rem; + font-weight: 400; + text-align: left; + text-decoration: none; + word-spacing: normal; + word-break: normal; + white-space: normal; +} +.fieldset-tooltip [class$="arrow"] { + border-top: 5px solid #fff !important; +} +.fieldset-tooltip-body { + overflow-y: auto; + max-width: 380px; + height: 140px; } \ No newline at end of file From 5af30464d7d41a32414b1913d672be6bead11da8 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Tue, 20 Oct 2020 22:30:10 -0700 Subject: [PATCH 35/46] added digits check --- .../components/forms/EditActivityFormFields.js | 17 ++++++++++++++++- client/src/js/utils.js | 15 +++++++++++++-- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index bb205944..e3195060 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -15,7 +15,7 @@ import * as api from '../../Api'; import * as Constants from '../../Constants'; import { Row,Col} from 'reactstrap'; import { isInteger} from 'lodash'; -import {isValueEmpty,isValueNotEmpty,toStringOrEmpty,toStringWithCommasOrEmpty} from '../../utils' +import {isValueEmpty,isValueNotEmpty,toStringOrEmpty,toStringWithCommasOrEmpty,isValidDecimal} from '../../utils' const tipAnalyticalValidation = [
                • Analytical Validations provide warnings when the activity accomplishment does not meet the defined parameters.
                • @@ -99,6 +99,13 @@ const validationSchema = Yup.object({ path: 'minValue', }); } + if(!isValidDecimal(this.parent.minValue,2)) + { + return this.createError({ + message: 'Must be less than or equal to 2 digits', + path: 'minValue', + }); + } if(isValueNotEmpty(this.parent.maxValue)) { if(Number(this.parent.maxValue) !== 0 && this.parent.maxValue < this.parent.minValue) @@ -126,6 +133,7 @@ const validationSchema = Yup.object({ .transform((_value, originalValue) => Number(originalValue.replace(/,/g, ''))) .min(0,'Must be greater than or equal to 0') .nullable() + .typeError('Must be number') .test( 'datamax', function() { @@ -140,6 +148,13 @@ const validationSchema = Yup.object({ path: 'maxValue', }); } + if(!isValidDecimal(this.parent.maxValue,2)) + { + return this.createError({ + message: 'Must be less than or equal to 2 digits', + path: 'maxValue', + }); + } if (isValueNotEmpty(this.parent.minValue)) { if(Number(this.parent.maxValue) !== 0 && this.parent.maxValue < this.parent.minValue) diff --git a/client/src/js/utils.js b/client/src/js/utils.js index db7f3025..8ff49957 100644 --- a/client/src/js/utils.js +++ b/client/src/js/utils.js @@ -72,7 +72,7 @@ export const isValueNotEmpty=(v)=>{ }; export const toNumberOrNull=(v)=>{ - return isValueNotEmpty(v) ? _.toNumber(v.replace(/,/g, '')): null; + return isValueNotEmpty(v) ? _.toNumber(removeStringCommas(v)): null; }; export const toStringOrEmpty=(v)=>{ return isValueNotEmpty(v) ? _.toString(v): ''; @@ -80,11 +80,22 @@ export const toStringOrEmpty=(v)=>{ export const toStringWithCommasOrEmpty=(v)=>{ return isValueNotEmpty(v) ? _.toString(addCommasToNumber(v)): ''; }; +export const removeStringCommas=(v)=>{ + return v.toString().replace(/,/g, ''); +} export const addCommasToNumber=(n) =>{ if(isValueEmpty(n)) return n; - let s = n.toString().replace(/,/g, '').split('.'); + let s = removeStringCommas(n).split('.'); if (s[0].length >= 4) { s[0] = s[0].replace(/(\d)(?=(\d{3})+$)/g, '$1,'); } return s.join('.'); } +export const isValidDecimal=(v,digits) =>{ + if(isValueEmpty(v)) return true; + const d = _.toInteger(digits); + let s = removeStringCommas(v).split('.'); + if(s.length <2) return true; + if (s[1].length <= d) return true; + return false; +} From bb7f8cd8323f29fd63f0492a2e041c6ceed7548c Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Wed, 21 Oct 2020 10:02:09 -0700 Subject: [PATCH 36/46] Updated scripts to USE appropriate instance (commented) Added script to add 'GPS Not on Unconstructed' surface type --- .../V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql | 5 +++++ .../V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql | 6 ++++++ .../2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql | 5 ++++- ...DM-dml_INSERT_HMR_ACTIVITY_CODE_RULE_V25_IS2.2.sql | 11 +++++++++++ 4 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 database/V25.0/3_HMR_PDM-dml_INSERT_HMR_ACTIVITY_CODE_RULE_V25_IS2.2.sql diff --git a/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql b/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql index b4e4a9ee..fd131e80 100644 --- a/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql +++ b/database/V24.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V24_IS2.1.sql @@ -5,6 +5,11 @@ -- HMR V24.0/dbo -- We recommend backing up the database prior to executing the script. +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; +GO SET XACT_ABORT ON GO diff --git a/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql b/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql index 17721f8e..0a2e1b8a 100644 --- a/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql +++ b/database/V25.0/1_HMR_PDM-ddl_ALTER_APP_HMR_V25_IS2.2.sql @@ -6,6 +6,12 @@ -- We recommend backing up the database prior to executing the script. +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; +GO + SET XACT_ABORT ON GO SET TRANSACTION ISOLATION LEVEL SERIALIZABLE diff --git a/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql b/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql index f4f79b29..07f37b3e 100644 --- a/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql +++ b/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql @@ -7,7 +7,10 @@ -- Doug Filteau 2020-Oct-14 Initial version. -- ***************************************************************************** -USE HMR_DEV; +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; GO INSERT INTO [dbo].[HMR_SERVICE_AREA_ACTIVITY] diff --git a/database/V25.0/3_HMR_PDM-dml_INSERT_HMR_ACTIVITY_CODE_RULE_V25_IS2.2.sql b/database/V25.0/3_HMR_PDM-dml_INSERT_HMR_ACTIVITY_CODE_RULE_V25_IS2.2.sql new file mode 100644 index 00000000..2f3dc077 --- /dev/null +++ b/database/V25.0/3_HMR_PDM-dml_INSERT_HMR_ACTIVITY_CODE_RULE_V25_IS2.2.sql @@ -0,0 +1,11 @@ +USE HMR_DEV; -- uncomment appropriate instance +--USE HMR_TST; +--USE HMR_UAT; +--USE HMR_PRD; +GO + +INSERT INTO [dbo].[HMR_ACTIVITY_CODE_RULE] + ([ACTIVITY_RULE_SET],[ACTIVITY_RULE_NAME],[ACTIVITY_RULE_EXEC_NAME],[DISPLAY_ORDER]) + VALUES + ('SURFACE_TYPE','GPS Not on Unconstructed','GPS_NOT_UNCONSTRUCTED',5) +GO \ No newline at end of file From 8621b60f68b34fabf0279a5868d3ebc194f22bd0 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Wed, 21 Oct 2020 12:54:47 -0700 Subject: [PATCH 37/46] decimal digits validation --- .../components/forms/EditActivityFormFields.js | 18 ++++++++++++------ client/src/js/utils.js | 8 +++----- client/src/scss/_forms.scss | 10 +++++++--- 3 files changed, 22 insertions(+), 14 deletions(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index e3195060..5e9d1939 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -17,7 +17,7 @@ import { Row,Col} from 'reactstrap'; import { isInteger} from 'lodash'; import {isValueEmpty,isValueNotEmpty,toStringOrEmpty,toStringWithCommasOrEmpty,isValidDecimal} from '../../utils' -const tipAnalyticalValidation = [
                    +const tipAnalyticalValidation = [
                    • Analytical Validations provide warnings when the activity accomplishment does not meet the defined parameters.
                    • Minimum Value and Maximum Value check the accomplishment for an activity is within numerical limits, as defined. No tolerances are added to the Minimum Value or Maximum Value calculations.
                    • @@ -27,7 +27,7 @@ const tipAnalyticalValidation = [
                        Frequency a time-based tolerance (e.g. by setting the minimum number of days to ‘20’ for an activity that should be completed monthly).
                      ]; -const tipHighwayAttributeValidation = [
                        +const tipHighwayAttributeValidation = [
                        • Highway Attribute Validations provide warnings for Location Code C activities when the features of the reported location and/or accomplishment do not meet the defined parameters.
                        • Road Length checks the accomplishment against the road length (either Road KM or Lane KM), @@ -81,7 +81,10 @@ const validationSchema = Yup.object({ locationCodeId: Yup.number().required('Required'), serviceAreaNumbers: Yup.array().required('At least one Service Area must be selected'), minValue: Yup.number() - .transform((_value, originalValue) => Number(originalValue.replace(/,/g, ''))) + .transform((_value, originalValue) => { + if(isValueEmpty(originalValue.replace(/,/g, ''))) return null; + return Number(originalValue.replace(/,/g, '')); + }) .min(0,'Must be greater than or equal to 0') .nullable() .typeError('Must be number') @@ -102,7 +105,7 @@ const validationSchema = Yup.object({ if(!isValidDecimal(this.parent.minValue,2)) { return this.createError({ - message: 'Must be less than or equal to 2 digits', + message: 'Must be less than or equal to two decimal positions', path: 'minValue', }); } @@ -130,7 +133,10 @@ const validationSchema = Yup.object({ } ), maxValue: Yup.number() - .transform((_value, originalValue) => Number(originalValue.replace(/,/g, ''))) + .transform((_value, originalValue) => { + if(isValueEmpty(originalValue.replace(/,/g, ''))) return null; + return Number(originalValue.replace(/,/g, '')); + }) .min(0,'Must be greater than or equal to 0') .nullable() .typeError('Must be number') @@ -151,7 +157,7 @@ const validationSchema = Yup.object({ if(!isValidDecimal(this.parent.maxValue,2)) { return this.createError({ - message: 'Must be less than or equal to 2 digits', + message: 'Must be less than or equal to two decimal positions', path: 'maxValue', }); } diff --git a/client/src/js/utils.js b/client/src/js/utils.js index 8ff49957..37c86786 100644 --- a/client/src/js/utils.js +++ b/client/src/js/utils.js @@ -72,7 +72,7 @@ export const isValueNotEmpty=(v)=>{ }; export const toNumberOrNull=(v)=>{ - return isValueNotEmpty(v) ? _.toNumber(removeStringCommas(v)): null; + return isValueNotEmpty(removeStringCommas(v)) ? _.toNumber(removeStringCommas(v)): null; }; export const toStringOrEmpty=(v)=>{ return isValueNotEmpty(v) ? _.toString(v): ''; @@ -86,15 +86,13 @@ export const removeStringCommas=(v)=>{ export const addCommasToNumber=(n) =>{ if(isValueEmpty(n)) return n; let s = removeStringCommas(n).split('.'); - if (s[0].length >= 4) { - s[0] = s[0].replace(/(\d)(?=(\d{3})+$)/g, '$1,'); - } + if (s[0].length >= 4) s[0] = s[0].replace(/(\d)(?=(\d{3})+$)/g, '$1,'); return s.join('.'); } export const isValidDecimal=(v,digits) =>{ if(isValueEmpty(v)) return true; const d = _.toInteger(digits); - let s = removeStringCommas(v).split('.'); + let s = Number(removeStringCommas(v)).toString().split('.'); if(s.length <2) return true; if (s[1].length <= d) return true; return false; diff --git a/client/src/scss/_forms.scss b/client/src/scss/_forms.scss index 76243928..0289a6d0 100644 --- a/client/src/scss/_forms.scss +++ b/client/src/scss/_forms.scss @@ -63,7 +63,6 @@ color:black; max-width: 400px; height: 160px; - font-family:Myriad-Pro,Calibri,Arial,sans serif; font-size: 0.875rem; font-weight: 400; text-align: left; @@ -71,10 +70,15 @@ word-spacing: normal; word-break: normal; white-space: normal; + background-clip: padding-box; + border: 1px solid rgba(0,0,0,.2); + box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24); + + } -.fieldset-tooltip [class$="arrow"] { - border-top: 5px solid #fff !important; +.fieldset-tooltip> div.show { + opacity: 1; } .fieldset-tooltip-body { overflow-y: auto; From 7554b3d82147d2d294402a49376e7eb1d68b4844 Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Wed, 21 Oct 2020 14:32:41 -0700 Subject: [PATCH 38/46] Created ActivityCodeRuleCache funcation and load the activity code rules as singleton on app creation. --- api/Hmcr.Api/Startup.cs | 5 ++-- .../Repositories/ActivityRuleRepository.cs | 16 ++++++++++ .../Services/FieldValidatorService.cs | 4 +++ api/Hmcr.Hangfire/Startup.cs | 4 ++- api/Hmcr.Model/Constants.cs | 30 +++++++++++++++++++ .../ActivityCodeRule/ActivityCodeRuleCache.cs | 16 ++++++++++ 6 files changed, 72 insertions(+), 3 deletions(-) create mode 100644 api/Hmcr.Model/Dtos/ActivityCodeRule/ActivityCodeRuleCache.cs diff --git a/api/Hmcr.Api/Startup.cs b/api/Hmcr.Api/Startup.cs index ffce4229..e7ec5a31 100644 --- a/api/Hmcr.Api/Startup.cs +++ b/api/Hmcr.Api/Startup.cs @@ -14,7 +14,6 @@ namespace Hmcr.Api { public class Startup { - public IConfiguration Configuration { get; } private IWebHostEnvironment _env; @@ -44,7 +43,8 @@ public void ConfigureServices(IServiceCollection services) } public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISubmissionObjectJobService jobService, - IServiceScopeFactory serviceScopeFactory, IServiceAreaService svcAreaService, ICodeLookupRepository codeLookupRepo, IFieldValidatorService validator) + IServiceScopeFactory serviceScopeFactory, IServiceAreaService svcAreaService, ICodeLookupRepository codeLookupRepo, + IActivityRuleRepository activityRuleRepo, IFieldValidatorService validator) { if (env.IsDevelopment()) app.UseDeveloperExceptionPage(); @@ -58,6 +58,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISubmiss app.UseHmcrSwagger(env, Configuration.GetSection("Constants:SwaggerApiUrl").Value); validator.CodeLookup = codeLookupRepo.LoadCodeLookupCache(); + validator.ActivityCodeRuleLookup = activityRuleRepo.LoadActivityCodeRuleCache(); } } } diff --git a/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs index 01825a34..142a2ddf 100644 --- a/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityRuleRepository.cs @@ -17,6 +17,7 @@ public interface IActivityRuleRepository Task> GetSurfaceTypeRulesAsync(); Task> GetRoadClassRulesAsync(); Task> GetDefaultRules(); + IEnumerable LoadActivityCodeRuleCache(); } public class ActivityRuleRepository : HmcrRepositoryBase, IActivityRuleRepository @@ -26,6 +27,21 @@ public ActivityRuleRepository(AppDbContext dbContext, IMapper mapper) { } + public IEnumerable LoadActivityCodeRuleCache() + { + return DbSet.AsNoTracking() + .Where(x => x.EndDate == null || DateTime.Today < x.EndDate) + .Select(x => + new ActivityCodeRuleCache + { + ActivityCodeRuleId = x.ActivityCodeRuleId, + ActivityRuleSet = x.ActivityRuleSet, + ActivityRuleName = x.ActivityRuleName, + ActivityRuleExecName = x.ActivityRuleExecName + } + ).ToArray(); + } + public async Task> GetRoadLengthRulesAsync() { var activityRules = await DbSet.AsNoTracking() diff --git a/api/Hmcr.Domain/Services/FieldValidatorService.cs b/api/Hmcr.Domain/Services/FieldValidatorService.cs index d86e89bf..cb4d2d8d 100644 --- a/api/Hmcr.Domain/Services/FieldValidatorService.cs +++ b/api/Hmcr.Domain/Services/FieldValidatorService.cs @@ -1,5 +1,6 @@ using Hmcr.Model; using Hmcr.Model.Dtos.CodeLookup; +using Hmcr.Model.Dtos.ActivityRule; using Hmcr.Model.Utils; using System; using System.Collections.Generic; @@ -14,12 +15,15 @@ public interface IFieldValidatorService void Validate(string entityName, string fieldName, T value, Dictionary> errors, int rowNum = 0); void Validate(string entityName, T entity, Dictionary> errors, int rowNum = 0, params string[] fieldsToSkip); IEnumerable CodeLookup { get; set; } + + IEnumerable ActivityCodeRuleLookup { get; set; } } public class FieldValidatorService : IFieldValidatorService { List _rules; RegexDefs _regex; public IEnumerable CodeLookup { get; set; } + public IEnumerable ActivityCodeRuleLookup { get; set; } public FieldValidatorService(RegexDefs regex) { _rules = new List(); diff --git a/api/Hmcr.Hangfire/Startup.cs b/api/Hmcr.Hangfire/Startup.cs index 91fafe4e..c8c2a587 100644 --- a/api/Hmcr.Hangfire/Startup.cs +++ b/api/Hmcr.Hangfire/Startup.cs @@ -43,7 +43,8 @@ public void ConfigureServices(IServiceCollection services) } public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISubmissionObjectJobService jobService, - IServiceScopeFactory serviceScopeFactory, IServiceAreaService svcAreaService, ICodeLookupRepository codeLookupRepo, IFieldValidatorService validator) + IServiceScopeFactory serviceScopeFactory, IServiceAreaService svcAreaService, ICodeLookupRepository codeLookupRepo, + IActivityRuleRepository activityRuleRepo, IFieldValidatorService validator) { if (env.IsDevelopment()) { @@ -67,6 +68,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ISubmiss //Inject Code Lookup validator.CodeLookup = codeLookupRepo.LoadCodeLookupCache(); + validator.ActivityCodeRuleLookup = activityRuleRepo.LoadActivityCodeRuleCache(); minutes = Configuration.GetValue("Hangfire:EmailJobIntervalInMinutes"); minutes = minutes < 1 ? 30 : minutes; diff --git a/api/Hmcr.Model/Constants.cs b/api/Hmcr.Model/Constants.cs index c1c33f29..3627133f 100644 --- a/api/Hmcr.Model/Constants.cs +++ b/api/Hmcr.Model/Constants.cs @@ -322,6 +322,36 @@ public static class FeatureType public const string PointLine = "Point/Line"; } + public static class ActivityRuleType + { + public const string RoadLength = "ROAD_LENGTH"; + public const string SurfaceType = "SURFACE_TYPE"; + public const string RoadClass = "ROAD_CLASS"; + } + + public static class SurfaceTypeRules + { + public const string NA = "NOT_APPLICABLE"; + public const string PavedStructure = "GPS_PAVED_STRUCTURE"; + public const string PavedSurface = "GPS_PAVED_SURFACE"; + public const string NonPavedSurface = "GPS_NON_PAVED_SURFACE"; + public const string Unconstructed = "GPS_NOT_UNCONSTRUCTED"; + } + + public static class RoadSurface + { + public const string HOT_MIX = "1"; + public const string COLD_MIX = "2"; + public const string CONCRETE = "3"; + public const string SURFACE_TREATED = "4"; + public const string GRAVEL = "5"; + public const string DIRT = "6"; + public const string CLEARED = "E"; + public const string UNCLEARED = "F"; + public const string OTHER = "7"; + public const string UNKNOWN = "Z"; + } + /// /// Spatial Data /// None - Non-Location specific reporting Fields diff --git a/api/Hmcr.Model/Dtos/ActivityCodeRule/ActivityCodeRuleCache.cs b/api/Hmcr.Model/Dtos/ActivityCodeRule/ActivityCodeRuleCache.cs new file mode 100644 index 00000000..4daf4077 --- /dev/null +++ b/api/Hmcr.Model/Dtos/ActivityCodeRule/ActivityCodeRuleCache.cs @@ -0,0 +1,16 @@ +using System; +using System.Text.Json.Serialization; + +namespace Hmcr.Model.Dtos.ActivityRule +{ + public class ActivityCodeRuleCache + { + [JsonPropertyName("id")] + public decimal ActivityCodeRuleId { get; set; } + [JsonPropertyName("name")] + public string ActivityRuleSet { get; set; } + public string ActivityRuleName { get; set; } + public string ActivityRuleExecName { get; set; } + + } +} \ No newline at end of file From e27a0ddd70682fa8f41a56928227becf97831f57 Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Wed, 21 Oct 2020 14:37:32 -0700 Subject: [PATCH 39/46] Added GetInventoryAssocWithWorkActivity query to CHRIS templates, this is used to get MC and Surface Type (possibly others). Created InventoryAPI CHRIS calls to get Surface Type data Setup SurfaceType validation in WorkReportJobService --- .../ChrisServiceCollectionExtensions.cs | 12 + api/Hmcr.Chris/InventoryApi.cs | 85 ++++++ api/Hmcr.Chris/InventoryQueries.cs | 30 ++ api/Hmcr.Chris/Models/Property.cs | 2 + api/Hmcr.Chris/Models/SurfaceType.cs | 31 ++ .../GetInventoryAssocWithWorkActivity.xml | 14 + .../Hangfire/WorkReportJobService.cs | 284 +++++++++++++++++- api/Hmcr.Domain/Services/SpatialService.cs | 26 +- .../ActivityCode/ActivityCodeValidationDto.cs | 24 ++ .../Dtos/WorkReport/WorkReportCsvDto.cs | 6 +- .../Dtos/WorkReport/WorkReportRoadFeature.cs | 18 ++ .../Dtos/WorkReport/WorkReportTyped.cs | 10 +- 12 files changed, 532 insertions(+), 10 deletions(-) create mode 100644 api/Hmcr.Chris/InventoryApi.cs create mode 100644 api/Hmcr.Chris/InventoryQueries.cs create mode 100644 api/Hmcr.Chris/Models/SurfaceType.cs create mode 100644 api/Hmcr.Chris/XmlTemplates/GetInventoryAssocWithWorkActivity.xml create mode 100644 api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeValidationDto.cs create mode 100644 api/Hmcr.Model/Dtos/WorkReport/WorkReportRoadFeature.cs diff --git a/api/Hmcr.Chris/ChrisServiceCollectionExtensions.cs b/api/Hmcr.Chris/ChrisServiceCollectionExtensions.cs index 84363d34..359a8768 100644 --- a/api/Hmcr.Chris/ChrisServiceCollectionExtensions.cs +++ b/api/Hmcr.Chris/ChrisServiceCollectionExtensions.cs @@ -41,6 +41,18 @@ public static void AddChrisHttpClient(this IServiceCollection services, IConfigu client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuth); }); + services.AddHttpClient(client => + { + client.BaseAddress = new Uri(config.GetValue("CHRIS:OASUrl")); + client.Timeout = new TimeSpan(0, 0, 15); + client.DefaultRequestHeaders.Clear(); + + var userId = config.GetValue("ServiceAccount:User"); + var password = config.GetValue("ServiceAccount:Password"); + var basicAuth = Convert.ToBase64String(Encoding.GetEncoding("ISO-8859-1").GetBytes($"{userId}:{password}")); + client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", basicAuth); + }); + services.AddScoped(); } } diff --git a/api/Hmcr.Chris/InventoryApi.cs b/api/Hmcr.Chris/InventoryApi.cs new file mode 100644 index 00000000..3f971dfb --- /dev/null +++ b/api/Hmcr.Chris/InventoryApi.cs @@ -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> GetSurfaceTypeAssociatedWithLine(string lineStringCoordinates); + Task 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; + + /// + /// Chris Query typeName values, used to call the Get Inventory + /// Assoc with Work Activity Query. + /// + 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("CHRIS:OASPath"); + } + + public async Task 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>(contents); + + SurfaceType surfaceType = new SurfaceType(); + if (results.features.Length > 0) + { + surfaceType.Type = results.features[0].properties.SURFACE_TYPE; + } + + return surfaceType; + } + + public async Task> 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>(contents); + + var surfaceTypes = new List(); + + 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; + } + } +} diff --git a/api/Hmcr.Chris/InventoryQueries.cs b/api/Hmcr.Chris/InventoryQueries.cs new file mode 100644 index 00000000..f4f0ebf2 --- /dev/null +++ b/api/Hmcr.Chris/InventoryQueries.cs @@ -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, "GetSurfaceTypeAssocWithLine.xml"))); + } + } + + public string SurfaceTypeAssocWithPointQuery + { + get + { + var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "XmlTemplates"); + return _surfaceTypeAssocWithPointQuery ?? (_surfaceTypeAssocWithPointQuery = File.ReadAllText(Path.Combine(folder, "GetSurfaceTypeAssocWithPoint.xml"))); + } + } + + } +} diff --git a/api/Hmcr.Chris/Models/Property.cs b/api/Hmcr.Chris/Models/Property.cs index 2c1a8556..e5dc0b39 100644 --- a/api/Hmcr.Chris/Models/Property.cs +++ b/api/Hmcr.Chris/Models/Property.cs @@ -7,5 +7,7 @@ public class Property public string NE_DESCR { get; set; } public float MEASURE { get; set; } public double POINT_VARIANCE { get; set; } + public string SURFACE_TYPE { get; set; } + public double CLIPPED_LENGTH_KM { get; set; } } } diff --git a/api/Hmcr.Chris/Models/SurfaceType.cs b/api/Hmcr.Chris/Models/SurfaceType.cs new file mode 100644 index 00000000..3d4f8ba9 --- /dev/null +++ b/api/Hmcr.Chris/Models/SurfaceType.cs @@ -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; } + /// + /// Length in Meters + /// + public double Length { get; set; } + + public string Type { get; set; } + + } + public class SurfaceType + { + + public Geometry geometry { get; set; } + /// + /// Length in Meters + /// + public double Length { get; set; } + + public string Type { get; set; } + + } +} diff --git a/api/Hmcr.Chris/XmlTemplates/GetInventoryAssocWithWorkActivity.xml b/api/Hmcr.Chris/XmlTemplates/GetInventoryAssocWithWorkActivity.xml new file mode 100644 index 00000000..72be03d3 --- /dev/null +++ b/api/Hmcr.Chris/XmlTemplates/GetInventoryAssocWithWorkActivity.xml @@ -0,0 +1,14 @@ + + + \ No newline at end of file diff --git a/api/Hmcr.Domain/Hangfire/WorkReportJobService.cs b/api/Hmcr.Domain/Hangfire/WorkReportJobService.cs index f3d561bc..1125054b 100644 --- a/api/Hmcr.Domain/Hangfire/WorkReportJobService.cs +++ b/api/Hmcr.Domain/Hangfire/WorkReportJobService.cs @@ -94,14 +94,15 @@ public override async Task ProcessSubmission(SubmissionDto submissionDto) continue; } - untypedRow.FeatureType = activityCode.FeatureType ?? FeatureType.None; - untypedRow.SpThresholdLevel = activityCode.SpThresholdLevel; - + //set activity code rules and location code + SetActivityCodeRulesIntoUntypedRow(untypedRow, activityCode); + //this also sets RowType (D2, D3, D4) var entityName = GetValidationEntityName(untypedRow, activityCode); _validator.Validate(entityName, untypedRow, errors); - + + //stage 2 validation PerformFieldValidation(errors, untypedRow, activityCode); if (errors.Count > 0) @@ -128,6 +129,7 @@ public override async Task ProcessSubmission(SubmissionDto submissionDto) CopyCalculatedFieldsFormUntypedRow(typedRows, untypedRows); + //stage 3 validation? PerformAdditionalValidation(typedRows); } @@ -137,6 +139,8 @@ public override async Task ProcessSubmission(SubmissionDto submissionDto) return true; } + //stage 4 validation starts + var workReports = PerformSpatialValidationAndConversionBatchAsync(typedRows); _logger.LogInformation($"{_methodLogHeader} PerformSpatialValidationAndConversionAsync 100%"); @@ -147,7 +151,17 @@ public override async Task ProcessSubmission(SubmissionDto submissionDto) return true; } + //perform surfacetype lookup and validation + workReports = PerformSurfaceTypeValidationBatchAsync(workReports); + + if (_submission.SubmissionStatusId != _statusService.FileInProgress) + { + await CommitAndSendEmailAsync(); + return true; + } + _submission.SubmissionStatusId = _statusService.FileSuccess; + //stage 4 validation ends await foreach (var entity in _workReportRepo.SaveWorkReportAsnyc(_submission, workReports)) { } @@ -156,6 +170,236 @@ public override async Task ProcessSubmission(SubmissionDto submissionDto) return true; } + private List PerformSurfaceTypeValidationBatchAsync(List workReports) + { + MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader, $"Total Record: {workReports.Count}"); + + //get surface type not applicable id + var notApplicableSurfaceTypeId = _validator.ActivityCodeRuleLookup + .Where(x => x.ActivityRuleSet == ActivityRuleType.SurfaceType) + .Where(x => x.ActivityRuleExecName == SurfaceTypeRules.NA) + .FirstOrDefault().ActivityCodeRuleId; + + //grouping the rows + var groups = new List>(); + var currentGroup = new List(); + + var count = 0; + foreach (var workReport in workReports) + { + currentGroup.Add(workReport); + count++; + + if (count % 10 == 0) + { + groups.Add(currentGroup); + currentGroup = new List(); + } + } + + if (currentGroup.Count > 0) + { + groups.Add(currentGroup); + } + + var updatedWorkReports = new ConcurrentBag(); + var progress = 0; + + foreach (var group in groups) + { + var tasklist = new List(); + + //don't batch if not location code C + foreach (var row in group.Where(x => x.WorkReportTyped.ActivityCodeValidation.LocationCode == "C")) + { + if (row.WorkReportTyped.ActivityCodeValidation.SurfaceTypeRuleId != notApplicableSurfaceTypeId) + { + tasklist.Add(Task.Run(async () => updatedWorkReports.Add(await PerformSurfaceTypeValidationAsync(row)))); + } + } + + Task.WaitAll(tasklist.ToArray()); + + progress += 10; + + if (progress % 500 == 0) + { + _logger.LogInformation($"{_methodLogHeader} PerformSurfaceTypeValidationAsync {progress}"); + } + } + + return updatedWorkReports.ToList(); + } + + private async Task PerformSurfaceTypeValidationAsync(WorkReportGeometry row) + { + var errors = new Dictionary>(); + var typedRow = row.WorkReportTyped; + var geometry = row.Geometry; + var submissionRow = _submissionRows[(decimal)typedRow.RowNum]; + typedRow.RoadFeatures = new List(); + + //build Geometry linestring + var geometryLineString = ""; + foreach (Coordinate coordinate in geometry.Coordinates) + { + geometryLineString += coordinate.X + "\\," + coordinate.Y; + geometryLineString += (coordinate != geometry.Coordinates.Last()) ? "\\," : ""; + } + + //surface type calls are different between Point & Line + if (typedRow.FeatureType == FeatureType.Point) + { + var result = await _spatialService.GetSurfaceTypeAssocWithPointAsync(geometryLineString); + + if (result.result == SpValidationResult.Fail) + { + SetErrorDetail(submissionRow, errors, _statusService.FileLocationError); + } + else if (result.result == SpValidationResult.Success) + { + if (result.surfaceType.Type != null) //only add if type was returned + { + typedRow.RoadFeatures.Add(new WorkReportRoadFeature(result.surfaceType.Type, result.surfaceType.Length)); + } + + PerformSurfaceTypeValidation(typedRow); + } + } + else if (typedRow.FeatureType == FeatureType.Line) + { + var result = await _spatialService.GetSurfaceTypeAssocWithLineAsync(geometryLineString); + + if (result.result == SpValidationResult.Fail) + { + SetErrorDetail(submissionRow, errors, _statusService.FileLocationError); + } + else if (result.result == SpValidationResult.Success) + { + var distinctTypes = result.surfaceTypes.Select(x => x.Type).Distinct().ToList(); + foreach (string type in distinctTypes) + { + var totalLengthOfType = result.surfaceTypes.Where(x => x.Type == type).Sum(x => x.Length); + typedRow.RoadFeatures.Add(new WorkReportRoadFeature(type, totalLengthOfType)); + } + + PerformSurfaceTypeValidation(typedRow); + } + } + + + return row; + } + + private void PerformSurfaceTypeValidation(WorkReportTyped typedRow) + { + //get total length of path + var totalLength = typedRow.RoadFeatures.Sum(x => x.SurfaceLength); + + //determine path length; paved, non-paved, unconstructed, other + var pavedLength = typedRow.RoadFeatures.Where(x => x.SurfaceType == RoadSurface.HOT_MIX || + x.SurfaceType == RoadSurface.COLD_MIX || x.SurfaceType == RoadSurface.CONCRETE || + x.SurfaceType == RoadSurface.SURFACE_TREATED).Sum(x => x.SurfaceLength); + + var unpavedLength = typedRow.RoadFeatures.Where(x => x.SurfaceType == RoadSurface.GRAVEL || + x.SurfaceType == RoadSurface.DIRT).Sum(x => x.SurfaceLength); + + var unconstructedLength = typedRow.RoadFeatures.Where(x => x.SurfaceType == RoadSurface.CLEARED || + x.SurfaceType == RoadSurface.UNCLEARED).Sum(x => x.SurfaceLength); + + var otherLength = typedRow.RoadFeatures.Where(x => x.SurfaceType == RoadSurface.OTHER || + x.SurfaceType == RoadSurface.UNKNOWN).Sum(x => x.SurfaceLength); + + var surfaceTypeRule = typedRow.ActivityCodeValidation.SurfaceTypeRuleExec; + + if (typedRow.FeatureType == FeatureType.Line) { + switch (surfaceTypeRule) + { + case SurfaceTypeRules.PavedSurface: + case SurfaceTypeRules.PavedStructure: + if ((pavedLength / totalLength) >= .8) + { + //nothing wrong + } + else + { + if (surfaceTypeRule == SurfaceTypeRules.PavedStructure) + { + //structure checking + } + else if (surfaceTypeRule == SurfaceTypeRules.PavedSurface) + { + //warning + } + } + + break; + case SurfaceTypeRules.NonPavedSurface: + if ((unpavedLength / totalLength) >= .8) + { + //nothing wrong + } + else + { + //warning + } + + break; + case SurfaceTypeRules.Unconstructed: + if ((unconstructedLength / totalLength) >= .2) + { + //warning + } + + break; + } + + } else if (typedRow.FeatureType == FeatureType.Point) + { + switch (surfaceTypeRule) + { + case SurfaceTypeRules.PavedSurface: + case SurfaceTypeRules.PavedStructure: + if (pavedLength > 0) + { + //nothign wrong + } + else + { + if (unpavedLength > 0 && surfaceTypeRule == SurfaceTypeRules.PavedStructure) + { + //structure checking + } + else if (unpavedLength > 0 && surfaceTypeRule == SurfaceTypeRules.PavedSurface) + { + //warning! + } + } + + break; + case SurfaceTypeRules.NonPavedSurface: + if (unpavedLength > 0) + { + //nothing wrong + } + else if (pavedLength > 0) + { + //warning? + } + + break; + case SurfaceTypeRules.Unconstructed: + if (unconstructedLength > 0) + { + //warning + } + + break; + } + } + + } + private void PerformFieldValidation(Dictionary> errors, WorkReportCsvDto untypedRow, ActivityCodeDto activityCode) { if (activityCode.LocationCode.LocationCode == "C" && activityCode.ActivityNumber.StartsWith('6')) @@ -257,9 +501,41 @@ private void CopyCalculatedFieldsFormUntypedRow(List typedRows, typedRow.SpatialData = untypedRow.SpatialData; typedRow.RowId = untypedRow.RowId; typedRow.SpThresholdLevel = untypedRow.SpThresholdLevel; + + //move activity rules and location code from untyped to typed + typedRow.ActivityCodeValidation.LocationCode = untypedRow.ActivityCodeValidation.LocationCode; + typedRow.ActivityCodeValidation.RoadLengthRuleId = untypedRow.ActivityCodeValidation.RoadLengthRuleId; + typedRow.ActivityCodeValidation.RoadLenghRuleExec = untypedRow.ActivityCodeValidation.RoadLenghRuleExec; + typedRow.ActivityCodeValidation.SurfaceTypeRuleId = untypedRow.ActivityCodeValidation.SurfaceTypeRuleId; + typedRow.ActivityCodeValidation.SurfaceTypeRuleExec = untypedRow.ActivityCodeValidation.SurfaceTypeRuleExec; + typedRow.ActivityCodeValidation.RoadClassRuleId = untypedRow.ActivityCodeValidation.RoadClassRuleId; + typedRow.ActivityCodeValidation.RoadClassRuleExec = untypedRow.ActivityCodeValidation.RoadClassRuleExec; } } + private void SetActivityCodeRulesIntoUntypedRow(WorkReportCsvDto untypedRow, ActivityCodeDto activityCode) + { + untypedRow.FeatureType = activityCode.FeatureType ?? FeatureType.None; + untypedRow.SpThresholdLevel = activityCode.SpThresholdLevel; + //set activity code rules and location code + untypedRow.ActivityCodeValidation.LocationCode = activityCode.LocationCode.LocationCode; + + untypedRow.ActivityCodeValidation.RoadLengthRuleId = activityCode.RoadLengthRule; + untypedRow.ActivityCodeValidation.RoadLenghRuleExec = _validator.ActivityCodeRuleLookup + .Where(x => x.ActivityCodeRuleId == activityCode.RoadLengthRule) + .FirstOrDefault().ActivityRuleExecName; + + untypedRow.ActivityCodeValidation.SurfaceTypeRuleId = activityCode.SurfaceTypeRule; + untypedRow.ActivityCodeValidation.SurfaceTypeRuleExec = _validator.ActivityCodeRuleLookup + .Where(x => x.ActivityCodeRuleId == activityCode.SurfaceTypeRule) + .FirstOrDefault().ActivityRuleExecName; + + untypedRow.ActivityCodeValidation.RoadClassRuleId = activityCode.RoadClassRule; + untypedRow.ActivityCodeValidation.RoadClassRuleExec = _validator.ActivityCodeRuleLookup + .Where(x => x.ActivityCodeRuleId == activityCode.RoadClassRule) + .FirstOrDefault().ActivityRuleExecName; + } + private List PerformSpatialValidationAndConversionBatchAsync(List typedRows) { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader, $"Total Record: {typedRows.Count}"); diff --git a/api/Hmcr.Domain/Services/SpatialService.cs b/api/Hmcr.Domain/Services/SpatialService.cs index a41ac296..9fce8afa 100644 --- a/api/Hmcr.Domain/Services/SpatialService.cs +++ b/api/Hmcr.Domain/Services/SpatialService.cs @@ -19,11 +19,14 @@ public interface ISpatialService (decimal offset, string rfiSegment, string rfiSegmentName, string thresholdLevel, Dictionary> errors); Task<(SpValidationResult result, decimal snappedStartOffset, decimal snappedEndOffset, Point startPoint, Point endPoint, List lines, RfiSegment rfiSegment)> ValidateLrsLineAsync(decimal startOffset, decimal endOffset, string rfiSegment, string rfiSegmentName, string thresholdLevel, Dictionary> errors); + Task<(SpValidationResult result, List surfaceTypes)> GetSurfaceTypeAssocWithLineAsync(string geometryLineString); + Task<(SpValidationResult result, SurfaceType surfaceType)> GetSurfaceTypeAssocWithPointAsync(string geometryLineString); } public class SpatialService : ISpatialService { private IOasApi _oasApi; + private IInventoryApi _inventoryApi; private IFieldValidatorService _validator; private ILookupCodeService _lookupService; @@ -31,11 +34,12 @@ public class SpatialService : ISpatialService private IEnumerable _nonSpHighwayUniques = null; private IEnumerable NonSpHighwayUniques => _nonSpHighwayUniques ??= _validator.CodeLookup.Where(x => x.CodeSet == CodeSet.NonSpHighwayUnique).Select(x => x.CodeValue).ToArray().ToLowercase(); - public SpatialService(IOasApi oasApi, IFieldValidatorService validator, ILookupCodeService lookupService) + public SpatialService(IOasApi oasApi, IFieldValidatorService validator, ILookupCodeService lookupService, IInventoryApi inventoryApi) { _oasApi = oasApi; _validator = validator; _lookupService = lookupService; + _inventoryApi = inventoryApi; } public async Task<(SpValidationResult result, LrsPointResult lrsResult, RfiSegment rfiSegment)> ValidateGpsPointAsync @@ -158,7 +162,7 @@ public SpatialService(IOasApi oasApi, IFieldValidatorService validator, ILookupC return (SpValidationResult.Success, snappedOffset, point, rfiResult.segment); } - public async Task<(SpValidationResult result, decimal snappedStartOffset, decimal snappedEndOffset, Point startPoint, Point endPoint, List lines, RfiSegment rfiSegment)> + public async Task<(SpValidationResult result, decimal snappedStartOffset, decimal snappedEndOffset, Point startPoint, Point endPoint, List lines, RfiSegment rfiSegment)> ValidateLrsLineAsync(decimal startOffset, decimal endOffset, string rfiSegment, string rfiSegmentName, string thresholdLevel, Dictionary> errors) { var snappedStartOffset = startOffset; @@ -175,7 +179,7 @@ public SpatialService(IOasApi oasApi, IFieldValidatorService validator, ILookupC { return (SpValidationResult.Fail, rfiResult.segment.Length, rfiResult.segment.Length, null, null, null, rfiResult.segment); } - snappedStartOffset = startTolCheck.snappedOffset; + snappedStartOffset = startTolCheck.snappedOffset; //Get point by snappedStartOffset. Otherwise, it will raise an exception when the offset is greater than length of the road var startPoint = await _oasApi.GetPointFromOffsetMeasureOnRfiSegmentAsync(rfiSegment, snappedStartOffset); @@ -241,6 +245,20 @@ public SpatialService(IOasApi oasApi, IFieldValidatorService validator, ILookupC return (SpValidationResult.Success, rfiDetail); } + public async Task<(SpValidationResult result, List surfaceTypes)> GetSurfaceTypeAssocWithLineAsync(string geometryLineString) + { + var surfaceTypes = await _inventoryApi.GetSurfaceTypeAssociatedWithLine(geometryLineString); + + return (SpValidationResult.Success, surfaceTypes); + } + + public async Task<(SpValidationResult result, SurfaceType surfaceType)> GetSurfaceTypeAssocWithPointAsync(string geometryLineString) + { + var surfaceType = await _inventoryApi.GetSurfaceTypeAssociatedWithPoint(geometryLineString); + + return (SpValidationResult.Success, surfaceType); + } + private (bool withinTolerance, decimal snappedOffset) GetSnappedOffset(RfiSegment segment, decimal offset, string rfiSegment, string rfiSegmentName, string thresholdLevel, Dictionary> errors) { @@ -250,7 +268,7 @@ public SpatialService(IOasApi oasApi, IFieldValidatorService validator, ILookupC { var threshold = _lookupService.GetThresholdLevel(thresholdLevel); - if (segment.Length + threshold.Error / 1000M < offset) + if (segment.Length + threshold.Error / 1000M < offset) { errors.AddItem($"Offset", $"Offset [{offset}] is not on the {rfiSegmentName} [{rfiSegment}] within the tolerance [{threshold.Error}] metres"); return (false, snappedOffset); diff --git a/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeValidationDto.cs b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeValidationDto.cs new file mode 100644 index 00000000..f2d2d950 --- /dev/null +++ b/api/Hmcr.Model/Dtos/ActivityCode/ActivityCodeValidationDto.cs @@ -0,0 +1,24 @@ +using Hmcr.Model.Dtos.LocationCode; +using System; +using System.Collections.Generic; +using System.Text.Json.Serialization; + +namespace Hmcr.Model.Dtos.ActivityCode +{ + public class ActivityCodeValidationDto + { + public string LocationCode { get; set; } + + public decimal RoadLengthRuleId { get; set; } + public string RoadLenghRuleExec { get; set; } + public decimal SurfaceTypeRuleId { get; set; } + public string SurfaceTypeRuleExec { get; set; } + public decimal RoadClassRuleId { get; set; } + public string RoadClassRuleExec { get; set; } + public virtual IList ServiceAreaNumbers { get; set; } + + public decimal? MinimumValue { get; set; } + public decimal? MaximumValue { get; set; } + public decimal? ReportingFrequency { get; set; } + } +} diff --git a/api/Hmcr.Model/Dtos/WorkReport/WorkReportCsvDto.cs b/api/Hmcr.Model/Dtos/WorkReport/WorkReportCsvDto.cs index ab6513f4..0a9931d8 100644 --- a/api/Hmcr.Model/Dtos/WorkReport/WorkReportCsvDto.cs +++ b/api/Hmcr.Model/Dtos/WorkReport/WorkReportCsvDto.cs @@ -1,4 +1,5 @@ -using System; +using Hmcr.Model.Dtos.ActivityCode; +using System; namespace Hmcr.Model.Dtos.WorkReport { @@ -43,5 +44,8 @@ public class WorkReportCsvDto : IReportCsvDto /// public SpatialData SpatialData { get; set; } public string SpThresholdLevel { get; set; } + + public ActivityCodeValidationDto ActivityCodeValidation { get; set; } + } } diff --git a/api/Hmcr.Model/Dtos/WorkReport/WorkReportRoadFeature.cs b/api/Hmcr.Model/Dtos/WorkReport/WorkReportRoadFeature.cs new file mode 100644 index 00000000..b6962876 --- /dev/null +++ b/api/Hmcr.Model/Dtos/WorkReport/WorkReportRoadFeature.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Hmcr.Model.Dtos.WorkReport +{ + public class WorkReportRoadFeature + { + public string SurfaceType { get; set; } + public double SurfaceLength { get; set; } + + public WorkReportRoadFeature(string surfaceType, double surfaceLength) + { + SurfaceType = surfaceType; + SurfaceLength = surfaceLength; + } + } +} \ No newline at end of file diff --git a/api/Hmcr.Model/Dtos/WorkReport/WorkReportTyped.cs b/api/Hmcr.Model/Dtos/WorkReport/WorkReportTyped.cs index 3a891b6e..b9457473 100644 --- a/api/Hmcr.Model/Dtos/WorkReport/WorkReportTyped.cs +++ b/api/Hmcr.Model/Dtos/WorkReport/WorkReportTyped.cs @@ -1,4 +1,6 @@ -using System; +using Hmcr.Model.Dtos.ActivityCode; +using System; +using System.Collections.Generic; namespace Hmcr.Model.Dtos.WorkReport { @@ -50,5 +52,11 @@ public class WorkReportTyped /// public SpatialData SpatialData { get; set; } public string SpThresholdLevel { get; set; } + + /// + /// Road feature data retrieved from CHRIS + /// + public virtual IList RoadFeatures { get; set; } + public ActivityCodeValidationDto ActivityCodeValidation { get; set; } } } From b19157b824330aea07d425f94c632f04d8c160a9 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Wed, 21 Oct 2020 14:48:04 -0700 Subject: [PATCH 40/46] removed space --- client/src/scss/_forms.scss | 2 -- 1 file changed, 2 deletions(-) diff --git a/client/src/scss/_forms.scss b/client/src/scss/_forms.scss index 0289a6d0..533d2d1e 100644 --- a/client/src/scss/_forms.scss +++ b/client/src/scss/_forms.scss @@ -73,8 +73,6 @@ background-clip: padding-box; border: 1px solid rgba(0,0,0,.2); box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 1px 2px rgba(0,0,0,.24); - - } .fieldset-tooltip> div.show { From 2abc9099fee70a745dc04763e227db11d1884316 Mon Sep 17 00:00:00 2001 From: "CORP\\wanwilso" Date: Wed, 21 Oct 2020 17:02:06 -0700 Subject: [PATCH 41/46] Fixed delete for activitycode --- api/Hmcr.Data/Repositories/ActivityCodeRepository.cs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs index 78ab887a..7c182cc1 100644 --- a/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs +++ b/api/Hmcr.Data/Repositories/ActivityCodeRepository.cs @@ -169,8 +169,13 @@ public async Task UpdateActivityCodeAsync(ActivityCodeUpdateDto activityCode) public async Task DeleteActivityCodeAsync(decimal id) { var activityCodeEntity = await DbSet + .Include(x => x.HmrServiceAreaActivities) .FirstAsync(ac => ac.ActivityCodeId == id); + foreach( var areaToDelete in activityCodeEntity.HmrServiceAreaActivities) + { DbContext.Remove(areaToDelete); + } + DbSet.Remove(activityCodeEntity); } From 6d537041f60b6dc364bfa89d5a2242f5022b020f Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Thu, 22 Oct 2020 16:48:38 -0700 Subject: [PATCH 42/46] Renamed ErrorDetail to MessageDetail in order to genericize the object for Warnings or Errors (or future types!) Modified existing warning system for GPS variance warning to use new object rather than parameterized string Set warnings for surface type rules as per business rules --- .../ChrisServiceCollectionExtensions.cs | 2 +- .../Hangfire/Base/ReportJobServiceBase.cs | 44 ++++++++++++++++++- .../Hangfire/WorkReportJobService.cs | 20 ++++++--- api/Hmcr.Model/EmailBody.cs | 2 +- api/Hmcr.Model/FieldMessage.cs | 3 ++ .../{ErrorDetail.cs => MessageDetail.cs} | 22 ++++++---- api/Hmcr.Model/Utils/StringExtensions.cs | 8 +++- 7 files changed, 80 insertions(+), 21 deletions(-) rename api/Hmcr.Model/{ErrorDetail.cs => MessageDetail.cs} (55%) diff --git a/api/Hmcr.Chris/ChrisServiceCollectionExtensions.cs b/api/Hmcr.Chris/ChrisServiceCollectionExtensions.cs index 359a8768..7b18c49d 100644 --- a/api/Hmcr.Chris/ChrisServiceCollectionExtensions.cs +++ b/api/Hmcr.Chris/ChrisServiceCollectionExtensions.cs @@ -44,7 +44,7 @@ public static void AddChrisHttpClient(this IServiceCollection services, IConfigu services.AddHttpClient(client => { client.BaseAddress = new Uri(config.GetValue("CHRIS:OASUrl")); - client.Timeout = new TimeSpan(0, 0, 15); + client.Timeout = new TimeSpan(0, 0, 45); client.DefaultRequestHeaders.Clear(); var userId = config.GetValue("ServiceAccount:User"); diff --git a/api/Hmcr.Domain/Hangfire/Base/ReportJobServiceBase.cs b/api/Hmcr.Domain/Hangfire/Base/ReportJobServiceBase.cs index 50488f22..3fff3a36 100644 --- a/api/Hmcr.Domain/Hangfire/Base/ReportJobServiceBase.cs +++ b/api/Hmcr.Domain/Hangfire/Base/ReportJobServiceBase.cs @@ -162,6 +162,36 @@ protected void SetErrorDetail(HmrSubmissionRow submissionRow, Dictionary> warnings) + { + //warning can only be set for a row + if (submissionRow != null) + { + if (submissionRow.WarningDetail != null) + { + var newWarnings = System.Text.Json.JsonSerializer.Deserialize(submissionRow.WarningDetail); + foreach (var warning in warnings) + { + newWarnings.FieldMessages.Add(new FieldMessage + { + Field = warning.Key.WordToWords(), + Messages = warning.Value + }); + } + submissionRow.WarningDetail = newWarnings.ToString(); + } else + { + //we need to check for + submissionRow.RowStatusId = _statusService.RowError; + submissionRow.WarningDetail = warnings.GetWarningDetail(); + } + + + + + } + } + protected async Task CommitAndSendEmailAsync() { MethodLogger.LogEntry(_logger, _enableMethodLog, _methodLogHeader); @@ -217,6 +247,7 @@ protected decimal GetRowNum(string row) protected void SetVarianceWarningDetail(HmrSubmissionRow row, string rfiSegment, string start, string end, string thresholdLevel) { + var warnings = new Dictionary>(); var threshold = _lookupService.GetThresholdLevel(thresholdLevel); var threasholdInKm = threshold.Warning / 1000M; @@ -225,11 +256,20 @@ protected void SetVarianceWarningDetail(HmrSubmissionRow row, string rfiSegment, if (row.StartVariance != null && row.StartVariance > threasholdInKm) { - row.WarningDetail = string.Format(RowWarning.VarianceWarning, "Start", start, rfiSegment, threshold.Warning); + //row.WarningDetail = string.Format(RowWarning.VarianceWarning, "Start", start, rfiSegment, threshold.Warning); + warnings.AddItem("Start GPS Variance", string.Format("{0} {1} is is not on the Highway Unique [{2}] within the warning threshold [{3}] metres", + "Start", start, rfiSegment, threshold.Warning)); } else if (row.EndVariance != null && row.EndVariance > threasholdInKm) { - row.WarningDetail = string.Format(RowWarning.VarianceWarning, "End", end, rfiSegment, threshold.Warning); + //row.WarningDetail = string.Format(RowWarning.VarianceWarning, "End", end, rfiSegment, threshold.Warning); + warnings.AddItem("End GPS Variance", string.Format("{0} {1} is is not on the Highway Unique [{2}] within the warning threshold [{3}] metres", + "End", end, rfiSegment, threshold.Warning)); + } + + if (warnings.Count > 0) + { + SetWarningDetail(row, warnings); } } diff --git a/api/Hmcr.Domain/Hangfire/WorkReportJobService.cs b/api/Hmcr.Domain/Hangfire/WorkReportJobService.cs index 1125054b..5f21999d 100644 --- a/api/Hmcr.Domain/Hangfire/WorkReportJobService.cs +++ b/api/Hmcr.Domain/Hangfire/WorkReportJobService.cs @@ -287,12 +287,14 @@ private async Task PerformSurfaceTypeValidationAsync(WorkRep } } - return row; } private void PerformSurfaceTypeValidation(WorkReportTyped typedRow) { + var warnings = new Dictionary>(); + var submissionRow = _submissionRows[(decimal)typedRow.RowNum]; + //get total length of path var totalLength = typedRow.RoadFeatures.Sum(x => x.SurfaceLength); @@ -329,7 +331,7 @@ private void PerformSurfaceTypeValidation(WorkReportTyped typedRow) } else if (surfaceTypeRule == SurfaceTypeRules.PavedSurface) { - //warning + warnings.AddItem("Surface Type Validation", $"Rule is {SurfaceTypeRules.PavedSurface} on Line and paved surface less than 80%"); } } @@ -341,14 +343,14 @@ private void PerformSurfaceTypeValidation(WorkReportTyped typedRow) } else { - //warning + warnings.AddItem("Surface Type Validation", $"Rule is {SurfaceTypeRules.NonPavedSurface} on Line and unpaved surface less than 80%"); } break; case SurfaceTypeRules.Unconstructed: if ((unconstructedLength / totalLength) >= .2) { - //warning + warnings.AddItem("Surface Type Validation", $"Rule is {SurfaceTypeRules.Unconstructed} on Line and unconstructed surface is more than 20%"); } break; @@ -372,7 +374,7 @@ private void PerformSurfaceTypeValidation(WorkReportTyped typedRow) } else if (unpavedLength > 0 && surfaceTypeRule == SurfaceTypeRules.PavedSurface) { - //warning! + warnings.AddItem("Surface Type Validation", $"Rule is {SurfaceTypeRules.NonPavedSurface}, unpaved surface found on Point"); } } @@ -384,20 +386,24 @@ private void PerformSurfaceTypeValidation(WorkReportTyped typedRow) } else if (pavedLength > 0) { - //warning? + warnings.AddItem("Surface Type Validation", $"Rule is {SurfaceTypeRules.NonPavedSurface}, paved surface found on Point"); } break; case SurfaceTypeRules.Unconstructed: if (unconstructedLength > 0) { - //warning + warnings.AddItem("Surface Type Validation", $"Rule is {SurfaceTypeRules.Unconstructed}, unconstructed surface found on Point"); } break; } } + if (warnings.Count > 0) + { + SetWarningDetail(submissionRow, warnings); + } } private void PerformFieldValidation(Dictionary> errors, WorkReportCsvDto untypedRow, ActivityCodeDto activityCode) diff --git a/api/Hmcr.Model/EmailBody.cs b/api/Hmcr.Model/EmailBody.cs index 01d5fce3..38c14dee 100644 --- a/api/Hmcr.Model/EmailBody.cs +++ b/api/Hmcr.Model/EmailBody.cs @@ -51,7 +51,7 @@ private string SetHtmlBody(bool success, bool isFileError = false, string errorD else if (isFileError && !string.IsNullOrEmpty(errorDetailJson)) { - var errorDetail = JsonSerializer.Deserialize(errorDetailJson, _jsonOptions); + var errorDetail = JsonSerializer.Deserialize(errorDetailJson, _jsonOptions); htmlBody.Append("
                        • Status Detail
                        • "); diff --git a/api/Hmcr.Model/FieldMessage.cs b/api/Hmcr.Model/FieldMessage.cs index 813cc899..35e132e4 100644 --- a/api/Hmcr.Model/FieldMessage.cs +++ b/api/Hmcr.Model/FieldMessage.cs @@ -1,12 +1,15 @@ using System; using System.Collections.Generic; using System.Text; +using System.Text.Json.Serialization; namespace Hmcr.Model { public class FieldMessage { + [JsonPropertyName("field")] public string Field { get; set; } + [JsonPropertyName("messages")] public List Messages { get; set; } } } diff --git a/api/Hmcr.Model/ErrorDetail.cs b/api/Hmcr.Model/MessageDetail.cs similarity index 55% rename from api/Hmcr.Model/ErrorDetail.cs rename to api/Hmcr.Model/MessageDetail.cs index 3e05bba9..c56d5256 100644 --- a/api/Hmcr.Model/ErrorDetail.cs +++ b/api/Hmcr.Model/MessageDetail.cs @@ -1,37 +1,41 @@ using Hmcr.Model.Utils; using System.Collections.Generic; using System.Text.Json; +using System.Text.Json.Serialization; namespace Hmcr.Model { - public class ErrorDetail + + public class MessageDetail { private static JsonSerializerOptions _jsonOptions = new JsonSerializerOptions { WriteIndented = false, PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; + [JsonPropertyName("fieldMessages")] public List FieldMessages { get; set; } - - public ErrorDetail() + + public MessageDetail() { - + FieldMessages = new List(); } - public ErrorDetail(Dictionary> errors) + public MessageDetail(Dictionary> messages) { FieldMessages = new List(); - foreach (var error in errors) + foreach (var message in messages) { FieldMessages.Add(new FieldMessage { - Field = error.Key.WordToWords(), - Messages = error.Value + Field = message.Key.WordToWords(), + Messages = message.Value }); } } public override string ToString() { - return JsonSerializer.Serialize(this, _jsonOptions); + return JsonSerializer.Serialize(this, _jsonOptions); } + } } diff --git a/api/Hmcr.Model/Utils/StringExtensions.cs b/api/Hmcr.Model/Utils/StringExtensions.cs index d63f1b77..3804ede8 100644 --- a/api/Hmcr.Model/Utils/StringExtensions.cs +++ b/api/Hmcr.Model/Utils/StringExtensions.cs @@ -89,10 +89,16 @@ public static void AddItem(this Dictionary> dictionary, str public static string GetErrorDetail(this Dictionary> errors) { - var fileErrorDetail = new ErrorDetail(errors); + var fileErrorDetail = new MessageDetail(errors); return fileErrorDetail.ToString(); } + public static string GetWarningDetail(this Dictionary> warnings) + { + var fileWarningDetail = new MessageDetail(warnings); + return fileWarningDetail.ToString(); + } + public static bool IsIdirUser(this string str) { return str.ToUpperInvariant() == UserTypeDto.INTERNAL; From e145df3386613b2a66e060b7a62f0acd4d74485a Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Mon, 26 Oct 2020 08:01:27 -0700 Subject: [PATCH 43/46] Change to XML query filename --- api/Hmcr.Chris/InventoryQueries.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/api/Hmcr.Chris/InventoryQueries.cs b/api/Hmcr.Chris/InventoryQueries.cs index f4f0ebf2..d4015b52 100644 --- a/api/Hmcr.Chris/InventoryQueries.cs +++ b/api/Hmcr.Chris/InventoryQueries.cs @@ -13,7 +13,7 @@ public string SurfaceTypeAssocWithLineQuery get { var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "XmlTemplates"); - return _surfaceTypeAssocWithLineQuery ?? (_surfaceTypeAssocWithLineQuery = File.ReadAllText(Path.Combine(folder, "GetSurfaceTypeAssocWithLine.xml"))); + return _surfaceTypeAssocWithLineQuery ?? (_surfaceTypeAssocWithLineQuery = File.ReadAllText(Path.Combine(folder, "GetInventoryAssocWithWorkActivity.xml"))); } } @@ -22,7 +22,7 @@ public string SurfaceTypeAssocWithPointQuery get { var folder = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().Location), "XmlTemplates"); - return _surfaceTypeAssocWithPointQuery ?? (_surfaceTypeAssocWithPointQuery = File.ReadAllText(Path.Combine(folder, "GetSurfaceTypeAssocWithPoint.xml"))); + return _surfaceTypeAssocWithPointQuery ?? (_surfaceTypeAssocWithPointQuery = File.ReadAllText(Path.Combine(folder, "GetInventoryAssocWithWorkActivity.xml"))); } } From 4ef6fe99942f68c1b32eff2d58e7c5fde2354e8f Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Mon, 26 Oct 2020 10:24:27 -0700 Subject: [PATCH 44/46] updated project file to move Chris XML file --- api/Hmcr.Chris/Hmcr.Chris.csproj | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/api/Hmcr.Chris/Hmcr.Chris.csproj b/api/Hmcr.Chris/Hmcr.Chris.csproj index cb61ee16..f257989a 100644 --- a/api/Hmcr.Chris/Hmcr.Chris.csproj +++ b/api/Hmcr.Chris/Hmcr.Chris.csproj @@ -7,6 +7,7 @@ + @@ -16,6 +17,9 @@ Always + + Always + From ccf06e694d6a4456bb9fbdba49e94f99ef18ea97 Mon Sep 17 00:00:00 2001 From: Darrel Siegle Date: Mon, 26 Oct 2020 14:08:20 -0700 Subject: [PATCH 45/46] Updated script to set Create/Update User information on Insert. --- .../2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql b/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql index 07f37b3e..63d3ded9 100644 --- a/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql +++ b/database/V25.0/2_HMR_PDM-dml_SERVICE_AREA_ACTIVITY_V25_IS2.2.sql @@ -14,9 +14,17 @@ USE HMR_DEV; -- uncomment appropriate instance GO INSERT INTO [dbo].[HMR_SERVICE_AREA_ACTIVITY] - (ACTIVITY_CODE_ID, SERVICE_AREA_NUMBER) + (ACTIVITY_CODE_ID, SERVICE_AREA_NUMBER, APP_CREATE_USERID, APP_CREATE_TIMESTAMP, APP_CREATE_USER_GUID, APP_CREATE_USER_DIRECTORY, APP_LAST_UPDATE_USERID, APP_LAST_UPDATE_TIMESTAMP, APP_LAST_UPDATE_USER_GUID, APP_LAST_UPDATE_USER_DIRECTORY) SELECT ACT.ACTIVITY_CODE_ID , SVC.SERVICE_AREA_NUMBER + , 'sa' + , getutcdate() + , '00000001-0000-0000-0000-000000000000' + , 'WIN AUTH' + , 'sa' + , getutcdate() + , '00000001-0000-0000-0000-000000000000' + , 'WIN AUTH' FROM [dbo].[HMR_ACTIVITY_CODE] ACT , (SELECT SERVICE_AREA_NUMBER FROM [dbo].[HMR_SERVICE_AREA]) SVC; From d748e7fe4e2bfa31b4f1e7a4b5ba1311fffaf204 Mon Sep 17 00:00:00 2001 From: AdvSol-Darrel <60364889+AdvSol-Darrel@users.noreply.github.com> Date: Wed, 28 Oct 2020 08:32:03 -0700 Subject: [PATCH 46/46] tweak maxvalue >0 (was >=0) (#514) * merge * tweak maxvalue >0 (was >=0) Co-authored-by: CORP\wanwilso --- client/src/js/components/forms/EditActivityFormFields.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/src/js/components/forms/EditActivityFormFields.js b/client/src/js/components/forms/EditActivityFormFields.js index 5e9d1939..b9311f92 100644 --- a/client/src/js/components/forms/EditActivityFormFields.js +++ b/client/src/js/components/forms/EditActivityFormFields.js @@ -137,7 +137,6 @@ const validationSchema = Yup.object({ if(isValueEmpty(originalValue.replace(/,/g, ''))) return null; return Number(originalValue.replace(/,/g, '')); }) - .min(0,'Must be greater than or equal to 0') .nullable() .typeError('Must be number') .test( @@ -147,6 +146,13 @@ const validationSchema = Yup.object({ { return true; } + if(Number(this.parent.maxValue) <=0) + { + return this.createError({ + message: 'Must be greater than 0', + path: 'maxValue', + }); + } if(Number(this.parent.maxValue) > 999999999.99) { return this.createError({ @@ -161,6 +167,7 @@ const validationSchema = Yup.object({ path: 'maxValue', }); } + if (isValueNotEmpty(this.parent.minValue)) { if(Number(this.parent.maxValue) !== 0 && this.parent.maxValue < this.parent.minValue)