Esempio n. 1
0
func (serv OrchioReadService) GetEvent(name, key, etype, timestamp string, ordinal int) string {
	datastore.TraceMsg("==> Orchio::GetEvent")

	data, mdata, err := datastore.GetEvent(name, key, etype, timestamp, ordinal)
	logError("Orchio::GetEvent", err)

	responseCode := 200
	response := updateResponse(serv.ResponseBuilder(), "")

	// Guard clause for 404 and 500 errors.
	if mdata == "" {
		var msgCode string
		if data == "" {
			responseCode = 404
			msgCode = "items_not_found"
		} else {
			responseCode = 500
			msgCode = "internal_error"
		}
		errorMsgBody := eventErrorMsgBody(responseCode, msgCode, name, key, etype, timestamp, ordinal)
		completeTheResponse(response, responseCode, errorMsgBody)
		return ""
	}

	completeTheResponse(response, responseCode, data)
	return ""
}
Esempio n. 2
0
func (serv OrchioWriteService) PutKey(data, name, key string) {
	datastore.TraceMsg("==> Orchio::PutKey:")

	req := serv.Context.Request()
	response := updateResponse(serv.ResponseBuilder(), "")

	var responseCode int
	var msgCode string
	var ok bool
	if responseCode, msgCode, ok = checkContentType(req.Header, "put"); ok {
		responseCode, msgCode, ok = checkConditionalHeaders(req.Header, name, key)
	}

	if !ok {
		errorMsgBody := keyErrorMsgBody(responseCode, msgCode, name, key)
		completeTheResponse(response, responseCode, errorMsgBody)
		return
	}

	ref := datastore.PutKey(data, name, key)
	response.AddHeader("Location", locationString(name, key, ref))
	response.AddHeader("Etag", strconv.Quote(ref))
	completeTheResponse(response, 201, "")
	return
}
Esempio n. 3
0
func getRelations(r *gorest.ResponseBuilder, name, key, kind string) string {
	datastore.TraceMsg(fmt.Sprintf("==> Orchio::getRelations: %s/%s/relations/%s", name, key, kind))

	data, _ := datastore.GetRelations(name, key, kind)

	response := updateResponse(r, "")
	completeTheResponse(response, 200, data)
	return ""
}
Esempio n. 4
0
func (serv OrchioWriteService) PutRelation(data, name, key, kind, to_c, to_k string) {
	datastore.TraceMsg("==> Orchio::PutRelation:")

	datastore.PutRelation(name, key, kind, to_c, to_k)

	response := updateResponse(serv.ResponseBuilder(), "")
	completeTheResponse(response, 204, "OrchioService::PutRelation")
	return
}
Esempio n. 5
0
func (serv OrchioWriteService) DeleteCollection(name string) {
	datastore.TraceMsg("==> Orchio::DeleteCollection:")

	req := serv.Context.Request()
	response := updateResponse(serv.ResponseBuilder(), "delete")

	// check for "?force=true"
	force := getParamBooleanValue("force", req.URL.RawQuery)
	datastore.DeleteCollection(name, force)
	completeTheResponse(response, 204, "")
	return
}
Esempio n. 6
0
func (serv OrchioWriteService) DeleteRelation(name, key, kind, to_c, to_k string) {
	datastore.TraceMsg("==> Orchio::DeleteRelation:")

	// check for "?purge=true"
	req := serv.Context.Request()
	if getParamBooleanValue("purge", req.URL.RawQuery) {
		datastore.DeleteRelation(name, key, kind, to_c, to_k)
	}
	response := updateResponse(serv.ResponseBuilder(), "delete")
	completeTheResponse(response, 204, "OrchioService::DeleteRelation")
	return
}
Esempio n. 7
0
func (serv OrchioReadService) ListEvents(name, key, etype string) string {
	datastore.TraceMsg("==> Orchio::GetEvents")

	// Check for range params (timestamp/ordinal)
	req := serv.Context.Request()
	paramValues := getParamValues(req.URL.RawQuery)

	response := updateResponse(serv.ResponseBuilder(), "")

	data, next, _, _ := datastore.ListEvents(name, key, etype, paramValues)

	if next != "" {
		response.AddHeader("Link", fmt.Sprintf("<%s>", next))
	}
	completeTheResponse(response, 200, data)
	return ""
}
Esempio n. 8
0
func (serv OrchioWriteService) DeleteKey(name, key string) {
	datastore.TraceMsg("==> Orchio::DeleteKey:")

	req := serv.Context.Request()
	response := updateResponse(serv.ResponseBuilder(), "delete")

	if responseCode, msgCode, ok := checkConditionalHeaders(req.Header, name, key); !ok {
		errorMsgBody := keyErrorMsgBody(responseCode, msgCode, name, key)
		completeTheResponse(response, responseCode, errorMsgBody)
		return
	}

	// check for "?purge=true"
	purge := getParamBooleanValue("purge", req.URL.RawQuery)
	datastore.DeleteKey(name, key, purge)
	completeTheResponse(response, 204, "")
	return
}
Esempio n. 9
0
func (serv OrchioReadService) GetCollection(name string) string {
	datastore.TraceMsg(fmt.Sprintf("==> Orchio::GetCollection: %s\n", name))

	req := serv.Context.Request()
	paramValues := getParamValues(req.URL.RawQuery)

	responseCode := 200
	response := updateResponse(serv.ResponseBuilder(), "")

	data, next, prev, err := datastore.GetCollection(name, paramValues)
	outputError("Orchio::GetCollection:", err)

	if next != "" {
		response.AddHeader("Link", fmt.Sprintf("<%s>; rel=\"next\"", next))
	}

	if _, ok := paramValues["query"]; ok && prev != "" {
		response.AddHeader("Link", fmt.Sprintf("<%s>; rel=\"prev\"", prev))
	}

	completeTheResponse(response, responseCode, data)
	return ""
}
Esempio n. 10
0
func (serv OrchioReadService) ListRefs(name, key string) string {
	datastore.TraceMsg(fmt.Sprintf("==> Orchio::ListRefs: %s", name))

	req := serv.Context.Request()
	paramValues := getParamValues(req.URL.RawQuery)

	responseCode := 200
	response := updateResponse(serv.ResponseBuilder(), "")

	data, next, prev, err := datastore.ListRefs(name, key, paramValues)
	outputError("Orchio::ListRefs:", err)

	if next != "" {
		response.AddHeader("Link", fmt.Sprintf("<%s>; rel=\"next\"", next))
	}

	if prev != "" {
		response.AddHeader("Link", fmt.Sprintf("<%s>; rel=\"prev\"", prev))
	}

	completeTheResponse(response, responseCode, data)
	return ""
}
Esempio n. 11
0
func (serv OrchioReadService) GetByRef(name, key, ref string) string {
	datastore.TraceMsg("==> Orchio::GetByRef:")
	return getKey(serv, name, key, ref)
}
Esempio n. 12
0
func (serv OrchioReadService) GetKey(name, key string) string {
	datastore.TraceMsg("==> Orchio::GetKey:")
	return getKey(serv, name, key, "")
}
Esempio n. 13
0
func (serv OrchioWriteService) PutEvent(data, name, key, etype, timestamp string, ordinal int) {
	datastore.TraceMsg("==> Orchio::PutEvent:")
	putEvent(serv, data, name, key, etype, timestamp, ordinal)
	return
}
Esempio n. 14
0
func (serv OrchioWriteService) PostEventTs(data, name, key, etype, timestamp string) {
	datastore.TraceMsg("==> Orchio::PostEventTS:")
	putEvent(serv, data, name, key, etype, timestamp, 0)
	return
}
Esempio n. 15
0
func (serv OrchioWriteService) PostEvent(data, name, key, etype string) {
	datastore.TraceMsg("==> Orchio::PostEvent:")
	putEvent(serv, data, name, key, etype, "", 0)
	return
}