Example #1
0
func (metric *Metric) Delete(context *ctp.ApiContext) *ctp.HttpError {
	metricUrl := ctp.NewLink(context.CtpBase, "@/metrics/$", metric.Id) // just to create a clean URL

	query := context.Session.DB("ctp").C("measurements").Find(bson.M{"metric": metricUrl})
	count, err := query.Count()
	if err != nil {
		return ctp.NewInternalServerError(err)
	}
	if count > 0 {
		return ctp.NewHttpError(http.StatusConflict, "Metric cannot be deleted because it is still in use by some measurements.")
	}

	if !ctp.DeleteResource(context, "metrics", metric.Id) {
		return ctp.NewInternalServerError("Metric deletion failed")
	}
	return nil
}
Example #2
0
func serviceViewDelete(context *ctp.ApiContext, id ctp.Base64Id) bool {
	if !IterateChildrenDelete(context, "assets", "parent", id, assetDelete) {
		return false
	}
	return ctp.DeleteResource(context, "serviceViews", id)
}
Example #3
0
func assetDelete(context *ctp.ApiContext, id ctp.Base64Id) bool {
	if !IterateChildrenDelete(context, "attributes", "parent", id, attributeDelete) {
		return false
	}
	return ctp.DeleteResource(context, "assets", id)
}
Example #4
0
func measurementDelete(context *ctp.ApiContext, id ctp.Base64Id) bool {
	return ctp.DeleteResource(context, "measurements", id)
}
Example #5
0
func (trigger *Trigger) Delete(context *ctp.ApiContext) *ctp.HttpError {
	if !ctp.DeleteResource(context, "triggers", trigger.Id) {
		return ctp.NewHttpError(http.StatusInternalServerError, "Could not delete trigger")
	}
	return nil
}
Example #6
0
func (account *Account) Delete(context *ctp.ApiContext) *ctp.HttpError {
	if !ctp.DeleteResource(context, "accounts", account.Id) {
		return ctp.NewInternalServerError("Account deletion failed")
	}
	return nil
}