001: /*
002: * Copyright 2006 Pentaho Corporation. All rights reserved.
003: * This software was developed by Pentaho Corporation and is provided under the terms
004: * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005: * this file except in compliance with the license. If you need a copy of the license,
006: * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007: * BI Platform. The Initial Developer is Pentaho Corporation.
008: *
009: * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. Please refer to
011: * the license for the specific language governing your rights and limitations.
012: *
013: * @created Jul 8, 2005
014: * @author James Dixon
015: */
016:
017: package org.pentaho.plugin.misc;
018:
019: import java.util.Date;
020:
021: import org.apache.commons.logging.Log;
022: import org.apache.commons.logging.LogFactory;
023: import org.pentaho.actionsequence.dom.IActionInputValueProvider;
024: import org.pentaho.actionsequence.dom.actions.ReceiptAuditAction;
025: import org.pentaho.messages.Messages;
026: import org.pentaho.plugin.ComponentBase;
027:
028: /**
029: * @author James Dixon
030: *
031: * TODO To change the template for this generated type comment go to Window -
032: * Preferences - Java - Code Style - Code Templates
033: */
034: public class ReceiptAuditComponent extends ComponentBase {
035:
036: private static final long serialVersionUID = -7641957638192444235L;
037:
038: public Log getLogger() {
039: return LogFactory.getLog(ReceiptAuditComponent.class);
040: }
041:
042: public static String RECEIPT_AUDIT = Messages
043: .getString("ReceiptAuditComponent.CODE_AUDIT_CONTENT_RECEIVED"); //$NON-NLS-1$
044:
045: protected boolean validateSystemSettings() {
046: // This component does not have any system settings to validate
047: return true;
048: }
049:
050: protected boolean validateAction() {
051: boolean actionValidated = true;
052: ReceiptAuditAction receiptAuditAction = null;
053:
054: if (getActionDefinition() instanceof ReceiptAuditAction) {
055: receiptAuditAction = (ReceiptAuditAction) getActionDefinition();
056:
057: // make sure that we have a message
058: if (receiptAuditAction.getMessage() == IActionInputValueProvider.NULL_INPUT) {
059: actionValidated = false;
060: error(Messages
061: .getErrorString("ReceiptAuditComponent.ERROR_0001_MESSAGE_NOT_SPECIFIED")); //$NON-NLS-1$
062: }
063:
064: // make sure that we have a timestamp
065: if (actionValidated
066: && receiptAuditAction.getDt() == IActionInputValueProvider.NULL_INPUT) {
067: actionValidated = false;
068: error(Messages
069: .getErrorString("ReceiptAuditComponent.ERROR_0002_TIMESTAMP_NOT_SPECIFIED")); //$NON-NLS-1$
070: }
071: } else {
072: actionValidated = false;
073: error(Messages
074: .getErrorString(
075: "ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", getActionDefinition().getElement().asXML())); //$NON-NLS-1$
076: }
077:
078: return actionValidated;
079: }
080:
081: public void done() {
082: }
083:
084: protected boolean executeAction() {
085:
086: ReceiptAuditAction receiptAuditAction = (ReceiptAuditAction) getActionDefinition();
087:
088: String message = receiptAuditAction.getMessage()
089: .getStringValue();
090: String dtString = receiptAuditAction.getDt().getStringValue();
091:
092: long dt = new Long(dtString).longValue();
093: long now = new Date().getTime();
094: int duration = (int) ((now - dt) / 1000);
095:
096: audit(RECEIPT_AUDIT, message, "", duration); //$NON-NLS-1$
097:
098: return true;
099: }
100:
101: /*
102: * (non-Javadoc)
103: *
104: * @see org.pentaho.component.ComponentBase#init()
105: */
106: public boolean init() {
107: return true;
108: }
109: }
|