Fix stream corrupted exception for profile type operations

issue-10462/secure-pending-operation-6.2
Lasantha Dharmakeerthi 4 months ago
commit ac9c7b1a38

@ -18,6 +18,7 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans; package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
import com.google.gson.Gson;
import io.swagger.annotations.ApiModel; import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty; import io.swagger.annotations.ApiModelProperty;
@ -113,4 +114,8 @@ public class ApplicationUninstallation {
public void setType(String type) { public void setType(String type) {
this.type = type; this.type = type;
} }
public String toJson() {
return new Gson().toJson(this);
}
} }

@ -19,7 +19,6 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl; package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse; import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType; import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException; import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
@ -44,6 +43,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.*; import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.MobileAppTypes;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationException; import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationService; import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceData; import io.entgra.device.mgt.core.device.mgt.common.device.details.DeviceData;
@ -1112,7 +1112,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@QueryParam("version") String version, @QueryParam("version") String version,
@QueryParam("user") String user) { @QueryParam("user") String user) {
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>(); List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
Operation operation = new Operation();
try { try {
RequestValidationUtil.validateDeviceIdentifier(type, id); RequestValidationUtil.validateDeviceIdentifier(type, id);
Device device = DeviceMgtAPIUtils.getDeviceManagementService().getDevice(id, false); Device device = DeviceMgtAPIUtils.getDeviceManagementService().getDevice(id, false);
@ -1133,11 +1132,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
//if the applications not installed via entgra store //if the applications not installed via entgra store
} else { } else {
if (Constants.ANDROID.equals(type)) { if (Constants.ANDROID.equals(type)) {
ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(packageName, "PUBLIC", name, platform, version, user); ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(packageName,
Gson gson = new Gson(); MobileAppTypes.PUBLIC.toString(), name, platform, version, user);
ProfileOperation operation = new ProfileOperation();
operation.setCode(MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL); operation.setCode(MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL);
operation.setType(Operation.Type.PROFILE); operation.setType(Operation.Type.PROFILE);
operation.setPayLoad(gson.toJson(applicationUninstallation)); operation.setPayLoad(applicationUninstallation.toJson());
DeviceManagementProviderService deviceManagementProviderService = HelperUtil DeviceManagementProviderService deviceManagementProviderService = HelperUtil
.getDeviceManagementProviderService(); .getDeviceManagementProviderService();
Activity activity = deviceManagementProviderService.addOperation( Activity activity = deviceManagementProviderService.addOperation(

Loading…
Cancel
Save