8203476c82a24bc633f65270dc48bd4bf422ab40
[so.git] / common / src / main / java / org / onap / so / client / aai / entities / CustomQuery.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.client.aai.entities;
22
23 import java.io.UnsupportedEncodingException;
24 import java.util.ArrayList;
25 import java.util.List;
26
27 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
28
29 import com.fasterxml.jackson.annotation.JsonInclude;
30
31
32 @JsonInclude(JsonInclude.Include.NON_NULL) 
33 public class CustomQuery {
34         
35         private List<String> start;
36         private String query;
37         private String gremlin;
38         
39         public String getGremlin() {
40                 return gremlin;
41         }
42
43         public void setGremlin(String gremlin) {
44                 this.gremlin = gremlin;
45         }
46
47         
48         public CustomQuery(List<AAIResourceUri> start){
49                 this.setStart(start);
50         }
51         
52         public CustomQuery(List<AAIResourceUri> start, String query){
53                 this.setStart(start);
54                 this.query= "query/" + query;
55         }
56         
57         public CustomQuery(String gremlin) throws UnsupportedEncodingException{
58                 this.gremlin=gremlin;
59         }
60         
61         public List<String> getStart() {
62                 return start;
63         }
64
65         public void setStart(List<AAIResourceUri> start) {
66                 this.start = this.mapUris(start);
67         }
68
69         public String getQuery() {
70                 return query;
71         }
72
73         public void setQuery(String query) {
74                 this.query = query;
75         }
76         
77         private List<String> mapUris(List<AAIResourceUri> uris) {
78                 final List<String> result = new ArrayList<>();
79                 uris.stream().map(item -> item.build().toString()).forEach(result::add);
80                 return result;
81         }
82 }