Merge branch 'master' into 'master'

Fix device type DAO handler being persisted in a wrong way

Closes product-iots#388

See merge request entgra/carbon-device-mgt!490
feature/appm-store/pbac
Dharmakeerthi Lasantha 5 years ago
commit 04431b57c7

@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.extensions.device.type.template;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOManager; import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOManager;
import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypePluginExtensionException; import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypePluginExtensionException;
import org.wso2.carbon.device.mgt.extensions.spi.DeviceTypePluginExtensionService; import org.wso2.carbon.device.mgt.extensions.spi.DeviceTypePluginExtensionService;
@ -36,34 +35,29 @@ public class DeviceTypePluginExtensionServiceImpl implements DeviceTypePluginExt
@Override @Override
public void addPluginDAOManager(String deviceType, DeviceTypePluginDAOManager pluginDAOManager) public void addPluginDAOManager(String deviceType, DeviceTypePluginDAOManager pluginDAOManager)
throws DeviceTypePluginExtensionException { throws DeviceTypePluginExtensionException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
if (pluginDAOManager == null) { if (pluginDAOManager == null) {
String msg = "Cannot save DeviceTypePluginDAOManager against tenant id " + tenantId String msg = "Cannot save DeviceTypePluginDAOManager of device type: " + deviceType
+ " and device type: " + deviceType + " since DeviceTypePluginDAOManager is null"; + " since DeviceTypePluginDAOManager is null";
log.error(msg); log.error(msg);
throw new DeviceTypePluginExtensionException(msg); throw new DeviceTypePluginExtensionException(msg);
} }
if (!pluginDAOManagers.containsKey(tenantId + deviceType)) { if (!pluginDAOManagers.containsKey(deviceType)) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Saving DeviceTypePluginDAOManager against tenant id " + tenantId + log.debug("Saving DeviceTypePluginDAOManager of device type: " + deviceType);
" and device type: " + deviceType);
} }
pluginDAOManagers.put(tenantId + deviceType, pluginDAOManager); pluginDAOManagers.put(deviceType, pluginDAOManager);
} }
} }
@Override @Override
public DeviceTypePluginDAOManager getPluginDAOManager(String deviceType) throws DeviceTypePluginExtensionException { public DeviceTypePluginDAOManager getPluginDAOManager(String deviceType) throws DeviceTypePluginExtensionException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); if (pluginDAOManagers.containsKey(deviceType)) {
if (pluginDAOManagers.containsKey(tenantId + deviceType)) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Retrieving DeviceTypePluginDAOManager against tenant id " + tenantId + log.debug("Retrieving DeviceTypePluginDAOManager of device type: " + deviceType);
" and device type: " + deviceType);
} }
return pluginDAOManagers.get(tenantId + deviceType); return pluginDAOManagers.get(deviceType);
} else { } else {
String msg = "DeviceTypePluginDAOManager could not be found against tenant id " + tenantId + String msg = "DeviceTypePluginDAOManager of device type: " + deviceType + " cannot be found";
" and device type: " + deviceType;
log.error(msg); log.error(msg);
throw new DeviceTypePluginExtensionException(msg); throw new DeviceTypePluginExtensionException(msg);
} }

Loading…
Cancel
Save