Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SSP Section 4 Parsing & Validation #2731

Merged
merged 19 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions tdrs-backend/tdpservice/parsers/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -251,50 +251,6 @@ def manager_parse_line(line, schema_manager, generate_error, is_encrypted=False)
)
])]


def get_schema_manager_options(program_type):
"""Return the allowed schema options."""
match program_type:
case 'TAN':
return {
'A': {
'T1': schema_defs.tanf.t1,
'T2': schema_defs.tanf.t2,
'T3': schema_defs.tanf.t3,
},
'C': {
'T4': schema_defs.tanf.t4,
'T5': schema_defs.tanf.t5,
},
'G': {
'T6': schema_defs.tanf.t6,
},
'S': {
'T7': schema_defs.tanf.t7,
},
}
case 'SSP':
return {
'A': {
'M1': schema_defs.ssp.m1,
'M2': schema_defs.ssp.m2,
'M3': schema_defs.ssp.m3,
},
'C': {
# 'M4': schema_options.m4,
# 'M5': schema_options.m5,
},
'G': {
# 'M6': schema_options.m6,
},
'S': {
# 'M7': schema_options.m7,
},
}
# case tribal?
return None


def get_schema_manager(line, section, program_type):
"""Return the appropriate schema for the line."""
line_type = line[0:2]
Expand Down
188 changes: 153 additions & 35 deletions tdrs-backend/tdpservice/parsers/schema_defs/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,44 +11,162 @@
preparsing_validators=[
validators.hasLength(
23,
lambda value, length: f'Header length is {len(value)} but must be {length} characters.'
lambda value, length: f"Header length is {len(value)} but must be {length} characters.",
),
validators.startsWith('HEADER'),
validators.startsWith("HEADER"),
],
postparsing_validators=[],
fields=[
Field(item="2", name='title', type='string', startIndex=0, endIndex=6, required=True, validators=[
validators.matches('HEADER'),
]),
Field(item="4", name='year', type='number', startIndex=6, endIndex=10, required=True, validators=[
validators.isInLimits(2000, 2099)
]),
Field(item="5", name='quarter', type='string', startIndex=10, endIndex=11, required=True, validators=[
validators.oneOf(['1', '2', '3', '4'])
]),
Field(item="6", name='type', type='string', startIndex=11, endIndex=12, required=True, validators=[
validators.oneOf(['A', 'C', 'G', 'S'])
]),
Field(item="1", name='state_fips', type='string', startIndex=12, endIndex=14, required=True, validators=[
validators.oneOf(("01", "02", "04", "05", "06", "08", "09", "10", "11", "12", "13", "15", "16", "17", "18",
"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31", "32", "33",
"34", "35", "36", "37", "38", "39", "40", "41", "42", "44", "45", "46", "47", "48", "49",
"50", "51", "53", "54", "55", "56", "66", "72", "78"))
]),
Field(item="3", name='tribe_code', type='string', startIndex=14, endIndex=17, required=False, validators=[
validators.isInStringRange(0, 999)
]),
Field(item="7", name='program_type', type='string', startIndex=17, endIndex=20, required=True, validators=[
validators.oneOf(['TAN', 'SSP'])
]),
Field(item="8", name='edit', type='string', startIndex=20, endIndex=21, required=True, validators=[
validators.oneOf(['1', '2'])
]),
Field(item="9", name='encryption', type='string', startIndex=21, endIndex=22, required=False, validators=[
validators.oneOf([' ', 'E'])
]),
Field(item="10", name='update', type='string', startIndex=22, endIndex=23, required=True, validators=[
validators.oneOf(['N', 'D', 'U'])
]),
Field(
item="2",
name="title",
type="string",
startIndex=0,
endIndex=6,
required=True,
validators=[
validators.matches("HEADER"),
],
),
Field(
item="4",
name="year",
type="number",
startIndex=6,
endIndex=10,
required=True,
validators=[validators.isInLimits(2000, 2099)],
),
Field(
item="5",
name="quarter",
type="string",
startIndex=10,
endIndex=11,
required=True,
validators=[validators.oneOf(["1", "2", "3", "4"])],
),
Field(
item="6",
name="type",
type="string",
startIndex=11,
endIndex=12,
required=True,
validators=[validators.oneOf(["A", "C", "G", "S"])],
),
Field(
item="1",
name="state_fips",
type="string",
startIndex=12,
endIndex=14,
required=True,
validators=[
validators.oneOf(
(
"01",
"02",
"04",
"05",
"06",
"08",
"09",
"10",
"11",
"12",
"13",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"32",
"33",
"34",
"35",
"36",
"37",
"38",
"39",
"40",
"41",
"42",
"44",
"45",
"46",
"47",
"48",
"49",
"50",
"51",
"53",
"54",
"55",
"56",
"66",
"72",
"78",
)
)
],
),
Field(
item="3",
name="tribe_code",
type="string",
startIndex=14,
endIndex=17,
required=False,
validators=[validators.isInStringRange(0, 999)],
),
Field(
item="7",
name="program_type",
type="string",
startIndex=17,
endIndex=20,
required=True,
validators=[validators.oneOf(["TAN", "SSP"])],
),
Field(
item="8",
name="edit",
type="string",
startIndex=20,
endIndex=21,
required=True,
validators=[validators.oneOf(["1", "2"])],
),
Field(
item="9",
name="encryption",
type="string",
startIndex=21,
endIndex=22,
required=False,
validators=[validators.oneOf([" ", "E"])],
),
Field(
item="10",
name="update",
type="string",
startIndex=22,
endIndex=23,
required=True,
validators=[validators.oneOf(["N", "D", "U"])],
),
],
)
2 changes: 2 additions & 0 deletions tdrs-backend/tdpservice/parsers/schema_defs/ssp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@
from .m2 import m2
from .m3 import m3
from .m6 import m6
from .m7 import m7

m1 = m1
m2 = m2
m3 = m3
m6 = m6
m7 = m7
6 changes: 3 additions & 3 deletions tdrs-backend/tdpservice/parsers/schema_defs/ssp/m1.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from tdpservice.search_indexes.models.ssp import SSP_M1

m1 = SchemaManager(
schemas=[
schemas=[
RowSchema(
model=SSP_M1,
preparsing_validators=[
Expand Down Expand Up @@ -243,5 +243,5 @@
required=False, validators=[]),
]
)
]
)
]
)
6 changes: 3 additions & 3 deletions tdrs-backend/tdpservice/parsers/schema_defs/ssp/m2.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@


m2 = SchemaManager(
schemas=[
schemas=[
RowSchema(
model=SSP_M2,
preparsing_validators=[
Expand Down Expand Up @@ -364,5 +364,5 @@
]),
],
)
]
)
]
)
7 changes: 1 addition & 6 deletions tdrs-backend/tdpservice/parsers/schema_defs/ssp/m3.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,9 +301,4 @@
]
)

m3 = SchemaManager(
schemas=[
first_part_schema,
second_part_schema
]
)
m3 = SchemaManager(schemas=[first_part_schema, second_part_schema])
Loading
Loading