OPNFLWPLUG-1032: Neon-MRI: Bump odlparent, yangtools, mdsal
[openflowplugin.git] / applications / notification-supplier / src / main / java / org / opendaylight / openflowplugin / applications / notification / supplier / impl / NodeNotificationSupplierImpl.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.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.FlowCapableNode;
15 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdated;
16 import org.opendaylight.yang.gen.v1.urn.opendaylight.flow.inventory.rev130819.FlowCapableNodeUpdatedBuilder;
17 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRef;
18 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemoved;
19 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeRemovedBuilder;
20 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdated;
21 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.NodeUpdatedBuilder;
22 import org.opendaylight.yang.gen.v1.urn.opendaylight.inventory.rev130819.nodes.Node;
23 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
24
25 /**
26  * Implementation define a contract between {@link FlowCapableNode} data object
27  * and {@link NodeUpdated} and {@link NodeRemoved} notifications.
28  */
29 public class NodeNotificationSupplierImpl extends AbstractNotificationSupplierForItemRoot<FlowCapableNode,
30         NodeUpdated, NodeRemoved> {
31
32     private static final InstanceIdentifier<FlowCapableNode> FLOW_CAPABLE_NODE_INSTANCE_IDENTIFIER = getNodeWildII()
33             .augmentation(FlowCapableNode.class);
34
35     /**
36      * Constructor register supplier as DataTreeChangeListener and create wildCarded InstanceIdentifier.
37      *
38      * @param notifProviderService - {@link NotificationProviderService}
39      * @param db                   - {@link DataBroker}
40      */
41     public NodeNotificationSupplierImpl(final NotificationProviderService notifProviderService, final DataBroker db) {
42         super(notifProviderService, db, FlowCapableNode.class);
43     }
44
45     @Override
46     public InstanceIdentifier<FlowCapableNode> getWildCardPath() {
47         return FLOW_CAPABLE_NODE_INSTANCE_IDENTIFIER;
48     }
49
50     @Override
51     public NodeUpdated createNotification(final FlowCapableNode flowCapableNode,
52                                           final InstanceIdentifier<FlowCapableNode> ii) {
53         Preconditions.checkArgument(flowCapableNode != null);
54         Preconditions.checkArgument(ii != null);
55         final FlowCapableNodeUpdatedBuilder flowNodeNotifBuilder = new FlowCapableNodeUpdatedBuilder(flowCapableNode);
56         final NodeUpdatedBuilder notifBuilder = new NodeUpdatedBuilder();
57         notifBuilder.setId(ii.firstKeyOf(Node.class).getId());
58         notifBuilder.setNodeRef(new NodeRef(getNodeII(ii)));
59         notifBuilder.addAugmentation(FlowCapableNodeUpdated.class, flowNodeNotifBuilder.build());
60         return notifBuilder.build();
61     }
62
63     @Override
64     public NodeRemoved deleteNotification(final InstanceIdentifier<FlowCapableNode> path) {
65         Preconditions.checkArgument(path != null);
66         final NodeRemovedBuilder delNodeNotifBuilder = new NodeRemovedBuilder();
67         delNodeNotifBuilder.setNodeRef(new NodeRef(path));
68         return delNodeNotifBuilder.build();
69     }
70 }
71