Project

General

Profile

« Previous | Next » 

Revision 10205

Added by Jing Tao over 7 years ago

In the expandRightHolder method, we don't use the parameter count=-1 to query the cn. Now we use count=200 and will use the page query to query again if it is necessary.

View differences:

src/edu/ucsb/nceas/metacat/dataone/D1NodeService.java
72 72
import org.dataone.service.types.v1.Identifier;
73 73
import org.dataone.service.types.v1.ObjectFormatIdentifier;
74 74
import org.dataone.service.types.v1.ObjectList;
75
import org.dataone.service.types.v1.Person;
75 76
import org.dataone.service.types.v1.SubjectInfo;
76 77
import org.dataone.service.types.v2.Log;
77 78
import org.dataone.service.types.v2.Node;
......
1279 1280
      boolean is = false;
1280 1281
      if(rightHolder != null && userSession != null && rightHolder.getValue() != null && !rightHolder.getValue().trim().equals("") && userSession.getValue() != null && !userSession.getValue().trim().equals("")) {
1281 1282
          CNode cn = D1Client.getCN();
1282
          logMetacat.debug("D1NodeService.expandRightHolder - after getting the cn node and cn node is "+cn.getNodeBaseServiceUrl());
1283
          logMetacat.debug("D1NodeService.expandRightHolder - at the start of method: after getting the cn node and cn node is "+cn.getNodeBaseServiceUrl());
1283 1284
          String query= rightHolder.getValue();
1284 1285
          int start =0;
1285
          int count=-1;
1286
          int count= 200;
1286 1287
          String status = null;
1287 1288
          Session session = null;
1288 1289
          SubjectInfo subjects = cn.listSubjects(session, query, status, start, count);
1289
          if(subjects != null) {
1290

  
1291
          while(subjects != null) {
1290 1292
              logMetacat.debug("D1NodeService.expandRightHolder - search the subject "+query+" in the cn and the returned result is not null");
1291 1293
              List<Group> groups = subjects.getGroupList();
1292
              if(groups != null) {
1293
                  logMetacat.debug("D1NodeService.expandRightHolder - search the subject "+query+" in the cn and the returned result does include groups and the size of groups is "+groups.size());
1294
                  for(Group group : groups) {
1295
                      //logMetacat.debug("D1NodeService.expandRightHolder - group has the subject "+group.getSubject().getValue());
1296
                      if(group != null && group.getSubject() != null && group.getSubject().equals(rightHolder)) {
1297
                          logMetacat.debug("D1NodeService.expandRightHolder - there is a group in the list having the subjecct "+group.getSubject().getValue()+" which matches the right holder's subject "+rightHolder.getValue());
1298
                          List<Subject> members = group.getHasMemberList();
1299
                          if(members != null ){
1300
                              logMetacat.debug("D1NodeService.expandRightHolder - the group "+group.getSubject().getValue()+" in the cn has members");
1301
                              for(Subject member : members) {
1302
                                  logMetacat.debug("D1NodeService.expandRightHolder - compare the member "+member.getValue()+" with the user "+userSession.getValue());
1303
                                  if(member.getValue() != null && !member.getValue().trim().equals("") && userSession.getValue() != null && member.getValue().equals(userSession.getValue())) {
1304
                                      logMetacat.debug("D1NodeService.expandRightHolder - Find it! The member "+member.getValue()+" in the group "+group.getSubject().getValue()+" matches the user "+userSession.getValue());
1305
                                      is = true;
1306
                                      return is;
1307
                                  }
1308
                              }
1309
                          }
1310
                          break;//we found the group but can't find the member matches the user. so break it.
1311
                      }
1294
              is = isInGroups(userSession, rightHolder, groups);
1295
              if(is) {
1296
                  //since we find it, return it.
1297
                  return is;
1298
              } else {
1299
                  //decide if we need to try the page query for another trying.
1300
                  int sizeOfGroups = 0;
1301
                  if(groups != null) {
1302
                     sizeOfGroups  = groups.size();
1312 1303
                  }
1313
              } else {
1314
                  logMetacat.debug("D1NodeService.expandRightHolder - search the subject "+query+" in the cn and the returned result does NOT have a group");
1304
                  List<Person> persons = subjects.getPersonList();
1305
                  int sizeOfPersons = 0;
1306
                  if(persons != null) {
1307
                      sizeOfPersons = persons.size();
1308
                  }
1309
                  int totalSize = sizeOfGroups+sizeOfPersons;
1310
                  //logMetacat.debug("D1NodeService.expandRightHolder - search the subject "+query+" in the cn and the size of return result is "+totalSize);
1311
                 //we can't find the target on the first query, maybe query again.
1312
                  if(totalSize == count) {
1313
                      start = start+count;
1314
                      logMetacat.debug("D1NodeService.expandRightHolder - search the subject "+query+" in the cn and the size of return result equals the count "+totalSize+" .And we didn't find the target in the this query. So we have to use the page query with the start number "+start);
1315
                      subjects = cn.listSubjects(session, query, status, start, count);
1316
                  } else if (totalSize < count){
1317
                      logMetacat.debug("D1NodeService.expandRightHolder - we are already at the end of the returned restult since the size of returned results "+totalSize+
1318
                          " is less than the count "+count+". So we have to break the loop and finish the try.");
1319
                      break;
1320
                  } else if (totalSize >count) {
1321
                      logMetacat.warn("D1NodeService.expandRightHolder - Something is wrong on the implementation of the method listSubject since the size of returned results "+totalSize+
1322
                              " is greater than the count "+count+". So we have to break the loop and finish the try.");
1323
                      break;
1324
                  }
1315 1325
              }
1316
          } else {
1317
              logMetacat.debug("D1NodeService.expandRightHolder - search the subject "+query+" in the cn and the returned result is null");
1318
          }
1326
              
1327
          } 
1328
          //logMetacat.debug("D1NodeService.expandRightHolder - search the subject "+query+" in the cn and the returned result is null");
1319 1329
          if(!is) {
1320 1330
              logMetacat.debug("D1NodeService.expandRightHolder - We can NOT find any member in the group "+query+" (if it is a group) matches the user "+userSession.getValue());
1321 1331
          }
......
1325 1335
     
1326 1336
      return is;
1327 1337
  }
1338
  
1328 1339
  /*
1340
   * If the given useSession is a member of a group which is in the given list of groups and has the name of righHolder.
1341
   */
1342
  private static boolean isInGroups(Subject userSession, Subject rightHolder, List<Group> groups) {
1343
      boolean is = false;
1344
      if(groups != null) {
1345
          logMetacat.debug("D1NodeService.isInGroups -  the given groups' (the returned result including groups) size is "+groups.size());
1346
          for(Group group : groups) {
1347
              //logMetacat.debug("D1NodeService.expandRightHolder - group has the subject "+group.getSubject().getValue());
1348
              if(group != null && group.getSubject() != null && group.getSubject().equals(rightHolder)) {
1349
                  logMetacat.debug("D1NodeService.isInGroups - there is a group in the list having the subjecct "+group.getSubject().getValue()+" which matches the right holder's subject "+rightHolder.getValue());
1350
                  List<Subject> members = group.getHasMemberList();
1351
                  if(members != null ){
1352
                      logMetacat.debug("D1NodeService.isInGroups - the group "+group.getSubject().getValue()+" in the cn has members");
1353
                      for(Subject member : members) {
1354
                          logMetacat.debug("D1NodeService.isInGroups - compare the member "+member.getValue()+" with the user "+userSession.getValue());
1355
                          if(member.getValue() != null && !member.getValue().trim().equals("") && userSession.getValue() != null && member.getValue().equals(userSession.getValue())) {
1356
                              logMetacat.debug("D1NodeService.isInGroups - Find it! The member "+member.getValue()+" in the group "+group.getSubject().getValue()+" matches the user "+userSession.getValue());
1357
                              is = true;
1358
                              return is;
1359
                          }
1360
                      }
1361
                  }
1362
                  break;//we found the group but can't find the member matches the user. so break it.
1363
              }
1364
          }
1365
      } else {
1366
          logMetacat.debug("D1NodeService.isInGroups -  the given group is null (the returned result does NOT have a group");
1367
      }
1368
      return is;
1369
  }
1370
  /*
1329 1371
   * parse a logEntry and get the relevant field from it
1330 1372
   * 
1331 1373
   * @param fieldname

Also available in: Unified diff