Changeset 35299


Ignore:
Timestamp:
2021-08-16T20:38:05+12:00 (3 years ago)
Author:
anupama
Message:
  1. UserTermInfo.toString() now displays expandedGroups instead of compactedGroups (or the earlier, original user-entered groups). Still need to check that this is not used somewhere important, and if so, then that it is only used in DB related contexts where it needs to be expandedGroups now. 2. Tidied up: origGroups and getOrigGroups() are now compactedGroups and getCompactedGroups() and cleaned up unused/commented out code I had added.
Location:
main/trunk/greenstone3/src/java/org/greenstone/gsdl3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/service/Authentication.java

    r35298 r35299  
    10841084            for (int i = 0; i < userQueryResult.getSize(); i++)
    10851085            {
    1086                 // can call either getExpandedGroups() or getOrigGroups() to check admin group is in there:
    1087                 if (((UserTermInfo) userInfo.get(i)).getOrigGroups() != null && ((UserTermInfo) userInfo.get(i)).getOrigGroups().matches(".*\\badministrator\\b.*"))
     1086                // can call either getExpandedGroups() or getCompactedGroups() to check admin group is in there:
     1087                if (((UserTermInfo) userInfo.get(i)).getCompactedGroups() != null && ((UserTermInfo) userInfo.get(i)).getCompactedGroups().matches(".*\\badministrator\\b.*"))
    10881088                {
    10891089                    adminFound = true;
     
    12171217                else if (dataType.equals(COMPACTED_GROUPS))
    12181218                {
    1219                     data = ((UserTermInfo) userInfo.get(i)).getOrigGroups();
     1219                    data = ((UserTermInfo) userInfo.get(i)).getCompactedGroups();
    12201220                    break;
    12211221                }
     
    12601260            Element user_node = doc.createElement(GSXML.USER_NODE_ELEM);
    12611261            String username = ((UserTermInfo) userInfo.get(i)).getUsername();
    1262             String compactedGroups = ((UserTermInfo) userInfo.get(i)).getOrigGroups();
     1262            String compactedGroups = ((UserTermInfo) userInfo.get(i)).getCompactedGroups();
    12631263            // Since this is used for display in admin pages, get compacted (more similar to user-entered) groups
    12641264            // and not expanded groups, as getUserNodeList only used in addUserInformationToNode() which
  • main/trunk/greenstone3/src/java/org/greenstone/gsdl3/util/UserTermInfo.java

    r35298 r35299  
    2727    private String username;
    2828    private String password;
    29         private String origGroups = null; // TODO: rename to compactedGroups and get-method, and update method calls accordingly
     29        /** The user-entered value of groups listing sorted into natural ordering
     30     * (alphabetic/ASCII order in this case) and with duplicates removed */
     31        private String compactedGroups;
     32        /** The user-entered value of groups listing with hierarchical groups expanded, sorted and duplicates removed
     33     * e.g. if groups="nz.ac.waikato.toto,nz.ac.waikato.cs.pinky"; expandedGroups="nz,nz.ac,nz.ac.waikato,nz.ac.waikato.cs,nz.ac.waikato.cs.pinky,nz.ac.waikato.toto" */
    3034        private String expandedGroups;
    3135    private String accountstatus;
     
    3438
    3539    // This constructor is called to instantiate a UserTermInfo object from entries in the userDB
    36     // which now stores expandedGroups instead of the user-entered origGroups
    37     // Use the other constructor if you know the user-entered groups
     40    // which now stores expandedGroups instead of the user-entered groups or the latter's more compactedGroups form
    3841    public UserTermInfo(String username, String password, String expandedGroups,
    3942            String accountStatus, String comment, String email) {
     
    4144    this.password = password;
    4245
    43 
     46    // Ensure these 2 representations of the groups listing are always in sync
    4447    this.expandedGroups = expandedGroups;
    45     this.origGroups = UserTermInfo.compactGroups(this.expandedGroups); // alternative: don't set here and do lazy evaluation when getOrigGroups() is called
     48    this.compactedGroups = UserTermInfo.compactGroups(this.expandedGroups); // alternative: don't set here and do lazy evaluation when getCompactedGroups() is called
     49   
    4650    this.accountstatus = accountStatus;
    4751    this.comment = comment;
    4852    this.email = email;
    4953    }
    50 
    51    
    52     // Not used, for completion's sake:
    53     // If you only have user-entered groups at hand, pass in null or "" for expandedGroups
    54     // to create a UserTermInfo object, which will work out the expandedGroups.
    55     /*
    56     public UserTermInfo(String username, String password, String userEnteredGroups, String expandedGroups,
    57             String accountStatus, String comment, String email) {
    58     this.username = username;
    59     this.password = password;
    60    
    61     this.origGroups = (userEnteredGroups == null) ? "" : userEnteredGroups;
    62     if(expandedGroups == null || expandedGroups.equals("")) {
    63         this.expandedGroups = UserTermInfo.expandGroups(this.origGroups);
    64     }
    65     this.accountstatus = accountStatus;
    66     this.comment = comment;
    67     this.email = email;
    68     }
    69     */
    7054   
    7155    public String toString()
     
    7458        result += "<username = " + username + ">";
    7559        result += "<password = " + password + ">";
    76         result += "<groups = " + origGroups + ">";
     60        result += "<groups = " + expandedGroups + ">"; // compactedGroups?
    7761        result += "<enable = " + accountstatus + ">";
    7862        result += "<comment = " + comment + ">";
     
    9074    }
    9175
    92     public String getOrigGroups() {
    93     return origGroups;
    94     //return UserTermInfo.compactGroups(this.expandedGroups); // not storing, evaluating on demand
    95 
    96     // lazy evaluation: getExpandedGroups() doesn't get called on every enquiry about
    97     // a UserTermInfo struct. It only gets called on authenticated-ping system-action
    98     // (including via ServletRealmCheck being run from run from commandline or gliserver.pl)
    99     // So for a whole list of users and the UserTermInfo struct of each,
    100     // don't pre-calculate and store the expanded groups.
    101     // Is it meaningful to store this at all Ever or better to always evaluate on demand?
    102    
     76    public String getCompactedGroups() {
     77    return compactedGroups;
     78    // could do lazy evaluation by calling UserTermInfo.compactGroups(this.expandedGroups) here and returning it
     79    // or 1st storing answer in compactedGroups member var before returning to avoid reevaluating multiple times.
    10380    }   
    10481   
    10582    public String getExpandedGroups() {
    10683    return expandedGroups;
    107     //return UserTermInfo.expandGroups(this.origGroups); // not storing, evaluating on demand
    108    
    109     // lazy evaluation: getExpandedGroups() doesn't get called on every enquiry about
    110     // a UserTermInfo struct. It only gets called on authenticated-ping system-action
    111     // (including via ServletRealmCheck being run from run from commandline or gliserver.pl)
    112     // So for a whole list of users and the UserTermInfo struct of each,
    113     // don't pre-calculate and store the expanded groups.
    114     // Is it meaningful to store this at all Ever or better to always evaluate on demand?
    115     ///if(expandedGroups == null) {
    116     ///    expandedGroups = UserTermInfo.expandGroups(this.origGroups);
    117     ///}
    118     ///return expandedGroups;
    11984    }
    12085
     
    196161        return compactGroupList.toString();
    197162    }
    198    
    199    
    200     /*
    201     else {
    202      
    203 
    204         String[] indivGroups = groups.split("\\s*,\\s*"); // simultaneously get rid of whitespace surrounding commas
    205         if(indivGroups.length == 0) {
    206         return groups;
    207         }
    208         Set<String> compactGroups = new TreeSet<String>();
    209         String currGroup = indivGroups[indivGroups.length-1];
    210         for(int i = indivGroups.length-1; i--; i > 0) {
    211         String prevGroup = indivGroups[i-1];
    212        
    213         int indexOfPeriod = currGroup.indexOf('.');
    214         if(indexOfPeriod == -1) {
    215            compactGroups.add(currGroup);
    216            currGroup = prevGroup;
    217         }
    218         else {
    219        
    220             if(currGroup.startsWith(prevGroup)) {
    221             compactGroups.add(currGroup);
    222             if(i == 0) {
    223                 break;             
    224             } else {
    225                 i--;
    226                 currGroup = indivGroups[i];
    227             }
    228             }
    229             else {
    230             compactGroups.add(currGroup);
    231             currGroup = prevGroup;
    232             }
    233         }
    234         }
    235     }
    236     */
    237163    }
    238164
     
    311237
    312238
    313      /*
    314     public static String expandGroups(String groups) {
    315     if(groups.indexOf('.') == -1) {
    316         return groups;
    317     }
    318     else {
    319         // Build up the string again
    320         StringBuilder expandedGroupList = new StringBuilder();     
    321 
    322         String[] indivGroups = groups.split("\\s*,\\s*"); // simultaneously get rid of any whitespace surrounding commas
    323         for(String s : indivGroups) {
    324         int indexOfPeriod = s.indexOf('.');
    325 
    326         if(indexOfPeriod != -1) {
    327             do {
    328             String expandedGroup = s.substring(0, indexOfPeriod);
    329             expandedGroupList.append(expandedGroup);
    330             expandedGroupList.append(',');
    331             indexOfPeriod += 1;         
    332             indexOfPeriod = s.indexOf('.', indexOfPeriod);
    333             } while(indexOfPeriod != -1);
    334         }
    335 
    336         // Whether this particular group s contained a period or not,
    337         // remember to add this group string, s, back in in its entirety too       
    338         expandedGroupList.append(s);
    339         expandedGroupList.append(',');
    340         }
    341         expandedGroupList.deleteCharAt(expandedGroupList.length()-1); // remove extraneous comma       
    342         return expandedGroupList.toString();
    343     }
    344     }
    345     */
    346    
    347239}
Note: See TracChangeset for help on using the changeset viewer.