2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ===================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END============================================
21 package org.onap.aai.champcore.transform;
23 import java.util.Iterator;
25 import org.apache.tinkerpop.gremlin.structure.Edge;
26 import org.apache.tinkerpop.gremlin.structure.Property;
27 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
29 import org.onap.aai.champcore.exceptions.ChampUnmarshallingException;
30 import org.onap.aai.champcore.model.ChampObject;
31 import org.onap.aai.champcore.model.ChampRelationship;
32 import org.onap.aai.champcore.model.fluent.object.ObjectBuildOrPropertiesStep;
33 import org.onap.aai.champcore.model.fluent.relationship.RelationshipBuildOrPropertiesStep;
35 public final class TinkerpopChampformer implements Champformer<Vertex, Edge> {
38 public Vertex marshallObject(ChampObject object) throws ChampUnmarshallingException {
39 throw new UnsupportedOperationException("Cannot marshall object to Tinkerpop Vertex without adding it to a graph");
43 public Edge marshallRelationship(ChampRelationship relationship) throws ChampUnmarshallingException {
44 throw new UnsupportedOperationException("Cannot marshall relationships to Tinkerpop Edge without adding it to a graph");
48 public ChampObject unmarshallObject(Vertex vertex) throws ChampUnmarshallingException {
49 final String type = vertex.label();
50 final ObjectBuildOrPropertiesStep aaiObjBuilder = ChampObject.create()
52 .withKey(vertex.id());
53 final Iterator<VertexProperty<Object>> properties = vertex.properties();
55 while (properties.hasNext()) {
56 final VertexProperty<Object> property = properties.next();
58 if (ChampObject.ReservedPropertyKeys.contains(property.key()) ||
59 ChampObject.IgnoreOnReadPropertyKeys.contains(property.key())) continue;
61 aaiObjBuilder.withProperty(property.key(), property.value());
64 return aaiObjBuilder.build();
68 public ChampRelationship unmarshallRelationship(Edge edge) throws ChampUnmarshallingException {
69 final ChampObject source = unmarshallObject(edge.outVertex());
70 final ChampObject target = unmarshallObject(edge.inVertex());
71 final String type = edge.label();
72 final RelationshipBuildOrPropertiesStep aaiRelBuilder = ChampRelationship.create()
81 final Iterator<Property<Object>> properties = edge.properties();
83 while (properties.hasNext()) {
84 final Property<Object> property = properties.next();
86 if (ChampRelationship.ReservedPropertyKeys.contains(property.key())) continue;
88 aaiRelBuilder.withProperty(property.key(), property.value());
91 return aaiRelBuilder.build();