2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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============================================
20 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.champcore.transform;
24 import java.util.Iterator;
26 import org.apache.tinkerpop.gremlin.structure.Edge;
27 import org.apache.tinkerpop.gremlin.structure.Property;
28 import org.apache.tinkerpop.gremlin.structure.Vertex;
29 import org.apache.tinkerpop.gremlin.structure.VertexProperty;
30 import org.onap.aai.champcore.exceptions.ChampUnmarshallingException;
31 import org.onap.aai.champcore.model.ChampObject;
32 import org.onap.aai.champcore.model.ChampRelationship;
33 import org.onap.aai.champcore.model.fluent.object.ObjectBuildOrPropertiesStep;
34 import org.onap.aai.champcore.model.fluent.relationship.RelationshipBuildOrPropertiesStep;
36 public final class TinkerpopChampformer implements Champformer<Vertex, Edge> {
39 public Vertex marshallObject(ChampObject object) throws ChampUnmarshallingException {
40 throw new UnsupportedOperationException("Cannot marshall object to Tinkerpop Vertex without adding it to a graph");
44 public Edge marshallRelationship(ChampRelationship relationship) throws ChampUnmarshallingException {
45 throw new UnsupportedOperationException("Cannot marshall relationships to Tinkerpop Edge without adding it to a graph");
49 public ChampObject unmarshallObject(Vertex vertex) throws ChampUnmarshallingException {
50 final String type = vertex.label();
51 final ObjectBuildOrPropertiesStep aaiObjBuilder = ChampObject.create()
53 .withKey(vertex.id());
54 final Iterator<VertexProperty<Object>> properties = vertex.properties();
56 while (properties.hasNext()) {
57 final VertexProperty<Object> property = properties.next();
59 if (ChampObject.ReservedPropertyKeys.contains(property.key()) ||
60 ChampObject.IgnoreOnReadPropertyKeys.contains(property.key())) continue;
62 aaiObjBuilder.withProperty(property.key(), property.value());
65 return aaiObjBuilder.build();
69 public ChampRelationship unmarshallRelationship(Edge edge) throws ChampUnmarshallingException {
70 final ChampObject source = unmarshallObject(edge.outVertex());
71 final ChampObject target = unmarshallObject(edge.inVertex());
72 final String type = edge.label();
73 final RelationshipBuildOrPropertiesStep aaiRelBuilder = ChampRelationship.create()
82 final Iterator<Property<Object>> properties = edge.properties();
84 while (properties.hasNext()) {
85 final Property<Object> property = properties.next();
87 if (ChampRelationship.ReservedPropertyKeys.contains(property.key())) continue;
89 aaiRelBuilder.withProperty(property.key(), property.value());
92 return aaiRelBuilder.build();