Fix enrollment modification issues

merge-requests/713/head
Charitha Goonetilleke 4 years ago
parent d75f48166e
commit 31a6497950

@ -307,10 +307,7 @@ public class DeviceTypeManager implements DeviceManager {
JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class); JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class);
Unmarshaller unmarshaller = context.createUnmarshaller(); Unmarshaller unmarshaller = context.createUnmarshaller();
return (PlatformConfiguration) unmarshaller.unmarshal(reader); return (PlatformConfiguration) unmarshaller.unmarshal(reader);
} else if (defaultPlatformConfiguration != null) { } else return defaultPlatformConfiguration;
return defaultPlatformConfiguration;
}
return null;
} catch (DeviceTypeMgtPluginException e) { } catch (DeviceTypeMgtPluginException e) {
throw new DeviceManagementException( throw new DeviceManagementException(
"Error occurred while retrieving the Registry instance : " + e.getMessage(), e); "Error occurred while retrieving the Registry instance : " + e.getMessage(), e);
@ -379,10 +376,16 @@ public class DeviceTypeManager implements DeviceManager {
boolean status; boolean status;
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Adding properties for new device : " + device.getDeviceIdentifier()); log.debug("Modifying properties for enrolling device : " + device.getDeviceIdentifier());
} }
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction();
status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(device); Device existingDevice = deviceTypePluginDAOManager.getDeviceDAO()
.getDevice(device.getDeviceIdentifier());
if (existingDevice == null) {
status = deviceTypePluginDAOManager.getDeviceDAO().addDevice(device);
} else {
status = deviceTypePluginDAOManager.getDeviceDAO().updateDevice(device);
}
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().commitTransaction();
} catch (DeviceTypeMgtPluginException e) { } catch (DeviceTypeMgtPluginException e) {
deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction(); deviceTypePluginDAOManager.getDeviceTypeDAOHandler().rollbackTransaction();
@ -395,7 +398,7 @@ public class DeviceTypeManager implements DeviceManager {
if (propertyBasedDeviceTypePluginDAOManager != null && status) { if (propertyBasedDeviceTypePluginDAOManager != null && status) {
try { try {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Updating properties for new device : " + device.getDeviceIdentifier()); log.debug("Updating properties for enrolling device : " + device.getDeviceIdentifier());
} }
propertyBasedDeviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction(); propertyBasedDeviceTypePluginDAOManager.getDeviceTypeDAOHandler().beginTransaction();
status = propertyBasedDeviceTypePluginDAOManager.getDeviceDAO().updateDevice(device); status = propertyBasedDeviceTypePluginDAOManager.getDeviceDAO().updateDevice(device);

@ -39,7 +39,6 @@ import org.apache.commons.lang.StringUtils;
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.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException; import org.wso2.carbon.device.mgt.extensions.device.type.template.exception.DeviceTypeMgtPluginException;
import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils; import org.wso2.carbon.device.mgt.extensions.device.type.template.util.DeviceTypeUtils;
@ -58,8 +57,8 @@ import java.util.List;
public class DeviceTypePluginDAOImpl implements PluginDAO { public class DeviceTypePluginDAOImpl implements PluginDAO {
private static final Log log = LogFactory.getLog(DeviceTypePluginDAOImpl.class); private static final Log log = LogFactory.getLog(DeviceTypePluginDAOImpl.class);
private DeviceTypeDAOHandler deviceTypeDAOHandler; private final DeviceTypeDAOHandler deviceTypeDAOHandler;
private DeviceDAODefinition deviceDAODefinition; private final DeviceDAODefinition deviceDAODefinition;
private String selectDBQueryForGetDevice; private String selectDBQueryForGetDevice;
private String createDBqueryForAddDevice; private String createDBqueryForAddDevice;
private String updateDBQueryForUpdateDevice; private String updateDBQueryForUpdateDevice;
@ -108,7 +107,6 @@ public class DeviceTypePluginDAOImpl implements PluginDAO {
throw new DeviceTypeMgtPluginException(msg, e); throw new DeviceTypeMgtPluginException(msg, e);
} finally { } finally {
DeviceTypeUtils.cleanupResources(stmt, resultSet); DeviceTypeUtils.cleanupResources(stmt, resultSet);
deviceTypeDAOHandler.closeConnection();
} }
return device; return device;

Loading…
Cancel
Save