mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
EMM-1757:Fixed admin device-detail view issue
This commit is contained in:
parent
954a2eb870
commit
a89b50197f
@ -334,6 +334,16 @@ public interface DeviceDAO {
|
||||
EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser,
|
||||
int tenantId) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve current enrollment of a given device.
|
||||
*
|
||||
* @param deviceId device id.
|
||||
* @param tenantId tenant id.
|
||||
* @return returns EnrolmentInfo object.
|
||||
* @throws DeviceManagementDAOException
|
||||
*/
|
||||
EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException;
|
||||
|
||||
/**
|
||||
* This method is used to retrieve current active enrollment of a given device and tenant id.
|
||||
*
|
||||
|
||||
@ -794,6 +794,37 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
EnrolmentInfo enrolmentInfo = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
|
||||
"DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
|
||||
"FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
|
||||
"AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
|
||||
"AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, deviceId.getId());
|
||||
stmt.setString(2, deviceId.getType());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setInt(4, tenantId);
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
enrolmentInfo = DeviceManagementDAOUtil.loadMatchingEnrolment(rs);
|
||||
}
|
||||
return enrolmentInfo;
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " +
|
||||
"of device '" + deviceId + "'", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnrolmentInfo getActiveEnrolment(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException {
|
||||
Connection conn;
|
||||
|
||||
@ -927,6 +927,13 @@ public class OperationManagerImpl implements OperationManager {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
String user = this.getUser();
|
||||
enrolmentInfo = deviceDAO.getEnrolment(deviceId, user, tenantId);
|
||||
if (enrolmentInfo == null) {
|
||||
boolean isAdminUser = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
||||
isDeviceAdminUser();
|
||||
if (isAdminUser) {
|
||||
enrolmentInfo = deviceDAO.getEnrolment(deviceId, tenantId);
|
||||
}
|
||||
}
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new OperationManagementException("Error occurred while retrieving enrollment data of '" +
|
||||
deviceId.getType() + "' device carrying the identifier '" +
|
||||
@ -934,6 +941,10 @@ public class OperationManagerImpl implements OperationManager {
|
||||
} catch (SQLException e) {
|
||||
throw new OperationManagementException(
|
||||
"Error occurred while opening a connection to the data source", e);
|
||||
} catch (DeviceAccessAuthorizationException e) {
|
||||
throw new OperationManagementException("Error occurred while checking the device access permissions for '" +
|
||||
deviceId.getType() + "' device carrying the identifier '" +
|
||||
deviceId.getId() + "'", e);
|
||||
} finally {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user