From 1fed47e8fd694445a505cc7abfccc026aa71cd4c Mon Sep 17 00:00:00 2001 From: osh Date: Mon, 21 Aug 2023 23:27:58 +0530 Subject: [PATCH 1/2] Add app details for UNMANAGED_APP_UNINSTALL --- .../beans/ApplicationUninstallation.java | 49 +++++++++++++++++++ .../service/api/DeviceManagementService.java | 26 +++++++++- .../impl/DeviceManagementServiceImpl.java | 8 ++- .../mgt/dao/impl/GenericOperationDAOImpl.java | 34 +++++++++++++ 4 files changed, 114 insertions(+), 3 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 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..7411f93c5a 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,9 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList<>(); String createdTo = null; String createdFrom = null; + ByteArrayInputStream bais; + ObjectInputStream ois; + 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 +1382,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,10 +1481,21 @@ 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"); + bais = new ByteArrayInputStream(operationDetails); + ois = new ObjectInputStream(bais); + profileOperation = (ProfileOperation) ois.readObject(); + operation.setPayLoad(profileOperation.getPayLoad()); + } operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation); } + } catch (IOException e) { + throw new OperationManagementDAOException("IO Error occurred while retrieving app data of operation ", e); + } catch (ClassNotFoundException e) { + throw new OperationManagementDAOException("Class not found error occurred while retrieving app data of operation ", e); } } } catch (SQLException e) { @@ -1493,6 +1512,9 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList<>(); String createdTo = null; String createdFrom = null; + ByteArrayInputStream bais; + ObjectInputStream ois; + 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 +1537,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,10 +1636,21 @@ 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"); + bais = new ByteArrayInputStream(operationDetails); + ois = new ObjectInputStream(bais); + profileOperation = (ProfileOperation) ois.readObject(); + operation.setPayLoad(profileOperation.getPayLoad()); + } operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS"))); OperationDAOUtil.setActivityId(operation, rs.getInt("ID")); operations.add(operation); } + } catch (IOException e) { + throw new OperationManagementDAOException("IO Error occurred while retrieving app data of operation " , e); + } catch (ClassNotFoundException e) { + throw new OperationManagementDAOException("Class not found error occurred while retrieving app data of operation ", e); } } } catch (SQLException e) { From 195bb64beafe347c6280d8715f074b4f29291949 Mon Sep 17 00:00:00 2001 From: osh Date: Wed, 23 Aug 2023 12:42:57 +0530 Subject: [PATCH 2/2] Resolve comments --- .../mgt/dao/impl/GenericOperationDAOImpl.java | 46 +++++++++++-------- 1 file changed, 26 insertions(+), 20 deletions(-) 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 7411f93c5a..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 @@ -1357,8 +1357,6 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList<>(); String createdTo = null; String createdFrom = null; - ByteArrayInputStream bais; - ObjectInputStream ois; ProfileOperation profileOperation = null; DateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); boolean isCreatedDayProvided = false; @@ -1483,19 +1481,24 @@ public class GenericOperationDAOImpl implements OperationDAO { operation.setInitiatedBy(rs.getString("INITIATED_BY")); if (MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL.equals(operation.getCode())) { byte[] operationDetails = rs.getBytes("OPERATION_DETAILS"); - bais = new ByteArrayInputStream(operationDetails); - ois = new ObjectInputStream(bais); - profileOperation = (ProfileOperation) ois.readObject(); - operation.setPayLoad(profileOperation.getPayLoad()); + 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); } - } catch (IOException e) { - throw new OperationManagementDAOException("IO Error occurred while retrieving app data of operation ", e); - } catch (ClassNotFoundException e) { - throw new OperationManagementDAOException("Class not found error occurred while retrieving app data of operation ", e); } } } catch (SQLException e) { @@ -1512,8 +1515,6 @@ public class GenericOperationDAOImpl implements OperationDAO { List operations = new ArrayList<>(); String createdTo = null; String createdFrom = null; - ByteArrayInputStream bais; - ObjectInputStream ois; ProfileOperation profileOperation = null; DateFormat simple = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS"); boolean isCreatedDayProvided = false; @@ -1638,19 +1639,24 @@ public class GenericOperationDAOImpl implements OperationDAO { operation.setInitiatedBy(rs.getString("INITIATED_BY")); if (MDMAppConstants.AndroidConstants.UNMANAGED_APP_UNINSTALL.equals(operation.getCode())) { byte[] operationDetails = rs.getBytes("OPERATION_DETAILS"); - bais = new ByteArrayInputStream(operationDetails); - ois = new ObjectInputStream(bais); - profileOperation = (ProfileOperation) ois.readObject(); - operation.setPayLoad(profileOperation.getPayLoad()); + 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); } - } catch (IOException e) { - throw new OperationManagementDAOException("IO Error occurred while retrieving app data of operation " , e); - } catch (ClassNotFoundException e) { - throw new OperationManagementDAOException("Class not found error occurred while retrieving app data of operation ", e); } } } catch (SQLException e) {