Add api changes for getting app details of operation

revert
osh 1 year ago
parent b11c932814
commit e6ee539239

@ -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;
}

@ -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<Integer,String> getCurrentInstalledAppVersion(int appId, List<Integer> 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;
}

@ -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);
}
}
}

@ -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();
}
}
}

@ -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}")

@ -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();
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();
}
}

@ -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);

@ -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;
}
}

Loading…
Cancel
Save