Adding more operation mgt test cases.

revert-70aa11f8
sinthuja 7 years ago
parent 0aab7c2e3d
commit 87b160cf19

@ -122,7 +122,7 @@ public class OperationManagerImpl implements OperationManager {
log.debug("operation:[" + operation.toString() + "]"); log.debug("operation:[" + operation.toString() + "]");
for (DeviceIdentifier deviceIdentifier : deviceIds) { for (DeviceIdentifier deviceIdentifier : deviceIds) {
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" +
deviceIdentifier.getType() + "]"); deviceIdentifier.getType() + "]");
} }
} }
try { try {
@ -137,7 +137,7 @@ public class OperationManagerImpl implements OperationManager {
//Send the operation statuses only for admin triggered operations //Send the operation statuses only for admin triggered operations
String deviceType = validDeviceIds.get(0).getType(); String deviceType = validDeviceIds.get(0).getType();
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult, activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult,
deviceType)); deviceType));
return activity; return activity;
} }
@ -160,7 +160,7 @@ public class OperationManagerImpl implements OperationManager {
boolean hasExistingTaskOperation; boolean hasExistingTaskOperation;
int enrolmentId; int enrolmentId;
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;
} }
@ -177,10 +177,10 @@ public class OperationManagerImpl implements OperationManager {
} }
} else if (isNotRepeated) { } else if (isNotRepeated) {
operationDAO.updateEnrollmentOperationsStatus(enrolmentId, operationCode, operationDAO.updateEnrollmentOperationsStatus(enrolmentId, operationCode,
org.wso2.carbon.device.mgt.core.dto.operation.mgt. org.wso2.carbon.device.mgt.core.dto.operation.mgt.
Operation.Status.PENDING, Operation.Status.PENDING,
org.wso2.carbon.device.mgt.core.dto.operation.mgt. org.wso2.carbon.device.mgt.core.dto.operation.mgt.
Operation.Status.REPEATED); Operation.Status.REPEATED);
operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled); operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled);
} else { } else {
operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled); operationMappingDAO.addOperationMapping(operationId, enrolmentId, isScheduled);
@ -200,8 +200,8 @@ public class OperationManagerImpl implements OperationManager {
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.COMPLETED); 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() + " device carrying id '" + deviceId.getType() + " device carrying id '" +
deviceId + "'", e); deviceId + "'", e);
// Reschedule if push notification failed. // Reschedule if push notification failed.
operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED); operationMappingDAO.updateOperationMapping(operationId, enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED);
} }
@ -219,7 +219,7 @@ public class OperationManagerImpl implements OperationManager {
//Get the device-type from 1st valid DeviceIdentifier. We know the 1st element is definitely there. //Get the device-type from 1st valid DeviceIdentifier. We know the 1st element is definitely there.
String deviceType = validDeviceIds.get(0).getType(); String deviceType = validDeviceIds.get(0).getType();
activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult, activity.setActivityStatus(this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult,
deviceType)); deviceType));
} }
return activity; return activity;
} else { } else {
@ -242,7 +242,7 @@ public class OperationManagerImpl implements OperationManager {
//Add the invalid DeviceIds //Add the invalid DeviceIds
for (String id : deviceIdValidationResult.getErrorDeviceIdList()) { for (String id : deviceIdValidationResult.getErrorDeviceIdList()) {
activityStatus = new ActivityStatus(); activityStatus = new ActivityStatus();
activityStatus.setDeviceIdentifier(new DeviceIdentifier(id,deviceType)); activityStatus.setDeviceIdentifier(new DeviceIdentifier(id, deviceType));
activityStatus.setStatus(ActivityStatus.Status.INVALID); activityStatus.setStatus(ActivityStatus.Status.INVALID);
activityStatuses.add(activityStatus); activityStatuses.add(activityStatus);
} }
@ -288,7 +288,7 @@ public class OperationManagerImpl implements OperationManager {
} }
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" + throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
this.getUser(), e); this.getUser(), e);
} }
deviceIDHolder.setValidDeviceIDList(authorizedDeviceList); deviceIDHolder.setValidDeviceIDList(authorizedDeviceList);
deviceIDHolder.setErrorDeviceIdList(unAuthorizedDeviceList); deviceIDHolder.setErrorDeviceIdList(unAuthorizedDeviceList);
@ -310,8 +310,8 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'"); deviceId.getId() + "'");
} }
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId); EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
@ -331,8 +331,8 @@ public class OperationManagerImpl implements OperationManager {
} }
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e); "' device '" + deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -350,15 +350,15 @@ public class OperationManagerImpl implements OperationManager {
String owner = request.getOwner(); String owner = request.getOwner();
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "' of owner '" + owner + "'" ); deviceId.getId() + "' of owner '" + owner + "'");
} }
EnrolmentInfo enrolmentInfo = this.getEnrolmentInfo(deviceId, owner); EnrolmentInfo enrolmentInfo = this.getEnrolmentInfo(deviceId, owner);
if (enrolmentInfo == null) { if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceId.getId() + " and given type" + "Identifier:" + deviceId.getId() + " and given type" +
deviceId.getType()); deviceId.getType());
} }
int enrolmentId = enrolmentInfo.getId(); int enrolmentId = enrolmentInfo.getId();
try { try {
@ -376,8 +376,8 @@ public class OperationManagerImpl implements OperationManager {
paginationResult.setRecordsFiltered(count); paginationResult.setRecordsFiltered(count);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e); "' device '" + deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -390,7 +390,7 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws
OperationManagementException { OperationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]"); log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
} }
@ -399,16 +399,16 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'"); deviceId.getId() + "'");
} }
// //
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId); EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) { if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for the given device Identifier:" + throw new OperationManagementException("Device not found for the given device Identifier:" +
deviceId.getId() + " and given type:" + deviceId.getId() + " and given type:" +
deviceId.getType()); deviceId.getType());
} }
int enrolmentId = enrolmentInfo.getId(); int enrolmentId = enrolmentInfo.getId();
//Changing the enrollment status & attempt count if the device is marked as inactive or unreachable //Changing the enrollment status & attempt count if the device is marked as inactive or unreachable
@ -437,8 +437,8 @@ public class OperationManagerImpl implements OperationManager {
Collections.sort(operations, new OperationCreateTimeComparator()); Collections.sort(operations, new OperationCreateTimeComparator());
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"pending operations assigned for '" + deviceId.getType() + "pending operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e); "' device '" + deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -457,15 +457,15 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'"); deviceId.getId() + "'");
} }
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId); EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) { if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceId.getId() + " and given type" + "Identifier:" + deviceId.getId() + " and given type" +
deviceId.getType()); deviceId.getType());
} }
int enrolmentId = enrolmentInfo.getId(); int enrolmentId = enrolmentInfo.getId();
//Changing the enrollment status & attempt count if the device is marked as inactive or unreachable //Changing the enrollment status & attempt count if the device is marked as inactive or unreachable
@ -479,23 +479,23 @@ public class OperationManagerImpl implements OperationManager {
try { try {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getNextOperation( org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getNextOperation(
enrolmentInfo.getId()); enrolmentInfo.getId());
if (dtoOperation != null) { if (dtoOperation != null) {
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND.equals(dtoOperation.getType() if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND.equals(dtoOperation.getType()
)) { )) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation = commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId()); getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled()); dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.equals(dtoOperation. } else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.equals(dtoOperation.
getType())) { getType())) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.equals(dtoOperation. } else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.equals(dtoOperation.
getType())) { getType())) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.equals(dtoOperation. } else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.equals(dtoOperation.
getType())) { getType())) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
@ -520,15 +520,15 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'"); deviceId.getId() + "'");
} }
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId); EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) { if (enrolmentInfo == null) {
throw new OperationManagementException( throw new OperationManagementException(
"Device not found for device id:" + deviceId.getId() + " " + "type:" + "Device not found for device id:" + deviceId.getId() + " " + "type:" +
deviceId.getType()); deviceId.getType());
} }
try { try {
@ -537,9 +537,9 @@ public class OperationManagerImpl implements OperationManager {
boolean isUpdated = false; boolean isUpdated = false;
if (operation.getStatus() != null) { if (operation.getStatus() != null) {
isUpdated = operationDAO.updateOperationStatus(enrolmentId, operationId, isUpdated = operationDAO.updateOperationStatus(enrolmentId, operationId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt. org.wso2.carbon.device.mgt.core.dto.operation.mgt.
Operation.Status.valueOf(operation.getStatus(). Operation.Status.valueOf(operation.getStatus().
toString())); toString()));
} }
if (operation.getOperationResponse() != null) { if (operation.getOperationResponse() != null) {
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse()); operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
@ -549,7 +549,7 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while updating the operation: " + operationId + " status:" + "Error occurred while updating the operation: " + operationId + " status:" +
operation.getStatus(), e); operation.getStatus(), e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating a transaction", e); throw new OperationManagementException("Error occurred while initiating a transaction", e);
} finally { } finally {
@ -584,56 +584,57 @@ public class OperationManagerImpl implements OperationManager {
Operation operation = null; Operation operation = null;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Operation Id: " + operationId + " Device Type: " + deviceId.getType() + " Device Identifier: " + log.debug("Operation Id: " + operationId + " Device Type: " + deviceId.getType() + " Device Identifier: " +
deviceId.getId()); deviceId.getId());
} }
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'"); deviceId.getId() + "'");
} }
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId); EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) { if (enrolmentInfo == null) {
throw new OperationManagementException("Device not found for given device identifier: " + throw new OperationManagementException("Device not found for given device identifier: " +
deviceId.getId() + " type: " + deviceId.getType()); deviceId.getId() + " type: " + deviceId.getType());
} }
try { try {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation deviceSpecificOperation = operationDAO.
getOperationByDeviceAndId(enrolmentInfo.getId(), getOperationByDeviceAndId(enrolmentInfo.getId(),
operationId); operationId);
if (dtoOperation.getType(). org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = deviceSpecificOperation;
if (deviceSpecificOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation = commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId()); getOperation(deviceSpecificOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled()); dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType(). } else if (deviceSpecificOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) { equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = configOperationDAO.getOperation(deviceSpecificOperation.getId());
} else if (dtoOperation.getType().equals( } else if (deviceSpecificOperation.getType().equals(
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) { org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = profileOperationDAO.getOperation(deviceSpecificOperation.getId());
} else if (dtoOperation.getType().equals( } else if (deviceSpecificOperation.getType().equals(
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) { org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = policyOperationDAO.getOperation(deviceSpecificOperation.getId());
} }
if (dtoOperation == null) { if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for operation Id:" + operationId + throw new OperationManagementException("Operation not found for operation Id:" + operationId +
" device id:" + deviceId.getId()); " device id:" + deviceId.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); dtoOperation.setStatus(deviceSpecificOperation.getStatus());
operation = OperationDAOUtil.convertOperation(deviceSpecificOperation);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "operations assigned for '" + deviceId.getType() +
"' device '" + deviceId.getId() + "'", e); "' device '" + deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening connection to the data source", throw new OperationManagementException("Error occurred while opening connection to the data source",
e); e);
} finally { } finally {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
@ -649,15 +650,15 @@ public class OperationManagerImpl implements OperationManager {
if (!isActionAuthorized(deviceId)) { if (!isActionAuthorized(deviceId)) {
throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" + throw new OperationManagementException("User '" + getUser() + "' is not authorized to access the '" +
deviceId.getType() + "' device, which carries the identifier '" + deviceId.getType() + "' device, which carries the identifier '" +
deviceId.getId() + "'"); deviceId.getId() + "'");
} }
EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId); EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId);
if (enrolmentInfo == null) { if (enrolmentInfo == null) {
throw new OperationManagementException( throw new OperationManagementException(
"Device not found for device id:" + deviceId.getId() + " " + "type:" + "Device not found for device id:" + deviceId.getId() + " " + "type:" +
deviceId.getType()); deviceId.getType());
} }
try { try {
@ -667,14 +668,14 @@ public class OperationManagerImpl implements OperationManager {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString()); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString());
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus)); dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus));
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.
Status.PENDING)); Status.PENDING));
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.
Status.PENDING)); Status.PENDING));
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation. org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.
Status.PENDING)); Status.PENDING));
Operation operation; Operation operation;
@ -685,9 +686,9 @@ public class OperationManagerImpl implements OperationManager {
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the list of " + throw new OperationManagementException("Error occurred while retrieving the list of " +
"operations assigned for '" + deviceId.getType() + "operations assigned for '" + deviceId.getType() +
"' device '" + "' device '" +
deviceId.getId() + "' and status:" + status.toString(), e); deviceId.getId() + "' and status:" + status.toString(), e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -703,32 +704,32 @@ public class OperationManagerImpl implements OperationManager {
try { try {
OperationManagementDAOFactory.openConnection(); OperationManagementDAOFactory.openConnection();
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation( org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation(
operationId); operationId);
if (dtoOperation == null) { if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for given Id:" + operationId); throw new OperationManagementException("Operation not found for given Id:" + operationId);
} }
if (dtoOperation.getType() if (dtoOperation.getType()
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { .equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation; org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
commandOperation = commandOperation =
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO. (org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
getOperation(dtoOperation.getId()); getOperation(dtoOperation.getId());
dtoOperation.setEnabled(commandOperation.isEnabled()); dtoOperation.setEnabled(commandOperation.isEnabled());
} else if (dtoOperation.getType(). } else if (dtoOperation.getType().
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) { equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
PROFILE)) { PROFILE)) {
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type. } else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
POLICY)) { POLICY)) {
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId()); dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the operation with operation Id '" + throw new OperationManagementException("Error occurred while retrieving the operation with operation Id '" +
operationId, e); operationId, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException("Error occurred while opening a connection to the data source", e); throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
} finally { } finally {
@ -808,7 +809,7 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while opening a connection to the data source.", e); throw new OperationManagementException("Error occurred while opening a connection to the data source.", e);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving the operation with activity Id '" + throw new OperationManagementException("Error occurred while retrieving the operation with activity Id '" +
activity, e); activity, e);
} finally { } finally {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
@ -850,7 +851,7 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while opening a connection to the data source.", e); throw new OperationManagementException("Error occurred while opening a connection to the data source.", e);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while getting the activity list changed after a " + throw new OperationManagementException("Error occurred while getting the activity list changed after a " +
"given time.", e); "given time.", e);
} finally { } finally {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
@ -866,7 +867,7 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while opening a connection to the data source.", e); throw new OperationManagementException("Error occurred while opening a connection to the data source.", e);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while getting the activity list changed after a " + throw new OperationManagementException("Error occurred while getting the activity list changed after a " +
"given time.", e); "given time.", e);
} finally { } finally {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
@ -881,7 +882,7 @@ public class OperationManagerImpl implements OperationManager {
throw new OperationManagementException("Error occurred while opening a connection to the data source.", e); throw new OperationManagementException("Error occurred while opening a connection to the data source.", e);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
throw new OperationManagementException("Error occurred while getting the activity count changed after a " + throw new OperationManagementException("Error occurred while getting the activity count changed after a " +
"given time.", e); "given time.", e);
} finally { } finally {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
} }
@ -904,12 +905,18 @@ public class OperationManagerImpl implements OperationManager {
private OperationDAO lookupOperationDAO(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operation) { private OperationDAO lookupOperationDAO(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operation) {
if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) { if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation ||
operation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
return commandOperationDAO; return commandOperationDAO;
} else if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation) { } else if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation ||
operation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) {
return profileOperationDAO; return profileOperationDAO;
} else if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation) { } else if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation ||
operation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
return configOperationDAO; return configOperationDAO;
} else if (operation instanceof org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation ||
operation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) {
return policyOperationDAO;
} else { } else {
return operationDAO; return operationDAO;
} }
@ -966,8 +973,8 @@ public class OperationManagerImpl implements OperationManager {
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, status, tenantId); enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, status, tenantId);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving metadata of '" + throw new OperationManagementException("Error occurred while retrieving metadata of '" +
deviceId.getType() + "' device carrying the identifier '" + deviceId.getType() + "' device carrying the identifier '" +
deviceId.getId() + "'", e); deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -995,15 +1002,15 @@ public class OperationManagerImpl implements OperationManager {
} }
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving enrollment data of '" + throw new OperationManagementException("Error occurred while retrieving enrollment data of '" +
deviceId.getType() + "' device carrying the identifier '" + deviceId.getType() + "' device carrying the identifier '" +
deviceId.getId() + "' of owner '" + owner + "'", e); deviceId.getId() + "' of owner '" + owner + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
} catch (DeviceAccessAuthorizationException e) { } catch (DeviceAccessAuthorizationException e) {
throw new OperationManagementException("Error occurred while checking the device access permissions for '" + throw new OperationManagementException("Error occurred while checking the device access permissions for '" +
deviceId.getType() + "' device carrying the identifier '" + deviceId.getType() + "' device carrying the identifier '" +
deviceId.getId() + "' of owner '" + owner + "'", e); deviceId.getId() + "' of owner '" + owner + "'", e);
} finally { } finally {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
@ -1018,8 +1025,8 @@ public class OperationManagerImpl implements OperationManager {
enrolmentInfo = deviceDAO.getActiveEnrolment(deviceId, tenantId); enrolmentInfo = deviceDAO.getActiveEnrolment(deviceId, tenantId);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
throw new OperationManagementException("Error occurred while retrieving enrollment data of '" + throw new OperationManagementException("Error occurred while retrieving enrollment data of '" +
deviceId.getType() + "' device carrying the identifier '" + deviceId.getType() + "' device carrying the identifier '" +
deviceId.getId() + "'", e); deviceId.getId() + "'", e);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementException( throw new OperationManagementException(
"Error occurred while opening a connection to the data source", e); "Error occurred while opening a connection to the data source", e);
@ -1040,7 +1047,7 @@ public class OperationManagerImpl implements OperationManager {
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction(); DeviceManagementDAOFactory.rollbackTransaction();
throw new OperationManagementException("Error occurred while updating enrollment status of device of " + throw new OperationManagementException("Error occurred while updating enrollment status of device of " +
"enrolment-id '" + enrolmentId + "'", e); "enrolment-id '" + enrolmentId + "'", e);
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
throw new OperationManagementException("Error occurred while initiating a transaction", e); throw new OperationManagementException("Error occurred while initiating a transaction", e);
} finally { } finally {
@ -1055,7 +1062,7 @@ public class OperationManagerImpl implements OperationManager {
List<MonitoringOperation> monitoringOperations = deviceManagementProviderService.getMonitoringOperationList(deviceType);//Get task list from each device type List<MonitoringOperation> monitoringOperations = deviceManagementProviderService.getMonitoringOperationList(deviceType);//Get task list from each device type
for(MonitoringOperation op : monitoringOperations){ for (MonitoringOperation op : monitoringOperations) {
if (operation.getCode().equals(op.getTaskName())) { if (operation.getCode().equals(op.getTaskName())) {
return true; return true;
} }

@ -18,6 +18,7 @@
*/ */
package org.wso2.carbon.device.mgt.core.operation.mgt.dao; package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationEnrolmentMapping;
import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping; import org.wso2.carbon.device.mgt.core.operation.mgt.OperationMapping;

@ -74,11 +74,11 @@ public class CommandOperationDAOImpl extends GenericOperationDAOImpl {
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(id);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE FROM DM_COMMAND_OPERATION WHERE OPERATION_ID = ?"); stmt = connection.prepareStatement("DELETE FROM DM_COMMAND_OPERATION WHERE OPERATION_ID = ?");
stmt.setInt(1, id); stmt.setInt(1, id);
stmt.executeUpdate(); stmt.executeUpdate();
super.deleteOperation(id);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e); throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
} finally { } finally {

@ -62,11 +62,11 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl {
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(id);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE FROM DM_CONFIG_OPERATION WHERE OPERATION_ID = ?") ; stmt = connection.prepareStatement("DELETE FROM DM_CONFIG_OPERATION WHERE OPERATION_ID = ?") ;
stmt.setInt(1, id); stmt.setInt(1, id);
stmt.executeUpdate(); stmt.executeUpdate();
super.deleteOperation(id);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e); throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
} finally { } finally {

@ -833,9 +833,9 @@ public class GenericOperationDAOImpl implements OperationDAO {
Operation operation = null; Operation operation = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE, " + String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, om.STATUS, o.OPERATION_CODE, " +
"om.ID AS OM_MAPPING_ID, " + "om.ID AS OM_MAPPING_ID, " +
"om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," + "om.UPDATED_TIMESTAMP FROM (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP," +
"OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " + "OPERATION_CODE FROM DM_OPERATION WHERE id = ?) o INNER JOIN (SELECT * FROM " +
"DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " + "DM_ENROLMENT_OP_MAPPING dm where dm.OPERATION_ID = ? AND dm.ENROLMENT_ID = ?) om " +
"ON o.ID = om.OPERATION_ID "; "ON o.ID = om.OPERATION_ID ";
@ -850,6 +850,7 @@ public class GenericOperationDAOImpl implements OperationDAO {
operation.setId(rs.getInt("ID")); operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE"))); operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString()); operation.setCreatedTimeStamp(rs.getTimestamp("CREATED_TIMESTAMP").toString());
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));
// if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) { // if (rs.getTimestamp("RECEIVED_TIMESTAMP") == null) {
// operation.setReceivedTimeStamp(""); // operation.setReceivedTimeStamp("");
// } else { // } else {

@ -126,11 +126,11 @@ public class PolicyOperationDAOImpl extends GenericOperationDAOImpl {
public void deleteOperation(int operationId) throws OperationManagementDAOException { public void deleteOperation(int operationId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(operationId);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE FROM DM_POLICY_OPERATION WHERE OPERATION_ID=?"); stmt = connection.prepareStatement("DELETE FROM DM_POLICY_OPERATION WHERE OPERATION_ID=?");
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.executeUpdate(); stmt.executeUpdate();
super.deleteOperation(operationId);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e); throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
} finally { } finally {

@ -127,11 +127,11 @@ public class ProfileOperationDAOImpl extends GenericOperationDAOImpl {
public void deleteOperation(int id) throws OperationManagementDAOException { public void deleteOperation(int id) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
super.deleteOperation(id);
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("DELETE FROM DM_PROFILE_OPERATION WHERE OPERATION_ID=?"); stmt = connection.prepareStatement("DELETE FROM DM_PROFILE_OPERATION WHERE OPERATION_ID=?");
stmt.setInt(1, id); stmt.setInt(1, id);
stmt.executeUpdate(); stmt.executeUpdate();
super.deleteOperation(id);
} catch (SQLException e) { } catch (SQLException e) {
throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e); throw new OperationManagementDAOException("Error occurred while deleting operation metadata", e);
} finally { } finally {

@ -35,6 +35,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.ActivityStatus;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; 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.OperationManagementException;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.core.TestDeviceManagementService; import org.wso2.carbon.device.mgt.core.TestDeviceManagementService;
import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl; import org.wso2.carbon.device.mgt.core.authorization.DeviceAccessAuthorizationServiceImpl;
import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest; import org.wso2.carbon.device.mgt.core.common.BaseDeviceManagementTest;
@ -64,7 +65,7 @@ import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
public class OperationManagementTests{ public class OperationManagementTests extends BaseDeviceManagementTest{
private static final Log log = LogFactory.getLog(OperationManagementTests.class); private static final Log log = LogFactory.getLog(OperationManagementTests.class);
private static final String DEVICE_TYPE = "OP_TEST_TYPE"; private static final String DEVICE_TYPE = "OP_TEST_TYPE";
@ -80,6 +81,7 @@ public class OperationManagementTests{
private List<DeviceIdentifier> deviceIds = new ArrayList<>(); private List<DeviceIdentifier> deviceIds = new ArrayList<>();
private OperationManager operationMgtService; private OperationManager operationMgtService;
private Activity commandActivity;
@BeforeClass @BeforeClass
public void init() throws Exception { public void init() throws Exception {
@ -122,9 +124,9 @@ public class OperationManagementTests{
@Test @Test
public void addCommandOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException { public void addCommandOperation() throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
Activity activity = this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE), this.commandActivity = this.operationMgtService.addOperation(getOperation(new CommandOperation(), Operation.Type.COMMAND, COMMAND_OPERATON_CODE),
this.deviceIds); this.deviceIds);
validateOperationResponse(activity); validateOperationResponse(this.commandActivity);
} }
@Test(dependsOnMethods = "addCommandOperation") @Test(dependsOnMethods = "addCommandOperation")
@ -209,7 +211,7 @@ public class OperationManagementTests{
try { try {
this.operationMgtService.getOperations(deviceIdentifier, request); this.operationMgtService.getOperations(deviceIdentifier, request);
} catch (OperationManagementException ex) { } catch (OperationManagementException ex) {
if (ex.getMessage() == null){ if (ex.getMessage() == null) {
Assert.assertTrue(ex.getMessage().contains("User '" + NON_ADMIN_USER + "' is not authorized")); Assert.assertTrue(ex.getMessage().contains("User '" + NON_ADMIN_USER + "' is not authorized"));
} }
} }
@ -221,7 +223,7 @@ public class OperationManagementTests{
public void updateOperation() throws OperationManagementException { public void updateOperation() throws OperationManagementException {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0); DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
List operations = this.operationMgtService.getPendingOperations(deviceIdentifier); List operations = this.operationMgtService.getPendingOperations(deviceIdentifier);
Assert.assertTrue(operations!= null && operations.size()==4); Assert.assertTrue(operations != null && operations.size() == 4);
Operation operation = (Operation) operations.get(0); Operation operation = (Operation) operations.get(0);
operation.setStatus(Operation.Status.COMPLETED); operation.setStatus(Operation.Status.COMPLETED);
operation.setOperationResponse("The operation is successfully completed"); operation.setOperationResponse("The operation is successfully completed");
@ -229,4 +231,36 @@ public class OperationManagementTests{
List pendingOperations = this.operationMgtService.getPendingOperations(deviceIdentifier); List pendingOperations = this.operationMgtService.getPendingOperations(deviceIdentifier);
Assert.assertEquals(pendingOperations.size(), 3); Assert.assertEquals(pendingOperations.size(), 3);
} }
@Test(dependsOnMethods = "updateOperation")
public void getNextPendingOperation() throws OperationManagementException {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
Operation operation = this.operationMgtService.getNextPendingOperation(deviceIdentifier);
Assert.assertTrue(operation.getType().equals(Operation.Type.POLICY));
}
@Test(dependsOnMethods = "getNextPendingOperation", enabled = false)
public void deleteOperation() throws OperationManagementException {
//TODO: Verify the operation management service operations.
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
Operation operation = this.operationMgtService.getNextPendingOperation(deviceIdentifier);
this.operationMgtService.deleteOperation(operation.getId());
Operation operationAfterDeletion = this.operationMgtService.getNextPendingOperation(deviceIdentifier);
Assert.assertTrue(operation.getId() != operation.getId());
Assert.assertTrue(operationAfterDeletion.getType().equals(Operation.Type.POLICY));
}
@Test(dependsOnMethods = "getNextPendingOperation")
public void getOperationByDeviceAndOperationId() throws OperationManagementException {
DeviceIdentifier deviceIdentifier = this.deviceIds.get(0);
String operationId = this.commandActivity.getActivityId().
replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, "");
Operation operation = this.operationMgtService.getOperationByDeviceAndOperationId(deviceIdentifier,
Integer.parseInt(operationId));
Assert.assertTrue(operation.getStatus().equals(Operation.Status.COMPLETED));
Assert.assertTrue(operation.getType().equals(Operation.Type.COMMAND));
}
} }

Loading…
Cancel
Save