mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Merge branch 'application-mgt-new' into 'application-mgt-new'
Improve APPM subscribing functionality See merge request entgra/carbon-device-mgt!323
This commit is contained in:
commit
de640638e3
@ -36,7 +36,7 @@ public class ApplicationInstallResponse {
|
|||||||
value = "List of devices that either device identity is not exist or device type doesn't compatible with the supported device type of the .",
|
value = "List of devices that either device identity is not exist or device type doesn't compatible with the supported device type of the .",
|
||||||
dataType = "List[org.wso2.carbon.device.mgt.common.DeviceIdentifier]"
|
dataType = "List[org.wso2.carbon.device.mgt.common.DeviceIdentifier]"
|
||||||
)
|
)
|
||||||
private List<DeviceIdentifier> errorDevices;
|
private List<DeviceIdentifier> errorDeviceIdentifiers;
|
||||||
|
|
||||||
|
|
||||||
@ApiModelProperty(
|
@ApiModelProperty(
|
||||||
@ -61,7 +61,7 @@ public class ApplicationInstallResponse {
|
|||||||
this.ignoredDeviceIdentifiers = ignoredDeviceIdentifiers;
|
this.ignoredDeviceIdentifiers = ignoredDeviceIdentifiers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<DeviceIdentifier> getErrorDevices() { return errorDevices; }
|
public List<DeviceIdentifier> getErrorDeviceIdentifiers() { return errorDeviceIdentifiers; }
|
||||||
|
|
||||||
public void setErrorDevices(List<DeviceIdentifier> errorDevices) { this.errorDevices = errorDevices; }
|
public void setErrorDeviceIdentifiers(List<DeviceIdentifier> errorDeviceIdentifiers) { this.errorDeviceIdentifiers = errorDeviceIdentifiers; }
|
||||||
}
|
}
|
||||||
|
|||||||
@ -140,7 +140,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
try (ResultSet rs = stmt.getGeneratedKeys()){
|
try (ResultSet rs = stmt.getGeneratedKeys()){
|
||||||
List<Integer> updatedDeviceSubIds = new ArrayList<>();
|
List<Integer> updatedDeviceSubIds = new ArrayList<>();
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
updatedDeviceSubIds.add(rs.getInt(1));
|
updatedDeviceSubIds.add(rs.getInt("ID"));
|
||||||
}
|
}
|
||||||
return updatedDeviceSubIds;
|
return updatedDeviceSubIds;
|
||||||
}
|
}
|
||||||
@ -402,7 +402,13 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
try (ResultSet rs = ps.executeQuery()) {
|
try (ResultSet rs = ps.executeQuery()) {
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
DeviceSubscriptionDTO deviceSubscriptionDTO = DAOUtil.constructDeviceSubscriptionDTO(rs);
|
DeviceSubscriptionDTO deviceSubscriptionDTO = DAOUtil.constructDeviceSubscriptionDTO(rs);
|
||||||
deviceSubscriptionDTOHashMap.put(deviceSubscriptionDTO.getId(), deviceSubscriptionDTO);
|
if (deviceSubscriptionDTOHashMap.containsKey(deviceSubscriptionDTO.getDeviceId())){
|
||||||
|
String msg = "There shouldn't be Device ids in multiple times in AP_DEVICE_SUBSCRIPTION "
|
||||||
|
+ "table.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementDAOException(msg);
|
||||||
|
}
|
||||||
|
deviceSubscriptionDTOHashMap.put(deviceSubscriptionDTO.getDeviceId(), deviceSubscriptionDTO);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -138,17 +138,17 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
.isEmpty(deviceIdentifier.getType())) {
|
.isEmpty(deviceIdentifier.getType())) {
|
||||||
log.warn("Found a device identifier which has either empty identity of the device or empty"
|
log.warn("Found a device identifier which has either empty identity of the device or empty"
|
||||||
+ " device type. Hence ignoring the device identifier. ");
|
+ " device type. Hence ignoring the device identifier. ");
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
|
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
|
||||||
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
|
||||||
if (!deviceType.getName().equals(deviceIdentifier.getType())) {
|
if (!deviceType.getName().equals(deviceIdentifier.getType())) {
|
||||||
String msg =
|
log.warn("Found a device identifier which is not matched with the supported device type "
|
||||||
"Found a device identifier which is not matched with the application device Type. "
|
+ "of the application release which has UUID " + applicationUUID + " Application "
|
||||||
+ "Application device type is " + deviceType.getName() + " and the "
|
+ "supported device type is " + deviceType.getName() + " and the "
|
||||||
+ "identifier of which has a " + "different device type is "
|
+ "identifier of which has a different device type is " + deviceIdentifier.getId());
|
||||||
+ deviceIdentifier.getId();
|
|
||||||
log.warn(msg);
|
|
||||||
errorDeviceIdentifiers.add(deviceIdentifier);
|
errorDeviceIdentifiers.add(deviceIdentifier);
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
|
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
|
||||||
@ -188,7 +188,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
applicationInstallResponse = performActionOnDevices(null, devices, applicationDTO, subType,
|
applicationInstallResponse = performActionOnDevices(null, devices, applicationDTO, subType,
|
||||||
subscribers, action);
|
subscribers, action);
|
||||||
}
|
}
|
||||||
applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers);
|
applicationInstallResponse.setErrorDeviceIdentifiers(errorDeviceIdentifiers);
|
||||||
return applicationInstallResponse;
|
return applicationInstallResponse;
|
||||||
} catch (DeviceManagementException e) {
|
} catch (DeviceManagementException e) {
|
||||||
String msg = "Error occurred while getting devices of given users or given roles.";
|
String msg = "Error occurred while getting devices of given users or given roles.";
|
||||||
@ -400,21 +400,23 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
entry.getKey(), action);
|
entry.getKey(), action);
|
||||||
activityList.add(activity);
|
activityList.add(activity);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (applicationDTO.getType().equals(ApplicationType.PUBLIC.toString())) {
|
||||||
if (applicationDTO.getType().equals(ApplicationType.PUBLIC.toString())) {
|
List<String> categories = getApplicationCategories(applicationDTO.getId());
|
||||||
List<String> categories = getApplicationCategories(applicationDTO.getId());
|
if (categories.contains("GooglePlaySyncedApp")) {
|
||||||
if (categories.contains("GooglePlaySyncedApp")) {
|
ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO();
|
||||||
ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO();
|
applicationPolicyDTO.setApplicationDTO(applicationDTO);
|
||||||
applicationPolicyDTO.setApplicationDTO(applicationDTO);
|
applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers);
|
||||||
applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers);
|
applicationPolicyDTO.setAction(action);
|
||||||
applicationPolicyDTO.setAction(action);
|
installEnrollmentApplications(applicationPolicyDTO);
|
||||||
installEnrollmentApplications(applicationPolicyDTO);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action);
|
Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action);
|
||||||
activityList.add(activity);
|
activityList.add(activity);
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action);
|
||||||
|
activityList.add(activity);
|
||||||
}
|
}
|
||||||
|
|
||||||
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
|
||||||
applicationInstallResponse.setActivities(activityList);
|
applicationInstallResponse.setActivities(activityList);
|
||||||
applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers);
|
applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers);
|
||||||
@ -600,16 +602,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private List<Integer> getOperationAddedDeviceIds(Activity activity, Map<DeviceIdentifier, Integer> deviceMap) {
|
private List<Integer> getOperationAddedDeviceIds(Activity activity, Map<DeviceIdentifier, Integer> deviceMap) {
|
||||||
List<Integer> deviceIds = new ArrayList<>();
|
|
||||||
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
|
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
|
||||||
for (ActivityStatus status : activityStatuses) {
|
return activityStatuses.stream().map(status -> deviceMap.get(status.getDeviceIdentifier()))
|
||||||
if (status.getStatus().equals(ActivityStatus.Status.PENDING)) {
|
.collect(Collectors.toList());
|
||||||
deviceIds.add(deviceMap.get(status.getDeviceIdentifier()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return deviceIds;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is responsible to get device subscription of particular application releasee for given set of devices.
|
||||||
|
*
|
||||||
|
* @param deviceIds Set of device Ids
|
||||||
|
* @param appReleaseId Application release Id
|
||||||
|
* @return {@link HashMap} with key as device id and value as {@link DeviceSubscriptionDTO}
|
||||||
|
* @throws ApplicationManagementException if error occured while executing SQL query or if more than one data found
|
||||||
|
* for a device id.
|
||||||
|
*/
|
||||||
private Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int appReleaseId)
|
private Map<Integer, DeviceSubscriptionDTO> getDeviceSubscriptions(List<Integer> deviceIds, int appReleaseId)
|
||||||
throws ApplicationManagementException {
|
throws ApplicationManagementException {
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
|||||||
@ -34,7 +34,6 @@ import org.wso2.carbon.device.application.mgt.common.BasicUserInfoList;
|
|||||||
import org.wso2.carbon.device.application.mgt.common.RoleList;
|
import org.wso2.carbon.device.application.mgt.common.RoleList;
|
||||||
import org.wso2.carbon.device.application.mgt.common.DeviceGroupList;
|
import org.wso2.carbon.device.application.mgt.common.DeviceGroupList;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.application.mgt.common.SubscriptionType;
|
|
||||||
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
|
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
|
||||||
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
|
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
|
||||||
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
|
||||||
|
|||||||
@ -19,5 +19,5 @@
|
|||||||
package org.wso2.carbon.device.mgt.common.app.mgt;
|
package org.wso2.carbon.device.mgt.common.app.mgt;
|
||||||
|
|
||||||
public enum MobileAppTypes {
|
public enum MobileAppTypes {
|
||||||
ENTERPRISE,WEBAPP,PUBLIC
|
ENTERPRISE,WEBAPP,PUBLIC,WEB_CLIP
|
||||||
}
|
}
|
||||||
|
|||||||
@ -61,6 +61,7 @@ public class MDMAndroidOperationUtil {
|
|||||||
operation.setPayLoad(appStoreApplication.toJSON());
|
operation.setPayLoad(appStoreApplication.toJSON());
|
||||||
break;
|
break;
|
||||||
case WEBAPP:
|
case WEBAPP:
|
||||||
|
case WEB_CLIP:
|
||||||
WebApplication webApplication = new WebApplication();
|
WebApplication webApplication = new WebApplication();
|
||||||
webApplication.setUrl(application.getLocation());
|
webApplication.setUrl(application.getLocation());
|
||||||
webApplication.setName(application.getName());
|
webApplication.setName(application.getName());
|
||||||
@ -101,6 +102,7 @@ public class MDMAndroidOperationUtil {
|
|||||||
operation.setPayLoad(appStoreApplication.toJSON());
|
operation.setPayLoad(appStoreApplication.toJSON());
|
||||||
break;
|
break;
|
||||||
case WEBAPP:
|
case WEBAPP:
|
||||||
|
case WEB_CLIP:
|
||||||
WebApplication webApplication = new WebApplication();
|
WebApplication webApplication = new WebApplication();
|
||||||
webApplication.setUrl(application.getLocation());
|
webApplication.setUrl(application.getLocation());
|
||||||
webApplication.setName(application.getName());
|
webApplication.setName(application.getName());
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user