func ModifyRepo(w http.ResponseWriter, r *http.Request) { repoID := r.URL.Query().Get(":ID") action := r.URL.Query().Get("Action") db := liboct.GetDefaultDB() val, err := db.Get(liboct.DBRepo, repoID) if err != nil { liboct.RenderError(w, err) return } if action == "Modify" { var newRepo liboct.TestCaseRepo result, _ := ioutil.ReadAll(r.Body) r.Body.Close() err := json.Unmarshal([]byte(result), &newRepo) if err != nil { liboct.RenderError(w, err) } else { oldRepo, _ := liboct.RepoFromString(val.String()) oldRepo.Modify(newRepo) db.Update(liboct.DBRepo, repoID, oldRepo) RefreshRepo(repoID) liboct.RenderOK(w, "", nil) } } else if action == "Refresh" { RefreshRepo(repoID) liboct.RenderOK(w, "", nil) } else { liboct.RenderErrorf(w, "The action in ModifyRepo is limited to Add/Refresh") } }
//This refresh the 'cache' maintained in casemanager func RefreshRepo(id string) { db := liboct.GetDefaultDB() val, err := db.Get(liboct.DBRepo, id) if err != nil { return } repo, _ := liboct.RepoFromString(val.String()) if repo.Refresh() { CleanRepo(repo) cases := repo.GetCases() for index := 0; index < len(cases); index++ { fmt.Println("case loaded ", cases[index]) db.Add(liboct.DBCase, cases[index]) } } }