Merge "Add test for generated code checking list of dependencies."
[controller.git] / opendaylight / md-sal / forwardingrules-manager / src / main / java / org / opendaylight / controller / frm / meter / MeterTransaction.xtend
1 package org.opendaylight.controller.frm.meter
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.inventory.rev130819.NodeRef
6 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node
7 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.AddMeterInputBuilder
8 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.RemoveMeterInputBuilder
9 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.SalMeterService
10 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.UpdateMeterInputBuilder
11 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.OriginalMeterBuilder
12 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.service.rev130918.meter.update.UpdatedMeterBuilder
13 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.Meter
14 import org.opendaylight.yangtools.yang.binding.DataObject
15 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.meter.types.rev130918.MeterRef
17
18 class MeterTransaction extends AbstractTransaction {
19     
20     @Property
21     val SalMeterService salMeterService;
22     
23     new(DataModification<InstanceIdentifier<? extends DataObject>, DataObject> modification,SalMeterService salMeterService) {
24         super(modification)
25         _salMeterService = salMeterService;
26     }
27     
28     override remove(InstanceIdentifier<?> instanceId, DataObject obj) {
29         if(obj instanceof Meter) {
30             val meter = (obj as Meter)
31             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
32             val builder = new RemoveMeterInputBuilder(meter);
33             builder.setNode(new NodeRef(nodeInstanceId));
34             builder.setMeterRef(new MeterRef(instanceId));
35             _salMeterService.removeMeter(builder.build());            
36         }
37     }
38     
39     override update(InstanceIdentifier<?> instanceId, DataObject originalObj, DataObject updatedObj) {
40         if(originalObj instanceof Meter && updatedObj instanceof Meter) {
41             val originalMeter = (originalObj as Meter)
42             val updatedMeter = (updatedObj as Meter)
43             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
44             val builder = new UpdateMeterInputBuilder();
45             builder.setNode(new NodeRef(nodeInstanceId));
46             builder.setMeterRef(new MeterRef(instanceId));
47             val ufb = new UpdatedMeterBuilder(updatedMeter);
48             builder.setUpdatedMeter((ufb.build()));
49             val ofb = new OriginalMeterBuilder(originalMeter);
50             builder.setOriginalMeter(ofb.build());      
51             _salMeterService.updateMeter(builder.build());
52            
53         }
54     }
55     
56     override add(InstanceIdentifier<?> instanceId, DataObject obj) {
57         if(obj instanceof Meter) {
58             val meter = (obj as Meter)
59             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
60             val builder = new AddMeterInputBuilder(meter);
61             builder.setNode(new NodeRef(nodeInstanceId));
62             builder.setMeterRef(new MeterRef(instanceId));
63             _salMeterService.addMeter(builder.build());            
64         }
65     }
66     
67     override validate() throws IllegalStateException {
68         MeterTransactionValidator.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.