Skip to content

Commit

Permalink
master
Browse files Browse the repository at this point in the history
  • Loading branch information
opoudjis committed Feb 16, 2017
1 parent 940e688 commit 084a00a
Show file tree
Hide file tree
Showing 8 changed files with 63 additions and 61 deletions.
3 changes: 2 additions & 1 deletion app/napval/napval.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
package main

import (
"github.com/nsip/nias2/lib"
"github.com/nsip/nias2/napval"
"log"
"runtime"
)

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)
Expand Down
17 changes: 9 additions & 8 deletions app/napval/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ package main
import (
"bytes"
"encoding/json"
"log"
//"log"
"net/url"
"os"
"path"
"strings"
"testing"
"time"

Nias2 "github.com/nsip/nias2/lib"
"github.com/nsip/nias2/napval"
"menteslibres.net/gosexy/rest"
)

Expand Down Expand Up @@ -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"])
Expand All @@ -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())
}
38 changes: 38 additions & 0 deletions lib/config.go
Original file line number Diff line number Diff line change
@@ -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
}
35 changes: 4 additions & 31 deletions napval/validation_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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
}
2 changes: 1 addition & 1 deletion napval/validation_distributor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion napval/validation_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
//"time"
)

var naplanconfig = lib.LoadNAPLANConfig()
var naplanconfig = LoadNAPLANConfig()
var VALIDATION_ROUTE = naplanconfig.ValidationRoute

var req_ec *nats.EncodedConn
Expand Down
2 changes: 1 addition & 1 deletion napval/validation_serviceregister.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 7 additions & 18 deletions xml/registrationrecord.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/gob"
"encoding/xml"
"github.com/nsip/nias2/go_SifMessage"
"strings"
)

func init() {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
Expand All @@ -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" {
Expand Down Expand Up @@ -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})
Expand All @@ -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})
Expand Down

0 comments on commit 084a00a

Please sign in to comment.