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=========================================================
21 package org.onap.aai.serialization.queryformats;
23 import com.google.gson.JsonArray;
24 import com.google.gson.JsonObject;
25 import com.google.gson.JsonParser;
27 import java.io.UnsupportedEncodingException;
28 import java.util.ArrayList;
29 import java.util.List;
30 import java.util.Optional;
32 import org.apache.tinkerpop.gremlin.structure.Edge;
33 import org.apache.tinkerpop.gremlin.structure.Property;
34 import org.apache.tinkerpop.gremlin.structure.Vertex;
35 import org.onap.aai.db.props.AAIProperties;
36 import org.onap.aai.exceptions.AAIException;
37 import org.onap.aai.introspection.Introspector;
38 import org.onap.aai.introspection.exceptions.AAIUnknownObjectException;
39 import org.onap.aai.serialization.queryformats.exceptions.AAIFormatVertexException;
41 public class SimpleFormat extends RawFormat {
43 protected SimpleFormat(Builder builder) {
49 public int parallelThreshold() {
54 public Optional<JsonObject> createPropertiesObject(Vertex v) throws AAIFormatVertexException {
56 final Introspector obj =
57 loader.introspectorFromName(v.<String>property(AAIProperties.NODE_TYPE).orElse(null));
59 final List<Vertex> wrapper = new ArrayList<>();
64 serializer.dbToObject(wrapper, obj, this.depth, true, "false");
65 } catch (AAIException | UnsupportedEncodingException e) {
66 throw new AAIFormatVertexException(
67 "Failed to format vertex - error while serializing: " + e.getMessage(), e);
70 final String json = obj.marshal(false);
71 return Optional.of(JsonParser.parseString(json).getAsJsonObject());
72 } catch (AAIUnknownObjectException e) {
73 return Optional.empty();
79 protected void addEdge(Edge e, Vertex v, JsonArray array) throws AAIFormatVertexException {
81 Property<Object> property = e.property("private");
83 if (property.isPresent()) {
84 if ("true".equals(e.property("private").value().toString())) {
89 super.addEdge(e, v, array);