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

Source Code of de.danet.an.workflow.clients.mgmtportlets.procdef.ProcDefWrapper

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2005 Danet GmbH (www.danet.de), BU TEL.
* 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: ProcDefWrapper.java 1992 2006-12-04 14:17:56Z drmlipp $
*
* $Log$
* Revision 1.10  2006/11/23 14:55:03  drmlipp
* Improved performance.
*
* Revision 1.9  2006/10/06 15:27:36  drmlipp
* Added access to process definition.
*
* Revision 1.8  2006/09/29 12:32:13  drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.7  2005/11/07 16:41:38  drmlipp
* Added multi deletes.
*
* Revision 1.6  2005/09/28 15:12:41  drmlipp
* Updated MyFaces to 1.1.
*
* Revision 1.5  2005/08/26 13:30:38  drmlipp
* Added default name representations for process definitions with no
* names.
*
* Revision 1.4  2005/06/22 15:14:01  drmlipp
* Added delete icon.
*
* Revision 1.3  2005/06/22 12:53:21  drmlipp
* Added enabled column.
*
* Revision 1.2  2005/06/22 07:43:53  drmlipp
* Completed sorting, added process creation.
*
* Revision 1.1  2005/06/20 15:09:30  drmlipp
* Added columns, started process creation.
*
*/
package de.danet.an.workflow.clients.mgmtportlets.procdef;

import java.io.Serializable;
import java.lang.reflect.InvocationTargetException;
import java.rmi.RemoteException;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import de.danet.an.util.jsf.JSFUtil;
import de.danet.an.workflow.api.InvalidKeyException;
import de.danet.an.workflow.api.MethodInvocationBatch;
import de.danet.an.workflow.api.ProcessDefinition;
import de.danet.an.workflow.api.ProcessDefinitionDirectory;
import de.danet.an.workflow.api.WorkflowService;

/**
* A wrapper class that make process definitions look like JavaBeans.
*/
public class ProcDefWrapper implements Serializable {

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

    private static String L10N_MSGS
  = "de.danet.an.workflow.clients.mgmtportlets.procdef.L10n";

    private String packageId;
    private String packageName;
    private String processId;
    private String processName;
    private String mgrName;
    private String version;
    private String description;
    private String definition;
    private boolean enabled;
    private boolean selected = false;
   
    /**
     * Create a new instance for the given process definition.
     * @param pd the process definition to wrap
     */
    public ProcDefWrapper (WorkflowService wfs, ProcessDefinitionDirectory pdd,
                           ProcessDefinition pd)
        throws RemoteException {
        MethodInvocationBatch mib = new MethodInvocationBatch ();
        mib.addInvocation(pd, "packageId", null, null);
        mib.addInvocation(pd, "packageName", null, null);
        mib.addInvocation(pd, "processId", null, null);
        mib.addInvocation(pd, "processName", null, null);
        mib.addInvocation(pd, "mgrName", null, null);
        mib.addInvocation(pd, "version", null, null);
        mib.addInvocation(pd, "processHeader", null, null);
        mib.addInvocation(-1, "description", null, null, true);
        mib.addInvocation(pd, "toXPDL", null, null);
        MethodInvocationBatch.Result mir = null;
        try {
            mir = (MethodInvocationBatch.Result)wfs.executeBatch(mib);
            if (mir.hasExceptions ()) {
                Exception e = mir.firstException ();
                logger.error ("Problem executing batch: " + e.getMessage(), e);
                throw new RemoteException (mir.firstException ().getMessage());
            }
        } catch (InvocationTargetException e) {
            throw (IllegalStateException)
                (new IllegalStateException (e.getMessage())).initCause(e);
        }
        if (mir.hasExceptions ()) {
            Exception e = mir.firstException ();
            if (e instanceof RemoteException) {
                throw (RemoteException)e;
            }
            throw (IllegalStateException)
                (new IllegalStateException(e.getMessage())).initCause(e);
        }
        packageId = mir.resultAsString(0);
        packageName = mir.resultAsString(1);
        processId = mir.resultAsString(2);
        processName = mir.resultAsString(3);
        mgrName = mir.resultAsString(4);
        version = mir.resultAsString(5);
        description = mir.resultAsString(6);
        definition = mir.resultAsString(7);
        try {
            enabled = pdd.isEnabled(packageId, processId);
        } catch (InvalidKeyException e) {
            // this can only happen if we have a race condition, retry
            throw new RemoteException (e.getMessage ());
        }
    }

    private ProcDefMgmt procDefMgmt () {
        FacesContext fc = FacesContext.getCurrentInstance();
        return (ProcDefMgmt)fc.getApplication()
            .createValueBinding("#{procDefMgmt}").getValue(fc);
    }
   
    /**
     * Returns the package name.
     * @return package name
     */
    public String getPackageName () {
        return packageName != null
          ? packageName : "(" + packageId + ")";
    }

    /**
     * Returns the process name.
     * @return the process name
     */
    public String getProcessName () {
        return processName != null
          ? processName : "(" + processId + ")";
    }
   
    /**
     * Return a unique id.
     * @return unique id.
     */
    public String getMgrName() {
        return mgrName;
    }
   
    /**
     * Returns the process definition's version.
     * @return the process definition's version
     */
    public String getVersion () {
        return version;
    }
   
    /**
     * Returns the process definition's description.
     * @return the process definition's defscription
     */
    public String getDescription () {
        return description;
    }

    /**
     * @return Returns the definition.
     */
    public String getDefinition() {
        return definition;
    }

    /**
     * @return Returns the enabled.
     */
    public boolean isEnabled() {
        return enabled;
    }
   
    /**
     * @param enabled The enabled to set.
     */
    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    /**
     * Create and start a process instance using this process definition.
     */
    public void start () {
        if (logger.isDebugEnabled()) {
            logger.debug ("Start for " + toString() + " called");
        }
        try {
            procDefMgmt().createAndStartProcess (packageId, processId);
            JSFUtil.addMessage(FacesMessage.SEVERITY_INFO, L10N_MSGS,
                    "processStarted", null);
        } catch (InvalidKeyException e) {
            JSFUtil.addMessage(FacesMessage.SEVERITY_ERROR, L10N_MSGS,
                    "procDefUnavailable", null, e);
        } catch (RemoteException e) {
            JSFUtil.addMessage(FacesMessage.SEVERITY_ERROR, L10N_MSGS,
                    "resourceCurrentlyUnavailable", null, e);
        }
    }

    /**
     * Toggle the enabled state.
     */
    public void toggleEnabled () {
        if (logger.isDebugEnabled()) {
            logger.debug ("Toggle enabled for " + toString() + " called");
        }
        try {
            procDefMgmt().setEnabled (packageId, processId, !enabled);
        } catch (InvalidKeyException e) {
            JSFUtil.addMessage(FacesMessage.SEVERITY_ERROR, L10N_MSGS,
                    "procDefUnavailable", null, e);
        } catch (RemoteException e) {
            JSFUtil.addMessage(FacesMessage.SEVERITY_ERROR, L10N_MSGS,
                    "resourceCurrentlyUnavailable", null, e);
        }
    }
   
    /**
     * Delete process definition.
     */
    public void remove () {
        if (logger.isDebugEnabled()) {
            logger.debug ("Delete for " + toString() + " called");
        }
        try {
            procDefMgmt().remove (packageId, processId);
        } catch (InvalidKeyException e) {
            JSFUtil.addMessage(FacesMessage.SEVERITY_ERROR, L10N_MSGS,
                    "procDefUnavailable", null, e);
        } catch (RemoteException e) {
            JSFUtil.addMessage(FacesMessage.SEVERITY_ERROR, L10N_MSGS,
                    "resourceCurrentlyUnavailable", null, e);
        }
    }
   
    /**
     * @return Returns the selected.
     */
    public boolean isSelected() {
        FacesContext fc = FacesContext.getCurrentInstance();
        if (fc.getExternalContext().getRequestMap()
            .containsKey("procDefAllSelection")) {
            return true;
        }
        return selected;
    }

    /**
     * @param selected The selected to set.
     */
    public void setSelected(boolean selected) {
        if (!this.selected && selected) {
            procDefMgmt().addSelected(this);
        }
        this.selected = selected;
    }

    public String toString () {
        return "ProcessDefinitionWrapper[packageId=" + packageId
            + ",processId=" + processId + "]";
    }
}
TOP

Related Classes of de.danet.an.workflow.clients.mgmtportlets.procdef.ProcDefWrapper

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.