Fix sonar issues holmes-common
[holmes/common.git] / holmes-actions / src / main / java / org / onap / holmes / common / aai / entity / RelationshipList.java
1 /**
2  * Copyright 2017 ZTE Corporation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 package org.onap.holmes.common.aai.entity;
18
19 import java.util.List;
20 import lombok.Getter;
21 import lombok.Setter;
22
23 @Setter
24 @Getter
25 public class RelationshipList {
26
27     private List<Relationship> relationships;
28
29     public Relationship getRelationship(String relatedTo) {
30         Relationship relationship = null;
31         if(null == relationships || relationships.isEmpty())
32             return  relationship;
33         for(int i = 0; i < relationships.size(); i++) {
34             if (relatedTo.equals(relationships.get(i).getRelatedTo())) {
35                 relationship = relationships.get(i);
36                 break;
37             }
38         }
39         return relationship;
40     }
41
42     @Setter
43     @Getter
44     public static class Relationship {
45         private String relatedLink;
46         private String relatedTo;
47         private List<RelatedToProperty> relatedToPropertyList;
48         private List<RelationshipData> relationshipDataList;
49
50         public String getRelatedToPropertyValue(String key) {
51             String value = "";
52             if (null == relatedToPropertyList || relatedToPropertyList.isEmpty()) {
53                 return "";
54             }
55             for(int i = 0; i < relatedToPropertyList.size(); i++) {
56                 if (key.equals(relatedToPropertyList.get(i).getPropertyKey())) {
57                     value = relatedToPropertyList.get(i).getPropertyValue();
58                     break;
59                 }
60             }
61             return value;
62         }
63
64         public String getRelationshipDataValue(String key) {
65             String value = "";
66             if (null == relationshipDataList || relationshipDataList.isEmpty()) {
67                 return "";
68             }
69             for(int i = 0; i < relationshipDataList.size(); i++) {
70                 if (key.equals(relationshipDataList.get(i).getRelationshipKey())) {
71                     value = relationshipDataList.get(i).getRelationshipValue();
72                     break;
73                 }
74             }
75             return value;
76         }
77     }
78
79     @Setter
80     @Getter
81     public static class RelationshipData {
82         private String relationshipKey;
83         private String relationshipValue;
84     }
85
86     @Getter
87     @Setter
88     public static class RelatedToProperty {
89         private String propertyKey;
90         private String propertyValue;
91     }
92
93 }