Merge branch 'support-4.1.15' into 'support-4.1.15'

Add master fixes

See merge request entgra-support/support-carbon-device-mgt!75
4.x.x
Charitha Goonetilleke 3 years ago
commit ee00a00437

@ -97,9 +97,11 @@ import java.net.URL;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;
import java.util.Set;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -443,7 +445,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService(); .getDeviceManagementProviderService();
GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService(); GroupManagementProviderService groupManagementProviderService = HelperUtil.getGroupManagementProviderService();
List<Device> devices = new ArrayList<>(); Set<Device> devices = new HashSet<>();
List<String> subscribers = new ArrayList<>(); List<String> subscribers = new ArrayList<>();
List<DeviceIdentifier> errorDeviceIdentifiers = new ArrayList<>(); List<DeviceIdentifier> errorDeviceIdentifiers = new ArrayList<>();
String deviceTypeName = null; String deviceTypeName = null;
@ -520,8 +522,10 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
devices.removeIf(device -> !tmpDeviceTypeName.equals(device.getType())); devices.removeIf(device -> !tmpDeviceTypeName.equals(device.getType()));
} }
List<Device> deviceList = new ArrayList<>();
deviceList.addAll(devices);
ApplicationSubscriptionInfo applicationSubscriptionInfo = new ApplicationSubscriptionInfo(); ApplicationSubscriptionInfo applicationSubscriptionInfo = new ApplicationSubscriptionInfo();
applicationSubscriptionInfo.setDevices(devices); applicationSubscriptionInfo.setDevices(deviceList);
applicationSubscriptionInfo.setSubscribers(subscribers); applicationSubscriptionInfo.setSubscribers(subscribers);
applicationSubscriptionInfo.setErrorDeviceIdentifiers(errorDeviceIdentifiers); applicationSubscriptionInfo.setErrorDeviceIdentifiers(errorDeviceIdentifiers);
applicationSubscriptionInfo.setAppSupportingDeviceTypeName(deviceTypeName); applicationSubscriptionInfo.setAppSupportingDeviceTypeName(deviceTypeName);

@ -477,6 +477,16 @@ public interface ActivityInfoProviderService {
"Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z\n." + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z\n." +
"Example: Mon, 05 Jan 2014 15:10:00 +0200" "Example: Mon, 05 Jan 2014 15:10:00 +0200"
) )
@HeaderParam("If-Modified-Since") String ifModifiedSince); @HeaderParam("If-Modified-Since") String ifModifiedSince,
@ApiParam(
name = "startTimestamp",
value = "Starting unix timestamp value for filtering activities"
)
@QueryParam("startTimestamp") long startTimestamp,
@ApiParam(
name = "endTimestamp",
value = "Ending unix timestamp value for filtering activities"
)
@QueryParam("endTimestamp") long endTimestamp);
} }

@ -228,11 +228,14 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
@QueryParam("deviceId") String deviceId, @QueryParam("deviceId") String deviceId,
@QueryParam("type") String type, @QueryParam("type") String type,
@QueryParam("status") String status, @QueryParam("status") String status,
@HeaderParam("If-Modified-Since") String ifModifiedSince) { @HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("startTimestamp") long startTimestamp,
@QueryParam("endTimestamp") long endTimestamp) {
long ifModifiedSinceTimestamp; long ifModifiedSinceTimestamp;
long sinceTimestamp; long sinceTimestamp;
long timestamp = 0; long timestamp = 0;
boolean isTimeDurationProvided = false;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("getActivities since: " + since + " , offset: " + offset + " ,limit: " + limit + " ," + log.debug("getActivities since: " + since + " , offset: " + offset + " ,limit: " + limit + " ," +
"ifModifiedSince: " + ifModifiedSince); "ifModifiedSince: " + ifModifiedSince);
@ -262,9 +265,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
} }
sinceTimestamp = sinceDate.getTime(); sinceTimestamp = sinceDate.getTime();
timestamp = sinceTimestamp / 1000; timestamp = sinceTimestamp / 1000;
} else if (startTimestamp > 0 && endTimestamp > 0) {
RequestValidationUtil.validateTimeDuration(startTimestamp, endTimestamp);
isTimeDurationProvided = true;
} }
if (timestamp == 0) { if (timestamp == 0 && !isTimeDurationProvided) {
//If timestamp is not sent by the user, a default value is set, that is equal to current time-12 hours. //If timestamp is not sent by the user, a default value is set, that is equal to current time-12 hours.
long time = System.currentTimeMillis() / 1000; long time = System.currentTimeMillis() / 1000;
timestamp = time - 42300; timestamp = time - 42300;
@ -300,7 +306,12 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
if (status != null && !status.isEmpty()) { if (status != null && !status.isEmpty()) {
activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase())); activityPaginationRequest.setStatus(Operation.Status.valueOf(status.toUpperCase()));
} }
if (timestamp > 0) {
activityPaginationRequest.setSince(timestamp); activityPaginationRequest.setSince(timestamp);
} else {
activityPaginationRequest.setStartTimestamp(startTimestamp);
activityPaginationRequest.setEndTimestamp(endTimestamp);
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Activity request: " + new Gson().toJson(activityPaginationRequest)); log.debug("Activity request: " + new Gson().toJson(activityPaginationRequest));
} }

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

@ -34,6 +34,8 @@ public class ActivityPaginationRequest {
private long since; private long since;
private Operation.Type type; private Operation.Type type;
private Operation.Status status; private Operation.Status status;
private long startTimestamp;
private long endTimestamp;
public ActivityPaginationRequest(int offset, int limit) { public ActivityPaginationRequest(int offset, int limit) {
this.offset = offset; this.offset = offset;
@ -113,4 +115,19 @@ public class ActivityPaginationRequest {
this.status = status; this.status = status;
} }
public long getStartTimestamp() {
return startTimestamp;
}
public void setStartTimestamp(long startTimestamp) {
this.startTimestamp = startTimestamp;
}
public long getEndTimestamp() {
return endTimestamp;
}
public void setEndTimestamp(long endTimestamp) {
this.endTimestamp = endTimestamp;
}
} }

@ -1726,6 +1726,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
public List<Activity> getActivities(ActivityPaginationRequest activityPaginationRequest) public List<Activity> getActivities(ActivityPaginationRequest activityPaginationRequest)
throws OperationManagementDAOException { throws OperationManagementDAOException {
try { try {
boolean isTimeDurationFilteringProvided = false;
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String sql = "SELECT " + String sql = "SELECT " +
@ -1766,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 = ? ";
} }
@ -1791,6 +1796,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getSince() != 0) { if (activityPaginationRequest.getSince() != 0) {
sql += "AND eom.UPDATED_TIMESTAMP > ? "; sql += "AND eom.UPDATED_TIMESTAMP > ? ";
} }
if (isTimeDurationFilteringProvided) {
sql += "AND eom.CREATED_TIMESTAMP BETWEEN ? AND ? ";
}
if (activityPaginationRequest.getType() != null) { if (activityPaginationRequest.getType() != null) {
sql += "AND eom.TYPE = ? "; sql += "AND eom.TYPE = ? ";
} }
@ -1818,6 +1826,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());
} }
@ -1844,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());
} }
@ -1872,6 +1888,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
public int getActivitiesCount(ActivityPaginationRequest activityPaginationRequest) public int getActivitiesCount(ActivityPaginationRequest activityPaginationRequest)
throws OperationManagementDAOException { throws OperationManagementDAOException {
try { try {
boolean isTimeDurationFilteringProvided = false;
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
String sql = "SELECT count(DISTINCT OPERATION_ID) AS ACTIVITY_COUNT FROM DM_ENROLMENT_OP_MAPPING " + String sql = "SELECT count(DISTINCT OPERATION_ID) AS ACTIVITY_COUNT FROM DM_ENROLMENT_OP_MAPPING " +
@ -1898,6 +1915,10 @@ public class GenericOperationDAOImpl implements OperationDAO {
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatus() != null) {
sql += "AND STATUS = ? "; sql += "AND STATUS = ? ";
} }
if (activityPaginationRequest.getStartTimestamp() > 0 && activityPaginationRequest.getEndTimestamp() > 0) {
isTimeDurationFilteringProvided = true;
sql += "AND CREATED_TIMESTAMP BETWEEN ? AND ? ";
}
int index = 1; int index = 1;
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1921,7 +1942,11 @@ public class GenericOperationDAOImpl implements OperationDAO {
stmt.setString(index++, activityPaginationRequest.getType().name()); stmt.setString(index++, activityPaginationRequest.getType().name());
} }
if (activityPaginationRequest.getStatus() != null) { if (activityPaginationRequest.getStatus() != null) {
stmt.setString(index, activityPaginationRequest.getStatus().name()); stmt.setString(index++, activityPaginationRequest.getStatus().name());
}
if (isTimeDurationFilteringProvided) {
stmt.setLong(index++, activityPaginationRequest.getStartTimestamp());
stmt.setLong(index, activityPaginationRequest.getEndTimestamp());
} }
try (ResultSet rs = stmt.executeQuery()) { try (ResultSet rs = stmt.executeQuery()) {

@ -183,6 +183,19 @@
<Scope>perm:metadata:update</Scope> <Scope>perm:metadata:update</Scope>
<Scope>perm:android:google-account</Scope> <Scope>perm:android:google-account</Scope>
<Scope>perm:android:update-default-sim</Scope> <Scope>perm:android:update-default-sim</Scope>
<Scope>perm:ios:lock</Scope>
<Scope>perm:ios:location</Scope>
<Scope>perm:ios:ring</Scope>
<Scope>perm:ios:clear-passcode</Scope>
<Scope>perm:ios:enterprise-wipe</Scope>
<Scope>perm:ios:notification</Scope>
<Scope>perm:ios:wipe-data</Scope>
<Scope>perm:ios:boolean-setting</Scope>
<Scope>perm:ios:wallpaper</Scope>
<Scope>perm:ios:app-attributes</Scope>
<Scope>perm:ios:app-configurations</Scope>
<Scope>perm:mac-os:shut-down</Scope>
<Scope>perm:mac-os:restart</Scope>
</Scopes> </Scopes>
<SSOConfiguration> <SSOConfiguration>
<Issuer>device-mgt</Issuer> <Issuer>device-mgt</Issuer>

Loading…
Cancel
Save