mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fixing the conflicts
This commit is contained in:
commit
dc205aa081
@ -92,4 +92,23 @@ public class EnrolmentInfo {
|
||||
this.device = device;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof EnrolmentInfo) {
|
||||
EnrolmentInfo tempInfo = (EnrolmentInfo) obj;
|
||||
if (owner != null && ownership != null
|
||||
&& tempInfo.getOwner() != null && tempInfo.getOwnership() != null) {
|
||||
|
||||
if (owner.equals(tempInfo.getOwner()) && ownership.equals(tempInfo.getOwnership())) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,5 +62,8 @@ public interface DeviceDAO {
|
||||
|
||||
|
||||
List<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException;
|
||||
|
||||
int getEnrolmentByStatus(DeviceIdentifier deviceId, Status status,
|
||||
int tenantId) throws DeviceManagementDAOException;
|
||||
}
|
||||
|
||||
|
||||
@ -435,6 +435,37 @@ public class DeviceDAOImpl implements DeviceDAO {
|
||||
}
|
||||
}
|
||||
|
||||
public int getEnrolmentByStatus(DeviceIdentifier deviceId, Status status,
|
||||
int tenantId) throws DeviceManagementDAOException {
|
||||
Connection conn;
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String sql =
|
||||
"SELECT ID AS ENROLMENT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " +
|
||||
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? " +
|
||||
"AND d.TENANT_ID = ?) AND STATUS = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, deviceId.getId());
|
||||
stmt.setString(2, deviceId.getType());
|
||||
stmt.setInt(3, tenantId);
|
||||
stmt.setString(4, status.toString());
|
||||
stmt.setInt(5, tenantId);
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
return rs.getInt("ENROLMENT_ID");
|
||||
} else {
|
||||
return -1; // if no results found
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new DeviceManagementDAOException("Error occurred while retrieving the enrolment " +
|
||||
"id of device '" + deviceId + "'", e);
|
||||
} finally {
|
||||
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
||||
}
|
||||
}
|
||||
|
||||
private Device loadDevice(ResultSet rs) throws SQLException {
|
||||
Device device = new Device();
|
||||
device.setId(rs.getInt("DEVICE_ID"));
|
||||
|
||||
@ -77,7 +77,7 @@ public class EnrolmentDAOImpl implements EnrolmentDAO {
|
||||
stmt.setString(1, enrolmentInfo.getOwnership().toString());
|
||||
stmt.setString(2, enrolmentInfo.getStatus().toString());
|
||||
stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment()));
|
||||
stmt.setTimestamp(4, new Timestamp(enrolmentInfo.getDateOfLastUpdate()));
|
||||
stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
|
||||
stmt.setInt(5, deviceId);
|
||||
stmt.setString(6, enrolmentInfo.getOwner());
|
||||
stmt.setInt(7, tenantId);
|
||||
@ -156,9 +156,9 @@ public class EnrolmentDAOImpl implements EnrolmentDAO {
|
||||
conn = this.getConnection();
|
||||
String sql = "SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(2, deviceId);
|
||||
stmt.setString(3, currentOwner);
|
||||
stmt.setInt(4, tenantId);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setString(2, currentOwner);
|
||||
stmt.setInt(3, tenantId);
|
||||
rs = stmt.executeQuery();
|
||||
if (rs.next()) {
|
||||
status = EnrolmentInfo.Status.valueOf(rs.getString("STATUS"));
|
||||
|
||||
@ -21,7 +21,6 @@ package org.wso2.carbon.device.mgt.core.operation.mgt;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.wso2.carbon.context.CarbonContext;
|
||||
import org.wso2.carbon.device.mgt.common.Device;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||
@ -32,7 +31,6 @@ import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory;
|
||||
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
|
||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationDAO;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
|
||||
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
|
||||
@ -81,7 +79,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
log.debug("operation:[" + operation.toString() + "]");
|
||||
for (DeviceIdentifier deviceIdentifier : deviceIds) {
|
||||
log.debug("device identifier id:[" + deviceIdentifier.getId() + "] type:[" + deviceIdentifier.getType()
|
||||
+ "]");
|
||||
+ "]");
|
||||
}
|
||||
}
|
||||
try {
|
||||
@ -91,17 +89,17 @@ public class OperationManagerImpl implements OperationManager {
|
||||
|
||||
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
|
||||
|
||||
Device device;
|
||||
int enrolmentId;
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
for (DeviceIdentifier deviceId : deviceIds) {
|
||||
device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
if (device == null) {
|
||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
if (enrolmentId < 0) {
|
||||
String errorMsg = "The operation not added for device.The device not found for " +
|
||||
"device Identifier type -'" + deviceId.getType() + "' and device Id '" +
|
||||
deviceId.getId();
|
||||
log.info(errorMsg);
|
||||
"device Identifier type -'" + deviceId.getType() + "' and device Id '" +
|
||||
deviceId.getId();
|
||||
log.error(errorMsg);
|
||||
} else {
|
||||
operationMappingDAO.addOperationMapping(operationId, device.getId());
|
||||
operationMappingDAO.addOperationMapping(operationId, enrolmentId);
|
||||
}
|
||||
}
|
||||
OperationManagementDAOFactory.commitTransaction();
|
||||
@ -126,21 +124,25 @@ public class OperationManagerImpl implements OperationManager {
|
||||
@Override
|
||||
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
|
||||
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
int enrolmentId = -1;
|
||||
|
||||
try {
|
||||
OperationManagementDAOFactory.getConnection();
|
||||
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
|
||||
if (device == null) {
|
||||
if (enrolmentId < 0) {
|
||||
throw new OperationManagementException("Device not found for given device " +
|
||||
"Identifier:" + deviceId.getId() + " and given type" + deviceId.getType());
|
||||
"Identifier:" + deviceId.getId() + " and given type" + deviceId.getType());
|
||||
}
|
||||
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList =
|
||||
operationDAO.getOperationsForDevice(device.getId());
|
||||
List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList = operationDAO
|
||||
.getOperationsForDevice(enrolmentId);
|
||||
|
||||
Operation operation;
|
||||
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
|
||||
operation = OperationDAOUtil.convertOperation(dtoOperation);
|
||||
operations.add(operation);
|
||||
@ -148,11 +150,11 @@ public class OperationManagerImpl implements OperationManager {
|
||||
return operations;
|
||||
} catch (OperationManagementDAOException e) {
|
||||
throw new OperationManagementException("Error occurred while retrieving the list of " +
|
||||
"operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId()
|
||||
+ "'", e);
|
||||
"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() + "'");
|
||||
deviceId.getType() + "' device carrying the identifier '" + deviceId.getId() + "'");
|
||||
} finally {
|
||||
try {
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
@ -160,6 +162,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
log.warn("Error occurred while closing data source connection", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -168,10 +171,10 @@ public class OperationManagerImpl implements OperationManager {
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType()
|
||||
+ "]");
|
||||
+ "]");
|
||||
}
|
||||
|
||||
Device device;
|
||||
int enrolmentId = -1;
|
||||
List<Operation> operations = new ArrayList<Operation>();
|
||||
|
||||
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
|
||||
@ -181,30 +184,24 @@ public class OperationManagerImpl implements OperationManager {
|
||||
OperationManagementDAOFactory.getConnection();
|
||||
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
|
||||
if (device == null) {
|
||||
if (enrolmentId < 0) {
|
||||
throw new OperationManagementException("Device not found for given device " +
|
||||
"Identifier:" + deviceId.getId() + " and given type:" + deviceId.getType());
|
||||
"Identifier:" + deviceId.getId() + " and given type:" + deviceId.getType());
|
||||
}
|
||||
|
||||
if (device.getEnrolmentInfo().getStatus() != null && !device.getEnrolmentInfo().getStatus().equals(
|
||||
EnrolmentInfo.Status.ACTIVE)) {
|
||||
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
|
||||
.updateDeviceEnrolmentInfo(device, EnrolmentInfo.Status.ACTIVE);
|
||||
}
|
||||
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
|
||||
enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||
|
||||
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||
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(configOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||
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(profileOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
|
||||
|
||||
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||
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) {
|
||||
@ -215,17 +212,14 @@ public class OperationManagerImpl implements OperationManager {
|
||||
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);
|
||||
"pending operations assigned for '" + deviceId.getType() + "' device '" +
|
||||
deviceId.getId() + "'", e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String errorMsg = "Error occurred while retrieving the device " +
|
||||
"for device Identifier type -'" + deviceId.getType() + "' and device Id '"
|
||||
+ deviceId.getId();
|
||||
"for device Identifier type -'" + deviceId.getType() + "' and device Id '"
|
||||
+ deviceId.getId();
|
||||
log.error(errorMsg, e);
|
||||
throw new OperationManagementException(errorMsg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred while update enrol status: " +
|
||||
deviceId.toString(), e);
|
||||
} finally {
|
||||
try {
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
@ -239,34 +233,22 @@ public class OperationManagerImpl implements OperationManager {
|
||||
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType()
|
||||
+ "]");
|
||||
+ "]");
|
||||
}
|
||||
Operation operation = null;
|
||||
Device device;
|
||||
int enrolmentId = -1;
|
||||
try {
|
||||
OperationManagementDAOFactory.getConnection();
|
||||
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
|
||||
if (device == null) {
|
||||
if (enrolmentId < 0) {
|
||||
throw new OperationManagementException("Device not found for given device " +
|
||||
"Identifier:" + deviceId.getId() + " and given type" + deviceId.getType());
|
||||
"Identifier:" + deviceId.getId() + " and given type" + deviceId.getType());
|
||||
}
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
|
||||
.getNextOperation(device.getId());
|
||||
|
||||
if (device.getEnrolmentInfo().getStatus() != null && !device.getEnrolmentInfo().getStatus().equals(
|
||||
EnrolmentInfo.Status.ACTIVE)) {
|
||||
try {
|
||||
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
|
||||
.updateDeviceEnrolmentInfo(device,
|
||||
EnrolmentInfo.Status.ACTIVE);
|
||||
} catch (DeviceManagementException e) {
|
||||
throw new OperationManagementException("Error occurred while update enrol status: '" +
|
||||
deviceId.toString() + "'", e);
|
||||
}
|
||||
}
|
||||
.getNextOperation(enrolmentId);
|
||||
|
||||
if (dtoOperation != null) {
|
||||
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND
|
||||
@ -293,7 +275,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
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);
|
||||
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" + deviceId.getId(), e);
|
||||
} finally {
|
||||
try {
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
@ -315,19 +297,21 @@ public class OperationManagerImpl implements OperationManager {
|
||||
OperationManagementDAOFactory.beginTransaction();
|
||||
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
int enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
|
||||
if (operation.getStatus() != null) {
|
||||
OperationManagementDAOFactory.beginTransaction();
|
||||
operationDAO.updateOperationStatus(device.getId(), operationId,
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
|
||||
.valueOf(operation.getStatus().toString()));
|
||||
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(device.getId(), operationId, operation.getOperationResponse());
|
||||
OperationManagementDAOFactory.beginTransaction();
|
||||
operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
|
||||
OperationManagementDAOFactory.commitTransaction();
|
||||
}
|
||||
OperationManagementDAOFactory.commitTransaction();
|
||||
} catch (OperationManagementDAOException e) {
|
||||
try {
|
||||
OperationManagementDAOFactory.rollbackTransaction();
|
||||
@ -335,7 +319,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
log.warn("Error occurred while roll-backing the update operation transaction", e1);
|
||||
}
|
||||
throw new OperationManagementException("Error occurred while updating the operation: " + operationId +
|
||||
" status:" + operation.getStatus(), e);
|
||||
" status:" + operation.getStatus(), e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
try {
|
||||
OperationManagementDAOFactory.rollbackTransaction();
|
||||
@ -343,7 +327,7 @@ public class OperationManagerImpl implements OperationManager {
|
||||
log.warn("Error occurred while roll-backing the update operation transaction", e1);
|
||||
}
|
||||
throw new OperationManagementException("Error occurred while fetching the device for device identifier: " +
|
||||
deviceId.getId() + "type:" + deviceId.getType(), e);
|
||||
deviceId.getId() + "type:" + deviceId.getType(), e);
|
||||
} finally {
|
||||
try {
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
@ -381,25 +365,25 @@ public class OperationManagerImpl implements OperationManager {
|
||||
@Override
|
||||
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
|
||||
throws OperationManagementException {
|
||||
Device device;
|
||||
int enrolmentId = -1;
|
||||
Operation operation;
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("Operation Id:" + operationId + " Device Type:" + deviceId.getType() + " Device Identifier:" +
|
||||
deviceId.getId());
|
||||
deviceId.getId());
|
||||
}
|
||||
|
||||
try {
|
||||
OperationManagementDAOFactory.getConnection();
|
||||
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
if (device == null) {
|
||||
enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
if (enrolmentId < 0) {
|
||||
throw new OperationManagementException("Device not found for given device identifier:" +
|
||||
deviceId.getId() + " type:" + deviceId.getType());
|
||||
deviceId.getId() + " type:" + deviceId.getType());
|
||||
}
|
||||
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
|
||||
.getOperationByDeviceAndId(device.getId(), operationId);
|
||||
.getOperationByDeviceAndId(enrolmentId, operationId);
|
||||
|
||||
if (dtoOperation.getType()
|
||||
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
|
||||
@ -412,27 +396,27 @@ public class OperationManagerImpl implements OperationManager {
|
||||
.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)) {
|
||||
.PROFILE)) {
|
||||
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
||||
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
||||
.POLICY)) {
|
||||
.POLICY)) {
|
||||
|
||||
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
||||
}
|
||||
|
||||
if (dtoOperation == null) {
|
||||
throw new OperationManagementException("Operation not found for operation Id:" + operationId +
|
||||
" device" + " Id:" + device.getId());
|
||||
" 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);
|
||||
"operations assigned for '" + deviceId.getType() + "' device '" + deviceId.getId()
|
||||
+ "'", e);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String errorMsg = "Error occurred while retrieving the device " +
|
||||
"for device Identifier type -'" + deviceId.getType() + "' and device Id '"
|
||||
+ deviceId.getId();
|
||||
"for device Identifier type -'" + deviceId.getType() + "' and device Id '"
|
||||
+ deviceId.getId();
|
||||
log.error(errorMsg, e);
|
||||
throw new OperationManagementException(errorMsg, e);
|
||||
} finally {
|
||||
@ -455,25 +439,28 @@ public class OperationManagerImpl implements OperationManager {
|
||||
OperationManagementDAOFactory.getConnection();
|
||||
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
Device device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
int enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
|
||||
|
||||
if (device == null) {
|
||||
if (enrolmentId < 0) {
|
||||
throw new OperationManagementException("Device not found for device id:" + deviceId.getId() + " " +
|
||||
"type:" + deviceId.getType());
|
||||
"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(device.getId(), dtoOpStatus));
|
||||
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(enrolmentId, dtoOpStatus));
|
||||
|
||||
dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(device.getId(),
|
||||
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(device.getId(),
|
||||
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(device.getId(),
|
||||
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;
|
||||
|
||||
@ -484,11 +471,11 @@ public class OperationManagerImpl implements OperationManager {
|
||||
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);
|
||||
"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);
|
||||
"for device Identifier type -'" + deviceId.getType() + "' and device Id '" + deviceId.getId(), e);
|
||||
} finally {
|
||||
try {
|
||||
OperationManagementDAOFactory.closeConnection();
|
||||
@ -521,10 +508,10 @@ public class OperationManagerImpl implements OperationManager {
|
||||
.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)) {
|
||||
.PROFILE)) {
|
||||
dtoOperation = profileOperationDAO.getOperation(dtoOperation.getId());
|
||||
} else if (dtoOperation.getType().equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type
|
||||
.POLICY)) {
|
||||
.POLICY)) {
|
||||
|
||||
dtoOperation = policyOperationDAO.getOperation(dtoOperation.getId());
|
||||
}
|
||||
|
||||
@ -22,15 +22,15 @@ import java.util.List;
|
||||
|
||||
public class PolicyOperation extends Operation {
|
||||
|
||||
public static final String POLICY_OPERATION_CODE = "POLICY_BUNDLE";
|
||||
private List<ProfileOperation> profileOperations;
|
||||
|
||||
public List<ProfileOperation> getProfileOperations() {
|
||||
return profileOperations;
|
||||
}
|
||||
public static final String POLICY_OPERATION_CODE = "POLICY_BUNDLE";
|
||||
|
||||
public void setProfileOperations(List<ProfileOperation> profileOperations) {
|
||||
this.profileOperations = profileOperations;
|
||||
}
|
||||
|
||||
private List<ProfileOperation> profileOperations;
|
||||
|
||||
}
|
||||
|
||||
@ -18,7 +18,6 @@
|
||||
*/
|
||||
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 java.util.List;
|
||||
@ -33,18 +32,18 @@ public interface OperationDAO {
|
||||
|
||||
Operation getOperation(int operationId) throws OperationManagementDAOException;
|
||||
|
||||
Operation getOperationByDeviceAndId(int deviceId, int operationId) throws OperationManagementDAOException;
|
||||
Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException;
|
||||
|
||||
List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId, Operation.Status status)
|
||||
List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId, Operation.Status status)
|
||||
throws OperationManagementDAOException;
|
||||
|
||||
List<? extends Operation> getOperationsForDevice(int deviceId) throws OperationManagementDAOException;
|
||||
List<? extends Operation> getOperationsForDevice(int enrolmentId) throws OperationManagementDAOException;
|
||||
|
||||
Operation getNextOperation(int deviceId) throws OperationManagementDAOException;
|
||||
Operation getNextOperation(int enrolmentId) throws OperationManagementDAOException;
|
||||
|
||||
void updateOperationStatus(int deviceId, int operationId,Operation.Status status)
|
||||
void updateOperationStatus(int enrolmentId, int operationId,Operation.Status status)
|
||||
throws OperationManagementDAOException;
|
||||
|
||||
void addOperationResponse(int deviceId, int operationId, Object operationResponse)
|
||||
void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
|
||||
throws OperationManagementDAOException;
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId,
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
@ -146,11 +146,11 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "Select co.OPERATION_ID,ENABLED from DM_COMMAND_OPERATION co " +
|
||||
"INNER JOIN " +
|
||||
"(Select * From DM_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID=? " +
|
||||
"(Select * From DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " +
|
||||
"AND STATUS=? ) dm ON dm.OPERATION_ID = co.OPERATION_ID";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
@ -169,7 +169,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
|
||||
}
|
||||
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
||||
"' with status '" + status.toString();
|
||||
log.error(errorMsg);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
|
||||
@ -168,7 +168,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId,
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
@ -184,11 +184,11 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "Select co.OPERATION_ID, co.OPERATION_CONFIG from DM_CONFIG_OPERATION co " +
|
||||
"INNER JOIN " +
|
||||
"(Select * From DM_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID=? " +
|
||||
"(Select * From DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " +
|
||||
"AND STATUS=?) dm ON dm.OPERATION_ID = co.OPERATION_ID";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
@ -211,7 +211,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
|
||||
log.error(errorMsg, e);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
||||
"' with status '" + status.toString();
|
||||
log.error(errorMsg);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
|
||||
@ -86,17 +86,17 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
}
|
||||
|
||||
public void updateOperationStatus(int deviceId, int operationId, Operation.Status status)
|
||||
public void updateOperationStatus(int enrolmentId, int operationId, Operation.Status status)
|
||||
throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("UPDATE DM_DEVICE_OPERATION_MAPPING O SET O.STATUS=? " +
|
||||
"WHERE O.DEVICE_ID=? and O.OPERATION_ID=?");
|
||||
stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS=? " +
|
||||
"WHERE O.ENROLMENT_ID=? and O.OPERATION_ID=?");
|
||||
|
||||
stmt.setString(1, status.toString());
|
||||
stmt.setInt(2, deviceId);
|
||||
stmt.setInt(2, enrolmentId);
|
||||
stmt.setInt(3, operationId);
|
||||
stmt.executeUpdate();
|
||||
|
||||
@ -111,7 +111,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOperationResponse(int deviceId, int operationId, Object operationResponse)
|
||||
public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
|
||||
throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
@ -129,7 +129,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
oos.writeObject(operationResponse);
|
||||
|
||||
stmt.setInt(1, operationId);
|
||||
stmt.setInt(2, deviceId);
|
||||
stmt.setInt(2, enrolmentId);
|
||||
stmt.setBytes(3, bao.toByteArray());
|
||||
stmt.executeUpdate();
|
||||
|
||||
@ -214,7 +214,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getOperationByDeviceAndId(int deviceId, int operationId) throws OperationManagementDAOException {
|
||||
public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
@ -225,13 +225,13 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
String sql = "SELECT o.ID, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.STATUS, o.OPERATION_CODE " +
|
||||
" From (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," +
|
||||
"OPERATION_CODE FROM DM_OPERATION WHERE id=?) o INNER JOIN (Select * from " +
|
||||
"DM_DEVICE_OPERATION_MAPPING dm where dm.OPERATION_ID=? AND dm.DEVICE_ID=?) om " +
|
||||
"DM_ENROLMENT_OPERATION_MAPPING dm where dm.OPERATION_ID=? AND dm.ENROLMENT_ID=?) om " +
|
||||
"ON o.ID = om.OPERATION_ID ";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, operationId);
|
||||
stmt.setInt(2, operationId);
|
||||
stmt.setInt(3, deviceId);
|
||||
stmt.setInt(3, enrolmentId);
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
if (rs.next()) {
|
||||
@ -247,7 +247,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
operation.setCode(rs.getString("OPERATION_CODE"));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
||||
"' with id '" + operationId;
|
||||
log.error(errorMsg);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
@ -259,7 +259,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId,
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
@ -272,11 +272,11 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
||||
"FROM DM_OPERATION o " +
|
||||
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
||||
"where dm.DEVICE_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
||||
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
|
||||
"where dm.ENROLMENT_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
@ -296,7 +296,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
operationList.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
||||
"' with status '" + status.toString();
|
||||
log.error(errorMsg);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
@ -308,7 +308,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsForDevice(int deviceId)
|
||||
public List<? extends Operation> getOperationsForDevice(int enrolmentId)
|
||||
throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
@ -321,11 +321,11 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
|
||||
"OPERATION_CODE,dm.STATUS FROM DM_OPERATION o " +
|
||||
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
||||
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
||||
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
|
||||
"where dm.ENROLMENT_ID=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
|
||||
@ -344,7 +344,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
operationList.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
||||
"' with status '";
|
||||
log.error(errorMsg);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
@ -356,7 +356,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Operation getNextOperation(int deviceId) throws OperationManagementDAOException {
|
||||
public Operation getNextOperation(int enrolmentId) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
ResultSet rs = null;
|
||||
@ -365,11 +365,11 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
Connection connection = OperationManagementDAOFactory.getConnection();
|
||||
stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
|
||||
"OPERATION_CODE FROM DM_OPERATION o " +
|
||||
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
||||
"where dm.DEVICE_ID=? AND dm.STATUS=?) om ON o.ID = om.OPERATION_ID " +
|
||||
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
|
||||
"where dm.ENROLMENT_ID=? AND dm.STATUS=?) om ON o.ID = om.OPERATION_ID " +
|
||||
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
|
||||
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, Operation.Status.PENDING.toString());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
@ -398,7 +398,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
}
|
||||
|
||||
|
||||
public List<? extends Operation> getOperationsByDeviceStatusAndType(int deviceId,
|
||||
public List<? extends Operation> getOperationsByDeviceStatusAndType(int enrolmentId,
|
||||
Operation.Status status, Operation.Type type) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
@ -412,12 +412,12 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
|
||||
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
|
||||
"FROM DM_OPERATION o WHERE o.TYPE=?) o " +
|
||||
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " +
|
||||
"where dm.DEVICE_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
||||
"INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
|
||||
"where dm.ENROLMENT_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setString(1, type.toString());
|
||||
stmt.setInt(2, deviceId);
|
||||
stmt.setInt(2, enrolmentId);
|
||||
stmt.setString(3, status.toString());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
@ -436,7 +436,7 @@ public class OperationDAOImpl implements OperationDAO {
|
||||
operationList.add(operation);
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
||||
"' with status '" + status.toString();
|
||||
log.error(errorMsg);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
|
||||
@ -35,7 +35,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "INSERT INTO DM_DEVICE_OPERATION_MAPPING(DEVICE_ID, OPERATION_ID,STATUS) VALUES(?, ?,?)";
|
||||
String sql = "INSERT INTO DM_ENROLMENT_OPERATION_MAPPING(ENROLMENT_ID, OPERATION_ID, STATUS) VALUES (?, ?,?)";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(2, operationId);
|
||||
@ -54,7 +54,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
|
||||
PreparedStatement stmt = null;
|
||||
try {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "DELETE FROM DM_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID = ? AND OPERATION_ID = ?";
|
||||
String sql = "DELETE FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? AND OPERATION_ID = ?";
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, 0);
|
||||
stmt.setInt(2, operationId);
|
||||
|
||||
@ -171,7 +171,7 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId,
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
@ -187,11 +187,11 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_POLICY_OPERATION po " +
|
||||
"INNER JOIN " +
|
||||
"(Select * From DM_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID=? " +
|
||||
"(Select * From DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " +
|
||||
"AND STATUS=?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
@ -214,7 +214,7 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
|
||||
log.error(errorMsg, e);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
||||
"' with status '" + status.toString();
|
||||
log.error(errorMsg);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
|
||||
@ -167,7 +167,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId,
|
||||
public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
|
||||
Operation.Status status) throws OperationManagementDAOException {
|
||||
|
||||
PreparedStatement stmt = null;
|
||||
@ -183,11 +183,11 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
||||
Connection conn = OperationManagementDAOFactory.getConnection();
|
||||
String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_PROFILE_OPERATION po " +
|
||||
"INNER JOIN " +
|
||||
"(Select * From DM_DEVICE_OPERATION_MAPPING WHERE DEVICE_ID=? " +
|
||||
"(Select * From DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID=? " +
|
||||
"AND STATUS=?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
|
||||
|
||||
stmt = conn.prepareStatement(sql);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(1, enrolmentId);
|
||||
stmt.setString(2, status.toString());
|
||||
|
||||
rs = stmt.executeQuery();
|
||||
@ -210,7 +210,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
|
||||
log.error(errorMsg, e);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
} catch (SQLException e) {
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + deviceId +
|
||||
String errorMsg = "SQL error occurred while retrieving the operation available for the device'" + enrolmentId +
|
||||
"' with status '" + status.toString();
|
||||
log.error(errorMsg);
|
||||
throw new OperationManagementDAOException(errorMsg, e);
|
||||
|
||||
@ -48,7 +48,7 @@ import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService,
|
||||
PluginInitializationListener {
|
||||
PluginInitializationListener {
|
||||
|
||||
private DeviceDAO deviceDAO;
|
||||
private DeviceTypeDAO deviceTypeDAO;
|
||||
@ -67,7 +67,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
DeviceManagementServiceComponent.registerPluginInitializationListener(this);
|
||||
}
|
||||
|
||||
DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test){
|
||||
/**
|
||||
* This constructor calls from unit tests
|
||||
*
|
||||
* @param pluginRepo
|
||||
*/
|
||||
DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test) {
|
||||
this.pluginRepository = pluginRepo;
|
||||
initDataAccessObjects();
|
||||
}
|
||||
@ -106,31 +111,60 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
|
||||
@Override
|
||||
public boolean enrollDevice(Device device) throws DeviceManagementException {
|
||||
|
||||
boolean status = false;
|
||||
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
|
||||
boolean status = dms.enrollDevice(device);
|
||||
dms.enrollDevice(device);
|
||||
try {
|
||||
if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) {
|
||||
if (dms.isClaimable(deviceIdentifier)) {
|
||||
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.INACTIVE);
|
||||
} else {
|
||||
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE);
|
||||
}
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
Device existingDevice = this.getDevice(deviceIdentifier);
|
||||
|
||||
DeviceType type = deviceTypeDAO.getDeviceType(device.getType());
|
||||
int deviceId = deviceDAO.addDevice(type.getId(), device, tenantId);
|
||||
int enrolmentId = enrolmentDAO.addEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
|
||||
if (existingDevice != null) {
|
||||
EnrolmentInfo existingEnrolmentInfo = existingDevice.getEnrolmentInfo();
|
||||
EnrolmentInfo newEnrolmentInfo = device.getEnrolmentInfo();
|
||||
if (existingEnrolmentInfo != null && newEnrolmentInfo != null) {
|
||||
if (existingEnrolmentInfo.equals(newEnrolmentInfo)) {
|
||||
device.getEnrolmentInfo().setDateOfEnrolment(existingEnrolmentInfo.getDateOfEnrolment());
|
||||
this.modifyEnrollment(device);
|
||||
status = true;
|
||||
} else {
|
||||
this.setStatus(deviceIdentifier, existingEnrolmentInfo.getOwner(), EnrolmentInfo.Status.INACTIVE);
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
int enrolmentId = enrolmentDAO.addEnrollment(existingDevice.getId(), newEnrolmentInfo, tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("An enrolment is successfully created with the id '" + enrolmentId + "' associated with " +
|
||||
"the device identified by key '" + device.getDeviceIdentifier() + "', which belongs to " +
|
||||
"platform '" + device.getType() + " upon the user '" +
|
||||
device.getEnrolmentInfo().getOwner() + "'");
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("An enrolment is successfully updated with the id '" + enrolmentId +
|
||||
"' associated with " + "the device identified by key '" + device.getDeviceIdentifier() +
|
||||
"', which belongs to " + "platform '" + device.getType() + " upon the user '" +
|
||||
device.getEnrolmentInfo().getOwner() + "'");
|
||||
}
|
||||
status = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
DeviceManagementDAOFactory.beginTransaction();
|
||||
DeviceType type = deviceTypeDAO.getDeviceType(device.getType());
|
||||
int deviceId = deviceDAO.addDevice(type.getId(), device, tenantId);
|
||||
int enrolmentId = enrolmentDAO.addEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
|
||||
if (log.isDebugEnabled()) {
|
||||
log.debug("An enrolment is successfully created with the id '" + enrolmentId + "' associated with " +
|
||||
"the device identified by key '" + device.getDeviceIdentifier() + "', which belongs to " +
|
||||
"platform '" + device.getType() + " upon the user '" +
|
||||
device.getEnrolmentInfo().getOwner() + "'");
|
||||
}
|
||||
status = true;
|
||||
}
|
||||
DeviceManagementDAOFactory.commitTransaction();
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
try {
|
||||
DeviceManagementDAOFactory.rollbackTransaction();
|
||||
@ -138,7 +172,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
log.warn("Error occurred while roll-backing the current transaction", e);
|
||||
}
|
||||
throw new DeviceManagementException("Error occurred while enrolling the device " +
|
||||
"'" + device.getId() + "'", e);
|
||||
"'" + device.getId() + "'", e);
|
||||
} finally {
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
@ -150,7 +184,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
|
||||
DeviceManager dms =
|
||||
@ -171,7 +204,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
log.warn("Error occurred while roll-backing the current transaction", e);
|
||||
}
|
||||
throw new DeviceManagementException("Error occurred while modifying the device " +
|
||||
"'" + device.getId() + "'", e);
|
||||
"'" + device.getId() + "'", e);
|
||||
} finally {
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
@ -189,16 +222,17 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
DeviceManager dms =
|
||||
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
|
||||
try {
|
||||
Device device = deviceDAO.getDevice(deviceId,tenantId);
|
||||
Device device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
|
||||
|
||||
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
||||
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
|
||||
enrolmentDAO.updateEnrollment(device.getId(), device.getEnrolmentInfo(), tenantId);
|
||||
deviceDAO.updateDevice(deviceType.getId(), device, tenantId);
|
||||
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
String errorMsg = "Error occurred while fetch device for device Identifier:";
|
||||
log.error(errorMsg + deviceId.toString(),e);
|
||||
String errorMsg = "Error occurred while fetch device for device Identifier:";
|
||||
log.error(errorMsg + deviceId.toString(), e);
|
||||
throw new DeviceManagementException(errorMsg, e);
|
||||
|
||||
}
|
||||
@ -236,7 +270,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
allDevices = deviceDAO.getDevices(tenantId);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while retrieving device list pertaining to " +
|
||||
"the current tenant", e);
|
||||
"the current tenant", e);
|
||||
} finally {
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
@ -270,7 +304,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
allDevices = deviceDAO.getDevices(type, tenantId);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while retrieving all devices of type '" +
|
||||
type + "' that are being managed within the scope of current tenant", e);
|
||||
type + "' that are being managed within the scope of current tenant", e);
|
||||
} finally {
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
@ -329,13 +363,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
|
||||
try {
|
||||
messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.FIRST_NAME + "\\}",
|
||||
URLEncoder.encode(emailMessageProperties.getFirstName(),
|
||||
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
|
||||
URLEncoder.encode(emailMessageProperties.getFirstName(),
|
||||
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
|
||||
messageBody = messageBody.trim() + System.getProperty("line.separator") +
|
||||
System.getProperty("line.separator") + url.replaceAll("\\{"
|
||||
+ EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}",
|
||||
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
|
||||
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
|
||||
System.getProperty("line.separator") + url.replaceAll("\\{"
|
||||
+ EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}",
|
||||
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
|
||||
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
|
||||
|
||||
messageBuilder.append(messageHeader).append(System.getProperty("line.separator"))
|
||||
.append(System.getProperty("line.separator"));
|
||||
@ -343,12 +377,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
messageBuilder.append(System.getProperty("line.separator")).append(System.getProperty("line.separator"));
|
||||
messageBuilder.append(messageFooter1.trim())
|
||||
.append(System.getProperty("line.separator")).append(messageFooter2.trim()).append(System
|
||||
.getProperty("line.separator")).append(messageFooter3.trim());
|
||||
.getProperty("line.separator")).append(messageFooter3.trim());
|
||||
|
||||
} catch (IOException e) {
|
||||
log.error("IO error in processing enrol email message " + emailMessageProperties);
|
||||
throw new DeviceManagementException("Error replacing tags in email template '" +
|
||||
emailMessageProperties.getSubject() + "'", e);
|
||||
emailMessageProperties.getSubject() + "'", e);
|
||||
}
|
||||
emailMessageProperties.setMessageBody(messageBuilder.toString());
|
||||
emailMessageProperties.setSubject(subject);
|
||||
@ -386,23 +420,23 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
|
||||
try {
|
||||
messageHeader = messageHeader.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.FIRST_NAME + "\\}",
|
||||
URLEncoder.encode(emailMessageProperties.getFirstName(),
|
||||
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
|
||||
URLEncoder.encode(emailMessageProperties.getFirstName(),
|
||||
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
|
||||
|
||||
messageBody = messageBody.trim().replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants
|
||||
.USERNAME
|
||||
+ "\\}",
|
||||
URLEncoder.encode(emailMessageProperties.getUserName(), EmailConstants.EnrolmentEmailConstants
|
||||
.ENCODED_SCHEME));
|
||||
.USERNAME
|
||||
+ "\\}",
|
||||
URLEncoder.encode(emailMessageProperties.getUserName(), EmailConstants.EnrolmentEmailConstants
|
||||
.ENCODED_SCHEME));
|
||||
|
||||
messageBody = messageBody.replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants.PASSWORD + "\\}",
|
||||
URLEncoder.encode(emailMessageProperties.getPassword(), EmailConstants.EnrolmentEmailConstants
|
||||
.ENCODED_SCHEME));
|
||||
URLEncoder.encode(emailMessageProperties.getPassword(), EmailConstants.EnrolmentEmailConstants
|
||||
.ENCODED_SCHEME));
|
||||
|
||||
messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{"
|
||||
+ EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}",
|
||||
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
|
||||
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
|
||||
+ EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}",
|
||||
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
|
||||
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
|
||||
|
||||
messageBuilder.append(messageHeader).append(System.getProperty("line.separator"));
|
||||
messageBuilder.append(messageBody).append(System.getProperty("line.separator")).append(
|
||||
@ -413,7 +447,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
} catch (IOException e) {
|
||||
log.error("IO error in processing enrol email message " + emailMessageProperties);
|
||||
throw new DeviceManagementException("Error replacing tags in email template '" +
|
||||
emailMessageProperties.getSubject() + "'", e);
|
||||
emailMessageProperties.getSubject() + "'", e);
|
||||
}
|
||||
emailMessageProperties.setMessageBody(messageBuilder.toString());
|
||||
emailMessageProperties.setSubject(subject);
|
||||
@ -428,7 +462,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
device = deviceDAO.getDevice(deviceId, tenantId);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while obtaining the device for id " +
|
||||
"'" + deviceId.getId() + "'", e);
|
||||
"'" + deviceId.getId() + "'", e);
|
||||
} finally {
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
@ -531,7 +565,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
|
||||
@Override
|
||||
public int addOperation(Operation operation, List<DeviceIdentifier> devices) throws
|
||||
OperationManagementException {
|
||||
OperationManagementException {
|
||||
return DeviceManagementDataHolder.getInstance().getOperationManager().addOperation(operation, devices);
|
||||
}
|
||||
|
||||
@ -591,7 +625,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
userDevices = deviceDAO.getDevicesOfUser(username, tenantId);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while retrieving the list of devices that " +
|
||||
"belong to the user '" + username + "'", e);
|
||||
"belong to the user '" + username + "'", e);
|
||||
} finally {
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
@ -622,11 +656,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
String[] users;
|
||||
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||
try {
|
||||
users = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
||||
users = DeviceManagementDataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId)
|
||||
.getUserStoreManager().getUserListOfRole(role);
|
||||
} catch (UserStoreException e) {
|
||||
throw new DeviceManagementException("Error occurred while obtaining the users, who are assigned " +
|
||||
"with the role '" + role + "'", e);
|
||||
"with the role '" + role + "'", e);
|
||||
}
|
||||
|
||||
List<Device> userDevices;
|
||||
@ -686,7 +720,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
allDevices = deviceDAO.getDevicesByName(deviceName, tenantId);
|
||||
} catch (DeviceManagementDAOException e) {
|
||||
throw new DeviceManagementException("Error occurred while fetching the list of devices that matches to '"
|
||||
+ deviceName + "'", e);
|
||||
+ deviceName + "'", e);
|
||||
} finally {
|
||||
try {
|
||||
DeviceManagementDAOFactory.closeConnection();
|
||||
@ -718,8 +752,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
|
||||
device.getEnrolmentInfo().setStatus(status);
|
||||
deviceDAO.updateDevice(deviceType.getId(), device, tenantId);
|
||||
}catch (DeviceManagementDAOException deviceDaoEx){
|
||||
String errorMsg = "Error occured update device enrolment status : "+device.getId();
|
||||
} catch (DeviceManagementDAOException deviceDaoEx) {
|
||||
String errorMsg = "Error occured update device enrolment status : " + device.getId();
|
||||
log.error(errorMsg, deviceDaoEx);
|
||||
throw new DeviceManagementException(errorMsg, deviceDaoEx);
|
||||
}
|
||||
@ -731,7 +765,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
pluginRepository.addDeviceManagementProvider(deviceManagementService);
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Error occurred while registering device management plugin '" +
|
||||
deviceManagementService.getType() + "'", e);
|
||||
deviceManagementService.getType() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -741,7 +775,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
pluginRepository.removeDeviceManagementProvider(deviceManagementService);
|
||||
} catch (DeviceManagementException e) {
|
||||
log.error("Error occurred while un-registering device management plugin '" +
|
||||
deviceManagementService.getType() + "'", e);
|
||||
deviceManagementService.getType() + "'", e);
|
||||
}
|
||||
}
|
||||
|
||||
@ -777,6 +811,4 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
||||
}
|
||||
return devices;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@ -50,18 +50,6 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
DEVICE_ID INTEGER NOT NULL,
|
||||
OPERATION_ID INTEGER NOT NULL,
|
||||
STATUS VARCHAR(50) NULL,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
DEVICE_ID INTEGER NOT NULL,
|
||||
@ -75,6 +63,20 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
||||
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
ENROLMENT_ID INTEGER NOT NULL,
|
||||
OPERATION_ID INTEGER NOT NULL,
|
||||
STATUS VARCHAR(50) NULL,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_APPLICATION (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
NAME VARCHAR(50) NOT NULL,
|
||||
|
||||
@ -24,10 +24,11 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.Serializable;
|
||||
import java.sql.Timestamp;
|
||||
import java.util.List;
|
||||
@XmlRootElement
|
||||
public class Profile {
|
||||
public class Profile implements Serializable {
|
||||
|
||||
private int profileId;
|
||||
private String profileName;
|
||||
|
||||
@ -90,12 +90,12 @@ public interface PolicyDAO {
|
||||
|
||||
List<String> getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException;
|
||||
|
||||
void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
|
||||
void addEffectivePolicyToDevice(int deviceId, Policy policy)
|
||||
throws PolicyManagerDAOException;
|
||||
|
||||
void setPolicyApplied(int deviceId) throws PolicyManagerDAOException;
|
||||
|
||||
void updateEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
|
||||
void updateEffectivePolicyToDevice(int deviceId, Policy policy)
|
||||
throws PolicyManagerDAOException;
|
||||
|
||||
boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException;
|
||||
|
||||
@ -190,7 +190,11 @@ public class MonitoringDAOImpl implements MonitoringDAO {
|
||||
for (ComplianceFeature feature : complianceFeatures) {
|
||||
stmt.setInt(1, policyComplianceStatusId);
|
||||
stmt.setString(2, feature.getFeatureCode());
|
||||
stmt.setString(3, String.valueOf(feature.isCompliance()));
|
||||
if (feature.isCompliance() == true) {
|
||||
stmt.setInt(3, 1);
|
||||
} else {
|
||||
stmt.setInt(3, 0);
|
||||
}
|
||||
stmt.addBatch();
|
||||
}
|
||||
stmt.executeBatch();
|
||||
|
||||
@ -413,7 +413,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
|
||||
} catch (SQLException e) {
|
||||
String msg = "Error occurred while inserting the criterion to policy (" + policy.getPolicyName() + ") " +
|
||||
"to database.";
|
||||
"to database.";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagerDAOException(msg, e);
|
||||
} finally {
|
||||
@ -433,7 +433,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_POLICY_CRITERIA_PROPERTIES (POLICY_CRITERION_ID, PROP_KEY, PROP_VALUE, " +
|
||||
"CONTENT) VALUES (?, ?, ?, ?)";
|
||||
"CONTENT) VALUES (?, ?, ?, ?)";
|
||||
stmt = conn.prepareStatement(query);
|
||||
|
||||
for (PolicyCriterion criterion : policyCriteria) {
|
||||
@ -474,9 +474,9 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "SELECT DPC.ID, DPC.CRITERIA_ID, DPCP.PROP_KEY, DPCP.PROP_VALUE, DPCP.CONTENT FROM " +
|
||||
"DM_POLICY_CRITERIA DPC LEFT JOIN DM_POLICY_CRITERIA_PROPERTIES DPCP " +
|
||||
"ON DPCP.POLICY_CRITERION_ID = DPC.ID RIGHT JOIN DM_CRITERIA DC " +
|
||||
"ON DC.ID=DPC.CRITERIA_ID WHERE DPC.POLICY_ID = ?";
|
||||
"DM_POLICY_CRITERIA DPC LEFT JOIN DM_POLICY_CRITERIA_PROPERTIES DPCP " +
|
||||
"ON DPCP.POLICY_CRITERION_ID = DPC.ID RIGHT JOIN DM_CRITERIA DC " +
|
||||
"ON DC.ID=DPC.CRITERIA_ID WHERE DPC.POLICY_ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, policyId);
|
||||
resultSet = stmt.executeQuery();
|
||||
@ -522,7 +522,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "UPDATE DM_POLICY SET NAME= ?, TENANT_ID = ?, PROFILE_ID = ?, PRIORITY = ?, COMPLIANCE = ?" +
|
||||
" WHERE ID = ?";
|
||||
" WHERE ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setString(1, policy.getPolicyName());
|
||||
stmt.setInt(2, policy.getTenantId());
|
||||
@ -746,7 +746,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
|
||||
|
||||
@Override
|
||||
public void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
|
||||
public void addEffectivePolicyToDevice(int deviceId, Policy policy)
|
||||
throws PolicyManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
@ -759,8 +759,8 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
"CREATED_TIME, UPDATED_TIME, TENANT_ID) VALUES (?, ?, ?, ?, ?, ?)";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, deviceId);
|
||||
stmt.setInt(2, policyId);
|
||||
stmt.setObject(3, profileFeatures);
|
||||
stmt.setInt(2, policy.getId());
|
||||
stmt.setObject(3, policy);
|
||||
stmt.setTimestamp(4, currentTimestamp);
|
||||
stmt.setTimestamp(5, currentTimestamp);
|
||||
stmt.setInt(6, tenantId);
|
||||
@ -804,7 +804,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
|
||||
|
||||
@Override
|
||||
public void updateEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures)
|
||||
public void updateEffectivePolicyToDevice(int deviceId, Policy policy)
|
||||
throws PolicyManagerDAOException {
|
||||
|
||||
Connection conn;
|
||||
@ -813,10 +813,10 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " +
|
||||
"APPLIED = ? WHERE DEVICE_ID = ?";
|
||||
"APPLIED = ? WHERE DEVICE_ID = ?";
|
||||
stmt = conn.prepareStatement(query);
|
||||
stmt.setInt(1, policyId);
|
||||
stmt.setObject(2, profileFeatures);
|
||||
stmt.setInt(1, policy.getId());
|
||||
stmt.setObject(2, policy);
|
||||
stmt.setTimestamp(3, currentTimestamp);
|
||||
stmt.setBoolean(4, false);
|
||||
stmt.setInt(5, deviceId);
|
||||
@ -1067,7 +1067,7 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
try {
|
||||
conn = this.getConnection();
|
||||
String query = "INSERT INTO DM_POLICY (NAME, PROFILE_ID, TENANT_ID, PRIORITY, COMPLIANCE, OWNERSHIP_TYPE)" +
|
||||
" VALUES (?, ?, ?, ?, ?, ?)";
|
||||
" VALUES (?, ?, ?, ?, ?, ?)";
|
||||
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
|
||||
|
||||
stmt.setString(1, policy.getPolicyName());
|
||||
@ -1244,11 +1244,11 @@ public class PolicyDAOImpl implements PolicyDAO {
|
||||
stmt.setInt(1, deviceId);
|
||||
resultSet = stmt.executeQuery();
|
||||
|
||||
|
||||
while (resultSet.next()) {
|
||||
ByteArrayInputStream bais = null;
|
||||
ObjectInputStream ois = null;
|
||||
byte[] contentBytes;
|
||||
|
||||
try {
|
||||
contentBytes = (byte[]) resultSet.getBytes("POLICY_CONTENT");
|
||||
bais = new ByteArrayInputStream(contentBytes);
|
||||
|
||||
@ -38,7 +38,7 @@ public interface PolicyManager {
|
||||
boolean deletePolicy(int policyId) throws PolicyManagementException;
|
||||
|
||||
Policy addPolicyToDevice(List<DeviceIdentifier> deviceIdentifierList, Policy policy) throws
|
||||
PolicyManagementException;
|
||||
PolicyManagementException;
|
||||
|
||||
Policy addPolicyToRole(List<String> roleNames, Policy policy) throws PolicyManagementException;
|
||||
|
||||
@ -60,10 +60,10 @@ public interface PolicyManager {
|
||||
|
||||
List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException;
|
||||
|
||||
void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature>
|
||||
profileFeatures) throws PolicyManagementException;
|
||||
void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
|
||||
throws PolicyManagementException;
|
||||
|
||||
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException;
|
||||
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException;
|
||||
|
||||
boolean checkPolicyAvailable(DeviceIdentifier deviceIdentifier) throws PolicyManagementException;
|
||||
|
||||
|
||||
@ -708,8 +708,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId,
|
||||
List<ProfileFeature> profileFeatures) throws PolicyManagementException {
|
||||
public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
|
||||
throws PolicyManagementException {
|
||||
|
||||
int deviceId = -1;
|
||||
try {
|
||||
@ -719,9 +719,9 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
boolean exist = policyDAO.checkPolicyAvailable(deviceId);
|
||||
PolicyManagementDAOFactory.beginTransaction();
|
||||
if (exist) {
|
||||
policyDAO.updateEffectivePolicyToDevice(deviceId, policyId, profileFeatures);
|
||||
policyDAO.updateEffectivePolicyToDevice(deviceId, policy);
|
||||
} else {
|
||||
policyDAO.addEffectivePolicyToDevice(deviceId, policyId, profileFeatures);
|
||||
policyDAO.addEffectivePolicyToDevice(deviceId, policy);
|
||||
}
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
@ -731,7 +731,7 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
log.warn("Error occurred while roll backing the transaction.");
|
||||
}
|
||||
String msg = "Error occurred while adding the evaluated policy to device (" +
|
||||
deviceId + " - " + policyId + ")";
|
||||
deviceId + " - " + policy.getId() + ")";
|
||||
log.error(msg, e);
|
||||
throw new PolicyManagementException(msg, e);
|
||||
} catch (DeviceManagementException e) {
|
||||
@ -756,12 +756,10 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
if (exist) {
|
||||
Policy policySaved = policyDAO.getAppliedPolicy(deviceId);
|
||||
if (!policy.equals(policySaved)) {
|
||||
policyDAO.updateEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile().
|
||||
getProfileFeaturesList());
|
||||
policyDAO.updateEffectivePolicyToDevice(deviceId, policy);
|
||||
}
|
||||
} else {
|
||||
policyDAO.addEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile().
|
||||
getProfileFeaturesList());
|
||||
policyDAO.addEffectivePolicyToDevice(deviceId, policy);
|
||||
}
|
||||
PolicyManagementDAOFactory.commitTransaction();
|
||||
} catch (PolicyManagerDAOException e) {
|
||||
@ -847,8 +845,8 @@ public class PolicyManagerImpl implements PolicyManager {
|
||||
try {
|
||||
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
|
||||
Device device = service.getDevice(deviceIdentifier);
|
||||
int policyId = policyDAO.getAppliedPolicyId(device.getId());
|
||||
policy = policyDAO.getPolicy(policyId);
|
||||
//int policyId = policyDAO.getAppliedPolicyId(device.getId());
|
||||
policy = policyDAO.getAppliedPolicy(device.getId());
|
||||
|
||||
} catch (DeviceManagementException e) {
|
||||
String msg = "Error occurred while getting device id.";
|
||||
|
||||
@ -59,18 +59,18 @@ public class PolicyMonitoringServiceTest implements PolicyMonitoringService {
|
||||
|
||||
List<ComplianceFeature> complianceFeatures = new ArrayList<>();
|
||||
|
||||
// List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
|
||||
List<ProfileFeature> profileFeatures = policy.getProfile().getProfileFeaturesList();
|
||||
|
||||
// for (ProfileFeature pf : profileFeatures) {
|
||||
// log.debug(pf.getFeatureCode());
|
||||
// ComplianceFeature comf = new ComplianceFeature();
|
||||
//
|
||||
// comf.setFeatureCode(pf.getFeatureCode());
|
||||
// comf.setCompliance(false);
|
||||
// comf.setMessage("This is a test....");
|
||||
//
|
||||
// complianceFeatures.add(comf);
|
||||
// }
|
||||
for (ProfileFeature pf : profileFeatures) {
|
||||
log.debug(pf.getFeatureCode());
|
||||
ComplianceFeature comf = new ComplianceFeature();
|
||||
|
||||
comf.setFeatureCode(pf.getFeatureCode());
|
||||
comf.setCompliance(false);
|
||||
comf.setMessage("This is a test....");
|
||||
|
||||
complianceFeatures.add(comf);
|
||||
}
|
||||
data.setComplianceFeatures(complianceFeatures);
|
||||
data.setStatus(false);
|
||||
|
||||
|
||||
@ -79,14 +79,14 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
|
||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
DEVICE_ID INTEGER NOT NULL,
|
||||
ENROLMENT_ID INTEGER NOT NULL,
|
||||
OPERATION_ID INTEGER NOT NULL,
|
||||
STATUS VARCHAR(50) NULL,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
@ -331,7 +331,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
|
||||
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
|
||||
ID INT NOT NULL AUTO_INCREMENT,
|
||||
COMPLIANCE_STATUS_ID INT NOT NULL,
|
||||
FEATURE_CODE INT NOT NULL,
|
||||
FEATURE_CODE VARCHAR(15) NOT NULL,
|
||||
STATUS INT NULL,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
|
||||
|
||||
@ -64,14 +64,28 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
|
||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
DEVICE_ID INTEGER NOT NULL,
|
||||
OWNER VARCHAR(50) NOT NULL,
|
||||
OWNERSHIP VARCHAR(45) NULL DEFAULT NULL,
|
||||
STATUS VARCHAR(50) NULL,
|
||||
DATE_OF_ENROLMENT TIMESTAMP NULL DEFAULT NULL,
|
||||
DATE_OF_LAST_UPDATE TIMESTAMP NULL DEFAULT NULL,
|
||||
TENANT_ID INT NOT NULL,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
ENROLMENT_ID INTEGER NOT NULL,
|
||||
OPERATION_ID INTEGER NOT NULL,
|
||||
STATUS VARCHAR(50) NULL,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
@ -303,7 +317,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS (
|
||||
CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES (
|
||||
ID INT NOT NULL AUTO_INCREMENT,
|
||||
COMPLIANCE_STATUS_ID INT NOT NULL,
|
||||
FEATURE_CODE INT NOT NULL,
|
||||
FEATURE_CODE VARCHAR(15) NOT NULL,
|
||||
STATUS INT NULL,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS
|
||||
@ -354,6 +368,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
|
||||
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
|
||||
-- POLICY RELATED TABLES FINISHED --
|
||||
|
||||
|
||||
|
||||
@ -62,14 +62,14 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_OPERATION (
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_MAPPING (
|
||||
CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OPERATION_MAPPING (
|
||||
ID INTEGER AUTO_INCREMENT NOT NULL,
|
||||
DEVICE_ID INTEGER NOT NULL,
|
||||
ENROLMENT_ID INTEGER NOT NULL,
|
||||
OPERATION_ID INTEGER NOT NULL,
|
||||
STATUS VARCHAR(50) NULL,
|
||||
PRIMARY KEY (ID),
|
||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES
|
||||
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
|
||||
DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
|
||||
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
|
||||
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
|
||||
);
|
||||
|
||||
Loading…
Reference in New Issue
Block a user