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