/
validate.go
76 lines (62 loc) · 2.27 KB
/
validate.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package validate
import (
"errors"
"github.com/andreluzz/cas-xog/constant"
"github.com/andreluzz/cas-xog/model"
"github.com/beevik/etree"
)
//Check verify the xog response output looking for errors and warnings
func Check(xog *etree.Document) (model.Output, error) {
errorOutput := model.Output{Code: constant.OutputError, Debug: ""}
warningOutput := model.Output{Code: constant.OutputWarning, Debug: ""}
if xog == nil {
errorOutput.Debug = "invalid xog"
return errorOutput, errors.New(errorOutput.Debug)
}
output := xog.FindElement("//XOGOutput")
if output == nil {
errorOutput.Debug = "no output tag defined"
return errorOutput, errors.New(errorOutput.Debug)
}
statusElement := output.FindElement("Status")
if statusElement == nil {
errorOutput.Debug = "no status tag defined"
return errorOutput, errors.New(errorOutput.Debug)
}
errorInformationElement := output.FindElement("//ErrorInformation")
if errorInformationElement != nil {
desc := ""
severityElement := errorInformationElement.FindElement("Severity")
descriptionElement := errorInformationElement.FindElement("Description")
if descriptionElement != nil {
desc = descriptionElement.Text()
}
if severityElement != nil {
if severityElement.Text() == "WARNING" {
warningOutput.Debug = desc
return warningOutput, nil
}
errorOutput.Debug = desc
return errorOutput, errors.New(errorOutput.Debug)
}
}
statisticsElement := output.FindElement("Statistics")
if statisticsElement != nil {
statTotalNumberOfRecords := statisticsElement.SelectAttrValue("totalNumberOfRecords", "0")
if statTotalNumberOfRecords == "0" {
errorOutput.Debug = "output statistics totalNumberOfRecords = 0"
return errorOutput, errors.New(errorOutput.Debug)
}
statFailureRecords := statisticsElement.SelectAttrValue("failureRecords", "0")
if statFailureRecords != "0" {
errorOutput.Debug = "output statistics failure on " + statFailureRecords + " records out of " + statTotalNumberOfRecords
return errorOutput, errors.New(errorOutput.Debug)
}
}
elapsedTime := statusElement.SelectAttrValue("elapsedTime", constant.Undefined)
debug := ""
if elapsedTime != constant.Undefined {
debug = "| Elapsed time: " + elapsedTime
}
return model.Output{Code: constant.OutputSuccess, Debug: debug}, nil
}