|
|
@ -384,6 +384,83 @@ public class GenericOperationDAOImpl implements OperationDAO {
|
|
|
|
return activity;
|
|
|
|
return activity;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Activity getActivityByDevice(int operationId, int deviceId) throws OperationManagementDAOException {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
ResultSet rs = null;
|
|
|
|
|
|
|
|
Activity activity = null;
|
|
|
|
|
|
|
|
List<ActivityStatus> activityStatusList = new ArrayList<>();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
Connection conn = OperationManagementDAOFactory.getConnection();
|
|
|
|
|
|
|
|
String sql = "SELECT eom.ENROLMENT_ID, eom.OPERATION_ID, eom.ID AS EOM_MAPPING_ID, dor.ID AS OP_RES_ID,\n" +
|
|
|
|
|
|
|
|
"de.DEVICE_ID, d.DEVICE_IDENTIFICATION, \n" +
|
|
|
|
|
|
|
|
"d.DEVICE_TYPE_ID, dt.NAME AS DEVICE_TYPE_NAME, eom.STATUS, eom.CREATED_TIMESTAMP, \n" +
|
|
|
|
|
|
|
|
"eom.UPDATED_TIMESTAMP, op.OPERATION_CODE, op.TYPE AS OPERATION_TYPE, dor.OPERATION_RESPONSE, \n" +
|
|
|
|
|
|
|
|
"dor.RECEIVED_TIMESTAMP FROM DM_ENROLMENT_OP_MAPPING AS eom \n" +
|
|
|
|
|
|
|
|
"INNER JOIN DM_OPERATION AS op ON op.ID=eom.OPERATION_ID\n" +
|
|
|
|
|
|
|
|
"INNER JOIN DM_ENROLMENT AS de ON de.ID=eom.ENROLMENT_ID\n" +
|
|
|
|
|
|
|
|
"INNER JOIN DM_DEVICE AS d ON d.ID=de.DEVICE_ID \n" +
|
|
|
|
|
|
|
|
"INNER JOIN DM_DEVICE_TYPE AS dt ON dt.ID=d.DEVICE_TYPE_ID\n" +
|
|
|
|
|
|
|
|
"LEFT JOIN DM_DEVICE_OPERATION_RESPONSE AS dor ON dor.ENROLMENT_ID=de.id \n" +
|
|
|
|
|
|
|
|
"AND dor.OPERATION_ID = eom.OPERATION_ID\n" +
|
|
|
|
|
|
|
|
"WHERE eom.OPERATION_ID = ? AND de.device_id = ? AND de.TENANT_ID = ?";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
stmt = conn.prepareStatement(sql);
|
|
|
|
|
|
|
|
stmt.setInt(1, operationId);
|
|
|
|
|
|
|
|
stmt.setInt(2, deviceId);
|
|
|
|
|
|
|
|
stmt.setInt(3, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
|
|
|
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int enrolmentId = 0;
|
|
|
|
|
|
|
|
ActivityStatus activityStatus = null;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (rs.next()) {
|
|
|
|
|
|
|
|
if (enrolmentId == 0) {
|
|
|
|
|
|
|
|
activity = new Activity();
|
|
|
|
|
|
|
|
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"));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if (enrolmentId != rs.getInt("ENROLMENT_ID")) {
|
|
|
|
|
|
|
|
activityStatus = new ActivityStatus();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
|
|
|
|
|
|
|
deviceIdentifier.setId(rs.getString("DEVICE_IDENTIFICATION"));
|
|
|
|
|
|
|
|
deviceIdentifier.setType(rs.getString("DEVICE_TYPE_NAME"));
|
|
|
|
|
|
|
|
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());
|
|
|
|
|
|
|
|
operationResponses.add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
activityStatus.setResponses(operationResponses);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
activityStatusList.add(activityStatus);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enrolmentId = rs.getInt("ENROLMENT_ID");
|
|
|
|
|
|
|
|
activity.setActivityStatus(activityStatusList);
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
|
|
|
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
|
|
|
|
|
|
|
|
activityStatus.getResponses().add(OperationDAOUtil.getOperationResponse(rs));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException("Error occurred while getting the operation details from " +
|
|
|
|
|
|
|
|
"the database.", e);
|
|
|
|
|
|
|
|
} catch (ClassNotFoundException e) {
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException("Error occurred while converting the operation response to string.", e);
|
|
|
|
|
|
|
|
} catch (IOException e) {
|
|
|
|
|
|
|
|
throw new OperationManagementDAOException("IO exception occurred while converting the operations responses.", e);
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
OperationManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return activity;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementDAOException {
|
|
|
|
public List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementDAOException {
|
|
|
|
return this.getActivitiesUpdatedAfter(timestamp, 0, 0);
|
|
|
|
return this.getActivitiesUpdatedAfter(timestamp, 0, 0);
|
|
|
|