From 084a00ae6513ca62b5980d8df237b1cf375034af Mon Sep 17 00:00:00 2001 From: Nick Nicholas Date: Thu, 16 Feb 2017 15:06:04 +1100 Subject: [PATCH] master --- app/napval/napval.go | 3 ++- app/napval/validator_test.go | 17 +++++++------ lib/config.go | 38 ++++++++++++++++++++++++++++ napval/validation_config.go | 35 +++---------------------- napval/validation_distributor.go | 2 +- napval/validation_server.go | 2 +- napval/validation_serviceregister.go | 2 +- xml/registrationrecord.go | 25 +++++------------- 8 files changed, 63 insertions(+), 61 deletions(-) create mode 100644 lib/config.go diff --git a/app/napval/napval.go b/app/napval/napval.go index f20eaec..f7aa39e 100644 --- a/app/napval/napval.go +++ b/app/napval/napval.go @@ -2,6 +2,7 @@ package main import ( + "github.com/nsip/nias2/lib" "github.com/nsip/nias2/napval" "log" "runtime" @@ -9,7 +10,7 @@ import ( func main() { - config := lib.LoadNAPLANConfig() + config := napval.LoadNAPLANConfig() NAPLAN_NATS_CFG := lib.NATSConfig{Port: config.NATSPort} log.Println("NAPVAL: Loading default config") log.Println("NAPVAL: Config values are: ", config) diff --git a/app/napval/validator_test.go b/app/napval/validator_test.go index 94eb963..1135960 100644 --- a/app/napval/validator_test.go +++ b/app/napval/validator_test.go @@ -3,7 +3,7 @@ package main import ( "bytes" "encoding/json" - "log" + //"log" "net/url" "os" "path" @@ -11,7 +11,7 @@ import ( "testing" "time" - Nias2 "github.com/nsip/nias2/lib" + "github.com/nsip/nias2/napval" "menteslibres.net/gosexy/rest" ) @@ -375,11 +375,12 @@ func test_harness(t *testing.T, filename string, errfield string, errdescription err = json.Unmarshal(lines[0], &dat) } errcheck(t, err) - // we are getting back a JSON array - for i := 0; i < len(lines); i++ { - log.Println("\t" + string(lines[i])) - } - log.Println(dat) + /* + // we are getting back a JSON array + for i := 0; i < len(lines); i++ { + log.Println("\t" + string(lines[i])) + log.Println(dat) + */ if errfield == "" { if len(dat) > 0 { t.Fatalf("Expected no error, got error in %s: %s", dat["errfield"], dat["description"]) @@ -399,7 +400,7 @@ func test_harness(t *testing.T, filename string, errfield string, errdescription } func TestMain(m *testing.M) { - config := Nias2.LoadNAPLANConfig() + config := napval.LoadNAPLANConfig() customClient, _ = rest.New("http://localhost:" + config.WebServerPort + "/") os.Exit(m.Run()) } diff --git a/lib/config.go b/lib/config.go new file mode 100644 index 0000000..b8d2430 --- /dev/null +++ b/lib/config.go @@ -0,0 +1,38 @@ +// configmanager.go +package lib + +import ( + "github.com/BurntSushi/toml" + "log" +) + +// utility object to manage configurable parameters + +type NIASConfig struct { + TestYear string + WebServerPort string + NATSPort string + ValidationRoute []string + SSFRoute []string + SMSRoute []string + PoolSize int // number of service processors + MsgTransport string + TxReportInterval int // progress report after every n records + UIMessageLimit int //how many messages to send to web ui + TxStorageLimit int + Loaded bool +} + +var defaultConfig NIASConfig = NIASConfig{} + +func LoadDefaultConfig() NIASConfig { + if !defaultConfig.Loaded { + ncfg := NIASConfig{} + if _, err := toml.DecodeFile("nias.toml", &ncfg); err != nil { + log.Fatalln("Unable to read default config, aborting.", err) + } + defaultConfig = ncfg + defaultConfig.Loaded = true + } + return defaultConfig +} diff --git a/napval/validation_config.go b/napval/validation_config.go index 7298693..d1a8907 100644 --- a/napval/validation_config.go +++ b/napval/validation_config.go @@ -3,32 +3,17 @@ package napval import ( "github.com/BurntSushi/toml" + "github.com/nsip/nias2/lib" "log" ) // utility object to manage configurable parameters -type NIASConfig struct { - TestYear string - WebServerPort string - NATSPort string - ValidationRoute []string - SSFRoute []string - SMSRoute []string - PoolSize int // number of service processors - MsgTransport string - TxReportInterval int // progress report after every n records - UIMessageLimit int //how many messages to send to web ui - TxStorageLimit int - Loaded bool -} - -var defaultConfig NIASConfig = NIASConfig{} -var nAPLANConfig NIASConfig = NIASConfig{} +var nAPLANConfig lib.NIASConfig = lib.NIASConfig{} -func LoadNAPLANConfig() NIASConfig { +func LoadNAPLANConfig() lib.NIASConfig { if !nAPLANConfig.Loaded { - ncfg := NIASConfig{} + ncfg := lib.NIASConfig{} if _, err := toml.DecodeFile("napval.toml", &ncfg); err != nil { log.Fatalln("Unable to read NAPLAN config, aborting.", err) } @@ -37,15 +22,3 @@ func LoadNAPLANConfig() NIASConfig { } return nAPLANConfig } - -func LoadDefaultConfig() NIASConfig { - if !defaultConfig.Loaded { - ncfg := NIASConfig{} - if _, err := toml.DecodeFile("nias.toml", &ncfg); err != nil { - log.Fatalln("Unable to read default config, aborting.", err) - } - defaultConfig = ncfg - defaultConfig.Loaded = true - } - return defaultConfig -} diff --git a/napval/validation_distributor.go b/napval/validation_distributor.go index b451a17..2e44466 100644 --- a/napval/validation_distributor.go +++ b/napval/validation_distributor.go @@ -20,7 +20,7 @@ type ValidationDistributor struct{} // services in parallel func (vd *ValidationDistributor) Run(poolsize int, nats_cfg lib.NATSConfig) { - config := lib.LoadNAPLANConfig() + config := LoadNAPLANConfig() ec := lib.CreateNATSConnection(nats_cfg) vs := NewValidationStore() tt := lib.NewTransactionTracker(config.TxReportInterval, nats_cfg) diff --git a/napval/validation_server.go b/napval/validation_server.go index 94ff34a..c1c7399 100644 --- a/napval/validation_server.go +++ b/napval/validation_server.go @@ -29,7 +29,7 @@ import ( //"time" ) -var naplanconfig = lib.LoadNAPLANConfig() +var naplanconfig = LoadNAPLANConfig() var VALIDATION_ROUTE = naplanconfig.ValidationRoute var req_ec *nats.EncodedConn diff --git a/napval/validation_serviceregister.go b/napval/validation_serviceregister.go index 312daee..517b439 100644 --- a/napval/validation_serviceregister.go +++ b/napval/validation_serviceregister.go @@ -10,7 +10,7 @@ import ( "sync" ) -var config = lib.LoadNAPLANConfig() +var config = LoadNAPLANConfig() // simple thread-safe container for group of services that will be available // to process messages passed from a distributor node diff --git a/xml/registrationrecord.go b/xml/registrationrecord.go index e5f3fb1..a4856a2 100644 --- a/xml/registrationrecord.go +++ b/xml/registrationrecord.go @@ -4,6 +4,7 @@ import ( "encoding/gob" "encoding/xml" "github.com/nsip/nias2/go_SifMessage" + "strings" ) func init() { @@ -90,18 +91,6 @@ type RegistrationRecord struct { YearLevel string `json:",omitempty" xml:"MostRecent>YearLevel>Code"` } -// convenience method to return otherid by type -func (r RegistrationRecord) GetOtherId(idtype string) string { - - for _, id := range r.OtherIdList.OtherId { - if id.Type == idtype { - return id.Value - } - } - - return idtype -} - // Flatten out Other IDs from XML into JSON/CSV flat structure func (r *RegistrationRecord) Flatten() RegistrationRecord { for _, id := range r.OtherIdList.OtherId { @@ -111,8 +100,8 @@ func (r *RegistrationRecord) Flatten() RegistrationRecord { if id.Type == "NationalStudentId" { r.NationalId = id.Value } - if id.Type == "OtherStudentId" { - r.OtherStudentId = id.Value + if id.Type == "OtherId" { + r.OtherId = id.Value } if id.Type == "NAPPlatformStudentId" { r.PlatformId = id.Value @@ -126,7 +115,7 @@ func (r *RegistrationRecord) Flatten() RegistrationRecord { if id.Type == "PreviousNationalStudentId" { r.PreviousNationalId = id.Value } - if id.Type == "PreviousOtherStudentId" { + if id.Type == "PreviousOtherId" { r.PreviousOtherId = id.Value } if id.Type == "PreviousNAPPlatformStudentId" { @@ -160,8 +149,8 @@ func (r *RegistrationRecord) Unflatten() RegistrationRecord { if r.NationalId != "" { r.OtherIdList.OtherId = append(r.OtherIdList.OtherId, XMLAttributeStruct{"NationalStudentId", r.NationalId}) } - if r.OtherStudentId != "" { - r.OtherIdList.OtherId = append(r.OtherIdList.OtherId, XMLAttributeStruct{"OtherStudentId", r.OtherStudentId}) + if r.OtherId != "" { + r.OtherIdList.OtherId = append(r.OtherIdList.OtherId, XMLAttributeStruct{"OtherStudentId", r.OtherId}) } if r.PlatformId != "" { r.OtherIdList.OtherId = append(r.OtherIdList.OtherId, XMLAttributeStruct{"NAPPlatformStudentId", r.PlatformId}) @@ -176,7 +165,7 @@ func (r *RegistrationRecord) Unflatten() RegistrationRecord { r.OtherIdList.OtherId = append(r.OtherIdList.OtherId, XMLAttributeStruct{"PreviousNationalStudentId", r.PreviousNationalId}) } if r.PreviousOtherId != "" { - r.OtherIdList.OtherId = append(r.OtherIdList.OtherId, XMLAttributeStruct{"PreviousOtherStudentId", r.PreviousOtherId}) + r.OtherIdList.OtherId = append(r.OtherIdList.OtherId, XMLAttributeStruct{"PreviousOtherId", r.PreviousOtherId}) } if r.PreviousPlatformId != "" { r.OtherIdList.OtherId = append(r.OtherIdList.OtherId, XMLAttributeStruct{"PreviousNAPPlatformStudentId", r.PreviousPlatformId})