156f9226ec1ef509f7cbed83afacce7181b8f4e9
[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     }
42
43     public MwtNotificationBase(String nodeName, Integer counter, InternalDateAndTime timeStamp, String objectId) {
44         this.nodeName = nodeName;
45         this.counter = String.valueOf(counter);
46         this.timeStamp = timeStamp.getValue();
47         this.objectId = objectId;
48         if (this.objectId == null) {
49             this.objectId = EMPTY;
50         }
51     }
52
53     @XmlElement(name = "nodeName")
54     public String getNodeName() {
55         return nodeName;
56     }
57
58     @XmlElement(name = "counter")
59     public String getCounter() {
60         return counter;
61     }
62
63     @XmlElement(name = "timeStamp")
64     public String getTimeStamp() {
65         return timeStamp;
66     }
67
68     @XmlElement(name = "objectId")
69     public String getObjectId() {
70         return objectId;
71     }
72
73     /**
74      * Provide ConnectionlogEntity type
75      * @return ConnectionlogEntity
76      */
77     public ConnectionlogEntity getConnectionlogEntity() {
78         return new ConnectionlogBuilder()
79                 .setNodeId(objectId)
80                 .setStatus(getStatus())
81                 .setTimestamp(new DateAndTime(timeStamp))
82                 .build();
83     }
84
85     /**
86      * Provide connection status for mountpoint log.
87      * TODO Add status disconnected if mountpoint is required, but does not exists.
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      * @return String with type name of child class
116      */
117     @JsonProperty("type")
118     public String getType() {
119         return this.getClass().getSimpleName();
120     }
121
122     @Override
123     public String toString() {
124         return "MwtNotificationBase [getType()="+ getType() + ", nodeName=" + nodeName + ", counter=" + counter + ", timeStamp=" + timeStamp
125                 + ", objectId=" + objectId + "]";
126     }
127
128
129
130 }