|
|
@ -23,6 +23,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityHolder;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
|
|
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse;
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
|
|
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
|
|
@ -375,6 +376,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
for (Map.Entry<String, List<OperationResponse>> deviceOpRes : deviceOpResponseMap.entrySet()) {
|
|
|
|
for (Map.Entry<String, List<OperationResponse>> deviceOpRes : deviceOpResponseMap.entrySet()) {
|
|
|
|
for (ActivityStatus status : activityStatuses) {
|
|
|
|
for (ActivityStatus status : activityStatuses) {
|
|
|
|
if (deviceOpRes.getKey().equalsIgnoreCase(status.getDeviceIdentifier().getId())) {
|
|
|
|
if (deviceOpRes.getKey().equalsIgnoreCase(status.getDeviceIdentifier().getId())) {
|
|
|
|
|
|
|
|
if(status.getResponses()==null){
|
|
|
|
|
|
|
|
List<OperationResponse> responses = new ArrayList<>();
|
|
|
|
|
|
|
|
status.setResponses(responses);
|
|
|
|
|
|
|
|
}
|
|
|
|
status.getResponses().addAll(deviceOpRes.getValue());
|
|
|
|
status.getResponses().addAll(deviceOpRes.getValue());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -942,349 +947,117 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Activity> getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset)
|
|
|
|
public List<Activity> getActivitiesUpdatedAfterByUser(long timestamp, String user, int limit, int offset)
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
List<Activity> activities = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
|
|
|
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
String sql = "SELECT " +
|
|
|
|
String sql = "SELECT " +
|
|
|
|
" opr.ENROLMENT_ID, " +
|
|
|
|
" eom.ENROLMENT_ID," +
|
|
|
|
" opr.CREATED_TIMESTAMP, " +
|
|
|
|
" eom.CREATED_TIMESTAMP," +
|
|
|
|
" opr.UPDATED_TIMESTAMP, " +
|
|
|
|
" eom.UPDATED_TIMESTAMP," +
|
|
|
|
" opr.OPERATION_ID, " +
|
|
|
|
" eom.OPERATION_ID," +
|
|
|
|
" opr.OPERATION_CODE, " +
|
|
|
|
" eom.OPERATION_CODE," +
|
|
|
|
" opr.OPERATION_TYPE, " +
|
|
|
|
" eom.INITIATED_BY," +
|
|
|
|
" opr.STATUS, " +
|
|
|
|
" eom.TYPE," +
|
|
|
|
" opr.DEVICE_ID, " +
|
|
|
|
" eom.STATUS," +
|
|
|
|
" opr.DEVICE_IDENTIFICATION, " +
|
|
|
|
" eom.DEVICE_ID," +
|
|
|
|
" opr.DEVICE_TYPE, " +
|
|
|
|
" eom.DEVICE_IDENTIFICATION," +
|
|
|
|
" ops.RECEIVED_TIMESTAMP, " +
|
|
|
|
" eom.DEVICE_TYPE," +
|
|
|
|
" ops.ID AS OP_RES_ID, " +
|
|
|
|
" opr.ID AS OP_RES_ID," +
|
|
|
|
" ops.OPERATION_RESPONSE , " +
|
|
|
|
" opr.RECEIVED_TIMESTAMP," +
|
|
|
|
" ops.IS_LARGE_RESPONSE , " +
|
|
|
|
" opr.OPERATION_RESPONSE," +
|
|
|
|
" opr.INITIATED_BY " +
|
|
|
|
" opr.IS_LARGE_RESPONSE " +
|
|
|
|
" FROM " +
|
|
|
|
"FROM " +
|
|
|
|
" (SELECT " +
|
|
|
|
" DM_ENROLMENT_OP_MAPPING eom " +
|
|
|
|
" opm.ID MAPPING_ID, " +
|
|
|
|
"LEFT JOIN " +
|
|
|
|
" opm.ENROLMENT_ID, " +
|
|
|
|
" DM_DEVICE_OPERATION_RESPONSE opr ON opr.EN_OP_MAP_ID = eom.ID " +
|
|
|
|
" opm.CREATED_TIMESTAMP, " +
|
|
|
|
"INNER JOIN " +
|
|
|
|
" opm.UPDATED_TIMESTAMP, " +
|
|
|
|
" (SELECT DISTINCT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING ORDER BY OPERATION_ID ASC limit ? , ? ) eom_ordered " +
|
|
|
|
" opm.OPERATION_ID, " +
|
|
|
|
" ON eom_ordered.OPERATION_ID = eom.OPERATION_ID " +
|
|
|
|
" op.OPERATION_CODE, " +
|
|
|
|
"WHERE " +
|
|
|
|
" op.INITIATED_BY, " +
|
|
|
|
" eom.UPDATED_TIMESTAMP > ? " +
|
|
|
|
" op.TYPE AS OPERATION_TYPE, " +
|
|
|
|
" AND eom.TENANT_ID = ? " +
|
|
|
|
" opm.STATUS, " +
|
|
|
|
" AND eom.INITIATED_BY = ? " +
|
|
|
|
" en.DEVICE_ID, " +
|
|
|
|
"ORDER BY eom.OPERATION_ID, eom.UPDATED_TIMESTAMP";
|
|
|
|
" de.DEVICE_IDENTIFICATION, " +
|
|
|
|
|
|
|
|
" dt.NAME AS DEVICE_TYPE, " +
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
" de.TENANT_ID " +
|
|
|
|
stmt.setInt(1, offset);
|
|
|
|
" FROM" +
|
|
|
|
stmt.setInt(2, limit);
|
|
|
|
" DM_ENROLMENT_OP_MAPPING opm " +
|
|
|
|
stmt.setLong(3, timestamp);
|
|
|
|
" INNER JOIN DM_OPERATION op ON opm.OPERATION_ID = op.ID " +
|
|
|
|
stmt.setInt(4, tenantId);
|
|
|
|
" INNER JOIN DM_ENROLMENT en ON opm.ENROLMENT_ID = en.ID " +
|
|
|
|
stmt.setString(5, user);
|
|
|
|
" INNER JOIN DM_DEVICE de ON en.DEVICE_ID = de.ID " +
|
|
|
|
|
|
|
|
" INNER JOIN DM_DEVICE_TYPE dt ON dt.ID = de.DEVICE_TYPE_ID " +
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
" WHERE " +
|
|
|
|
ActivityHolder activityHolder = OperationDAOUtil.getActivityHolder(rs);
|
|
|
|
" opm.UPDATED_TIMESTAMP > ? AND op.INITIATED_BY = ?" +
|
|
|
|
List<Integer> largeResponseIDs = activityHolder.getLargeResponseIDs();
|
|
|
|
" AND de.TENANT_ID = ? " +
|
|
|
|
List<Activity> activities = activityHolder.getActivityList();
|
|
|
|
" ORDER BY opm.UPDATED_TIMESTAMP " +
|
|
|
|
if (!largeResponseIDs.isEmpty()) {
|
|
|
|
" LIMIT ? OFFSET ?) opr " +
|
|
|
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
|
|
|
" LEFT JOIN DM_DEVICE_OPERATION_RESPONSE ops ON opr.MAPPING_ID = ops.EN_OP_MAP_ID " +
|
|
|
|
|
|
|
|
" WHERE " +
|
|
|
|
|
|
|
|
" opr.UPDATED_TIMESTAMP > ? AND opr.INITIATED_BY = ?" +
|
|
|
|
|
|
|
|
" AND opr.TENANT_ID = ? ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setLong(1, timestamp);
|
|
|
|
|
|
|
|
stmt.setString(2, user);
|
|
|
|
|
|
|
|
stmt.setInt(3, tenantId);
|
|
|
|
|
|
|
|
stmt.setInt(4, limit);
|
|
|
|
|
|
|
|
stmt.setInt(5, offset);
|
|
|
|
|
|
|
|
stmt.setLong(6, timestamp);
|
|
|
|
|
|
|
|
stmt.setString(7, user);
|
|
|
|
|
|
|
|
stmt.setInt(8, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int operationId = 0;
|
|
|
|
|
|
|
|
int enrolmentId = 0;
|
|
|
|
|
|
|
|
int responseId = 0;
|
|
|
|
|
|
|
|
Activity activity = null;
|
|
|
|
|
|
|
|
ActivityStatus activityStatus = null;
|
|
|
|
|
|
|
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (operationId != rs.getInt("OPERATION_ID")) {
|
|
|
|
|
|
|
|
activity = new Activity();
|
|
|
|
|
|
|
|
activities.add(activity);
|
|
|
|
|
|
|
|
List<ActivityStatus> statusList = new ArrayList<>();
|
|
|
|
|
|
|
|
activityStatus = new ActivityStatus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
operationId = rs.getInt("OPERATION_ID");
|
|
|
|
|
|
|
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
|
|
|
|
|
|
|
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
|
|
|
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
|
|
|
activity.setInitiatedBy(rs.getString("INITIATED_BY"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
|
|
|
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
deviceIdentifier.setType(rs.getString("DEVICE_TYPE"));
|
|
|
|
|
|
|
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<OperationResponse> operationResponses = new ArrayList<>();
|
|
|
|
|
|
|
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
|
|
|
|
|
|
|
activityStatus.setUpdatedTimestamp(new java.util.Date(
|
|
|
|
|
|
|
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
|
|
|
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
|
|
|
|
|
|
|
largeResponseIDs.add(responseId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
|
|
|
|
statusList.add(activityStatus);
|
|
|
|
|
|
|
|
activity.setActivityStatus(statusList);
|
|
|
|
|
|
|
|
activity.setActivityId(OperationDAOUtil.getActivityId(rs.getInt("OPERATION_ID")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) {
|
|
|
|
|
|
|
|
activityStatus = new ActivityStatus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
|
|
|
|
|
|
|
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
|
|
|
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
|
|
|
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
deviceIdentifier.setType(rs.getString("DEVICE_TYPE"));
|
|
|
|
|
|
|
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<OperationResponse> operationResponses = new ArrayList<>();
|
|
|
|
|
|
|
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
|
|
|
|
|
|
|
activityStatus.setUpdatedTimestamp(new java.util.Date(
|
|
|
|
|
|
|
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
|
|
|
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
|
|
|
|
|
|
|
largeResponseIDs.add(responseId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
|
|
|
|
activity.getActivityStatus().add(activityStatus);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
|
|
|
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
|
|
|
|
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
|
|
|
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
|
|
|
|
|
|
|
largeResponseIDs.add(responseId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return activities;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!largeResponseIDs.isEmpty()) {
|
|
|
|
|
|
|
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
|
|
|
String msg = "Error occurred while getting the operation details from the database. ";
|
|
|
|
"the database. " + e.getMessage(), e);
|
|
|
|
log.error(msg, e);
|
|
|
|
} finally {
|
|
|
|
throw new OperationManagementDAOException(msg, e);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return activities;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit,
|
|
|
|
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset)
|
|
|
|
int offset) throws OperationManagementDAOException {
|
|
|
|
throws OperationManagementDAOException {
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
List<Activity> activities = new ArrayList<>();
|
|
|
|
|
|
|
|
List<Integer> largeResponseIDs = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
String sql = "SELECT " +
|
|
|
|
|
|
|
|
" opr.ENROLMENT_ID, " +
|
|
|
|
|
|
|
|
" opr.CREATED_TIMESTAMP, " +
|
|
|
|
|
|
|
|
" opr.UPDATED_TIMESTAMP, " +
|
|
|
|
|
|
|
|
" opr.OPERATION_ID, " +
|
|
|
|
|
|
|
|
" opr.OPERATION_CODE, " +
|
|
|
|
|
|
|
|
" opr.OPERATION_TYPE, " +
|
|
|
|
|
|
|
|
" opr.STATUS, " +
|
|
|
|
|
|
|
|
" opr.DEVICE_ID, " +
|
|
|
|
|
|
|
|
" opr.DEVICE_IDENTIFICATION, " +
|
|
|
|
|
|
|
|
" opr.DEVICE_TYPE, " +
|
|
|
|
|
|
|
|
" ops.RECEIVED_TIMESTAMP, " +
|
|
|
|
|
|
|
|
" ops.IS_LARGE_RESPONSE, " +
|
|
|
|
|
|
|
|
" ops.ID AS OP_RES_ID, " +
|
|
|
|
|
|
|
|
" ops.OPERATION_RESPONSE " +
|
|
|
|
|
|
|
|
" FROM " +
|
|
|
|
|
|
|
|
" (SELECT " +
|
|
|
|
|
|
|
|
" opm.ID MAPPING_ID, " +
|
|
|
|
|
|
|
|
" opm.ENROLMENT_ID, " +
|
|
|
|
|
|
|
|
" opm.CREATED_TIMESTAMP, " +
|
|
|
|
|
|
|
|
" opm.UPDATED_TIMESTAMP, " +
|
|
|
|
|
|
|
|
" opm.OPERATION_ID, " +
|
|
|
|
|
|
|
|
" op.OPERATION_CODE, " +
|
|
|
|
|
|
|
|
" op.TYPE AS OPERATION_TYPE, " +
|
|
|
|
|
|
|
|
" opm.STATUS, " +
|
|
|
|
|
|
|
|
" en.DEVICE_ID, " +
|
|
|
|
|
|
|
|
" de.DEVICE_IDENTIFICATION, " +
|
|
|
|
|
|
|
|
" dt.NAME AS DEVICE_TYPE, " +
|
|
|
|
|
|
|
|
" de.TENANT_ID " +
|
|
|
|
|
|
|
|
" FROM" +
|
|
|
|
|
|
|
|
" DM_ENROLMENT_OP_MAPPING opm " +
|
|
|
|
|
|
|
|
" INNER JOIN DM_OPERATION op ON opm.OPERATION_ID = op.ID " +
|
|
|
|
|
|
|
|
" INNER JOIN DM_ENROLMENT en ON opm.ENROLMENT_ID = en.ID " +
|
|
|
|
|
|
|
|
" INNER JOIN DM_DEVICE de ON en.DEVICE_ID = de.ID " +
|
|
|
|
|
|
|
|
" INNER JOIN DM_DEVICE_TYPE dt ON dt.ID = de.DEVICE_TYPE_ID " +
|
|
|
|
|
|
|
|
" WHERE " +
|
|
|
|
|
|
|
|
" opm.UPDATED_TIMESTAMP > ? " +
|
|
|
|
|
|
|
|
" AND de.TENANT_ID = ? " +
|
|
|
|
|
|
|
|
" ORDER BY opm.UPDATED_TIMESTAMP " +
|
|
|
|
|
|
|
|
" LIMIT ? OFFSET ?) opr " +
|
|
|
|
|
|
|
|
" LEFT JOIN DM_DEVICE_OPERATION_RESPONSE ops ON opr.MAPPING_ID = ops.EN_OP_MAP_ID " +
|
|
|
|
|
|
|
|
" WHERE " +
|
|
|
|
|
|
|
|
" opr.UPDATED_TIMESTAMP > ? " +
|
|
|
|
|
|
|
|
" AND opr.TENANT_ID = ? ";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt.setLong(1, timestamp);
|
|
|
|
|
|
|
|
stmt.setInt(2, tenantId);
|
|
|
|
|
|
|
|
stmt.setInt(3, limit);
|
|
|
|
|
|
|
|
stmt.setInt(4, offset);
|
|
|
|
|
|
|
|
stmt.setLong(5, timestamp);
|
|
|
|
|
|
|
|
stmt.setInt(6, tenantId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int operationId = 0;
|
|
|
|
|
|
|
|
int enrolmentId = 0;
|
|
|
|
|
|
|
|
int responseId = 0;
|
|
|
|
|
|
|
|
Activity activity = null;
|
|
|
|
|
|
|
|
ActivityStatus activityStatus = null;
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (operationId != rs.getInt("OPERATION_ID")) {
|
|
|
|
|
|
|
|
activity = new Activity();
|
|
|
|
|
|
|
|
activities.add(activity);
|
|
|
|
|
|
|
|
List<ActivityStatus> statusList = new ArrayList<>();
|
|
|
|
|
|
|
|
activityStatus = new ActivityStatus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
operationId = rs.getInt("OPERATION_ID");
|
|
|
|
|
|
|
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
|
|
|
|
|
|
|
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
|
|
|
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
|
|
|
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
deviceIdentifier.setType(rs.getString("DEVICE_TYPE"));
|
|
|
|
|
|
|
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
List<OperationResponse> operationResponses = new ArrayList<>();
|
|
|
|
|
|
|
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
|
|
|
|
|
|
|
activityStatus.setUpdatedTimestamp(new java.util.Date(
|
|
|
|
|
|
|
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
|
|
|
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
|
|
|
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
|
|
|
|
|
|
|
largeResponseIDs.add(responseId);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
|
|
|
|
statusList.add(activityStatus);
|
|
|
|
|
|
|
|
activity.setActivityStatus(statusList);
|
|
|
|
|
|
|
|
activity.setActivityId(OperationDAOUtil.getActivityId(rs.getInt("OPERATION_ID")));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (operationId == rs.getInt("OPERATION_ID") && enrolmentId != rs.getInt("ENROLMENT_ID")) {
|
|
|
|
|
|
|
|
activityStatus = new ActivityStatus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
|
|
|
|
|
|
|
|
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
|
|
|
|
activity.setCode(rs.getString("OPERATION_CODE"));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
|
|
|
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
deviceIdentifier.setType(rs.getString("DEVICE_TYPE"));
|
|
|
|
|
|
|
|
activityStatus.setDeviceIdentifier(deviceIdentifier);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activityStatus.setStatus(ActivityStatus.Status.valueOf(rs.getString("STATUS")));
|
|
|
|
String sql = "SELECT " +
|
|
|
|
|
|
|
|
" eom.ENROLMENT_ID," +
|
|
|
|
List<OperationResponse> operationResponses = new ArrayList<>();
|
|
|
|
" eom.CREATED_TIMESTAMP," +
|
|
|
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
|
|
|
" eom.UPDATED_TIMESTAMP," +
|
|
|
|
activityStatus.setUpdatedTimestamp(new java.util.Date(
|
|
|
|
" eom.OPERATION_ID," +
|
|
|
|
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
|
|
|
|
" eom.OPERATION_CODE," +
|
|
|
|
}
|
|
|
|
" eom.INITIATED_BY," +
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
|
|
|
" eom.TYPE," +
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
" eom.STATUS," +
|
|
|
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
|
|
|
" eom.DEVICE_ID," +
|
|
|
|
largeResponseIDs.add(responseId);
|
|
|
|
" eom.DEVICE_IDENTIFICATION," +
|
|
|
|
} else {
|
|
|
|
" eom.DEVICE_TYPE," +
|
|
|
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
" ops.ID AS OP_RES_ID," +
|
|
|
|
}
|
|
|
|
" ops.RECEIVED_TIMESTAMP," +
|
|
|
|
}
|
|
|
|
" ops.OPERATION_RESPONSE," +
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
" ops.IS_LARGE_RESPONSE " +
|
|
|
|
activity.getActivityStatus().add(activityStatus);
|
|
|
|
"FROM " +
|
|
|
|
|
|
|
|
" DM_ENROLMENT_OP_MAPPING AS eom " +
|
|
|
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
|
|
|
"INNER JOIN " +
|
|
|
|
}
|
|
|
|
" (SELECT DISTINCT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING ORDER BY OPERATION_ID ASC limit ? , ? ) AS eom_ordered " +
|
|
|
|
|
|
|
|
" ON eom_ordered.OPERATION_ID = eom.OPERATION_ID " +
|
|
|
|
if (rs.getInt("OP_RES_ID") != 0 && responseId != rs.getInt("OP_RES_ID")) {
|
|
|
|
"LEFT JOIN " +
|
|
|
|
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != null) {
|
|
|
|
" DM_DEVICE_OPERATION_RESPONSE AS ops ON ops.EN_OP_MAP_ID = eom.ID " +
|
|
|
|
responseId = rs.getInt("OP_RES_ID");
|
|
|
|
"WHERE " +
|
|
|
|
if (rs.getBoolean("IS_LARGE_RESPONSE")) {
|
|
|
|
" eom.UPDATED_TIMESTAMP > ? " +
|
|
|
|
largeResponseIDs.add(responseId);
|
|
|
|
" AND eom.TENANT_ID = ? " +
|
|
|
|
} else {
|
|
|
|
"ORDER BY eom.OPERATION_ID, eom.UPDATED_TIMESTAMP";
|
|
|
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
|
|
|
|
}
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
|
|
|
|
stmt.setInt(1, offset);
|
|
|
|
|
|
|
|
stmt.setInt(2, limit);
|
|
|
|
|
|
|
|
stmt.setLong(3, timestamp);
|
|
|
|
|
|
|
|
stmt.setInt(4, tenantId);
|
|
|
|
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
|
|
|
|
ActivityHolder activityHolder = OperationDAOUtil.getActivityHolder(rs);
|
|
|
|
|
|
|
|
List<Integer> largeResponseIDs = activityHolder.getLargeResponseIDs();
|
|
|
|
|
|
|
|
List<Activity> activities = activityHolder.getActivityList();
|
|
|
|
|
|
|
|
if (!largeResponseIDs.isEmpty()) {
|
|
|
|
|
|
|
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return activities;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!largeResponseIDs.isEmpty()) {
|
|
|
|
|
|
|
|
populateLargeOperationResponses(activities, largeResponseIDs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
|
|
|
String msg = "Error occurred while getting the operation details from the database.";
|
|
|
|
"the database. " + e.getMessage(), e);
|
|
|
|
log.error(msg,e);
|
|
|
|
} finally {
|
|
|
|
throw new OperationManagementDAOException(msg, e);
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return activities;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
@ -1293,7 +1066,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
ResultSet rs = null;
|
|
|
|
ResultSet rs = null;
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
String sql = "SELECT COUNT(*) AS COUNT FROM DM_ENROLMENT_OP_MAPPING WHERE " +
|
|
|
|
String sql = "SELECT COUNT(DISTINCT(OPERATION_ID)) AS COUNT FROM DM_ENROLMENT_OP_MAPPING WHERE " +
|
|
|
|
"UPDATED_TIMESTAMP > ? AND TENANT_ID = ?";
|
|
|
|
"UPDATED_TIMESTAMP > ? AND TENANT_ID = ?";
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
stmt.setLong(1, timestamp);
|
|
|
|
stmt.setLong(1, timestamp);
|
|
|
@ -1490,11 +1263,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
// if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
|
|
|
|
// operation.setReceivedTimeStamp("");
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
@ -1692,11 +1460,6 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
operation.setId(rs.getInt("ID"));
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
|
|
|
|
// if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
|
|
|
|
|
|
|
|
// operation.setReceivedTimeStamp("");
|
|
|
|
|
|
|
|
// } else {
|
|
|
|
|
|
|
|
// operation.setReceivedTimeStamp(rs.getTimestamp("RECEIVED_TIMESTAMP").toString());
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
operation.setReceivedTimeStamp("");
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|