Merge "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.group.service.rev130918.AddGroupInputBuilder
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.RemoveGroupInputBuilder
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.SalGroupService
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.UpdateGroupInputBuilder
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.OriginalGroupBuilder
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.service.rev130918.group.update.UpdatedGroupBuilder
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.GroupRef
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.group.types.rev131018.groups.Group
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
18 class GroupTransaction extends AbstractTransaction {
19     
20     @Property
21     val SalGroupService groupService;
22     
23     new(DataModification<InstanceIdentifier<? extends DataObject>, DataObject> modification,SalGroupService groupService) {
24         super(modification)
25         _groupService = groupService;
26     }
27     
28     override remove(InstanceIdentifier<?> instanceId, DataObject obj) {
29         if(obj instanceof Group) {
30             val group = (obj as Group)
31             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
32             val builder = new RemoveGroupInputBuilder(group);
33             builder.setNode(new NodeRef(nodeInstanceId));
34             builder.setGroupRef(new GroupRef(instanceId));
35             _groupService.removeGroup(builder.build());            
36         }
37     }
38     
39     override update(InstanceIdentifier<?> instanceId, DataObject originalObj, DataObject updatedObj) {
40         if(originalObj instanceof Group && updatedObj instanceof Group) {
41             val originalGroup = (originalObj as Group)
42             val updatedGroup = (updatedObj as Group)
43             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
44             val builder = new UpdateGroupInputBuilder();
45             builder.setNode(new NodeRef(nodeInstanceId));
46             builder.setGroupRef(new GroupRef(instanceId));
47             val ufb = new UpdatedGroupBuilder(updatedGroup);
48             builder.setUpdatedGroup((ufb.build()));
49             val ofb = new OriginalGroupBuilder(originalGroup);
50             builder.setOriginalGroup(ofb.build());      
51             _groupService.updateGroup(builder.build());
52            
53         }
54     }
55     
56     override add(InstanceIdentifier<?> instanceId, DataObject obj) {
57         if(obj instanceof Group) {
58             val group = (obj as Group)
59             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
60             val builder = new AddGroupInputBuilder(group);
61             builder.setNode(new NodeRef(nodeInstanceId));
62             builder.setGroupRef(new GroupRef(instanceId));
63             _groupService.addGroup(builder.build());            
64         }
65     }
66     
67     override validate() throws IllegalStateException {
68         GroupTransactionValidator.validate(this)
69     }  
70 }

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