6e295407ba0cc60c280e65316dde522973547aa8
[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, Map<String,String> searchTags ) {
60         
61         SearchableEntity se = new SearchableEntity();
62         
63         se.setEntityType(entityType);
64         se.setEntityPrimaryKeyValue(pkeyValue);
65         se.setLink(link);
66         
67         if ( searchTags != null) {
68             
69             Set<Entry<String, String>> entrySet = searchTags.entrySet();
70             
71             for ( Entry<String, String> entry : entrySet ) {
72                 se.addSearchTagWithKey(entry.getKey(), entry.getValue());
73             }
74         }
75         
76         se.deriveFields();
77         
78         return se;
79         
80     }
81     
82     protected static Map<String,String> getSearchTagMap(String... tags) {
83         
84         HashMap<String,String> dataMap = new HashMap<String,String>();
85         
86         if ( tags != null && tags.length >= 2 ) {
87             
88             int numTags = tags.length;
89             int index = 0;
90             
91             while ( index < numTags ) {
92                 
93                 if ( index + 1 < numTags ) {
94                     // we have enough parameters for the current set
95                     dataMap.put(tags[index], tags[index+1]);
96                     index += 2;
97                 } else {
98                     break;
99                 }
100             }
101             
102         }
103         
104         return dataMap;
105         
106         
107     }
108
109     @Override
110     public String toString() {
111         return "SearchableEntityList [" + (entities != null ? "entities=" + entities : "") + "]";
112     }
113
114 }