Project

General

Profile

Revision 5391

Added by berkley almost 11 years ago

finished getLogRecords. Fixed some date bugs in metacat.

View differences:

lib/web.xml.tomcat5
384 384
        <servlet-name>RestServlet</servlet-name>
385 385
        <url-pattern>/identifier/*</url-pattern>
386 386
    </servlet-mapping>
387
    
388
    <servlet-mapping>
389
        <servlet-name>RestServlet</servlet-name>
390
        <url-pattern>/log/*</url-pattern>
391
    </servlet-mapping>
387 392

  
388 393

  
389 394
 <!-- uncomment this if you want the admin servlet -->
src/edu/ucsb/nceas/metacat/restservice/ResourceHandler.java
32 32
import javax.servlet.http.HttpServletRequest;
33 33
import javax.servlet.http.HttpServletResponse;
34 34
import java.text.DateFormat;
35
import java.text.ParsePosition;
36
import java.text.SimpleDateFormat;
35 37

  
38

  
36 39
import org.apache.commons.httpclient.util.DateParser;
37 40
import org.apache.commons.io.IOUtils;
38 41
import org.apache.log4j.Logger;
......
388 391
        OutputStream out = null;
389 392
        try
390 393
        {
394
            System.out.println("getting logs.");
391 395
            out = response.getOutputStream();
392 396
            AuthToken token = new AuthToken(sessionId);
393 397
            String fromDateS = params.get("fromDate")[0];
......
396 400
            Date toDate = null;
397 401
            String eventS = params.get("event")[0];
398 402
            Event event = null;
403
            SimpleDateFormat sdf = new SimpleDateFormat();
399 404
            if(fromDateS != null)
400 405
            {
401
                fromDate = DateParser.parseDate(fromDateS);
406
                System.out.println("fromDate: " + fromDateS);
407
                fromDate = new Date(new Long(fromDateS).longValue());//sdf.parse(fromDateS, new ParsePosition(0));
402 408
            }
403 409
            if(toDateS != null)
404 410
            {
405
                toDate = DateParser.parseDate(toDateS);
411
                System.out.println("toDate: " + toDateS);
412
                toDate = new Date(new Long(toDateS).longValue());//sdf.parse(toDateS, new ParsePosition(0));
406 413
            }
407 414
            if(eventS != null)
408 415
            {
416
                System.out.println("event: " + eventS);
409 417
                event = Event.convert(eventS);
410 418
            }
411

  
419
            System.out.println("calling CrudService.getLogRecords");
420
            System.out.println("fromDate: " + fromDate);
421
            System.out.println("toDate: " + toDate);
422
            System.out.println("event: " + event);
412 423
            Log log = CrudService.getInstance().getLogRecords(token, fromDate, toDate, event);
424
            System.out.println("done with CrudService.");
413 425
            serializeServiceType(Log.class, log, out);
426
            System.out.println("Done serializing output.");
414 427
        }
415 428
        catch(Exception e)
416 429
        {
......
625 638
                { //parse the params and make the crud call
626 639
                    String name = (String) paramlist.nextElement();
627 640
                    String[] value = (String[])request.getParameterValues(name);
628
                    if(name.equals("startTime"))
641
                    System.out.println("name: " + name + " value: " + value);
642
                    if(name.equals("startTime") && value != null)
629 643
                    {
630 644
                        try
631 645
                        {
......
637 651
                            startTime = null;
638 652
                        }
639 653
                    }
640
                    else if(name.equals("endTime"))
654
                    else if(name.equals("endTime") && value != null)
641 655
                    {
642 656
                        try
643 657
                        {
......
649 663
                            endTime = null;
650 664
                        }
651 665
                    }
652
                    else if(name.equals("objectFormat"))
666
                    else if(name.equals("objectFormat") && value != null)
653 667
                    {
654 668
                        objectFormat = ObjectFormat.convert(value[0]);
655 669
                    }
656
                    else if(name.equals("replicaStatus"))
670
                    else if(name.equals("replicaStatus") && value != null)
657 671
                    {
658
                        if(value[0].equals("true") || value[0].equals("TRUE") || value[0].equals("YES"))
672
                        if(value != null && 
673
                           value.length > 0 && 
674
                           (value[0].equals("true") || value[0].equals("TRUE") || value[0].equals("YES")))
659 675
                        {
660 676
                            replicaStatus = true;
661 677
                        }
662 678
                    }
663
                    else if(name.equals("start"))
679
                    else if(name.equals("start") && value != null)
664 680
                    {
665 681
                        start = new Integer(value[0]).intValue();
666 682
                    }
667
                    else if(name.equals("count"))
683
                    else if(name.equals("count") && value != null)
668 684
                    {
669 685
                        count = new Integer(value[0]).intValue();
670 686
                    }
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
665 665
        Vector<LogEntry> logs = new Vector<LogEntry>();
666 666
        IdentifierManager im = IdentifierManager.getInstance();
667 667
        EventLog el = EventLog.getInstance();
668
        if(fromDate == null)
669
        {
670
            fromDate = new Date(1);
671
        }
672
        if(toDate == null)
673
        {
674
            toDate = new Date();
675
        }
668 676
        String report = el.getReport(null, null, null, null, 
669 677
                new java.sql.Timestamp(fromDate.getTime()), 
670 678
                new java.sql.Timestamp(toDate.getTime()));

Also available in: Unified diff