mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Removing some hack used to workaround issues that popped up while writing unit tests upon tenant-enabled code
This commit is contained in:
parent
15d56e29c3
commit
e4fd0607e8
@ -180,10 +180,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|||||||
@Override
|
@Override
|
||||||
public void updateApplicationListInstalledInDevice(
|
public void updateApplicationListInstalledInDevice(
|
||||||
DeviceIdentifier deviceIdentifier, List<Application> applications) throws ApplicationManagementException {
|
DeviceIdentifier deviceIdentifier, List<Application> applications) throws ApplicationManagementException {
|
||||||
|
|
||||||
int tenantId = getTenantId();
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
DeviceManagementDAOFactory.beginTransaction();
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
Device device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
||||||
|
|
||||||
@ -199,8 +197,8 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|||||||
List<Application> appsToAdd = new ArrayList<Application>();
|
List<Application> appsToAdd = new ArrayList<Application>();
|
||||||
List<Integer> appIdsToRemove = new ArrayList<Integer>();
|
List<Integer> appIdsToRemove = new ArrayList<Integer>();
|
||||||
|
|
||||||
for(Application installedApp:installedAppList){
|
for (Application installedApp : installedAppList) {
|
||||||
if (!applications.contains(installedApp)){
|
if (!applications.contains(installedApp)) {
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Remove app Id:" + installedApp.getId());
|
log.debug("Remove app Id:" + installedApp.getId());
|
||||||
}
|
}
|
||||||
@ -211,12 +209,12 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|||||||
Application installedApp;
|
Application installedApp;
|
||||||
List<Integer> applicationIds = new ArrayList<>();
|
List<Integer> applicationIds = new ArrayList<>();
|
||||||
|
|
||||||
for(Application application:applications){
|
for (Application application : applications) {
|
||||||
if (!installedAppList.contains(application)) {
|
if (!installedAppList.contains(application)) {
|
||||||
installedApp = applicationDAO.getApplication(application.getApplicationIdentifier(), tenantId);
|
installedApp = applicationDAO.getApplication(application.getApplicationIdentifier(), tenantId);
|
||||||
if (installedApp == null){
|
if (installedApp == null) {
|
||||||
appsToAdd.add(application);
|
appsToAdd.add(application);
|
||||||
}else{
|
} else {
|
||||||
applicationIds.add(installedApp.getId());
|
applicationIds.add(installedApp.getId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -234,7 +232,7 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("num of remove app Ids:" + appIdsToRemove.size());
|
log.debug("num of remove app Ids:" + appIdsToRemove.size());
|
||||||
}
|
}
|
||||||
applicationMappingDAO.removeApplicationMapping(device.getId(), appIdsToRemove,tenantId);
|
applicationMappingDAO.removeApplicationMapping(device.getId(), appIdsToRemove, tenantId);
|
||||||
DeviceManagementDAOFactory.commitTransaction();
|
DeviceManagementDAOFactory.commitTransaction();
|
||||||
} catch (DeviceManagementDAOException deviceDaoEx) {
|
} catch (DeviceManagementDAOException deviceDaoEx) {
|
||||||
String errorMsg = "Error occurred saving application list to the device";
|
String errorMsg = "Error occurred saving application list to the device";
|
||||||
@ -242,37 +240,24 @@ public class ApplicationManagerProviderServiceImpl implements ApplicationManagem
|
|||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.rollbackTransaction();
|
DeviceManagementDAOFactory.rollbackTransaction();
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
log.error("Error occurred while roll back transaction",e);
|
log.error("Error occurred while roll back transaction", e);
|
||||||
}
|
}
|
||||||
throw new ApplicationManagementException(errorMsg, deviceDaoEx);
|
throw new ApplicationManagementException(errorMsg, deviceDaoEx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int getTenantId() {
|
|
||||||
|
|
||||||
int tenantId = 0;
|
|
||||||
if (isTest){
|
|
||||||
tenantId = DeviceManagerUtil.currentTenant.get();
|
|
||||||
}else{
|
|
||||||
tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
}
|
|
||||||
|
|
||||||
return tenantId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
|
public List<Application> getApplicationListForDevice(
|
||||||
throws ApplicationManagementException {
|
DeviceIdentifier deviceId) throws ApplicationManagementException {
|
||||||
Device device = null;
|
Device device = null;
|
||||||
try {
|
try {
|
||||||
int tenantId = getTenantId();
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
device = deviceDAO.getDevice(deviceIdentifier, tenantId);
|
device = deviceDAO.getDevice(deviceId, tenantId);
|
||||||
return applicationDAO.getInstalledApplications(device.getId());
|
return applicationDAO.getInstalledApplications(device.getId());
|
||||||
}catch (DeviceManagementDAOException deviceDaoEx) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
String errorMsg = "Error occured while fetching the Application List of device : " + device.getId();
|
throw new ApplicationManagementException("Error occured while fetching the Application List of '" +
|
||||||
log.error(errorMsg, deviceDaoEx);
|
deviceId.getType() + "' device carrying the identifier'" + deviceId.getId(), e);
|
||||||
throw new ApplicationManagementException(errorMsg, deviceDaoEx);
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -53,7 +53,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
private DeviceTypeDAO deviceTypeDAO;
|
private DeviceTypeDAO deviceTypeDAO;
|
||||||
private EnrolmentDAO enrolmentDAO;
|
private EnrolmentDAO enrolmentDAO;
|
||||||
private DeviceManagementPluginRepository pluginRepository;
|
private DeviceManagementPluginRepository pluginRepository;
|
||||||
private boolean isTest = false;
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
|
private static Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class);
|
||||||
private int tenantId;
|
private int tenantId;
|
||||||
@ -75,7 +74,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test){
|
DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test){
|
||||||
this.pluginRepository = pluginRepo;
|
this.pluginRepository = pluginRepo;
|
||||||
initDataAccessObjects();
|
initDataAccessObjects();
|
||||||
isTest = test;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initDataAccessObjects() {
|
private void initDataAccessObjects() {
|
||||||
@ -108,7 +106,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
} else {
|
} else {
|
||||||
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE);
|
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||||
}
|
}
|
||||||
int tenantId = getTenantId();
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
|
||||||
DeviceManagementDAOFactory.beginTransaction();
|
DeviceManagementDAOFactory.beginTransaction();
|
||||||
|
|
||||||
@ -724,14 +722,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementDAOFactory.getConnection();
|
DeviceManagementDAOFactory.getConnection();
|
||||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
allDevices = deviceDAO.getDevicesByStatus(status, tenantId);
|
allDevices = deviceDAO.getDevicesByStatus(status, tenantId);
|
||||||
|
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
String errorMsg = "Error occurred while fetching the list of devices that matches to status: '"
|
throw new DeviceManagementException(
|
||||||
+ status + "'";
|
"Error occurred while fetching the list of devices that matches to status: '" + status + "'", e);
|
||||||
log.error(errorMsg, e);
|
|
||||||
throw new DeviceManagementException(errorMsg, e);
|
|
||||||
} finally {
|
} finally {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
DeviceManagementDAOFactory.closeConnection();
|
DeviceManagementDAOFactory.closeConnection();
|
||||||
} catch (DeviceManagementDAOException e) {
|
} catch (DeviceManagementDAOException e) {
|
||||||
@ -753,19 +747,4 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
return devices;
|
return devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private int getTenantId() {
|
|
||||||
|
|
||||||
ThreadLocal<Integer> tenantId = new ThreadLocal<Integer>();
|
|
||||||
int tenant = 0;
|
|
||||||
|
|
||||||
if (isTest){
|
|
||||||
tenant = DeviceManagerUtil.currentTenant.get();
|
|
||||||
}else{
|
|
||||||
tenant = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
||||||
}
|
|
||||||
return tenant;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -49,7 +49,6 @@ import java.util.*;
|
|||||||
public final class DeviceManagerUtil {
|
public final class DeviceManagerUtil {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
|
private static final Log log = LogFactory.getLog(DeviceManagerUtil.class);
|
||||||
public static ThreadLocal<Integer> currentTenant = new ThreadLocal<Integer>();
|
|
||||||
|
|
||||||
enum HTTPMethod {
|
enum HTTPMethod {
|
||||||
GET, POST, DELETE, PUT, OPTIONS
|
GET, POST, DELETE, PUT, OPTIONS
|
||||||
|
|||||||
@ -58,7 +58,6 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
|
|||||||
deviceManagementProviderService = new DeviceManagementProviderServiceImpl(deviceManagementPluginRepository,
|
deviceManagementProviderService = new DeviceManagementProviderServiceImpl(deviceManagementPluginRepository,
|
||||||
true);
|
true);
|
||||||
DeviceManagerUtil.registerDeviceType(TestDataHolder.TEST_DEVICE_TYPE);
|
DeviceManagerUtil.registerDeviceType(TestDataHolder.TEST_DEVICE_TYPE);
|
||||||
DeviceManagerUtil.currentTenant.set(TestDataHolder.SUPER_TENANT_ID);
|
|
||||||
|
|
||||||
Device device = TestDataHolder.generateDummyDeviceData(TestDataHolder.TEST_DEVICE_TYPE);
|
Device device = TestDataHolder.generateDummyDeviceData(TestDataHolder.TEST_DEVICE_TYPE);
|
||||||
boolean isEnrolled = deviceManagementProviderService.enrollDevice(device);
|
boolean isEnrolled = deviceManagementProviderService.enrollDevice(device);
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user