summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2015-12-13 04:02:43 (GMT)
committerChristian Pointner <equinox@helsinki.at>2015-12-13 04:02:43 (GMT)
commit036e7a314729bb473998127f0ad20d7e1c3b7709 (patch)
tree19120859df59c8a6b13973be26676d2cbe9260b5
parent2a2d9d2a574da4e21414698e8b9ed1d273f237bc (diff)
music pool group check works now
-rw-r--r--importer.go33
-rw-r--r--rddb.go61
2 files changed, 74 insertions, 20 deletions
diff --git a/importer.go b/importer.go
index 95f61f7..8206082 100644
--- a/importer.go
+++ b/importer.go
@@ -97,7 +97,13 @@ func (ctx *ImportContext) SanityCheck() error {
return nil
}
if ctx.GroupName != "" {
- // TODO: check if GroupName is a music pool -> Error if not
+ ismusic, err := ctx.checkMusicGroup()
+ if err != nil {
+ return err
+ }
+ if !ismusic {
+ return fmt.Errorf("supplied GroupName is not a music pool")
+ }
return nil
}
if ctx.Cart == 0 {
@@ -118,14 +124,13 @@ func (ctx *ImportContext) getPassword(cached bool) (err error) {
res := <-req.response
if res.err != nil {
- err = res.err
- return
+ return res.err
}
ctx.Password = res.password
- return
+ return nil
}
-func (ctx *ImportContext) getGroupOfCart() (err error) {
+func (ctx *ImportContext) getGroupOfCart() error {
req := getGroupOfCartRequest{}
req.cart = ctx.Cart
req.response = make(chan getGroupOfCartResult)
@@ -133,11 +138,10 @@ func (ctx *ImportContext) getGroupOfCart() (err error) {
res := <-req.response
if res.err != nil {
- err = res.err
- return
+ return res.err
}
ctx.GroupName = res.group
- return
+ return nil
}
func (ctx *ImportContext) getShowInfo() (err error) {
@@ -155,6 +159,19 @@ func (ctx *ImportContext) getShowInfo() (err error) {
return
}
+func (ctx *ImportContext) checkMusicGroup() (bool, error) {
+ req := checkMusicGroupRequest{}
+ req.group = ctx.GroupName
+ req.response = make(chan checkMusicGroupResult)
+ ctx.RdDb.checkMusicGroupChan <- req
+
+ res := <-req.response
+ if res.err != nil {
+ return false, res.err
+ }
+ return res.ismusic, nil
+}
+
type ImportResult struct {
ResponseCode int
ErrorString string
diff --git a/rddb.go b/rddb.go
index 85a3177..52d6e18 100644
--- a/rddb.go
+++ b/rddb.go
@@ -62,17 +62,29 @@ type getShowInfoRequest struct {
response chan getShowInfoResult
}
+type checkMusicGroupResult struct {
+ ismusic bool
+ err error
+}
+
+type checkMusicGroupRequest struct {
+ group string
+ response chan checkMusicGroupResult
+}
+
type RdDb struct {
- dbh *sql.DB
- password_cache map[string]string
- getPasswordChan chan getPasswordRequest
- getPasswordStmt *sql.Stmt
- getGroupOfCartChan chan getGroupOfCartRequest
- getGroupOfCartStmt *sql.Stmt
- getShowInfoChan chan getShowInfoRequest
- getShowInfoStmt *sql.Stmt
- quit chan bool
- done chan bool
+ dbh *sql.DB
+ password_cache map[string]string
+ getPasswordChan chan getPasswordRequest
+ getPasswordStmt *sql.Stmt
+ getGroupOfCartChan chan getGroupOfCartRequest
+ getGroupOfCartStmt *sql.Stmt
+ getShowInfoChan chan getShowInfoRequest
+ getShowInfoStmt *sql.Stmt
+ checkMusicGroupChan chan checkMusicGroupRequest
+ checkMusicGroupStmt *sql.Stmt
+ quit chan bool
+ done chan bool
}
func (self *RdDb) init(conf *Config) (err error) {
@@ -89,6 +101,9 @@ func (self *RdDb) init(conf *Config) (err error) {
if self.getShowInfoStmt, err = self.dbh.Prepare("select TITLE,MACROS from CART where NUMBER = ?;"); err != nil {
return
}
+ if self.checkMusicGroupStmt, err = self.dbh.Prepare("select count(*) from DROPBOXES where GROUP_NAME = ? and SET_USER_DEFINED like \"M;%\";"); err != nil {
+ return
+ }
return
}
@@ -152,11 +167,25 @@ func (self *RdDb) getShowInfo(showid int) (title string, carts map[int]int, err
}
rhdl.Printf("RdDb: macros for showid '%d' are set to '%s'", showid, macros)
- // TODO: also fetch cart list
+ // TODO: also fetch cart list and import params (norm_level, ...)
carts = make(map[int]int)
return
}
+func (self *RdDb) checkMusicGroup(group string) (ismusic bool, err error) {
+ var cnt int
+ err = self.checkMusicGroupStmt.QueryRow(group).Scan(&cnt)
+ if err != nil {
+ if err == sql.ErrNoRows {
+ err = nil
+ ismusic = false
+ }
+ return
+ }
+ ismusic = cnt > 0
+ return
+}
+
func (self *RdDb) dispatchRequests() {
defer func() { self.done <- true }()
for {
@@ -179,6 +208,10 @@ func (self *RdDb) dispatchRequests() {
rhdl.Println("RdDb: got getShowInfo request for", req.showid)
title, carts, err := self.getShowInfo(req.showid)
req.response <- getShowInfoResult{title, carts, err}
+ case req := <-self.checkMusicGroupChan:
+ rhdl.Println("RdDb: got checkMusicGroup request for", req.group)
+ ismusic, err := self.checkMusicGroup(req.group)
+ req.response <- checkMusicGroupResult{ismusic, err}
}
}
}
@@ -199,7 +232,10 @@ func (self *RdDb) Cleanup() {
self.getGroupOfCartStmt.Close()
}
if self.getShowInfoStmt != nil {
- self.getPasswordStmt.Close()
+ self.getShowInfoStmt.Close()
+ }
+ if self.checkMusicGroupStmt != nil {
+ self.checkMusicGroupStmt.Close()
}
}
@@ -212,6 +248,7 @@ func NewRdDb(conf *Config) (db *RdDb, err error) {
db.getPasswordChan = make(chan getPasswordRequest)
db.getGroupOfCartChan = make(chan getGroupOfCartRequest)
db.getShowInfoChan = make(chan getShowInfoRequest)
+ db.checkMusicGroupChan = make(chan checkMusicGroupRequest)
if err = db.init(conf); err != nil {
return