use of org.compiere.wf.MWFActivity in project adempiere by adempiere.
the class WorkflowTag method doStartTag.
// setActivityID
/**
* Start Tag
* @return SKIP_BODY
* @throws JspException
*/
public int doStartTag() throws JspException {
Properties ctx = JSPEnv.getCtx((HttpServletRequest) pageContext.getRequest());
// Activity
int AD_WF_Activity_ID = 0;
String info = null;
try {
info = (String) ExpressionUtil.evalNotNull("workflow", "activityID", m_activityID_el, String.class, this, pageContext);
if (info != null && info.length() != 0)
AD_WF_Activity_ID = Integer.parseInt(info);
} catch (Exception e) {
log.severe("doStartTag - Activity" + e);
}
MWFActivity act = new MWFActivity(ctx, AD_WF_Activity_ID, null);
if (AD_WF_Activity_ID == 0 || act == null || act.get_ID() != AD_WF_Activity_ID) {
log.severe("doStartTag - Activity Not found - " + m_activityID_el + " (" + info + ")");
return (SKIP_BODY);
}
String name = null;
if (act.isUserApproval())
name = "IsApproved";
else if (act.isUserManual())
name = "IsConfirmed";
else
return (SKIP_BODY);
// YesNo
option[] yesNoOptions = new option[3];
yesNoOptions[0] = new option(" ");
yesNoOptions[0].addElement(" ");
yesNoOptions[0].setSelected(true);
yesNoOptions[1] = new option("Y");
yesNoOptions[1].addElement(Util.maskHTML(Msg.translate(ctx, "Yes")));
yesNoOptions[2] = new option("N");
yesNoOptions[2].addElement(Util.maskHTML(Msg.translate(ctx, "No")));
select yesNoSelect = new select(name, yesNoOptions);
yesNoSelect.setID("ID_" + name);
yesNoSelect.setClass(C_MANDATORY);
//
String nameTrl = Msg.translate(ctx, name);
// Assemble
HtmlCode html = new HtmlCode();
html.addElement(new b(nameTrl));
html.addElement(yesNoSelect);
html.addElement(new br());
JspWriter out = pageContext.getOut();
html.output(out);
//
return (SKIP_BODY);
}
use of org.compiere.wf.MWFActivity in project adempiere by adempiere.
the class WebInfo method getActivities.
// getNote
/**
* Get Workflow Activities
* @return activities
*/
public ArrayList<MWFActivity> getActivities() {
ArrayList<MWFActivity> list = new ArrayList<MWFActivity>();
String sql = "SELECT * FROM AD_WF_Activity " + "WHERE AD_User_ID=?" + " AND Processed='N' " + "ORDER BY Priority DESC, Created";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, getAD_User_ID());
rs = pstmt.executeQuery();
while (rs.next()) list.add(new MWFActivity(m_ctx, rs, null));
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
log.fine("#" + list.size());
return list;
}
use of org.compiere.wf.MWFActivity in project adempiere by adempiere.
the class WorkflowServlet method streamAttachment.
// doGet
/**
* Stream Attachment
* @param request request
* @param response response
* @return "" or error message
*/
private String streamAttachment(HttpServletRequest request, HttpServletResponse response) {
// Get Activity ID
int AD_WF_Activity_ID = WebUtil.getParameterAsInt(request, P_WF_Activity_ID);
if (AD_WF_Activity_ID == 0) {
log.fine("streamAttachment - no AD_WF_Activity_ID)");
return "No Activity ID";
}
int attachmentIndex = WebUtil.getParameterAsInt(request, P_ATTACHMENT_INDEX);
if (attachmentIndex == 0) {
log.fine("streamAttachment - no index)");
return "No Request Attachment index";
}
log.info("streamAttachment - AD_WF_Activity_ID=" + AD_WF_Activity_ID + " / " + attachmentIndex);
// Get Note
Properties ctx = JSPEnv.getCtx(request);
MWFActivity doc = new MWFActivity(ctx, AD_WF_Activity_ID, null);
if (doc.get_ID() != AD_WF_Activity_ID) {
log.fine("streamAttachment - Activity not found - ID=" + AD_WF_Activity_ID);
return "Activity not found";
}
MAttachment attachment = doc.getAttachment(false);
if (attachment == null) {
log.fine("streamAttachment - No Attachment for AD_WF_Activity_ID=" + AD_WF_Activity_ID);
return "Notice Attachment not found";
}
// Get WebUser & Compare with invoice
HttpSession session = request.getSession(true);
WebUser wu = (WebUser) session.getAttribute(WebUser.NAME);
if (wu.getAD_User_ID() != doc.getAD_User_ID()) {
log.warning("streamAttachment - AD_WF_Activity_ID=" + AD_WF_Activity_ID + " - User_Activity=" + doc.getAD_User_ID() + " = Web_User=" + wu.getAD_User_ID());
return "Your Activity not found";
}
// Stream it
return WebUtil.streamAttachment(response, attachment, attachmentIndex);
}
use of org.compiere.wf.MWFActivity in project adempiere by adempiere.
the class WorkflowProcessor method sendAlerts.
// setPriority
/**
* Send Alerts
*/
private void sendAlerts() {
// Alert over Priority
if (m_model.getAlertOverPriority() > 0) {
String sql = "SELECT * " + "FROM AD_WF_Activity a " + // suspended
"WHERE Processed='N' AND WFState='OS'" + // ##1
" AND Priority >= ?" + " AND (DateLastAlert IS NULL";
if (m_model.getRemindDays() > 0)
sql += " OR (DateLastAlert+" + m_model.getRemindDays() + ") < SysDate";
sql += ") 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" + " AND (wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=?))";
int count = 0;
int countEMails = 0;
PreparedStatement pstmt = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_model.getAlertOverPriority());
pstmt.setInt(2, m_model.getAD_WorkflowProcessor_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MWFActivity activity = new MWFActivity(getCtx(), rs, null);
boolean escalate = activity.getDateLastAlert() != null;
countEMails += sendEmail(activity, "ActivityOverPriority", escalate, true);
activity.setDateLastAlert(new Timestamp(System.currentTimeMillis()));
activity.saveEx();
count++;
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, "(Priority) - " + sql, e);
} finally {
DB.close(pstmt);
}
m_summary.append("OverPriority #").append(count);
if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)");
m_summary.append(" - ");
}
// Alert over Priority
/**
* Over End Wait
*/
String sql = "SELECT * " + "FROM AD_WF_Activity a " + // suspended
"WHERE Processed='N' AND WFState='OS'" + " AND EndWaitTime > SysDate" + " AND (DateLastAlert IS NULL";
if (m_model.getRemindDays() > 0)
sql += " OR (DateLastAlert+" + m_model.getRemindDays() + ") < SysDate";
sql += ") 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" + // not 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_WorkflowProcessor_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MWFActivity activity = new MWFActivity(getCtx(), rs, null);
boolean escalate = activity.getDateLastAlert() != null;
countEMails += sendEmail(activity, "ActivityEndWaitTime", escalate, false);
activity.setDateLastAlert(new Timestamp(System.currentTimeMillis()));
activity.saveEx();
count++;
}
rs.close();
} catch (Exception e) {
log.log(Level.SEVERE, "(EndWaitTime) - " + sql, e);
} finally {
DB.close(pstmt);
}
m_summary.append("EndWaitTime #").append(count);
if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)");
m_summary.append(" - ");
/**
* Send inactivity alerts
*/
if (m_model.getInactivityAlertDays() > 0) {
sql = "SELECT * " + "FROM AD_WF_Activity a " + // suspended
"WHERE Processed='N' AND WFState='OS'" + " AND (Updated+" + m_model.getInactivityAlertDays() + ") < SysDate" + " AND (DateLastAlert IS NULL";
if (m_model.getRemindDays() > 0)
sql += " OR (DateLastAlert+" + m_model.getRemindDays() + ") < SysDate";
sql += ") 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" + " AND (wf.AD_WorkflowProcessor_ID IS NULL OR wf.AD_WorkflowProcessor_ID=?))";
count = 0;
countEMails = 0;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_model.getAD_WorkflowProcessor_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MWFActivity activity = new MWFActivity(getCtx(), rs, null);
boolean escalate = activity.getDateLastAlert() != null;
countEMails += sendEmail(activity, "ActivityInactivity", escalate, false);
activity.setDateLastAlert(new Timestamp(System.currentTimeMillis()));
activity.saveEx();
count++;
}
rs.close();
pstmt.close();
} catch (SQLException e) {
log.log(Level.SEVERE, "(Inactivity): " + sql, e);
} finally {
DB.close(pstmt);
}
m_summary.append("Inactivity #").append(count);
if (countEMails > 0)
m_summary.append(" (").append(countEMails).append(" EMail)");
m_summary.append(" - ");
}
// Inactivity
}
use of org.compiere.wf.MWFActivity in project adempiere by adempiere.
the class WorkflowProcessor method dynamicPriority.
// wakeup
/**
* Set/Increase Priority dynamically
*/
private void dynamicPriority() {
// suspend activities with dynamic priority node
String sql = "SELECT * " + "FROM AD_WF_Activity a " + // suspended
"WHERE Processed='N' AND WFState='OS'" + " 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 AND wf.AD_WorkflowProcessor_ID=?" + " AND wfn.DynPriorityUnit IS NOT NULL AND wfn.DynPriorityChange IS NOT NULL)";
PreparedStatement pstmt = null;
int count = 0;
int countEMails = 0;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, m_model.getAD_WorkflowProcessor_ID());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MWFActivity activity = new MWFActivity(getCtx(), rs, null);
if (activity.getDynPriorityStart() == 0)
activity.setDynPriorityStart(activity.getPriority());
long ms = System.currentTimeMillis() - activity.getCreated().getTime();
MWFNode node = activity.getNode();
int prioDiff = node.calculateDynamicPriority((int) (ms / 1000));
activity.setPriority(activity.getDynPriorityStart() + prioDiff);
activity.saveEx();
count++;
}
rs.close();
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(pstmt);
}
m_summary.append("DynPriority #").append(count).append(" - ");
}
Aggregations