Add test for generated code checking list of dependencies.
[controller.git] / opendaylight / md-sal / forwardingrules-manager / src / main / java / org / opendaylight / controller / frm / flow / FlowTransaction.xtend
1 package org.opendaylight.controller.frm.flow
2
3 import org.opendaylight.controller.frm.AbstractTransaction
4 import org.opendaylight.controller.md.sal.common.api.data.DataModification
5 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.tables.Table
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.AddFlowInputBuilder
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.FlowTableRef
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.RemoveFlowInputBuilder
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.UpdateFlowInputBuilder
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.OriginalFlowBuilder
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.flow.update.UpdatedFlowBuilder
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.types.rev131026.Flow
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
15 import org.opendaylight.yangtools.yang.binding.DataObject
16 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.service.rev130819.SalFlowService
18
19 class FlowTransaction extends AbstractTransaction {
20     
21     @Property
22     val SalFlowService salFlowService;
23     
24     new(DataModification<InstanceIdentifier<? extends DataObject>, DataObject> modification,SalFlowService salFlowService) {
25         super(modification)
26         _salFlowService = salFlowService;
27     }
28     
29     override remove(InstanceIdentifier<?> instanceId, DataObject obj) {
30         if(obj instanceof Flow) {
31             val flow = (obj as Flow)
32             val tableInstanceId = instanceId.firstIdentifierOf(Table);
33             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
34             val builder = new RemoveFlowInputBuilder(flow);
35             builder.setNode(new NodeRef(nodeInstanceId));
36             builder.setFlowTable(new FlowTableRef(tableInstanceId));
37             _salFlowService.removeFlow(builder.build());            
38         }
39     }
40     
41     override update(InstanceIdentifier<?> instanceId, DataObject originalObj, DataObject updatedObj) {
42         if(originalObj instanceof Flow && updatedObj instanceof Flow) {
43             val originalFlow = (originalObj as Flow)
44             val updatedFlow = (updatedObj as Flow)
45             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
46             val builder = new UpdateFlowInputBuilder();
47             builder.setNode(new NodeRef(nodeInstanceId));
48             val ufb = new UpdatedFlowBuilder(updatedFlow);
49             builder.setUpdatedFlow((ufb.build()));
50             val ofb = new OriginalFlowBuilder(originalFlow);
51             builder.setOriginalFlow(ofb.build());      
52             _salFlowService.updateFlow(builder.build());
53            
54         }
55     }
56     
57     override add(InstanceIdentifier<?> instanceId, DataObject obj) {
58         if(obj instanceof Flow) {
59             val flow = (obj as Flow)
60             val tableInstanceId = instanceId.firstIdentifierOf(Table);
61             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
62             val builder = new AddFlowInputBuilder(flow);
63             builder.setNode(new NodeRef(nodeInstanceId));
64             builder.setFlowTable(new FlowTableRef(tableInstanceId));
65             _salFlowService.addFlow(builder.build());            
66         }
67     }
68     
69     override validate() throws IllegalStateException {
70         FlowTransactionValidator.validate(this)
71     }  
72 }

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.