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.entities;
23 import java.io.IOException;
24 import java.util.HashMap;
26 import java.util.Optional;
28 import org.openecomp.mso.client.aai.AAICommonObjectMapperProvider;
29 import org.openecomp.mso.jsonpath.JsonPathUtil;
31 import com.fasterxml.jackson.core.type.TypeReference;
32 import com.fasterxml.jackson.databind.ObjectMapper;
34 public class AAIResultWrapper {
36 private final String jsonBody;
37 private final ObjectMapper mapper;
38 public AAIResultWrapper(String json) {
40 this.mapper = new AAICommonObjectMapperProvider().getMapper();
43 public Optional<Relationships> getRelationships() {
44 final String path = "$.relationship-list";
45 Optional<String> result = JsonPathUtil.getInstance().locateResult(jsonBody, path);
46 if (result.isPresent()) {
47 return Optional.of(new Relationships(result.get()));
49 return Optional.empty();
53 public String getJson() {
57 public Map<String, Object> asMap() {
59 return mapper.readValue(this.jsonBody, new TypeReference<Map<String, Object>>(){});
60 } catch (IOException e) {
61 return new HashMap<>();
65 public <T> Optional<T> asBean(Class<T> clazz) {
67 return Optional.of(mapper.readValue(this.jsonBody, clazz));
68 } catch (IOException e) {
69 return Optional.empty();
74 public String toString() {
75 return this.getJson();