Skip to content

Commit 7daf3d7

Browse files
hukhoJiviteshT
authored andcommitted
Process AIO weeks to increment and update file names (#251)
* Allow week number to be adjusted on calculation * Update year / week calculations * Update editorconfig * Rework week number calculations * Pass week number details through code * Calculate week number up front * Rename * Small fix * Update AIO file names * Test update * Revert spacing * Set weeks to increment value * Update tests to match new file names * Update functional tests and stub * Fix for week numbers in testing * Reinstate accidentally removed code * Further fix * And another fix * Add parameter to functional tests
1 parent e88743d commit 7daf3d7

File tree

29 files changed

+710
-508
lines changed

29 files changed

+710
-508
lines changed

.editorconfig

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,33 @@ trim_trailing_whitespace = true
1515
# Generated code
1616
[*{_AssemblyInfo.cs,.notsupported.cs,AsmOffsets.cs}]
1717
generated_code = true
18+
dotnet_style_operator_placement_when_wrapping = beginning_of_line
19+
tab_width = 4
20+
end_of_line = crlf
21+
dotnet_style_coalesce_expression = true:suggestion
22+
dotnet_style_null_propagation = true:suggestion
23+
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:suggestion
24+
dotnet_style_prefer_auto_properties = true:suggestion
25+
dotnet_style_object_initializer = true:suggestion
26+
dotnet_style_collection_initializer = true:suggestion
27+
dotnet_style_prefer_simplified_boolean_expressions = true:suggestion
28+
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
29+
dotnet_style_prefer_conditional_expression_over_return = true:silent
30+
dotnet_style_explicit_tuple_names = true:suggestion
31+
dotnet_style_prefer_inferred_tuple_names = true:suggestion
32+
dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
33+
dotnet_style_prefer_compound_assignment = true:suggestion
34+
dotnet_style_prefer_simplified_interpolation = true:suggestion
35+
dotnet_style_prefer_collection_expression = when_types_exactly_match:suggestion
36+
dotnet_style_namespace_match_folder = true:suggestion
37+
dotnet_style_readonly_field = true:suggestion
38+
39+
# JSON files
40+
[*.json]
41+
insert_final_newline = true
42+
indent_style = space
43+
indent_size = 2
44+
trim_trailing_whitespace = true
1845

1946
# C# files
2047
[*.cs]
@@ -31,12 +58,12 @@ csharp_new_line_between_query_expression_clauses = true
3158
csharp_indent_block_contents = true
3259
csharp_indent_braces = false
3360
csharp_indent_case_contents = true
34-
csharp_indent_case_contents_when_block = true
61+
csharp_indent_case_contents_when_block = false
3562
csharp_indent_switch_labels = true
3663
csharp_indent_labels = one_less_than_current
3764

3865
# Modifier preferences
39-
csharp_preferred_modifier_order = public,private,protected,internal,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,volatile,async:suggestion
66+
csharp_preferred_modifier_order = public,private,protected,internal,file,static,extern,new,virtual,abstract,sealed,override,readonly,unsafe,required,volatile,async:suggestion
4067

4168
# avoid this. unless absolutely necessary
4269
dotnet_style_qualification_for_field = false:suggestion
@@ -45,24 +72,24 @@ dotnet_style_qualification_for_method = false:suggestion
4572
dotnet_style_qualification_for_event = false:suggestion
4673

4774
# Types: use keywords instead of BCL types, and permit var only when the type is clear
48-
csharp_style_var_for_built_in_types = false:suggestion
49-
csharp_style_var_when_type_is_apparent = false:none
50-
csharp_style_var_elsewhere = false:suggestion
75+
csharp_style_var_for_built_in_types = true:suggestion
76+
csharp_style_var_when_type_is_apparent = true:suggestion
77+
csharp_style_var_elsewhere = true:suggestion
5178
dotnet_style_predefined_type_for_locals_parameters_members = true:suggestion
5279
dotnet_style_predefined_type_for_member_access = true:suggestion
5380

5481
# name all constant fields using PascalCase
5582
dotnet_naming_rule.constant_fields_should_be_pascal_case.severity = suggestion
5683
dotnet_naming_rule.constant_fields_should_be_pascal_case.symbols = constant_fields
57-
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
84+
dotnet_naming_rule.constant_fields_should_be_pascal_case.style = pascal_case_style
5885
dotnet_naming_symbols.constant_fields.applicable_kinds = field
5986
dotnet_naming_symbols.constant_fields.required_modifiers = const
6087
dotnet_naming_style.pascal_case_style.capitalization = pascal_case
6188

6289
# static fields should have s_ prefix
6390
dotnet_naming_rule.static_fields_should_have_prefix.severity = suggestion
6491
dotnet_naming_rule.static_fields_should_have_prefix.symbols = static_fields
65-
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
92+
dotnet_naming_rule.static_fields_should_have_prefix.style = static_prefix_style
6693
dotnet_naming_symbols.static_fields.applicable_kinds = field
6794
dotnet_naming_symbols.static_fields.required_modifiers = static
6895
dotnet_naming_symbols.static_fields.applicable_accessibilities = private, internal, private_protected
@@ -72,7 +99,7 @@ dotnet_naming_style.static_prefix_style.capitalization = camel_case
7299
# internal and private fields should be _camelCase
73100
dotnet_naming_rule.camel_case_for_private_internal_fields.severity = suggestion
74101
dotnet_naming_rule.camel_case_for_private_internal_fields.symbols = private_internal_fields
75-
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
102+
dotnet_naming_rule.camel_case_for_private_internal_fields.style = camel_case_underscore_style
76103
dotnet_naming_symbols.private_internal_fields.applicable_kinds = field
77104
dotnet_naming_symbols.private_internal_fields.applicable_accessibilities = private, internal
78105
dotnet_naming_style.camel_case_underscore_style.required_prefix = _
@@ -88,10 +115,21 @@ csharp_prefer_static_local_function = true:suggestion
88115
csharp_prefer_simple_using_statement = false:none
89116
csharp_style_prefer_switch_expression = true:suggestion
90117
dotnet_style_readonly_field = true:suggestion
118+
csharp_style_namespace_declarations = block_scoped:silent
119+
csharp_style_prefer_method_group_conversion = true:silent
120+
csharp_style_prefer_top_level_statements = true:silent
121+
csharp_style_prefer_primary_constructors = true:suggestion
122+
csharp_style_prefer_null_check_over_type_check = true:suggestion
123+
csharp_style_prefer_local_over_anonymous_function = true:suggestion
124+
csharp_style_implicit_object_creation_when_type_is_apparent = true:suggestion
125+
csharp_style_prefer_tuple_swap = true:suggestion
126+
csharp_style_deconstructed_variable_declaration = true:suggestion
127+
csharp_prefer_system_threading_lock = true:suggestion
91128

92129
# Expression-level preferences
93130
dotnet_style_object_initializer = true:suggestion
94131
dotnet_style_collection_initializer = true:suggestion
132+
dotnet_style_prefer_collection_expression = when_types_exactly_match
95133
dotnet_style_explicit_tuple_names = true:suggestion
96134
dotnet_style_coalesce_expression = true:suggestion
97135
dotnet_style_null_propagation = true:suggestion

UKHO.FmEssFssMock.API/UKHO.FmEssFssMock.API/Common/FileShareServiceConfiguration.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ public class FileShareServiceConfiguration
55
public string FssDataDirectoryPath { get; set; }
66
public string FssInfoResponseFileName { get; set; }
77
public string FssSingleReadMeResponseFileName { get; set; }
8-
public string FssMultipleReadMeResponseFileName { get; set; }
8+
public string FssMultipleReadMeResponseFileName { get; set; }
9+
public int WeeksToIncrement { get; set; }
910
}
1011
}

UKHO.FmEssFssMock.API/UKHO.FmEssFssMock.API/Services/FileShareService.cs

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ namespace UKHO.FmEssFssMock.API.Services
1010
public class FileShareService
1111
{
1212
private readonly IOptions<FileShareServiceConfiguration> fssConfiguration;
13-
private readonly string aioInfoFilesBatchId = "649C902D-5282-4CCF-924A-2B548EF42179";
13+
private readonly string aioInfoFilesBatchId = "649C902D-5282-4CCF-924A-2B548EF42179";
1414
private readonly Dictionary<string, string> mimeTypes = new()
1515
{
1616
{ ".zip", "application/zip" },
@@ -61,26 +61,39 @@ public BatchResponse CreateBatch(IEnumerable<KeyValuePair<string, string>> attri
6161
return new BatchResponse() { BatchId = Guid.Parse(batchId) };
6262
}
6363

64+
private (string CurrentWeek, string CurrentYear) GetWeekNumber(bool isAioBatchType)
65+
{
66+
var now = isAioBatchType ? DateTime.UtcNow.AddDays(fssConfiguration.Value.WeeksToIncrement * 7) : DateTime.UtcNow;
67+
var currentWeek = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(now, CalendarWeekRule.FirstFullWeek, DayOfWeek.Thursday);
68+
var currentYear = now.Year;
69+
70+
if (currentWeek > 5 && now.Month < 2)
71+
{
72+
currentYear--;
73+
}
74+
75+
return (currentWeek.ToString("00"), currentYear.ToString("0000"));
76+
}
77+
6478
public BatchDetail GetBatchDetails(string batchId, string homeDirectoryPath)
6579
{
6680
batchId = batchId.ToLower();
67-
CultureInfo cultureInfo = CultureInfo.InvariantCulture;
68-
string currentWeek = CultureInfo.InvariantCulture.Calendar.GetWeekOfYear(DateTime.UtcNow, CalendarWeekRule.FirstFullWeek, DayOfWeek.Thursday).ToString().PadLeft(2, '0');
69-
string currentYear = DateTime.UtcNow.Year.ToString();
70-
string path = Path.Combine(homeDirectoryPath, batchId);
71-
string businessUnit = "AVCSData";
72-
List<BatchFile> files = new();
73-
74-
foreach (string? filePath in Directory.GetFiles(path))
81+
var isAioBatchType = aioBatchTypes.Contains(EnumHelper.GetValueFromDescription<Batch>(batchId));
82+
(var currentWeek, var currentYear) = GetWeekNumber(isAioBatchType);
83+
var path = Path.Combine(homeDirectoryPath, batchId);
84+
var businessUnit = "AVCSData";
85+
List<BatchFile> files = [];
86+
87+
foreach (var filePath in Directory.GetFiles(path))
7588
{
76-
FileInfo fileInfo = new(filePath);
89+
var fileInfo = new FileInfo(filePath);
7790

78-
files.Add(new BatchFile()
91+
files.Add(new BatchFile
7992
{
8093
Attributes = new List<Models.Response.Attribute>
8194
{
82-
new Models.Response.Attribute { Key = "Product Type", Value = aioBatchTypes.Contains(EnumHelper.GetValueFromDescription<Batch>(batchId)) ? "AIO" : "AVCS" },
83-
new Models.Response.Attribute { Key = "File Name", Value = fileInfo.Name }
95+
new() { Key = "Product Type", Value = isAioBatchType ? "AIO" : "AVCS" },
96+
new() { Key = "File Name", Value = fileInfo.Name }
8497
},
8598
MimeType = mimeTypes.ContainsKey(fileInfo.Extension.ToLower()) ? mimeTypes[fileInfo.Extension.ToLower()] : DEFAULTMIMETYPE,
8699
FileSize = fileInfo.Length,
@@ -138,7 +151,7 @@ public BatchDetail GetBatchDetails(string batchId, string homeDirectoryPath)
138151

139152
List<KeyValuePair<string, string>> attributes = new()
140153
{
141-
new("Product Type", aioBatchTypes.Contains(EnumHelper.GetValueFromDescription<Batch>(batchId)) ? "AIO" : "AVCS"),
154+
new("Product Type", isAioBatchType ? "AIO" : "AVCS"),
142155
new("Week Number", currentWeek),
143156
new("Year", currentYear),
144157
new("Year / Week", currentYear + " / " + currentWeek), };

UKHO.FmEssFssMock.API/UKHO.FmEssFssMock.API/UKHO.FmEssFssMock.API.csproj

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<None Update="Data\10D40DD5-DDFB-497A-BB67-D99FB1658320\distributors.zip">
6161
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6262
</None>
63-
<None Update="Data\15B38135-AA92-4D1A-9B6B-846462A18362\AIO_S63_WK34_22_Only.zip">
63+
<None Update="Data\15B38135-AA92-4D1A-9B6B-846462A18362\AIO_Update_WK34_22_Only.zip">
6464
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
6565
</None>
6666
<None Update="Data\27067A02-DF4B-49A1-8699-442B265A75D2\V01X01.zip">
@@ -156,13 +156,13 @@
156156
<None Update="Data\D2B46C4F-415A-4CA3-B844-6577254F39E5\CommitInProgress.txt">
157157
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
158158
</None>
159-
<None Update="Data\EB74B68E-95A7-4D3B-A162-1444EFE43257\AIO_S631-1_CD_WK34_22.iso">
159+
<None Update="Data\EB74B68E-95A7-4D3B-A162-1444EFE43257\AIO_CD_WK34_22.iso">
160160
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
161161
</None>
162-
<None Update="Data\EB74B68E-95A7-4D3B-A162-1444EFE43257\AIO_S631-1_CD_WK34_22.iso.sha1">
162+
<None Update="Data\EB74B68E-95A7-4D3B-A162-1444EFE43257\AIO_CD_WK34_22.iso.sha1">
163163
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
164164
</None>
165-
<None Update="Data\EB74B68E-95A7-4D3B-A162-1444EFE43257\AIO_S631-1_CD_WK34_22.zip">
165+
<None Update="Data\EB74B68E-95A7-4D3B-A162-1444EFE43257\AIO_CD_WK34_22.zip">
166166
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
167167
</None>
168168
<None Update="Data\F8FD2FB4-3DD6-425D-B34F-3059E262FEED\V01X01.zip">
Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,40 @@
11
{
2-
"Logging": {
3-
"LogLevel": {
4-
"Default": "Information",
5-
"Microsoft.AspNetCore": "Warning"
6-
}
7-
},
8-
"AllowedHosts": "*",
9-
"FleetManagerB2BApiConfiguration": {
10-
"UserName": "",
11-
"Password": "",
12-
"SubscriptionKey": "",
13-
"GetCatalogueResponseFilePath": "FM\\avcs_catalogue_ft.xml"
14-
},
15-
"ExchangeSetServiceConfiguration": {
16-
"EssDataDirectoryPath": "Data\\ESS\\",
17-
"PostProductIdentifiersResponseFileName": "ESSResponse.json"
18-
},
19-
"FileShareServiceConfiguration": {
20-
"FssDataDirectoryPath": "Data\\FSS\\",
21-
"FssInfoResponseFileName": "FssInfoResponse.json",
22-
"FssSingleReadMeResponseFileName": "FssSingleReadMeResponse.json",
23-
"FssMultipleReadMeResponseFileName": "FssMultipleFilesReadMeResponse.json"
24-
},
25-
"IsFTRunning": true,
26-
"POSFolderName": "POS",
27-
"BessStorageConfiguration": {
28-
"ConnectionString": "",
29-
"ContainerName": "bess-configs-ft"
30-
},
31-
"SharedKeyConfiguration": {
32-
"Key": ""
33-
},
34-
"SalesCatalogue": {
35-
"FileDirectoryPath": "Data\\SalesCatalogueService\\",
36-
"ScsResponseFile": "SCSResponse.json",
37-
"ScsCatalogueResponseFile": "SCSCatalogueResponse.json"
2+
"Logging": {
3+
"LogLevel": {
4+
"Default": "Information",
5+
"Microsoft.AspNetCore": "Warning"
386
}
7+
},
8+
"AllowedHosts": "*",
9+
"FleetManagerB2BApiConfiguration": {
10+
"UserName": "",
11+
"Password": "",
12+
"SubscriptionKey": "",
13+
"GetCatalogueResponseFilePath": "FM\\avcs_catalogue_ft.xml"
14+
},
15+
"ExchangeSetServiceConfiguration": {
16+
"EssDataDirectoryPath": "Data\\ESS\\",
17+
"PostProductIdentifiersResponseFileName": "ESSResponse.json"
18+
},
19+
"FileShareServiceConfiguration": {
20+
"FssDataDirectoryPath": "Data\\FSS\\",
21+
"FssInfoResponseFileName": "FssInfoResponse.json",
22+
"FssSingleReadMeResponseFileName": "FssSingleReadMeResponse.json",
23+
"FssMultipleReadMeResponseFileName": "FssMultipleFilesReadMeResponse.json",
24+
"WeeksToIncrement": 1
25+
},
26+
"IsFTRunning": true,
27+
"POSFolderName": "POS",
28+
"BessStorageConfiguration": {
29+
"ConnectionString": "",
30+
"ContainerName": "bess-configs-ft"
31+
},
32+
"SharedKeyConfiguration": {
33+
"Key": ""
34+
},
35+
"SalesCatalogue": {
36+
"FileDirectoryPath": "Data\\SalesCatalogueService\\",
37+
"ScsResponseFile": "SCSResponse.json",
38+
"ScsCatalogueResponseFile": "SCSCatalogueResponse.json"
39+
}
3940
}

0 commit comments

Comments
 (0)