Search in sources :

Example 1 with MStatus

use of org.compiere.model.MStatus in project adempiere by adempiere.

the class RequestProcessor method processStatus.

//  escalate
/**************************************************************************
	 * 	Process Request Status
	 */
private void processStatus() {
    int count = 0;
    //	Requests with status with after timeout
    String sql = "SELECT * FROM R_Request r WHERE EXISTS (" + "SELECT * FROM R_Status s " + "WHERE r.R_Status_ID=s.R_Status_ID" + " AND s.TimeoutDays > 0 AND s.Next_Status_ID > 0" + " AND r.DateLastAction+s.TimeoutDays < SysDate" + ") " + "ORDER BY R_Status_ID";
    PreparedStatement pstmt = null;
    MStatus status = null;
    MStatus next = null;
    try {
        pstmt = DB.prepareStatement(sql, null);
        ResultSet rs = pstmt.executeQuery();
        while (rs.next()) {
            MRequest r = new MRequest(getCtx(), rs, null);
            //	Get/Check Status
            if (status == null || status.getR_Status_ID() != r.getR_Status_ID())
                status = MStatus.get(getCtx(), r.getR_Status_ID());
            if (status.getTimeoutDays() <= 0 || status.getNext_Status_ID() == 0)
                continue;
            //	Next Status
            if (next == null || next.getR_Status_ID() != status.getNext_Status_ID())
                next = MStatus.get(getCtx(), status.getNext_Status_ID());
            //
            String result = Msg.getMsg(getCtx(), "RequestStatusTimeout") + ": " + status.getName() + " -> " + next.getName();
            r.setResult(result);
            r.setR_Status_ID(status.getNext_Status_ID());
            if (r.save())
                count++;
        }
        rs.close();
    } catch (Exception e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(pstmt);
    }
    m_summary.append("Status Timeout #").append(count).append(" - ");
}
Also used : MRequest(org.compiere.model.MRequest) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) MStatus(org.compiere.model.MStatus) SQLException(java.sql.SQLException)

Aggregations

PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 MRequest (org.compiere.model.MRequest)1 MStatus (org.compiere.model.MStatus)1