Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 20a141e8ec5fbaea2805e96a4b9b289433a727cd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*******************************************************************************
 * Copyright (c) 2010-2015, Andras Szabolcs Nagy, Abel Hegedus, Akos Horvath, Zoltan Ujhelyi and Daniel Varro
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v. 2.0 which is available at
 * http://www.eclipse.org/legal/epl-v20.html.
 * 
 * SPDX-License-Identifier: EPL-2.0
 *******************************************************************************/
package org.eclipse.viatra.dse.examples.bpmn.rules

import org.eclipse.viatra.dse.examples.bpmn.patterns.AllocateTaskToVariant
import org.eclipse.viatra.dse.examples.bpmn.patterns.CreateResource
import org.eclipse.viatra.dse.examples.bpmn.patterns.MakeParallel
import org.eclipse.viatra.dse.examples.bpmn.patterns.MakeSequential
import org.eclipse.viatra.dse.examples.bpmn.problems.BpmnProblems
import org.eclipse.viatra.dse.examples.bpmn.problems.SimplifiedBpmnBuilder
import org.eclipse.viatra.dse.examples.simplifiedbpmn.SimplifiedbpmnFactory
import org.eclipse.viatra.transformation.runtime.emf.rules.batch.BatchTransformationRule
import org.eclipse.viatra.transformation.runtime.emf.rules.batch.BatchTransformationRuleFactory

class BpmnRuleProvider {
    private extension BatchTransformationRuleFactory factory = new BatchTransformationRuleFactory

    public BatchTransformationRule<?, ?> allocateRule
    public BatchTransformationRule<?, ?> createResourceRule
    public BatchTransformationRule<?, ?> makeParallelRule
    public BatchTransformationRule<?, ?> makeSequentialRule
    public BatchTransformationRule<?, ?> allocateRuleFilteredExample
    

    new() {
        allocateRule = createRule
            .name("AllocateTaskToVariantRule")
            .precondition(AllocateTaskToVariant.instance())
            .action[
                t.variant = RTV
            ]
            .build

        allocateRuleFilteredExample = createRule
            .name("FilteredAllocateTaskToVariantRule")
            .precondition(AllocateTaskToVariant.instance())
            .action[
                t.variant = RTV
            ]
            .filter[
                if (it.RTV.name.equals(BpmnProblems.NOSQL_MEDIUM) ||
                    it.RTV.name.equals(BpmnProblems.SQL_MEDIUM)) {
                    return false;
                }
                return true;
            ]
            .build

        createResourceRule = createRule
            .name("CreateResourceRule")
            .precondition(CreateResource.instance())
            .action[
                RTV.instances += SimplifiedbpmnFactory.eINSTANCE.createResourceInstance()
            ]
            .build

        makeParallelRule = createRule
            .name("MakeParallelRule")
            .precondition(MakeParallel.instance())
            .action[
                val builder = new SimplifiedBpmnBuilder(root)

                val divergingGateway = builder.createParallelGateway(t1, t2, true)
                val convergingGateway = builder.createParallelGateway(t1, t2, false)

                var flows = t1.inFlows
                while (!flows.empty) {
                    val flow = flows.get(0)
                    flow.target = divergingGateway
                }
                flows = t2.outFlows
                while (!flows.empty) {
                    val flow = flows.get(0)
                    flow.source = convergingGateway
                }

                val flow = t1.outFlows.get(0)
                root.sequenceFlows -= flow
                flow.target = null
                flow.source = null

                builder.createFlow(divergingGateway, t1)
                builder.createFlow(divergingGateway, t2)
                builder.createFlow(t1, convergingGateway)
                builder.createFlow(t2, convergingGateway)
            ]
            .build

        makeSequentialRule = createRule
            .name("MakeSequentialRule")
            .precondition(MakeSequential.instance())
            .action[
                var flows = t1.inFlows
                val divergingGateway = flows.get(0).getSource()
                root.parallelGateways.remove(divergingGateway)
                root.sequenceFlows.removeAll(flows)
                flows.clear()
                flows = t2.inFlows
                root.sequenceFlows.removeAll(flows)
                flows.clear()
                flows = t1.outFlows
                root.sequenceFlows.removeAll(flows)
                flows.clear()
                flows = t2.outFlows
                val convergingGateway = flows.get(0).target
                root.parallelGateways.remove(convergingGateway)
                root.sequenceFlows.removeAll(flows)
                flows.clear()

                flows = divergingGateway.inFlows
                while (!flows.empty) {
                    val flow = flows.get(0)
                    flow.target = t1
                }
                flows = convergingGateway.getOutFlows()
                while (!flows.empty) {
                    val flow = flows.get(0)
                    flow.source = t2
                }

                new SimplifiedBpmnBuilder(root).createFlow(t1, t2)
            ]
            .build
    }
}

Back to the top