+ private static void handleUnknownProperty(JanusGraphManagement graphMgmt, Map<String, PropertyKey> seenProps,
+ Introspector obj, String propertyName, String dbPropertyName) {
+
+ Class<?> type = obj.getClass(propertyName);
+ Cardinality cardinality = Cardinality.SINGLE;
+ boolean process = false;
+ if (obj.isListType(propertyName) && obj.isSimpleGenericType(propertyName)) {
+ cardinality = Cardinality.SET;
+ type = obj.getGenericTypeClass(propertyName);
+ process = true;
+ } else if (obj.isSimpleType(propertyName)) {
+ process = true;
+ }
+
+ if (process) {
+ String imsg =
+ "Creating PropertyKey: [" + dbPropertyName + "], [" + type.getSimpleName() + "], [" + cardinality + "]";
+ LOGGER.info(imsg);
+ PropertyKey propK;
+ propK = getPropertyKey(graphMgmt, seenProps, dbPropertyName, type, cardinality);
+ buildIndex(graphMgmt, obj, propertyName, dbPropertyName, propK);
+ }
+ }
+
+ private static void buildIndex(JanusGraphManagement graphMgmt, Introspector obj, String propertyName,
+ String dbPropertyName, PropertyKey propK) {
+ String imsg;
+ if (graphMgmt.containsGraphIndex(dbPropertyName)) {
+ String dmsg = " Index [" + dbPropertyName + "] already existed in the DB. ";
+ LOGGER.debug(dmsg);
+ } else {
+ if (obj.getIndexedProperties().contains(propertyName)) {
+ if (obj.getUniqueProperties().contains(propertyName)) {
+ imsg = "Add Unique index for PropertyKey: [" + dbPropertyName + "]";
+ LOGGER.info(imsg);
+ graphMgmt.buildIndex(dbPropertyName, Vertex.class).addKey(propK).unique().buildCompositeIndex();
+ } else {
+ imsg = "Add index for PropertyKey: [" + dbPropertyName + "]";
+ LOGGER.info(imsg);
+ graphMgmt.buildIndex(dbPropertyName, Vertex.class).addKey(propK).buildCompositeIndex();
+ }
+ } else {
+ imsg = "No index added for PropertyKey: [" + dbPropertyName + "]";
+ LOGGER.info(imsg);
+ }
+ }
+ }
+
+ private static PropertyKey getPropertyKey(JanusGraphManagement graphMgmt, Map<String, PropertyKey> seenProps,
+ String dbPropertyName, Class<?> type, Cardinality cardinality) {
+ PropertyKey propK;
+ if (!seenProps.containsKey(dbPropertyName)) {
+ propK = graphMgmt.makePropertyKey(dbPropertyName).dataType(type).cardinality(cardinality).make();
+ seenProps.put(dbPropertyName, propK);
+ } else {
+ propK = seenProps.get(dbPropertyName);
+ }
+ return propK;
+ }
+
+ private static void handleExistingProperty(String propertyName) {
+ String dmsg = " PropertyKey [" + propertyName + "] already existed in the DB. ";
+ LOGGER.debug(dmsg);
+ }
+
+ private static void addEdgeLabel(JanusGraphManagement graphMgmt, String label) {
+ if (graphMgmt.containsRelationType(label)) {
+ String dmsg = " EdgeLabel [" + label + "] already existed. ";
+ LOGGER.debug(dmsg);
+ } else {
+ String dmsg = "Making EdgeLabel: [" + label + "]";
+ LOGGER.debug(dmsg);
+ graphMgmt.makeEdgeLabel(label).multiplicity(Multiplicity.valueOf("MULTI")).make();
+ }
+ }
+