e3923c9cc19ef62636178f9901e8ea35ea3abcdf
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START========================================================================
3  * ONAP : ccsdk feature sdnr wt
4  * =================================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property. All rights reserved.
6  * =================================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
8  * in compliance with the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software distributed under the License
13  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
14  * or implied. See the License for the specific language governing permissions and limitations under
15  * the License.
16  * ============LICENSE_END==========================================================================
17  */
18 package org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.xml;
19
20 import com.fasterxml.jackson.annotation.JsonProperty;
21 import javax.annotation.Nonnull;
22 import javax.xml.bind.annotation.XmlElement;
23 import org.onap.ccsdk.features.sdnr.wt.devicemanager.impl.util.InternalDateAndTime;
24 import org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.yang.types.rev130715.DateAndTime;
25 import org.opendaylight.yang.gen.v1.urn.opendaylight.netconf.node.topology.rev150114.NetconfNodeConnectionStatus.ConnectionStatus;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionLogStatus;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogBuilder;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev190801.ConnectionlogEntity;
29
30 public class MwtNotificationBase {
31
32     private static String EMPTY = "empty";
33
34     private String nodeName;
35     private String counter;
36     private String timeStamp;
37     private @Nonnull String objectId;
38
39     public MwtNotificationBase() {
40         // For Jaxb
41         this.objectId = EMPTY;
42     }
43
44     public MwtNotificationBase(String nodeName, Integer counter, InternalDateAndTime timeStamp, String objectId) {
45         this.nodeName = nodeName;
46         this.counter = String.valueOf(counter);
47         this.timeStamp = timeStamp.getValue();
48         this.objectId = objectId;
49         if (this.objectId == null) {
50             this.objectId = EMPTY;
51         }
52     }
53
54     @XmlElement(name = "nodeName")
55     public String getNodeName() {
56         return nodeName;
57     }
58
59     @XmlElement(name = "counter")
60     public String getCounter() {
61         return counter;
62     }
63
64     @XmlElement(name = "timeStamp")
65     public String getTimeStamp() {
66         return timeStamp;
67     }
68
69     @XmlElement(name = "objectId")
70     public String getObjectId() {
71         return objectId;
72     }
73
74     /**
75      * Provide ConnectionlogEntity type
76      * 
77      * @return ConnectionlogEntity
78      */
79     public ConnectionlogEntity getConnectionlogEntity() {
80         return new ConnectionlogBuilder().setNodeId(objectId).setStatus(getStatus())
81                 .setTimestamp(new DateAndTime(timeStamp)).build();
82     }
83
84     /**
85      * Provide connection status for mountpoint log. TODO Add status disconnected if mountpoint is required, but does
86      * not exists.
87      * 
88      * @return
89      */
90     private ConnectionLogStatus getStatus() {
91
92         if (this instanceof ObjectCreationNotificationXml) {
93             return ConnectionLogStatus.Mounted;
94
95         } else if (this instanceof ObjectDeletionNotificationXml) {
96             return ConnectionLogStatus.Unmounted;
97
98         } else if (this instanceof AttributeValueChangedNotificationXml) {
99             String pnx = ((AttributeValueChangedNotificationXml) this).getNewValue();
100             if (pnx.equals(ConnectionStatus.Connected.getName())) {
101                 return ConnectionLogStatus.Connected;
102
103             } else if (pnx.equals(ConnectionStatus.Connecting.getName())) {
104                 return ConnectionLogStatus.Connecting;
105
106             } else if (pnx.equals(ConnectionStatus.UnableToConnect.getName())) {
107                 return ConnectionLogStatus.UnableToConnect;
108             }
109         }
110         return ConnectionLogStatus.Undefined;
111     }
112
113     /**
114      * Type for the Database to document the the same name that is used in the websockets.
115      * 
116      * @return String with type name of child class
117      */
118     @JsonProperty("type")
119     public String getType() {
120         return this.getClass().getSimpleName();
121     }
122
123     @Override
124     public String toString() {
125         return "MwtNotificationBase [getType()=" + getType() + ", nodeName=" + nodeName + ", counter=" + counter
126                 + ", timeStamp=" + timeStamp + ", objectId=" + objectId + "]";
127     }
128
129
130
131 }