Project

General

Profile

« Previous | Next » 

Revision 1513

Added by Jing Tao about 21 years ago

Add code to handle if a unaccessable subtree is another subtree of unaccessable subtree.

View differences:

PermissionController.java
366 366
        }
367 367
      }//if
368 368
    }//for
369
    // merge the subtree if a subtree is another subtree'subtree    
370
    resultUnaccessableSubTree = mergeIntoBigSubtree(resultUnaccessableSubTree);
369 371
    return resultUnaccessableSubTree;
370 372
  }//hasUnaccessableSubtree
371 373
  
374
  
375
  /* 
376
   * A method to merge nested subtree into bigger one. For example subtree b
377
   * is a subtree of subtree a. And user doesn't have read permission for both
378
   * so we only use subtree a is enough.
379
   */
380
  private Hashtable mergeIntoBigSubtree(Hashtable unAccessSubTree)
381
  {
382
    Hashtable newSubTreeHash = new Hashtable();
383
    boolean   needDelete = false;
384
    // check the parameters
385
    if (unAccessSubTree == null || unAccessSubTree.isEmpty())
386
    {
387
      return newSubTreeHash;
388
    }
389
    else
390
    {
391
      // look every subtree start point and stop point, to see if it is embedded
392
      // in another one. If embedded, they are equavelent and we can use bigger
393
      // one to replace smaller one
394
      Enumeration en = unAccessSubTree.elements();
395
      while (en.hasMoreElements())
396
      {
397
        SubTree tree    = (SubTree)en.nextElement();
398
        String  treeId  = tree.getSubTreeId();
399
        long    startId = tree.getStartNodeId();
400
        long    endId   = tree.getEndNodeId();
401
        
402
        Enumeration enu = unAccessSubTree.elements();
403
        while (enu.hasMoreElements())
404
        {
405
          SubTree subTree = (SubTree)enu.nextElement();
406
          String subTreeId= subTree.getSubTreeId();
407
          long   subTreeStartId = subTree.getStartNodeId();
408
          long   subTreeEndId   = subTree.getEndNodeId();
409
          //compare and if the first subtree is a subtree of the second
410
          // one, set neeDelete true
411
          if (startId > subTreeStartId && endId < subTreeEndId)
412
          {
413
            needDelete = true;
414
            MetaCatUtil.debugMessage("the subtree: "+ treeId + 
415
                                     " need to be get rid of from unaccessable"+
416
                                     " subtree list becuase it is a subtree of"+
417
                                     " another subtree in the list", 45);
418
            break;
419
          }//if
420
        }//while
421
        // if not need to delete, put the subtree into hash
422
        if (!needDelete)
423
        {
424
          newSubTreeHash.put(treeId, tree);
425
        }
426
        //reset needDelete
427
        needDelete = false;
428
      }//while
429
      return newSubTreeHash;
430
    }//else
431
  }
432
  
372 433
  /**
373 434
    * Check if a document id is a access document. Access document need user
374 435
    * has "all" permission to access it.

Also available in: Unified diff