2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * Modifications Copyright (C) 2019 IBM
8 * ===================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END============================================
22 package org.onap.aai.champjanus.graph.impl;
24 import java.io.ByteArrayOutputStream;
25 import java.io.IOException;
26 import java.io.OutputStream;
28 import org.apache.tinkerpop.gremlin.structure.Direction;
29 import org.apache.tinkerpop.gremlin.structure.Vertex;
30 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONMapper;
31 import org.apache.tinkerpop.gremlin.structure.io.graphson.GraphSONWriter;
32 import org.janusgraph.graphdb.tinkerpop.JanusGraphIoRegistry;
33 import org.onap.aai.champcore.FormatMapper;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
37 import com.google.gson.JsonObject;
38 import com.google.gson.JsonParser;
40 public class GraphSON implements FormatMapper {
41 private static final Logger LOGGER = LoggerFactory.getLogger(GraphSON.class);
42 private final GraphSONMapper mapper;
43 private final GraphSONWriter writer;
44 protected JsonParser parser;
47 this.mapper = GraphSONMapper.build().addRegistry(JanusGraphIoRegistry.getInstance()).create();
48 this.writer = GraphSONWriter.build().mapper(this.mapper).create();
49 this.parser = new JsonParser();
52 public JsonObject formatObject(Object v) {
53 OutputStream os = new ByteArrayOutputStream();
57 this.writer.writeVertex(os, (Vertex) v, Direction.BOTH);
58 result = os.toString();
59 } catch (IOException var5) {
60 LOGGER.debug("Exception occured while formatting object : " + var5.getMessage());
63 return this.parser.parse(result).getAsJsonObject();
66 public int parallelThreshold() {