Adding the activity count for the activty paginantion

merge-requests/7/head
geethkokila 8 years ago
parent a67f432993
commit c07914eb36

@ -113,6 +113,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
try {
dmService = DeviceMgtAPIUtils.getDeviceManagementService();
activities = dmService.getActivitiesUpdatedAfter(timestamp, limit, offset);
activityList.setList(activities);
int count = dmService.getActivityCountUpdatedAfter(timestamp);
activityList.setCount(count);
if (activities == null || activities.size() == 0) {
if (isIfModifiedSinceSet) {
return Response.status(Response.Status.NOT_MODIFIED).entity(
@ -132,6 +135,6 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
throw new UnexpectedServerErrorException(new ErrorResponse.ErrorResponseBuilder().setCode(500l)
.setMessage(msg).build());
}
return Response.status(Response.Status.OK).entity(activities).build();
return Response.status(Response.Status.OK).entity(activityList).build();
}
}

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

@ -809,6 +809,21 @@ public class OperationManagerImpl implements OperationManager {
}
}
@Override
public int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementException {
try {
OperationManagementDAOFactory.openConnection();
return operationDAO.getActivityCountUpdatedAfter(timestamp);
} 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 count changed after a " +
"given time.", e);
} finally {
OperationManagementDAOFactory.closeConnection();
}
}
private OperationDAO lookupOperationDAO(Operation operation) {
if (operation instanceof CommandOperation) {

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

@ -474,6 +474,31 @@ public class GenericOperationDAOImpl implements OperationDAO {
return activities;
}
@Override
public int getActivityCountUpdatedAfter(long timestamp) throws OperationManagementDAOException {
PreparedStatement stmt = null;
ResultSet rs = null;
try {
Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT COUNT(*) AS COUNT FROM DM_ENROLMENT_OP_MAPPING AS m \n" +
"INNER JOIN DM_ENROLMENT AS d ON m.ENROLMENT_ID = d.ID \n" +
"WHERE m.UPDATED_TIMESTAMP > ? AND d.TENANT_ID = ?;";
stmt = conn.prepareStatement(sql);
stmt.setLong(1, timestamp);
stmt.setInt(2, PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
rs = stmt.executeQuery();
if(rs.next()){
return rs.getInt("COUNT");
}
} catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while getting the activity count from " +
"the database.", e);
} finally {
OperationManagementDAOUtil.cleanupResources(stmt, rs);
}
return 0;
}
private OperationResponse getOperationResponse(ResultSet rs) throws
ClassNotFoundException, IOException, SQLException {
OperationResponse response = new OperationResponse();

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

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

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

Loading…
Cancel
Save