Fixes for device enrollment status change issues

revert-70ac1926
Charitha Goonetilleke 4 years ago
parent 542fea8992
commit fb3da8c94d

@ -674,6 +674,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
while (rs.next()) { while (rs.next()) {
if (enrolmentId == 0) { if (enrolmentId == 0) {
activity = new Activity(); activity = new Activity();
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE"))); activity.setType(Activity.Type.valueOf(rs.getString("OPERATION_TYPE")));
activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString()); activity.setCreatedTimeStamp(new java.util.Date(rs.getLong(("CREATED_TIMESTAMP")) * 1000).toString());
activity.setCode(rs.getString("OPERATION_CODE")); activity.setCode(rs.getString("OPERATION_CODE"));

@ -73,7 +73,6 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion;
import org.wso2.carbon.device.mgt.core.geo.GeoCluster; import org.wso2.carbon.device.mgt.core.geo.GeoCluster;
import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate; import org.wso2.carbon.device.mgt.core.geo.geoHash.GeoCoordinate;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import java.sql.SQLException; import java.sql.SQLException;
import java.util.Date; import java.util.Date;

@ -2747,14 +2747,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
if (EnrolmentInfo.Status.REMOVED == newStatus) { if (EnrolmentInfo.Status.REMOVED == newStatus) {
isDeviceUpdated = disenrollDevice(deviceIdentifier); isDeviceUpdated = disenrollDevice(deviceIdentifier);
} else { } else {
enrolmentInfo = device.getEnrolmentInfo(); enrolmentInfo.setStatus(newStatus);
if (enrolmentInfo.getStatus() != newStatus) { isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId);
enrolmentInfo.setStatus(newStatus);
isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId);
} else {
isDeviceUpdated = false;
}
} }
this.removeDeviceFromCache(deviceIdentifier);
return isDeviceUpdated; return isDeviceUpdated;
} }
@ -2790,15 +2786,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
boolean isUpdatedEnrollment = false; boolean isUpdatedEnrollment = false;
try { try {
DeviceManagementDAOFactory.openConnection(); DeviceManagementDAOFactory.beginTransaction();
int updatedRows = enrollmentDAO.updateEnrollment(enrolmentInfo, tenantId); int updatedRows = enrollmentDAO.updateEnrollment(enrolmentInfo, tenantId);
DeviceManagementDAOFactory.commitTransaction();
if (updatedRows > 0) { if (updatedRows > 0) {
isUpdatedEnrollment = true; isUpdatedEnrollment = true;
} }
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction(); DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating the enrollment information device for" + String msg = "Error occurred while updating the enrollment information device for" +
@ -3321,6 +3314,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.beginTransaction(); DeviceManagementDAOFactory.beginTransaction();
success = deviceDAO.setEnrolmentStatusInBulk(deviceType, status, getTenantId(), deviceList); success = deviceDAO.setEnrolmentStatusInBulk(deviceType, status, getTenantId(), deviceList);
DeviceManagementDAOFactory.commitTransaction(); DeviceManagementDAOFactory.commitTransaction();
if (success) {
for (String id : deviceList) {
this.removeDeviceFromCache(new DeviceIdentifier(id, deviceType));
}
}
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction(); DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred in while updating status of devices :" + deviceType + " status : " + status; String msg = "Error occurred in while updating status of devices :" + deviceType + " status : " + status;

Loading…
Cancel
Save