示例#1
0
func (w *WebGrabberController) ConnectToSedotanServer() (*SshSetting, *colonycore.Server, error) {
	filter := dbox.And(dbox.Eq("os", "linux"), dbox.Eq("serverType", "node"))
	cursor, err := colonycore.Find(new(colonycore.Server), filter)
	if err != nil {
		return nil, nil, err
	}

	data := []colonycore.Server{}
	err = cursor.Fetch(&data, 0, true)
	if err != nil {
		return nil, nil, err
	}

	if len(data) == 0 {
		return nil, nil, errors.New("No sedotan server found")
	}

	server := data[0]

	var client SshSetting
	client.SSHHost = server.Host
	client.SSHAuthType = SSHAuthType_Password
	client.SSHUser = server.SSHUser
	client.SSHPassword = server.SSHPass

	return &client, &server, nil
}
示例#2
0
func (d *DataGrabberController) FindDataGrabber(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	//~ payload := map[string]string{"inputText":"test"}
	payload := map[string]interface{}{}

	err := r.GetPayload(&payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	text := payload["inputText"].(string)
	textLow := strings.ToLower(text)

	var query *dbox.Filter
	valueInt, errv := strconv.Atoi(text)
	fmt.Printf("", valueInt)
	fmt.Printf("", errv)
	if errv == nil {
		// == try useing Eq for support integer
		query = dbox.Or(dbox.Eq("GrabInterval", valueInt), dbox.Eq("TimeoutInterval", valueInt))
	} else {
		// == try useing Contains for support autocomplite
		query = dbox.Or(dbox.Contains("_id", text), dbox.Contains("_id", textLow), dbox.Contains("DataSourceOrigin", text), dbox.Contains("DataSourceOrigin", textLow), dbox.Contains("DataSourceDestination", text), dbox.Contains("DataSourceDestination", textLow), dbox.Contains("IntervalType", text), dbox.Contains("IntervalType", textLow))
	}

	data := []colonycore.DataGrabber{}
	cursor, err := colonycore.Find(new(colonycore.DataGrabber), query)
	cursor.Fetch(&data, 0, false)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer cursor.Close()

	return helper.CreateResult(true, data, "")
}
示例#3
0
func TestSelectFilter(t *testing.T) {
	c, e := prepareConnection()
	if e != nil {
		t.Errorf("Unable to connect %s \n", e.Error())
		return
	}
	defer c.Close()

	csr, e := c.NewQuery().
		Select("id", "name").
		Where(dbox.And(dbox.Eq("id", "1"), (dbox.Eq("name", "a")))).
		From("tes").Cursor(nil)
	if e != nil {
		t.Errorf("Cursor pre error: %s \n", e.Error())
		return
	}
	if csr == nil {
		t.Errorf("Cursor not initialized")
		return
	}
	defer csr.Close()

	//rets := []toolkit.M{}

	ds, e := csr.Fetch(nil, 0, false)
	if e != nil {
		t.Errorf("Unable to fetch: %s \n", e.Error())
	} else {
		fmt.Printf("Fetch N OK. Result: %v \n",
			ds.Data)
	}
}
示例#4
0
func TestSelectFilter(t *testing.T) {
	t.Skip()
	c, e := prepareConnection()
	if e != nil {
		t.Errorf("Unable to connect %s \n", e.Error())
		return
	}
	defer c.Close()

	csr, e := c.NewQuery().
		Select("empno", "ename", "mgr", "hiredate").
		Where(dbox.Or(dbox.Eq("empno", 7521), dbox.Eq("ename", "ADAMS"))).
		From(tableName).Cursor(nil)
	if e != nil {
		t.Errorf("Cursor pre error: %s \n", e.Error())
		return
	}
	if csr == nil {
		t.Errorf("Cursor not initialized")
		return
	}
	defer csr.Close()

	rets := /*[]customers{}*/ []toolkit.M{}
	e = csr.Fetch(&rets, 0, false)
	if e != nil {
		t.Errorf("Unable to fetch: %s \n", e.Error())
	} else {
		toolkit.Printf("Filter OK. Result: %v \n", toolkit.JsonString(rets))
	}
}
func (d *DataSourceController) RemoveDataSource(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := map[string]interface{}{}
	err := r.GetPayload(&payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	id := payload["_id"].(string)

	dg := new(colonycore.DataGrabber)
	filter := dbox.Or(dbox.Eq("DataSourceOrigin", id), dbox.Eq("DataSourceDestination", id))
	cursor, err := colonycore.Find(dg, filter)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer cursor.Close()

	if cursor.Count() > 0 {
		return helper.CreateResult(false, nil, "Cannot delete data source because used on data grabber")
	}

	o := new(colonycore.DataSource)
	o.ID = id
	err = colonycore.Delete(o)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	return helper.CreateResult(true, nil, "")
}
示例#6
0
func TestDelete(t *testing.T) {
	t.Skip()
	c, e := prepareConnection()
	if e != nil {
		t.Errorf("Unable to connect %s \n", e.Error())
		return
	}
	defer c.Close()

	e = c.NewQuery().From("students").Where(dbox.And(dbox.Eq("name", "dwayne johnson"), dbox.Eq("age", 32))).Delete().Exec(nil)
	// e = c.NewQuery().From("students").Where(dbox.Eq("name", "dwayne johnson")).Delete().Exec(nil)
	if e != nil {
		t.Errorf("Unable to delete table %s\n", e.Error())
		return
	}

	/* ===============================CLEAR ALL TABLE DATA==============================*/

	// e = c.NewQuery().SetConfig("multiexec", true).
	// 	From("coba").Delete().Exec(nil)
	// if e != nil {
	// 	t.Errorf("Unable to clear table %s\n", e.Error())
	// 	return
	// }
}
示例#7
0
func (l *LangenvironmentController) UninstallLang(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := new(colonycore.LanguageEnvironmentPayload)
	err := r.GetPayload(payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	dataServers := new(colonycore.Server)
	err = colonycore.Get(dataServers, payload.ServerId)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	serverPathSeparator := CreateApplicationController(l.Server).GetServerPathSeparator(dataServers)

	sshSetting, sshClient, err := dataServers.Connect()
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer sshClient.Close()

	var query *dbox.Filter
	if payload.Lang == LANG_SCALA {
		var IsInstalled bool
		for _, eachLang := range dataServers.InstalledLang {
			if eachLang.Lang == LANG_JAVA {
				IsInstalled = eachLang.IsInstalled
				break
			}
		}
		if !IsInstalled {
			query = dbox.Or(dbox.Eq("language", LANG_JAVA), dbox.Eq("language", LANG_SCALA))
		} else {
			query = dbox.Eq("language", payload.Lang)
		}
	} else {
		query = dbox.Eq("language", payload.Lang)
	}

	result, err := l.ProcessSetup(dataServers, query, serverPathSeparator, sshSetting)
	if err != nil {
		helper.CreateResult(false, nil, err.Error())
	}
	fmt.Println("result :: ", result)

	for _, eachLang := range dataServers.InstalledLang {
		if eachLang.Lang == payload.Lang {
			eachLang.IsInstalled = false
			break
		}
	}

	err = colonycore.Save(dataServers)
	if err != nil {
		helper.CreateResult(false, nil, err.Error())
	}

	return helper.CreateResult(true, payload, "")
}
示例#8
0
func TestFilter(t *testing.T) {
	fb := dbox.NewFilterBuilder(new(FilterBuilder))
	fb.AddFilter(dbox.Or(
		dbox.Eq("_id", 1),
		dbox.Eq("group", "administrators")))
	b, e := fb.Build()
	if e != nil {
		t.Errorf("Error %s", e.Error())
	} else {
		fmt.Printf("Result:\n%v\n", toolkit.JsonString(b))
	}
}
示例#9
0
func (s *ServerController) GetServers(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := struct {
		Search     string `json:"search"`
		ServerOS   string `json:"serverOS"`
		ServerType string `json:"serverType"`
		SSHType    string `json:"sshType"`
	}{}
	err := r.GetPayload(&payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	filters := []*dbox.Filter{}
	if payload.Search != "" {
		filters = append(filters, dbox.Or(
			dbox.Contains("_id", payload.Search),
			dbox.Contains("os", payload.Search),
			dbox.Contains("host", payload.Search),
			dbox.Contains("serverType", payload.Search),
			dbox.Contains("sshtype", payload.Search),
		))
	}
	if payload.ServerOS != "" {
		filters = append(filters, dbox.Eq("os", payload.ServerOS))
	}
	if payload.ServerType != "" {
		filters = append(filters, dbox.Eq("serverType", payload.ServerType))
	}
	if payload.SSHType != "" {
		filters = append(filters, dbox.Eq("sshtype", payload.SSHType))
	}

	var query *dbox.Filter
	if len(filters) > 0 {
		query = dbox.And(filters...)
	}

	cursor, err := colonycore.Find(new(colonycore.Server), query)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	data := []colonycore.Server{}
	err = cursor.Fetch(&data, 0, false)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer cursor.Close()

	return helper.CreateResult(true, data, "")
}
示例#10
0
func filterCondition(cond toolkit.M) *dbox.Filter {
	fb := new(dbox.Filter)

	for key, val := range cond {
		if key == "$and" || key == "$or" {
			afb := []*dbox.Filter{}
			for _, sVal := range val.([]interface{}) {
				rVal := sVal.(map[string]interface{})
				mVal := toolkit.M{}
				for rKey, mapVal := range rVal {
					mVal.Set(rKey, mapVal)
				}

				afb = append(afb, filterCondition(mVal))
			}

			if key == "$and" {
				fb = dbox.And(afb...)
			} else {
				fb = dbox.Or(afb...)
			}

		} else {
			if reflect.ValueOf(val).Kind() == reflect.Map {
				mVal := val.(map[string]interface{})
				tomVal, _ := toolkit.ToM(mVal)
				switch {
				case tomVal.Has("$eq"):
					fb = dbox.Eq(key, tomVal["$eq"].(string))
				case tomVal.Has("$ne"):
					fb = dbox.Ne(key, tomVal["$ne"].(string))
				case tomVal.Has("$regex"):
					fb = dbox.Contains(key, tomVal["$regex"].(string))
				case tomVal.Has("$gt"):
					fb = dbox.Gt(key, tomVal["$gt"].(string))
				case tomVal.Has("$gte"):
					fb = dbox.Gte(key, tomVal["$gte"].(string))
				case tomVal.Has("$lt"):
					fb = dbox.Lt(key, tomVal["$lt"].(string))
				case tomVal.Has("$lte"):
					fb = dbox.Lte(key, tomVal["$lte"].(string))
				}
			} else {
				fb = dbox.Eq(key, val)
			}
		}
	}

	return fb
}
示例#11
0
func (c *DashboardController) GetPowerVsFuelConsumtion(k *knot.WebContext) interface{} {
	//c.LoadBase(k)
	k.Config.OutputType = knot.OutputJson

	d := struct {
		StartDate string
		EndDate   string
		Period    int
		Plant     []string
	}{}

	e := k.GetPayload(&d)

	r := new(tk.Result)
	r.Run(func(in interface{}) (interface{}, error) {

		var (
			filter []*dbox.Filter
		)

		selectedPeriod := d.Period
		filter = append(filter, dbox.Eq("Year", selectedPeriod))

		if len(d.Plant) > 0 {
			filter = append(filter, dbox.Eq("Plant", d.Plant[0]))
		}

		result := make([]tk.M, 0)

		cursor, e := c.DB().Connection.NewQuery().
			Select("Plant as _id").
			From("ValueEquation_Dashboard").
			Where(filter...).
			Group("Plant").
			Aggr(dbox.AggrSum, "UpdatedFuelConsumption", "FuelConsumtion").
			Aggr(dbox.AggrSum, "NetGeneration", "Power").
			Order("_id").
			Cursor(nil)

		defer cursor.Close()

		e = cursor.Fetch(&result, 0, true)

		e = c.CheckNotError(e)

		return result, e
	}, nil)

	return ResultInfo(r, e)
}
示例#12
0
func TestCRUD(t *testing.T) {
	//t.Skip()
	c, e := prepareConnection()
	if e != nil {
		t.Errorf("Unable to connect %s \n", e.Error())
		return
	}
	defer c.Close()

	e = c.NewQuery().From("tes").Where(dbox.And(dbox.Eq("id", "1133331"), dbox.Eq("name", "testing"))).Delete().Exec(nil)
	if e != nil {
		t.Errorf("Unablet to delete table %s\n", e.Error())
		return
	}
	defer c.Close()

	e = c.NewQuery().From("tes").Delete().Exec(nil)
	if e != nil {
		t.Errorf("Unablet to clear table %s\n", e.Error())
		return
	}

	defer c.Close()

	// q := c.NewQuery().SetConfig("multiexec", true).From("tes").Save()
	type user struct {
		// Id     int
		Name string
		// Date   time.Time
	}

	// // 	//go func(q dbox.IQuery, i int) {
	data := user{}
	// data.Id =111
	data.Name = "testingupdate2222"
	// data.Date = time.Now()

	// e = q.Exec(toolkit.M{
	// 	"data": data,
	// })
	// if e != nil {
	// 	t.Errorf("Unable to save: %s \n", e.Error())
	// }
	e = c.NewQuery().From("tes").Where(dbox.Eq("id", "111")).Update().Exec(toolkit.M{"data": data})
	if e != nil {
		t.Errorf("Unable to update: %s \n", e.Error())
	}

}
示例#13
0
func Getquery(nameid string) ([]interface{}, error) {
	ci := &dbox.ConnectionInfo{filename, "", "", "", nil}
	c, e := dbox.NewConnection("json", ci)
	if e != nil {
		return nil, e
	}

	e = c.Connect()
	if e != nil {
		return nil, e
	}
	defer c.Close()
	csr, e := c.NewQuery().Where(dbox.Eq("nameid", nameid)).Cursor(nil)
	if e != nil {
		return nil, e
	}

	result := []interface{}{}
	data := []toolkit.M{}
	e = csr.Fetch(&data, 0, false)
	if e != nil {
		return nil, e
	}
	for _, v := range data {
		result = append(result, v)
	}
	return result, nil
}
示例#14
0
func TestSelect(t *testing.T) {
	skipIfConnectionIsNil(t)

	cursor, e := ctx.NewQuery().From(tableName).Where(dbox.Eq("Enable", false)).Cursor(nil)
	if e != nil {
		t.Fatalf("Cursor error: " + e.Error())
	}
	defer cursor.Close()

	if cursor.Count() == 0 {
		t.Fatalf("No record found")
	}

	var datas []toolkit.M
	e = cursor.Fetch(&datas, 0, false)
	if e != nil {
		t.Fatalf("Fetch error: %s", e.Error())
	}
	if len(datas) != cursor.Count() {
		t.Fatalf("Expect %d records got %d\n%s\n", cursor.Count(), len(datas), toolkit.JsonString(datas))
	}
	toolkit.Printf("Record found: %d\nData:\n%s\n", len(datas),
		func() string {
			var ret []string
			for _, v := range datas {
				ret = append(ret, v.GetString("_id"))
			}
			return strings.Join(ret, ",")
		}())
}
示例#15
0
func (a *ConfigurationController) Delete(k *knot.WebContext) interface{} {
	var (
		filename string
	)

	d := struct {
		NameID string
	}{}
	e := k.GetPayload(&d)
	k.Config.OutputType = knot.OutputJson

	filename = wd + filepath.Join("data", "Config", "config.json")
	ci := &dbox.ConnectionInfo{filename, "", "", "", nil}
	c, e := dbox.NewConnection("json", ci)
	defer c.Close()
	e = c.Connect()
	e = c.NewQuery().Where(dbox.Eq("nameid", d.NameID)).Delete().Exec(nil)
	if e != nil {
		fmt.Println("Found : ", e)
	}
	if e != nil {
		return e.Error()
	} else {
		return "OK"
	}
}
示例#16
0
func (c *AdministrationController) SaveUser(k *knot.WebContext) interface{} {
	d := struct {
		Id       string
		UserName string
		FullName string
		Password string
		Email    string
		Enable   bool
		ADUser   bool
	}{}
	e := k.GetPayload(&d)
	if e != nil {
		return ResultInfo(nil, e)
	}

	data := new(UserModel)
	data.UserName = d.UserName
	data.FullName = d.FullName
	data.PasswordHash = GetMD5Hash(d.Password)
	data.Email = d.Email
	data.Enable = d.Enable
	data.ADUser = d.ADUser
	data.SecurityStamp = time.Now().UTC()
	data.ConfirmedAtUtc = time.Now().UTC()

	e = c.Ctx.Connection.NewQuery().From(data.TableName()).Where(dbox.Eq("Email", d.Id)).Delete().Exec(nil)
	if e != nil {
		return ResultInfo(nil, e)
	}
	_, e = c.Ctx.InsertOut(data)
	if e != nil {
		return ResultInfo(nil, e)
	}
	return ResultInfo(data, e)
}
示例#17
0
func TestSelectFilter(t *testing.T) {
	c, e := prepareConnection()
	if e != nil {
		t.Errorf("Unable to connect %s \n", e.Error())
		return
	}
	defer c.Close()

	csr, e := c.NewQuery().
		//Select("_id", "email").
		Where(dbox.Eq("email", "*****@*****.**")).
		Cursor(nil)
	if e != nil {
		t.Errorf("Cursor pre error: %s \n", e.Error())
		return
	}
	if csr == nil {
		t.Errorf("Cursor not initialized")
		return
	}
	defer csr.Close()

	//rets := []toolkit.M{}

	ds, e := csr.Fetch(nil, 0, false)
	if e != nil {
		t.Errorf("Unable to fetch: %s \n", e.Error())
	} else {
		fmt.Printf("Fetch OK. Result: %v \n",
			toolkit.JsonString(ds.Data[0]))

	}
}
示例#18
0
func (t *DesignerController) GetConfig(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := map[string]string{}
	err := r.GetForms(&payload)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}
	_id := payload["_id"]

	data, err := t.getConfig(_id)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	connection, err := helper.LoadConfig(t.AppViewsPath + "/data/routes.json")
	if !helper.HandleError(err) {
		helper.Result(false, nil, err.Error())
	}
	defer connection.Close()

	cursor, err := connection.NewQuery().Where(dbox.Eq("_id", _id)).Cursor(nil)
	if !helper.HandleError(err) {
		helper.Result(false, nil, err.Error())
	}
	defer cursor.Close()

	dataSource, err := cursor.Fetch(nil, 0, false)
	if !helper.HandleError(err) {
		helper.Result(false, nil, err.Error())
	}
	data["href"] = dataSource.Data[0].(map[string]interface{})["href"]

	return helper.Result(true, data, "")
}
示例#19
0
func (d *DataGrabberController) SaveDataGrabber(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := new(colonycore.DataGrabber)
	err := r.GetPayload(payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	_, err = d.GenerateNewField(payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	before := new(colonycore.DataGrabber)
	cursor, err := colonycore.Find(before, dbox.Eq("_id", payload.ID))
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer cursor.Close()

	payload.RunAt = before.RunAt
	err = colonycore.Save(payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	return helper.CreateResult(true, payload, "")
}
示例#20
0
func (t *ChartController) RemoveChartConfig(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := map[string]string{}
	err := r.GetForms(&payload)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	// remove chart
	filename := fmt.Sprintf("chart-%s.json", payload["_id"])
	err = os.Remove(t.AppViewsPath + "data/chart/" + filename)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	// remove chart meta data
	connection, err := helper.LoadConfig(t.AppViewsPath + "data/chart.json")
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}
	defer connection.Close()

	err = connection.NewQuery().Delete().Where(dbox.Eq("_id", payload["_id"])).Exec(nil)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	return helper.Result(true, nil, "")
}
示例#21
0
func (d *DataBrowserController) DeleteBrowser(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := map[string]interface{}{}
	err := r.GetPayload(&payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	idArray := payload["_id"].([]interface{})

	for _, id := range idArray {
		ds := new(colonycore.DataBrowser)
		cursor, err := colonycore.Find(ds, dbox.Eq("ID", id.(string)))
		if err != nil {
			return helper.CreateResult(false, nil, err.Error())
		}
		defer cursor.Close()

		if cursor.Count() > 0 {
			return helper.CreateResult(false, nil, "Cannot delete DataBrowser because used on data source")
		}

		o := new(colonycore.DataBrowser)
		o.ID = id.(string)
		err = colonycore.Delete(o)
		if err != nil {
			return helper.CreateResult(false, nil, err.Error())
		}
	}

	return helper.CreateResult(true, nil, "")
}
示例#22
0
func (t *DataSourceController) RemoveDataSource(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := map[string]string{}
	err := r.GetForms(&payload)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	connection, err := helper.LoadConfig(t.AppViewsPath + "data/datasource.json")
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}
	defer connection.Close()

	err = connection.NewQuery().Delete().Where(dbox.Eq("_id", payload["_id"])).Exec(nil)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	if payload["type"] == "file" {
		err = os.Remove(t.AppViewsPath + "data/datasource/" + payload["path"])
		if !helper.HandleError(err) {
			return helper.Result(false, nil, err.Error())
		}
	}

	return helper.Result(true, nil, "")
}
示例#23
0
func getsnapshot() (err error) {
	err = nil

	config := toolkit.M{"useheader": true, "delimiter": ","}
	conn, err := prepareconnection("csv", snapshot, "", "", "", config)
	if err != nil {
		sedotan.CheckError(errors.New(fmt.Sprintf("Fatal error on get snapshot : %v", err.Error())))
	}
	defer conn.Close()

	csr, err := conn.NewQuery().Where(dbox.Eq("Id", _id)).Cursor(nil)
	if err != nil {
		sedotan.CheckError(errors.New(fmt.Sprintf("Fatal error on get snapshot : %v", err.Error())))
		return
	}

	if csr == nil {
		sedotan.CheckError(errors.New(fmt.Sprintf("Fatal error on get snapshot : Cursor not initialized")))
		return
	}
	defer csr.Close()
	// aa := toolkit.M{}
	err = csr.Fetch(&snapshotdata, 1, false)
	if err != nil {
		sedotan.CheckError(errors.New(fmt.Sprintf("Fatal error on get snapshot : %v", err.Error())))
	}

	return
}
示例#24
0
func (a *ApplicationController) SearchApps(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	text := "Mandiri"
	var query *dbox.Filter
	if text != "" {
		// query = dbox.Or(dbox.Eq("AppsName", text), dbox.Eq("ID", text))
		query = dbox.Eq("AppsName", text)
	}

	cursor, err := colonycore.Find(new(colonycore.Application), query)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	data := []colonycore.Application{}
	err = cursor.Fetch(&data, 0, false)
	fmt.Println("data pencarian : ", data)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer cursor.Close()

	return helper.CreateResult(true, data, "")
}
func (d *DataSourceController) RemoveConnection(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := map[string]interface{}{}
	err := r.GetPayload(&payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	id := payload["_id"].(string)

	ds := new(colonycore.DataSource)
	cursor, err := colonycore.Find(ds, dbox.Eq("ConnectionID", id))
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer cursor.Close()

	if cursor.Count() > 0 {
		return helper.CreateResult(false, nil, "Cannot delete connection because used on data source")
	}

	o := new(colonycore.Connection)
	o.ID = id
	err = colonycore.Delete(o)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	return helper.CreateResult(true, nil, "")
}
func (d *DataSourceController) FindConnection(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	//~ payload := map[string]string{"inputText":"tes","inputDrop":""}
	payload := map[string]interface{}{}

	err := r.GetPayload(&payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	text := payload["inputText"].(string)
	pilih := payload["inputDrop"].(string)

	textLow := strings.ToLower(text)

	// == try useing Contains for support autocomplite
	var query *dbox.Filter
	if text != "" {
		query = dbox.Or(dbox.Contains("_id", text), dbox.Contains("_id", textLow), dbox.Contains("Database", text), dbox.Contains("Database", textLow), dbox.Contains("Driver", text), dbox.Contains("Driver", textLow), dbox.Contains("Host", text), dbox.Contains("Host", textLow), dbox.Contains("UserName", text), dbox.Contains("UserName", textLow), dbox.Contains("Password", text), dbox.Contains("Password", textLow))
	}

	if pilih != "" {
		query = dbox.And(query, dbox.Eq("Driver", pilih))
	}

	data := []colonycore.Connection{}
	cursor, err := colonycore.Find(new(colonycore.Connection), query)
	cursor.Fetch(&data, 0, false)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer cursor.Close()

	return helper.CreateResult(true, data, "")
}
示例#27
0
func (d *WebGrabberController) FindWebGrabber(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson
	//~ payload := map[string]string{"inputText": "GRAB_TEST", "inputRequest": "", "inputType": ""}
	payload := map[string]interface{}{}

	err := r.GetPayload(&payload)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}

	text := payload["inputText"].(string)
	req := payload["inputRequest"].(string)
	tipe := payload["inputType"].(string)

	textLow := strings.ToLower(text)

	// == bug, cant find if autocomplite, just full text can be get result
	var query *dbox.Filter
	if text != "" {
		valueInt, errv := strconv.Atoi(text)
		if errv == nil {
			// == try useing Eq for support integer
			query = dbox.Or(dbox.Eq("GrabInterval", valueInt), dbox.Eq("TimeoutInterval", valueInt))
		} else {
			// == try useing Contains for support autocomplite
			query = dbox.Or(dbox.Contains("_id", text), dbox.Contains("_id", textLow), dbox.Contains("Calltype", text), dbox.Contains("Calltype", textLow), dbox.Contains("SourceType", text), dbox.Contains("SourceType", textLow), dbox.Contains("IntervalType", text), dbox.Contains("IntervalType", textLow))
		}
	}

	if req != "" {
		query = dbox.And(query, dbox.Eq("Calltype", req))
	}

	if tipe != "" {
		query = dbox.And(query, dbox.Eq("SourceType", tipe))
	}

	data := []colonycore.WebGrabber{}
	cursor, err := colonycore.Find(new(colonycore.WebGrabber), query)
	cursor.Fetch(&data, 0, false)
	if err != nil {
		return helper.CreateResult(false, nil, err.Error())
	}
	defer cursor.Close()

	return helper.CreateResult(true, payload, "")
}
示例#28
0
func (t *ChartController) GetChartConfig(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson

	payload := map[string]string{}
	err := r.GetForms(&payload)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	filename := fmt.Sprintf("chart-%s.json", payload["_id"])
	isWithDataSource, err := strconv.ParseBool(payload["isWithDataSource"])
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	fileContent, err := ioutil.ReadFile(t.AppViewsPath + "data/chart/" + filename)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	data := map[string]interface{}{}
	err = json.Unmarshal(fileContent, &data)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	if isWithDataSource {
		dataSourceID := data["outsider"].(map[string]interface{})["dataSourceKey"].(string)

		connection, err := helper.LoadConfig(t.AppViewsPath + "data/datasource.json")
		if !helper.HandleError(err) {
			return helper.Result(false, nil, err.Error())
		}
		defer connection.Close()

		cursor, err := connection.NewQuery().Where(dbox.Eq("_id", dataSourceID)).Cursor(nil)
		if !helper.HandleError(err) {
			return helper.Result(false, nil, err.Error())
		}
		defer cursor.Close()

		res := []toolkit.M{}
		err = cursor.Fetch(&res, 0, false)
		if !helper.HandleError(err) {
			return helper.Result(false, nil, err.Error())
		}
		if len(res) == 0 {
			return helper.Result(false, nil, "No data found")
		}

		dsID := res[0].GetString("_id")
		dsType := res[0].GetString("type")
		dsPath := res[0].GetString("path")
		dataSource, _ := helper.FetchDataSource(dsID, dsType, dsPath)
		data["dataSource"] = map[string]interface{}{"data": dataSource}
	}

	return helper.Result(true, data, "")
}
示例#29
0
func (t *DataSourceController) SaveDataSource(r *knot.WebContext) interface{} {
	r.Config.OutputType = knot.OutputJson
	r.Request.ParseMultipartForm(32 << 20)

	payload := map[string]string{}
	err := r.GetForms(&payload)
	if !helper.HandleError(err) {
		return helper.Result(false, nil, err.Error())
	}

	_id := payload["_id"]
	if _id == "" {
		_id = helper.RandomIDWithPrefix("ds")
	}

	// upload file
	if payload["type"] == "file" {
		filename := fmt.Sprintf("datasource-%s.json", _id)
		filepath := t.AppViewsPath + "data/datasource/" + filename

		_, _, err = helper.FetchThenSaveFile(r.Request, "file", filepath)
		if !helper.HandleError(err) {
			return helper.Result(false, nil, err.Error())
		}
		payload["path"] = filename
	}

	delete(payload, "file")

	if payload["_id"] == "" {
		payload["_id"] = _id

		// insert
		connection, err := helper.LoadConfig(t.AppViewsPath + "/data/datasource.json")
		if !helper.HandleError(err) {
			return helper.Result(false, nil, err.Error())
		}
		defer connection.Close()

		err = connection.NewQuery().Insert().Exec(toolkit.M{"data": payload})
		if !helper.HandleError(err) {
			return helper.Result(false, nil, err.Error())
		}
	} else {
		// update
		connection, err := helper.LoadConfig(t.AppViewsPath + "/data/datasource.json")
		if !helper.HandleError(err) {
			return helper.Result(false, nil, err.Error())
		}
		defer connection.Close()

		err = connection.NewQuery().Update().Where(dbox.Eq("_id", _id)).Exec(toolkit.M{"data": payload})
		if !helper.HandleError(err) {
			return helper.Result(false, nil, err.Error())
		}
	}

	return helper.Result(true, nil, "")
}
示例#30
0
func EmployeeFindByEnable(enable bool, order []string, skip, limit int) dbox.ICursor {
	c, _ := DB().Find(new(Employee),
		toolkit.M{}.Set("where", dbox.Eq("enable", enable)).
			Set("order", order).
			Set("skip", skip).
			Set("limit", limit))
	return dbox.NewCursor(c)
}