-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
5 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
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,77 @@ | ||
// numericvalidservice.go | ||
package nias2 | ||
|
||
import ( | ||
"fmt" | ||
"log" | ||
"strconv" | ||
) | ||
|
||
// numeric value validator service | ||
|
||
// implementation of the id service | ||
type NumericValidService struct { | ||
} | ||
|
||
// create a new id service instance | ||
func NewNumericValidService() (*NumericValidService, error) { | ||
num := NumericValidService{} | ||
|
||
return &num, nil | ||
} | ||
|
||
// implement the nias Service interface | ||
func (num *NumericValidService) HandleMessage(req *NiasMessage) ([]NiasMessage, error) { | ||
|
||
responses := make([]NiasMessage, 0) | ||
|
||
rr, ok := req.Body.(RegistrationRecord) | ||
if !ok { | ||
log.Println("NumericValidService received a message that is not a RegistrationRecord, ignoring") | ||
return responses, nil | ||
} | ||
|
||
fte := rr.FTE | ||
desc := "" | ||
field := "FTE" | ||
ok = true | ||
|
||
if len(fte) > 0 { | ||
fte_f, err := strconv.ParseFloat(fte, 64) | ||
if err != nil { | ||
ok = false | ||
desc = fmt.Sprintf("FTE %s is not a well formed float", fte) | ||
} else { | ||
if fte_f < 0 { | ||
ok = false | ||
desc = "FTE is less than 0" | ||
} | ||
if fte_f > 1 { | ||
ok = false | ||
desc = "FTE is greater than 1" | ||
} | ||
} | ||
} | ||
if !ok { | ||
responses = add_error(responses, desc, field, req) | ||
} | ||
|
||
return responses, nil | ||
|
||
} | ||
|
||
func add_error(responses []NiasMessage, desc string, field string, req *NiasMessage) []NiasMessage { | ||
ve := ValidationError{ | ||
Description: desc, | ||
Field: field, | ||
OriginalLine: req.SeqNo, | ||
Vtype: "date", | ||
} | ||
r := NiasMessage{} | ||
r.TxID = req.TxID | ||
r.SeqNo = req.SeqNo | ||
r.Target = VALIDATION_PREFIX | ||
r.Body = ve | ||
responses = append(responses, r) | ||
return responses | ||
} |
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