Package de.danet.an.workflow.clients.mgmtportlets.process

Source Code of de.danet.an.workflow.clients.mgmtportlets.process.ProcessSelection

/*
* 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: ProcessSelection.java 1953 2006-11-23 14:55:03Z drmlipp $
*
* $Log$
* Revision 1.10  2006/11/22 12:49:47  drmlipp
* Improved error handling.
*
* Revision 1.9  2006/11/21 18:38:29  drmlipp
* Improving exception handling.
*
* Revision 1.8  2006/09/29 12:32:11  drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.7  2006/09/06 09:31:06  drmlipp
* Cleaned up event display.
*
* Revision 1.6  2005/11/22 21:48:16  mlipp
* Fixed Lifecycle access.
*
* Revision 1.5  2005/11/07 14:36:11  drmlipp
* Adapted to revised request attribute handling.
*
* Revision 1.4  2005/11/03 20:50:17  mlipp
* Simplified a bit.
*
* Revision 1.3  2005/10/24 15:30:49  drmlipp
* Implemented context data change display.
*
* Revision 1.2  2005/10/23 18:16:34  mlipp
* Improved selection menu
*
* Revision 1.1  2005/10/21 15:05:51  drmlipp
* Continued audit event display and cleaned up some things.
*
* Revision 1.1  2005/10/20 09:54:34  drmlipp
* Improved process selection
*
* Revision 1.5  2005/10/19 20:52:07  mlipp
* Various fixes.
*
* Revision 1.4  2005/10/19 14:36:40  drmlipp
* Improved process editing.
*
* Revision 1.3  2005/09/30 21:48:58  mlipp
* Basic process detail display working.
*
* Revision 1.2  2005/09/29 21:59:08  mlipp
* Continued process detail view implementation.
*
* Revision 1.1  2005/09/29 15:11:57  drmlipp
* Implementation of detail view continued.
*
*/
package de.danet.an.workflow.clients.mgmtportlets.process;

import java.io.Serializable;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import javax.faces.context.FacesContext;
import javax.faces.event.PhaseEvent;
import javax.faces.event.PhaseId;
import javax.faces.event.PhaseListener;
import javax.faces.model.DataModel;
import javax.faces.model.ListDataModel;
import javax.faces.model.ScalarDataModel;

import de.danet.an.util.BeanSorter;
import de.danet.an.util.jsf.JSFUtil;
import de.danet.an.workflow.clients.mgmtportlets.WorkflowServiceConnection;
import de.danet.an.workflow.omgcore.HistoryNotAvailableException;
import de.danet.an.workflow.omgcore.WfActivity;
import de.danet.an.workflow.omgcore.WfAuditEvent;
import de.danet.an.workflow.api.InvalidKeyException;
import de.danet.an.workflow.api.Process;
import de.danet.an.workflow.api.WorkflowService;

/**
* Simple JavaBean used to access a selected process and selection dependant
* attributes. By default, the currently selected process determined by
* the <code>ProcessUniqueKey</code> obtained by retrieving
* <code>SELECTED_PROCESS</code> from the portlet session (portlet scope). 
*
* @author lipp
*/
public class ProcessSelection implements Serializable, PhaseListener {

    private static final org.apache.commons.logging.Log logger
        = org.apache.commons.logging.LogFactory.getLog (ProcessSelection.class);

    protected static String L10N_MSGS
        = "de.danet.an.workflow.clients.mgmtportlets.process.L10n";

    private String processMgr;
    private String processKey;
    private transient ProcessWrapper wrappedProcessCache = null;
    private transient DataModel dataModelCache = null;
    private BeanSorter auditEventSorter = null;
    private Map selAttrs = new HashMap ();
    private transient DataModel auditEventsCache = null;
    private String eventSelection = "allEvents";
    private transient ListDataModel auditEventDataChanges
        = new ListDataModel ();
   
    /**
     * @param processMgr
     * @param processKey
     */
    public ProcessSelection(String processMgrName, String processKey) {
        this.processMgr = processMgrName;
        this.processKey = processKey;
        JSFUtil.addPhaseListenerForPortlet(this);
    }

    /* (non-Javadoc)
     * @see javax.faces.event.PhaseListener#getPhaseId()
     */
    public PhaseId getPhaseId() {
        return PhaseId.RENDER_RESPONSE;
    }

    /* (non-Javadoc)
     * @see javax.faces.event.PhaseListener#beforePhase
     */
    public void beforePhase(PhaseEvent arg0) {
        // May have been changed by action
        wrappedProcessCache = null;
        dataModelCache = null;
        auditEventsCache = null;
    }

    /* (non-Javadoc)
     * @see javax.faces.event.PhaseListener#afterPhase
     */
    public void afterPhase(PhaseEvent arg0) {
        wrappedProcessCache = null;
        dataModelCache = null;
        auditEventsCache = null;
    }

    private ProcessMgmt processMgmt () {
        FacesContext fc = FacesContext.getCurrentInstance();
        return (ProcessMgmt)fc.getApplication()
            .getVariableResolver().resolveVariable(fc, "processMgmt");
    }

    /**
     * Return the selected process.
     * @return selected process
     */
    public ProcessWrapper getProcess () throws RemoteException {
        if (wrappedProcessCache == null) {
            WorkflowService wfs = WorkflowServiceConnection
                .instance("workflowServiceConnection").getWorkflowService();
            wrappedProcessCache
                = new ProcessMutableWrapper (wfs, processMgr, processKey);
        }
        return wrappedProcessCache;
    }

    protected Process process() throws RemoteException {
        return getProcess().process();
    }
   
    /**
     * Return process as a list.
     * @return process as list
     */
    public DataModel getProcessAsDataModel () throws RemoteException {
        if (dataModelCache == null) {
            dataModelCache = new ScalarDataModel(getProcess());
        }
        return dataModelCache;
    }
   
    /**
     * @return Returns the selectionAttributes.
     */
    public Map getSelectionAttributes() {
        return selAttrs;
    }

    /**
     * The show events action for the activity events
     * @return outcome
     */
    public String showEvents () {
        setEventSelection("allEvents");
        return "showAuditEvents";       
    }

    /**
     * @return the audit events
     */
    public DataModel getAuditEvents() throws RemoteException {
        if (auditEventSorter == null) {
            auditEventSorter = processMgmt().getAuditEventSorter();
        }
        if (auditEventsCache == null) {
            logger.debug("Retrieving audit event list");
            List evtList = new ArrayList();
            String eventSelection = getEventSelection();
            try {
                if (eventSelection.equals("allEvents")
                    || eventSelection.equals("processEvents")) {
                    for (Iterator i = process().history().iterator();
                         i.hasNext();) {
                        WfAuditEvent evt = (WfAuditEvent)i.next();
                        evtList.add(new EventWrapper(evt));
                    }
                }
                if (eventSelection.equals("allEvents")) {
                    for (Iterator i = process().steps().iterator();
                         i.hasNext();) {
                        WfActivity act = (WfActivity)i.next();
                        for (Iterator j = act.history().iterator();
                            j.hasNext();) {
                            WfAuditEvent evt = (WfAuditEvent)j.next();
                            evtList.add(new EventWrapper(evt));                           
                        }
                    }
                } else if (!eventSelection.equals("processEvents")) {
                    try {
                        WfActivity act=process().activityByKey(eventSelection);
                        for (Iterator j = act.history().iterator();
                            j.hasNext();) {
                            WfAuditEvent evt = (WfAuditEvent)j.next();
                            evtList.add(new EventWrapper(evt));                           
                        }
                    } catch (InvalidKeyException e) {
                        logger.debug("Cannot find activity (ignored): "
                                     + eventSelection);
                    }
                }
            } catch (HistoryNotAvailableException e) {
                logger.debug("Cannot obtain history: " + e.getMessage());
            }
            auditEventSorter.sort (evtList);
            auditEventsCache = new ListDataModel (evtList);
        } else {
            logger.debug ("Re-using audit events");
            if (auditEventSorter.isModified ()) {
                auditEventSorter.sort ((List)auditEventsCache.getWrappedData());
            }
        }
        return auditEventsCache;
    }

    /**
     * @return Returns the eventSelection.
     */
    public String getEventSelection() {
        return eventSelection;
    }

    /**
     * @param eventSelection The eventSelection to set.
     */
    public void setEventSelection(String eventSelection) {
        this.eventSelection = eventSelection;
        setAuditEventDataChangesData(null);
    }

    /**
     * @return the possible event selections
     */
    public Map getEventSelectionItems () throws RemoteException {
        Map res = new TreeMap ();
        res.put ("", "processEvents");
        res.put("*", "allEvents");
        for (Iterator i = process().steps().iterator(); i.hasNext();) {
            WfActivity act = (WfActivity)i.next();
            res.put(act.key() + " | " + act.name(), act.key());
        }
        return res;
    }

    /**
     * @return Returns the auditEventDetails.
     */
    public ListDataModel getAuditEventDataChanges() {
        return auditEventDataChanges;
    }

    /**
     * @param auditEventDetails The auditEventDetails to set.
     */
    public void setAuditEventDataChangesData(List auditEventDetails) {
        this.auditEventDataChanges.setWrappedData(auditEventDetails);
    }

    /**
     * @return Returns the processKey.
     */
    public String getProcessKey() {
        return processKey;
    }

    /**
     * @return Returns the processMgr.
     */
    public String getProcessMgr() {
        return processMgr;
    }

}
TOP

Related Classes of de.danet.an.workflow.clients.mgmtportlets.process.ProcessSelection

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.