def _create_decision(self, node_id, activity):
        ''' create a decision after the action, if the action has more than 2 outgoings
        1. change the 2 edges source to the decisionId
        2. create a edge between action and decision, at the same time,
        create a outgoing,incoming, their xmi_idref is the id of edge,
        and change the outgoings of the action, incomings of the decision
        3. create a decision
        4. put the decision, edge to the dicts
        @param node_id: the id of the node
        @type node_id: str
        '''
        nodes_dict = activity.nodes_dict
        edges_dict = activity.edges_dict
        # get the node
        node = nodes_dict[node_id]
        # get the decision id
        # decision_id1,decision_id2
        decision_xmi_id = self._get_new_id("decision", nodes_dict)
        # "uml:DecisionNode"
        xmi_type = uml_element.Types.DECISION_NODE
        name = decision_xmi_id
        decision_outgoings = []
        node_outgoings = []
        # 1. change the 2 edges attribute source to the decision
        outgoings = node.outgoings
        for outgoing in outgoings:
            outgoing_id = outgoing.xmi_idref
            edge = edges_dict[outgoing_id]
            if edge.xmi_type == uml_element.Types.CONTROL_FLOW:
                edge.source = decision_xmi_id
                decision_outgoings.append(outgoing)
            # object flow
            else:
                node_outgoings.append(outgoing)

        # 2. create a Incoming instance for merge, a ActivityEdge instance,
        # and a Outgoing instance for node
        # 2a. create a Incoming instance. edge_id is the xmi_id in edge,
        # also the xmi_idref of the instance Incoming
        # get the id of the edge
        edge_id = self._get_new_id("edge", edges_dict)
        edge_name = edge_id
        # create incoming
        incoming = uml_element.Incoming(edge_id)
        incomings = [incoming]
        # 2b. create a ActivityEdge instance. target: decision_xmi_id, source: node_id
        new_edge = uml_element.ControlFlow(edge_id, uml_element.Types.CONTROL_FLOW, \
                                           edge_name, decision_xmi_id, node_id, None)
        # 2c. the same time, create outgoing
        # edge---incoming or outgoing
        outgoing = uml_element.Outgoing(edge_id)
        node_outgoings.append(outgoing)
        node.outgoings = node_outgoings
        # 3. create decision
        decision = uml_element.Decision(decision_xmi_id, xmi_type, name,
                                        incomings, decision_outgoings)
        # put into the dicts
        nodes_dict[decision_xmi_id] = decision
        edges_dict[edge_id] = new_edge
示例#2
0
    def test_fork_has_more_incomings(self):
        '''fork_has_more_incomings()
        '''
        activity = self.activity
        self.assertEqual(self.tclass.fork_has_more_incomings(activity), [],
                         "fork_has_more_incomings() assertEqual1 failed")
        # action1->edge1->fork
        # action2->edge2->fork

        action1 = uml_element.Action("action1", uml_element.Types.ACTION,
                                     "action1", ["1"],
                                     [uml_element.Outgoing("edge1")], None,
                                     None)
        edge1 = uml_element.ControlFlow("edge1",
                                        uml_element.Types.CONTROL_FLOW, "fork",
                                        "action1", "initial", None)

        action2 = uml_element.Action("action2", uml_element.Types.ACTION,
                                     "action2", ["2"],
                                     [uml_element.Outgoing("edge2")], None,
                                     None)
        edge2 = uml_element.ControlFlow("edge2",
                                        uml_element.Types.CONTROL_FLOW, "fork",
                                        "action2", "action1", None)

        fork = uml_element.FinalNode(
            "fork", uml_element.Types.FORK_NODE, "fork",
            [uml_element.Incoming("edge1"),
             uml_element.Incoming("edge2")], ["3"])

        activity1 = uml_element.Activity(0, uml_element.Types.ACTIVITY, 0, {},
                                         {}, {})

        activity1.edges_dict["edge1"] = edge1
        activity1.edges_dict["edge2"] = edge2
        activity1.nodes_dict["action1"] = action1
        activity1.nodes_dict["action2"] = action2
        activity1.nodes_dict["fork"] = fork
        self.assertEqual(self.tclass.fork_has_more_incomings(activity1),
                         ["fork"],
                         "fork_has_more_incomings() assertEqual2 failed")
示例#3
0
    def create_edge_object(self, edges_dict, xmi_id, xmi_type, name, target, source, guard):
        '''create instance of uml_activity_diagram_element.ActivityEdge
        from the xmi_type
        '''
        if xmi_type == uml_element.Types.CONTROL_FLOW:
            edge = uml_element.ControlFlow(xmi_id, xmi_type, name, target, source, guard)
            edges_dict[xmi_id] = edge
            # get the probability from the guard of the control flow(edge)
            cf_prob = self._get_cf_prob_from_text(guard)
            edge.prob = cf_prob

        elif xmi_type == uml_element.Types.OBJECT_FLOW:
            edge = uml_element.ObjectFlow(xmi_id, xmi_type, name, target, source, guard)
            edges_dict[xmi_id] = edge
        else:
            log.show_warn("the edge is not control flow, neither object flow")
 def _add_control_flow(self, node1, node2, activity):
     '''add one control flow from node1 to node2.
     '''
     edges_dict = activity.edges_dict
     # get the edge_id, and create a edge
     edge_id = self._get_new_id("edge", edges_dict)
     edge = uml_element.ControlFlow(edge_id, uml_element.Types.CONTROL_FLOW,
                                    edge_id, node2.xmi_id, node1.xmi_id,
                                    None)
     # node1.outgoings and node2.incomings
     outgoing = uml_element.Outgoing(edge_id)
     node1.outgoings.append(outgoing)
     incoming = uml_element.Incoming(edge_id)
     node2.incomings.append(incoming)
     # put the edge to the edge_dict
     edges_dict[edge_id] = edge
     # shwo info
     log.show_info("one control flow is created from %s to %s." %
                   (str(node1.name), str(node2.name)))
    def _create_merge(self, node_id, activity, flow_type):
        ''' create a merge before the action(fork), if the action(fork) has
        more than 2 incomings control flow
        1. change the 2 or more edges(control flow) target to the mergeId
        2. create a edge between merge and action(fork), at the same time,
        create a outgoing,incoming, their xmi_idref is the id of edge,
        and change the incomings of the action(fork), outgoings of the merge
        3. create a merge
        4. put the merge, edge to the dicts
        @attention: do not change the object flow edge
        @param node_id: the id of the node
        @type node_id: str
        @param flow_type: the type of the flow(edge).
        @type flow_type: 1.uml_element.Types.CONTROL_FLOW 2.uml_element.Types.OBJECT_FLOW
        '''

        nodes_dict = activity.nodes_dict
        edges_dict = activity.edges_dict
        # get the node
        node = nodes_dict[node_id]
        # get the merge id
        # merge_id1,merge_id2
        merge_xmi_id = self._get_new_id("merge", nodes_dict)
        # "uml:MergeNode"
        xmi_type = uml_element.Types.MERGE_NODE
        name = merge_xmi_id
        merge_incomings = []
        node_incomings = []
        # 1. change the 2 edges attribute target to the merge
        incomings = node.incomings
        for incoming in incomings:
            incoming_id = incoming.xmi_idref
            edge = edges_dict[incoming_id]
            if edge.xmi_type == uml_element.Types.CONTROL_FLOW:
                edge.target = merge_xmi_id
                merge_incomings.append(incoming)
            # object flow
            else:
                node_incomings.append(incoming)
        # 2. create a Outgoing instance for merge, a ActivityEdge instance,
        # and a Incoming instance for node
        # 2a. create a Outgoing instance. edge_id is the xmi_id in edge,
        # also the xmi_idref of the instance Outgoing

        # get the id of the edge
        edge_id = self._get_new_id("edge", edges_dict)
        edge_name = edge_id
        # create outgoing
        outgoing = uml_element.Outgoing(edge_id)
        outgoings = [outgoing]
        # 2b. create a ActivityEdge instance. target: node_id, source: merge_xmi_id
        new_edge = uml_element.ControlFlow(edge_id, flow_type, edge_name,
                                           node_id, merge_xmi_id, None)
        # 2c. the same time, create incoming
        # edge---incoming or outgoing
        incoming = uml_element.Incoming(edge_id)
        node_incomings.append(incoming)
        node.incomings = node_incomings
        # 3. create merge
        merge = uml_element.Merge(merge_xmi_id, xmi_type, name,
                                  merge_incomings, outgoings)
        # put into the dicts
        nodes_dict[merge_xmi_id] = merge
        edges_dict[edge_id] = new_edge
示例#6
0
    def setUp(self):
        '''setup
        '''
        # new the to unit test class object
        self.tclass = activity_transform_epf.AdToEpfTransformer()

        # init->edge1->action1->edge2->action2->edge4->final
        # action2->edge3->action1
        # action1->edge5->object1->edge6->action2

        initial = uml_element.InitialNode("initial", uml_element.Types.INITIAL_NODE, \
                                          "initial", [], [uml_element.Outgoing("edge1")])
        edge1 = uml_element.ControlFlow("edge1", uml_element.Types.CONTROL_FLOW, \
                                        "edge1", "action1", "initial", None)
        action1 = uml_element.Action(
            "action1", uml_element.Types.ACTION, "action1",
            [uml_element.Incoming("edge1"),
             uml_element.Incoming("edge3")],
            [uml_element.Outgoing("edge2"),
             uml_element.Outgoing("edge5")], None, None)
        edge2 = uml_element.ControlFlow("edge2",
                                        uml_element.Types.CONTROL_FLOW,
                                        "edge2", "action2", "action1", None)
        action2 = uml_element.Action(
            "action2", uml_element.Types.ACTION, "action2",
            [uml_element.Incoming("edge2"),
             uml_element.Incoming("edge6")],
            [uml_element.Outgoing("edge3"),
             uml_element.Outgoing("edge4")], None, None)
        edge4 = uml_element.ControlFlow("edge4",
                                        uml_element.Types.CONTROL_FLOW,
                                        "edge4", "final", "action2", None)
        final = uml_element.ActivityFinal(
            "final", uml_element.Types.ACTIVITY_FINAL_NODE, "final",
            [uml_element.Incoming("edge4")], [])

        edge3 = uml_element.ControlFlow("edge3",
                                        uml_element.Types.CONTROL_FLOW,
                                        "edge3", "action1", "action2", None)
        edge5 = uml_element.ControlFlow("edge5", uml_element.Types.OBJECT_FLOW,
                                        "edge5", "object1", "action1", None)
        edge6 = uml_element.ControlFlow("edge6", uml_element.Types.OBJECT_FLOW,
                                        "edge6", "action2", "object1", None)
        object1 = uml_element.ObjectNode("object1",
                                         uml_element.Types.OBJECT_NODE,
                                         "object1",
                                         [uml_element.Incoming("edge5")],
                                         [uml_element.Outgoing("edge6")])

        activity = uml_element.Activity(0, uml_element.Types.ACTIVITY, 0, {},
                                        {}, {})

        activity.edges_dict["edge1"] = edge1
        activity.edges_dict["edge2"] = edge2
        activity.edges_dict["edge3"] = edge3
        activity.edges_dict["edge4"] = edge4
        activity.edges_dict["edge5"] = edge5
        activity.edges_dict["edge6"] = edge6

        activity.nodes_dict["initial"] = initial
        activity.nodes_dict["action1"] = action1
        activity.nodes_dict["action2"] = action2
        activity.nodes_dict["object1"] = object1
        activity.nodes_dict["final"] = final
        self.activity = activity