Update activity loading

revert
osh 1 year ago
parent 9fa34a32af
commit e2a467bc45

@ -1438,7 +1438,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
public Activity getOperationAppDetails(int operationId, int tenantId) throws ApplicationManagementDAOException { public Activity getOperationAppDetails(int operationId, int tenantId) throws ApplicationManagementDAOException {
Activity activity = null;
try { try {
String sql = "SELECT " String sql = "SELECT "
+ "AP.NAME, " + "AP.NAME, "
@ -1456,18 +1455,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setInt(2,tenantId); stmt.setInt(2,tenantId);
try (ResultSet rs = stmt.executeQuery()) { try (ResultSet rs = stmt.executeQuery()) {
if (log.isDebugEnabled()) { return DAOUtil.loadOperationActivity(rs);
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) { } 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; String msg = "Error occurred when processing SQL to retrieve app details of operation" + operationId;
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementDAOException(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);
} }
} }
} }

@ -21,6 +21,7 @@ import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import io.entgra.device.mgt.core.application.mgt.common.dto.*; 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.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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
@ -361,6 +362,32 @@ public class DAOUtil {
return subscriptionDTOS; return subscriptionDTOS;
} }
public static Activity loadOperationActivity(ResultSet rs) throws SQLException, UnexpectedServerErrorException {
List<Activity> 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<Activity> loadOperationActivities (ResultSet rs) throws SQLException {
List<Activity> 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 { public static VppUserDTO loadVppUser(ResultSet rs) throws SQLException, UnexpectedServerErrorException {
List<VppUserDTO> vppUserDTOS = loadVppUsers(rs); List<VppUserDTO> vppUserDTOS = loadVppUsers(rs);
if (vppUserDTOS.isEmpty()) { if (vppUserDTOS.isEmpty()) {

@ -169,10 +169,16 @@ public class ActivityProviderServiceImpl implements ActivityInfoProviderService
} }
SubscriptionManager subscriptionManager = DeviceMgtAPIUtils.getSubscriptionManager(); SubscriptionManager subscriptionManager = DeviceMgtAPIUtils.getSubscriptionManager();
appActivity = subscriptionManager.getOperationAppDetails(id); appActivity = subscriptionManager.getOperationAppDetails(id);
if (appActivity != null) {
activity.setUsername(appActivity.getUsername()); activity.setUsername(appActivity.getUsername());
activity.setPackageName(appActivity.getPackageName()); activity.setPackageName(appActivity.getPackageName());
activity.setAppName(appActivity.getAppName()); activity.setAppName(appActivity.getAppName());
activity.setStatus(appActivity.getStatus()); 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 { } else {
activity = dmService.getOperationByActivityIdAndDevice(id, deviceIdentifier); activity = dmService.getOperationByActivityIdAndDevice(id, deviceIdentifier);
} }

Loading…
Cancel
Save