Merge branch 'application-mgt-new' into 'application-mgt-new'

Improve APPM subscribing functionality

See merge request entgra/carbon-device-mgt!323
feature/appm-store/pbac
Dharmakeerthi Lasantha 5 years ago
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 .",
dataType = "List[org.wso2.carbon.device.mgt.common.DeviceIdentifier]"
)
private List<DeviceIdentifier> errorDevices;
private List<DeviceIdentifier> errorDeviceIdentifiers;
@ApiModelProperty(
@ -61,7 +61,7 @@ public class ApplicationInstallResponse {
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()){
List<Integer> updatedDeviceSubIds = new ArrayList<>();
while (rs.next()) {
updatedDeviceSubIds.add(rs.getInt(1));
updatedDeviceSubIds.add(rs.getInt("ID"));
}
return updatedDeviceSubIds;
}
@ -402,7 +402,13 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
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())) {
log.warn("Found a device identifier which has either empty identity of the device or empty"
+ " device type. Hence ignoring the device identifier. ");
continue;
}
if (!ApplicationType.WEB_CLIP.toString().equals(applicationDTO.getType())) {
DeviceType deviceType = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
if (!deviceType.getName().equals(deviceIdentifier.getType())) {
String msg =
"Found a device identifier which is not matched with the application device Type. "
+ "Application device type is " + deviceType.getName() + " and the "
+ "identifier of which has a " + "different device type is "
+ deviceIdentifier.getId();
log.warn(msg);
log.warn("Found a device identifier which is not matched with the supported device type "
+ "of the application release which has UUID " + applicationUUID + " Application "
+ "supported device type is " + deviceType.getName() + " and the "
+ "identifier of which has a different device type is " + deviceIdentifier.getId());
errorDeviceIdentifiers.add(deviceIdentifier);
continue;
}
}
devices.add(deviceManagementProviderService.getDevice(deviceIdentifier, false));
@ -188,7 +188,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
applicationInstallResponse = performActionOnDevices(null, devices, applicationDTO, subType,
subscribers, action);
}
applicationInstallResponse.setErrorDevices(errorDeviceIdentifiers);
applicationInstallResponse.setErrorDeviceIdentifiers(errorDeviceIdentifiers);
return applicationInstallResponse;
} catch (DeviceManagementException e) {
String msg = "Error occurred while getting devices of given users or given roles.";
@ -400,8 +400,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
entry.getKey(), action);
activityList.add(activity);
}
} else {
if (applicationDTO.getType().equals(ApplicationType.PUBLIC.toString())) {
} else if (applicationDTO.getType().equals(ApplicationType.PUBLIC.toString())) {
List<String> categories = getApplicationCategories(applicationDTO.getId());
if (categories.contains("GooglePlaySyncedApp")) {
ApplicationPolicyDTO applicationPolicyDTO = new ApplicationPolicyDTO();
@ -409,12 +408,15 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
applicationPolicyDTO.setDeviceIdentifierList(deviceIdentifiers);
applicationPolicyDTO.setAction(action);
installEnrollmentApplications(applicationPolicyDTO);
}
} else {
Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action);
activityList.add(activity);
}
} else {
Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action);
activityList.add(activity);
}
ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse();
applicationInstallResponse.setActivities(activityList);
applicationInstallResponse.setIgnoredDeviceIdentifiers(ignoredDeviceIdentifiers);
@ -600,16 +602,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
private List<Integer> getOperationAddedDeviceIds(Activity activity, Map<DeviceIdentifier, Integer> deviceMap) {
List<Integer> deviceIds = new ArrayList<>();
List<ActivityStatus> activityStatuses = activity.getActivityStatus();
for (ActivityStatus status : activityStatuses) {
if (status.getStatus().equals(ActivityStatus.Status.PENDING)) {
deviceIds.add(deviceMap.get(status.getDeviceIdentifier()));
}
}
return deviceIds;
return activityStatuses.stream().map(status -> deviceMap.get(status.getDeviceIdentifier()))
.collect(Collectors.toList());
}
/**
* 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)
throws ApplicationManagementException {
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.DeviceGroupList;
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.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;

@ -19,5 +19,5 @@
package org.wso2.carbon.device.mgt.common.app.mgt;
public enum MobileAppTypes {
ENTERPRISE,WEBAPP,PUBLIC
ENTERPRISE,WEBAPP,PUBLIC,WEB_CLIP
}

@ -61,6 +61,7 @@ public class MDMAndroidOperationUtil {
operation.setPayLoad(appStoreApplication.toJSON());
break;
case WEBAPP:
case WEB_CLIP:
WebApplication webApplication = new WebApplication();
webApplication.setUrl(application.getLocation());
webApplication.setName(application.getName());
@ -101,6 +102,7 @@ public class MDMAndroidOperationUtil {
operation.setPayLoad(appStoreApplication.toJSON());
break;
case WEBAPP:
case WEB_CLIP:
WebApplication webApplication = new WebApplication();
webApplication.setUrl(application.getLocation());
webApplication.setName(application.getName());

Loading…
Cancel
Save