Fixed issue releated to activity api since

revert-70aa11f8
Chatura Dilan Perera 8 years ago
parent 763993263c
commit 549a2773f2

@ -406,31 +406,35 @@ public class GenericOperationDAOImpl implements OperationDAO {
// sql = sql + " OFFSET ?"; // sql = sql + " OFFSET ?";
// } // }
String sql = "SELECT feom.ENROLMENT_ID, feom.OPERATION_ID, feom.CREATED_TIMESTAMP, o.TYPE AS OPERATION_TYPE, " +
"o.OPERATION_CODE, orsp.OPERATION_RESPONSE, orsp.LATEST_RECEIVED_TIMESTAMP AS RECEIVED_TIMESTAMP, " + String sql = "SELECT opm.ENROLMENT_ID, opm.CREATED_TIMESTAMP, opm.UPDATED_TIMESTAMP, opm.OPERATION_ID,\n" +
"orsp.ID AS OP_RES_ID, feom.STATUS, feom.UPDATED_TIMESTAMP, feom.DEVICE_IDENTIFICATION, " + "op.OPERATION_CODE, op.TYPE as OPERATION_TYPE, opm.STATUS, en.DEVICE_ID,\n" +
"feom.DEVICE_TYPE FROM (SELECT eom.ENROLMENT_ID, eom.OPERATION_ID, eom.STATUS, eom.CREATED_TIMESTAMP, " + "op.RECEIVED_TIMESTAMP, ops.ID as OP_RES_ID, ops.OPERATION_RESPONSE,\n" +
"eom.UPDATED_TIMESTAMP, fe.DEVICE_IDENTIFICATION, fe.DEVICE_TYPE FROM " + "de.DEVICE_IDENTIFICATION, dt.NAME as DEVICE_TYPE\n" +
"(SELECT ENROLMENT_ID, OPERATION_ID, STATUS, CREATED_TIMESTAMP, UPDATED_TIMESTAMP " + "FROM DM_ENROLMENT_OP_MAPPING AS opm\n" +
"FROM DM_ENROLMENT_OP_MAPPING WHERE UPDATED_TIMESTAMP > ? ORDER BY OPERATION_ID LIMIT ? OFFSET ?) eom " + "LEFT JOIN DM_OPERATION AS op ON opm.OPERATION_ID = op.ID\n" +
"LEFT OUTER JOIN (SELECT e.ID AS ENROLMENT_ID, d.ID AS DEVICE_ID, d.DEVICE_IDENTIFICATION, " + "LEFT JOIN DM_ENROLMENT as en ON opm.ENROLMENT_ID = en.ID\n" +
"t.NAME AS DEVICE_TYPE FROM DM_ENROLMENT e LEFT OUTER JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " + "LEFT JOIN DM_DEVICE as de ON en.DEVICE_ID = de.ID\n" +
"LEFT OUTER JOIN DM_DEVICE_TYPE t ON d.DEVICE_TYPE_ID = t.ID WHERE d.TENANT_ID = ? AND " + "LEFT JOIN DM_DEVICE_TYPE as dt ON dt.ID = de.DEVICE_TYPE_ID\n" +
"e.TENANT_ID = ?) fe ON fe.ENROLMENT_ID = eom.ENROLMENT_ID) feom LEFT OUTER JOIN DM_OPERATION o " + "LEFT JOIN DM_DEVICE_OPERATION_RESPONSE as ops ON ops.ID = opm.OPERATION_ID\n" +
"ON feom.OPERATION_ID = o.ID LEFT OUTER JOIN (SELECT ID, ENROLMENT_ID, OPERATION_ID, " + "WHERE opm.UPDATED_TIMESTAMP > ? \n" +
"OPERATION_RESPONSE, MAX(RECEIVED_TIMESTAMP) LATEST_RECEIVED_TIMESTAMP " + "AND de.TENANT_ID = ? \n";
"FROM DM_DEVICE_OPERATION_RESPONSE GROUP BY ENROLMENT_ID , OPERATION_ID) orsp " +
"ON o.ID = orsp.OPERATION_ID AND feom.ENROLMENT_ID = orsp.ENROLMENT_ID GROUP BY feom.ENROLMENT_ID, " + if(timestamp == 0){
"feom.OPERATION_ID"; sql += "ORDER BY opm.OPERATION_ID LIMIT ? OFFSET ?;";
}else{
sql += "ORDER BY opm.UPDATED_TIMESTAMP asc LIMIT ? OFFSET ?";
}
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setLong(1, timestamp); stmt.setLong(1, timestamp);
stmt.setInt(2, limit);
stmt.setInt(3, offset);
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
stmt.setInt(4, tenantId); stmt.setInt(2, tenantId);
stmt.setInt(5, tenantId); stmt.setInt(3, limit);
stmt.setInt(4, offset);
rs = stmt.executeQuery(); rs = stmt.executeQuery();

Loading…
Cancel
Save