2 * Copyright (c) 2016 Wipro Ltd. and others. All rights reserved.
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
9 package org.opendaylight.mwtn.devicemanager.impl.xml;
11 import java.time.Instant;
12 import java.time.temporal.ChronoUnit;
13 import java.util.regex.Matcher;
14 import java.util.regex.Pattern;
16 import javax.xml.bind.annotation.XmlElement;
17 import javax.xml.bind.annotation.XmlRootElement;
19 import org.opendaylight.mwtn.base.internalTypes.InternalDateAndTime;
20 import org.opendaylight.mwtn.base.internalTypes.InternalSeverity;
22 import com.fasterxml.jackson.annotation.JsonIgnore;
24 @XmlRootElement(name = "ProblemNotification")
25 public class ProblemNotificationXml extends MwtNotificationBase implements GetEventType {
27 private static String EVENTTYPE = "ProblemNotification";
28 private static final Pattern pattern = Pattern.compile(".*\\[layerProtocol=(.*)\\]");
30 @XmlElement(name = "problem")
31 private String problem;
33 @XmlElement(name = "severity")
34 private InternalSeverity severity;
36 public ProblemNotificationXml() {
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.
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;
57 public String getProblem() {
61 public InternalSeverity getSeverity() {
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
71 public String genSpecificEsId() {
75 Matcher matcher = pattern.matcher(getObjectId());
76 if (matcher.matches() && matcher.groupCount() == 1) {
77 uuId = matcher.group(1);
82 StringBuffer strBuf = new StringBuffer();
83 strBuf.append(getNodeName());
87 strBuf.append(getProblem());
88 return strBuf.toString();
93 public String toString() {
94 return "ProblemNotificationXml [problem=" + problem + ", severity=" + severity + ", toString()="
95 + super.toString() + "]";
99 public String getEventType() {
104 public String getTimeStampOffset(int off) {
105 Instant instant=Instant.parse(this.getTimeStamp());
106 return instant.truncatedTo(ChronoUnit.SECONDS).plusSeconds(off*60).toString();