fixed issue in modify enrollment

revert-70aa11f8
hasuniea 9 years ago
parent 3582973f84
commit 9f6dd55223

@ -22,7 +22,6 @@ import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status; import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
import java.util.List; import java.util.List;
@ -33,7 +32,7 @@ public interface DeviceDAO {
int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException; int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException;
int updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException; boolean updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException;
int removeDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException; int removeDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException;

@ -67,11 +67,11 @@ public class DeviceDAOImpl implements DeviceDAO {
} }
@Override @Override
public int updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException { public boolean updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; boolean status = false;
int deviceId = -1; int rows;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql =
@ -83,18 +83,16 @@ public class DeviceDAOImpl implements DeviceDAO {
stmt.setString(3, device.getDeviceIdentifier()); stmt.setString(3, device.getDeviceIdentifier());
stmt.setInt(4, typeId); stmt.setInt(4, typeId);
stmt.setInt(5, tenantId); stmt.setInt(5, tenantId);
stmt.executeUpdate(); rows = stmt.executeUpdate();
if (rows>0) {
rs = stmt.getGeneratedKeys(); status = true;
if (rs.next()) {
deviceId = rs.getInt(1);
} }
return deviceId; return status;
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while enrolling device '" + throw new DeviceManagementDAOException("Error occurred while enrolling device '" +
device.getName() + "'", e); device.getName() + "'", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, null);
} }
} }

@ -139,6 +139,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
EnrolmentInfo newEnrolmentInfo = device.getEnrolmentInfo(); EnrolmentInfo newEnrolmentInfo = device.getEnrolmentInfo();
if (existingEnrolmentInfo != null && newEnrolmentInfo != null) { if (existingEnrolmentInfo != null && newEnrolmentInfo != null) {
if (existingEnrolmentInfo.equals(newEnrolmentInfo)) { if (existingEnrolmentInfo.equals(newEnrolmentInfo)) {
device.setId(existingDevice.getId());
device.getEnrolmentInfo().setDateOfEnrolment(existingEnrolmentInfo.getDateOfEnrolment()); device.getEnrolmentInfo().setDateOfEnrolment(existingEnrolmentInfo.getDateOfEnrolment());
this.modifyEnrollment(device); this.modifyEnrollment(device);
status = true; status = true;
@ -210,8 +211,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.beginTransaction(); DeviceManagementDAOFactory.beginTransaction();
DeviceType type = deviceTypeDAO.getDeviceType(device.getType()); DeviceType type = deviceTypeDAO.getDeviceType(device.getType());
int deviceId = deviceDAO.updateDevice(type.getId(), device, tenantId); deviceDAO.updateDevice(type.getId(), device, tenantId);
enrolmentDAO.updateEnrollment(deviceId, device.getEnrolmentInfo(), tenantId); enrolmentDAO.updateEnrollment(device.getId(), device.getEnrolmentInfo(), tenantId);
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException | TransactionManagementException e) { } catch (DeviceManagementDAOException | TransactionManagementException e) {

Loading…
Cancel
Save