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
17 class MeterTransaction extends AbstractTransaction {
18     
19     @Property
20     val SalMeterService salMeterService;
21     
22     new(DataModification<InstanceIdentifier<? extends DataObject>, DataObject> modification,SalMeterService salMeterService) {
23         super(modification)
24         _salMeterService = salMeterService;
25     }
26     
27     override remove(InstanceIdentifier<?> instanceId, DataObject obj) {
28         if(obj instanceof Meter) {
29             val meter = (obj as Meter)
30             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
31             val builder = new RemoveMeterInputBuilder(meter);
32             builder.setNode(new NodeRef(nodeInstanceId));
33             _salMeterService.removeMeter(builder.build());            
34         }
35     }
36     
37     override update(InstanceIdentifier<?> instanceId, DataObject originalObj, DataObject updatedObj) {
38         if(originalObj instanceof Meter && updatedObj instanceof Meter) {
39             val originalMeter = (originalObj as Meter)
40             val updatedMeter = (updatedObj as Meter)
41             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
42             val builder = new UpdateMeterInputBuilder();
43             builder.setNode(new NodeRef(nodeInstanceId));
44             val ufb = new UpdatedMeterBuilder(updatedMeter);
45             builder.setUpdatedMeter((ufb.build()));
46             val ofb = new OriginalMeterBuilder(originalMeter);
47             builder.setOriginalMeter(ofb.build());      
48             _salMeterService.updateMeter(builder.build());
49            
50         }
51     }
52     
53     override add(InstanceIdentifier<?> instanceId, DataObject obj) {
54         if(obj instanceof Meter) {
55             val meter = (obj as Meter)
56             val nodeInstanceId = instanceId.firstIdentifierOf(Node);
57             val builder = new AddMeterInputBuilder(meter);
58             builder.setNode(new NodeRef(nodeInstanceId));
59             _salMeterService.addMeter(builder.build());            
60         }
61     }
62     
63     override validate() throws IllegalStateException {
64         MeterTransactionValidator.validate(this)
65     }  
66 }

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