Esempio n. 1
0
class FunctionFlow(Flow):
    start = flow.StartFunction(create_test_flow).Next(this.func_task)
    default_start = flow.StartFunction().Next(this.func_task)
    inline_start = flow.StartFunction().Next(this.func_task)
    func_task = flow.Function(function_task).Next(this.handler_task)
    handler_task = flow.Handler(handler).Next(this.end)
    end = flow.End()

    def inline_start_func(self, activation):
        activation.prepare()
        activation.done()
        self.inline_start_func_called = True
        return activation
Esempio n. 2
0
class StartUndoFlow(Flow):
    start = flow.StartFunction(create_test_flow).Next(this.func_task)
    func_task = flow.Function(function_task).Next(this.end)
    end = flow.End()

    def start_undo(self, activation):
        self.handler_called = True
Esempio n. 3
0
class BaseFlow(Flow):
    start = flow.StartFunction().Next(this.end)
    handle = flow.Handler(this.handler_execute)
    end = flow.End()

    def handler_execute(self, activation):
        raise NotImplementedError
Esempio n. 4
0
class JoinTestFlow(Flow):
    start = flow.StartFunction().Next(this.split)
    split = flow.Split().Next(this.task1).Next(this.task2)
    task1 = flow.Function(func).Next(this.join)
    task2 = flow.Function(func).Next(this.join)
    join = flow.Join().Next(this.end)
    end = flow.End()
Esempio n. 5
0
class ListViewTestFlow(Flow):
    start1 = flow.StartFunction().Next(this.test_task)
    start2 = flow.Start(lambda request: None).Permission(
        'auth.start_flow_perm').Next(this.test_task)
    start3 = flow.Start(lambda request: None).Next(this.test_task)
    test_task = flow.View(lambda request: None).Next(this.end)
    end = flow.End()
Esempio n. 6
0
class SwitchTestFlow(Flow):
    start = flow.StartFunction(create_test_flow).Next(this.switch)
    switch = flow.Switch().Case(this.task1,
                                cond=lambda process: True).Default(this.task2)
    task1 = flow.Handler(handler).Next(this.end)
    task2 = flow.Handler(handler).Next(this.end)
    end = flow.End()
Esempio n. 7
0
class BrokenGateFlow(Flow):
    process_cls = BrokenGateProcess

    start = flow.StartFunction(create_test_flow).Next(this.gate)
    gate = flow.If(lambda process: process.test()).OnTrue(this.end).OnFalse(
        this.end)
    end = flow.End()
Esempio n. 8
0
class IfTestFlow(Flow):
    start = flow.StartFunction(create_test_flow).Next(this.if_task)
    if_task = flow.If(cond=lambda process: True).OnTrue(this.on_true).OnFalse(
        this.on_false)
    on_true = flow.Handler(handler).Next(this.end)
    on_false = flow.Handler(handler).Next(this.end)
    end = flow.End()
class JoinTestFlow(Flow):
    start = flow.StartFunction().Next(this.split)
    split = flow.Split().Next(this.task1).Next(this.task2)
    task1 = flow.Function(func, task_loader=lambda flow_task, task: task).Next(this.join)
    task2 = flow.Function(func, task_loader=lambda flow_task, task: task).Next(this.join)
    join = flow.Join().Next(this.end)
    end = flow.End()
Esempio n. 10
0
class ModerateAccidentFlow(Flow):
    process_class = models.AccidentPendingModeration

    start = flow.StartFunction(this.start_flow).Next(this.approve)

    approve = flow.View(UpdateProcessView, fields=[
        'approved'
    ]).Permission('icw.moderate_accident').Next(this.check_approve)

    check_approve = flow.If(
        lambda activation: activation.process.approved).Then(
            this.approved).Else(this.end)

    end = flow.End()

    def start_flow(self, activation: Activation):
        activation.prepare()
        activation.done()
        return activation

    @flow.Handler
    def approved(self, activation):
        pass

    class Meta:
        view_permission_name = 'icw.moderate_accident'
Esempio n. 11
0
        class Flow(FlowStub):
            start = flow.StartFunction()

            def start_task_func(self, activation):
                activation.prepare()
                FlowStub.method_called = True
                activation.done()
                return activation
Esempio n. 12
0
    def test_start_function_with_default_activation(self):
        def start_func(activation):
            activation.prepare()
            activation.done()
            return activation

        flow_task = self.init_node(flow.StartFunction(start_func))
        act = flow_task.run()
        self.assertEqual(act.task.status, STATUS.DONE)
Esempio n. 13
0
class SplitJoinTestFlow(Flow):
    start = flow.StartFunction(create_test_flow).Next(this.split)
    split = flow.Split().Next(this.task1).Next(this.task2).Next(
        this.task3, cond=lambda process: False)
    task1 = flow.Function(function_task).Next(this.join)
    task2 = flow.Function(function_task).Next(this.join)
    task3 = flow.Function(function_task).Next(this.join)
    join = flow.Join().Next(this.end)
    end = flow.End()
Esempio n. 14
0
        class Flow(FlowStub):
            start = flow.StartFunction(this.start_task_func)

            @method_decorator(flow.flow_start_func)
            def start_task_func(self, activation):
                activation.prepare()
                FlowStub.method_called = True
                activation.done()
                return activation
Esempio n. 15
0
class FunctionFlow(Flow):
    process_cls = TestProcess

    start = flow.StartFunction(tasks.start_process) \
        .Next(this.task1)

    task1 = flow.Handler(tasks.do_handler_task) \
        .Next(this.task2)

    task2 = flow.Function(tasks.do_func_task) \
        .Next(this.end)

    end = flow.End()
Esempio n. 16
0
    def test_start_function_inline_activation(self):
        class StartFunc(StartActivation):
            inline_called = False

            @Activation.status.super()
            def initialize(self, flow_task, task):
                StartFunc.inline_called = True
                super(StartFunc, self).initialize(flow_task, task)

            def __call__(self):
                self.prepare()
                self.done()
                return self

        flow_task = self.init_node(flow.StartFunction(StartFunc))
        act = flow_task.run()
        self.assertEqual(act.task.status, STATUS.DONE)
        self.assertTrue(StartFunc.inline_called)
Esempio n. 17
0
class RegistryApprovalFlow(Flow):
    process_cls = potential_models.PotentialApprovalProcess
    task_cls = potential_models.PotentialApprovalTask
    lock_impl = lock.select_for_update_lock

    start = flow.StartFunction(launch_func).Next(this.fill_in)

    fill_in = flow.View(FillInView).Next(this.approve).Assign(lambda p: p.created_by)

    # assign_to = flow.View(AssignToView).Next(this.approve)
        # .Assign(username='******')

    approve = flow.View(ApproveView, assign_view=AssignToView.as_view()).Next(this.check_approve)

    check_approve = flow.If(cond=lambda p: p.is_approved) \
        .OnTrue(this.end) \
        .OnFalse(this.fill_in)

    end = flow.End()
Esempio n. 18
0
class ReviewWorkFlow(Flow):
    """ Review the details of a work.
    """
    process_class = ReviewWorkProcess
    summary_template = "Review metadata for {{ process.work.frbr_uri }}"

    start = (flow.StartFunction(this.start_workflow).Next(this.instructions))

    # wait for human to do the work and then move the task into the next state
    instructions = (flow.View(
        views.HumanInteractionView,
        task_title="Review the metadata and details of the work",
        task_description=format_html(
            'View the work. The task is done if the details are correct and accurate. Make corrections if necessary.'
        ),
        task_result_summary="{{ flow_task.task_description }}",
    ).Permission('indigo_api.add_work').Next(this.end))

    end = flow.End()

    @staticmethod
    @flow.flow_start_func
    def start_workflow(activation, work):
        activation.prepare()
        activation.process.work = work
        activation.done()
        return activation

    @classmethod
    def get_or_create(cls, work):
        """ Get (or create a new) existing, unfinished process for a work.
        """
        process = cls.process_class.objects.filter(work=work,
                                                   status=STATUS.NEW).first()
        if not process:
            activation = cls.start.run(work)
            process = activation.process
        return process
Esempio n. 19
0
class StartUndoFlow(Flow):
    start = flow.StartFunction(create_test_flow).Next(this.func_task)
    func_task = flow.Function(function_task).Next(this.end)
    end = flow.End()
Esempio n. 20
0
class OrderItemFlow(Flow):
    start = flow.StartFunction(tasks.create_items_flow).Next(this.prepare)
    prepare = flow.View().Next(this.end)
    end = flow.End()
Esempio n. 21
0
class ShipmentFlow(Flow):
    """
    Delivery process
    """
    process_cls = models.ShipmentProcess

    start = flow.StartFunction(tasks.start_shipment_process) \
        .Next(this.split_clerk_warehouse)

    # clerk
    split_clerk_warehouse = flow.Split() \
        .Next(this.set_shipment_type) \
        .Next(this.package_goods)

    set_shipment_type = flow.View(views.ShipmentView, fields=["carrier"]) \
        .Permission(auto_create=True) \
        .Next(this.delivery_mode)

    delivery_mode = flow.If(cond=lambda p: p.is_normal_post()) \
        .OnTrue(this.check_insurance) \
        .OnFalse(this.request_quotes)

    request_quotes = flow.View(views.ShipmentView, fields=["carrier_quote"]) \
        .Assign(this.set_shipment_type.owner) \
        .Next(this.join_clerk_warehouse)

    check_insurance = flow.View(views.ShipmentView, fields=["need_insurance"]) \
        .Assign(this.set_shipment_type.owner) \
        .Next(this.split_on_insurance)

    split_on_insurance = flow.Split() \
        .Next(this.take_extra_insurance, cond=lambda p: p.need_extra_insurance()) \
        .Always(this.fill_post_label)

    fill_post_label = flow.View(views.ShipmentView, fields=["post_label"]) \
        .Next(this.join_on_insurance) \
        .Assign(this.set_shipment_type.owner)

    join_on_insurance = flow.Join() \
        .Next(this.join_clerk_warehouse)

    # Logistic manager
    take_extra_insurance = flow.View(views.InsuranceView) \
        .Next(this.join_on_insurance) \
        .Permission(auto_create=True)

    # Warehouse worker
    package_goods = flow.View(ProcessView) \
        .Next(this.join_clerk_warehouse) \
        .Permission(auto_create=True)

    join_clerk_warehouse = flow.Join() \
        .Next(this.move_package)

    move_package = flow.View(ProcessView.as_view()) \
        .Assign(this.package_goods.owner) \
        .Next(this.mark_order_done)

    mark_order_done = flow.Handler(tasks.done_order) \
        .Next(this.end)

    end = flow.End()
Esempio n. 22
0
class JobTestFlow(Flow):
    start = flow.StartFunction().Next(this.job)
    job = job.AbstractJob(job_handler,
                          activation_cls=JobActivation).Next(this.end)
    end = flow.End()
Esempio n. 23
0
class TestCeleryFlow(Flow):
    process_cls = TestCeleryProcess

    start = flow.StartFunction(create_test_flow).Next(this.task)
    task = celery.Job(celery_test_job).Next(this.end)
    end = flow.End()
Esempio n. 24
0
class DefaultProcessFunctionFlow(Flow):
    start = flow.StartFunction(tasks.start_process) \
        .Next(this.end)
    end = flow.End()
Esempio n. 25
0
 def test_start_function_default(self):
     flow_task = self.init_node(flow.StartFunction())
     act = flow_task.run()
     self.assertEqual(act.task.status, STATUS.DONE)
Esempio n. 26
0
class BaseViewTestFlow(Flow):
    start = flow.StartFunction().Next(this.test_task)
    test_task = flow.View(lambda request: None).Next(this.end)
    end = flow.End()
Esempio n. 27
0
class FlowEndTestFlow(Flow):
    start = flow.StartFunction().Next(this.task)
    task = flow.Function(lambda t: None).Next(this.end)
    end = flow.End()
Esempio n. 28
0
class GrantManagementFlow(Flow):
    summary_template = "{{ process.grant_application.company.name" \
                       "|default:process.grant_application.manual_company_name }} " \
                       "[{{ process.status }}]"
    process_class = GrantManagementProcess

    start = flow.StartFunction(this.start_callback,
                               task_title='Submit your application.').Next(
                                   this.send_application_submitted_email)

    send_application_submitted_email = flow.Handler(
        this.send_application_submitted_email_callback).Next(
            this.create_verify_tasks)

    # Verify Eligibility tasks
    create_verify_tasks = (flow.Split().Always(
        this.verify_previous_applications).Always(
            this.verify_event_commitment).Always(
                this.verify_business_entity).Always(
                    this.verify_state_aid).Always(this.finish_verify_tasks))

    verify_previous_applications = flow.View(
        BaseGrantManagementView,
        form_class=VerifyPreviousApplicationsForm,
        task_title='Verify number of previous grants').Next(
            this.finish_verify_tasks)

    verify_event_commitment = flow.View(
        BaseGrantManagementView,
        form_class=VerifyEventCommitmentForm,
        task_title='Verify event commitment').Next(this.finish_verify_tasks)

    verify_business_entity = flow.View(
        BaseGrantManagementView,
        form_class=VerifyBusinessEntityForm,
        task_title='Verify business eligibility').Next(
            this.finish_verify_tasks)

    verify_state_aid = flow.View(BaseGrantManagementView,
                                 form_class=VerifyStateAidForm,
                                 task_title='Verify event commitment').Next(
                                     this.finish_verify_tasks)

    finish_verify_tasks = flow.Join().Next(this.create_suitability_tasks)

    # Suitability tasks
    create_suitability_tasks = (flow.Split().Always(
        this.products_and_services).Always(
            this.products_and_services_competitors).Always(
                this.export_strategy).Always(this.event_is_appropriate).Always(
                    this.finish_suitability_tasks))

    products_and_services = flow.View(BaseGrantManagementView,
                                      form_class=ProductsAndServicesForm,
                                      task_title='Products and services').Next(
                                          this.finish_suitability_tasks)

    products_and_services_competitors = flow.View(
        BaseGrantManagementView,
        form_class=ProductsAndServicesCompetitorsForm,
        task_title='Products and services competitors').Next(
            this.finish_suitability_tasks)

    export_strategy = flow.View(BaseGrantManagementView,
                                form_class=ExportStrategyForm,
                                task_title='Export strategy').Next(
                                    this.finish_suitability_tasks)

    event_is_appropriate = flow.View(BaseGrantManagementView,
                                     form_class=EventIsAppropriateForm,
                                     task_title='Event is appropriate').Next(
                                         this.finish_suitability_tasks)

    finish_suitability_tasks = flow.Join().Next(this.decision)

    # Decision task
    decision = flow.View(
        BaseGrantManagementView,
        form_class=DecisionForm,
        task_title='Final review',
    ).Next(this.send_decision_email)

    send_decision_email = flow.Handler(this.send_decision_email_callback).Next(
        this.end)

    end = flow.End()

    @method_decorator(flow.flow_start_func)
    def start_callback(self, activation, grant_application):
        activation.prepare()
        activation.process.grant_application = grant_application
        activation.done()
        return activation.process

    def send_application_submitted_email_callback(self, activation):
        NotifyService().send_application_submitted_email(
            email_address=activation.process.grant_application.applicant_email,
            applicant_full_name=activation.process.grant_application.
            applicant_full_name,
            application_id=activation.process.grant_application.id_str)

    def send_decision_email_callback(self, activation):
        if activation.process.is_approved:
            NotifyService().send_application_approved_email(
                email_address=activation.process.grant_application.
                applicant_email,
                applicant_full_name=activation.process.grant_application.
                applicant_full_name,
                application_id=activation.process.grant_application.id_str)
        else:
            NotifyService().send_application_rejected_email(
                email_address=activation.process.grant_application.
                applicant_email,
                applicant_full_name=activation.process.grant_application.
                applicant_full_name,
                application_id=activation.process.grant_application.id_str)
Esempio n. 29
0
class ActionsTestFlow(Flow):
    start = flow.StartFunction().Next(this.task)
    if_gate = flow.If(lambda p: True).OnTrue(this.end).OnFalse(this.end)
    task = flow.View(ProcessView, fields=[]).Next(this.end)
    end = flow.End()
Esempio n. 30
0
class TestTemplateTagsFlow(Flow):
    start = flow.StartFunction().Next(this.view)
    view = flow.View(viewflow.ProcessView).Next(this.end)
    end = flow.End()