2 * ============LICENSE_START========================================================================
\r
3 * ONAP : tr-069-adapter
\r
4 * =================================================================================================
\r
5 * Copyright (C) 2020 CommScope Inc Intellectual Property.
\r
6 * =================================================================================================
\r
7 * This tr-069-adapter software file is distributed by CommScope Inc under the Apache License,
\r
8 * Version 2.0 (the "License"); you may not use this file except in compliance with the License. You
\r
9 * may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
\r
14 * either express or implied. See the License for the specific language governing permissions and
\r
15 * limitations under the License.
\r
16 * ===============LICENSE_END=======================================================================
\r
19 package org.commscope.tr069adapter.vesagent.fault;
\r
21 import java.util.HashMap;
\r
22 import java.util.List;
\r
23 import java.util.Map;
\r
25 import org.apache.commons.logging.Log;
\r
26 import org.apache.commons.logging.LogFactory;
\r
27 import org.commscope.tr069adapter.acs.common.ParameterDTO;
\r
28 import org.commscope.tr069adapter.vesagent.InformEventData;
\r
29 import org.commscope.tr069adapter.vesagent.exception.InvalidFaultOperationException;
\r
30 import org.commscope.tr069adapter.vesagent.model.PnfRegEventFields;
\r
32 public class Parser {
\r
34 private Log logger = LogFactory.getLog(Parser.class);
\r
36 public Map<String, ExpeditedEvent> parseFaultParams(List<ParameterDTO> parameters)
\r
37 throws InvalidFaultOperationException {
\r
38 Map<String, ExpeditedEvent> dmAlarmParameters = new HashMap<>();
\r
41 for (ParameterDTO parameter : parameters) {
\r
42 logger.debug("PARAM NAME " + parameter.getParamName());
\r
43 if (parameter.getParamName() == null || !isAlarmEvent(parameter.getParamName())) {
\r
47 String alarmParamMO = parameter.getParamName();
\r
48 String alarmParam = null;
\r
49 String alarmParamParentMoWithIndex = null;
\r
51 if (null != alarmParamMO) {
\r
52 alarmParam = alarmParamMO.substring(alarmParamMO.lastIndexOf('.') + 1);
\r
53 alarmParamParentMoWithIndex = alarmParamMO.substring(0, alarmParamMO.lastIndexOf('.'));
\r
56 ExpeditedEvent expeditedEvent = null;
\r
57 if (dmAlarmParameters.containsKey(alarmParamParentMoWithIndex)) {
\r
58 expeditedEvent = dmAlarmParameters.get(alarmParamParentMoWithIndex);
\r
60 expeditedEvent = new ExpeditedEvent();
\r
61 logger.debug("ADDING " + alarmParamParentMoWithIndex);
\r
62 dmAlarmParameters.put(alarmParamParentMoWithIndex, expeditedEvent);
\r
65 expeditedEvent.parse(parameter, alarmParam);
\r
67 } catch (NumberFormatException ex) {
\r
68 logger.error("Error while parsing alarm event parameter {}", ex);
\r
69 throw new InvalidFaultOperationException(ex.getMessage());
\r
70 } catch (Exception e) {
\r
71 logger.error("Error occurred while parsing alarm event notification");
\r
72 throw new InvalidFaultOperationException(e.getMessage());
\r
75 return dmAlarmParameters;
\r
78 public PnfRegEventFields parseNotificationParams(List<ParameterDTO> parameters) {
\r
79 InformEventData feild = new InformEventData();
\r
81 for (ParameterDTO parameter : parameters) {
\r
83 if (isAlarmEvent(parameter.getParamName())) {
\r
87 feild.parse(parameter, parameter.getParamName());
\r
89 } catch (Exception e) {
\r
90 logger.error("Error occurred while parsing alarm event notification");
\r
93 return feild.getFeilds();
\r
96 public static boolean isAlarmEvent(String str) {
\r
97 return (str.contains(".FaultMgmt.ExpeditedEvent.")
\r
98 || str.startsWith("InternetGatewayDevice.X_0005B9_FaultStatus"));
\r