Convert Sparky to Spring-Boot
[aai/sparky-be.git] / sparkybe-onap-service / src / main / java / org / onap / aai / sparky / viewandinspect / entity / SearchableEntityList.java
1 /**
2  * ============LICENSE_START===================================================
3  * SPARKY (AAI UI service)
4  * ============================================================================
5  * Copyright © 2017 AT&T Intellectual Property.
6  * Copyright © 2017 Amdocs
7  * All rights reserved.
8  * ============================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=====================================================
21  *
22  * ECOMP and OpenECOMP are trademarks
23  * and service marks of AT&T Intellectual Property.
24  */
25 package org.onap.aai.sparky.viewandinspect.entity;
26
27 import java.util.ArrayList;
28 import java.util.HashMap;
29 import java.util.List;
30 import java.util.Map;
31 import java.util.Map.Entry;
32
33 import org.onap.aai.sparky.sync.entity.SearchableEntity;
34
35 import java.util.Set;
36
37 public class SearchableEntityList {
38
39     private List<SearchableEntity> entities;
40     
41     public SearchableEntityList() {
42         entities = new ArrayList<SearchableEntity>();
43     }
44
45     public List<SearchableEntity> getEntities() {
46         return entities;
47     }
48
49     public void setEntities(List<SearchableEntity> entities) {
50         this.entities = entities;
51     }
52     
53     public void addEntity(SearchableEntity entity) {
54         
55         if ( !entities.contains(entity)) {
56             entities.add(entity);
57         }
58         
59     }
60
61     protected static SearchableEntity buildEntity(String entityType, String pkeyValue, String link, Map<String,String> searchTags ) {
62         
63         SearchableEntity se = new SearchableEntity();
64         
65         se.setEntityType(entityType);
66         se.setEntityPrimaryKeyValue(pkeyValue);
67         se.setLink(link);
68         
69         if ( searchTags != null) {
70             
71             Set<Entry<String, String>> entrySet = searchTags.entrySet();
72             
73             for ( Entry<String, String> entry : entrySet ) {
74                 se.addSearchTagWithKey(entry.getKey(), entry.getValue());
75             }
76         }
77         
78         se.deriveFields();
79         
80         return se;
81         
82     }
83     
84     protected static Map<String,String> getSearchTagMap(String... tags) {
85         
86         HashMap<String,String> dataMap = new HashMap<String,String>();
87         
88         if ( tags != null && tags.length >= 2 ) {
89             
90             int numTags = tags.length;
91             int index = 0;
92             
93             while ( index < numTags ) {
94                 
95                 if ( index + 1 < numTags ) {
96                     // we have enough parameters for the current set
97                     dataMap.put(tags[index], tags[index+1]);
98                     index += 2;
99                 } else {
100                     break;
101                 }
102             }
103             
104         }
105         
106         return dataMap;
107         
108         
109     }
110
111     @Override
112     public String toString() {
113         return "SearchableEntityList [" + (entities != null ? "entities=" + entities : "") + "]";
114     }
115
116 }