Change time filtering DB column

master
Pahansith Gunathilake 3 years ago
parent a0856f7069
commit 9f2cedd09c

@ -773,8 +773,9 @@ public class RequestValidationUtil {
public static void validateTimeDuration(long startTimestamp, long endTimestamp) { public static void validateTimeDuration(long startTimestamp, long endTimestamp) {
if (startTimestamp > endTimestamp) { if (startTimestamp > endTimestamp) {
throw new InputValidationException( throw new InputValidationException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage("Request parameter startTimestamp" + new ErrorResponse.ErrorResponseBuilder().setCode(400l)
" should not be higher values than endTimestamp").build()); .setMessage("Request parameter startTimestamp should not be " +
"a higher value than endTimestamp").build());
} }
} }
} }

@ -1767,6 +1767,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getSince() != 0) { if (activityPaginationRequest.getSince() != 0) {
sql += "AND UPDATED_TIMESTAMP > ? "; sql += "AND UPDATED_TIMESTAMP > ? ";
} }
if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) {
isTimeDurationFilteringProvided = true;
sql += "AND CREATED_TIMESTAMP BETWEEN ? AND ? ";
}
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
sql += "AND TYPE = ? "; sql += "AND TYPE = ? ";
} }
@ -1792,9 +1796,8 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getSince() != 0) { if (activityPaginationRequest.getSince() != 0) {
sql += "AND eom.UPDATED_TIMESTAMP > ? "; sql += "AND eom.UPDATED_TIMESTAMP > ? ";
} }
if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) { if (isTimeDurationFilteringProvided) {
isTimeDurationFilteringProvided = true; sql += "AND eom.CREATED_TIMESTAMP BETWEEN ? AND ? ";
sql += "AND eom.UPDATED_TIMESTAMP BETWEEN ? AND ? ";
} }
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
sql += "AND eom.TYPE = ? "; sql += "AND eom.TYPE = ? ";
@ -1853,6 +1856,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getSince() != 0) { if (activityPaginationRequest.getSince() != 0) {
stmt.setLong(index++, activityPaginationRequest.getSince()); stmt.setLong(index++, activityPaginationRequest.getSince());
} }
if (isTimeDurationFilteringProvided) {
stmt.setLong(index++, activityPaginationRequest.getStartTimestamp());
stmt.setLong(index++, activityPaginationRequest.getEndTimestamp());
}
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
stmt.setString(index++, activityPaginationRequest.getType().name()); stmt.setString(index++, activityPaginationRequest.getType().name());
} }
@ -1910,7 +1917,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
} }
if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) { if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) {
isTimeDurationFilteringProvided = true; isTimeDurationFilteringProvided = true;
sql += "AND UPDATED_TIMESTAMP BETWEEN ? AND ? "; sql += "AND CREATED_TIMESTAMP BETWEEN ? AND ? ";
} }
int index = 1; int index = 1;

Loading…
Cancel
Save