15d8bbffaddcf4d820b4abab819db6c1aa7c238e
[ccsdk/apps.git] / sdnr / wireless-transport / code-Carbon-SR1 / apps / devicemanager / impl / src / main / java / org / opendaylight / mwtn / devicemanager / impl / xml / ProblemNotificationXml.java
1 /*
2 * Copyright (c) 2016 Wipro Ltd. 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.mwtn.devicemanager.impl.xml;
10
11 import java.time.Instant;
12 import java.time.temporal.ChronoUnit;
13 import java.util.regex.Matcher;
14 import java.util.regex.Pattern;
15
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
18
19 import org.opendaylight.mwtn.base.internalTypes.InternalDateAndTime;
20 import org.opendaylight.mwtn.base.internalTypes.InternalSeverity;
21
22 import com.fasterxml.jackson.annotation.JsonIgnore;
23
24 @XmlRootElement(name = "ProblemNotification")
25 public class ProblemNotificationXml extends MwtNotificationBase implements GetEventType {
26
27     private static String EVENTTYPE =  "ProblemNotification";
28     private static final Pattern pattern = Pattern.compile(".*\\[layerProtocol=(.*)\\]");
29
30     @XmlElement(name = "problem")
31     private String problem;
32
33     @XmlElement(name = "severity")
34     private InternalSeverity severity;
35
36     public ProblemNotificationXml() {
37
38     }
39
40     /**
41      * Generic Problem.
42      * All the parameters are of type Strings according to YANG specification.
43      * @param nodeName Name of mountpoint
44      * @param uuId Name of Interface Pac
45      * @param problemNameString Name of the problem
46      * @param problemSeverityString Severitycode of the problem
47      * @param counterString Counter from device
48      * @param internaltimeStampString Timestamp according to internal format.
49      */
50     public ProblemNotificationXml(String nodeName, String uuId, String problemNameString, InternalSeverity problemSeverityString,
51             String counterString, InternalDateAndTime internaltimeStampString) {
52         super(nodeName, counterString, internaltimeStampString, uuId);
53         this.problem = problemNameString;
54         this.severity = problemSeverityString;
55     }
56
57     public String getProblem() {
58         return problem;
59     }
60
61     public InternalSeverity getSeverity() {
62         return severity;
63     }
64
65     /**
66      * Create a specific ES id for the current log.
67      * @param fault is the input.
68      * @return a string with the generated ES Id
69      */
70     @JsonIgnore
71     public String genSpecificEsId() {
72
73         String uuId;
74
75         Matcher matcher = pattern.matcher(getObjectId());
76         if (matcher.matches() && matcher.groupCount() == 1) {
77             uuId = matcher.group(1);
78         } else {
79             uuId = getObjectId();
80         }
81
82         StringBuffer strBuf = new StringBuffer();
83         strBuf.append(getNodeName());
84         strBuf.append("/");
85         strBuf.append(uuId);
86         strBuf.append("/");
87         strBuf.append(getProblem());
88         return strBuf.toString();
89     }
90
91
92     @Override
93     public String toString() {
94         return "ProblemNotificationXml [problem=" + problem + ", severity=" + severity + ", toString()="
95                 + super.toString() + "]";
96     }
97
98     @Override
99     public String getEventType() {
100         return EVENTTYPE;
101     }
102
103     @JsonIgnore
104     public String getTimeStampOffset(int off) {
105         Instant instant=Instant.parse(this.getTimeStamp());
106         return instant.truncatedTo(ChronoUnit.SECONDS).plusSeconds(off*60).toString();
107 }
108
109 }