Пример #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, ''
Пример #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)
Пример #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