Update activity loading

Bug#10300
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 {
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);
}
}
}

@ -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> 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 {
List<VppUserDTO> vppUserDTOS = loadVppUsers(rs);
if (vppUserDTOS.isEmpty()) {

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

Loading…
Cancel
Save