Project

General

Profile

« Previous | Next » 

Revision 5389

Added by berkley over 14 years ago

changed getLogRecords to use new classes for log events

View differences:

test/edu/ucsb/nceas/metacat/dataone/CrudServiceTest.java
39 39
import junit.framework.Test;
40 40
import junit.framework.TestSuite;
41 41

  
42
import org.apache.log.LogEvent;
42 43
import org.dataone.service.exceptions.InvalidRequest;
43 44
import org.dataone.service.exceptions.InvalidToken;
44 45
import org.dataone.service.exceptions.NotAuthorized;
......
155 156
	        Date fromDate = new Date();
156 157
	        Identifier id = createDoc(token, getTestDoc());
157 158
	        Date toDate = new Date();
158
	        LogRecordSet lrs = cs.getLogRecords(token, fromDate, toDate);
159
	        Set s = lrs.getRecords();
160
	        assertNotNull(s);
161
	        assertTrue(lrs.getRecords().size() == 1);
162
	        LogRecord lrLogRecord = (LogRecord)s.iterator().next();
163
	        
159
	        Log lrs = cs.getLogRecords(token, fromDate, toDate);
160
	        assertNotNull(lrs);
161
	        assertTrue(lrs.sizeLogEntryList() == 1);
162
	        LogEntry lrLogEvent = lrs.getLogEntry(0);
163
	        assertTrue(lrLogEvent.getEvent().name().equals("CREATE"));
164 164
	    }
165 165
	    catch(Exception e)
166 166
	    {
......
664 664
	private void printTestHeader(String testName)
665 665
	{
666 666
	    System.out.println();
667
	    System.out.println("********************************** " + testName + " **********************************");
667
	    System.out.println("*************** " + testName + " ***************");
668 668
	}
669 669
  
670 670
	/**
src/edu/ucsb/nceas/metacat/dataone/CrudService.java
657 657
    /**
658 658
     * get log records.  
659 659
     */
660
    public LogRecordSet getLogRecords(AuthToken token, Date fromDate, Date toDate)
660
    public Log getLogRecords(AuthToken token, Date fromDate, Date toDate)
661 661
            throws InvalidToken, ServiceFailure, NotAuthorized, InvalidRequest, 
662 662
            NotImplemented 
663 663
    {
664
        Log log = new Log();
665
        Vector<LogEntry> logs = new Vector<LogEntry>();
664 666
        IdentifierManager im = IdentifierManager.getInstance();
665
        HashSet<LogRecord> logs = new HashSet<LogRecord>();
666 667
        EventLog el = EventLog.getInstance();
667 668
        String report = el.getReport(null, null, null, null, 
668 669
                new java.sql.Timestamp(fromDate.getTime()), 
......
688 689
            String event = getLogEntryField("event", entry);
689 690
            String dateLogged = getLogEntryField("dateLogged", entry);
690 691
            
691
            LogRecord lr = new LogRecord();
692
            LogEntry le = new LogEntry();
692 693
            
693 694
            Event e = Event.convert(event);
694 695
            if(e == null)
695 696
            { //skip any events that are not Dataone Crud events
696 697
                continue;
697 698
            }
698
            lr.setEvent(e);
699
            le.setEvent(e);
699 700
            Identifier entryid = new Identifier();
700 701
            entryid.setValue(entryId);
701
            lr.setEntryId(entryid);
702
            le.setEntryId(entryid);
702 703
            Identifier identifier = new Identifier();
703 704
            try
704 705
            {
......
709 710
                identifier.setValue(docid);
710 711
            }
711 712
            
712
            lr.setIdentifier(identifier);
713
            lr.setIpAddress(ipAddress);
713
            le.setIdentifier(identifier);
714
            le.setIpAddress(ipAddress);
714 715
            Calendar c = Calendar.getInstance();
715 716
            String year = dateLogged.substring(0, 4);
716 717
            String month = dateLogged.substring(5, 7);
......
718 719
            //System.out.println("year: " + year + " month: " + month + " day: " + date);
719 720
            c.set(new Integer(year).intValue(), new Integer(month).intValue(), new Integer(date).intValue());
720 721
            Date logDate = c.getTime();
721
            lr.setLogDate(logDate);
722
            le.setDateLogged(logDate);
722 723
            NodeReference memberNode = new NodeReference();
723 724
            memberNode.setValue(ipAddress);
724
            lr.setMemberNode(memberNode);
725
            le.setMemberNode(memberNode);
725 726
            Principal princ = new Principal();
726 727
            princ.setValue(principal);
727
            lr.setPrincipal(princ);
728
            lr.setUserAgent("metacat/RESTService");
729
            logs.add(lr);
728
            le.setPrincipal(princ);
729
            le.setUserAgent("metacat/RESTService");
730
            logs.add(le);
730 731
        }
731 732
        
732
        LogRecordSet set = new LogRecordSet(logs);
733
        set.setRecords(logs);
734
        return set;
733
        log.setLogEntryList(logs);
734
        return log;
735 735
    }
736 736
    
737 737
    /**

Also available in: Unified diff