diff --git a/src/pactivities_api.go b/src/pactivities_api.go index f43fea2..79bb102 100644 --- a/src/pactivities_api.go +++ b/src/pactivities_api.go @@ -4,7 +4,6 @@ import ( "fmt" "log" "net/http" - "reflect" "github.com/julienschmidt/httprouter" "github.com/securitybunker/databunker/src/utils" @@ -32,40 +31,16 @@ func (e mainEnv) pactivityCreate(w http.ResponseWriter, r *http.Request, ps http w.Write([]byte(`{"status":"ok"}`)) }() - title := "" - script := "" - fulldesc := "" legalbasis := "" - newactivity := "" - applicableto := "" - if value, ok := records["title"]; ok { - if reflect.TypeOf(value) == reflect.TypeOf("string") { - title = value.(string) - } - } + title := utils.GetStringValue(records["title"]) if len(title) == 0 { title = activity } - if value, ok := records["script"]; ok { - if reflect.TypeOf(value) == reflect.TypeOf("string") { - script = value.(string) - } - } - if value, ok := records["fulldesc"]; ok { - if reflect.TypeOf(value) == reflect.TypeOf("string") { - fulldesc = value.(string) - } - } - if value, ok := records["activity"]; ok { - if reflect.TypeOf(value) == reflect.TypeOf("string") { - newactivity = value.(string) - } - } - if value, ok := records["applicableto"]; ok { - if reflect.TypeOf(value) == reflect.TypeOf("string") { - applicableto = value.(string) - } - } + script := utils.GetStringValue(records["script"]) + fulldesc := utils.GetStringValue(records["fulldesc"]) + newactivity := utils.GetStringValue(records["activity"]) + applicableto := utils.GetStringValue(records["applicableto"]) + e.db.createProcessingActivity(activity, newactivity, title, script, fulldesc, legalbasis, applicableto) } diff --git a/src/pactivities_db.go b/src/pactivities_db.go index e60e3bb..e7ec4fa 100644 --- a/src/pactivities_db.go +++ b/src/pactivities_db.go @@ -4,7 +4,6 @@ import ( "encoding/json" "errors" "fmt" - "reflect" "strings" "time" @@ -69,12 +68,7 @@ func (dbobj dbcon) linkProcessingActivity(activity string, brief string) (bool, if raw == nil { return false, errors.New("not found") } - legalbasis := "" - if value, ok := raw["legalbasis"]; ok { - if reflect.TypeOf(value) == reflect.TypeOf("string") { - legalbasis = value.(string) - } - } + legalbasis := utils.GetStringValue(raw["legalbasis"]) briefs := strings.Split(legalbasis, ",") if utils.SliceContains(briefs, brief) == true { // nothing to do here @@ -100,12 +94,7 @@ func (dbobj dbcon) unlinkProcessingActivity(activity string, brief string) (bool if raw == nil { return false, errors.New("not found") } - legalbasis := "" - if val, ok := raw["legalbasis"]; ok { - if reflect.TypeOf(val) == reflect.TypeOf("string") { - legalbasis = val.(string) - } - } + legalbasis := utils.GetStringValue(raw["legalbasis"]) briefs := strings.Split(legalbasis, ",") if utils.SliceContains(briefs, brief) == false { // nothing to do here