Search in sources :

Example 1 with MWFActivity

use of org.compiere.wf.MWFActivity in project adempiere by adempiere.

the class WWFActivity method loadActivities.

/**
	 * 	Load Activities
	 * 	@return int
	 */
public int loadActivities() {
    long start = System.currentTimeMillis();
    int MAX_ACTIVITIES_IN_LIST = MSysConfig.getIntValue("MAX_ACTIVITIES_IN_LIST", 200, Env.getAD_Client_ID(Env.getCtx()));
    model = new ListModelTable();
    ArrayList<MWFActivity> list = new ArrayList<MWFActivity>();
    String sql = "SELECT * FROM AD_WF_Activity a " + "WHERE a.Processed='N' AND a.WFState='OS' AND (" + //	Owner of Activity
    " a.AD_User_ID=?" + //	Invoker (if no invoker = all)
    " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + //	#2
    " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" + // Responsible User
    " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + //	#3
    " AND r.AD_User_ID=?)" + //	Responsible Role
    " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)" + //	#4
    " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?)" + //
    ") ORDER BY a.Priority DESC, Created";
    int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
    MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
    sql = role.addAccessSQL(sql, "a", true, false);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_User_ID);
        pstmt.setInt(2, AD_User_ID);
        pstmt.setInt(3, AD_User_ID);
        pstmt.setInt(4, AD_User_ID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            MWFActivity activity = new MWFActivity(Env.getCtx(), rs, null);
            list.add(activity);
            List<Object> rowData = new ArrayList<Object>();
            rowData.add(activity.getPriority());
            rowData.add(activity.getNodeName());
            rowData.add(activity.getSummary());
            model.add(rowData);
            if (list.size() > MAX_ACTIVITIES_IN_LIST && MAX_ACTIVITIES_IN_LIST > 0) {
                log.warning("More then 200 Activities - ignored");
                break;
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    m_activities = new MWFActivity[list.size()];
    list.toArray(m_activities);
    //
    log.fine("#" + m_activities.length + "(" + (System.currentTimeMillis() - start) + "ms)");
    m_index = 0;
    String[] columns = new String[] { Msg.translate(Env.getCtx(), "Priority"), Msg.translate(Env.getCtx(), "AD_WF_Node_ID"), Msg.translate(Env.getCtx(), "Summary") };
    WListItemRenderer renderer = new WListItemRenderer(Arrays.asList(columns));
    ListHeader header = new ListHeader();
    header.setWidth("30px");
    renderer.setListHeader(0, header);
    renderer.addTableValueChangeListener(listbox);
    model.setNoColumns(columns.length);
    listbox.setModel(model);
    listbox.setItemRenderer(renderer);
    listbox.repaint();
    listbox.setFixedLayout(true);
    return m_activities.length;
}
Also used : WListItemRenderer(org.adempiere.webui.component.WListItemRenderer) MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList) ListModelTable(org.adempiere.webui.component.ListModelTable) PreparedStatement(java.sql.PreparedStatement) MWFActivity(org.compiere.wf.MWFActivity) ResultSet(java.sql.ResultSet) ListHeader(org.adempiere.webui.component.ListHeader)

Example 2 with MWFActivity

use of org.compiere.wf.MWFActivity in project adempiere by adempiere.

the class WebInfo method getActivity.

//	getActivities
/**
	 * 	Get Acitivity.
	 * 	Needs to have ID set first
	 *	@return notification of User with ID
	 */
public MWFActivity getActivity() {
    m_infoMessage = null;
    MWFActivity retValue = null;
    String sql = "SELECT * FROM AD_WF_Activity WHERE AD_User_ID=? AND AD_WF_Activity_ID=?";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, getAD_User_ID());
        pstmt.setInt(2, m_id);
        rs = pstmt.executeQuery();
        if (rs.next())
            retValue = new MWFActivity(m_ctx, rs, null);
    } catch (Exception e) {
        log.log(Level.SEVERE, "AD_WF_Activity_ID=" + m_id, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    log.fine("AD_WF_Activity_ID=" + m_id + " - " + retValue);
    return retValue;
}
Also used : MWFActivity(org.compiere.wf.MWFActivity) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with MWFActivity

use of org.compiere.wf.MWFActivity in project adempiere by adempiere.

the class WFActivity method loadActivities.

/**
	 * 	Load Activities
	 * 	@return int
	 */
public int loadActivities() {
    resetDisplay(null);
    while (selTableModel.getRowCount() > 0) selTableModel.removeRow(0);
    long start = System.currentTimeMillis();
    ArrayList<MWFActivity> list = new ArrayList<MWFActivity>();
    String sql = "SELECT * FROM AD_WF_Activity a " + "WHERE a.Processed='N' AND a.WFState='OS' AND (" + //	Owner of Activity
    " a.AD_User_ID=?" + //	Invoker (if no invoker = all)
    " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + //	#2
    " AND COALESCE(r.AD_User_ID,0)=0 AND COALESCE(r.AD_Role_ID,0)=0 AND (a.AD_User_ID=? OR a.AD_User_ID IS NULL))" + // Responsible User
    " OR EXISTS (SELECT * FROM AD_WF_Responsible r WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID" + //	#3
    " AND r.AD_User_ID=?)" + //	Responsible Role
    " OR EXISTS (SELECT * FROM AD_WF_Responsible r INNER JOIN AD_User_Roles ur ON (r.AD_Role_ID=ur.AD_Role_ID)" + //	#4
    " WHERE a.AD_WF_Responsible_ID=r.AD_WF_Responsible_ID AND ur.AD_User_ID=?)" + //
    ") ORDER BY a.Priority DESC, Created";
    int AD_User_ID = Env.getAD_User_ID(Env.getCtx());
    MRole role = MRole.get(Env.getCtx(), Env.getAD_Role_ID(Env.getCtx()));
    sql = role.addAccessSQL(sql, "a", true, false);
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, AD_User_ID);
        pstmt.setInt(2, AD_User_ID);
        pstmt.setInt(3, AD_User_ID);
        pstmt.setInt(4, AD_User_ID);
        rs = pstmt.executeQuery();
        while (rs.next()) {
            MWFActivity activity = new MWFActivity(Env.getCtx(), rs, null);
            Object[] rowData = new Object[4];
            rowData[0] = new IDColumn(activity.get_ID());
            rowData[1] = activity.getPriority();
            rowData[2] = activity.getNodeName();
            rowData[3] = activity.getSummary();
            selTableModel.addRow(rowData);
            if (list.size() > MAX_ACTIVITIES_IN_LIST) {
                log.warning("More than " + MAX_ACTIVITIES_IN_LIST + " Activities - ignored");
                break;
            }
        }
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    selTable.autoSize(false);
    log.fine("#" + selTable.getModel().getRowCount() + "(" + (System.currentTimeMillis() - start) + "ms)");
    return selTable.getModel().getRowCount();
}
Also used : MRole(org.compiere.model.MRole) ArrayList(java.util.ArrayList) PreparedStatement(java.sql.PreparedStatement) MWFActivity(org.compiere.wf.MWFActivity) IDColumn(org.compiere.minigrid.IDColumn) ResultSet(java.sql.ResultSet)

Example 4 with MWFActivity

use of org.compiere.wf.MWFActivity in project adempiere by adempiere.

the class WorkflowProcessor method wakeup.

//	doWork
/**
	 * 	Continue Workflow After Sleep
	 */
private void wakeup() {
    String sql = "SELECT * " + "FROM AD_WF_Activity a " + //	suspended
    "WHERE Processed='N' AND WFState='OS'" + " AND EndWaitTime > SysDate" + " AND AD_Client_ID=?" + " AND EXISTS (SELECT * FROM AD_Workflow wf " + " INNER JOIN AD_WF_Node wfn ON (wf.AD_Workflow_ID=wfn.AD_Workflow_ID) " + "WHERE a.AD_WF_Node_ID=wfn.AD_WF_Node_ID" + //	sleeping
    " AND wfn.Action='Z'" + " AND (wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=?))";
    PreparedStatement pstmt = null;
    int count = 0;
    int countEMails = 0;
    try {
        pstmt = DB.prepareStatement(sql, null);
        pstmt.setInt(1, m_model.getAD_Client_ID());
        pstmt.setInt(2, m_model.getAD_WorkflowProcessor_ID());
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            MWFActivity activity = new MWFActivity(getCtx(), rs, null);
            activity.setWFState(StateEngine.STATE_Completed);
            // saves and calls MWFProcess.checkActivities();
            count++;
        }
        rs.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, "wakeup", e);
    } finally {
        DB.close(pstmt);
    }
    m_summary.append("Wakeup #").append(count).append(" - ");
}
Also used : MWFActivity(org.compiere.wf.MWFActivity) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) SQLException(java.sql.SQLException)

Example 5 with MWFActivity

use of org.compiere.wf.MWFActivity in project adempiere by adempiere.

the class WorkflowServlet method doPost.

//	streamAttachment
/**************************************************************************
	 *  Process the HTTP Post request.
	 *
	 *  @param request request
	 *  @param response response
	 *  @throws ServletException
	 *  @throws IOException
	 */
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    log.info("doPost from " + request.getRemoteHost() + " - " + request.getRemoteAddr());
    String url = "/notes.jsp";
    //
    //	Log.setTraceLevel(9);
    //	WebEnv.dump(request);
    //
    HttpSession session = request.getSession(false);
    if (session == null || session.getAttribute(WebInfo.NAME) == null)
        url = "/login.jsp";
    else {
        session.removeAttribute(WebSessionCtx.HDR_MESSAGE);
        Properties ctx = JSPEnv.getCtx(request);
        WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
        if (wu == null) {
            log.warning("doPost - no web user");
            if (!response.isCommitted())
                //	entry
                response.sendRedirect("loginServlet?ForwardTo=note.jsp");
            return;
        }
        //	Get Feedback
        int AD_WF_Activity_ID = WebUtil.getParameterAsInt(request, P_WF_Activity_ID);
        boolean isConfirmed = WebUtil.getParameterAsBoolean(request, "IsConfirmed");
        boolean isApproved = WebUtil.getParameterAsBoolean(request, "IsApproved");
        boolean isRejected = WebUtil.getParameterAsBoolean(request, "IsApproved");
        String textMsg = WebUtil.getParameter(request, "textMsg");
        log.fine("doPost - TextMsg=" + textMsg);
        //
        MWFActivity act = new MWFActivity(ctx, AD_WF_Activity_ID, null);
        log.fine("doPost - " + act);
        if (AD_WF_Activity_ID == 0 || act == null || act.getAD_WF_Activity_ID() != AD_WF_Activity_ID)
            session.setAttribute(WebSessionCtx.HDR_MESSAGE, "Activity not found");
        else {
            if (act.isUserApproval() && (isApproved || isRejected)) {
                try {
                    act.setUserChoice(wu.getAD_User_ID(), isApproved ? "Y" : "N", DisplayType.YesNo, textMsg);
                    act.saveEx();
                } catch (Exception e) {
                }
            } else //	approval
            if (act.isUserManual() && isConfirmed) {
                act.setUserConfirmation(wu.getAD_User_ID(), textMsg);
                act.saveEx();
            } else if (textMsg != null && textMsg.length() > 0) {
                act.setTextMsg(textMsg);
                act.saveEx();
            }
        }
    }
    log.info("doGet - Forward to " + url);
    RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(url);
    dispatcher.forward(request, response);
}
Also used : MWFActivity(org.compiere.wf.MWFActivity) HttpSession(javax.servlet.http.HttpSession) WebUser(org.compiere.util.WebUser) Properties(java.util.Properties) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) RequestDispatcher(javax.servlet.RequestDispatcher)

Aggregations

MWFActivity (org.compiere.wf.MWFActivity)10 PreparedStatement (java.sql.PreparedStatement)7 ResultSet (java.sql.ResultSet)7 SQLException (java.sql.SQLException)3 ArrayList (java.util.ArrayList)3 Properties (java.util.Properties)3 HttpSession (javax.servlet.http.HttpSession)2 MRole (org.compiere.model.MRole)2 WebUser (org.compiere.util.WebUser)2 IOException (java.io.IOException)1 Timestamp (java.sql.Timestamp)1 RequestDispatcher (javax.servlet.RequestDispatcher)1 ServletException (javax.servlet.ServletException)1 JspException (javax.servlet.jsp.JspException)1 JspWriter (javax.servlet.jsp.JspWriter)1 ListHeader (org.adempiere.webui.component.ListHeader)1 ListModelTable (org.adempiere.webui.component.ListModelTable)1 WListItemRenderer (org.adempiere.webui.component.WListItemRenderer)1 org.apache.ecs.xhtml.b (org.apache.ecs.xhtml.b)1 org.apache.ecs.xhtml.br (org.apache.ecs.xhtml.br)1