/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2005 Danet GmbH (www.danet.de), BU BTS.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: EventWrapper.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.4 2006/09/06 09:31:06 drmlipp
* Cleaned up event display.
*
* Revision 1.3 2005/10/24 15:30:49 drmlipp
* Implemented context data change display.
*
* Revision 1.2 2005/10/21 15:05:51 drmlipp
* Continued audit event display and cleaned up some things.
*
* Revision 1.1 2005/10/20 13:52:17 drmlipp
* Implementation of audit event display continued.
*
*/
package de.danet.an.workflow.clients.mgmtportlets.process;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import java.util.TreeSet;
import javax.faces.context.FacesContext;
import javax.faces.model.DataModel;
import de.danet.an.workflow.omgcore.ProcessData;
import de.danet.an.workflow.omgcore.WfAuditEvent;
import de.danet.an.workflow.omgcore.WfDataAuditEvent;
import de.danet.an.workflow.omgcore.WfStateAuditEvent;
/**
* @author lipp
*
*/
public class EventWrapper implements Serializable {
private static final org.apache.commons.logging.Log logger
= org.apache.commons.logging.LogFactory.getLog (EventWrapper.class);
private WfAuditEvent event;
/**
* Create a new instance, backed by the given event.
* @param event the event
*/
public EventWrapper(WfAuditEvent event) {
this.event = event;
}
/* (non-Javadoc)
* @see de.danet.an.workflow.omgcore.WfAuditEvent#activityKey()
*/
public String getActivityKey() {
return event.activityKey();
}
/* (non-Javadoc)
* @see de.danet.an.workflow.omgcore.WfAuditEvent#activityName()
*/
public String getActivityName() {
return event.activityName();
}
/* (non-Javadoc)
* @see de.danet.an.workflow.omgcore.WfAuditEvent#eventType()
*/
public String getEventType() {
return event.eventType();
}
/* (non-Javadoc)
* @see de.danet.an.workflow.omgcore.WfAuditEvent#processKey()
*/
public String getProcessKey() {
return event.processKey();
}
/* (non-Javadoc)
* @see de.danet.an.workflow.omgcore.WfAuditEvent#processMgrName()
*/
public String getProcessMgrName() {
return event.processMgrName();
}
/* (non-Javadoc)
* @see de.danet.an.workflow.omgcore.WfAuditEvent#processMgrVersion()
*/
public String getProcessMgrVersion() {
return event.processMgrVersion();
}
/* (non-Javadoc)
* @see de.danet.an.workflow.omgcore.WfAuditEvent#processName()
*/
public String getProcessName() {
return event.processName();
}
/* (non-Javadoc)
* @see de.danet.an.workflow.omgcore.WfAuditEvent#timeStamp()
*/
public Date getTimeStamp() {
return event.timeStamp();
}
public boolean isStateAuditEvent () {
return event instanceof WfStateAuditEvent;
}
/* (non-Javadoc)
* @see WfStateAuditEvent#oldState
*/
public String getOldState() {
if (isStateAuditEvent()) {
return ((WfStateAuditEvent)event).oldState();
}
throw new UnsupportedOperationException ();
}
/* (non-Javadoc)
* @see #getOldState
*/
public String getOldStateName() {
return StateNameMapper.mapState(getOldState());
}
/* (non-Javadoc)
* @see WfStateAuditEvent#newState
*/
public String getNewState() {
if (isStateAuditEvent()) {
return ((WfStateAuditEvent)event).newState();
}
throw new UnsupportedOperationException ();
}
/* (non-Javadoc)
* @see #getNewState
*/
public String getNewStateName() {
return StateNameMapper.mapState(getNewState());
}
public boolean isDataAuditEvent () {
return event instanceof WfDataAuditEvent;
}
public String showDetail () {
if (isDataAuditEvent()) {
if (logger.isDebugEnabled()) {
logger.debug ("Setting data changes for " + event);
}
List changes = new ArrayList ();
Set items = new TreeSet();
ProcessData oldData = ((WfDataAuditEvent)event).oldData();
ProcessData newData = ((WfDataAuditEvent)event).newData();
items.addAll (oldData.keySet());
items.addAll (newData.keySet());
for (Iterator i = items.iterator(); i.hasNext(); ) {
String item = (String)i.next();
changes.add (new ContextChangeWrapper
(item, oldData.get(item), newData.get(item)));
}
FacesContext fc = FacesContext.getCurrentInstance();
((ProcessSelection)fc.getExternalContext().getSessionMap()
.get("processSelection")).setAuditEventDataChangesData(changes);
return null;
}
logger.warn ("Show detail called, but " + event + " has no details");
return null;
}
}