|
|
|
@ -24,12 +24,14 @@ import org.wso2.carbon.context.CarbonContext;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
|
|
|
|
import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException;
|
|
|
|
|
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.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;
|
|
|
|
@ -76,44 +78,54 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
log.debug("operation:[" + operation.toString() + "]");
|
|
|
|
|
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
|
|
|
|
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" +
|
|
|
|
|
deviceIdentifier.getType() + "]");
|
|
|
|
|
deviceIdentifier.getType() + "]");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
List<EnrolmentInfo> enrolments;
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
enrolments = deviceDAO.getEnrolmentsByStatus(deviceIds, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening a connection the data " +
|
|
|
|
|
"source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
|
|
|
|
OperationDAOUtil.convertOperation(operation);
|
|
|
|
|
|
|
|
|
|
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
|
|
|
|
|
|
|
|
|
for (EnrolmentInfo enrolmentInfo : enrolments) {
|
|
|
|
|
operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId());
|
|
|
|
|
List<DeviceIdentifier> authorizedDeviceList = DeviceManagementDataHolder.getInstance().
|
|
|
|
|
getDeviceAccessAuthorizationService().isUserAuthorized(deviceIds).getAuthorizedDevices();
|
|
|
|
|
if (authorizedDeviceList.size() > 0) {
|
|
|
|
|
try {
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
List<EnrolmentInfo> enrolments;
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
enrolments = deviceDAO.getEnrolmentsByStatus(deviceIds, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening a connection the data " +
|
|
|
|
|
"source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operationDto =
|
|
|
|
|
OperationDAOUtil.convertOperation(operation);
|
|
|
|
|
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
|
|
|
|
for (EnrolmentInfo enrolmentInfo : enrolments) {
|
|
|
|
|
operationMappingDAO.addOperationMapping(operationId, enrolmentInfo.getId());
|
|
|
|
|
}
|
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
|
return operationId;
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException("Error occurred while adding operation", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving device metadata", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while initiating the transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.info("User : " + getUser() + " is not authorized to perform operations on given device-list.");
|
|
|
|
|
}
|
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
|
return operationId;
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException("Error occurred while adding operation", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving device metadata", e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while initiating the transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
|
|
|
|
this.getUser(), e);
|
|
|
|
|
}
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -121,45 +133,58 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
int enrolmentId;
|
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException("Device not found for given device " +
|
|
|
|
|
"Identifier:" + deviceId.getId() + " and given type" + deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
|
|
|
|
|
operationDAO.getOperationsForDevice(enrolmentId);
|
|
|
|
|
|
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
|
|
|
|
|
Operation operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
|
|
|
|
isUserAuthorized(deviceId);
|
|
|
|
|
if (isUserAuthorized) {
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException("Device not found for given device " +
|
|
|
|
|
"Identifier:" + deviceId.getId() + " and given type" +
|
|
|
|
|
deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
|
|
|
|
|
operationDAO.getOperationsForDevice(enrolmentId);
|
|
|
|
|
|
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
|
|
|
|
|
Operation operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
}
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
|
"operations assigned for '" + deviceId.getType() +
|
|
|
|
|
"' device '" + deviceId.getId() + "'", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
|
|
|
|
|
deviceId.getType() + "' device carrying the identifier '" +
|
|
|
|
|
deviceId.getId() + "'");
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException(
|
|
|
|
|
"Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.info("User : " + getUser() + " is not authorized to fetch operations on device : " + deviceId.getId());
|
|
|
|
|
}
|
|
|
|
|
return operations;
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
|
"operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId() + "'", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving metadata of '" +
|
|
|
|
|
deviceId.getType() + "' device carrying the identifier '" + deviceId.getId() + "'");
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
|
|
|
|
|
this.getUser(), e);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return operations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public List<? extends Operation> getPendingOperations(
|
|
|
|
|
DeviceIdentifier deviceId) throws OperationManagementException {
|
|
|
|
|
public List<? extends Operation> getPendingOperations(DeviceIdentifier deviceId) throws
|
|
|
|
|
OperationManagementException {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
|
|
|
|
|
}
|
|
|
|
@ -167,113 +192,130 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
|
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = new ArrayList<>();
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException("Device not found for the given device Identifier:" +
|
|
|
|
|
deviceId.getId() + " and given type:" + deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
|
|
|
|
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
|
|
|
|
|
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(
|
|
|
|
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
|
|
|
|
|
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(
|
|
|
|
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
|
|
|
|
|
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(
|
|
|
|
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
|
|
|
|
|
Operation operation;
|
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
|
|
|
|
isUserAuthorized(deviceId);
|
|
|
|
|
if (isUserAuthorized) {
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException("Device not found for the given device Identifier:" +
|
|
|
|
|
deviceId.getId() + " and given type:" +
|
|
|
|
|
deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
|
|
|
|
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(
|
|
|
|
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(
|
|
|
|
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(
|
|
|
|
|
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
Operation operation;
|
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
}
|
|
|
|
|
Collections.sort(operations, new OperationCreateTimeComparator());
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
|
"pending operations assigned for '" + deviceId.getType() +
|
|
|
|
|
"' device '" + deviceId.getId() + "'", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
|
|
|
"for device Identifier type -'" + deviceId.getType() +
|
|
|
|
|
"' and device Id '" + deviceId.getId() + "'", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException(
|
|
|
|
|
"Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
|
|
|
|
|
+ deviceId.getId());
|
|
|
|
|
}
|
|
|
|
|
Collections.sort(operations, new OperationCreateTimeComparator());
|
|
|
|
|
return operations;
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
|
"pending operations assigned for '" + deviceId.getType() + "' device '" +
|
|
|
|
|
deviceId.getId() + "'", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
|
|
|
"for device Identifier type -'" + deviceId.getType() + "' and device Id '"
|
|
|
|
|
+ deviceId.getId() + "'", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
|
|
|
|
this.getUser(), e);
|
|
|
|
|
}
|
|
|
|
|
return operations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType()
|
|
|
|
|
+ "]");
|
|
|
|
|
log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]");
|
|
|
|
|
}
|
|
|
|
|
Operation operation = null;
|
|
|
|
|
int enrolmentId;
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException("Device not found for given device " +
|
|
|
|
|
"Identifier:" + deviceId.getId() + " and given type" + deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
|
|
|
|
|
.getNextOperation(enrolmentId);
|
|
|
|
|
|
|
|
|
|
if (dtoOperation != null) {
|
|
|
|
|
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;
|
|
|
|
|
commandOperation =
|
|
|
|
|
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO
|
|
|
|
|
.getOperation(dtoOperation.getId());
|
|
|
|
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
|
|
|
|
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG
|
|
|
|
|
.equals(dtoOperation.getType())) {
|
|
|
|
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE
|
|
|
|
|
.equals(dtoOperation.getType())) {
|
|
|
|
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
|
|
|
|
.POLICY.equals(dtoOperation.getType())) {
|
|
|
|
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
|
|
|
|
isUserAuthorized(deviceId);
|
|
|
|
|
if (isUserAuthorized) {
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException("Device not found for given device " +
|
|
|
|
|
"Identifier:" + deviceId.getId() + " and given type" +
|
|
|
|
|
deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
|
|
|
|
|
getNextOperation(enrolmentId);
|
|
|
|
|
if (dtoOperation != null) {
|
|
|
|
|
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;
|
|
|
|
|
commandOperation =
|
|
|
|
|
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
|
|
|
|
|
getOperation(dtoOperation.getId());
|
|
|
|
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
|
|
|
|
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG.
|
|
|
|
|
equals(dtoOperation.getType())) {
|
|
|
|
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE.
|
|
|
|
|
equals(dtoOperation.getType())) {
|
|
|
|
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY.
|
|
|
|
|
equals(dtoOperation.getType())) {
|
|
|
|
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
}
|
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
}
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
|
|
|
"for device Identifier type -'" + deviceId.getType() +
|
|
|
|
|
"' and device Id '" + deviceId.getId(), e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException(
|
|
|
|
|
"Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
} else {
|
|
|
|
|
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
|
|
|
|
|
+ deviceId.getId());
|
|
|
|
|
}
|
|
|
|
|
return operation;
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving next pending operation", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
|
|
|
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" + deviceId.getId(), e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user : " +
|
|
|
|
|
this.getUser(), e);
|
|
|
|
|
}
|
|
|
|
|
return operation;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -284,39 +326,52 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
}
|
|
|
|
|
int enrolmentId;
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
|
|
if (operation.getStatus() != null) {
|
|
|
|
|
operationDAO.updateOperationStatus(enrolmentId, operationId,
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
|
|
|
|
|
.valueOf(operation.getStatus().toString()));
|
|
|
|
|
}
|
|
|
|
|
if (operation.getOperationResponse() != null) {
|
|
|
|
|
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
|
|
|
|
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
|
|
|
|
isUserAuthorized(deviceId);
|
|
|
|
|
if (isUserAuthorized) {
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening a connection to the" +
|
|
|
|
|
" data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
|
if (operation.getStatus() != null) {
|
|
|
|
|
operationDAO.updateOperationStatus(enrolmentId, operationId,
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.
|
|
|
|
|
valueOf(operation.getStatus().toString()));
|
|
|
|
|
}
|
|
|
|
|
if (operation.getOperationResponse() != null) {
|
|
|
|
|
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
|
|
|
|
|
}
|
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException(
|
|
|
|
|
"Error occurred while updating the operation: " + operationId + " status:" +
|
|
|
|
|
operation.getStatus(), e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException(
|
|
|
|
|
"Error occurred while fetching the device for device identifier: " + deviceId.getId() +
|
|
|
|
|
"type:" + deviceId.getType(), e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while initiating a transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.info("User : " + getUser() + " is not authorized to update operations on device : "
|
|
|
|
|
+ deviceId.getId());
|
|
|
|
|
}
|
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException("Error occurred while updating the operation: " + operationId +
|
|
|
|
|
" status:" + operation.getStatus(), e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
|
throw new OperationManagementException("Error occurred while fetching the device for device identifier: " +
|
|
|
|
|
deviceId.getId() + "type:" + deviceId.getType(), e);
|
|
|
|
|
} catch (TransactionManagementException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while initiating a transaction", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
|
|
|
|
this.getUser(), e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -324,14 +379,12 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
public void deleteOperation(int operationId) throws OperationManagementException {
|
|
|
|
|
try {
|
|
|
|
|
OperationManagementDAOFactory.beginTransaction();
|
|
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation operation =
|
|
|
|
|
operationDAO.getOperation(operationId);
|
|
|
|
|
if (operation == null) {
|
|
|
|
|
throw new OperationManagementException("Operation not found for operation id:" + operationId);
|
|
|
|
|
throw new OperationManagementException("Operation not found for operation id : " + operationId);
|
|
|
|
|
}
|
|
|
|
|
lookupOperationDAO(operation).deleteOperation(operationId);
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.commitTransaction();
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
OperationManagementDAOFactory.rollbackTransaction();
|
|
|
|
@ -347,64 +400,75 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
|
|
|
|
|
throws OperationManagementException {
|
|
|
|
|
int enrolmentId;
|
|
|
|
|
Operation operation;
|
|
|
|
|
Operation operation = null;
|
|
|
|
|
if (log.isDebugEnabled()) {
|
|
|
|
|
log.debug("Operation Id:" + operationId + " Device Type:" + deviceId.getType() + " Device Identifier:" +
|
|
|
|
|
deviceId.getId());
|
|
|
|
|
log.debug("Operation Id: " + operationId + " Device Type: " + deviceId.getType() + " Device Identifier: " +
|
|
|
|
|
deviceId.getId());
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException("Device not found for given device identifier:" +
|
|
|
|
|
deviceId.getId() + " type:" + deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
|
|
|
|
|
.getOperationByDeviceAndId(enrolmentId, operationId);
|
|
|
|
|
|
|
|
|
|
if (dtoOperation.getType()
|
|
|
|
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
|
|
|
|
commandOperation =
|
|
|
|
|
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
|
|
|
|
|
getOperation(dtoOperation.getId());
|
|
|
|
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
|
|
|
|
} else if (dtoOperation.getType()
|
|
|
|
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
|
|
|
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (dtoOperation.getType().equals(
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) {
|
|
|
|
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (dtoOperation.getType().equals(
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) {
|
|
|
|
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dtoOperation == null) {
|
|
|
|
|
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
|
|
|
|
|
" device id:" + deviceId.getId());
|
|
|
|
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
|
|
|
|
isUserAuthorized(deviceId);
|
|
|
|
|
if (isUserAuthorized) {
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException("Device not found for given device identifier: " +
|
|
|
|
|
deviceId.getId() + " type: " + deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
|
|
|
|
|
getOperationByDeviceAndId(enrolmentId, operationId);
|
|
|
|
|
if (dtoOperation.getType().
|
|
|
|
|
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
|
|
|
|
commandOperation =
|
|
|
|
|
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
|
|
|
|
|
getOperation(dtoOperation.getId());
|
|
|
|
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
|
|
|
|
} else if (dtoOperation.getType().
|
|
|
|
|
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
|
|
|
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (dtoOperation.getType().equals(
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.PROFILE)) {
|
|
|
|
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (dtoOperation.getType().equals(
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.POLICY)) {
|
|
|
|
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dtoOperation == null) {
|
|
|
|
|
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
|
|
|
|
|
" device id:" + deviceId.getId());
|
|
|
|
|
}
|
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
|
"operations assigned for '" + deviceId.getType() +
|
|
|
|
|
"' device '" + deviceId.getId() + "'", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
|
|
|
"for device Identifier type -'" + deviceId.getType() +
|
|
|
|
|
"' and device Id '" + deviceId.getId() + "'", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening connection to the data source",
|
|
|
|
|
e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
|
|
|
|
|
+ deviceId.getId());
|
|
|
|
|
}
|
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
|
"operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId()
|
|
|
|
|
+ "'", e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
|
|
|
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" +
|
|
|
|
|
deviceId.getId() + "'", e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
|
|
|
|
this.getUser(), e);
|
|
|
|
|
}
|
|
|
|
|
return operation;
|
|
|
|
|
}
|
|
|
|
@ -413,59 +477,69 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
public List<? extends Operation> getOperationsByDeviceAndStatus(
|
|
|
|
|
DeviceIdentifier deviceId, Operation.Status status) throws OperationManagementException {
|
|
|
|
|
List<Operation> operations = new ArrayList<>();
|
|
|
|
|
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
|
|
|
|
new ArrayList<>();
|
|
|
|
|
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = new ArrayList<>();
|
|
|
|
|
int enrolmentId;
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException("Device not found for device id:" + deviceId.getId() + " " +
|
|
|
|
|
"type:" + deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status dtoOpStatus = org.wso2.carbon.device
|
|
|
|
|
.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString());
|
|
|
|
|
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus));
|
|
|
|
|
|
|
|
|
|
dtoOperationList.addAll(
|
|
|
|
|
configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
|
|
|
|
|
dtoOperationList.addAll(
|
|
|
|
|
profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
|
|
|
|
|
dtoOperationList.addAll(
|
|
|
|
|
policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
|
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
boolean isUserAuthorized = DeviceManagementDataHolder.getInstance().getDeviceAccessAuthorizationService().
|
|
|
|
|
isUserAuthorized(deviceId);
|
|
|
|
|
if (isUserAuthorized) {
|
|
|
|
|
try {
|
|
|
|
|
try {
|
|
|
|
|
DeviceManagementDAOFactory.openConnection();
|
|
|
|
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
|
|
|
|
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
|
|
|
|
} finally {
|
|
|
|
|
DeviceManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
OperationManagementDAOFactory.openConnection();
|
|
|
|
|
|
|
|
|
|
if (enrolmentId < 0) {
|
|
|
|
|
throw new OperationManagementException(
|
|
|
|
|
"Device not found for device id:" + deviceId.getId() + " " + "type:" +
|
|
|
|
|
deviceId.getType());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status dtoOpStatus =
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.valueOf(status.toString());
|
|
|
|
|
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus));
|
|
|
|
|
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
|
|
|
|
|
|
|
|
|
Operation operation;
|
|
|
|
|
|
|
|
|
|
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
|
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
operations.add(operation);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
|
"operations assigned for '" + deviceId.getType() +
|
|
|
|
|
"' device '" +
|
|
|
|
|
deviceId.getId() + "' and status:" + status.toString(), e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
|
|
|
"for device Identifier type -'" + deviceId.getType() +
|
|
|
|
|
"' and device Id '" + deviceId.getId(), e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException(
|
|
|
|
|
"Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log.info("User : " + getUser() + " is not authorized to fetch operations on device : "
|
|
|
|
|
+ deviceId.getId());
|
|
|
|
|
}
|
|
|
|
|
return operations;
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
|
|
|
|
"operations assigned for '" + deviceId.getType() + "' device '" +
|
|
|
|
|
deviceId.getId() + "' and status:" + status.toString(), e);
|
|
|
|
|
} catch (DeviceManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the device " +
|
|
|
|
|
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" + deviceId.getId(), e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
|
OperationManagementDAOFactory.closeConnection();
|
|
|
|
|
} catch (DeviceAccessAuthorizationException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while authorizing access to the devices for user :" +
|
|
|
|
|
this.getUser(), e);
|
|
|
|
|
}
|
|
|
|
|
return operations;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@ -473,35 +547,32 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
Operation operation;
|
|
|
|
|
try {
|
|
|
|
|
OperationManagementDAOFactory.getConnection();
|
|
|
|
|
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.getOperation
|
|
|
|
|
(operationId);
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO.
|
|
|
|
|
getOperation(operationId);
|
|
|
|
|
if (dtoOperation == null) {
|
|
|
|
|
throw new OperationManagementException("Operation not found for given Id:" + operationId);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (dtoOperation.getType()
|
|
|
|
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
|
|
|
|
if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
|
|
|
|
org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation commandOperation;
|
|
|
|
|
commandOperation =
|
|
|
|
|
(org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation) commandOperationDAO.
|
|
|
|
|
getOperation(dtoOperation.getId());
|
|
|
|
|
getOperation(dtoOperation.getId());
|
|
|
|
|
dtoOperation.setEnabled(commandOperation.isEnabled());
|
|
|
|
|
} else if (dtoOperation.getType()
|
|
|
|
|
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
|
|
|
|
} else if (dtoOperation.getType().
|
|
|
|
|
equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.CONFIG)) {
|
|
|
|
|
dtoOperation = configOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
|
|
|
|
.PROFILE)) {
|
|
|
|
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
|
|
|
|
|
PROFILE)) {
|
|
|
|
|
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
|
|
|
|
.POLICY)) {
|
|
|
|
|
|
|
|
|
|
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.
|
|
|
|
|
POLICY)) {
|
|
|
|
|
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
|
|
|
|
}
|
|
|
|
|
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
|
|
|
|
} catch (OperationManagementDAOException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while retrieving the operation with operation Id '" +
|
|
|
|
|
operationId, e);
|
|
|
|
|
operationId, e);
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
|
throw new OperationManagementException("Error occurred while opening a connection to the data source", e);
|
|
|
|
|
} finally {
|
|
|
|
@ -538,4 +609,8 @@ public class OperationManagerImpl implements OperationManager {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getUser() {
|
|
|
|
|
return CarbonContext.getThreadLocalCarbonContext().getUsername();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|