KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > pentaho > core > audit > AuditHelper


1 /*
2  * Copyright 2006 Pentaho Corporation. All rights reserved.
3  * This software was developed by Pentaho Corporation and is provided under the terms
4  * of the Mozilla Public License, Version 1.1, or any later version. You may not use
5  * this file except in compliance with the license. If you need a copy of the license,
6  * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
7  * BI Platform. The Initial Developer is Pentaho Corporation.
8  *
9  * Software distributed under the Mozilla Public License is distributed on an "AS IS"
10  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
11  * the license for the specific language governing your rights and limitations.
12  *
13  * @created Apr 15, 2005
14  * @author Marc Batchelor
15  */

16 package org.pentaho.core.audit;
17
18 import java.math.BigDecimal JavaDoc;
19
20 import org.pentaho.core.runtime.IRuntimeContext;
21 import org.pentaho.core.session.IPentahoSession;
22 import org.pentaho.messages.Messages;
23 import org.pentaho.util.logging.ILogger;
24 import org.pentaho.util.logging.Logger;
25
26 public class AuditHelper {
27
28     public static void audit(IRuntimeContext runtimeContext, IPentahoSession session, String JavaDoc messageType, String JavaDoc message, String JavaDoc value, BigDecimal JavaDoc duration, ILogger logger) {
29         try {
30
31             String JavaDoc instanceId = (runtimeContext == null) ? "" : runtimeContext.getInstanceId(); //$NON-NLS-1$
32
String JavaDoc userId = session.getName();
33             String JavaDoc actionName = (runtimeContext == null) ? null : runtimeContext.getActionName();
34             String JavaDoc objectType = runtimeContext.getCurrentComponentName();
35             String JavaDoc processId = (runtimeContext == null) ? null : runtimeContext.getProcessId();
36
37             audit(instanceId, userId, actionName, objectType, processId, messageType, message, value, duration, logger);
38
39         } catch (Exception JavaDoc e) {
40             if (logger != null) {
41                 logger.error(Messages.getErrorString("AUDITHELPER.ERROR_0001_AUDIT_ENTRY_ERROR"), e); //$NON-NLS-1$
42
} else {
43                 Logger.error(AuditHelper.class.getName(), Messages.getErrorString("AUDITHELPER.ERROR_0001_AUDIT_ENTRY_ERROR"), e); //$NON-NLS-1$
44
}
45         }
46     }
47
48     public static void audit(String JavaDoc instanceId, String JavaDoc userId, String JavaDoc actionName, String JavaDoc objectType, String JavaDoc processId, String JavaDoc messageType, String JavaDoc message, String JavaDoc value, BigDecimal JavaDoc duration, ILogger logger) {
49         try {
50
51             if ((processId == null) || (instanceId == null) || (actionName == null) || actionName.equals("")) { //$NON-NLS-1$
52
if (processId == null) {
53                     processId = ""; //$NON-NLS-1$
54
// TODO log this as an error
55
}
56                 if (instanceId == null) {
57                     instanceId = ""; //$NON-NLS-1$
58
// TODO log this as an error
59
}
60                 if (actionName == null) {
61                     actionName = ""; //$NON-NLS-1$
62
// TODO log this as an error
63
}
64             }
65             AuditEntry.auditJobDuration(processId, instanceId, actionName, objectType, userId, messageType, message, value, duration);
66         } catch (Exception JavaDoc e) {
67             if (logger != null) {
68                 logger.error(Messages.getErrorString("AUDITHELPER.ERROR_0001_AUDIT_ENTRY_ERROR"), e); //$NON-NLS-1$
69
} else {
70                 Logger.error(AuditHelper.class.getName(), Messages.getErrorString("AUDITHELPER.ERROR_0001_AUDIT_ENTRY_ERROR"), e); //$NON-NLS-1$
71
}
72         }
73     }
74
75 }
76
Popular Tags