2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 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=========================================================
20 package org.onap.aai.serialization.queryformats;
22 import java.io.UnsupportedEncodingException;
23 import java.util.ArrayList;
24 import java.util.List;
26 import org.apache.tinkerpop.gremlin.structure.Vertex;
27 import org.onap.aai.db.props.AAIProperties;
28 import org.onap.aai.exceptions.AAIException;
29 import org.onap.aai.introspection.Introspector;
30 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
31 import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
33 import com.google.gson.JsonObject;
35 public class SimpleFormat extends RawFormat {
38 protected SimpleFormat(Builder builder) {
44 public int parallelThreshold() {
49 public JsonObject createPropertiesObject(Vertex v) throws AAIFormatVertexException {
51 final Introspector obj = loader.introspectorFromName(
52 v.<String>property(AAIProperties.NODE_TYPE)
56 final List<Vertex> wrapper = new ArrayList<>();
61 serializer.dbToObject(wrapper, obj, this.depth, true, "false");
62 } catch (AAIException | UnsupportedEncodingException e) {
63 throw new AAIFormatVertexException("Failed to format vertex - error while serializing: " + e.getMessage(), e);
66 final String json = obj.marshal(false);
67 return parser.parse(json).getAsJsonObject();
68 } catch (AAIUnknownObjectException e) {
69 throw new AAIFormatVertexException("Failed to format vertex - unknown object", e);