View Javadoc
1   /**
2    * Copyright 2014 Internet2
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  /*
17   * @author mchyzer
18   * $Id: AuditEntry.java,v 1.9 2009-05-26 06:50:56 mchyzer Exp $
19   */
20  package edu.internet2.middleware.grouper.audit;
21  
22  import java.io.StringWriter;
23  import java.sql.Timestamp;
24  import java.text.SimpleDateFormat;
25  import java.util.Set;
26  
27  import org.apache.commons.lang.StringUtils;
28  import org.apache.commons.lang.builder.EqualsBuilder;
29  
30  import edu.internet2.middleware.grouper.GrouperAPI;
31  import edu.internet2.middleware.grouper.GrouperSession;
32  import edu.internet2.middleware.grouper.Member;
33  import edu.internet2.middleware.grouper.MemberFinder;
34  import edu.internet2.middleware.grouper.app.loader.GrouperLoader;
35  import edu.internet2.middleware.grouper.hibernate.GrouperContext;
36  import edu.internet2.middleware.grouper.hibernate.HibernateSession;
37  import edu.internet2.middleware.grouper.internal.dao.hib3.Hib3GrouperVersioned;
38  import edu.internet2.middleware.grouper.internal.util.GrouperUuid;
39  import edu.internet2.middleware.grouper.misc.GrouperDAOFactory;
40  import edu.internet2.middleware.grouper.misc.GrouperVersion;
41  import edu.internet2.middleware.grouper.util.GrouperUtil;
42  import edu.internet2.middleware.grouper.xml.export.XmlExportAuditEntry;
43  import edu.internet2.middleware.grouper.xml.export.XmlImportable;
44  import edu.internet2.middleware.subject.Subject;
45  
46  
47  /**
48   * represents a user audit record.  This is one unit of work that could 
49   * contain multiple operations.
50   */
51  @SuppressWarnings("serial")
52  public class AuditEntry extends GrouperAPI implements Hib3GrouperVersioned, XmlImportable<AuditEntry> {
53    
54    //*****  START GENERATED WITH GenerateFieldConstants.java *****//
55  
56    /** constant for field name for: actAsMemberId */
57    public static final String FIELD_ACT_AS_MEMBER_ID = "actAsMemberId";
58  
59    /** constant for field name for: auditTypeId */
60    public static final String FIELD_AUDIT_TYPE_ID = "auditTypeId";
61  
62    /** constant for field name for: contextId */
63    public static final String FIELD_CONTEXT_ID = "contextId";
64  
65    /** constant for field name for: createdOnDb */
66    public static final String FIELD_CREATED_ON_DB = "createdOnDb";
67  
68    /** constant for field name for: description */
69    public static final String FIELD_DESCRIPTION = "description";
70  
71    /** constant for field name for: durationMicroseconds */
72    public static final String FIELD_DURATION_MICROSECONDS = "durationMicroseconds";
73  
74    /** constant for field name for: envName */
75    public static final String FIELD_ENV_NAME = "envName";
76  
77    /** constant for field name for: grouperEngine */
78    public static final String FIELD_GROUPER_ENGINE = "grouperEngine";
79  
80    /** constant for field name for: grouperVersion */
81    public static final String FIELD_GROUPER_VERSION = "grouperVersion";
82  
83    /** constant for field name for: id */
84    public static final String FIELD_ID = "id";
85  
86    /** constant for field name for: int01 */
87    public static final String FIELD_INT01 = "int01";
88  
89    /** constant for field name for: int02 */
90    public static final String FIELD_INT02 = "int02";
91  
92    /** constant for field name for: int03 */
93    public static final String FIELD_INT03 = "int03";
94  
95    /** constant for field name for: int04 */
96    public static final String FIELD_INT04 = "int04";
97  
98    /** constant for field name for: int05 */
99    public static final String FIELD_INT05 = "int05";
100 
101   /** constant for field name for: lastUpdatedDb */
102   public static final String FIELD_LAST_UPDATED_DB = "lastUpdatedDb";
103 
104   /** constant for field name for: loggedInMemberId */
105   public static final String FIELD_LOGGED_IN_MEMBER_ID = "loggedInMemberId";
106 
107   /** constant for field name for: queryCount */
108   public static final String FIELD_QUERY_COUNT = "queryCount";
109 
110   /** constant for field name for: serverHost */
111   public static final String FIELD_SERVER_HOST = "serverHost";
112 
113   /** constant for field name for: serverUserName */
114   public static final String FIELD_SERVER_USER_NAME = "serverUserName";
115 
116   /** constant for field name for: string01 */
117   public static final String FIELD_STRING01 = "string01";
118 
119   /** constant for field name for: string02 */
120   public static final String FIELD_STRING02 = "string02";
121 
122   /** constant for field name for: string03 */
123   public static final String FIELD_STRING03 = "string03";
124 
125   /** constant for field name for: string04 */
126   public static final String FIELD_STRING04 = "string04";
127 
128   /** constant for field name for: string05 */
129   public static final String FIELD_STRING05 = "string05";
130 
131   /** constant for field name for: string06 */
132   public static final String FIELD_STRING06 = "string06";
133 
134   /** constant for field name for: string07 */
135   public static final String FIELD_STRING07 = "string07";
136 
137   /** constant for field name for: string08 */
138   public static final String FIELD_STRING08 = "string08";
139 
140   /** constant for field name for: userIpAddress */
141   public static final String FIELD_USER_IP_ADDRESS = "userIpAddress";
142 
143   //*****  END GENERATED WITH GenerateFieldConstants.java *****//
144 
145   /** to string deep fields */
146   private static final Set<String> TO_STRING_DEEP_FIELDS = GrouperUtil.toSet(
147       FIELD_ACT_AS_MEMBER_ID, FIELD_AUDIT_TYPE_ID, FIELD_CONTEXT_ID, FIELD_CREATED_ON_DB, 
148       FIELD_DESCRIPTION, FIELD_DURATION_MICROSECONDS, FIELD_ENV_NAME, FIELD_GROUPER_ENGINE, 
149       FIELD_GROUPER_VERSION, FIELD_HIBERNATE_VERSION_NUMBER, FIELD_ID, FIELD_INT01, 
150       FIELD_INT02, FIELD_INT03, FIELD_INT04, FIELD_INT05, 
151       FIELD_LAST_UPDATED_DB, FIELD_LOGGED_IN_MEMBER_ID, FIELD_QUERY_COUNT, FIELD_SERVER_HOST, 
152       FIELD_SERVER_USER_NAME, FIELD_STRING01, FIELD_STRING02, FIELD_STRING03, 
153       FIELD_STRING04, FIELD_STRING05, FIELD_STRING06, FIELD_STRING07, 
154       FIELD_STRING08, FIELD_USER_IP_ADDRESS);
155 
156   /**
157    * see if one audit type is the same as another (not looking at last update, id, etc)
158    * @param auditEntry
159    * @return true if equals, false if not
160    */
161   public boolean equalsDeep(AuditEntry auditEntry) {
162     
163     return new EqualsBuilder().append(this.actAsMemberId, auditEntry.actAsMemberId)
164       .append(this.auditTypeId, auditEntry.auditTypeId)
165       .append(this.contextId, auditEntry.contextId)
166       .append(this.createdOnDb, auditEntry.createdOnDb)
167       .append(this.description, auditEntry.description)
168       .append(this.durationMicroseconds, auditEntry.durationMicroseconds)
169       .append(this.envName, auditEntry.envName)
170       .append(this.grouperEngine, auditEntry.grouperEngine)
171       .append(this.grouperVersion, auditEntry.grouperVersion)
172       .append(this.id, auditEntry.id)
173       .append(this.int01, auditEntry.int01)
174       .append(this.int02, auditEntry.int02)
175       .append(this.int03, auditEntry.int03)
176       .append(this.int04, auditEntry.int04)
177       .append(this.int05, auditEntry.int05)
178       //not last updated
179       .append(this.loggedInMemberId, auditEntry.loggedInMemberId)
180       .append(this.queryCount, auditEntry.queryCount)
181       .append(this.serverHost, auditEntry.serverHost)
182       .append(this.serverUserName, auditEntry.serverUserName)
183       .append(this.string01, auditEntry.string01)
184       .append(this.string02, auditEntry.string02)
185       .append(this.string03, auditEntry.string03)
186       .append(this.string04, auditEntry.string04)
187       .append(this.string05, auditEntry.string05)
188       .append(this.string06, auditEntry.string06)
189       .append(this.string07, auditEntry.string07)
190       .append(this.string08, auditEntry.string08)
191       .append(this.userIpAddress, auditEntry.userIpAddress)
192       .isEquals();
193       
194   }
195 
196 //  public Set<String> getRelatedGroupNames() {
197 //    
198 //  }
199 //  
200 //  public Set<String> getRelatedStemNames() {
201 //    
202 //  }
203   
204   /**
205    * 
206    * @see java.lang.Object#toString()
207    */
208   public String toString() {
209     return "Audit entry: " + StringUtils.substring(this.description, 0, 30);
210   }
211 
212   /**
213    * get the audit type, it better be there
214    * @return the audit type
215    */
216   public AuditType getAuditType() {
217     return AuditTypeFinder.find(this.auditTypeId, true);
218   }
219   
220   /**
221    * 
222    * @param extended if all fields should be printed
223    * @return the report
224    */
225   public String toStringReport(boolean extended) {
226     StringBuilder result = new StringBuilder();
227     AuditType auditType = this.getAuditType();
228     Timestamp lastUpdated = this.getLastUpdated();
229     
230     SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
231     String lastUpdatedString = simpleDateFormat.format(lastUpdated);
232     
233     result.append(lastUpdatedString).append(" ").append(StringUtils.rightPad(auditType.getAuditCategory(), 12))
234       .append(" - ").append(StringUtils.rightPad(auditType.getActionName(), 20))
235       .append(" (").append(StringUtils.leftPad(Long.toString(this.getDurationMicroseconds()/1000), 6))
236       .append("ms, ").append(StringUtils.leftPad(Integer.toString(this.getQueryCount()), 3)).append(" queries)\n");
237     
238     GrouperSession grouperSession = GrouperSession.startRootSession(false);
239     
240     if (!StringUtils.isBlank(this.loggedInMemberId)) {
241       result.append("  ").append(StringUtils.rightPad("Logged in user:", 20));
242       Member loggedInMember = MemberFinder.findByUuid(grouperSession, this.loggedInMemberId, false);
243       String loggedInMemberString = subjectToString(loggedInMember);
244       result.append(loggedInMemberString);
245       
246       if (!StringUtils.isBlank(this.userIpAddress)) {
247         result.append(" (ip: ").append(this.userIpAddress).append(")");
248       }
249       
250       if (!StringUtils.isBlank(this.actAsMemberId) && !StringUtils.equals(this.actAsMemberId, this.loggedInMemberId)) {
251         result.append(" (actAs: ");
252         Member actAsMember = MemberFinder.findByUuid(grouperSession, this.actAsMemberId, false);
253         String actAsMemberString = subjectToString(actAsMember);
254         result.append(actAsMemberString);
255         result.append(")");
256       }
257       result.append("\n");
258     }
259 
260     if (!StringUtils.isBlank(this.description)) {
261       result.append("  ").append(StringUtils.rightPad("Description:", 20))
262         .append(StringUtils.abbreviate(this.description, 200)).append("\n");
263     }
264     result.append("  ").append(StringUtils.rightPad("Server:", 20));
265     result.append(this.grouperEngine).append(", host: ").append(this.serverHost);
266     result.append(", user: ").append(this.serverUserName);
267     result.append("\n");
268     
269     if (extended) {
270       
271       for (String label: auditType.labels()) {
272         
273         //see if there is data
274         String fieldName = auditType.retrieveAuditEntryFieldForLabel(label);
275         Object value = GrouperUtil.fieldValue(this, fieldName);
276         String valueString = GrouperUtil.stringValue(value);
277         if (!StringUtils.isBlank(valueString)) {
278           
279           result.append("  ").append(StringUtils.rightPad(StringUtils.capitalize(label) + ":", 20)).append(value).append("\n");
280           
281         }
282       }
283     }
284     
285     return result.toString();
286   }
287   
288   /**
289    * convert a subject to a string
290    * @param member
291    * @return the string
292    */
293   private static String subjectToString(Member member) {
294     StringBuilder result = new StringBuilder();
295     result.append(member.getSubjectSourceIdDb()).append(" - ").append(member.getSubjectIdDb())
296       .append(" - ");
297     try {
298       Subject subject = member.getSubject();
299       String more = subject.getAttributeValue("description");
300       if (StringUtils.isBlank(more)) {
301         more = subject.getDescription();
302       }
303       if (StringUtils.isBlank(more)) {
304         more = subject.getAttributeValue("name");
305       }
306       if (StringUtils.isBlank(more)) {
307         more = subject.getName();
308       }
309       
310       if (!StringUtils.isBlank(more)) {
311         result.append(more);
312       }
313       
314     } catch (Exception e) {
315       result.append(" problem with subject: " + e.getMessage());
316     }
317     return result.toString();
318   }
319   
320   /**
321    * construct
322    */
323   public AuditEntry() {
324     this.id = GrouperUuid.getUuid();
325 
326   }
327 
328   /**
329    * save or update this object
330    * @param copyContextData 
331    */
332   public void saveOrUpdate(boolean copyContextData) {
333     if (copyContextData) {
334       GrouperContext.assignAuditEntryFields(this);
335     }
336     if (!GrouperLoader.isDryRun()) {
337       GrouperDAOFactory.getFactory().getAuditEntry().saveOrUpdate(this);
338     }
339   }
340   
341   /**
342    * construct, assign an id
343    * @param auditTypeIdentifier points to audit type
344    * @param labelNamesAndValues alternate label name and value
345    */
346   public AuditEntry(AuditTypeIdentifier auditTypeIdentifier, 
347       String... labelNamesAndValues) {
348     
349     this.id = GrouperUuid.getUuid();
350     
351     AuditType auditType = AuditTypeFinder.find(auditTypeIdentifier.getAuditCategory(),
352         auditTypeIdentifier.getActionName(), true);
353     
354     this.auditTypeId = auditType.getId();
355     
356     int labelNamesAndValuesLength = GrouperUtil.length(labelNamesAndValues);
357     
358     if (labelNamesAndValuesLength % 2 != 0) {
359       throw new RuntimeException("labelNamesAndValuesLength must be divisible by 2: " 
360           + labelNamesAndValuesLength);
361     }
362     
363     for (int i=0;i<labelNamesAndValuesLength;i+=2) {
364       String label = labelNamesAndValues[i];
365       String value = labelNamesAndValues[i+1];
366 
367       assignStringValue(auditType, label, value);
368     }
369   }
370 
371   /**
372    * @param auditType
373    * @param label
374    * @param value
375    */
376   public void assignStringValue(AuditType auditType, String label, String value) {
377     if (StringUtils.equals(label, auditType.getLabelString01())) {
378       this.string01 = value;
379     } else if (StringUtils.equals(label, auditType.getLabelString02())) {
380       this.string02 = value;
381     } else if (StringUtils.equals(label, auditType.getLabelString03())) {
382       this.string03 = value;
383     } else if (StringUtils.equals(label, auditType.getLabelString04())) {
384       this.string04 = value;
385     } else if (StringUtils.equals(label, auditType.getLabelString05())) {
386       this.string05 = value;
387     } else if (StringUtils.equals(label, auditType.getLabelString06())) {
388       this.string06 = value;
389     } else if (StringUtils.equals(label, auditType.getLabelString07())) {
390       this.string07 = value;
391     } else if (StringUtils.equals(label, auditType.getLabelString08())) {
392       this.string08 = value;
393     } else {
394       throw new RuntimeException("Cant find string label: '" + label 
395           + "' in audit type: " + auditType.getAuditCategory() + " - " + auditType.getActionName());
396     }
397   }
398   
399   /**
400    * @param auditType
401    * @param label
402    * @param value
403    */
404   public void assignIntValue(AuditType auditType, String label, Long value) {
405     if (StringUtils.equals(label, auditType.getLabelInt01())) {
406       this.int01 = value;
407     } else if (StringUtils.equals(label, auditType.getLabelInt02())) {
408       this.int02 = value;
409     } else if (StringUtils.equals(label, auditType.getLabelInt03())) {
410       this.int03 = value;
411     } else if (StringUtils.equals(label, auditType.getLabelInt04())) {
412       this.int04 = value;
413     } else if (StringUtils.equals(label, auditType.getLabelInt05())) {
414       this.int05 = value;
415       throw new RuntimeException("Cant find int label: '" + label 
416           + "' in audit type: " + auditType.getAuditCategory() + " - " + auditType.getActionName());
417     }
418   }
419   
420   /** name of the grouper audit entry table in the db */
421   public static final String TABLE_GROUPER_AUDIT_ENTRY = "grouper_audit_entry";
422 
423   /** primary key uuid of this record */
424   private String id;
425   
426   /** foreign key to the type of audit entry this is */
427   private String auditTypeId;
428 
429   /** env label from grouper.properties */
430   private String envName;
431   
432   /** WS, UI, loader, GSH, etc */
433   private String grouperEngine;
434   
435   /** version of the grouper API, e.g. 1.4.0 */
436   private String grouperVersion;
437   
438   /**
439    * member uuid of the user being acted as. 
440    */
441   private String actAsMemberId;
442 
443   /**
444    * context id ties multiple db changes  
445    */
446   private String contextId;
447 
448   /**
449    * member uuid of the user logged in to grouper ui or ws etc
450    */
451   private String loggedInMemberId;
452 
453   /**
454    * host of the server that executed the transaction
455    */
456   private String serverHost;
457 
458   /**
459    * ip address of user (from WS or UI etc)
460    */
461   private String userIpAddress;
462 
463   /**
464    * Username of the OS user running the API.  This might identify who ran a GSH call
465    */
466   private String serverUserName;
467   
468   /**
469    * number of microseconds that the duration of the context took
470    */
471   private long durationMicroseconds;
472   
473   /**
474    * number of queries (count be db or otherwise)
475    */
476   private int queryCount;
477   
478   /**
479    * description of what happened in paragraph form
480    */
481   private String description;
482   
483   /**
484    * misc field 1
485    */
486   private String string01;
487   
488   /**
489    * misc field 2
490    */
491   private String string02;
492   
493   /**
494    * misc field 3
495    */
496   private String string03;
497   
498   /**
499    * misc field 4
500    */
501   private String string04;
502   
503   /**
504    * misc field 5
505    */
506   private String string05;
507   
508   /**
509    * misc field 6
510    */
511   private String string06;
512   
513   /**
514    * misc field 7
515    */
516   private String string07;
517   
518   /**
519    * misc field 8
520    */
521   private String string08;
522 
523   /**
524    * misc int field 1
525    */
526   private Long int01;
527   
528   /**
529    * misc int field 2
530    */
531   private Long int02;
532   
533   /**
534    * misc int field 3
535    */
536   private Long int03;
537   
538   /**
539    * misc int field 4
540    */
541   private Long int04;
542   
543   /**
544    * misc int field 5
545    */
546   private Long int05;
547 
548   /**
549    * when this record was created 
550    */
551   private Long createdOnDb;
552 
553   /**
554    * when this record was last updated 
555    */
556   private Long lastUpdatedDb;
557   
558   /**
559    * foreign key to the type of audit entry this is
560    * @return the audit type id
561    */
562   public String getAuditTypeId() {
563     return this.auditTypeId;
564   }
565 
566   /**
567    * foreign key to the type of audit entry this is
568    * @param auditTypeId1
569    */
570   public void setAuditTypeId(String auditTypeId1) {
571     this.auditTypeId = auditTypeId1;
572   }
573 
574   /**
575    * primary key uuid of this record
576    * @return the id
577    */
578   public String getId() {
579     return this.id;
580   }
581 
582   /**
583    * primary key uuid of this record
584    * @param id1
585    */
586   public void setId(String id1) {
587     this.id = id1;
588   }
589 
590   /**
591    * member uuid of the user being acted as
592    * @return uuid
593    */
594   public String getActAsMemberId() {
595     return this.actAsMemberId;
596   }
597 
598   /**
599    * context id ties multiple db changes
600    * @return id
601    */
602   public String getContextId() {
603     return this.contextId;
604   }
605 
606   /**
607    * member uuid of the user logged in to grouper ui or ws etc
608    * @return uuid
609    */
610   public String getLoggedInMemberId() {
611     return this.loggedInMemberId;
612   }
613 
614   /**
615    * host of the server that executed the transaction
616    * @return host
617    */
618   public String getServerHost() {
619     return this.serverHost;
620   }
621 
622   /**
623    * ip address of user (from WS or UI etc)
624    * @return user ip address
625    */
626   public String getUserIpAddress() {
627     return this.userIpAddress;
628   }
629 
630   /**
631    * member uuid of the user being acted as
632    * @param actAsMemberUuid1
633    */
634   public void setActAsMemberId(String actAsMemberUuid1) {
635     this.actAsMemberId = actAsMemberUuid1;
636   }
637 
638   /**
639    * context id ties multiple db changes
640    * @param contextId1
641    */
642   public void setContextId(String contextId1) {
643     this.contextId = contextId1;
644   }
645 
646   /**
647    * member uuid of the user logged in to grouper ui or ws etc
648    * @param loggedInMemberUuid
649    */
650   public void setLoggedInMemberId(String loggedInMemberUuid) {
651     this.loggedInMemberId = loggedInMemberUuid;
652   }
653 
654   /**
655    * host of the server that executed the transaction
656    * @param serverHost1
657    */
658   public void setServerHost(String serverHost1) {
659     this.serverHost = serverHost1;
660   }
661 
662   /**
663    * ip address of user (from WS or UI etc)
664    * @param userIpAddress1
665    */
666   public void setUserIpAddress(String userIpAddress1) {
667     this.userIpAddress = userIpAddress1;
668   }
669 
670   /**
671    * env label from grouper.properties
672    * @return env label
673    */
674   public String getEnvName() {
675     return this.envName;
676   }
677 
678   /**
679    * env label from grouper.properties
680    * @param envLabel1
681    */
682   public void setEnvName(String envLabel1) {
683     this.envName = envLabel1;
684   }
685 
686   /**
687    * WS, UI, loader, GSH, etc
688    * @return grouper system
689    */
690   public String getGrouperEngine() {
691     return this.grouperEngine;
692   }
693 
694   /**
695    * WS, UI, loader, GSH, etc
696    * @param grouperSystem1
697    */
698   public void setGrouperEngine(String grouperSystem1) {
699     this.grouperEngine = grouperSystem1;
700   }
701 
702   /**
703    * misc field 1
704    * @return field
705    */
706   public String getString01() {
707     return this.string01;
708   }
709 
710   /**
711    * misc field 1
712    * @param string01a
713    */
714   public void setString01(String string01a) {
715     this.string01 = string01a;
716   }
717 
718   /**
719    * misc field 2
720    * @return field
721    */
722   public String getString02() {
723     return this.string02;
724   }
725 
726   /**
727    * misc field 2
728    * @param string02a
729    */
730   public void setString02(String string02a) {
731     this.string02 = string02a;
732   }
733 
734   /**
735    * misc field 3
736    * @return field
737    */
738   public String getString03() {
739     return this.string03;
740   }
741 
742   /**
743    * misc field 3
744    * @param string03a
745    */
746   public void setString03(String string03a) {
747     this.string03 = string03a;
748   }
749 
750   /**
751    * misc field 4
752    * @return field
753    */
754   public String getString04() {
755     return this.string04;
756   }
757 
758   /**
759    * misc field 4
760    * @param string04a
761    */
762   public void setString04(String string04a) {
763     this.string04 = string04a;
764   }
765 
766   /**
767    * misc field 5
768    * @return field
769    */
770   public String getString05() {
771     return this.string05;
772   }
773 
774   /**
775    * misc field 5
776    * @param string05a
777    */
778   public void setString05(String string05a) {
779     this.string05 = string05a;
780   }
781 
782   /**
783    * misc field 6
784    * @return field
785    */
786   public String getString06() {
787     return this.string06;
788   }
789 
790   /**
791    * misc field 6
792    * @param string06a
793    */
794   public void setString06(String string06a) {
795     this.string06 = string06a;
796   }
797 
798   /**
799    * misc field 7
800    * @return field
801    */
802   public String getString07() {
803     return this.string07;
804   }
805 
806   /**
807    * misc field 7
808    * @param string07a
809    */
810   public void setString07(String string07a) {
811     this.string07 = string07a;
812   }
813 
814   /**
815    * misc field 8
816    * @return field
817    */
818   public String getString08() {
819     return this.string08;
820   }
821 
822   /**
823    * misc field 8
824    * @param string08a
825    */
826   public void setString08(String string08a) {
827     this.string08 = string08a;
828   }
829 
830   /**
831    * misc integer field 1
832    * @return field
833    */
834   public Long getInt01() {
835     return this.int01;
836   }
837 
838   /**
839    * misc integer field 1
840    * @param int01a
841    */
842   public void setInt01(Long int01a) {
843     this.int01 = int01a;
844   }
845 
846   /**
847    * misc integer field 2
848    * @return field
849    */
850   public Long getInt02() {
851     return this.int02;
852   }
853 
854   /**
855    * misc integer field 2
856    * @param int02a
857    */
858   public void setInt02(Long int02a) {
859     this.int02 = int02a;
860   }
861 
862   /**
863    * misc integer field 3
864    * @return field
865    */
866   public Long getInt03() {
867     return this.int03;
868   }
869 
870   /**
871    * misc integer field 3
872    * @param int03a
873    */
874   public void setInt03(Long int03a) {
875     this.int03 = int03a;
876   }
877 
878   /**
879    * misc integer field 4
880    * @return field
881    */
882   public Long getInt04() {
883     return this.int04;
884   }
885 
886   /**
887    * misc integer field 4
888    * @param int04a
889    */
890   public void setInt04(Long int04a) {
891     this.int04 = int04a;
892   }
893 
894   /**
895    * misc integer field 5
896    * @return field
897    */
898   public Long getInt05() {
899     return this.int05;
900   }
901 
902   /**
903    * misc integer field 5
904    * @param int05a
905    */
906   public void setInt05(Long int05a) {
907     this.int05 = int05a;
908   }
909 
910   /**
911    * description of what happened in paragraph form
912    * @return description
913    */
914   public String getDescription() {
915     return this.description;
916   }
917 
918   /**
919    * description of what happened in paragraph form
920    * @param description1
921    */
922   public void setDescription(String description1) {
923     this.description = description1;
924   }
925 
926   /**
927    * when created
928    * @return timestamp
929    */
930   public Timestamp getCreatedOn() {
931     return this.createdOnDb == null ? null : new Timestamp(this.createdOnDb);
932   }
933 
934   /**
935    * when last updated
936    * @return timestamp
937    */
938   public Timestamp getLastUpdated() {
939     return this.lastUpdatedDb == null ? null : new Timestamp(this.lastUpdatedDb);
940   }
941 
942   /**
943    * when created
944    * @return timestamp
945    */
946   public Long getCreatedOnDb() {
947     return this.createdOnDb;
948   }
949 
950   /**
951    * when last updated
952    * @return timestamp
953    */
954   public Long getLastUpdatedDb() {
955     return this.lastUpdatedDb;
956   }
957 
958   /**
959    * when created
960    * @param createdOn1
961    */
962   public void setCreatedOn(Timestamp createdOn1) {
963     this.createdOnDb = createdOn1 == null ? null : createdOn1.getTime();
964   }
965 
966   /**
967    * when last updated
968    * @param lastUpdated1
969    */
970   public void setLastUpdated(Timestamp lastUpdated1) {
971     this.lastUpdatedDb = lastUpdated1 == null ? null : lastUpdated1.getTime();
972   }
973 
974   /**
975    * make sure this object will fit in the DB
976    */
977   public void truncate() {
978     this.actAsMemberId = GrouperUtil.truncateAscii(this.actAsMemberId, 128);
979     this.auditTypeId = GrouperUtil.truncateAscii(this.auditTypeId, 128);
980     this.contextId = GrouperUtil.truncateAscii(this.contextId, 128);
981     this.description = GrouperUtil.truncateAscii(this.description, 4000);
982     this.envName = GrouperUtil.truncateAscii(this.envName, 50);
983     this.grouperEngine = GrouperUtil.truncateAscii(this.grouperEngine, 50);
984     this.grouperVersion = GrouperUtil.truncateAscii(this.grouperVersion, 20);
985     this.id = GrouperUtil.truncateAscii(this.id, 128);
986     this.loggedInMemberId = GrouperUtil.truncateAscii(this.loggedInMemberId, 128);
987     this.serverHost = GrouperUtil.truncateAscii(this.serverHost, 50);
988     this.serverUserName = GrouperUtil.truncateAscii(this.serverUserName, 50);
989     this.string01 = GrouperUtil.truncateAscii(this.string01, 4000);
990     this.string02 = GrouperUtil.truncateAscii(this.string02, 4000);
991     this.string03 = GrouperUtil.truncateAscii(this.string03, 4000);
992     this.string04 = GrouperUtil.truncateAscii(this.string04, 4000);
993     this.string05 = GrouperUtil.truncateAscii(this.string05, 4000);
994     this.string06 = GrouperUtil.truncateAscii(this.string06, 4000);
995     this.string07 = GrouperUtil.truncateAscii(this.string07, 4000);
996     this.string08 = GrouperUtil.truncateAscii(this.string08, 4000);
997     this.userIpAddress = GrouperUtil.truncateAscii(this.userIpAddress, 50);
998   }
999 
1000   /**
1001    * version of the grouper API, e.g. 1.4.0
1002    * @return version
1003    */
1004   public String getGrouperVersion() {
1005     return this.grouperVersion;
1006   }
1007 
1008   /**
1009    * version of the grouper API, e.g. 1.4.0
1010    * @param grouperVersion1
1011    */
1012   public void setGrouperVersion(String grouperVersion1) {
1013     this.grouperVersion = grouperVersion1;
1014   }
1015 
1016   /**
1017    * @see edu.internet2.middleware.grouper.GrouperAPI#clone()
1018    */
1019   @Override
1020   public GrouperAPI clone() {
1021     throw new RuntimeException("not implemented");
1022   }
1023 
1024   /**
1025    * number of nanos that the duration of the context took
1026    * @return duration nanos
1027    */
1028   public long getDurationMicroseconds() {
1029     return this.durationMicroseconds;
1030   }
1031 
1032   /**
1033    * number of nanos that the duration of the context took
1034    * @param durationMicroseconds1
1035    */
1036   public void setDurationMicroseconds(long durationMicroseconds1) {
1037     this.durationMicroseconds = durationMicroseconds1;
1038   }
1039 
1040   /**
1041    * 
1042    * @see edu.internet2.middleware.grouper.GrouperAPI#onPreSave(edu.internet2.middleware.grouper.hibernate.HibernateSession)
1043    */
1044   @Override
1045   public void onPreSave(HibernateSession hibernateSession) {
1046     super.onPreSave(hibernateSession);
1047     if (this.lastUpdatedDb == null) {
1048       this.lastUpdatedDb = System.currentTimeMillis();
1049     }
1050     if (this.createdOnDb == null) {
1051       this.createdOnDb = System.currentTimeMillis();
1052     }
1053     if (this.actAsMemberId == null && this.loggedInMemberId != null) {
1054       this.actAsMemberId = this.loggedInMemberId;
1055     }
1056   }
1057 
1058   /**
1059    * 
1060    * @see edu.internet2.middleware.grouper.GrouperAPI#onPreUpdate(edu.internet2.middleware.grouper.hibernate.HibernateSession)
1061    */
1062   @Override
1063   public void onPreUpdate(HibernateSession hibernateSession) {
1064     super.onPreUpdate(hibernateSession);
1065     this.setLastUpdatedDb(System.currentTimeMillis());
1066   }
1067 
1068   /**
1069    * number of queries (count be db or otherwise)
1070    * @return query count
1071    */
1072   public int getQueryCount() {
1073     return this.queryCount;
1074   }
1075 
1076   /**
1077    * number of queries (count be db or otherwise)
1078    * @param queryCount
1079    */
1080   public void setQueryCount(int queryCount) {
1081     this.queryCount = queryCount;
1082   }
1083 
1084   /**
1085    * Username of the OS user running the API.  This might identify who ran a GSH call
1086    * @return server user name
1087    */
1088   public String getServerUserName() {
1089     return this.serverUserName;
1090   }
1091 
1092   /**
1093    * Username of the OS user running the API.  This might identify who ran a GSH call
1094    * @param serverUserName1
1095    */
1096   public void setServerUserName(String serverUserName1) {
1097     this.serverUserName = serverUserName1;
1098   }
1099 
1100   /**
1101    * when created
1102    * @param createdOn1
1103    */
1104   public void setCreatedOnDb(Long createdOn1) {
1105     this.createdOnDb = createdOn1;
1106   }
1107 
1108   /**
1109    * when last updated
1110    * @param lastUpdated1
1111    */
1112   public void setLastUpdatedDb(Long lastUpdated1) {
1113     this.lastUpdatedDb = lastUpdated1;
1114   }
1115 
1116   /**
1117    * the string repre
1118    * @return string 
1119    */
1120   public String toStringDeep() {
1121     return GrouperUtil.toStringFields(this, TO_STRING_DEEP_FIELDS);
1122   }
1123 
1124   /**
1125    * @see edu.internet2.middleware.grouper.xml.export.XmlImportable#xmlRetrieveByIdOrKey()
1126    */
1127   public XmlImportable<AuditEntry> xmlRetrieveByIdOrKey() {
1128     //in this case we are only going to find audits by id...
1129     return GrouperDAOFactory.getFactory().getAuditEntry().findById(this.id, false);
1130   }
1131 
1132   /**
1133    * @see edu.internet2.middleware.grouper.xml.export.XmlImportableBase#xmlCopyBusinessPropertiesToExisting(java.lang.Object)
1134    */
1135   public void xmlCopyBusinessPropertiesToExisting(AuditEntry existingRecord) {
1136     existingRecord.setActAsMemberId(this.actAsMemberId);
1137     existingRecord.setAuditTypeId(this.auditTypeId);
1138     existingRecord.setContextId(this.contextId);
1139     existingRecord.setDescription(this.description);
1140     existingRecord.setDurationMicroseconds(this.durationMicroseconds);
1141     existingRecord.setEnvName(this.envName);
1142     existingRecord.setGrouperEngine(this.grouperEngine);
1143     existingRecord.setGrouperVersion(this.grouperVersion);
1144     existingRecord.setId(this.id);
1145     existingRecord.setInt01(this.int01);
1146     existingRecord.setInt02(this.int02);
1147     existingRecord.setInt03(this.int03);
1148     existingRecord.setInt04(this.int04);
1149     existingRecord.setInt05(this.int05);
1150     existingRecord.setLoggedInMemberId(this.loggedInMemberId);
1151     existingRecord.setQueryCount(this.queryCount);
1152     existingRecord.setServerHost(this.serverHost);
1153     existingRecord.setServerUserName(this.serverUserName);
1154     existingRecord.setString01(this.string01);
1155     existingRecord.setString02(this.string02);
1156     existingRecord.setString03(this.string03);
1157     existingRecord.setString04(this.string04);
1158     existingRecord.setString05(this.string05);
1159     existingRecord.setString06(this.string06);
1160     existingRecord.setString07(this.string07);
1161     existingRecord.setString08(this.string08);
1162     existingRecord.setUserIpAddress(this.userIpAddress);
1163   }
1164 
1165   /**
1166    * @see edu.internet2.middleware.grouper.xml.export.XmlImportableBase#xmlDifferentBusinessProperties(java.lang.Object)
1167    */
1168   public boolean xmlDifferentBusinessProperties(AuditEntry other) {
1169     if (!StringUtils.equals(this.actAsMemberId, other.actAsMemberId)) {
1170       return true;
1171     }
1172     if (!StringUtils.equals(this.auditTypeId, other.auditTypeId)) {
1173       return true;
1174     }
1175     if (!StringUtils.equals(this.description, other.description)) {
1176       return true;
1177     }
1178     if (this.durationMicroseconds != other.durationMicroseconds) {
1179       return true;
1180     }
1181     if (!StringUtils.equals(this.envName, other.envName)) {
1182       return true;
1183     }
1184     if (!StringUtils.equals(this.grouperEngine, other.grouperEngine)) {
1185       return true;
1186     }
1187     if (!StringUtils.equals(this.grouperVersion, other.grouperVersion)) {
1188       return true;
1189     }
1190     if (!StringUtils.equals(this.id, other.id)) {
1191       return true;
1192     }
1193     if (!GrouperUtil.equals(this.int01, other.int01)) {
1194       return true;
1195     }
1196     if (!GrouperUtil.equals(this.int02, other.int02)) {
1197       return true;
1198     }
1199     if (!GrouperUtil.equals(this.int03, other.int03)) {
1200       return true;
1201     }
1202     if (!GrouperUtil.equals(this.int04, other.int04)) {
1203       return true;
1204     }
1205     if (!GrouperUtil.equals(this.int05, other.int05)) {
1206       return true;
1207     }
1208     if (!StringUtils.equals(this.loggedInMemberId, other.loggedInMemberId)) {
1209       return true;
1210     }
1211     if (this.queryCount != other.queryCount) {
1212       return true;
1213     }
1214     if (!StringUtils.equals(this.serverHost, other.serverHost)) {
1215       return true;
1216     }
1217     if (!StringUtils.equals(this.serverUserName, other.serverUserName)) {
1218       return true;
1219     }
1220     if (!StringUtils.equals(this.string01, other.string01)) {
1221       return true;
1222     }
1223     if (!StringUtils.equals(this.string02, other.string02)) {
1224       return true;
1225     }
1226     if (!StringUtils.equals(this.string03, other.string03)) {
1227       return true;
1228     }
1229     if (!StringUtils.equals(this.string04, other.string04)) {
1230       return true;
1231     }
1232     if (!StringUtils.equals(this.string05, other.string05)) {
1233       return true;
1234     }
1235     if (!StringUtils.equals(this.string06, other.string06)) {
1236       return true;
1237     }
1238     if (!StringUtils.equals(this.string07, other.string07)) {
1239       return true;
1240     }
1241     if (!StringUtils.equals(this.string08, other.string08)) {
1242       return true;
1243     }
1244     if (!StringUtils.equals(this.userIpAddress, other.userIpAddress)) {
1245       return true;
1246     }
1247     return false;
1248   }
1249 
1250   /**
1251    * @see edu.internet2.middleware.grouper.xml.export.XmlImportableBase#xmlDifferentUpdateProperties(java.lang.Object)
1252    */
1253   public boolean xmlDifferentUpdateProperties(AuditEntry other) {
1254     if (!StringUtils.equals(this.contextId, other.contextId)) {
1255       return true;
1256     }
1257     if (!GrouperUtil.equals(this.createdOnDb, other.createdOnDb)) {
1258       return true;
1259     }
1260     if (!GrouperUtil.equals(this.getHibernateVersionNumber(), other.getHibernateVersionNumber())) {
1261       return true;
1262     }
1263     if (!GrouperUtil.equals(this.lastUpdatedDb, other.lastUpdatedDb)) {
1264       return true;
1265     }
1266     return false;
1267   }
1268 
1269   /**
1270    * @see edu.internet2.middleware.grouper.xml.export.XmlImportableBase#xmlGetId()
1271    */
1272   public String xmlGetId() {
1273     return this.getId();
1274   }
1275 
1276   /**
1277    * @see edu.internet2.middleware.grouper.xml.export.XmlImportableBase#xmlSaveBusinessProperties(java.lang.Object)
1278    */
1279   public AuditEntrynternet2/middleware/grouper/audit/AuditEntry.html#AuditEntry">AuditEntry xmlSaveBusinessProperties(AuditEntry existingRecord) {
1280     //if its an insert, call the business method
1281     if (existingRecord == null) {
1282       existingRecord = new AuditEntry();
1283     }
1284     this.xmlCopyBusinessPropertiesToExisting(existingRecord);
1285     //if its an insert or update, then do the rest of the fields
1286     existingRecord.saveOrUpdate(false);
1287     return existingRecord;
1288   }
1289 
1290   /**
1291    * @see edu.internet2.middleware.grouper.xml.export.XmlImportableBase#xmlSaveUpdateProperties()
1292    */
1293   public void xmlSaveUpdateProperties() {
1294     GrouperDAOFactory.getFactory().getAuditEntry().saveUpdateProperties(this);
1295   }
1296 
1297   /**
1298    * @see edu.internet2.middleware.grouper.xml.export.XmlImportableBase#xmlSetId(java.lang.String)
1299    */
1300   public void xmlSetId(String theId) {
1301     this.setId(theId);
1302   }
1303 
1304   /**
1305    * convert to xml bean for export
1306    * @param grouperVersion
1307    * @return xml bean
1308    */
1309   public XmlExportAuditEntry xmlToExportAuditEntry(GrouperVersion grouperVersion) {
1310     if (grouperVersion == null) {
1311       throw new RuntimeException();
1312     }
1313     
1314     XmlExportAuditEntryrtAuditEntry.html#XmlExportAuditEntry">XmlExportAuditEntry xmlExportAuditEntry = new XmlExportAuditEntry();
1315     xmlExportAuditEntry.setActAsMemberId(this.getActAsMemberId());
1316     xmlExportAuditEntry.setAuditTypeId(this.getAuditTypeId());
1317     xmlExportAuditEntry.setContextId(this.getContextId());
1318     xmlExportAuditEntry.setCreatedOn(GrouperUtil.dateStringValue(this.getCreatedOnDb()));
1319     xmlExportAuditEntry.setDescription(this.getDescription());
1320     xmlExportAuditEntry.setDurationMicroseconds(this.getDurationMicroseconds());
1321     xmlExportAuditEntry.setEnvName(this.getEnvName());
1322     xmlExportAuditEntry.setGrouperEngine(this.getGrouperEngine());
1323     xmlExportAuditEntry.setGrouperVersion(this.getGrouperVersion());
1324     xmlExportAuditEntry.setHibernateVersionNumber(GrouperUtil.longValue(this.getHibernateVersionNumber(), 0));
1325     xmlExportAuditEntry.setId(this.getId());
1326     xmlExportAuditEntry.setInt01(this.getInt01());
1327     xmlExportAuditEntry.setInt02(this.getInt02());
1328     xmlExportAuditEntry.setInt03(this.getInt03());
1329     xmlExportAuditEntry.setInt04(this.getInt04());
1330     xmlExportAuditEntry.setInt05(this.getInt05());
1331     xmlExportAuditEntry.setLastUpdated(GrouperUtil.dateStringValue(this.getLastUpdatedDb()));
1332     xmlExportAuditEntry.setLoggedInMemberId(this.getLoggedInMemberId());
1333     xmlExportAuditEntry.setQueryCount(this.getQueryCount());
1334     xmlExportAuditEntry.setServerHost(this.getServerHost());
1335     xmlExportAuditEntry.setServerUserName(this.getServerUserName());
1336     xmlExportAuditEntry.setString01(this.getString01());
1337     xmlExportAuditEntry.setString02(this.getString02());
1338     xmlExportAuditEntry.setString03(this.getString03());
1339     xmlExportAuditEntry.setString04(this.getString04());
1340     xmlExportAuditEntry.setString05(this.getString05());
1341     xmlExportAuditEntry.setString06(this.getString06());
1342     xmlExportAuditEntry.setString07(this.getString07());
1343     xmlExportAuditEntry.setString08(this.getString08());
1344     xmlExportAuditEntry.setUserIpAddress(this.getUserIpAddress());
1345     return xmlExportAuditEntry;
1346   }
1347 
1348   /**
1349    * get a string value from name value pairs
1350    * @param label
1351    * 
1352    * @return value
1353    */
1354   public String retrieveStringValue(String label) {
1355     return this.retrieveStringValue(this.getAuditType(), label);
1356   }
1357   
1358   /**
1359    * get a string value from name value pairs
1360    * @param auditType
1361    * @param label
1362    * @return value
1363    */
1364   public String retrieveStringValue(AuditType auditType, String label) {
1365     if (StringUtils.equals(label, auditType.getLabelString01())) {
1366       return this.string01;
1367     } else if (StringUtils.equals(label, auditType.getLabelString02())) {
1368       return this.string02;
1369     } else if (StringUtils.equals(label, auditType.getLabelString03())) {
1370       return this.string03;
1371     } else if (StringUtils.equals(label, auditType.getLabelString04())) {
1372       return this.string04;
1373     } else if (StringUtils.equals(label, auditType.getLabelString05())) {
1374       return this.string05;
1375     } else if (StringUtils.equals(label, auditType.getLabelString06())) {
1376       return this.string06;
1377     } else if (StringUtils.equals(label, auditType.getLabelString07())) {
1378       return this.string07;
1379     } else if (StringUtils.equals(label, auditType.getLabelString08())) {
1380       return this.string08;
1381     } else {
1382       throw new RuntimeException("Cant find string label: '" + label 
1383           + "' in audit type: " + auditType.getAuditCategory() + " - " + auditType.getActionName());
1384     }
1385   }
1386 
1387   /**
1388    * @see edu.internet2.middleware.grouper.xml.export.XmlImportableBase#xmlToString()
1389    */
1390   public String xmlToString() {
1391     StringWriter stringWriter = new StringWriter();
1392     
1393     stringWriter.write("AuditEntry: " + this.getId());
1394     
1395 //    XmlExportUtils.toStringAuditType(null, stringWriter, this.getAuditTypeId(), false);
1396     
1397     return stringWriter.toString();
1398     
1399   }
1400 
1401 }