BUG-4117: add impl for FlowCapableNode Connector notif.
[openflowplugin.git] / applications / old-notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / old / notification / supplier / impl / NodeConnectorNotificationSupplierImpl.java
1 /*
2  * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6  * and is available at http://www.eclipse.org/legal/epl-v10.html
7  */
8
9 package org.opendaylight.openflowplugin.applications.old.notification.supplier.impl;
10
11 import com.google.common.base.Preconditions;
12 import org.opendaylight.controller.md.sal.binding.api.DataBroker;
13 import org.opendaylight.controller.sal.binding.api.NotificationProviderService;
14 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnector;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdated;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeConnectorUpdatedBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemoved;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorRemovedBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdated;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeConnectorUpdatedBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnector;
23 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.node.NodeConnectorKey;
24 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
25
26 /**
27  * Implementation define a contract between {@link FlowCapableNodeConnector} data object
28  * and {@link NodeConnectorUpdated} and {@link NodeConnectorRemoved} notifications.
29  */
30 public class NodeConnectorNotificationSupplierImpl extends
31         AbstractNofitSupplierFoItemRoot<FlowCapableNodeConnector, NodeConnectorUpdated, NodeConnectorRemoved> {
32
33     private static final InstanceIdentifier<FlowCapableNodeConnector> wildCardedInstanceIdent = getNodeWildII().child(NodeConnector.class).augmentation(FlowCapableNodeConnector.class);
34
35     /**
36      * Constructor register supplier as DataChangeLister and create wildCarded InstanceIdentifier.
37      *
38      * @param notifProviderService - {@link NotificationProviderService}
39      * @param db                   - {@link DataBroker}
40      */
41     public NodeConnectorNotificationSupplierImpl(final NotificationProviderService notifProviderService, final DataBroker db) {
42         super(notifProviderService, db, FlowCapableNodeConnector.class);
43     }
44
45     @Override
46     public InstanceIdentifier<FlowCapableNodeConnector> getWildCardPath() {
47         return wildCardedInstanceIdent;
48     }
49
50     @Override
51     public NodeConnectorUpdated createNotification(final FlowCapableNodeConnector o,
52                                                    final InstanceIdentifier<FlowCapableNodeConnector> path) {
53         Preconditions.checkArgument(o != null);
54         Preconditions.checkArgument(path != null);
55         final NodeConnectorUpdatedBuilder notifBuilder = new NodeConnectorUpdatedBuilder();
56         final FlowCapableNodeConnectorUpdatedBuilder connNotifBuilder = new FlowCapableNodeConnectorUpdatedBuilder(o);
57         notifBuilder.setId(path.firstKeyOf(NodeConnector.class, NodeConnectorKey.class).getId());
58         notifBuilder.setNodeConnectorRef(new NodeConnectorRef(path));
59         notifBuilder.addAugmentation(FlowCapableNodeConnectorUpdated.class, connNotifBuilder.build());
60         return notifBuilder.build();
61     }
62
63     @Override
64     public NodeConnectorRemoved deleteNotification(final InstanceIdentifier<FlowCapableNodeConnector> path) {
65         Preconditions.checkArgument(path != null);
66         final NodeConnectorRemovedBuilder notifBuilder = new NodeConnectorRemovedBuilder();
67         notifBuilder.setNodeConnectorRef(new NodeConnectorRef(path));
68         return notifBuilder.build();
69     }
70 }
71