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.db.schema;
23 import java.util.Iterator;
24 import java.util.LinkedHashSet;
26 import org.apache.tinkerpop.gremlin.structure.Vertex;
28 import com.thinkaurelius.titan.core.EdgeLabel;
29 import com.thinkaurelius.titan.core.PropertyKey;
30 import com.thinkaurelius.titan.core.TitanGraph;
31 import com.thinkaurelius.titan.core.schema.TitanGraphIndex;
32 import com.thinkaurelius.titan.core.schema.TitanManagement;
34 public class AuditTitan extends Auditor {
36 private final TitanGraph graph;
39 * Instantiates a new audit titan.
43 public AuditTitan (TitanGraph g) {
51 private void buildSchema() {
58 * Populate properties.
60 private void populateProperties() {
61 TitanManagement mgmt = graph.openManagement();
62 Iterable<PropertyKey> iterable = mgmt.getRelationTypes(PropertyKey.class);
63 Iterator<PropertyKey> titanProperties = iterable.iterator();
65 while (titanProperties.hasNext()) {
66 propKey = titanProperties.next();
67 DBProperty prop = new DBProperty();
69 prop.setName(propKey.name());
70 prop.setCardinality(propKey.cardinality());
71 prop.setTypeClass(propKey.dataType());
73 this.properties.put(prop.getName(), prop);
80 private void populateIndexes() {
81 TitanManagement mgmt = graph.openManagement();
82 Iterable<TitanGraphIndex> iterable = mgmt.getGraphIndexes(Vertex.class);
83 Iterator<TitanGraphIndex> titanIndexes = iterable.iterator();
84 TitanGraphIndex titanIndex;
85 while (titanIndexes.hasNext()) {
86 titanIndex = titanIndexes.next();
87 if (titanIndex.isCompositeIndex()) {
88 DBIndex index = new DBIndex();
89 LinkedHashSet<DBProperty> dbProperties = new LinkedHashSet<>();
90 index.setName(titanIndex.name());
91 index.setUnique(titanIndex.isUnique());
92 PropertyKey[] keys = titanIndex.getFieldKeys();
93 for (PropertyKey key : keys) {
94 dbProperties.add(this.properties.get(key.name()));
96 index.setProperties(dbProperties);
97 index.setStatus(titanIndex.getIndexStatus(keys[0]));
98 this.indexes.put(index.getName(), index);
104 * Populate edge labels.
106 private void populateEdgeLabels() {
107 TitanManagement mgmt = graph.openManagement();
108 Iterable<EdgeLabel> iterable = mgmt.getRelationTypes(EdgeLabel.class);
109 Iterator<EdgeLabel> titanEdgeLabels = iterable.iterator();
111 while (titanEdgeLabels.hasNext()) {
112 edgeLabel = titanEdgeLabels.next();
113 EdgeProperty edgeProperty = new EdgeProperty();
115 edgeProperty.setName(edgeLabel.name());
116 edgeProperty.setMultiplicity(edgeLabel.multiplicity());
118 this.edgeLabels.put(edgeProperty.getName(), edgeProperty);