Package de.danet.an.xformstool.portletapp

Source Code of de.danet.an.xformstool.portletapp.AssignmentData

/*
* 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: AssignmentData.java 3009 2009-03-20 12:46:39Z drmlipp $
*
* $Log$
* Revision 1.4  2007/01/16 15:04:10  drmlipp
* Fixed formatting.
*
* Revision 1.3  2006/12/12 14:22:09  drmlipp
* Merged XForms client from branch.
*
* Revision 1.2.4.7  2006/12/11 21:12:52  mlipp
* Finished indirect assignment display.
*
* Revision 1.2.4.6  2006/12/11 16:04:36  drmlipp
* Added activity completion.
*
* Revision 1.2.4.5  2006/12/11 13:30:19  drmlipp
* Continued with result delivery.
*
* Revision 1.2.4.4  2006/12/07 23:17:13  mlipp
* Restructured XForm component's properties.
*
* Revision 1.2.4.3  2006/12/07 14:34:45  drmlipp
* Added namespace attributes restoration.
*
* Revision 1.2.4.2  2006/12/06 12:54:38  drmlipp
* Displaying real form now.
*
* Revision 1.2.4.1  2006/12/05 14:18:43  drmlipp
* Initial display working.
*
* Revision 1.2  2006/09/29 12:32:12  drmlipp
* Consistently using WfMOpen as projct name now.
*
* Revision 1.1  2006/09/21 15:02:31  drmlipp
* Continuing implementation.
*
*/
package de.danet.an.xformstool.portletapp;

import java.rmi.RemoteException;
import java.util.Date;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.el.EvaluationException;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerFactoryConfigurationError;
import javax.xml.transform.dom.DOMResult;
import javax.xml.transform.sax.SAXTransformerFactory;
import javax.xml.transform.sax.TransformerHandler;

import org.w3c.dom.Node;
import org.xml.sax.SAXException;

import de.danet.an.util.jsf.xftaglib.InstanceDataModel;
import de.danet.an.util.sax.NamespaceAttributesAdder;
import de.danet.an.workflow.api.Activity;
import de.danet.an.workflow.api.FormalParameter;
import de.danet.an.workflow.api.InvalidKeyException;
import de.danet.an.workflow.api.ProcessDirectory;
import de.danet.an.workflow.api.SAXEventBuffer;
import de.danet.an.workflow.omgcore.CannotCompleteException;
import de.danet.an.workflow.omgcore.InvalidDataException;
import de.danet.an.workflow.omgcore.WfResource;
import de.danet.an.workflow.tools.util.SimpleApplicationInfo;

/**
* This class provides the display data for an assignment.
*
* @author Michael Lipp
*
*/
public class AssignmentData {

    private static final org.apache.commons.logging.Log logger
        = org.apache.commons.logging.LogFactory.getLog(AssignmentData.class);
   
    private SimpleApplicationInfo applInfo;
    private String assignedTo = null;
    private Activity.Info activityInfo;
    private Node form = null;
    private InstanceDataModelImpl instanceData = null;
   
    /**
     * Create a new instance with all attributes initialized
     * to defaults or the given values.
     *
     * @param assignee the assignee
     * @param info the info
     * @param activity the activity
     */
    public AssignmentData
        (WfResource assignee, SimpleApplicationInfo info, Activity activity)
        throws RemoteException {
        if (assignee != null) {
            assignedTo = assignee.resourceName();
        }
        applInfo = info;
        activityInfo = activity.activityInfo();
    }
   
    /**
     * @return the instance id
     */
    public long getInstanceId() {
        return applInfo.id();
    }
   
    /**
     * @return the priority
     */
    public int getPriority () {
        return activityInfo.priority();
    }
   
    /**
     * @return the assignment date
     */
    public Date getAssignedAt () {
        return applInfo.assignedAt();
    }
   
    /**
     * @return Returns the assignedTo.
     */
    public String getAssignedTo() {
        return assignedTo;
    }

    /**
     * @return the process name
     */
    public String getProcessName () {
        return activityInfo.processName();
    }
   
    /**
     * @return the activity name
     */
    public String getActivityName () {
        return activityInfo.name();
    }

    /**
     * @return the form as W3CDom
     */
    public Node getForm () {
        if (form == null) {
            DOMResult res = new DOMResult();
            try {
                TransformerHandler t = ((SAXTransformerFactory)
                    SAXTransformerFactory.newInstance())
                        .newTransformerHandler();
                t.setResult(res);
                ((SAXEventBuffer)((Object[])applInfo.state())[1])
                    .emit(new NamespaceAttributesAdder(t));
            } catch (TransformerConfigurationException e) {
                logger.error(e.getMessage(), e);
            } catch (TransformerFactoryConfigurationError e) {
                logger.error(e.getMessage(), e);
            } catch (SAXException e) {
                logger.error(e.getMessage(), e);
            }
            form = res.getNode();
        }
        return form;
    }
   
    /**
     * @return the form as W3CDom
     */
    public InstanceDataModel getInstanceDataModel () {
        if (instanceData == null) {
            instanceData = new InstanceDataModelImpl
                (Long.toString(getInstanceId()),
                 (String)((Object[])applInfo.state())[0],
                 (FormalParameter[])((Object[])applInfo.state())[2],
                 (Map)((Object[])applInfo.state())[3]);
        }
        return instanceData;
    }
   
    /**
     * @return outcome
     */
    public String showForm () {
        FacesContext fc = FacesContext.getCurrentInstance();
        AssignmentService svc = (AssignmentService)fc.getApplication()
            .getVariableResolver().resolveVariable(fc, "assignmentService");
        svc.setChosenInstanceId(new Long(applInfo.id()));
        return "showForm";
    }
   
    /**
     * @return outcome
     */
    public String complete () throws RemoteException {
        FacesContext fc = FacesContext.getCurrentInstance();
        AssignmentService assignSvc = (AssignmentService)fc.getApplication()
            .getVariableResolver().resolveVariable(fc, "assignmentService");
        if (instanceData.getSubmitAction().equals("invoke:application")) {
            WorkflowServiceConnection wsc = (WorkflowServiceConnection)
                fc.getApplication().getVariableResolver()
                .resolveVariable(fc, "workflowServiceConnection");
            try {
                ProcessDirectory pd
                    = wsc.getWorkflowService().processDirectory();
                Activity act = pd.lookupActivity(activityInfo.uniqueKey());
                act.setResult(instanceData.resultData());
                act.complete();
                assignSvc.applicationDirectory().removeInstance(applInfo.id());
            } catch (EvaluationException e) {
                logger.error (e.getMessage(), e);
            } catch (RemoteException e) {
            } catch (InvalidKeyException e) {
                // activity no longer exists.
                logger.debug (e.getMessage (), e);
            } catch (InvalidDataException e) {
                logger.error (e.getMessage(), e);
            } catch (CannotCompleteException e) {
                // activity no longer exists (in appropriate state).
                logger.debug (e.getMessage (), e);
            }
        }
       
        assignSvc.setChosenInstanceId(null);
        return "showAssignments";
    }
   
}
TOP

Related Classes of de.danet.an.xformstool.portletapp.AssignmentData

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.