Project

General

Profile

« Previous | Next » 

Revision 5413

Added by berkley over 14 years ago

fixed query for listObjects so that paging works as advertised.

View differences:

test/test.properties
1 1
# Set this to the location of the metacat application context
2 2
# directory.  The tests will use this to find metacat.properties
3
metacat.contextDir=/var/lib/tomcat/webapps/knb
3
metacat.contextDir=/Users/berkley/tools/tomcat/webapps/knb
4 4
#metacat.contextDir=/usr/share/tomcat5.5/webapps/knb
test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
87 87
	public static Test suite() 
88 88
	{
89 89
		TestSuite suite = new TestSuite();
90
		suite.addTest(new CrudServiceTest("initialize"));
90
		/*suite.addTest(new CrudServiceTest("initialize"));
91 91
		suite.addTest(new CrudServiceTest("testSingletonAccessor"));
92 92
		suite.addTest(new CrudServiceTest("testCreateAndGet"));
93 93
		suite.addTest(new CrudServiceTest("testGetSystemMetadata"));
94
		suite.addTest(new CrudServiceTest("testUpdate"));
94
		suite.addTest(new CrudServiceTest("testUpdate"));*/
95 95
		suite.addTest(new CrudServiceTest("testListObjects"));
96
		suite.addTest(new CrudServiceTest("testAccessControl"));
96
		/*suite.addTest(new CrudServiceTest("testAccessControl"));
97 97
		suite.addTest(new CrudServiceTest("testGenerateMissingSystemMetadata"));
98 98
		suite.addTest(new CrudServiceTest("testGetLogRecords"));
99 99
		suite.addTest(new CrudServiceTest("testChecksumError"));
100
		//suite.addTest(new CrudServiceTest("testPublicAccess"));
100
		suite.addTest(new CrudServiceTest("testPublicAccess"));*/
101 101
		return suite;
102 102
	}
103 103
	
......
344 344
            //now get the objects for specific time ranges and test that it returns
345 345
            //the correct objects
346 346
            
347
            ObjectList list = cs.listObjects(token, null, null, null);
347
            //ObjectList list = cs.listObjects(token, null, null, null);
348 348
            //System.out.println("list size: " + list.sizeObjectInfoList());
349 349
           
350 350
            //should return sm1 and sm2
......
395 395
            //should return 4 (id1 is not public)
396 396
            token = new AuthToken("public");
397 397
            ObjectList list7 = cs.listObjects(token, d1, d6, null);
398
            System.out.println("list7 size: " + list7.sizeObjectInfoList());
398
            //System.out.println("list7 size: " + list7.sizeObjectInfoList());
399 399
            assertTrue(list7.sizeObjectInfoList() == 4);
400 400
            
401
            //test paging
402
            ObjectList list8 = cs.listObjects(token, d1, d6, null, false, 2, 2);
403
            assertTrue(list8.getCount() == 2);
404
            assertTrue(list8.getStart() == 2);
405
            assertTrue(list8.getTotal() == 4);
406
            
401 407
	    }
402 408
	    catch(Exception e)
403 409
	    {
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
633 633
                { //parse the params and make the crud call
634 634
                    String name = (String) paramlist.nextElement();
635 635
                    String[] value = (String[])request.getParameterValues(name);
636
                    System.out.println("name: " + name + " value: " + value);
636
                    for(int i=0; i<value.length; i++)
637
                    {
638
                        System.out.println("name: " + name + " value: " + value[i]);
639
                    }
637 640
                    if(name.equals("startTime") && value != null)
638 641
                    {
639 642
                        try
......
688 691
                */
689 692
                ObjectList ol = cs.listObjects(token, startTime, endTime, 
690 693
                        objectFormat, replicaStatus, start, count);
691
                ol = cs.listObjects(token, null, null, null, false, 0, 1000);
694
                ol = cs.listObjects(token, startTime, endTime, objectFormat, replicaStatus, start, count);
692 695
                
693 696
                StringReader sr = new StringReader(ol.toString());                
694 697
                out = response.getOutputStream();                
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
455 455
    {
456 456
      ObjectList ol = new ObjectList();
457 457
      final SessionData sessionData = getSessionData(token);
458
      int totalAfterQuery = 0;
458 459
      try
459 460
      {
460 461
          params.clear();
......
475 476
              count = docs.size();
476 477
          }
477 478
          
478
          //System.out.println("query returned " + count + " documents.");
479
          //System.out.println("query returned " + docs.size() + " documents.");
480
          Vector<Document> docCopy = new Vector<Document>();
479 481
          
480
          for(int i=start; i<count; i++)
482
          //preparse the list to remove any that don't match the query params
483
          for(int i=0; i<docs.size(); i++)
481 484
          {
482
              //get the document from the result
483 485
              Document d = (Document)docs.get(i);
484
              //System.out.println("processing doc " + d.docid);
485 486
              ObjectFormat returnedObjectFormat = ObjectFormat.convert(d.getField("objectFormat"));
486
              if(returnedObjectFormat == null)
487
              {
488
                  continue;
489
              }
490
              if(objectFormat != null && !objectFormat.toString().trim().equals(returnedObjectFormat.toString().trim()))
487
              
488
              if(returnedObjectFormat != null && 
489
                 objectFormat != null && 
490
                 !objectFormat.toString().trim().equals(returnedObjectFormat.toString().trim()))
491 491
              { //make sure the objectFormat is the one specified
492 492
                  continue;
493 493
              }
494 494
              
495 495
              String dateSMM = d.getField("dateSysMetadataModified");
496
              if(dateSMM == null)
497
              {
496
              if((startTime != null || endTime != null) && dateSMM == null)
497
              {  //if startTime or endTime are not null, we need a date to compare to
498 498
                  continue;
499 499
              }
500
              Date dateSysMetadataModified = parseDate(dateSMM);
500
              
501
              //date parse
502
              Date dateSysMetadataModified = null;
503
              if(dateSMM != null)
504
              {
505
                  dateSysMetadataModified = parseDate(dateSMM);
506
              }
507
              //System.out.println("dateSysMetadataModified: " + dateSysMetadataModified);
508
              //System.out.println("startTime: " + startTime);
509
              //System.out.println("endtime: " + endTime);
501 510
              int startDateComparison = 0;
502 511
              int endDateComparison = 0;
503 512
              if(startTime != null)
504 513
              {
505
                  startDateComparison = dateSysMetadataModified.compareTo(startTime);
514
                  if(dateSysMetadataModified == null)
515
                  {
516
                      startDateComparison = -1;
517
                  }
518
                  else
519
                  {
520
                      startDateComparison = dateSysMetadataModified.compareTo(startTime);
521
                  }
522
                  //System.out.println("startDateCom: " + startDateComparison);
506 523
              }
524
              else
525
              {
526
                  startDateComparison = 1;
527
              }
507 528
              
508 529
              if(endTime != null)
509 530
              {
510
                  endDateComparison = dateSysMetadataModified.compareTo(endTime);
531
                  if(dateSysMetadataModified == null)
532
                  {
533
                      endDateComparison = 1;
534
                  }
535
                  else
536
                  {
537
                      endDateComparison = dateSysMetadataModified.compareTo(endTime);
538
                  }
539
                  //System.out.println("endDateCom: " + endDateComparison);
511 540
              }
541
              else
542
              {
543
                  endDateComparison = -1;
544
              }
512 545
              
546
              
513 547
              if(startDateComparison < 0 || endDateComparison > 0)
514
              { //this date falls outside of the startTime and endTime params, so
515
                //skip it
548
              { 
516 549
                  continue;                  
517 550
              }
518 551
              
552
              docCopy.add((Document)docs.get(i));
553
          } //end pre-parse
554
          
555
          docs = docCopy;
556
          totalAfterQuery = docs.size();
557
          //System.out.println("total after subquery: " + totalAfterQuery);
558
          
559
          //make sure we don't run over the end
560
          int end = start + count;
561
          if(end > docs.size())
562
          {
563
              end = docs.size();
564
          }
565
          
566
          for(int i=start; i<end; i++)
567
          {
568
              //get the document from the result
569
              Document d = (Document)docs.get(i);
570
              //System.out.println("processing doc " + d.docid);
571
              
572
              String dateSMM = d.getField("dateSysMetadataModified");
573
              Date dateSysMetadataModified = null;
574
              if(dateSMM != null)
575
              {
576
                  try
577
                  {
578
                      dateSysMetadataModified = parseDate(dateSMM);
579
                  }
580
                  catch(Exception e)
581
                  { //if we fail to parse the date, just ignore the value
582
                      dateSysMetadataModified = null;
583
                  }
584
              }
585
              ObjectFormat returnedObjectFormat = ObjectFormat.convert(d.getField("objectFormat"));
586
                
587
              
519 588
              ObjectInfo info = new ObjectInfo();
520 589
              //add the fields to the info object
521 590
              Checksum cs = new Checksum();
......
533 602
              id.setValue(d.getField("identifier"));
534 603
              info.setIdentifier(id);
535 604
              info.setObjectFormat(returnedObjectFormat);
536
              info.setSize(new Long(d.getField("size").trim()).longValue());
605
              String size = d.getField("size");
606
              if(size != null)
607
              {
608
                  info.setSize(new Long(size.trim()).longValue());
609
              }
537 610
              //add the ObjectInfo to the ObjectList
538 611
              ol.addObjectInfo(info);
539 612
          }
......
548 621
              username, null, "read");
549 622
      logCrud.info("listObjects");
550 623
      //System.out.println("ol.size: " + ol.sizeObjectInfoList());
551
      ol.setCount(ol.sizeObjectInfoList());
552
      ol.setStart(0);
553
      ol.setTotal(ol.sizeObjectInfoList());
624
      ol.setCount(count);
625
      ol.setStart(start);
626
      ol.setTotal(totalAfterQuery);
554 627
      return ol;
555 628
    }
556 629
    

Also available in: Unified diff