Add test for generated code checking list of dependencies.
[controller.git] / opendaylight / md-sal / forwardingrules-manager / src / main / java / org / opendaylight / controller / frm / group / GroupTransaction.xtend
1 package org.opendaylight.controller.frm.group
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 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroupBuilder
24 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.AddGroupInputBuilder
25
26 class GroupTransaction extends AbstractTransaction {
27     
28     @Property
29     val SalGroupService groupService;
30     
31     new(DataModification<InstanceIdentifier<? extends DataObject>, DataObject> modification,SalGroupService groupService) {
32         super(modification)
33         _groupService = groupService;
34     }
35     
36     override remove(InstanceIdentifier<?> instanceId, DataObject obj) {
37         if(obj instanceof Group) {
38             val group = (obj as Group)
39             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
40             val builder = new RemoveGroupInputBuilder(group);
41             builder.setNode(new NodeRef(nodeInstanceId));
42             _groupService.removeGroup(builder.build());            
43         }
44     }
45     
46     override update(InstanceIdentifier<?> instanceId, DataObject originalObj, DataObject updatedObj) {
47         if(originalObj instanceof Group && updatedObj instanceof Group) {
48             val originalGroup = (originalObj as Group)
49             val updatedGroup = (updatedObj as Group)
50             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
51             val builder = new UpdateGroupInputBuilder();
52             builder.setNode(new NodeRef(nodeInstanceId));
53             val ufb = new UpdatedGroupBuilder(updatedGroup);
54             builder.setUpdatedGroup((ufb.build()));
55             val ofb = new OriginalGroupBuilder(originalGroup);
56             builder.setOriginalGroup(ofb.build());      
57             _groupService.updateGroup(builder.build());
58            
59         }
60     }
61     
62     override add(InstanceIdentifier<?> instanceId, DataObject obj) {
63         if(obj instanceof Group) {
64             val group = (obj as Group)
65             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
66             val builder = new AddGroupInputBuilder(group);
67             builder.setNode(new NodeRef(nodeInstanceId));
68             _groupService.addGroup(builder.build());            
69         }
70     }
71     
72     override validate() throws IllegalStateException {
73         GroupTransactionValidator.validate(this)
74     }  
75 }

©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.