Merge branch 'feature/add-installed-version-to-subscription-details' into 'master'

Add installed version for installation details view

See merge request entgra/carbon-device-mgt!842
temp
Pahansith Gunathilake 3 years ago
commit f0cd2d91a2

@ -29,6 +29,7 @@ public class DeviceSubscriptionData {
private String actionType;
private String status;
private Device device;
private String currentInstalledVersion;
public String getAction() {
return action;
@ -77,4 +78,8 @@ public class DeviceSubscriptionData {
public void setDevice(Device device) {
this.device = device;
}
public String getCurrentInstalledVersion() { return currentInstalledVersion; }
public void setCurrentInstalledVersion(String currentInstalledVersion) { this.currentInstalledVersion = currentInstalledVersion; }
}

@ -175,12 +175,13 @@ public interface SubscriptionManager {
* @param actionStatus status of the operation.
* @param action action related to the device.
* @param appUUID application release UUID
* @param installedVersion installed version
* @return {@link PaginationResult}
* @throws ApplicationManagementException if offset or limit contains incorrect values, if it couldn't find an
* application release for given UUID, if an error occurred while getting device details of subscribed device ids,
* if an error occurred while getting subscription details of given application release UUID.
*/
PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, String action)
PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus, String action, String installedVersion)
throws ApplicationManagementException;
/***

@ -239,4 +239,13 @@ public interface SubscriptionDAO {
*/
List<Integer> getAppSubscribedDevicesForGroups(int appReleaseId, String subtype, int tenantId)
throws ApplicationManagementDAOException;
/**
* This method is used to get the currently installed version for given app release id
* @param appId id of the application
* @param deviceIdList id list of devices
* @return Map with device id as a key and currently installed version as value
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
*/
Map<Integer,String> getCurrentInstalledAppVersion(int appId, List<Integer> deviceIdList, String installedVersion) throws ApplicationManagementDAOException;
}

@ -1311,4 +1311,66 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public Map<Integer,String> getCurrentInstalledAppVersion(int appId, List<Integer> deviceIdList, String installedVersion ) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get current installed version of the app for " +
"given app release id.");
}
try {
Map<Integer,String> installedVersionsMap = new HashMap<>();
Connection conn = this.getDBConnection();
int index = 1;
boolean isInstalledVersionAvailable = false;
StringJoiner joiner = new StringJoiner(",",
" SELECT DM_DEVICE_ID AS DEVICE,VERSION FROM " +
" (SELECT AP_APP.ID, VERSION FROM AP_APP_RELEASE AP_APP " +
" WHERE ID IN (SELECT ID FROM AP_APP_RELEASE " +
" WHERE AP_APP_ID = ?) " +
" ) AP_APP_V" +
" INNER JOIN " +
" (SELECT AP_APP_RELEASE_ID, DM_DEVICE_ID FROM AP_DEVICE_SUBSCRIPTION AP_DEV_1 " +
" INNER JOIN (" +
" SELECT MAX(ID) AS ID FROM AP_DEVICE_SUBSCRIPTION " +
" WHERE STATUS = 'COMPLETED' AND DM_DEVICE_ID IN (",
") GROUP BY DM_DEVICE_ID " +
") AP_DEV_2 " +
"ON AP_DEV_2.ID = AP_DEV_1.ID ) AP_APP_R " +
"ON AP_APP_R.AP_APP_RELEASE_ID = AP_APP_V.ID");
deviceIdList.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
if(installedVersion != null && !installedVersion.isEmpty()){
query += " WHERE VERSION = ? ";
isInstalledVersionAvailable = true;
}
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setInt(index++, appId);
for (int deviceId : deviceIdList) {
ps.setInt(index++, deviceId);
}
if(isInstalledVersionAvailable){
ps.setString(index++, installedVersion);
}
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
installedVersionsMap.put(rs.getInt("DEVICE"),rs.getString("VERSION"));
}
}
return installedVersionsMap;
}
}catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get current installed version of the app for " +
"given app id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL Error occurred while getting current installed version of the app for given " +
"app id.";
log.error(msg, e);
throw new ApplicationManagementDAOException(msg, e);
}
}
}

@ -1361,7 +1361,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
@Override
public PaginationResult getAppSubscriptionDetails(PaginationRequest request, String appUUID, String actionStatus,
String action) throws ApplicationManagementException {
String action, String installedVersion) throws ApplicationManagementException {
int limitValue = request.getRowCount();
int offsetValue = request.getStartIndex();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1395,6 +1395,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
List<Integer> deviceIdList = deviceSubscriptionDTOS.stream().map(DeviceSubscriptionDTO::getDeviceId)
.collect(Collectors.toList());
Map<Integer,String> currentVersionsMap = subscriptionDAO.getCurrentInstalledAppVersion(applicationDTO.getId(),deviceIdList, installedVersion);
try {
//pass the device id list to device manager service method
PaginationResult paginationResult = deviceManagementProviderService.getAppSubscribedDevices
@ -1404,7 +1405,15 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!paginationResult.getData().isEmpty()) {
List<Device> devices = (List<Device>) paginationResult.getData();
for (Device device : devices) {
if(installedVersion != null && !installedVersion.isEmpty() && !currentVersionsMap.containsKey(device.getId())){
continue;
}
DeviceSubscriptionData deviceSubscriptionData = new DeviceSubscriptionData();
if(currentVersionsMap.containsKey(device.getId())){
deviceSubscriptionData.setCurrentInstalledVersion(currentVersionsMap.get(device.getId()));
}else{
deviceSubscriptionData.setCurrentInstalledVersion("-");
}
for (DeviceSubscriptionDTO subscription : deviceSubscriptionDTOS) {
if (subscription.getDeviceId() == device.getId()) {
deviceSubscriptionData.setDevice(device);

@ -139,6 +139,10 @@ public interface SubscriptionManagementAdminAPI {
name = "status",
value = "Provide the device status details, such as active or inactive.")
@QueryParam("status") List<String> status,
@ApiParam(
name = "installedVersion",
value = "Provide the installed version of the application.")
@QueryParam("installedVersion") String installedVersion,
@ApiParam(
name = "uuid",
value = "uuid of the application release.",

@ -60,6 +60,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
@QueryParam("action") String action,
@QueryParam("actionStatus") String actionStatus,
@QueryParam("status") List<String> status,
@QueryParam("installedVersion") String installedVersion,
@PathParam("uuid") String uuid,
@DefaultValue("0")
@QueryParam("offset") int offset,
@ -97,7 +98,7 @@ public class SubscriptionManagementAdminAPIImpl implements SubscriptionManagemen
}
SubscriptionManager subscriptionManager = APIUtil.getSubscriptionManager();
PaginationResult subscriptionData = subscriptionManager.getAppSubscriptionDetails
(request, uuid, actionStatus, action);
(request, uuid, actionStatus, action, installedVersion);
return Response.status(Response.Status.OK).entity(subscriptionData).build();
} catch (NotFoundException e) {
String msg = "Application with application release UUID: " + uuid + " is not found";

Loading…
Cancel
Save