708467d0da8e474713b690d9924b850607277291
[ccsdk/features.git] /
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP : ccsdk features
4  * ================================================================================
5  * Copyright (C) 2019 highstreet technologies GmbH Intellectual Property.
6  * All rights reserved.
7  * ================================================================================
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  *     http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  * ============LICENSE_END=========================================================
20  *
21  */
22 package org.onap.ccsdk.features.sdnr.wt.dataprovider.database.elasticsearch.data.entity;
23
24 import javax.annotation.Nonnull;
25 import org.onap.ccsdk.features.sdnr.wt.dataprovider.database.sqldb.data.entity.DatabaseIdGenerator;
26 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.Fault;
27 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.FaultcurrentEntity;
28 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.data.provider.rev201110.SeverityType;
29
30 public class FaultEntityManager {
31
32     /**
33      * The leading indication for notification or events that are not in the currentProblem data of the ONF Coremodel
34      */
35     private static final String NOCURRENTPROBLEMINDICATION = "#";
36
37     /**
38      * Specific problems are not moving into current problem list
39      *
40      * @param problemName to be verified
41      * @return true if problem is current
42      */
43     public static boolean isManagedAsCurrentProblem(String problemName) {
44         return !problemName.startsWith(NOCURRENTPROBLEMINDICATION);
45     }
46
47     public static boolean isManagedAsCurrentProblem(Fault problem) {
48         return isManagedAsCurrentProblem(problem.getProblem());
49     }
50
51     /**
52      * Specific problems are not moving into current problem list
53      *
54      * @param fault to be verified
55      * @return true if cleared indication
56      */
57     public static boolean isNoAlarmIndication(@Nonnull Fault fault) {
58         return SeverityType.NonAlarmed.equals(fault.getSeverity());
59     }
60
61     /**
62      * Create a specific ES id for the current log.
63      *
64      * @return a string with the generated ES Id
65      */
66     public static String genSpecificEsId(String nodeName, String objectId, String problemName) {
67
68         String uuId = DatabaseIdGenerator.extractUuid(objectId);
69
70         StringBuffer strBuf = new StringBuffer();
71         strBuf.append(nodeName);
72         strBuf.append("/");
73         strBuf.append(uuId);
74         strBuf.append("/");
75         strBuf.append(problemName);
76         return strBuf.toString();
77     }
78
79     /**
80      * Create Es id
81      *
82      * @param fault used to create uuid for faultcurrent
83      * @return String with Id
84      */
85     public static String genSpecificEsId(FaultcurrentEntity fault) {
86         return genSpecificEsId(fault.getNodeId(), fault.getObjectId(), fault.getProblem());
87     }
88 }