Example #1
0
// HTTP handler for Flow Update
func (h *handler) handlePutFlowDef() error {

	// derive flow def key from  URL path
	flowDefKey := h.PathVar("flowDefKey")
	base.Logf("Flow Definition Key: ", flowDefKey)

	if flowDefKey == "" {
		return base.HTTPErrorf(http.StatusBadRequest, "Invalid Flow Def Key")
	}
	//
	wf := db.NewWorkflowDef(flowDefKey)

	// read JSON HTTP input into Object
	_, err := h.readObject(&wf)

	//base.Logf("Encoding Workflow Def ..%s",wf)
	data, _ := json.Marshal(wf)

	//base.Logf("Saving Workflow Def ...%s",wf)
	_, err = h.db.PutDocRaw(flowDefKey, data)
	//base.Logf("Done save...")

	if err != nil {
		return base.HTTPErrorf(http.StatusBadRequest, "Flow Definition Could not be updated") //TO DO: Need to relook at error
	}
	_, err = h.db.PutDocRaw(wf.Name, []byte(flowDefKey))

	// this should be inside db trx TO DO
	//_, err =writeLastVersion(h.db , wf.Name , )

	//db.Body{"ok": true, "flowDefKey": flowDefKey}
	h.writeJSONStatus(http.StatusCreated, &wf)
	return nil
}
Example #2
0
// HTTP handler for Flow query
func (h *handler) handleGetFlowDef() error {
	// derive flow def key from  URL path
	flowDefKey := h.PathVar("flowDefKey")
	base.Logf("Flow Definition Key: ", flowDefKey)

	if flowDefKey == "" {
		return base.HTTPErrorf(http.StatusBadRequest,
			"Invalid Flow Def Key")
	}

	data, err := h.db.GetDocRaw(flowDefKey)
	if err != nil {
		return base.HTTPErrorf(http.StatusBadRequest,
			"WF Definition Query Failed")
	}

	if data == nil {
		return base.HTTPErrorf(http.StatusBadRequest,
			"WF Definition Not Found. Check Flow Def Key again.")
	}

	wf := db.NewWorkflowDef(flowDefKey)

	err = json.Unmarshal([]byte(data), &wf)

	if err != nil {
		return err
	}

	h.writeJSONStatus(http.StatusCreated, wf)
	return nil
}
Example #3
0
// HTTP handler for Flow creation
//TO DO: Need to handle validations. Last Version write for deriving correct Def Keys on update.
// need to remove flow def from URL
func (h *handler) handlePostFlowDef() error {

	// derive flow name from URL path
	flowDefName := h.PathVar("flowName")
	base.Logf("...Flow Definition Name...", flowDefName)

	//generate flow def key
	flowDefKey, err := NextFlowDefKey(h.db, flowDefName)
	base.Logf("Flow Def Key:%s", flowDefKey)

	if flowDefKey == "" {
		return base.HTTPErrorf(http.StatusBadRequest, "Could not generate Flow Def Key")
	}

	wf := db.NewWorkflowDef(flowDefKey)

	_, err = h.readObject(wf)
	if err != nil {
		return base.HTTPErrorf(http.StatusBadRequest, "Could not map JSON to WfDef Object") //TO DO: Need to relook at error
	}

	//base.Logf("Encoding Workflow Def ..%s",wf)
	data, _ := json.Marshal(wf)

	//base.Logf("Saving Workflow Def ...%s",wf)
	_, _ = h.db.PutDocRaw(flowDefKey, data)
	//base.Logf("Done save...")

	// this should be inside db trx TO DO
	//_, err =writeLastVersion(h.db , wf.Name , )

	h.writeJSONStatus(http.StatusCreated, db.Body{"ok": true, "flowDefKey": flowDefKey})
	return nil
}