bed26024d370b6dd146c6d4ee3e73c38aa077ddd
[aai/sparky-be.git] / src / main / java / org / onap / aai / sparky / viewandinspect / entity / SearchableEntityList.java
1 /**
2  * ============LICENSE_START=======================================================
3  * org.onap.aai
4  * ================================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * Copyright © 2017 Amdocs
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  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22  */
23 package org.onap.aai.sparky.viewandinspect.entity;
24
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Map;
29 import java.util.Map.Entry;
30
31 import org.onap.aai.sparky.sync.entity.SearchableEntity;
32
33 import java.util.Set;
34
35 public class SearchableEntityList {
36
37   private List<SearchableEntity> entities;
38
39   public SearchableEntityList() {
40     entities = new ArrayList<SearchableEntity>();
41   }
42
43   public List<SearchableEntity> getEntities() {
44     return entities;
45   }
46
47   public void setEntities(List<SearchableEntity> entities) {
48     this.entities = entities;
49   }
50
51   public void addEntity(SearchableEntity entity) {
52
53     if (!entities.contains(entity)) {
54       entities.add(entity);
55     }
56
57   }
58
59   protected static SearchableEntity buildEntity(String entityType, String pkeyValue, String link,
60       Map<String, String> searchTags) {
61
62     SearchableEntity se = new SearchableEntity();
63
64     se.setEntityType(entityType);
65     se.setEntityPrimaryKeyValue(pkeyValue);
66     se.setLink(link);
67
68     if (searchTags != null) {
69
70       Set<Entry<String, String>> entrySet = searchTags.entrySet();
71
72       for (Entry<String, String> entry : entrySet) {
73         se.addSearchTagWithKey(entry.getKey(), entry.getValue());
74       }
75     }
76
77     se.deriveFields();
78
79     return se;
80
81   }
82
83   protected static Map<String, String> getSearchTagMap(String... tags) {
84
85     HashMap<String, String> dataMap = new HashMap<String, String>();
86
87     if (tags != null && tags.length >= 2) {
88
89       int numTags = tags.length;
90       int index = 0;
91
92       while (index < numTags) {
93
94         if (index + 1 < numTags) {
95           // we have enough parameters for the current set
96           dataMap.put(tags[index], tags[index + 1]);
97           index += 2;
98         } else {
99           break;
100         }
101       }
102
103     }
104
105     return dataMap;
106
107
108   }
109
110   @Override
111   public String toString() {
112     return "SearchableEntityList [" + (entities != null ? "entities=" + entities : "") + "]";
113   }
114
115 }