示例#1
0
def xl_upload(confobj, wfc, doctype_name, request=None, xlfile=None):
    response_list = []
    if xlfile:
        xlreceiver = XLReceiver(confobj, wfc, xlfile=xlfile)
    else:
        xlreceiver = XLReceiver(confobj, wfc, request=request)
    if not xlreceiver.lower_key_dict:
        raise xlexc.NoDataExtractedFromExcel
    for xl_dict in xlreceiver.lower_key_dict:
        try:
            if xl_dict.get('doctype'): doctype_name = xl_dict.get('doctype')
            if xl_dict.get('action').lower() == "create":
                wf = Workflow(doctype_name, wfc=wfc)
                status_msg_dict = wf.create_doc(xl_dict)
                response_list.append(status_msg_dict)
        except xlexc.FlexFlowException as e:
            msg = e.ret_val
            response_list.append(msg)
            continue
        except Exception as e:
            msg = {"status": "Failed", "message": str(e)}
            response_list.append(msg)
            continue


#     logger.debug('got response list after calling the  the'
#                 ' workflow create_doc', status_msg_dict)
    kafka_producer.notify_kafka(confobj, wfc, response_list)
    return response_list
示例#2
0
def wfdoc_fulldetial(uniquename, wfc):
    try:
        wf = Workflow('Wfdoc', wfc=wfc)
        msg = wf.get_full_wfdoc_as_dict(uniquename, )
    except (rexc.FlexFlowException) as e:
        msg = e.ret_val
    except Exception as e:
        msg = {"status": "Failed", "message": str(e)}
    return jsonify(msg)
示例#3
0
def list_wfdoc_by_doctype(doctype, wfc):
    try:
        wf = Workflow(doctype, wfc=wfc)
        msg = wf.list_wfdoc()
    except (rexc.FlexFlowException) as e:
        msg = e.ret_val
    except Exception as e:
        msg = {"status": "Failed", "message": str(e)}
    return jsonify(msg)
示例#4
0
def wfdocdraft_fulldetial(uniquename, replace_orig_data, wfc):
    try:
        wf = Workflow('Wfdoc', wfc=wfc)
        msg = wf.get_full_doc_with_draft_data(uniquename, replace_orig_data )
    except (rexc.FlexFlowException) as e:
        msg = e.ret_val
    except Exception as e:
        msg = {"status": "Failed", "message": str(e)}
    return jsonify(msg)
示例#5
0
def action_fm_draft(uniquename, intended_action, wfc):
    try:
        addl_input = request.json.get('addl_input')
        wf = Workflow('Wfdoc', wfc=wfc)
        msg = wf.action_from_draft(uniquename, intended_action, addl_input)
    except (rexc.FlexFlowException) as e:
        msg = e.ret_val
    except Exception as e:
        msg = {"status": "Failed", "message": str(e)}
    return jsonify(msg)
示例#6
0
def wfdoc_create(doctype, wfc):
    try:           
        doc_data = request.json
        #print('data posted.................',doc_data)
        wf = Workflow(doctype, wfc=wfc)
        msg = wf.create_doc(doc_data)
    except (rexc.FlexFlowException) as e:
        msg = e.ret_val
    except Exception as e:
        msg = {"status": "Failed", "message": str(e)}
    return jsonify(msg)
示例#7
0
def wfdoc_update(wfc):
    try:
        wfdoc_name = request.json.get('wfdoc_name')
        intended_action = request.json.get('intended_action')
        doc_data = request.json.get('doc_data')
        wf = Workflow('Wfdoc', wfc=wfc)# TODO: doctype param shoikd be passed here. 'Wfdoc' was passed  worongly here , howere we were saved since the change is not dependent on the Doctyoe
        msg = wf.action_change_status(wfdoc_name, intended_action, doc_data)
    except (rexc.FlexFlowException) as e:
        msg = e.ret_val
    except Exception as e:
        msg = {"status": "Failed", "message": str(e)}
    return jsonify(msg)
示例#8
0
def wfdoc_saveasdraft(doctype, wfdoc_name, wfc):
    try:
        if "draft_data" not in request.json.keys():
            raise rexc.InvalidInputdata
        draft_data = request.json.get('draft_data')
        wf = Workflow(doctype, wfc=wfc)
        msg = wf.save_as_draft(wfdoc_name, draft_data)
    except (rexc.FlexFlowException) as e:
        msg = e.ret_val
    except Exception as e:
        msg = {"status": "Failed", "message": str(e)}
    return jsonify(msg)
示例#9
0
def update_all_from_drafts(wfc):
    print('request.json',request.json)    
    try:
        wf = Workflow('Wfdoc', wfc=wfc)
        if "wfdocs" not in request.json.keys() and \
            "intended_action" not in request.json.keys():
            raise rexc.InvalidInputdata
        wfdocs = request.json.get('wfdocs')
        intended_action = request.json.get('intended_action')        
        result_list = workers.update_all_from_drafts(flexflow_configs, wfc, wf, wfdocs, intended_action)
        print('update_all_from_draft', result_list)
    except (rexc.FlexFlowException) as e:
        msg = e.ret_val
        result_list.append(msg)
    except Exception as e:
        msg = {"status": "Failed", "message": str(e)}
        result_list.append(msg)
    return jsonify(result_list)        
示例#10
0
 def test_workflow(self):
     m.dbdriver.delete(m.Draftdata)
     m.dbdriver.delete(m.Holddoc)
     m.dbdriver.delete(m.Wfdocaudit)
     m.dbdriver.delete(m.Wfdoc)
     m.dbdriver.delete(m.Wfaction)
     m.dbdriver.delete(m.Wfstatus)
     m.dbdriver.delete(m.Datadocfield)
     m.dbdriver.delete(m.Doctype)
     self._register_doctype_n_actions()
     testconf.testwfc.roles = ['r1']
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     ##create should fail  when primary key fields in datadoc is not in rule
     try:
         msg = wf.create_doc({
             "dk1": "dv1",
             "dk2-nonprim": "dv22",
         })
     except Exception as e:
         self.assertTrue(e.status == "PrimaryKeyNotPresentInDataDict")
     ##Converts data type  when  fields dk1 is not string
     #wf.create_doc({"dk1": 100, "dk2": "dv2222", })
     ##Fail  when  fields dk3 is not present in the rule at all
     try:
         msg = wf.create_doc({
             "dk3": "not defined in the rule",
             "dk2": "dv22",
             "dk1": 100,
             "tsp": "tata",
             "division": "divison1"
         })
     except Exception as e:
         self.assertTrue(e.status == "UnknownFieldNameInDataDoc")
     ### WORKFLOW IS ABLE TO CREATE DOC
     testconf.testwfc.roles = ['r1']
     testconf.testwfc.org = 'org1'
     msg = wf.create_doc({
         "dk1": "dv1",
         "dk2": "dv22",
         "tsp": "org1",
         "division": "divison1"
     })
     self.assertTrue(msg['message'] == "has been registered")
     ####ABLE TO RETRIEVE THE BY THE PRIMKEY AS DEFINED IN THE DOCTYPE
     doc_repo = DomainRepo("Wfdoc")
     wfdocObj_list = doc_repo.list_domain_obj(name="dv22")
     self.assertTrue(wfdocObj_list[0].name == "dv22")
     ####UPDATE DOC STATUS AS PER THE ACTION RULE,
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     msg = wf.action_change_status("dv22", "wfaction1",
                                   {"dk1": "changed_data_on_action1"})
     ### check that self._validate_editable_fields(wfdocObj, data) working
     self.assertTrue(msg['status'] == "success")
     ###wdoc should be able to understand that dk2 is editable and dk1 is not
     self.assertTrue("dk2" not in [
         f.name for f in wfdocObj_list[0].editable_fields_at_current_status
     ])
     self.assertTrue("dk1" in [
         f.name for f in wfdocObj_list[0].editable_fields_at_current_status
     ])
     ###USE ROLE "hide_to_roles": ["r4", "r5"] to see that data is showing from holddoc
     #data still should show previous data {"dk1": "dv1", "dk2": "dv22", }
     testconf.testwfc.roles = ['r4']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.list_wfdoc()
     self.assertTrue(result[0].get('doc_data').get('dk1') ==
                     'dv1')  # data is showing from holddoc for role r4
     ####same for r5
     testconf.testwfc.roles = ['r5']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.list_wfdoc()
     self.assertTrue(result[0].get('doc_data').get('dk1') == 'dv1')
     #########FOR R6 AND R1 THE UPDATED DATA IS VISIBLE
     testconf.testwfc.roles = ['r1', 'r6']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.list_wfdoc()
     self.assertTrue(
         result[0].get('doc_data').get('dk1') == 'changed_data_on_action1')
     ####SHOULD FAIL FOR INCORRECT ROLE
     testconf.testwfc.roles = ['r1']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     try:
         msg = wf.action_change_status("dv22", "wfaction2")
     except rexc.RoleNotPermittedForThisAction as err:
         self.assertTrue(err.status == "RoleNotPermittedForThisAction")
     ###SHOULD PASS THE ROLE AND THE RULE
     testconf.testwfc.request_id = str(uuid.uuid4())
     testconf.testwfc.roles = ['r2']
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     msg = wf.action_change_status("dv22", "wfaction2",
                                   {"dk1": "changed_data_on_action2"})
     self.assertTrue(msg['status'] == "success")
     ##during action1 "hide_to_roles": ["r4", "r5"], and in action2 "undo_prev_hide_for": ["r4",],
     ####should be able to see latest data
     ##########hold for R4 has now been removed
     ####should be able to see latest data
     testconf.testwfc.roles = ['r4']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.list_wfdoc()
     self.assertTrue(
         result[0].get('doc_data').get('dk1') == 'changed_data_on_action2')
     ##########hold for R5 stil remains
     testconf.testwfc.roles = ['r5']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.list_wfdoc()
     self.assertTrue(
         result[0].get('doc_data').get('dk1') == 'dv1'
     )  # data remained what it was before action1 which is the data at create stage
     ####HAVE A TEST FOR RULE STATUS VALIDATION FAILURE
     testconf.testwfc.request_id = str(uuid.uuid4())
     testconf.testwfc.roles = ['r1']
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     try:
         msg = wf.action_change_status("dv22", "wfaction1")
     except rexc.WorkflowActionRuleViolation as err:
         self.assertTrue(err.status == "WorkflowActionRuleViolation")
     ####WFDOC SHOULD HAVE actions_for_current_stattus
     actions_for_current_status = [
         a.name for a in wfdocObj_list[0].actions_for_current_status
     ]
     self.assertTrue(actions_for_current_status == ['wfaction1'])
     ###fail due to data having non editable field dk1
     ###develop logic to check if the data has actually changed
     testconf.testwfc.request_id = str(uuid.uuid4())
     testconf.testwfc.roles = ['r3']
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     try:
         wf.action_change_status("dv22", "wfaction3", {
             "dk1": "dv1",
             "dk2": "dv22"
         })
     except Exception as e:
         self.assertTrue(e.status == "EditNotAllowedForThisField")
     ###get full wfdoc dict including current action list and editable field list
     msg = wf.get_full_wfdoc_as_dict('dv22')
     self.assertTrue('dk1' in msg.get('current_edit_fields'))
     self.assertTrue('wfaction3' in msg.get('current_actions'))
     ###WITH R5 ROLE SEE HOLDDOC IS CREATED
     #         testconf.testwfc.request_id = str(uuid.uuid4())
     #         testconf.testwfc.roles= ['r3']
     #         wf = Workflow('doctype2', wfc=testconf.testwfc)
     ##############################################################
     ############document was created as tsp="org1", division="division1"
     ###field to wfc mapping was tsp field maps to  org for role r1
     ###and divison maps to ou for role r3
     testconf.testwfc.org = "org2"
     testconf.testwfc.orgunit = "divison1"
     testconf.testwfc.roles = ['r3']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.list_wfdoc()
     self.assertTrue(
         result[0].get('doc_data').get('division') == 'divison1')
     ####division1 cant see when the  doc is created for  divison2
     testconf.testwfc.roles = ['r1']
     testconf.testwfc.org = 'org1'
     msg = wf.create_doc({
         "dk1": "dv1",
         "dk2": "dkdiv2",
         "tsp": "org1",
         "division": "divison2"
     })
     testconf.testwfc.org = "org2"
     testconf.testwfc.orgunit = "divison1"
     testconf.testwfc.roles = ['r3']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.list_wfdoc()
     self.assertTrue(not len(result) == 2)
     ###TSPorg2 cant see doc created by tsp=org1
     testconf.testwfc.roles = ['r1']
     testconf.testwfc.org = 'tsporg2'
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.list_wfdoc()
     self.assertTrue(not result)
     ###AT THIS STAGE ACTION 3 IS PERMITTED TO ROLE3
     ###Role3 should be able to put some data in save as draft
     testconf.testwfc.org = "org2"
     testconf.testwfc.orgunit = "divison1"
     testconf.testwfc.roles = ['r3']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     draft_data = {"dk1": "want_to_save_as_draft"}
     result = wf.save_as_draft("dv22", draft_data)
     self.assertTrue(
         result.get('draft_create_msg').get('status') == "success")
     self.assertTrue(
         result.get('wfdoc_update_msg').get('status') == "success")
     ##get draft data for  same role
     result = wf.get_draft_data_for_role('dv22')
     self.assertTrue(result.get('dk1') == 'want_to_save_as_draft')
     ##other are not seeing the draft doc even when queried
     testconf.testwfc.roles = ['r2']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.get_draft_data_for_role('dv22')
     self.assertTrue(not result)
     #list draft doc
     result = wf.list_wfdocs_superimposed_by_draft(
     )  #?????????????????????????????????
     #TODO: check why this is failing ???????
     #self.assertTrue(result[0].get('doc_data').get('dk1') == "want_to_save_as_draft")
     ##update or action  from draft
     testconf.testwfc.roles = ['r3']
     testconf.testwfc.request_id = str(uuid.uuid4())
     wf = Workflow('doctype2', wfc=testconf.testwfc)
     result = wf.action_from_draft('dv22', "wfaction3")
     self.assertTrue("want_to_save_as_draft" in result.get('message'))
示例#11
0
    def test_workflow(self):
        m.dbdriver.delete(m.Wfdoc)
        m.dbdriver.delete(m.Wfaction)
        m.dbdriver.delete(m.Wfstatus)
        m.dbdriver.delete(m.Datadocfield)
        m.dbdriver.delete(m.Doctype)
        self._register_doctype_n_actions()
        wf = Workflow('doctype2', 'r1')

        ##create should fail  when primary key fields in datadoc is not in rule
        try:
            wf.create_doc({
                "dk1": "dv1",
                "dk2-nonprim": "dv2",
            }, 'r1')
        except Exception as e:
            self.assertTrue(e.status == "PrimaryKeyNotPresentInDataDict")
        ##Fail  when  fields dk1 is not string
        try:
            wf.create_doc({
                "dk1": 100,
                "dk2": "dv2",
            }, 'r1')
        except Exception as e:
            self.assertTrue(e.status == "DataTypeViolation")
        ##Fail  when  fields dk3 is not present in the rule at all
        try:
            wf.create_doc({
                "dk3": "not defined in the rule",
                "dk2": "dv2",
            }, 'r1')
        except Exception as e:
            self.assertTrue(e.status == "UnknownFieldNameInDataDoc")
        ### WORKFLOW IS ABLE TO CREATE DOC
        msg = wf.create_doc({
            "dk1": "dv1",
            "dk2": "dv2",
        }, 'r1')
        self.assertTrue(msg['message'] == "has been registered")
        ####ABLE TO RETRIEVE THE BY THE PRIMKEY AS DEFINED IN THE DOCTYPE
        doc_repo = DomainRepo("Wfdoc")
        wfdocObj_list = doc_repo.list_domain_obj(name="dv2")
        self.assertTrue(wfdocObj_list[0].name == "dv2")
        ####UPDATE DOC STATUS AS PER THE ACTION RULE
        msg = wf.action_change_status("dv2", "wfaction1", {"dk2": "dv2"})
        ### check that self._validate_editable_fields(wfdocObj, data) working
        self.assertTrue(msg['status'] == "success")
        ###wdoc should be able to understand that dk2 is editable and dk1 is not
        self.assertTrue(
            "dk2" in wfdocObj_list[0].editable_fields_at_current_status)
        self.assertTrue(
            "dk1" not in wfdocObj_list[0].editable_fields_at_current_status)
        ####SHOULD FAIL FOR INCORRECT ROLE
        wf = Workflow('doctype2', 'r1')
        try:
            msg = wf.action_change_status("dv2", "wfaction2")
        except rexc.RoleNotPermittedForThisAction as err:
            self.assertTrue(err.status == "RoleNotPermittedForThisAction")
        ###SHOULD PASS THE ROLE AND THE RULE
        wf = Workflow('doctype2', 'r2')
        msg = wf.action_change_status("dv2", "wfaction2")
        self.assertTrue(msg['status'] == "success")
        ####HAVE A TEST FOR RULE STATUS VALIDATION FAILURE
        try:
            msg = wf.action_change_status("dv2", "wfaction1")
        except rexc.WorkflowActionRuleViolation as err:
            self.assertTrue(err.status == "WorkflowActionRuleViolation")
        ####WFDOC SHOULD HAVE actions_for_current_stattus
        actions_for_current_status = wfdocObj_list[
            0].actions_for_current_status
        self.assertTrue(actions_for_current_status == ['wfaction1'])
        ###fail due to data having non editable field dk1
        ###develop logic to check if the data has actually changed
        wf = Workflow('doctype2', 'r3')
        try:
            wf.action_change_status("dv2", "wfaction3", {
                "dk1": "dv1",
                "dk2": "dv2"
            })
        except Exception as e:
            self.assertTrue(e.status == "EditNotAllowedForThisField")