2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.mso.client.aai;
23 import java.util.Optional;
24 import java.util.UUID;
26 import org.openecomp.mso.client.aai.entities.CustomQuery;
27 import org.openecomp.mso.client.aai.entities.uri.AAIUri;
28 import org.openecomp.mso.client.aai.entities.uri.AAIUriFactory;
29 import org.openecomp.mso.client.policy.RestClient;
30 import org.openecomp.mso.client.aai.AAIVersion;
32 public class AAIQueryClient extends AAIClient {
35 private final AAIVersion version;
36 private Optional<String> depth = Optional.empty();
37 private boolean nodesOnly = false;
38 private Optional<AAISubgraphType> subgraph = Optional.empty();
40 public AAIQueryClient() {
41 super(UUID.randomUUID());
42 this.version = super.getVersion();
45 public AAIQueryClient(AAIVersion version, UUID requestId) {
47 this.version = version;
50 public AAIQueryClient(AAIVersion version) {
51 this(version, UUID.randomUUID());
54 public String query(Format format, CustomQuery query) {
55 return this.createClient(AAIUriFactory.createResourceUri(AAIObjectType.CUSTOM_QUERY).queryParam("format", format.toString()))
56 .addRequestId(requestId).put(query, String.class);
60 protected AAIVersion getVersion() {
64 public AAIQueryClient depth (String depth) {
65 this.depth = Optional.of(depth);
68 public AAIQueryClient nodesOnly() {
69 this.nodesOnly = true;
72 public AAIQueryClient subgraph(AAISubgraphType type){
74 subgraph = Optional.of(type);
80 public RestClient createClient(AAIUri uri) {
81 AAIUri clone = uri.clone();
82 if (this.depth.isPresent()) {
83 clone.queryParam("depth", depth.get());
86 clone.queryParam("nodesOnly", "");
88 if (this.subgraph.isPresent()) {
89 clone.queryParam("subgraph", this.subgraph.get().toString());
91 return super.createClient(clone);