Set device type plugin DAO manager in hashmap

revert-70aa11f8
Saad Sahibjan 5 years ago
parent 9d81ee6cb4
commit 0d203e0cd5

@ -49,11 +49,9 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration
import org.wso2.carbon.device.mgt.common.license.mgt.License; import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManagementException;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager; import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.extensions.spi.DeviceTypeManagerExtensionService;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DataSource; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DataSource;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceDetails;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeConfiguration;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.DeviceTypeManagerExtensionConfig;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Feature;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Table; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.Table;
import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TableConfig; import org.wso2.carbon.device.mgt.extensions.device.type.template.config.TableConfig;
@ -65,6 +63,7 @@ import org.wso2.carbon.device.mgt.extensions.device.type.template.feature.Config
import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypePluginConstants; import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypePluginConstants;
import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils; import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils;
import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager; import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager;
import org.wso2.carbon.device.mgt.extensions.spi.DeviceTypePluginExtensionService;
import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.RegistryException;
import org.wso2.carbon.registry.api.Resource; import org.wso2.carbon.registry.api.Resource;
import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.CarbonUtils;
@ -216,34 +215,18 @@ public class DeviceTypeManager implements DeviceManager {
} }
} }
} }
setDeviceTypeManagerExtensionServices(deviceTypeConfiguration); setDeviceTypePluginManager();
} }
private void setDeviceTypeManagerExtensionServices(DeviceTypeConfiguration deviceTypeConfiguration) { /**
DeviceTypeManagerExtensionConfig deviceTypeExtensionConfig = deviceTypeConfiguration.getDeviceTypeExtensionConfig(); * Set device type plugin DAO manager of each device type in a HashMap which can then be used via individual
if (deviceTypeExtensionConfig != null) { * device type plugin in working with its DAO components
String extensionClass = deviceTypeExtensionConfig.getExtensionClass(); */
if (StringUtils.isNotEmpty(extensionClass)) { private void setDeviceTypePluginManager() {
try { if (StringUtils.isNotEmpty(deviceType) && deviceTypePluginDAOManager != null) {
Class<?> clz = Class.forName(extensionClass); DeviceTypePluginExtensionService deviceTypeManagerExtensionService =
DeviceTypeManagerExtensionService deviceTypeManagerExtensionService = (DeviceTypeManagerExtensionService) clz.newInstance(); new DeviceTypePluginExtensionServiceImpl();
if (deviceTypePluginDAOManager != null) { deviceTypeManagerExtensionService.addPluginDAOManager(deviceType, deviceTypePluginDAOManager);
deviceTypeManagerExtensionService.setDeviceTypePluginDAOManager(deviceTypePluginDAOManager);
}
} catch (ClassNotFoundException e) {
String msg = "Extension class cannot be located";
log.error(msg, e);
throw new DeviceTypeDeployerPayloadException(msg, e);
} catch (IllegalAccessException e) {
String msg = "Cannot access the class or its constructor is not accessible.";
log.error(msg, e);
throw new DeviceTypeDeployerPayloadException(msg, e);
} catch (InstantiationException e) {
String msg = "Extension class instantiation is failed";
log.error(msg, e);
throw new DeviceTypeDeployerPayloadException(msg, e);
}
}
} }
} }
@ -339,15 +322,11 @@ public class DeviceTypeManager implements DeviceManager {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction();
} }
} catch (DeviceTypeMgtPluginException e) { } catch (DeviceTypeMgtPluginException e) {
try {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction();
} catch (DeviceTypeMgtPluginException ex) {
String msg = "Error occurred while roll back the device enrol transaction :" +
device.toString();
log.warn(msg, ex);
}
String msg = "Error while enrolling the " + deviceType + " device : " + device.getDeviceIdentifier(); String msg = "Error while enrolling the " + deviceType + " device : " + device.getDeviceIdentifier();
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} finally {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection();
} }
return status; return status;
} }
@ -366,16 +345,12 @@ public class DeviceTypeManager implements DeviceManager {
status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(device); status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(device);
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction();
} catch (DeviceTypeMgtPluginException e) { } catch (DeviceTypeMgtPluginException e) {
try {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction();
} catch (DeviceTypeMgtPluginException mobileDAOEx) {
String msg = "Error occurred while roll back the update device transaction :" +
device.toString();
log.warn(msg, mobileDAOEx);
}
String msg = "Error while updating the enrollment of the " + deviceType + " device : " + String msg = "Error while updating the enrollment of the " + deviceType + " device : " +
device.getDeviceIdentifier(); device.getDeviceIdentifier();
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} finally {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection();
} }
return status; return status;
} }
@ -410,13 +385,7 @@ public class DeviceTypeManager implements DeviceManager {
deviceId.getId(); deviceId.getId();
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} finally { } finally {
try {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection();
} catch (DeviceTypeMgtPluginException e) {
String msg = "Error occurred while closing the transaction to check device " +
deviceId.getId() + " is enrolled.";
log.warn(msg, e);
}
} }
return isEnrolled; return isEnrolled;
} }
@ -451,12 +420,7 @@ public class DeviceTypeManager implements DeviceManager {
throw new DeviceManagementException( throw new DeviceManagementException(
"Error occurred while fetching the " + deviceType + " device: '" + deviceId.getId() + "'", e); "Error occurred while fetching the " + deviceType + " device: '" + deviceId.getId() + "'", e);
} finally { } finally {
try {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection();
} catch (DeviceTypeMgtPluginException e) {
String msg = "Error occurred while closing the transaction to get device " + deviceId.getId();
log.warn(msg, e);
}
} }
return device; return device;
} }
@ -479,14 +443,11 @@ public class DeviceTypeManager implements DeviceManager {
status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(updatedDevice); status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(updatedDevice);
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction();
} catch (DeviceTypeMgtPluginException e) { } catch (DeviceTypeMgtPluginException e) {
try {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction();
} catch (DeviceTypeMgtPluginException transactionException) {
String msg = "Error occurred while rolling back transaction for device: " + deviceId.getId();
log.warn(msg, transactionException);
}
throw new DeviceManagementException( throw new DeviceManagementException(
"Error occurred while fetching the " + deviceType + " device: '" + deviceId.getId() + "'", e); "Error occurred while fetching the " + deviceType + " device: '" + deviceId.getId() + "'", e);
} finally {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection();
} }
} }
return status; return status;
@ -576,15 +537,12 @@ public class DeviceTypeManager implements DeviceManager {
status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(existingDevice); status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(existingDevice);
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction();
} catch (DeviceTypeMgtPluginException e) { } catch (DeviceTypeMgtPluginException e) {
try {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction();
} catch (DeviceTypeMgtPluginException e1) {
log.warn("Error occurred while roll back the update device info transaction : '" +
device.toString() + "'", e1);
}
throw new DeviceManagementException( throw new DeviceManagementException(
"Error occurred while updating the " + deviceType + " device: '" + "Error occurred while updating the " + deviceType + " device: '" +
device.getDeviceIdentifier() + "'", e); device.getDeviceIdentifier() + "'", e);
} finally {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection();
} }
return status; return status;
} }
@ -604,12 +562,7 @@ public class DeviceTypeManager implements DeviceManager {
} catch (DeviceTypeMgtPluginException e) { } catch (DeviceTypeMgtPluginException e) {
throw new DeviceManagementException("Error occurred while fetching all " + deviceType + " devices", e); throw new DeviceManagementException("Error occurred while fetching all " + deviceType + " devices", e);
} finally { } finally {
try {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection();
} catch (DeviceTypeMgtPluginException e) {
String msg = "Error occurred while closing the transaction to get all devices.";
log.warn(msg, e);
}
} }
return devices; return devices;
} }
@ -632,15 +585,12 @@ public class DeviceTypeManager implements DeviceManager {
status = deviceTypePluginDAOManager.getDeviceDAO().deleteDevice(existingDevice); status = deviceTypePluginDAOManager.getDeviceDAO().deleteDevice(existingDevice);
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction();
} catch (DeviceTypeMgtPluginException e) { } catch (DeviceTypeMgtPluginException e) {
try {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction();
} catch (DeviceTypeMgtPluginException e1) {
log.warn("Error occurred while roll back the delete device info transaction : '" +
device.toString() + "'", e1);
}
throw new DeviceManagementException( throw new DeviceManagementException(
"Error occurred while deleting the " + deviceType + " device: '" + "Error occurred while deleting the " + deviceType + " device: '" +
device.getDeviceIdentifier() + "'", e); device.getDeviceIdentifier() + "'", e);
} finally {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().closeConnection();
} }
return status; return status;
} }

@ -1,26 +0,0 @@
/*
* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.wso2.carbon.device.mgt.extensions.spi;
import org.wso2.carbon.device.mgt.extensions.device.type.template.dao.DeviceTypePluginDAOManager;
public interface DeviceTypeManagerExtensionService {
void setDeviceTypePluginDAOManager(DeviceTypePluginDAOManager deviceManager);
}
Loading…
Cancel
Save