From e6ee539239ed9d625120d3fe8af358b72896758b Mon Sep 17 00:00:00 2001 From: osh Date: Wed, 9 Aug 2023 00:27:33 +0530 Subject: [PATCH 1/4] Add api changes for getting app details of operation --- .../common/services/SubscriptionManager.java | 10 ++++ .../mgt/core/dao/SubscriptionDAO.java | 12 +++++ .../GenericSubscriptionDAOImpl.java | 46 +++++++++++++++++++ .../core/impl/SubscriptionManagerImpl.java | 26 +++++++++++ .../api/ActivityInfoProviderService.java | 12 ++++- .../impl/ActivityProviderServiceImpl.java | 29 ++++++++++-- .../impl/ActivityProviderServiceImplTest.java | 2 +- .../mgt/common/operation/mgt/Activity.java | 46 +++++++++++++++++++ 8 files changed, 178 insertions(+), 5 deletions(-) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java index f2bd759fd7..e06a17cb9b 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/SubscriptionManager.java @@ -27,6 +27,7 @@ import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App; +import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity; import java.util.List; import java.util.Properties; @@ -207,4 +208,13 @@ public interface SubscriptionManager { */ PaginationResult getAppInstalledSubscribeDevices(PaginationRequest request, String appUUID, String subType, String subTypeName) throws ApplicationManagementException; + + + /*** + * This method is responsible for retrieving application details of the passed operation id. + * @param id ID of the related operation + * @return {@link Activity} Activity result of the app information. + * @throws {@link SubscriptionManagementException} Exception of the subscription management + */ + Activity getOperationAppDetails(String id) throws SubscriptionManagementException; } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java index 8b5caec6ac..804a4a29e2 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/SubscriptionDAO.java @@ -23,6 +23,7 @@ import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDT import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO; import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException; import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException; +import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity; import java.util.List; import java.util.Map; @@ -252,4 +253,15 @@ public interface SubscriptionDAO { * @throws {@link ApplicationManagementDAOException} if connections establishment fails. */ Map getCurrentInstalledAppVersion(int appId, List deviceIdList, String installedVersion) throws ApplicationManagementDAOException; + + + /** + * Retrieves app details by operation id. + * + * @param operationId ID of the operation which app details needs to be retrieved + * @param tenantId ID of tenant + * @return {@link Activity} + * @throws ApplicationManagementDAOException if error occurred while retrieving the app details + */ + Activity getOperationAppDetails(int operationId, int tenantId) throws ApplicationManagementDAOException; } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 353340e3d3..373ade8595 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -21,6 +21,7 @@ import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO; import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl; import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException; import io.entgra.device.mgt.core.application.mgt.core.util.DAOUtil; +import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus; @@ -1435,4 +1436,49 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc throw new ApplicationManagementDAOException(msg, e); } } + + public Activity getOperationAppDetails(int operationId, int tenantId) throws ApplicationManagementDAOException { + Activity activity = null; + try { + String sql = "SELECT " + + "AP.NAME, " + + "AR.PACKAGE_NAME, " + + "DS.SUBSCRIBED_BY, " + + "DS.STATUS " + + "FROM AP_APP_SUB_OP_MAPPING SOP " + + "JOIN AP_DEVICE_SUBSCRIPTION DS ON SOP.AP_DEVICE_SUBSCRIPTION_ID = DS.ID " + + "JOIN AP_APP_RELEASE AR ON DS.AP_APP_RELEASE_ID = AR.ID " + + "JOIN AP_APP AP ON AP.ID = AR.AP_APP_ID " + + " WHERE SOP.OPERATION_ID = ? AND SOP.TENANT_ID = ?"; + + Connection conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, operationId); + stmt.setInt(2,tenantId); + try (ResultSet rs = stmt.executeQuery()) { + if (log.isDebugEnabled()) { + log.debug("Successfully retrieved app details for operation " + + operationId); + } + while (rs.next()) { + activity = new Activity(); + activity.setAppName(rs.getString("NAME")); + activity.setUsername(rs.getString("SUBSCRIBED_BY")); + activity.setPackageName(rs.getString("PACKAGE_NAME")); + activity.setStatus(rs.getString("STATUS")); + } + return activity; + } + } + } catch (DBConnectionException e) { + String msg = + "Error occurred while getting the app details from the database related to operation " + operationId; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred when processing SQL to retrieve app details of operation" + operationId; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java index d89039dee5..0829906682 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.application.mgt.core.impl; import com.google.gson.Gson; import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException; +import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants; import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext; import io.entgra.device.mgt.core.notification.logger.impl.EntgraAppInstallLoggerImpl; @@ -1568,4 +1569,29 @@ public class SubscriptionManagerImpl implements SubscriptionManager { ConnectionManagerUtil.closeDBConnection(); } } + + @Override + public Activity getOperationAppDetails(String id) throws SubscriptionManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); + int operationId = Integer.parseInt( + id.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "")); + if (operationId == 0) { + throw new IllegalArgumentException("Operation ID cannot be null or zero (0)."); + } + try { + ConnectionManagerUtil.openDBConnection(); + return subscriptionDAO.getOperationAppDetails(operationId, tenantId); + } catch (ApplicationManagementDAOException e) { + String msg = "Error occurred while retrieving app details of operation: " + operationId; + log.error(msg, e); + throw new SubscriptionManagementException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred while retrieving the database connection"; + log.error(msg, e); + throw new SubscriptionManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + } 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/ActivityInfoProviderService.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/ActivityInfoProviderService.java index 99b56d9fbe..23076328e4 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/ActivityInfoProviderService.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/ActivityInfoProviderService.java @@ -308,7 +308,17 @@ public interface ActivityInfoProviderService { "Provide the value in the Java Date Format: EEE, d MMM yyyy HH:mm:ss Z\n." + "Example: Mon, 05 Jan 2014 15:10:00 +0200", required = false) - @HeaderParam("If-Modified-Since") String ifModifiedSince); + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @ApiParam( + name = "response", + value = "The starting pagination index for the complete list of qualified items.", + required = false) + @QueryParam("response") Boolean response, + @ApiParam( + name = "appInstall", + value = "The starting pagination index for the complete list of qualified items.", + required = false) + @QueryParam("appInstall") Boolean appInstall); @GET @Path("/type/{operationCode}") 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/ActivityProviderServiceImpl.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/ActivityProviderServiceImpl.java index db2a8eab31..d4860d3dc3 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/ActivityProviderServiceImpl.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/ActivityProviderServiceImpl.java @@ -18,6 +18,8 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl; import com.google.gson.Gson; +import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException; +import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import io.entgra.device.mgt.core.device.mgt.common.ActivityPaginationRequest; @@ -146,8 +148,11 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService @Size(max = 45) String devicetype, @PathParam("deviceid") @Size(max = 45) String deviceid, - @HeaderParam("If-Modified-Since") String ifModifiedSince) { - Activity activity; + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @QueryParam("response") Boolean response, + @QueryParam("appInstall") Boolean appInstall) { + Activity activity = new Activity(); + Activity appActivity = null; DeviceManagementProviderService dmService; try { RequestValidationUtil.validateActivityId(id); @@ -157,7 +162,20 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService deviceIdentifier.setType(devicetype); dmService = DeviceMgtAPIUtils.getDeviceManagementService(); - activity = dmService.getOperationByActivityIdAndDevice(id, deviceIdentifier); + + if (appInstall != null && appInstall) { + if (response != null && response) { + activity = dmService.getOperationByActivityIdAndDevice(id, deviceIdentifier); + } + SubscriptionManager subscriptionManager = DeviceMgtAPIUtils.getSubscriptionManager(); + appActivity = subscriptionManager.getOperationAppDetails(id); + activity.setUsername(appActivity.getUsername()); + activity.setPackageName(appActivity.getPackageName()); + activity.setAppName(appActivity.getAppName()); + activity.setStatus(appActivity.getStatus()); + } else { + activity = dmService.getOperationByActivityIdAndDevice(id, deviceIdentifier); + } if (activity == null) { String msg = "No activity can be " + "found upon the provided activity id '" + id + "'"; @@ -169,6 +187,11 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } catch (SubscriptionManagementException e) { + String msg = "ErrorResponse occurred while fetching the app details for the supplied id."; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImplTest.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImplTest.java index f56c673495..0e3d23d705 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImplTest.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/test/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/ActivityProviderServiceImplTest.java @@ -206,7 +206,7 @@ public class ActivityProviderServiceImplTest { Mockito.when(this.deviceManagementProviderService .getOperationByActivityIdAndDevice(TEST_ACTIVITY_ID, deviceIdentifier)).thenReturn(activity); Response response = this.activityInfoProviderService.getActivityByDevice(TEST_ACTIVITY_ID, - DEVICE_TYPE, DEVICE_ID, IF_MODIFIED_SINCE); + DEVICE_TYPE, DEVICE_ID, IF_MODIFIED_SINCE, false, false); Assert.assertNotNull(response); Assert.assertEquals(response.getStatus(), Response.Status.OK.getStatusCode()); Mockito.reset(this.deviceManagementProviderService); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/operation/mgt/Activity.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/operation/mgt/Activity.java index 5a04185e0a..e9874778d9 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/operation/mgt/Activity.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/operation/mgt/Activity.java @@ -80,6 +80,20 @@ public class Activity { @JsonProperty("initiatedBy") private String initiatedBy; + @ApiModelProperty(name = "appName", value = "App Name.") + private String appName; + + @ApiModelProperty(name = "packageName", + value = "package name of the application") + private String packageName; + @ApiModelProperty(name = "username", + value = "username of subscribed person") + private String username; + @ApiModelProperty(name = "status", + value = "Status of app install") + private String status; + + public String getActivityId() { return activityId; } @@ -127,5 +141,37 @@ public class Activity { public void setInitiatedBy(String initiatedBy) { this.initiatedBy = initiatedBy; } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } } From e2a467bc455c7b960a7f244bdffc0529b9628d1d Mon Sep 17 00:00:00 2001 From: osh Date: Wed, 9 Aug 2023 15:03:29 +0530 Subject: [PATCH 2/4] Update activity loading --- .../GenericSubscriptionDAOImpl.java | 18 ++++--------- .../application/mgt/core/util/DAOUtil.java | 27 +++++++++++++++++++ .../impl/ActivityProviderServiceImpl.java | 14 +++++++--- 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 373ade8595..429ecc1e35 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -1438,7 +1438,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc } public Activity getOperationAppDetails(int operationId, int tenantId) throws ApplicationManagementDAOException { - Activity activity = null; try { String sql = "SELECT " + "AP.NAME, " @@ -1456,18 +1455,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc stmt.setInt(1, operationId); stmt.setInt(2,tenantId); try (ResultSet rs = stmt.executeQuery()) { - if (log.isDebugEnabled()) { - log.debug("Successfully retrieved app details for operation " - + operationId); - } - while (rs.next()) { - activity = new Activity(); - activity.setAppName(rs.getString("NAME")); - activity.setUsername(rs.getString("SUBSCRIBED_BY")); - activity.setPackageName(rs.getString("PACKAGE_NAME")); - activity.setStatus(rs.getString("STATUS")); - } - return activity; + return DAOUtil.loadOperationActivity(rs); } } } catch (DBConnectionException e) { @@ -1479,6 +1467,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc String msg = "Error occurred when processing SQL to retrieve app details of operation" + operationId; log.error(msg, e); throw new ApplicationManagementDAOException(msg, e); + } catch (UnexpectedServerErrorException e) { + String msg = "More than one app for operation " + operationId; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); } } } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java index 08ebe3b60d..ede8d7ff6d 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java @@ -21,6 +21,7 @@ import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; import io.entgra.device.mgt.core.application.mgt.common.dto.*; import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException; +import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; @@ -361,6 +362,32 @@ public class DAOUtil { return subscriptionDTOS; } + public static Activity loadOperationActivity(ResultSet rs) throws SQLException, UnexpectedServerErrorException { + List activity = loadOperationActivities(rs); + if (activity.isEmpty()) { + return null; + } + if (activity.size() > 1) { + String msg = "Internal server error. Found more than one app for operation"; + log.error(msg); + throw new UnexpectedServerErrorException(msg); + } + return activity.get(0); + } + + public static List loadOperationActivities (ResultSet rs) throws SQLException { + List activities = new ArrayList<>(); + while (rs.next()) { + Activity activity = new Activity(); + activity.setAppName(rs.getString("NAME")); + activity.setUsername(rs.getString("SUBSCRIBED_BY")); + activity.setPackageName(rs.getString("PACKAGE_NAME")); + activity.setStatus(rs.getString("STATUS")); + activities.add(activity); + } + return activities; + } + public static VppUserDTO loadVppUser(ResultSet rs) throws SQLException, UnexpectedServerErrorException { List vppUserDTOS = loadVppUsers(rs); if (vppUserDTOS.isEmpty()) { 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/ActivityProviderServiceImpl.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/ActivityProviderServiceImpl.java index d4860d3dc3..60272d589f 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/ActivityProviderServiceImpl.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/ActivityProviderServiceImpl.java @@ -169,10 +169,16 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService } SubscriptionManager subscriptionManager = DeviceMgtAPIUtils.getSubscriptionManager(); appActivity = subscriptionManager.getOperationAppDetails(id); - activity.setUsername(appActivity.getUsername()); - activity.setPackageName(appActivity.getPackageName()); - activity.setAppName(appActivity.getAppName()); - activity.setStatus(appActivity.getStatus()); + if (appActivity != null) { + activity.setUsername(appActivity.getUsername()); + activity.setPackageName(appActivity.getPackageName()); + activity.setAppName(appActivity.getAppName()); + activity.setStatus(appActivity.getStatus()); + } else { + String msg = "Cannot find the app details related to the operation "; + log.error(msg); + Response.status(404).entity(msg).build(); + } } else { activity = dmService.getOperationByActivityIdAndDevice(id, deviceIdentifier); } From 81e57ce78fd26d3fc83ec755c1850cb176353cd4 Mon Sep 17 00:00:00 2001 From: osh Date: Thu, 10 Aug 2023 13:01:41 +0530 Subject: [PATCH 3/4] Retrieve extra details --- .../GenericSubscriptionDAOImpl.java | 5 ++- .../application/mgt/core/util/DAOUtil.java | 3 ++ .../impl/ActivityProviderServiceImpl.java | 3 ++ .../mgt/common/operation/mgt/Activity.java | 36 +++++++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java index 429ecc1e35..457de13bee 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/dao/impl/subscription/GenericSubscriptionDAOImpl.java @@ -1441,9 +1441,12 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc try { String sql = "SELECT " + "AP.NAME, " + + "AP.TYPE, " + "AR.PACKAGE_NAME, " + + "AR.VERSION, " + "DS.SUBSCRIBED_BY, " - + "DS.STATUS " + + "DS.STATUS, " + + "DS.ACTION_TRIGGERED_FROM " + "FROM AP_APP_SUB_OP_MAPPING SOP " + "JOIN AP_DEVICE_SUBSCRIPTION DS ON SOP.AP_DEVICE_SUBSCRIPTION_ID = DS.ID " + "JOIN AP_APP_RELEASE AR ON DS.AP_APP_RELEASE_ID = AR.ID " diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java index ede8d7ff6d..a41f48e1e9 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/DAOUtil.java @@ -380,9 +380,12 @@ public class DAOUtil { while (rs.next()) { Activity activity = new Activity(); activity.setAppName(rs.getString("NAME")); + activity.setAppType(rs.getString("TYPE")); activity.setUsername(rs.getString("SUBSCRIBED_BY")); activity.setPackageName(rs.getString("PACKAGE_NAME")); activity.setStatus(rs.getString("STATUS")); + activity.setVersion(rs.getString("VERSION")); + activity.setTriggeredBy(rs.getString("ACTION_TRIGGERED_FROM")); activities.add(activity); } return activities; 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/ActivityProviderServiceImpl.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/ActivityProviderServiceImpl.java index 60272d589f..d9fec4b91b 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/ActivityProviderServiceImpl.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/ActivityProviderServiceImpl.java @@ -174,6 +174,9 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService activity.setPackageName(appActivity.getPackageName()); activity.setAppName(appActivity.getAppName()); activity.setStatus(appActivity.getStatus()); + activity.setAppType(appActivity.getAppType()); + activity.setVersion(appActivity.getVersion()); + activity.setTriggeredBy(appActivity.getTriggeredBy()); } else { String msg = "Cannot find the app details related to the operation "; log.error(msg); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/operation/mgt/Activity.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/operation/mgt/Activity.java index e9874778d9..e001d72929 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/operation/mgt/Activity.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/operation/mgt/Activity.java @@ -93,6 +93,18 @@ public class Activity { value = "Status of app install") private String status; + @ApiModelProperty(name = "version", + value = "Version of app") + private String version; + + @ApiModelProperty(name = "triggeredBy", + value = "Operation triggered by what") + private String triggeredBy; + + @ApiModelProperty(name = "appType", + value = "Type of application") + private String appType; + public String getActivityId() { return activityId; @@ -173,5 +185,29 @@ public class Activity { public void setStatus(String status) { this.status = status; } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + + public String getTriggeredBy() { + return triggeredBy; + } + + public void setTriggeredBy(String triggeredBy) { + this.triggeredBy = triggeredBy; + } + + public String getAppType() { + return appType; + } + + public void setAppType(String appType) { + this.appType = appType; + } } From 74d4e2dded9aee97ef5179a3320f30a26cd57d0b Mon Sep 17 00:00:00 2001 From: osh Date: Thu, 10 Aug 2023 13:12:19 +0530 Subject: [PATCH 4/4] Add vpp scopes --- .../src/main/resources/conf/mdm-ui-config.xml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index 4e7b97fc6e..30c9e55f57 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -241,6 +241,10 @@ perm:ios:app-configurations perm:mac-os:restart perm:mac-os:shut-down + perm:app:vpp:user:modify + perm:app:vpp:user:view + perm:app:vpp:asset:modify + perm:app:vpp:asset:view device-mgt