aboutsummaryrefslogtreecommitdiffstats
path: root/ajsc-aai/src/main/java/org/openecomp/aai/util/RestURL.java
blob: 470754450f1635ad8fcbff7562e7b0a757778a86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
/*-
 * ============LICENSE_START=======================================================
 * org.openecomp.aai
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

package org.openecomp.aai.util;

import java.io.UnsupportedEncodingException;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Set;

import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.openecomp.aai.dbgen.DbMeth;
import org.openecomp.aai.dbmap.AAIGraph;
import org.openecomp.aai.domain.model.AAIResource;
import org.openecomp.aai.domain.model.AAIResourceKey;
import org.openecomp.aai.domain.model.AAIResourceKeys;
import org.openecomp.aai.domain.model.AAIResources;
import org.openecomp.aai.exceptions.AAIException;
import org.openecomp.aai.extensions.AAIExtensionMap;
import org.openecomp.aai.ingestModel.DbMaps;
import org.openecomp.aai.ingestModel.IngestModelMoxyOxm;
import org.springframework.web.util.UriUtils;

import com.google.common.base.CaseFormat;
import com.thinkaurelius.titan.core.TitanEdge;
import com.thinkaurelius.titan.core.TitanTransaction;
import com.thinkaurelius.titan.core.TitanTransaction;
import com.thinkaurelius.titan.core.TitanVertex;

public class RestURL {
	
	
	/*
	 * method returns a REST URL for the given node based on its nodetype and key
	 * information 
	 * Special cases for REST URLs:
	 *  - old URLS for vserver, ipaddress and volume node types for v2/v3
	 *  - images, flavor, vnic and l-interface node types will return new url
	 *  - nodetypes with multiple keys such as service capability
	 *  - nodetypes with multiple keys such as ipaddress where we use one key in the URL
	 *  - cvlan-tags and *list nodetypes - have special or no plurals - they get handled via the hash Map
	 *  
	 *      3.0 - generate links for v4-v6 as the current version and clean up the default cloud region.
	 *          - Ensures that the all links under the default cr will work but still provides non default details
	 */	

	/**
	 * Gets the.
	 *
	 * @param graph the graph
	 * @param node the node
	 * @param apiVersion the api version
	 * @param isLegacyVserverUEB the is legacy vserver UEB
	 * @param isCallbackurl the is callbackurl
	 * @return the string
	 * @throws AAIException the AAI exception
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static String get(TitanTransaction graph, TitanVertex node, String apiVersion, Boolean isLegacyVserverUEB, Boolean isCallbackurl) throws AAIException, UnsupportedEncodingException
	{
		String nodeType = node.<String>property("aai-node-type").orElse(null);
		String url = "";
     	String currentNodeType = nodeType;
     	Boolean noMoreDependentNodes = true;
     	TitanVertex currentNode = node;
     	Boolean oldVServer = false;

     	// if the caller supplies an apiVersion we'll use it, otherwise we'll just
     	// reflect back from the called URI
       	if (apiVersion == null) { 
       		apiVersion = AAIApiVersion.get();
     	}
			
       	// for v2 and v3 still return old vserver url format
		if ((apiVersion.equals("v2") || apiVersion.equals("v3")) && 
			(nodeType.equals("vserver") || nodeType.equals("ipaddress") || nodeType.equals("volume"))) 
			oldVServer = true;
		
       	if (! oldVServer) { // aai-unique-key for these will be aspirational one which we cant return
	     	String nodeURI = null;
	     	if (Boolean.parseBoolean(AAIConfig.get("aai.use.unique.key", "false")))
	     		nodeURI = node.<String>property("aai-unique-key").orElse(null);
	     	
			if (nodeURI != null && !nodeURI.equals("")) {
		    	if (isCallbackurl) {
		    		url = AAIConfig.get(AAIConstants.AAI_GLOBAL_CALLBACK_URL) + apiVersion + "/" + nodeURI;
		    		return url;
		    	} else if(isLegacyVserverUEB || (apiVersion.equals("v2") || apiVersion.equals("v3") || apiVersion.equals("v4"))) {
		    									// for v2, v3, v4 do not use the http header server host to return
		    		url = AAIConfig.get(AAIConstants.AAI_SERVER_URL_BASE) + apiVersion + "/" + nodeURI;
					return url;
		    	} else {
		    		url = AAIApiServerURLBase.get() + apiVersion + "/" + nodeURI;
					return url;
		    	}
			}
       	}
		
       	// TODO
		DbMaps dbMaps = IngestModelMoxyOxm.dbMapsContainer.get(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP));
		
     	// add the url component for the dependent on nodes for the node passed in
     	while (noMoreDependentNodes) {
        	Collection <String> depNodeTypeColl =  dbMaps.NodeDependencies.get(currentNodeType);
         	Iterator <String> depNodeTypeListIterator = (Iterator<String>) depNodeTypeColl.iterator();
         	if (!depNodeTypeListIterator.hasNext()) {
         		noMoreDependentNodes = false;
         		break;
         	}
         	
		    // Look for IN edges for the current Node and find its Parent - and make it the current Node
         	boolean foundParent = false;
		  	Iterator <Edge> inEdges = currentNode.edges(Direction.IN);
	    	while( inEdges.hasNext() ){
	    		TitanEdge inEdge = (TitanEdge) inEdges.next();
	    		Boolean inEdgeIsParent = inEdge.<Boolean>property("isParent").orElse(null);
	    		if( inEdgeIsParent != null && inEdgeIsParent ){
	    			foundParent = true;
	        		currentNode = (TitanVertex) inEdge.otherVertex(currentNode);
	        		break;
	    		}
	    	}
	    	
	    	if (foundParent == false) { 
	    		break;
	    	}
	    	
         	// find the key(s) and add to the url
	    	// first see what type of node the parent is - note some nodes can have one of many kinds of parents
	    	String depNodeType = currentNode.<String>property("aai-node-type").orElse(null);
	    	Collection <String> keyProps =  dbMaps.NodeKeyProps.get(depNodeType);
		    Iterator <String> keyPropI = keyProps.iterator();
		    
		    String nodeUrl = null;
		    String depNodeTypePlural = dbMaps.NodePlural.get(depNodeType);

			if (oldVServer) { // old server url format
			    if (depNodeType.equals("vserver") || depNodeType.equals("ipaddress") || depNodeType.equals("volume")) // no nodeType
			    	nodeUrl =  depNodeTypePlural ; 
			    else if (depNodeType.equals("tenant")) // no nodeType or plural
			    	nodeUrl = "";
			    else // this case doesnt really exist but adding to complete the logic here 
			    	if (depNodeTypePlural != null)
			    		nodeUrl = depNodeTypePlural + "/" + depNodeType + "/"; 
		    } else {
		    	if (depNodeTypePlural != null)
		    		nodeUrl = depNodeTypePlural + "/" + depNodeType + "/";
		    }		    
		    
		    while (keyPropI.hasNext()) {
		    	Object nodeKey = currentNode.<Object>property(keyPropI.next()).orElse(null);
		    	nodeUrl += encodeURL(nodeKey.toString()) + "/";
		    }
		    	    	
	        currentNodeType = depNodeType;	
			url = nodeUrl + url;
		}
     	// use the name space of the highest level of unique node since lots of children node types
     	// are common ex. l-interface is in the path for pserver and vpe
		String urlNamespace = dbMaps.NodeNamespace.get(currentNodeType) + "/"; 
		urlNamespace = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, urlNamespace);
	    
     	// add the url component for the node passed in
    	Collection <String> keyProps =  dbMaps.NodeKeyProps.get(nodeType);
	    Iterator <String> keyPropI = keyProps.iterator();
	    
	    String nodeUrl = null;
		String nodeTypePlural = "";
		nodeTypePlural = dbMaps.NodePlural.get(nodeType);
	    
	    if (oldVServer) {
	    	if (nodeTypePlural != null && !nodeTypePlural.equals(""))
	    		nodeUrl = nodeTypePlural + "/";
	    } else {
	    	if (nodeTypePlural != null && !nodeTypePlural.equals(""))
	    		nodeUrl = nodeTypePlural + "/" + nodeType + "/";
	    	else
	    		nodeUrl = nodeType + "/";
	    }

	    if (nodeType.equals("ipaddress")) { // this has 2 keys but API only uses port-or -address in URL
	    	String nodeKey = node.<String>property("port-or-interface").orElse(null);
	    	nodeUrl += encodeURL(nodeKey) + "/";
	    } else {
		    while (keyPropI.hasNext()) {
		    	Object nodeKey = node.<Object>property(keyPropI.next()).orElse(null);
		    	nodeUrl += encodeURL(nodeKey.toString()) + "/";
		    }
	    }
	    if (isCallbackurl) {
    		url = AAIConfig.get(AAIConstants.AAI_GLOBAL_CALLBACK_URL) + apiVersion + "/" + urlNamespace + url + nodeUrl;
    	} else if (oldVServer)
	    	url = AAIApiServerURLBase.get() + "servers/" + apiVersion + "/" + url + nodeUrl;
	    else {
	    	url = AAIApiServerURLBase.get() + apiVersion + "/" + urlNamespace + url + nodeUrl;
	    }
		return url;
	}

	/**
	 * Gets the search url.
	 *
	 * @param graph the graph
	 * @param node the node
	 * @param apiVersion the api version
	 * @return the search url
	 * @throws AAIException the AAI exception
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static String getSearchUrl(TitanTransaction graph, TitanVertex node, String apiVersion) throws AAIException, UnsupportedEncodingException
	{
		String nodeType = node.<String>property("aai-node-type").orElse(null);
		String url = "";
     	String currentNodeType = nodeType;
     	Boolean noMoreDependentNodes = true;
     	TitanVertex currentNode = node;
     	Boolean hasCloudRegion = false;

     	// if the caller supplies an apiVersion we'll use it, otherwise we'll just
     	// reflect back from the called URI
       	if (apiVersion == null) { 
       		apiVersion = AAIApiVersion.get();
     	}
		
		DbMaps dbMaps = IngestModelMoxyOxm.dbMapsContainer.get(AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP));
		
     	// add the url component for the dependent on nodes for the node passed in
     	while (noMoreDependentNodes) {
        	Collection <String> depNodeTypeColl =  dbMaps.NodeDependencies.get(currentNodeType);
         	Iterator <String> depNodeTypeListIterator = (Iterator<String>) depNodeTypeColl.iterator();
         	if (!depNodeTypeListIterator.hasNext()) {
         		noMoreDependentNodes = false;
         		break;
         	}
         	
		    // Look for IN edges for the current Node and find its Parent - and make it the current Node
         	boolean foundParent = false;
		  	Iterator <Edge> inEdges = currentNode.edges(Direction.IN);
	    	while( inEdges.hasNext() ){
	    		TitanEdge inEdge = (TitanEdge) inEdges.next();
	    		Boolean inEdgeIsParent = inEdge.<Boolean>property("isParent").orElse(null);
	    		if( inEdgeIsParent != null && inEdgeIsParent ){
	    			foundParent = true;
	        		currentNode = inEdge.otherVertex(currentNode);
	        		break;
	    		}
	    	}
	    	
	    	if (foundParent == false) { 
	    		break;
	    	}
	    	
         	// find the key(s) and add to the url
	    	// first see what type of node the parent is - note some nodes can have one of many kinds of parents
	    	String depNodeType = currentNode.<String>property("aai-node-type").orElse(null);
	    	Collection <String> keyProps =  dbMaps.NodeKeyProps.get(depNodeType);
		    Iterator <String> keyPropI = keyProps.iterator();
		    
		    String nodeUrl = null;
		    String depNodeTypePlural = dbMaps.NodePlural.get(depNodeType);

	    	if (depNodeTypePlural != null)
	    		nodeUrl = depNodeTypePlural + "/" + depNodeType + "/";

		    while (keyPropI.hasNext()) {
		    	Object nodeKey = currentNode.<Object>property(keyPropI.next()).orElse(null);
		    	nodeUrl += encodeURL(nodeKey.toString()) + "/";
		    }
		    	    	
	        currentNodeType = depNodeType;	
			url = nodeUrl + url;
		}
     	// use the name space of the highest level of unique node since lots of children node types
     	// are common ex. l-interface is in the path for pserver and vpe
		String urlNamespace = dbMaps.NodeNamespace.get(currentNodeType) + "/"; 
		urlNamespace = CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_HYPHEN, urlNamespace);
	    
     	// add the url component for the node passed in
    	Collection <String> keyProps =  dbMaps.NodeKeyProps.get(nodeType);
	    Iterator <String> keyPropI = keyProps.iterator();
	    
	    String nodeUrl = null;
		String nodeTypePlural = "";
		nodeTypePlural = dbMaps.NodePlural.get(nodeType);
	    
    	if (nodeTypePlural != null && !nodeTypePlural.equals(""))
    		nodeUrl = nodeTypePlural + "/" + nodeType + "/";
    	else
    		nodeUrl = nodeType + "/";

	    if (nodeType.equals("ipaddress")) { // this has 2 keys but API only uses port-or -address in URL
	    	String nodeKey = node.<String>property("port-or-interface").orElse(null);
	    	nodeUrl += encodeURL(nodeKey) + "/";
	    } else {
		    while (keyPropI.hasNext()) {
		    	Object nodeKey = node.<Object>property(keyPropI.next()).orElse(null);
		    	nodeUrl += encodeURL(nodeKey.toString()) + "/";
		    }
	    }

    	String nodeVersion = dbMaps.NodeVersionInfoMap.get(nodeType);	     	
    	String urlVersion = null;
    	int nodeVerNum = Integer.parseInt(nodeVersion.substring(1));
    	int apiVerNum  = Integer.parseInt(apiVersion.substring(1));
    			    		
    	if (nodeVerNum == apiVerNum || nodeVerNum < apiVerNum)
    		urlVersion = apiVersion;			
    	else 
    		urlVersion = nodeVersion;
			
    	url = AAIApiServerURLBase.get() + urlVersion + "/" + urlNamespace + url + nodeUrl;

		return url;
	}
	
	/**
	 * Gets the.
	 *
	 * @param graph the graph
	 * @param node the node
	 * @return the string
	 * @throws AAIException the AAI exception
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static String get(TitanTransaction graph, TitanVertex node) throws AAIException, UnsupportedEncodingException
	{
		return get(graph, node, null, false, false);
	}
	
	/**
	 * Gets the.
	 *
	 * @param graph the graph
	 * @param node the node
	 * @param apiVersion the api version
	 * @return the string
	 * @throws AAIException the AAI exception
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static String get(TitanTransaction graph, TitanVertex node, String apiVersion) throws AAIException, UnsupportedEncodingException
	{
		return get(graph, node, apiVersion, false, false);
	}
	
	/**
	 * Gets the.
	 *
	 * @param graph the graph
	 * @param node the node
	 * @param apiVersion the api version
	 * @param isLegacyVserverUEB the is legacy vserver UEB
	 * @return the string
	 * @throws AAIException the AAI exception
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static String get(TitanTransaction graph, TitanVertex node, String apiVersion, Boolean isLegacyVserverUEB) throws AAIException, UnsupportedEncodingException
	{
		return get(graph, node, apiVersion, isLegacyVserverUEB, false);
	}
	
	/**
	 * Gets the key hashes.
	 *
	 * @param graph the graph
	 * @param node the node
	 * @return the key hashes
	 * @throws AAIException the AAI exception
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static LinkedHashMap<String, Object> getKeyHashes(TitanTransaction graph, TitanVertex node) throws AAIException, UnsupportedEncodingException
	{
		return getKeyHashes(graph, node, null);
	}
	
	/**
	 * Encode URL.
	 *
	 * @param nodeKey the node key
	 * @return the string
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static final String encodeURL (String nodeKey) throws UnsupportedEncodingException {
		return UriUtils.encodePath(nodeKey, "UTF-8").replaceAll("\\+", "%20");
	}
	
	/*
	 * method returns a Hash of Hashes for each parents keys for the given node based on its nodetype 
	 * Special cases for REST URLs:
	 *  - old URLS for vserver, ipaddress and volume node types for v2/v3
	 *  - images, flavor, vnic and l-interface node types will return new url
	 *  - nodetypes with multiple keys such as service capability
	 *  - nodetypes with multiple keys such as ipaddress where we use one key in the URL
	 *  - cvlan-tags and *list nodetypes - have special or no plurals - they get handled via the hash Map
	 */	

	/**
	 * Gets the key hashes.
	 *
	 * @param graph the graph
	 * @param node the node
	 * @param apiVersion the api version
	 * @return the key hashes
	 * @throws AAIException the AAI exception
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static LinkedHashMap <String,Object> getKeyHashes(TitanTransaction graph, TitanVertex node, String apiVersion) throws AAIException, UnsupportedEncodingException
	{
		String nodeType = node.<String>property("aai-node-type").orElse(null);
     	Boolean noMoreDependentNodes = true;
     	TitanVertex currentNode = node;
     
       	if (apiVersion == null || apiVersion.equals("")) { 
       		apiVersion = AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP);
     	}
       	
		DbMaps dbMaps = IngestModelMoxyOxm.dbMapsContainer.get(apiVersion);
		
       	// Hash of hashes of keys for each node and its ancestry
		LinkedHashMap <String,Object> returnHash = new LinkedHashMap <String,Object> ();
		
     	// create the hash for the keys for the node passed in
     	HashMap <String,Object> thisNodeHash = new HashMap <String,Object> ();
    	Collection <String> keyProps =  dbMaps.NodeKeyProps.get(nodeType);
	    Iterator <String> keyPropI = keyProps.iterator();
	    
	    if (nodeType.equals("ipaddress")) { // this has 2 keys but API only uses port-or -address in URL
	    	String nodeKeyValue = node.<String>property("port-or-interface").orElse(null);
	    	thisNodeHash.put("port-or-interface", nodeKeyValue);
	    } else {
		    while (keyPropI.hasNext()) {
		    	String nodeKeyName = keyPropI.next();
		    	Object nodeKeyValue = node.<Object>property(nodeKeyName).orElse(null);
		    	thisNodeHash.put(nodeKeyName, nodeKeyValue);
		    	nodeKeyName =  nodeType + "." + nodeKeyName;
		    }
	    }
	    returnHash.putAll(thisNodeHash);	    
			
     	// create and add the hashes for the dependent nodes for the node passed in
     	while (noMoreDependentNodes) {
//        	Collection <String> depNodeTypeColl =  DbRules.NodeDependencies.get(currentNodeType);
//         	Iterator <String> depNodeTypeListIterator = (Iterator<String>) depNodeTypeColl.iterator();
         	HashMap <String,Object> depNodeHash = new HashMap <String,Object> ();
//         	
//         	if (!depNodeTypeListIterator.hasNext()) {
//         		noMoreDependentNodes = false;
//         		break;
//         	}
         	
         	boolean foundParent = false;
         	
		    // Look for IN edges for the current Node and find its Parent - and make it the current Node
		  	Iterator <Edge> inEdges = currentNode.edges(Direction.IN);
	    	while( inEdges.hasNext() ){
	    		TitanEdge inEdge = (TitanEdge) inEdges.next();
	    		Boolean inEdgeIsParent = inEdge.<Boolean>property("isParent").orElse(null);
	    		if( inEdgeIsParent != null && inEdgeIsParent ){
	        		currentNode = inEdge.otherVertex(currentNode);
	        		foundParent = true;
	        		break;
	    		}
	    	}
	    	if (foundParent == false) { 
	    		break;
	    	}
	    	
         	// find the key(s) and add to the url
	    	// first see what type of node the parent is - note some nodes can have one of many kinds of parents
	    	String depNodeType = currentNode.<String>property("aai-node-type").orElse(null);
	    	keyProps =  dbMaps.NodeKeyProps.get(depNodeType);
		    keyPropI = keyProps.iterator();
		    		    
		    while (keyPropI.hasNext()) {
		    	String nodeKeyName = keyPropI.next();
		    	Object nodeKeyValue = currentNode.<Object>property(nodeKeyName).orElse(null);
		    	nodeKeyName = depNodeType + "." + nodeKeyName;
		    	// key name will be like tenant.tenant-id
		    	
		    	depNodeHash.put(nodeKeyName, nodeKeyValue);
		    }
		    returnHash.putAll(depNodeHash);		
		}
	    
		return returnHash;
	}
	
	/*
	 * method returns a Hash of Hashes for each parents keys for the given node based on its nodeURI
	 * Special cases for REST URLs:
	 *  - images, flavor, vnic and l-interface node types will return new url
	 *  - nodetypes with multiple keys such as service capability
	 *  - nodetypes with multiple keys such as ipaddress where we use one key in the URL
	 *  - cvlan-tags and *list nodetypes - have special or no plurals - they get handled via the hash Map
	 */	

	/**
	 * Gets the key hashes.
	 *
	 * @param nodeURI the node URI
	 * @return the key hashes
	 * @throws AAIException the AAI exception
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static LinkedHashMap <String,Object> getKeyHashes(String nodeURI) throws AAIException, UnsupportedEncodingException
	{
		return getKeyHashes(nodeURI, null);
		
	}
	
	/**
	 * Gets the key hashes.
	 *
	 * @param nodeURI the node URI
	 * @param apiVersion the api version
	 * @return the key hashes
	 * @throws AAIException the AAI exception
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 */
	public static LinkedHashMap <String,Object> getKeyHashes(String nodeURI, String apiVersion) throws AAIException, UnsupportedEncodingException
	{
		
		if (apiVersion == null || apiVersion.equals(""))
			apiVersion = AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP);
			
		DbMaps dbMaps = IngestModelMoxyOxm.dbMapsContainer.get(apiVersion);
		
       	// Hash of hashes of keys for each node and its ancestry
		LinkedHashMap <String,Object> returnHash = new LinkedHashMap <String,Object> ();
           	
       	String path = nodeURI.replaceFirst("^/", "");		
		Path p = Paths.get(path);
		int index = p.getNameCount() - 2; // index of where we expect the node type to be
		
		// if the node type has one key
		String currentNodeType = p.getName(index).toString();
		// if the node type has two keys - this assumes max 2 keys
		if (!dbMaps.NodeKeyProps.containsKey(currentNodeType))
			currentNodeType = p.getName(--index).toString();
	
     	// create the hash for the keys for the node passed in
     	LinkedHashMap <String,Object> thisNodeHash = new LinkedHashMap <String,Object> ();
    	Collection <String> keyProps =  dbMaps.NodeKeyProps.get(currentNodeType);
	    Iterator <String> keyPropI = keyProps.iterator();
    	
	    if (currentNodeType.equals("ipaddress")) { // this has 2 keys but API only uses port-or -address in URL
	    	String nodeKeyValue = p.getName(index + 1).toString();
	    	thisNodeHash.put("port-or-interface", nodeKeyValue);
	    } else {
	    	int j = 1;
		    while (keyPropI.hasNext()) {
		    	String nodeKeyName = currentNodeType + "." + keyPropI.next();
		    	String nodeKeyValue = p.getName(index + j++).toString();
		    	thisNodeHash.put(nodeKeyName, nodeKeyValue);
		    }
	    }
	    returnHash.putAll(thisNodeHash);	    
	    if (!currentNodeType.contains("-list"))
	    	index -= 3; 
	    else
	    	index -= 2; // no plural in this case
			

     	// create and add the hashes for the dependent nodes for the node passed in
	    LinkedHashMap <String,Object> depNodeHash = new LinkedHashMap <String,Object> (); 
	    String depNodeType = null;
     	while (index >= 2) {
     		if (depNodeType == null) depNodeType = p.getName(index).toString();
     		//System.out.println("index=" + index);        	
    		// if the node type has one key
    		currentNodeType = p.getName(index).toString();
    		// if the node type has two keys - this assumes max 2 keys
    		if (!dbMaps.NodeKeyProps.containsKey(currentNodeType))
    			currentNodeType = p.getName(--index).toString();
    	
        	keyProps =  dbMaps.NodeKeyProps.get(currentNodeType);
    	    keyPropI = keyProps.iterator();
        	
    	    if (currentNodeType.equals("ipaddress")) { // this has 2 keys but API only uses port-or -address in URL
    	    	String nodeKeyValue = p.getName(index + 1).toString();
    	    	depNodeHash.put("port-or-interface", nodeKeyValue);
    	    } else {
    	    	int j = 1;
    		    while (keyPropI.hasNext()) {
    		    	String nodeKeyName = currentNodeType + "." + keyPropI.next();
    		    	String nodeKeyValue = p.getName(index + j++).toString();
    		    	depNodeHash.put(nodeKeyName, nodeKeyValue);
    		    }
    	    }

    	    if (!currentNodeType.contains("-list"))
    	    	index -= 3; 
    	    else
    	    	index -= 2; // no plural in this case    	    
		}
     	if (depNodeType != null) 
     		returnHash.putAll(depNodeHash);
	    
		return returnHash;
	}
	
	/**
	 * Parses the uri.
	 *
	 * @param allKeys the all keys
	 * @param keyList the key list
	 * @param uri the uri
	 * @param aaiExtMap the aai ext map
	 * @return the AAI resource
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 * @throws AAIException the AAI exception
	 */
	public static AAIResource parseUri(HashMap<String, String> allKeys, LinkedHashMap<String, 
			LinkedHashMap<String,Object>> keyList, String uri, 
			AAIExtensionMap aaiExtMap) throws UnsupportedEncodingException, AAIException {		
		List<String> ps = Arrays.asList(uri.split("/"));
		
		// uri is the entire url including server name and version etc.
		String apiVersion = ps.get(4).toString();
		aaiExtMap.setApiVersion(apiVersion);
		
		AAIResources aaiResources = org.openecomp.aai.ingestModel.IngestModelMoxyOxm.aaiResourceContainer.get(apiVersion);
		
		String namespace = ps.get(5).toString();
		
		aaiExtMap.setNamespace(namespace);
		
		// /vces/vce/{vnf-id}/port-groups/port-group/{port-group-id}/cvlan-tag-entry/cvlan-tag/{cvlan-tag}
		
		// FullName -> /Vces/Vce/PortGroups/PortGroup/CvlanTagEntry/CvlanTag <- 

		String fullResourceName = "/" + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, namespace);
		AAIResources theseResources = new AAIResources();
		
		StringBuffer thisUri = new StringBuffer();
		
		// the URI config option in the props file has a trailing slash
		thisUri.append("/" + namespace);
				
		boolean firstNode = true;
		
		AAIResource lastResource = null;
		
		for (int i = 6; i < ps.size(); i++) { 
			
			AAIResource aaiRes;
			StringBuffer tmpResourceName = new StringBuffer();
						
			String p = ps.get(i);
			String seg = p.toString();
						
			thisUri.append("/" + seg);
			
			tmpResourceName.append(fullResourceName);
			
			if (seg.equals("cvlan-tag")) {
				seg = "cvlan-tag-entry";
			}
			tmpResourceName.append("/" + CaseFormat.LOWER_HYPHEN.to(CaseFormat.UPPER_CAMEL, seg));
			
			String tmpResource = tmpResourceName.toString();
			
			if (aaiResources.getAaiResources().containsKey(tmpResource)) {
				aaiRes = aaiResources.getAaiResources().get(tmpResource);
				lastResource = aaiRes;
				theseResources.getAaiResources().put(tmpResource, aaiRes);
				fullResourceName = tmpResource;
				if ("node".equals(aaiRes.getResourceType())) {
					
					if (firstNode == true) { 
						aaiExtMap.setTopObjectFullResourceName(fullResourceName);
						firstNode = false;
					}
							
					// get the keys, which will be in order and the next path segment(s)
					AAIResourceKeys keys = aaiRes.getAaiResourceKeys();
									
					LinkedHashMap<String,Object> subKeyList = new LinkedHashMap<String,Object>();
					
					// there might not be another path segment
					if ( (i + 1) < ps.size()) { 
						
						for (AAIResourceKey rk : keys.getAaiResourceKey()) {
							String p1 = ps.get(++i);
							String encodedKey = p1.toString();
							thisUri.append("/" + encodedKey);
							String decodedKey =  UriUtils.decode(p1.toString(), "UTF-8");
							subKeyList.put(rk.getKeyName(), decodedKey);
						}
						keyList.put(tmpResource, subKeyList);
						// this is the key
						allKeys.put(tmpResource, thisUri.toString());
											
					}
				} else { // examples sit directly under the container level, should probably be query params!!!
					if ( (i + 1) < ps.size()) { 
						String p1 = ps.get(i+1);
						if (p1.toString().equals("example") || p1.toString().equals("singletonExample")) { 
							LinkedHashMap<String,Object> subKeyList = new LinkedHashMap<String,Object>();
							subKeyList.put("container|example", p1.toString());
							keyList.put(tmpResource, subKeyList);
						}
					}
				}
			} else {
				if (p.toString().equals("relationship-list")) { 
					LinkedHashMap<String,Object> subKeyList = new LinkedHashMap<String,Object>();
					subKeyList.put("container|relationship", p.toString());
					keyList.put(tmpResource, subKeyList);
				} else if ( p.toString().length() > 0 && !p.toString().equals("example") && !p.toString().equals("singletonExample") 
						&& !p.toString().equals("relationship") ) {
					// this means the URL will break the model, so we bail
					throw new AAIException("AAI_3001", "bad path");
				}
			}
		}
		aaiExtMap.setUri(AAIConfig.get("aai.global.callback.url")  + apiVersion + thisUri.toString());
		aaiExtMap.setNotificationUri(AAIConfig.get("aai.global.callback.url") + AAIConfig.get("aai.notification.current.version") + thisUri.toString());
		aaiExtMap.setFullResourceName(fullResourceName);
		return lastResource;
	}


	/**
	 * The main method.
	 *
	 * @param args the arguments
	 * @throws UnsupportedEncodingException the unsupported encoding exception
	 * @throws AAIException the AAI exception
	 */
	public static void main (String[] args) throws UnsupportedEncodingException, AAIException {
		
		String nodeURI = args[0];
		
		IngestModelMoxyOxm moxyMod = new IngestModelMoxyOxm();
		try {
			ArrayList <String> defaultVerLst = new ArrayList <String> ();
			defaultVerLst.add( AAIConfig.get(AAIConstants.AAI_DEFAULT_API_VERSION_PROP) );
			moxyMod.init( defaultVerLst, false);
			}
		catch (Exception ex){
			String emsg = " ERROR - Could not get the DbMaps object. ";
			System.out.print(emsg);
			System.out.println("Exception.getMessage() = [" + ex.getMessage() + "]");
			System.exit(1);
		}
		
		LinkedHashMap <String,Object> returnHash = getKeyHashes(nodeURI);
		
		Set<String> returnKeySet = returnHash.keySet();
		Iterator<String> iter = returnKeySet.iterator();
		
		while (iter.hasNext()) {
			String key = (String) iter.next();
			System.out.println("from url :" +  key + ":" + (returnHash.get(key)).toString());
		}

		TitanTransaction g = AAIGraph.getInstance().getGraph().newTransaction();
		
		TitanVertex vtx = DbMeth.getUniqueNodeWithDepParams("test", "test", g, "l3-interface-ipv6-address-list", returnHash, "v7");
		returnHash = getKeyHashes(g, vtx);
		
		returnKeySet = returnHash.keySet();
		iter = returnKeySet.iterator();
		
		while (iter.hasNext()) {
			String key = (String) iter.next();
			System.out.println("from vtx: " + key + ":" + (returnHash.get(key)).toString());
		}		
		g.rollback();
		System.exit(0);
	}

}