Merge "fix oauth code"
[ccsdk/features.git] / sdnr / wt / devicemanager / provider / src / main / java / org / onap / ccsdk / features / sdnr / wt / devicemanager / impl / xml / ProblemNotificationXml.java
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 import java.util.regex.Matcher;
22 import java.util.regex.Pattern;
23 import javax.xml.bind.annotation.XmlElement;
24 import javax.xml.bind.annotation.XmlRootElement;
25 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalDateAndTime;
26 import org.onap.ccsdk.features.sdnr.wt.devicemanager.base.internalTypes.InternalSeverity;
27
28 @XmlRootElement(name = "ProblemNotification")
29 public class ProblemNotificationXml extends MwtNotificationBase implements GetEventType {
30
31     private static String EVENTTYPE = "ProblemNotification";
32     private static final Pattern pattern = Pattern.compile(".*\\[layerProtocol=(.*)\\]");
33     /**
34      * The leading indication for notification or events that are not in the
35      * currentProblem data of the ONF Coremodel
36      */
37     private static final String NOCURRENTPROBLEMINDICATION = "#";
38
39     @XmlElement(name = "problem")
40     private String problem;
41
42     @XmlElement(name = "severity")
43     private InternalSeverity severity;
44
45     public ProblemNotificationXml() {
46
47     }
48
49     /**
50      * Generic Problem. All the parameters are of type Strings according to YANG
51      * specification.
52      *
53      * @param nodeName                Name of mountpoint
54      * @param uuId                    Name of Interface Pac
55      * @param problemNameString       Name of the problem
56      * @param problemSeverityString   Severitycode of the problem
57      * @param counterString           Counter from device
58      * @param internaltimeStampString Timestamp according to internal format.
59      */
60     public ProblemNotificationXml(String nodeName, String uuId, String problemNameString,
61             InternalSeverity problemSeverityString, String counterString, InternalDateAndTime internaltimeStampString) {
62         super(nodeName, counterString, internaltimeStampString, uuId);
63         this.problem = problemNameString;
64         this.severity = problemSeverityString;
65     }
66
67     public String getProblem() {
68         return problem;
69     }
70
71     public InternalSeverity getSeverity() {
72         return severity;
73     }
74
75     public boolean isNotManagedAsCurrentProblem() {
76         return problem.startsWith(NOCURRENTPROBLEMINDICATION);
77     }
78
79     /**
80      * Create a specific ES id for the current log.
81      *
82      * @return a string with the generated ES Id
83      */
84     @JsonIgnore
85     public String genSpecificEsId() {
86
87         String uuId;
88
89         Matcher matcher = pattern.matcher(getObjectId());
90         if (matcher.matches() && matcher.groupCount() == 1) {
91             uuId = matcher.group(1);
92         } else {
93             uuId = getObjectId();
94         }
95
96         StringBuffer strBuf = new StringBuffer();
97         strBuf.append(getNodeName());
98         strBuf.append("/");
99         strBuf.append(uuId);
100         strBuf.append("/");
101         strBuf.append(getProblem());
102         return strBuf.toString();
103     }
104
105     @Override
106     public String toString() {
107         return "ProblemNotificationXml [problem=" + problem + ", severity=" + severity + ", toString()="
108                 + super.toString() + "]";
109     }
110
111     @Override
112     public String getEventType() {
113         return EVENTTYPE;
114     }
115 }