Beispiel #1
0
    def subprocess_ref_validate(self, data, root_id=None, root_name=None):
        """
        验证子流程引用是否合法
        @param data:
        @param root_id:
        @param root_name:
        @return: 引用是否合法,相关信息
        """
        try:
            sub_refs, name_map = self.construct_subprocess_ref_graph(
                data, root_id=root_id, root_name=root_name)
        except PipelineTemplate.DoesNotExist as e:
            return False, e.message

        nodes = sub_refs.keys()
        flows = []
        for node in nodes:
            for ref in sub_refs[node]:
                if ref in nodes:
                    flows.append([node, ref])
        graph = Graph(nodes, flows)
        # circle reference check
        trace = graph.get_cycle()
        if trace:
            name_trace = u' → '.join(
                map(lambda proc_id: name_map[proc_id], trace))
            return False, _(u"子流程引用链中存在循环引用:%s") % name_trace

        return True, ''
Beispiel #2
0
    def subprocess_ref_validate(self, bundle, data, root_id=None, root_name=None):
        try:
            sub_refs, name_map = PipelineTemplate.objects.construct_subprocess_ref_graph(data, root_id=root_id,
                                                                                      root_name=root_name)
        except PipelineTemplate.DoesNotExist as e:
            raise_validation_error(self, bundle,
                                   'templates', 'data', e.message)

        nodes = sub_refs.keys()
        flows = []
        for node in nodes:
            for ref in sub_refs[node]:
                if ref in nodes:
                    flows.append([node, ref])
        graph = Graph(nodes, flows)
        # circle reference check
        trace = graph.get_cycle()
        if trace:
            name_trace = ' -> '.join(map(lambda proc_id: name_map[proc_id], trace))
            raise_validation_error(self, bundle,
                                   'templates', 'data', _(u"子流程引用链中存在循环引用:%s") % name_trace)
Beispiel #3
0
    def resolve(self):
        if self.pool:
            return

        refs = self.get_reference_info()

        nodes = refs.keys()
        flows = []
        for node in nodes:
            for ref in refs[node]:
                if ref in nodes:
                    flows.append([node, ref])
        graph = Graph(nodes, flows)
        # circle reference check
        trace = graph.get_cycle()
        if trace:
            raise ConstantReferenceException(
                'Exist circle reference between constants: %s' %
                '->'.join(trace))

        # resolve the constants reference
        pool = {}
        temp_pool = copy.deepcopy(self.raw_pool)
        # get those constants which are referenced only(not refer other constants)
        referenced_only = ConstantPool._get_referenced_only(temp_pool)
        while temp_pool:
            for ref in referenced_only:
                value = temp_pool[ref]['value']

                # resolve those constants which reference the 'ref'
                for key, info in temp_pool.iteritems():
                    maps = {deformat_constant_key(ref): value}
                    temp_pool[key]['value'] = ConstantTemplate(
                        info['value']).resolve_data(maps)

                pool[ref] = temp_pool[ref]
                temp_pool.pop(ref)
            referenced_only = ConstantPool._get_referenced_only(temp_pool)

        self.pool = pool
Beispiel #4
0
def find_graph_circle(data):
    """
    validate if a graph has not cycle

    return {
        "result": False,
        "message": "error message",
        "failed_nodes": ["dfc939e785c4484f884583beb9bb791a", "8f0bf9a291dd94627997870405eeff4d"]
    }
    """

    nodes = [data[PE.start_event][PE.id], data[PE.end_event][PE.id]]
    nodes += data[PE.gateways].keys() + data[PE.activities].keys()
    flows = [[flow[PE.source], flow[PE.target]] for _, flow in data[PE.flows].items()]
    cycle = Graph(nodes, flows).get_cycle()
    if cycle:
        return {
            'result': False,
            'message': 'pipeline graph has circle',
            'error_data': cycle
        }
    return {'result': True, 'data': []}
Beispiel #5
0
def validate_graph_cycle(data):
    """
    validate if a graph has not cycle

    return {
        "result": False,
        "message": "error message",
        "failed_nodes": ["dfc939e785c4484f884583beb9bb791a", "8f0bf9a291dd94627997870405eeff4d"]
    }
    """

    nodes = [data['start_event']['id'], data['end_event']['id']]
    nodes += data['gateways'].keys() + data['activities'].keys()
    flows = [[flow['source'], flow['target']] for __, flow in data['flows'].iteritems()]
    cycle = Graph(nodes, flows).get_cycle()
    if cycle:
        return {
            'result': False,
            'message': 'pipeline graph has cycle',
            'error_data': cycle
        }
    return {'result': True, 'data': []}