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
|
/**
* ============LICENSE_START=======================================================
* org.onap.aai
* ================================================================================
* Copyright © 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=========================================================
*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
package org.onap.aai.dbgen;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Properties;
import java.util.Scanner;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal;
import org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__;
import org.apache.tinkerpop.gremlin.structure.Direction;
import org.apache.tinkerpop.gremlin.structure.Edge;
import org.apache.tinkerpop.gremlin.structure.Vertex;
import org.apache.tinkerpop.gremlin.structure.VertexProperty;
import org.onap.aai.exceptions.AAIException;
import org.onap.aai.serialization.db.AAIDirection;
import org.onap.aai.serialization.db.EdgeProperty;
import org.onap.aai.util.AAIConfig;
import org.onap.aai.util.AAIConstants;
import org.slf4j.MDC;
import com.att.eelf.configuration.Configuration;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import com.thinkaurelius.titan.core.TitanFactory;
import com.thinkaurelius.titan.core.TitanGraph;
public class ForceDeleteTool {
/*
* The main method.
*
* @param args the arguments
*/
public static void main(String[] args) {
//SWGK 01/21/2016 - To suppress the warning message when the tool is run from the Terminal.
// Set the logging file properties to be used by EELFManager
Properties props = System.getProperties();
props.setProperty(Configuration.PROPERTY_LOGGING_FILE_NAME, "forceDelete-logback.xml");
props.setProperty(Configuration.PROPERTY_LOGGING_FILE_PATH, AAIConstants.AAI_HOME_ETC_APP_PROPERTIES);
EELFLogger logger = EELFManager.getInstance().getLogger(ForceDeleteTool.class.getSimpleName());
MDC.put("logFilenameAppender", ForceDeleteTool.class.getSimpleName());
String actionVal = "";
String userIdVal = "";
String dataString = "";
Boolean displayAllVidsFlag = false; // Note - This should rarely be needed
Boolean overRideProtection = false; // This should rarely be used - it overrides all our new checking
long vertexIdLong = 0;
String edgeIdStr = "";
String argStr4Msg = "";
if (args != null && args.length > 0) {
// They passed some arguments in that will affect processing
for (int i = 0; i < args.length; i++) {
String thisArg = args[i];
argStr4Msg = argStr4Msg + " " + thisArg;
if (thisArg.equals("-action")) {
i++;
if (i >= args.length) {
logger.error(" No value passed with -action option. ");
System.exit(0);
}
actionVal = args[i];
argStr4Msg = argStr4Msg + " " + actionVal;
}
else if (thisArg.equals("-userId")) {
i++;
if (i >= args.length) {
logger.error(" No value passed with -userId option. ");
System.exit(0);
}
userIdVal = args[i];
argStr4Msg = argStr4Msg + " " + userIdVal;
}
else if (thisArg.equals("-overRideProtection")) {
overRideProtection = true;
}
else if (thisArg.equals("-DISPLAY_ALL_VIDS")) {
displayAllVidsFlag = true;
}
else if (thisArg.equals("-vertexId")) {
i++;
if (i >= args.length) {
logger.error(" No value passed with -vertexId option. ");
System.exit(0);
}
String nextArg = args[i];
argStr4Msg = argStr4Msg + " " + nextArg;
try {
vertexIdLong = Long.parseLong(nextArg);
} catch (Exception e) {
logger.error("Bad value passed with -vertexId option: ["
+ nextArg + "]");
System.exit(0);
}
}
else if (thisArg.equals("-params4Collect")) {
i++;
if (i >= args.length) {
logger.error(" No value passed with -params4Collect option. ");
System.exit(0);
}
dataString = args[i];
argStr4Msg = argStr4Msg + " " + dataString;
}
else if (thisArg.equals("-edgeId")) {
i++;
if (i >= args.length) {
logger.error(" No value passed with -edgeId option. ");
System.exit(0);
}
String nextArg = args[i];
argStr4Msg = argStr4Msg + " " + nextArg;
edgeIdStr = nextArg;
}
else {
logger.error(" Unrecognized argument passed to ForceDeleteTool: ["
+ thisArg + "]. ");
logger.error(" Valid values are: -action -userId -vertexId -edgeId -overRideProtection -params4Collect -DISPLAY_ALL_VIDS");
System.exit(0);
}
}
}
if( !actionVal.equals("COLLECT_DATA") && !actionVal.equals("DELETE_NODE") && !actionVal.equals("DELETE_EDGE")){
String emsg = "Bad action parameter [" + actionVal + "] passed to ForceDeleteTool(). Valid values = COLLECT_DATA or DELETE_NODE or DELETE_EDGE\n";
System.out.println(emsg);
logger.error(emsg);
System.exit(0);
}
if( actionVal.equals("DELETE_NODE") && vertexIdLong == 0 ){
String emsg = "ERROR: No vertex ID passed on DELETE_NODE request. \n";
System.out.println(emsg);
logger.error(emsg);
System.exit(0);
}
else if( actionVal.equals("DELETE_EDGE") && edgeIdStr.equals("")){
String emsg = "ERROR: No edge ID passed on DELETE_EDGE request. \n";
System.out.println(emsg);
logger.error(emsg);
System.exit(0);
}
userIdVal = userIdVal.trim();
if( (userIdVal.length() < 6) || userIdVal.toUpperCase().equals("AAIADMIN") ){
String emsg = "Bad userId parameter [" + userIdVal + "] passed to ForceDeleteTool(). must be not empty and not aaiadmin \n";
System.out.println(emsg);
logger.error(emsg);
System.exit(0);
}
String msg = "";
TitanGraph graph = null;
try {
AAIConfig.init();
System.out.println(" ---- NOTE --- about to open graph (takes a little while)--------\n");
graph = TitanFactory.open(AAIConstants.REALTIME_DB_CONFIG);
if( graph == null ){
String emsg = "could not get graph object in ForceDeleteTool() \n";
System.out.println(emsg);
logger.error(emsg);
System.exit(0);
}
}
catch (AAIException e1) {
msg = e1.getErrorObject().toString();
System.out.println(msg);
logger.error(msg);
System.exit(0);
}
catch (Exception e2) {
msg = e2.toString();
System.out.println(msg);
logger.error(msg);
System.exit(0);
}
msg = "ForceDelete called by: userId [" + userIdVal + "] with these params: [" + argStr4Msg + "]";
System.out.println(msg);
logger.info(msg);
ForceDelete fd = new ForceDelete(graph);
if( actionVal.equals("COLLECT_DATA") ){
// When doing COLLECT_DATA, we expect the dataString string to be comma separated
// name value pairs like this:
// "propName1|propVal1,propName2|propVal2" etc. We will look for a node or nodes
// that have properties that ALL match what was passed in.
int resCount = 0;
int firstPipeLoc = dataString.indexOf("|");
if( firstPipeLoc <= 0 ){
msg = "Must use the -params4Collect option when collecting data with data string in a format like: 'propName1|propVal1,propName2|propVal2'";
System.out.println(msg);
logger.error(msg);
System.exit(0);
}
GraphTraversal<Vertex, Vertex> g = graph.traversal().V();
String qStringForMsg = " graph.traversal().V()";
// Note - if they're only passing on parameter, there won't be any commas
String [] paramArr = dataString.split(",");
for( int i = 0; i < paramArr.length; i++ ){
int pipeLoc = paramArr[i].indexOf("|");
if( pipeLoc <= 0 ){
msg = "Must use the -params4Collect option when collecting data with data string in a format like: 'propName1|propVal1,propName2|propVal2'";
System.out.println(msg);
logger.error(msg);
System.exit(0);
}
else {
String propName = paramArr[i].substring(0,pipeLoc);
String propVal = paramArr[i].substring(pipeLoc + 1);
g = g.has(propName,propVal);
qStringForMsg = qStringForMsg + ".has(" + propName + "," + propVal + ")";
}
}
if( (g != null)){
Iterator<Vertex> vertItor = g;
while( vertItor.hasNext() ){
resCount++;
Vertex v = vertItor.next();
fd.showNodeInfo( logger, v, displayAllVidsFlag );
int descendantCount = fd.countDescendants( logger, v, 0 );
String infMsg = " Found " + descendantCount + " descendant nodes \n";
System.out.println( infMsg );
logger.info( infMsg );
}
}
else {
msg = "Bad TitanGraphQuery object. ";
System.out.println(msg);
logger.error(msg);
System.exit(0);
}
String infMsg = "\n\n Found: " + resCount + " nodes for this query: [" + qStringForMsg + "]\n";
System.out.println( infMsg );
logger.info( infMsg );
}
else if( actionVal.equals("DELETE_NODE") ){
Iterator <Vertex> vtxItr = graph.vertices( vertexIdLong );
if( vtxItr != null && vtxItr.hasNext() ) {
Vertex vtx = vtxItr.next();
fd.showNodeInfo( logger, vtx, displayAllVidsFlag );
int descendantCount = fd.countDescendants( logger, vtx, 0 );
String infMsg = " Found " + descendantCount + " descendant nodes. Note - forceDelete does not cascade to " +
" child nodes, but they may become unreachable after the delete. \n";
System.out.println( infMsg );
logger.info( infMsg );
int edgeCount = fd.countEdges( logger, vtx );
infMsg = " Found total of " + edgeCount + " edges incident on this node. \n";
System.out.println( infMsg );
logger.info( infMsg );
if( fd.getNodeDelConfirmation(logger, userIdVal, vtx, descendantCount, edgeCount, overRideProtection) ){
vtx.remove();
graph.tx().commit();
infMsg = ">>>>>>>>>> Removed node with vertexId = " + vertexIdLong;
logger.info( infMsg );
System.out.println(infMsg);
}
else {
infMsg = " Delete Cancelled. ";
System.out.println(infMsg);
logger.info( infMsg );
}
}
else {
String infMsg = ">>>>>>>>>> Vertex with vertexId = " + vertexIdLong + " not found.";
System.out.println( infMsg );
logger.info( infMsg );
}
}
else if( actionVal.equals("DELETE_EDGE") ){
Edge thisEdge = null;
Iterator <Edge> edItr = graph.edges( edgeIdStr );
if( edItr != null && edItr.hasNext() ) {
thisEdge = edItr.next();
}
if( thisEdge == null ){
String infMsg = ">>>>>>>>>> Edge with edgeId = " + edgeIdStr + " not found.";
logger.info( infMsg );
System.out.println(infMsg);
System.exit(0);
}
if( fd.getEdgeDelConfirmation(logger, userIdVal, thisEdge, overRideProtection) ){
thisEdge.remove();
graph.tx().commit();
String infMsg = ">>>>>>>>>> Removed edge with edgeId = " + edgeIdStr;
logger.info( infMsg );
System.out.println(infMsg);
}
else {
String infMsg = " Delete Cancelled. ";
System.out.println(infMsg);
logger.info( infMsg );
}
System.exit(0);
}
else {
String emsg = "Unknown action parameter [" + actionVal + "] passed to ForceDeleteTool(). Valid values = COLLECT_DATA, DELETE_NODE or DELETE_EDGE \n";
System.out.println(emsg);
logger.info( emsg );
System.exit(0);
}
System.exit(0);
}// end of main()
public static class ForceDelete {
private final int MAXDESCENDENTDEPTH = 15;
private final TitanGraph graph;
public ForceDelete(TitanGraph graph) {
this.graph = graph;
}
public void showNodeInfo(EELFLogger logger, Vertex tVert, Boolean displayAllVidsFlag ){
try {
Iterator<VertexProperty<Object>> pI = tVert.properties();
String infStr = ">>> Found Vertex with VertexId = " + tVert.id() + ", properties: ";
System.out.println( infStr );
logger.info(infStr);
while( pI.hasNext() ){
VertexProperty<Object> tp = pI.next();
infStr = " [" + tp.key() + "|" + tp.value() + "] ";
System.out.println( infStr );
logger.info(infStr);
}
ArrayList <String> retArr = collectEdgeInfoForNode( logger, tVert, displayAllVidsFlag );
for( String infoStr : retArr ){
System.out.println( infoStr );
logger.info(infoStr);
}
}
catch (Exception e){
String warnMsg = " -- Error -- trying to display edge info. [" + e.getMessage() + "]";
System.out.println( warnMsg );
logger.warn(warnMsg);
}
}// End of showNodeInfo()
public void showPropertiesForEdge( EELFLogger logger, Edge tEd ){
String infMsg = "";
if( tEd == null ){
infMsg = "null Edge object passed to showPropertiesForEdge()";
System.out.print(infMsg);
logger.info(infMsg);
return;
}
// Try to show the edge properties
try {
infMsg =" Label for this Edge = [" + tEd.label() + "] ";
System.out.print(infMsg);
logger.info(infMsg);
infMsg =" EDGE Properties for edgeId = " + tEd.id() + ": ";
System.out.print(infMsg);
logger.info(infMsg);
Iterator <String> pI = tEd.keys().iterator();
while( pI.hasNext() ){
String propKey = pI.next();
infMsg = "Prop: [" + propKey + "], val = ["
+ tEd.property(propKey) + "] ";
System.out.print(infMsg);
logger.info(infMsg);
}
}
catch( Exception ex ){
infMsg = " Could not retrieve properties for this edge. exMsg = ["
+ ex.getMessage() + "] ";
System.out.println( infMsg );
logger.info(infMsg);
}
// Try to show what's connected to the IN side of this Edge
try {
infMsg = " Looking for the Vertex on the IN side of the edge: ";
System.out.print(infMsg);
logger.info(infMsg);
Vertex inVtx = tEd.inVertex();
Iterator<VertexProperty<Object>> pI = inVtx.properties();
String infStr = ">>> Found Vertex with VertexId = " + inVtx.id()
+ ", properties: ";
System.out.println( infStr );
logger.info(infStr);
while( pI.hasNext() ){
VertexProperty<Object> tp = pI.next();
infStr = " [" + tp.key() + "|" + tp.value() + "] ";
System.out.println( infStr );
logger.info(infStr);
}
}
catch( Exception ex ){
infMsg = " Could not retrieve vertex data for the IN side of "
+ "the edge. exMsg = [" + ex.getMessage() + "] ";
System.out.println( infMsg );
logger.info(infMsg);
}
// Try to show what's connected to the OUT side of this Edge
try {
infMsg = " Looking for the Vertex on the OUT side of the edge: ";
System.out.print(infMsg);
logger.info(infMsg);
Vertex outVtx = tEd.outVertex();
Iterator<VertexProperty<Object>> pI = outVtx.properties();
String infStr = ">>> Found Vertex with VertexId = " + outVtx.id()
+ ", properties: ";
System.out.println( infStr );
logger.info(infStr);
while( pI.hasNext() ){
VertexProperty<Object> tp = pI.next();
infStr = " [" + tp.key() + "|" + tp.value() + "] ";
System.out.println( infStr );
logger.info(infStr);
}
}
catch( Exception ex ){
infMsg = " Could not retrieve vertex data for the OUT side of "
+ "the edge. exMsg = [" + ex.getMessage() + "] ";
System.out.println( infMsg );
logger.info(infMsg);
}
}// end showPropertiesForEdge()
public ArrayList <String> collectEdgeInfoForNode( EELFLogger logger, Vertex tVert, boolean displayAllVidsFlag ){
ArrayList <String> retArr = new ArrayList <String> ();
Direction dir = Direction.OUT;
for ( int i = 0; i <= 1; i++ ){
if( i == 1 ){
// Second time through we'll look at the IN edges.
dir = Direction.IN;
}
Iterator <Edge> eI = tVert.edges(dir);
if( ! eI.hasNext() ){
retArr.add("No " + dir + " edges were found for this vertex. ");
}
while( eI.hasNext() ){
Edge ed = eI.next();
String lab = ed.label();
Vertex vtx = null;
if( dir == Direction.OUT ){
// get the vtx on the "other" side
vtx = ed.inVertex();
}
else {
// get the vtx on the "other" side
vtx = ed.outVertex();
}
if( vtx == null ){
retArr.add(" >>> COULD NOT FIND VERTEX on the other side of this edge edgeId = " + ed.id() + " <<< ");
}
else {
String nType = vtx.<String>property("aai-node-type").orElse(null);
if( displayAllVidsFlag ){
// This should rarely be needed
String vid = vtx.id().toString();
retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node with VtxId = " + vid );
}
else {
// This is the normal case
retArr.add("Found an " + dir + " edge (" + lab + ") between this vertex and a [" + nType + "] node. ");
}
}
}
}
return retArr;
}// end of collectEdgeInfoForNode()
public int countEdges( EELFLogger logger, Vertex vtx ){
int edgeCount = 0;
try {
Iterator<Edge> edgesItr = vtx.edges(Direction.BOTH);
while( edgesItr.hasNext() ){
edgesItr.next();
edgeCount++;
}
}
catch (Exception e) {
String wMsg = "-- ERROR -- Stopping the counting of edges because of Exception [" + e.getMessage() + "]";
System.out.println( wMsg );
logger.warn( wMsg );
}
return edgeCount;
}// end of countEdges()
public int countDescendants(EELFLogger logger, Vertex vtx, int levelVal ){
int totalCount = 0;
int thisLevel = levelVal + 1;
if( thisLevel > MAXDESCENDENTDEPTH ){
String wMsg = "Warning -- Stopping the counting of descendents because we reached the max depth of " + MAXDESCENDENTDEPTH;
System.out.println( wMsg );
logger.warn( wMsg );
return totalCount;
}
try {
Iterator <Vertex> vertI = graph.traversal().V(vtx).union(__.outE().has(EdgeProperty.CONTAINS.toString(), AAIDirection.OUT.toString()).inV(), __.inE().has(EdgeProperty.CONTAINS.toString(), AAIDirection.IN.toString()).outV());
while( vertI != null && vertI.hasNext() ){
totalCount++;
Vertex childVtx = vertI.next();
totalCount = totalCount + countDescendants( logger, childVtx, thisLevel );
}
}
catch (Exception e) {
String wMsg = "Error -- Stopping the counting of descendents because of Exception [" + e.getMessage() + "]";
System.out.println( wMsg );
logger.warn( wMsg );
}
return totalCount;
}// end of countDescendants()
public boolean getEdgeDelConfirmation( EELFLogger logger, String uid, Edge ed,
Boolean overRideProtection ) {
showPropertiesForEdge( logger, ed );
System.out.print("\n Are you sure you want to delete this EDGE? (y/n): ");
Scanner s = new Scanner(System.in);
s.useDelimiter("");
String confirm = s.next();
s.close();
if (!confirm.equalsIgnoreCase("y")) {
String infMsg = " User [" + uid + "] has chosen to abandon this delete request. ";
System.out.println("\n" + infMsg);
logger.info(infMsg);
return false;
}
else {
String infMsg = " User [" + uid + "] has confirmed this delete request. ";
System.out.println("\n" + infMsg);
logger.info(infMsg);
return true;
}
} // End of getEdgeDelConfirmation()
public boolean getNodeDelConfirmation( EELFLogger logger, String uid, Vertex vtx, int edgeCount,
int descendantCount, Boolean overRideProtection ) {
String thisNodeType = "";
try {
thisNodeType = vtx.<String>property("aai-node-type").orElse(null);
}
catch ( Exception nfe ){
// Let the user know something is going on - but they can confirm the delete if they want to.
String infMsg = " -- WARNING -- could not get an aai-node-type for this vertex. -- WARNING -- ";
System.out.println( infMsg );
logger.warn( infMsg );
}
String ntListString = "";
String maxDescString = "";
String maxEdgeString = "";
int maxDescCount = 10; // default value
int maxEdgeCount = 10; // default value
ArrayList <String> protectedNTypes = new ArrayList <String> ();
protectedNTypes.add("cloud-region"); // default value
try {
ntListString = AAIConfig.get("aai.forceDel.protected.nt.list");
maxDescString = AAIConfig.get("aai.forceDel.protected.descendant.count");
maxEdgeString = AAIConfig.get("aai.forceDel.protected.edge.count");
}
catch ( Exception nfe ){
// Don't worry, we will use default values
String infMsg = "-- WARNING -- could not get aai.forceDel.protected values from aaiconfig.properties -- will use default values. ";
System.out.println( infMsg );
logger.warn( infMsg );
}
if( maxDescString != null && !maxDescString.equals("") ){
try {
maxDescCount = Integer.parseInt(maxDescString);
}
catch ( Exception nfe ){
// Don't worry, we will leave "maxDescCount" set to the default value
}
}
if( maxEdgeString != null && !maxEdgeString.equals("") ){
try {
maxEdgeCount = Integer.parseInt(maxEdgeString);
}
catch ( Exception nfe ){
// Don't worry, we will leave "maxEdgeCount" set to the default value
}
}
if( ntListString != null && !ntListString.trim().equals("") ){
String [] nodeTypes = ntListString.split("\\|");
for( int i = 0; i < nodeTypes.length; i++ ){
protectedNTypes.add(nodeTypes[i]);
}
}
boolean giveProtOverRideMsg = false;
boolean giveProtErrorMsg = false;
if( descendantCount > maxDescCount ){
// They are trying to delete a node with a lots of descendants
String infMsg = " >> WARNING >> This node has more descendant edges than the max ProtectedDescendantCount: " + edgeCount + ". Max = " +
maxEdgeCount + ". It can be DANGEROUS to delete one of these. << WARNING << ";
System.out.println(infMsg);
logger.info(infMsg);
if( ! overRideProtection ){
// They cannot delete this kind of node without using the override option
giveProtErrorMsg = true;
}
else {
giveProtOverRideMsg = true;
}
}
if( edgeCount > maxEdgeCount ){
// They are trying to delete a node with a lot of edges
String infMsg = " >> WARNING >> This node has more edges than the max ProtectedEdgeCount: " + edgeCount + ". Max = " +
maxEdgeCount + ". It can be DANGEROUS to delete one of these. << WARNING << ";
System.out.println(infMsg);
logger.info(infMsg);
if( ! overRideProtection ){
// They cannot delete this kind of node without using the override option
giveProtErrorMsg = true;
}
else {
giveProtOverRideMsg = true;
}
}
if( thisNodeType != null && !thisNodeType.equals("") && protectedNTypes.contains(thisNodeType) ){
// They are trying to delete a protected Node Type
String infMsg = " >> WARNING >> This node is a PROTECTED NODE-TYPE (" + thisNodeType + "). " +
" It can be DANGEROUS to delete one of these. << WARNING << ";
System.out.println(infMsg);
logger.info(infMsg);
if( ! overRideProtection ){
// They cannot delete this kind of node without using the override option
giveProtErrorMsg = true;
}
else {
giveProtOverRideMsg = true;
}
}
if( giveProtOverRideMsg ){
String infMsg = " !!>> WARNING >>!! you are using the overRideProtection parameter which will let you do this potentially dangerous delete.";
System.out.println("\n" + infMsg);
logger.info(infMsg);
}
else if( giveProtErrorMsg ) {
String errMsg = " ERROR >> this kind of node can only be deleted if you pass the overRideProtection parameter.";
System.out.println("\n" + errMsg);
logger.error(errMsg);
return false;
}
System.out.print("\n Are you sure you want to do this delete? (y/n): ");
Scanner s = new Scanner(System.in);
s.useDelimiter("");
String confirm = s.next();
s.close();
if (!confirm.equalsIgnoreCase("y")) {
String infMsg = " User [" + uid + "] has chosen to abandon this delete request. ";
System.out.println("\n" + infMsg);
logger.info(infMsg);
return false;
}
else {
String infMsg = " User [" + uid + "] has confirmed this delete request. ";
System.out.println("\n" + infMsg);
logger.info(infMsg);
return true;
}
} // End of getNodeDelConfirmation()
}
}
|