26757170bdd8ba0a27585400723edb358ef26545
[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.JsonIgnore;
21
22 import java.util.List;
23 import java.util.regex.Matcher;
24 import java.util.regex.Pattern;
25 import javax.xml.bind.annotation.XmlElement;
26 import javax.xml.bind.annotation.XmlRootElement;
27 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime;
28 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
29 import org.slf4j.Logger;
30
31 @XmlRootElement(name = "ProblemNotification")
32 public class ProblemNotificationXml extends MwtNotificationBase implements GetEventType {
33
34     private static String EVENTTYPE = "ProblemNotification";
35     private static final Pattern pattern = Pattern.compile(".*\\[layerProtocol=(.*)\\]");
36     /**
37      * The leading indication for notification or events that are not in the
38      * currentProblem data of the ONF Coremodel
39      */
40     private static final String NOCURRENTPROBLEMINDICATION = "#";
41
42     @XmlElement(name = "problem")
43     private String problem;
44
45     @XmlElement(name = "severity")
46     private InternalSeverity severity;
47
48     public ProblemNotificationXml() {
49
50     }
51
52     /**
53      * Generic Problem. All the parameters are of type Strings according to YANG
54      * specification.
55      *
56      * @param nodeName                Name of mountpoint
57      * @param uuId                    Name of Interface Pac
58      * @param problemNameString       Name of the problem
59      * @param problemSeverityString   Severitycode of the problem
60      * @param counterString           Counter from device
61      * @param internaltimeStampString Timestamp according to internal format.
62      */
63     public ProblemNotificationXml(String nodeName, String uuId, String problemNameString,
64             InternalSeverity problemSeverityString, String counterString, InternalDateAndTime internaltimeStampString) {
65         super(nodeName, counterString, internaltimeStampString, uuId);
66         this.problem = problemNameString;
67         this.severity = problemSeverityString;
68     }
69
70     public String getProblem() {
71         return problem;
72     }
73
74     public InternalSeverity getSeverity() {
75         return severity;
76     }
77
78     public boolean isNotManagedAsCurrentProblem() {
79         return problem.startsWith(NOCURRENTPROBLEMINDICATION);
80     }
81
82     /**
83      * Create a specific ES id for the current log.
84      *
85      * @return a string with the generated ES Id
86      */
87     @JsonIgnore
88     public String genSpecificEsId() {
89
90         String uuId;
91
92         Matcher matcher = pattern.matcher(getObjectId());
93         if (matcher.matches() && matcher.groupCount() == 1) {
94             uuId = matcher.group(1);
95         } else {
96             uuId = getObjectId();
97         }
98
99         StringBuffer strBuf = new StringBuffer();
100         strBuf.append(getNodeName());
101         strBuf.append("/");
102         strBuf.append(uuId);
103         strBuf.append("/");
104         strBuf.append(getProblem());
105         return strBuf.toString();
106     }
107
108
109     @Override
110     public String toString() {
111         return "ProblemNotificationXml [problem=" + problem + ", severity=" + severity + ", toString()="
112                 + super.toString() + "]";
113     }
114
115     @Override
116     public String getEventType() {
117         return EVENTTYPE;
118     }
119
120     /**
121      * LOG the newly added problems of the interface pac
122      * @param idxStart
123      * @param uuid
124      * @param resultList
125      */
126     public static void debugResultList(Logger log, String uuid, List<ProblemNotificationXml> resultList, int idxStart) {
127         if (log.isDebugEnabled()) {
128             StringBuffer sb = new StringBuffer();
129             int idx = 0;
130             for (int t = idxStart; t < resultList.size(); t++) {
131                 sb.append(idx++);
132                 sb.append(":{");
133                 sb.append(resultList.get(t));
134                 sb.append('}');
135             }
136             log.debug("Found problems {} {}", uuid, sb.toString());
137         }
138     }
139 }