From 71eae764ce2d0d23a594341a08b0ed8bbfce2d49 Mon Sep 17 00:00:00 2001 From: navodzoysa Date: Mon, 22 Jul 2024 02:07:16 +0530 Subject: [PATCH] Fix stream corrupted exception for profile type operations --- .../mgt/api/jaxrs/beans/ApplicationUninstallation.java | 5 +++++ .../service/impl/DeviceManagementServiceImpl.java | 10 +++++----- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/ApplicationUninstallation.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/ApplicationUninstallation.java index f78d15966e..eee5f06c49 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/ApplicationUninstallation.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/beans/ApplicationUninstallation.java @@ -18,6 +18,7 @@ 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.ApiModelProperty; @@ -113,4 +114,8 @@ public class ApplicationUninstallation { public void setType(String type) { this.type = type; } + + public String toJson() { + return new Gson().toJson(this); + } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java index b514277817..88cfe125ca 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -19,7 +19,6 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl; 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.SubscriptionType; 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.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.MobileAppTypes; 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.device.details.DeviceData; @@ -1112,7 +1112,6 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { @QueryParam("version") String version, @QueryParam("user") String user) { List deviceIdentifiers = new ArrayList<>(); - Operation operation = new Operation(); try { RequestValidationUtil.validateDeviceIdentifier(type, id); Device device = DeviceMgtAPIUtils.getDeviceManagementService().getDevice(id, false); @@ -1133,11 +1132,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { //if the applications not installed via entgra store } else { if (Constants.ANDROID.equals(type)) { - ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(packageName, "PUBLIC", name, platform, version, user); - Gson gson = new Gson(); + ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(packageName, + MobileAppTypes.PUBLIC.toString(), name, platform, version, user); + ProfileOperation operation = new ProfileOperation(); operation.setCode(MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL); operation.setType(Operation.Type.PROFILE); - operation.setPayLoad(gson.toJson(applicationUninstallation)); + operation.setPayLoad(applicationUninstallation.toJson()); DeviceManagementProviderService deviceManagementProviderService = HelperUtil .getDeviceManagementProviderService(); Activity activity = deviceManagementProviderService.addOperation( -- 2.36.3