Fixing the limit and offset for activity

revert-70aa11f8
geethkokila 9 years ago
parent a9f8e8c84d
commit 236eb90ce2

@ -112,7 +112,7 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
DeviceManagementProviderService dmService;
try {
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
activities = dmService.getActivitiesUpdatedAfter(timestamp);
activities = dmService.getActivitiesUpdatedAfter(timestamp, limit, offset);
if (activities == null || activities.size() == 0) {
if (isIfModifiedSinceSet) {
return Response.status(Response.Status.NOT_MODIFIED).entity(

@ -88,4 +88,6 @@ public interface OperationManager {
List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementException;
List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException;
}

@ -794,6 +794,21 @@ public class OperationManagerImpl implements OperationManager {
}
}
@Override
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException {
try {
OperationManagementDAOFactory.openConnection();
return operationDAO.getActivitiesUpdatedAfter(timestamp, limit, offset);
} catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection to the data source.", e);
} catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while getting the activity list changed after a " +
"given time.", e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
}
private OperationDAO lookupOperationDAO(Operation operation) {
if (operation instanceof CommandOperation) {

@ -73,4 +73,6 @@ public interface OperationDAO {
List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementDAOException;
List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementDAOException;
}

@ -306,7 +306,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
activityStatus.setUpdatedTimestamp(String.valueOf(rs.getInt("UPDATED_TIMESTAMP")));
activityStatus.setUpdatedTimestamp(new java.util.Date(rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
operationResponses.add(this.getOperationResponse(rs));
}
activityStatus.setResponses(operationResponses);
@ -336,6 +336,11 @@ public class GenericOperationDAOImpl implements OperationDAO {
@Override
public List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementDAOException {
return this.getActivitiesUpdatedAfter(timestamp, 0, 0);
}
@Override
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
List<Activity> activities = new ArrayList<>();
@ -352,11 +357,28 @@ public class GenericOperationDAOImpl implements OperationDAO {
"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.UPDATED_TIMESTAMP > ? AND de.TENANT_ID = ?";
"WHERE eom.UPDATED_TIMESTAMP > ? AND de.TENANT_ID = ? ORDER BY eom.OPERATION_ID";
if(limit > 0) {
sql = sql + " LIMIT ?";
}
if(offset > 0) {
sql = sql + " OFFSET ?";
}
stmt = conn.prepareStatement(sql);
stmt.setLong(1, timestamp);
stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
int increment = 2;
if(limit > 0) {
stmt.setInt(++increment, limit);
}
if(offset > 0) {
stmt.setInt(++increment, offset);
}
rs = stmt.executeQuery();
int operationId = 0;
@ -388,7 +410,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
activityStatus.setUpdatedTimestamp(String.valueOf(rs.getInt("UPDATED_TIMESTAMP")));
activityStatus.setUpdatedTimestamp(new java.util.Date(
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
}
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
operationResponses.add(this.getOperationResponse(rs));
@ -417,7 +441,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
List<OperationResponse> operationResponses = new ArrayList<>();
if (rs.getInt("UPDATED_TIMESTAMP") != 0) {
activityStatus.setUpdatedTimestamp(String.valueOf(rs.getInt("UPDATED_TIMESTAMP")));
activityStatus.setUpdatedTimestamp(new java.util.Date(
rs.getLong(("UPDATED_TIMESTAMP")) * 1000).toString());
}
if (rs.getTimestamp("RECEIVED_TIMESTAMP") != (null)) {
operationResponses.add(this.getOperationResponse(rs));

@ -126,4 +126,9 @@ public class PushNotificationBasedOperationManager implements OperationManager {
return this.operationManager.getActivitiesUpdatedAfter(timestamp);
}
@Override
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException {
return this.operationManager.getActivitiesUpdatedAfter(timestamp, limit, offset);
}
}

@ -240,4 +240,6 @@ public interface DeviceManagementProviderService {
List<Activity> getActivitiesUpdatedAfter(long timestamp) throws OperationManagementException;
List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException;
}

@ -1093,6 +1093,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return DeviceManagementDataHolder.getInstance().getOperationManager().getActivitiesUpdatedAfter(timestamp);
}
@Override
public List<Activity> getActivitiesUpdatedAfter(long timestamp, int limit, int offset) throws OperationManagementException {
return DeviceManagementDataHolder.getInstance().getOperationManager().getActivitiesUpdatedAfter(timestamp, limit, offset);
}
@Override
public List<Device> getDevicesOfUser(String username) throws DeviceManagementException {
List<Device> devices = new ArrayList<>();

Loading…
Cancel
Save