|
|
|
@ -165,52 +165,52 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("operation:[" + operation.toString() + "]");
|
|
|
|
|
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
|
|
|
|
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" +
|
|
|
|
|
deviceIdentifier.getType() + "]");
|
|
|
|
|
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType()
|
|
|
|
|
+ "]");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
|
|
|
|
|
List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
|
|
|
|
|
if (validDeviceIds.size() > 0) {
|
|
|
|
|
DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
|
|
|
|
|
List<DeviceIdentifier> authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList();
|
|
|
|
|
if (authorizedDeviceIds.size() <= 0) {
|
|
|
|
|
log.warn("User : " + getUser() + " is not authorized to perform operations on given device-list.");
|
|
|
|
|
Activity activity = new Activity();
|
|
|
|
|
//Send the operation statuses only for admin triggered operations
|
|
|
|
|
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
|
|
|
|
|
deviceAuthorizationResult));
|
|
|
|
|
return activity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
|
|
|
|
|
String initiatedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
if (initiatedBy == null && isScheduledOperation) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("initiatedBy : " + SYSTEM);
|
|
|
|
|
}
|
|
|
|
|
operation.setInitiatedBy(SYSTEM);
|
|
|
|
|
} else {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("initiatedBy : " + initiatedBy);
|
|
|
|
|
}
|
|
|
|
|
operation.setInitiatedBy(initiatedBy);
|
|
|
|
|
}
|
|
|
|
|
DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds);
|
|
|
|
|
List<DeviceIdentifier> validDeviceIds = deviceValidationResult.getValidDeviceIDList();
|
|
|
|
|
if (!validDeviceIds.isEmpty()) {
|
|
|
|
|
DeviceIDHolder deviceAuthorizationResult = this.authorizeDevices(operation, validDeviceIds);
|
|
|
|
|
List<DeviceIdentifier> authorizedDeviceIds = deviceAuthorizationResult.getValidDeviceIDList();
|
|
|
|
|
if (authorizedDeviceIds.isEmpty()) {
|
|
|
|
|
log.warn("User : " + getUser() + " is not authorized to perform operations on given device-list.");
|
|
|
|
|
Activity activity = new Activity();
|
|
|
|
|
//Send the operation statuses only for admin triggered operations
|
|
|
|
|
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
|
|
|
|
|
return activity;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
|
|
|
|
OperationDAOUtil.convertOperation(operation);
|
|
|
|
|
String operationCode = operationDto.getCode();
|
|
|
|
|
Map<Integer, Device> enrolments = new HashMap<>();
|
|
|
|
|
Device device;
|
|
|
|
|
for (DeviceIdentifier deviceId : authorizedDeviceIds) {
|
|
|
|
|
device = getDevice(deviceId);
|
|
|
|
|
enrolments.put(device.getEnrolmentInfo().getId(), device);
|
|
|
|
|
boolean isScheduledOperation = this.isTaskScheduledOperation(operation);
|
|
|
|
|
String initiatedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
if (initiatedBy == null && isScheduledOperation) {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("initiatedBy : " + SYSTEM);
|
|
|
|
|
}
|
|
|
|
|
operation.setInitiatedBy(SYSTEM);
|
|
|
|
|
} else {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("initiatedBy : " + initiatedBy);
|
|
|
|
|
}
|
|
|
|
|
operation.setInitiatedBy(initiatedBy);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto = OperationDAOUtil
|
|
|
|
|
.convertOperation(operation);
|
|
|
|
|
String operationCode = operationDto.getCode();
|
|
|
|
|
Map<Integer, Device> enrolments = new HashMap<>();
|
|
|
|
|
Device device;
|
|
|
|
|
for (DeviceIdentifier deviceId : authorizedDeviceIds) {
|
|
|
|
|
device = getDevice(deviceId);
|
|
|
|
|
enrolments.put(device.getEnrolmentInfo().getId(), device);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
|
if (operationDto.getControl() ==
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
|
|
|
|
|
if (operationDto.getControl()
|
|
|
|
|
== org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Control.NO_REPEAT) {
|
|
|
|
|
Map<Integer, Integer> pendingOperationIDs = operationDAO
|
|
|
|
|
.getExistingOperationIDs(enrolments.keySet().toArray(new Integer[0]), operationCode);
|
|
|
|
|
for (Integer enrolmentId : pendingOperationIDs.keySet()) {
|
|
|
|
@ -227,8 +227,8 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
+ operationCode);
|
|
|
|
|
}
|
|
|
|
|
Activity activity = new Activity();
|
|
|
|
|
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
|
|
|
|
|
deviceAuthorizationResult));
|
|
|
|
|
activity.setActivityStatus(
|
|
|
|
|
this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
|
|
|
|
|
return activity;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -242,20 +242,20 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
activity.setType(Activity.Type.valueOf(operationDto.getType().toString()));
|
|
|
|
|
//For now set the operation statuses only for admin triggered operations
|
|
|
|
|
if (!isScheduledOperation) {
|
|
|
|
|
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult,
|
|
|
|
|
deviceAuthorizationResult));
|
|
|
|
|
activity.setActivityStatus(
|
|
|
|
|
this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult));
|
|
|
|
|
}
|
|
|
|
|
return activity;
|
|
|
|
|
} else {
|
|
|
|
|
throw new InvalidDeviceException("Invalid device Identifiers found.");
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException("Error occurred while adding operation", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while initiating the transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException("Error occurred while adding operation", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while initiating the transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
} else {
|
|
|
|
|
throw new InvalidDeviceException("Invalid device Identifiers found.");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|