|
|
@ -155,6 +155,7 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
|
|
|
|
|
|
|
boolean hasExistingTaskOperation;
|
|
|
|
boolean hasExistingTaskOperation;
|
|
|
|
int enrolmentId;
|
|
|
|
int enrolmentId;
|
|
|
|
|
|
|
|
List<Device> devices = new ArrayList<>();
|
|
|
|
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT == operationDto.
|
|
|
|
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT == operationDto.
|
|
|
|
getControl()) {
|
|
|
|
getControl()) {
|
|
|
|
isNotRepeated = true;
|
|
|
|
isNotRepeated = true;
|
|
|
@ -164,6 +165,7 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
String operationCode = operationDto.getCode();
|
|
|
|
String operationCode = operationDto.getCode();
|
|
|
|
for (DeviceIdentifier deviceId : authorizedDeviceList) {
|
|
|
|
for (DeviceIdentifier deviceId : authorizedDeviceList) {
|
|
|
|
Device device = getDevice(deviceId);
|
|
|
|
Device device = getDevice(deviceId);
|
|
|
|
|
|
|
|
devices.add(device);
|
|
|
|
enrolmentId = device.getEnrolmentInfo().getId();
|
|
|
|
enrolmentId = device.getEnrolmentInfo().getId();
|
|
|
|
//Do not repeat the task operations
|
|
|
|
//Do not repeat the task operations
|
|
|
|
if (isScheduledOperation) {
|
|
|
|
if (isScheduledOperation) {
|
|
|
@ -181,30 +183,46 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled);
|
|
|
|
operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
/*
|
|
|
|
If notification strategy has not enable to send push notification using scheduler task
|
|
|
|
If notification strategy has not enable to send push notification using scheduler task we will send
|
|
|
|
we will send notification immediately
|
|
|
|
notification immediately. This is done in separate loop inorder to prevent overlap with DB insert
|
|
|
|
|
|
|
|
operations with the possible db update operations trigger followed by pending operation call.
|
|
|
|
|
|
|
|
Otherwise device may call pending operation while DB is locked for write and deadlock can occur.
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
if (notificationStrategy != null && !isScheduled) {
|
|
|
|
if (notificationStrategy != null && !isScheduled) {
|
|
|
|
try {
|
|
|
|
for (Device device : devices) {
|
|
|
|
|
|
|
|
DeviceIdentifier deviceId = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
log.debug("Sending push notification to " + deviceId + " from add operation method.");
|
|
|
|
log.debug("Sending push notification to " + deviceId + " from add operation method.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
operation.setId(operationId);
|
|
|
|
operation.setId(operationId);
|
|
|
|
operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
|
|
|
|
operation.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
|
|
|
|
|
|
|
|
try {
|
|
|
|
notificationStrategy.execute(new NotificationContext(deviceId, operation));
|
|
|
|
notificationStrategy.execute(new NotificationContext(deviceId, operation));
|
|
|
|
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.COMPLETED);
|
|
|
|
|
|
|
|
} catch (PushNotificationExecutionFailedException e) {
|
|
|
|
} catch (PushNotificationExecutionFailedException e) {
|
|
|
|
log.error("Error occurred while sending push notifications to " +
|
|
|
|
log.error("Error occurred while sending push notifications to " + deviceId.getType() +
|
|
|
|
deviceId.getType() + " device carrying id '" +
|
|
|
|
" device carrying id '" + deviceId + "'", e);
|
|
|
|
deviceId + "'", e);
|
|
|
|
/*
|
|
|
|
// Reschedule if push notification failed.
|
|
|
|
Reschedule if push notification failed. Doing db transactions in atomic way to prevent
|
|
|
|
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED);
|
|
|
|
deadlocks.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
enrolmentId = device.getEnrolmentInfo().getId();
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon
|
|
|
|
|
|
|
|
.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED);
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
} catch (OperationManagementDAOException ex) {
|
|
|
|
|
|
|
|
// Not throwing this exception in order to keep sending remaining notifications if any.
|
|
|
|
|
|
|
|
log.error("Error occurred while setting push notification status to SCHEDULED.", ex);
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
|
|
|
|
Activity activity = new Activity();
|
|
|
|
Activity activity = new Activity();
|
|
|
|
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
|
|
|
|
activity.setActivityId(DeviceManagementConstants.OperationAttributes.ACTIVITY + operationId);
|
|
|
|
activity.setCode(operationCode);
|
|
|
|
activity.setCode(operationCode);
|
|
|
|