Improve the subscribed devices and category details APIs

feature/appm-store/pbac
nipunnadeen 5 years ago committed by nipun
parent 4cfa0789ac
commit 61bd91b21f

@ -22,9 +22,6 @@ import io.swagger.annotations.ApiModelProperty;
public class BasePaginatedResult {
/**
* Number of Resources returned.
*/
@ApiModelProperty(
value = "Number of total resources.",
example = "1")

@ -33,12 +33,13 @@ public interface SubscriptionManager {
/***
* This method used to get the app id ,device ids and pass them to DM service method
* @param appUUID uuid
* @param offsetValue offsetValue
* @param limitValue limitValue
* @param status status
* @return deviceDetails
* @throws ApplicationManagementException Exception of the application management
* @param appUUID UUID of the application release
* @param offsetValue offset value for get paginated result
* @param limitValue limit value for get paginated result
* @param status status of the devices
* @return deviceDetails - device details for given application release.
* @throws ApplicationManagementException throws {@link ApplicationManagementException} Exception
* of the application management
*/
PaginationResult getAppInstalledDevices(int offsetValue, int limitValue, String appUUID,
String status)
@ -46,12 +47,13 @@ public interface SubscriptionManager {
/***
* This method used to get category details
* @param appUUID uuid
* @param subType subType
* @param offsetValue offsetValue
* @param limitValue limitValue
* @return paginationResult
* @throws ApplicationManagementException Exception of the application management
* @param appUUID UUID of the application release
* @param subType subscription type of the application
* @param offsetValue offset value for get paginated result
* @param limitValue limit value for get paginated result
* @return {@link PaginationResult} pagination result of the category details.
* @throws ApplicationManagementException throws {@link ApplicationManagementException} Exception
* of the application management
*/
PaginationResult getAppInstalledCategories(int offsetValue, int limitValue, String appUUID,
String subType)

@ -87,11 +87,11 @@ public interface SubscriptionDAO {
/**
* this method is used to get the details of users
* @param tenantId tenant id
* @param offsetValue offsetValue
* @param limitValue limitValue
* @param appReleaseId appReleaseId
* @return subscribedUsers
* @param tenantId id of the current tenant
* @param offsetValue offset value for get paginated result
* @param limitValue limit value for get paginated result
* @param appReleaseId id of the application release.
* @return subscribedUsers - list of app subscribed users.
* @throws ApplicationManagementDAOException throws {@link ApplicationManagementDAOException} if
* connections establishment fails.
*/
@ -101,11 +101,11 @@ public interface SubscriptionDAO {
/**
* this method is used to get the details of roles
* @param tenantId tenant id
* @param offsetValue offsetValue
* @param limitValue limitValue
* @param appReleaseId appReleaseId
* @return subscribedRoles
* @param tenantId id of the current tenant
* @param offsetValue offset value for get paginated result
* @param limitValue limit value for get paginated result
* @param appReleaseId id of the application release.
* @return subscribedRoles - list of app subscribed roles.
* @throws ApplicationManagementDAOException throws {@link ApplicationManagementDAOException} if
* connections establishment fails.
*/
@ -114,12 +114,12 @@ public interface SubscriptionDAO {
throws ApplicationManagementDAOException;
/**
* this method is used to get the details of groups
* @param tenantId tenant id
* @param offsetValue offsetValue
* @param limitValue limitValue
* @param appReleaseId appReleaseId
* @return subscribedUsers
* this method is used to get the details of subscribed groups
* @param tenantId id of the current tenant
* @param offsetValue offset value for get paginated result
* @param limitValue limit value for get paginated result
* @param appReleaseId id of the application release.
* @return subscribedGroups - list of app subscribed groups.
* @throws ApplicationManagementDAOException throws {@link ApplicationManagementDAOException} if
* connections establishment fails.
*/

@ -708,7 +708,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
try {
Connection conn = this.getDBConnection();
int index = 1;
List<String> subscribedUsers = new ArrayList<>();
String sql = "SELECT "
+ "US.USER_NAME AS USER "
@ -716,10 +715,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ?,?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(index++, appReleaseId);
stmt.setInt(index++, tenantId);
stmt.setInt(index++, offsetValue);
stmt.setInt(index, limitValue);
stmt.setInt(1, appReleaseId);
stmt.setInt(2, tenantId);
stmt.setInt(3, offsetValue);
stmt.setInt(4, limitValue);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
subscribedUsers.add(rs.getString("USER"));
@ -749,7 +748,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
try {
Connection conn = this.getDBConnection();
int index = 1;
List<String> subscribedRoles = new ArrayList<>();
String sql = "SELECT "
+ "US.ROLE_NAME AS ROLE "
@ -757,10 +755,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ?,?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(index++, appReleaseId);
ps.setInt(index++, tenantId);
ps.setInt(index++, offsetValue);
ps.setInt(index, limitValue);
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
ps.setInt(3, offsetValue);
ps.setInt(4, limitValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedRoles.add(rs.getString("ROLE"));
@ -790,7 +788,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
try {
Connection conn = this.getDBConnection();
int index = 1;
List<String> subscribedGroups = new ArrayList<>();
String sql = "SELECT "
+ "GS.GROUP_NAME AS GROUPS "
@ -798,10 +795,10 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
+ "WHERE "
+ "AP_APP_RELEASE_ID = ? AND TENANT_ID = ? LIMIT ?,?";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(index++, appReleaseId);
ps.setInt(index++, tenantId);
ps.setInt(index++, offsetValue);
ps.setInt(index, limitValue);
ps.setInt(1, appReleaseId);
ps.setInt(2, tenantId);
ps.setInt(3, offsetValue);
ps.setInt(4, limitValue);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedGroups.add(rs.getString("GROUPS"));

@ -571,7 +571,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(appUUID, tenantId);
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();
@ -580,14 +579,13 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (deviceSubscriptionDTOS.isEmpty()) {
String msg = "Couldn't found an subscribed devices for application release id: "
+ applicationReleaseId;
log.error(msg);
log.info(msg);
}
List<Integer> deviceIdList = new ArrayList<>();
for (DeviceSubscriptionDTO deviceIds : deviceSubscriptionDTOS) {
deviceIdList.add(deviceIds.getDeviceId());
}
//pass the device id list to device manager service layer method
//pass the device id list to device manager service method
try {
PaginationResult deviceDetails = deviceManagementProviderService
.getAppSubscribedDevices(offsetValue ,limitValue, deviceIdList, status);
@ -630,7 +628,6 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
PaginationResult paginationResult = new PaginationResult();
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO
.getAppWithRelatedRelease(appUUID, tenantId);
int applicationReleaseId = applicationDTO.getApplicationReleaseDTOs().get(0).getId();

@ -552,13 +552,13 @@ public interface DeviceDAO {
String toDate) throws DeviceManagementDAOException;
/**
* this method is used to get the details of devices
* @param deviceIds device ids
* @param tenantId tenant id
* @param offsetValue offsetValue
* @param limitValue limitValue
* @param status status
* @return subscribed device details list
* this method is used to get the details of subscribed devices.
* @param deviceIds device ids of the subscribed devices.
* @param tenantId Id of the current tenant.
* @param offsetValue offset value for get paginated result.
* @param limitValue limit value for get paginated result.
* @param status status of the devices.
* @return devices - subscribed device details list
* @throws DeviceManagementDAOException throws {@link DeviceManagementDAOException} if connections
* establishment fails.
*/

@ -618,8 +618,10 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
}
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving information " +
"of all registered devices according to device ids and the limit area", e);
String msg = "Error occurred while retrieving information of all registered devices " +
"according to device ids and the limit area.";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}

@ -37,6 +37,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.StringJoiner;
/**
* This class holds the generic implementation of DeviceDAO which can be used to support ANSI db syntax.
@ -572,7 +573,61 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
public List<Device> getSubscribedDevices(int offsetValue, int limitValue,
List<Integer> deviceIds, int tenantId, String status)
throws DeviceManagementDAOException {
return null;
Connection conn;
try {
conn = this.getConnection();
int index = 1;
boolean isStatusProvided = false;
StringJoiner joiner = new StringJoiner(",",
"SELECT " +
"f.ID AS DEVICE_ID, f.NAME AS DEVICE_NAME, f.DESCRIPTION AS DESCRIPTION, " +
"f.DEVICE_TYPE_ID, f.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " +
"e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " +
"e.DATE_OF_LAST_UPDATE, e.STATUS, t.NAME AS DEVICE_TYPE " +
"FROM DM_ENROLMENT AS e,DM_DEVICE AS f, DM_DEVICE_TYPE t " +
"WHERE " +
"e.DEVICE_ID=f.ID AND " +
"e.DEVICE_ID IN (", ") AND e.TENANT_ID=?");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
if (status != null && !status.isEmpty()) {
query = query + " AND e.STATUS=?";
isStatusProvided = true;
}
query = query + " ORDER BY ENROLMENT_ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement ps = conn.prepareStatement(query)) {
for (Integer deviceId : deviceIds) {
ps.setObject(index++, deviceId);
}
ps.setInt(index++, tenantId);
if (isStatusProvided) {
ps.setString(index++, status);
}
ps.setInt(index++, offsetValue);
ps.setInt(index, limitValue);
try (ResultSet rs = ps.executeQuery()) {
List<Device> devices = new ArrayList<>();
while (rs.next()) {
devices.add(DeviceManagementDAOUtil.loadDevice(rs));
}
return devices;
}
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving information of all registered devices " +
"according to device ids and the limit area.";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
private Connection getConnection() throws SQLException {

@ -34,6 +34,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.StringJoiner;
/**
* This class holds the generic implementation of DeviceDAO which can be used to support ANSI db syntax.
@ -550,7 +551,61 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
public List<Device> getSubscribedDevices(int offsetValue, int limitValue,
List<Integer> deviceIds, int tenantId, String status)
throws DeviceManagementDAOException {
return null;
Connection conn;
try {
conn = this.getConnection();
int index = 1;
boolean isStatusProvided = false;
StringJoiner joiner = new StringJoiner(",",
"SELECT " +
"f.ID AS DEVICE_ID, f.NAME AS DEVICE_NAME, f.DESCRIPTION AS DESCRIPTION, " +
"f.DEVICE_TYPE_ID, f.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " +
"e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " +
"e.DATE_OF_LAST_UPDATE, e.STATUS, t.NAME AS DEVICE_TYPE " +
"FROM DM_ENROLMENT AS e,DM_DEVICE AS f, DM_DEVICE_TYPE t "+
"WHERE " +
"e.DEVICE_ID=f.ID AND " +
"e.DEVICE_ID IN (", ") AND e.TENANT_ID=?");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
if (status != null && !status.isEmpty()) {
query = query + " AND e.STATUS=?";
isStatusProvided = true;
}
query = query + " LIMIT ? OFFSET ?";
try (PreparedStatement ps = conn.prepareStatement(query)) {
for (Integer deviceId : deviceIds) {
ps.setObject(index++, deviceId);
}
ps.setInt(index++, tenantId);
if (isStatusProvided) {
ps.setString(index++, status);
}
ps.setInt(index++, offsetValue);
ps.setInt(index, limitValue);
try (ResultSet rs = ps.executeQuery()) {
List<Device> devices = new ArrayList<>();
while (rs.next()) {
devices.add(DeviceManagementDAOUtil.loadDevice(rs));
}
return devices;
}
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving information of all registered devices " +
"according to device ids and the limit area.";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
private Connection getConnection() throws SQLException {

@ -34,6 +34,7 @@ import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.StringJoiner;
/**
* This class holds the generic implementation of DeviceDAO which can be used to support ANSI db syntax.
@ -505,7 +506,61 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
public List<Device> getSubscribedDevices(int offsetValue, int limitValue,
List<Integer> deviceIds, int tenantId, String status)
throws DeviceManagementDAOException {
return null;
Connection conn;
try {
conn = this.getConnection();
int index = 1;
boolean isStatusProvided = false;
StringJoiner joiner = new StringJoiner(",",
"SELECT " +
"f.ID AS DEVICE_ID, f.NAME AS DEVICE_NAME, f.DESCRIPTION AS DESCRIPTION, " +
"f.DEVICE_TYPE_ID, f.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION, " +
"e.ID AS ENROLMENT_ID, e.OWNER, e.OWNERSHIP, e.DATE_OF_ENROLMENT, " +
"e.DATE_OF_LAST_UPDATE, e.STATUS, t.NAME AS DEVICE_TYPE " +
"FROM DM_ENROLMENT AS e,DM_DEVICE AS f, DM_DEVICE_TYPE t "+
"WHERE " +
"e.DEVICE_ID=f.ID AND " +
"e.DEVICE_ID IN (", ") AND e.TENANT_ID=?");
deviceIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
if (status != null && !status.isEmpty()) {
query = query + " AND e.STATUS=?";
isStatusProvided = true;
}
query = query + " LIMIT ?,?";
try (PreparedStatement ps = conn.prepareStatement(query)) {
for (Integer deviceId : deviceIds) {
ps.setObject(index++, deviceId);
}
ps.setInt(index++, tenantId);
if (isStatusProvided) {
ps.setString(index++, status);
}
ps.setInt(index++, offsetValue);
ps.setInt(index, limitValue);
try (ResultSet rs = ps.executeQuery()) {
List<Device> devices = new ArrayList<>();
while (rs.next()) {
devices.add(DeviceManagementDAOUtil.loadDevice(rs));
}
return devices;
}
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving information of all registered devices " +
"according to device ids and the limit area.";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
}
private Connection getConnection() throws SQLException {

@ -771,12 +771,13 @@ public interface DeviceManagementProviderService {
/**
* This method retrieves a list of subscribed devices.
* @param devicesIds devices ids
* @param offsetValue offsetValue
* @param limitValue limitValue
* @param status status
* @param devicesIds devices ids of the subscribed devices
* @param offsetValue offset value for get paginated result
* @param limitValue limit value for get paginated result
* @param status status of the devices
* @return {@link PaginationResult}
* @throws DeviceManagementException if any service level or DAO level error occurs
* @throws DeviceManagementException throws {@link DeviceManagementException} if any service
* level or DAO level error occurs
*/
PaginationResult getAppSubscribedDevices(int offsetValue, int limitValue,
List<Integer> devicesIds, String status)

Loading…
Cancel
Save