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 a38ae2982d..f78d15966e 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 @@ -41,6 +41,14 @@ public class ApplicationUninstallation { @Pattern(regexp = "^[A-Za-z]*$") String type; + String name; + + String platform; + + String version; + + String user; + public ApplicationUninstallation() { } @@ -49,6 +57,47 @@ public class ApplicationUninstallation { this.type = type; } + public ApplicationUninstallation(String appIdentifier, String type, String name, String platform, String version, String user) { + this.appIdentifier = appIdentifier; + this.type = type; + this.name = name; + this.platform = platform; + this.version = version; + this.user = user; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPlatform() { + return platform; + } + + public void setPlatform(String platform) { + this.platform = platform; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + public String getAppIdentifier() { return appIdentifier; } 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/api/DeviceManagementService.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/api/DeviceManagementService.java index 53f7fd9360..bb5349da68 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/api/DeviceManagementService.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/api/DeviceManagementService.java @@ -1657,7 +1657,31 @@ public interface DeviceManagementService { value = "The package name of the app user want to uninstall", required = true) @QueryParam("packageName") - String packageName); + String packageName, + @ApiParam( + name = "platform", + value = "The platform of the app user want to uninstall", + required = false) + @QueryParam("platform") + String platform, + @ApiParam( + name = "name", + value = "The name of the app user want to uninstall", + required = false) + @QueryParam("name") + String name, + @ApiParam( + name = "version", + value = "The version of the app user want to uninstall", + required = false) + @QueryParam("version") + String version, + @ApiParam( + name = "user", + value = "The user who triggered the app uninstall", + required = false) + @QueryParam("user") + String user); @GET @Produces(MediaType.APPLICATION_JSON) 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 b5851dff0c..2eaa0a5595 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 @@ -981,7 +981,11 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { public Response uninstallation( @PathParam("type") @Size(max = 45) String type, @PathParam("id") @Size(max = 45) String id, - @QueryParam("packageName") String packageName) { + @QueryParam("packageName") String packageName, + @QueryParam("platform") String platform, + @QueryParam("name") String name, + @QueryParam("version") String version, + @QueryParam("user") String user) { List deviceIdentifiers = new ArrayList<>(); Operation operation = new Operation(); try { @@ -1004,7 +1008,7 @@ 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"); + ApplicationUninstallation applicationUninstallation = new ApplicationUninstallation(packageName, "PUBLIC", name, platform, version, user); Gson gson = new Gson(); operation.setCode(MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL); operation.setType(Operation.Type.PROFILE); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java index 046556459a..164e50a8ec 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/dao/impl/GenericOperationDAOImpl.java @@ -17,6 +17,8 @@ */ package io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.impl; +import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants; +import io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.ProfileOperation; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; @@ -41,6 +43,8 @@ import io.entgra.device.mgt.core.device.mgt.core.operation.mgt.dao.util.Operatio import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectOutputStream; +import java.io.ObjectInputStream; +import java.io.ByteArrayInputStream; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -1353,6 +1357,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList<>(); String createdTo = null; String createdFrom = null; + ProfileOperation profileOperation = null; DateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); boolean isCreatedDayProvided = false; boolean isUpdatedDayProvided = false; //updated day = received day @@ -1375,6 +1380,7 @@ public class GenericOperationDAOImpl implements OperationDAO { "o.RECEIVED_TIMESTAMP, " + "o.OPERATION_CODE, " + "o.INITIATED_BY, " + + "o.OPERATION_DETAILS, " + "om.STATUS, " + "om.ID AS OM_MAPPING_ID, " + "om.UPDATED_TIMESTAMP " + @@ -1473,6 +1479,22 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setInitiatedBy(rs.getString("INITIATED_BY")); + if (MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL.equals(operation.getCode())) { + byte[] operationDetails = rs.getBytes("OPERATION_DETAILS"); + try (ByteArrayInputStream bais = new ByteArrayInputStream(operationDetails); + ObjectInputStream ois = new ObjectInputStream(bais)) { + profileOperation = (ProfileOperation) ois.readObject(); + operation.setPayLoad(profileOperation.getPayLoad()); + } catch (IOException e) { + String msg = "IO Error occurred while retrieving app data of operation "; + log.error(msg, e); + throw new OperationManagementDAOException(msg, e); + } catch (ClassNotFoundException e) { + String msg = "Class not found error occurred while retrieving app data of operation "; + log.error(msg, e); + throw new OperationManagementDAOException(msg, e); + } + } operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation); @@ -1493,6 +1515,7 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList<>(); String createdTo = null; String createdFrom = null; + ProfileOperation profileOperation = null; DateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); boolean isCreatedDayProvided = false; boolean isUpdatedDayProvided = false; //updated day = received day @@ -1515,6 +1538,7 @@ public class GenericOperationDAOImpl implements OperationDAO { "o.RECEIVED_TIMESTAMP, " + "o.OPERATION_CODE, " + "o.INITIATED_BY, " + + "o.OPERATION_DETAILS, " + "om.STATUS, " + "om.ID AS OM_MAPPING_ID, " + "om.UPDATED_TIMESTAMP " + @@ -1613,6 +1637,22 @@ public class GenericOperationDAOImpl implements OperationDAO { } operation.setCode(rs.getString("OPERATION_CODE")); operation.setInitiatedBy(rs.getString("INITIATED_BY")); + if (MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL.equals(operation.getCode())) { + byte[] operationDetails = rs.getBytes("OPERATION_DETAILS"); + try (ByteArrayInputStream bais = new ByteArrayInputStream(operationDetails); + ObjectInputStream ois = new ObjectInputStream(bais)) { + profileOperation = (ProfileOperation) ois.readObject(); + operation.setPayLoad(profileOperation.getPayLoad()); + } catch (IOException e) { + String msg = "IO Error occurred while retrieving app data of operation "; + log.error(msg, e); + throw new OperationManagementDAOException(msg, e); + } catch (ClassNotFoundException e) { + String msg = "Class not found error occurred while retrieving app data of operation "; + log.error(msg, e); + throw new OperationManagementDAOException(msg, e); + } + } operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation);