mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Set device status to active when poll operations
This commit is contained in:
parent
6263a550ff
commit
f3dd402e4b
@ -24,12 +24,15 @@ import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
@ -57,6 +60,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
private OperationMappingDAO operationMappingDAO;
|
||||
private OperationDAO operationDAO;
|
||||
private DeviceDAO deviceDAO;
|
||||
private DeviceTypeDAO deviceTypeDAO;
|
||||
|
||||
public OperationManagerImpl() {
|
||||
commandOperationDAO = OperationManagementDAOFactory.getCommandOperationDAO();
|
||||
@ -66,6 +70,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
operationMappingDAO = OperationManagementDAOFactory.getOperationMappingDAO();
|
||||
operationDAO = OperationManagementDAOFactory.getOperationDAO();
|
||||
deviceDAO = DeviceManagementDAOFactory.getDeviceDAO();
|
||||
deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -169,6 +174,21 @@ public class OperationManagerImpl implements OperationManager {
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
|
||||
if (device.getEnrolmentInfo().getStatus() !=null && !device.getEnrolmentInfo().getStatus().equals(
|
||||
EnrolmentInfo.Status.ACTIVE)){
|
||||
try {
|
||||
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
|
||||
.updateDeviceEnrolmentInfo(device,
|
||||
EnrolmentInfo.Status.ACTIVE);
|
||||
}catch (DeviceManagementException deviceMgtEx){
|
||||
String errorMsg = "Error occurred while update enrol status: "+deviceId.toString();
|
||||
log.error(errorMsg, deviceMgtEx);
|
||||
throw new OperationManagementException(errorMsg, deviceMgtEx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (device == null) {
|
||||
throw new OperationManagementException("Device not found for given device " +
|
||||
"Identifier:" + deviceId.getId() + " and given type:" + deviceId.getType());
|
||||
@ -225,6 +245,20 @@ public class OperationManagerImpl implements OperationManager {
|
||||
}
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
|
||||
.getNextOperation(device.getId());
|
||||
|
||||
if (device.getEnrolmentInfo().getStatus() !=null && !device.getEnrolmentInfo().getStatus().equals(
|
||||
EnrolmentInfo.Status.ACTIVE)){
|
||||
try {
|
||||
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
|
||||
.updateDeviceEnrolmentInfo(device,
|
||||
EnrolmentInfo.Status.ACTIVE);
|
||||
}catch (DeviceManagementException deviceMgtEx){
|
||||
String errorMsg = "Error occurred while update enrol status: "+deviceId.toString();
|
||||
log.error(errorMsg, deviceMgtEx);
|
||||
throw new OperationManagementException(errorMsg, deviceMgtEx);
|
||||
}
|
||||
}
|
||||
|
||||
if (dtoOperation != null) {
|
||||
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND
|
||||
.equals(dtoOperation.getType())) {
|
||||
|
||||
@ -87,4 +87,5 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM
|
||||
*/
|
||||
List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException;
|
||||
|
||||
void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException;
|
||||
}
|
||||
|
||||
@ -137,7 +137,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
DeviceType type = deviceTypeDAO.getDeviceType(device.getType());
|
||||
deviceDAO.updateDevice(type.getId(),device, tenantId);
|
||||
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
try {
|
||||
@ -652,6 +651,22 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status status) throws DeviceManagementException {
|
||||
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
|
||||
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
||||
device.getEnrolmentInfo().setStatus(status);
|
||||
deviceDAO.updateDevice(deviceType.getId(), device, tenantId);
|
||||
}catch (DeviceManagementDAOException deviceDaoEx){
|
||||
String errorMsg = "Error occured update device enrolment status:"+device.getId();
|
||||
log.error(errorMsg, deviceDaoEx);
|
||||
throw new DeviceManagementException(errorMsg, deviceDaoEx);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void registerDeviceManagementService(DeviceManagementService deviceManagementService) {
|
||||
try {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user