generated from ministryofjustice/opg-template-repository
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat/SSM-30: introduced lp1h doc parsers & types (#32)
* feat/SSM-30: introduced lp1h doc parsers & types * feat/SSM-30: refactored registry to enable better transparency on document handling. * feat/SSM-30: improved test coverage fir job queue. * feat/SSM-30: improved validation behaviours. * feat/SSM-30: added validation logic for LP1H and bug fixes. * feat/SSM-30: change name of validate section function * feat/SSM-30: naming convention change for commonValidators.
- Loading branch information
Showing
25 changed files
with
1,021 additions
and
536 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package factory | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/ministryofjustice/opg-scanning/internal/parser" | ||
"github.com/ministryofjustice/opg-scanning/internal/parser/corresp_parser" | ||
"github.com/ministryofjustice/opg-scanning/internal/parser/lp1f_parser" | ||
"github.com/ministryofjustice/opg-scanning/internal/parser/lp1h_parser" | ||
) | ||
|
||
// Component defines a registry entry for a document type. | ||
type Component struct { | ||
Parser func([]byte) (interface{}, error) | ||
Validator parser.CommonValidator | ||
Sanitizer parser.CommonSanitizer | ||
} | ||
|
||
func GetComponent(docType string) (Component, error) { | ||
switch docType { | ||
case "LP1H": | ||
return Component{ | ||
Parser: func(data []byte) (interface{}, error) { | ||
return lp1h_parser.Parse(data) | ||
}, | ||
Validator: lp1h_parser.NewValidator(), | ||
Sanitizer: lp1h_parser.NewSanitizer(), | ||
}, nil | ||
case "LP1F": | ||
return Component{ | ||
Parser: func(data []byte) (interface{}, error) { | ||
return lp1f_parser.Parse(data) | ||
}, | ||
Validator: lp1f_parser.NewValidator(), | ||
Sanitizer: lp1f_parser.NewSanitizer(), | ||
}, nil | ||
case "Correspondence": | ||
return Component{ | ||
Parser: func(data []byte) (interface{}, error) { | ||
return corresp_parser.Parse(data) | ||
}, | ||
Validator: corresp_parser.NewValidator(), | ||
Sanitizer: corresp_parser.NewSanitizer(), | ||
}, nil | ||
default: | ||
return Component{}, fmt.Errorf("unsupported docType: %s", docType) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,11 @@ | ||
package lp1f_parser | ||
|
||
import ( | ||
"encoding/xml" | ||
|
||
"github.com/ministryofjustice/opg-scanning/internal/parser" | ||
lp1f_types "github.com/ministryofjustice/opg-scanning/internal/types/lpf1_types" | ||
lp1f_types "github.com/ministryofjustice/opg-scanning/internal/types/lp1f_types" | ||
) | ||
|
||
func Parse(data []byte) (*lp1f_types.LP1FDocument, error) { | ||
func Parse(data []byte) (interface{}, error) { | ||
doc := &lp1f_types.LP1FDocument{} | ||
if err := xml.Unmarshal(data, doc); err != nil { | ||
return nil, err | ||
} | ||
|
||
// Validate required fields based on struct tags | ||
if err := parser.ValidateStruct(doc); err != nil { | ||
return nil, err | ||
} | ||
|
||
return doc, nil | ||
return parser.DocumentParser(data, doc) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.