Merge branch 'milanperera-master'

merge-requests/7/head
geethkokila 9 years ago
commit 821697f24e

@ -92,4 +92,23 @@ public class EnrolmentInfo {
this.device = device; 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; 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 { private Device loadDevice(ResultSet rs) throws SQLException {
Device device = new Device(); Device device = new Device();
device.setId(rs.getInt("DEVICE_ID")); device.setId(rs.getInt("DEVICE_ID"));

@ -77,7 +77,7 @@ public class EnrolmentDAOImpl implements EnrolmentDAO {
stmt.setString(1, enrolmentInfo.getOwnership().toString()); stmt.setString(1, enrolmentInfo.getOwnership().toString());
stmt.setString(2, enrolmentInfo.getStatus().toString()); stmt.setString(2, enrolmentInfo.getStatus().toString());
stmt.setTimestamp(3, new Timestamp(enrolmentInfo.getDateOfEnrolment())); 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.setInt(5, deviceId);
stmt.setString(6, enrolmentInfo.getOwner()); stmt.setString(6, enrolmentInfo.getOwner());
stmt.setInt(7, tenantId); stmt.setInt(7, tenantId);
@ -156,9 +156,9 @@ public class EnrolmentDAOImpl implements EnrolmentDAO {
conn = this.getConnection(); conn = this.getConnection();
String sql = "SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?"; String sql = "SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = ? AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(2, deviceId); stmt.setInt(1, deviceId);
stmt.setString(3, currentOwner); stmt.setString(2, currentOwner);
stmt.setInt(4, tenantId); stmt.setInt(3, tenantId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
status = EnrolmentInfo.Status.valueOf(rs.getString("STATUS")); 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext; 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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo; 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.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; 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.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.OperationDAO;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOException;
import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory; import org.wso2.carbon.device.mgt.core.operation.mgt.dao.OperationManagementDAOFactory;
@ -91,17 +89,17 @@ public class OperationManagerImpl implements OperationManager {
int operationId = this.lookupOperationDAO(operation).addOperation(operationDto); int operationId = this.lookupOperationDAO(operation).addOperation(operationDto);
Device device; int enrolmentId;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
for (DeviceIdentifier deviceId : deviceIds) { for (DeviceIdentifier deviceId : deviceIds) {
device = deviceDAO.getDevice(deviceId, tenantId); enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
if (device == null) { if (enrolmentId < 0) {
String errorMsg = "The operation not added for device.The device not found for " + String errorMsg = "The operation not added for device.The device not found for " +
"device Identifier type -'" + deviceId.getType() + "' and device Id '" + "device Identifier type -'" + deviceId.getType() + "' and device Id '" +
deviceId.getId(); deviceId.getId();
log.info(errorMsg); log.error(errorMsg);
} else { } else {
operationMappingDAO.addOperationMapping(operationId, device.getId()); operationMappingDAO.addOperationMapping(operationId, enrolmentId);
} }
} }
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
@ -126,21 +124,25 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException { public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
List<Operation> operations = new ArrayList<Operation>();
int enrolmentId = -1;
try { try {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); 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 " + 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 = List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList = operationDAO
operationDAO.getOperationsForDevice(device.getId()); .getOperationsForDevice(enrolmentId);
Operation operation; Operation operation;
List<Operation> operations = new ArrayList<Operation>();
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) { for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : operationList) {
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
operations.add(operation); operations.add(operation);
@ -160,6 +162,7 @@ public class OperationManagerImpl implements OperationManager {
log.warn("Error occurred while closing data source connection", e); log.warn("Error occurred while closing data source connection", e);
} }
} }
} }
@Override @Override
@ -171,7 +174,7 @@ public class OperationManagerImpl implements OperationManager {
+ "]"); + "]");
} }
Device device; int enrolmentId = -1;
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList = List<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> dtoOperationList =
@ -181,30 +184,24 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); 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 " + 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( dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(
EnrolmentInfo.Status.ACTIVE)) { enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.updateDeviceEnrolmentInfo(device, EnrolmentInfo.Status.ACTIVE);
}
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(device.getId(), dtoOperationList.addAll(configOperationDAO.getOperationsByDeviceAndStatus(
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); 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(device.getId(), dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(device.getId(), dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); enrolmentId, org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
Operation operation; Operation operation;
for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) { for (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation : dtoOperationList) {
@ -223,9 +220,6 @@ public class OperationManagerImpl implements OperationManager {
+ deviceId.getId(); + deviceId.getId();
log.error(errorMsg, e); log.error(errorMsg, e);
throw new OperationManagementException(errorMsg, e); throw new OperationManagementException(errorMsg, e);
} catch (DeviceManagementException e) {
throw new OperationManagementException("Error occurred while update enrol status: " +
deviceId.toString(), e);
} finally { } finally {
try { try {
OperationManagementDAOFactory.closeConnection(); OperationManagementDAOFactory.closeConnection();
@ -242,31 +236,19 @@ public class OperationManagerImpl implements OperationManager {
+ "]"); + "]");
} }
Operation operation = null; Operation operation = null;
Device device; int enrolmentId = -1;
try { try {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); 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 " + 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 org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
.getNextOperation(device.getId()); .getNextOperation(enrolmentId);
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);
}
}
if (dtoOperation != null) { if (dtoOperation != null) {
if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND if (org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND
@ -315,19 +297,21 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.beginTransaction(); OperationManagementDAOFactory.beginTransaction();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
Device device = deviceDAO.getDevice(deviceId, tenantId); int enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
if (operation.getStatus() != null) { if (operation.getStatus() != null) {
OperationManagementDAOFactory.beginTransaction(); OperationManagementDAOFactory.beginTransaction();
operationDAO.updateOperationStatus(device.getId(), operationId, operationDAO.updateOperationStatus(enrolmentId, operationId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status
.valueOf(operation.getStatus().toString())); .valueOf(operation.getStatus().toString()));
} }
if (operation.getOperationResponse() != null) { 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) { } catch (OperationManagementDAOException e) {
try { try {
OperationManagementDAOFactory.rollbackTransaction(); OperationManagementDAOFactory.rollbackTransaction();
@ -381,7 +365,7 @@ public class OperationManagerImpl implements OperationManager {
@Override @Override
public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId) public Operation getOperationByDeviceAndOperationId(DeviceIdentifier deviceId, int operationId)
throws OperationManagementException { throws OperationManagementException {
Device device; int enrolmentId = -1;
Operation operation; Operation operation;
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -393,13 +377,13 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); 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:" + 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 org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation dtoOperation = operationDAO
.getOperationByDeviceAndId(device.getId(), operationId); .getOperationByDeviceAndId(enrolmentId, operationId);
if (dtoOperation.getType() if (dtoOperation.getType()
.equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) { .equals(org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Type.COMMAND)) {
@ -422,7 +406,7 @@ public class OperationManagerImpl implements OperationManager {
if (dtoOperation == null) { if (dtoOperation == null) {
throw new OperationManagementException("Operation not found for operation Id:" + operationId + throw new OperationManagementException("Operation not found for operation Id:" + operationId +
" device" + " Id:" + device.getId()); " device id:" + deviceId.getId());
} }
operation = OperationDAOUtil.convertOperation(dtoOperation); operation = OperationDAOUtil.convertOperation(dtoOperation);
} catch (OperationManagementDAOException e) { } catch (OperationManagementDAOException e) {
@ -455,24 +439,27 @@ public class OperationManagerImpl implements OperationManager {
OperationManagementDAOFactory.getConnection(); OperationManagementDAOFactory.getConnection();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); 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() + " " + 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 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()); .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(), dtoOperationList.addAll(
configOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
dtoOperationList.addAll(profileOperationDAO.getOperationsByDeviceAndStatus(device.getId(), dtoOperationList.addAll(
profileOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
dtoOperationList.addAll(policyOperationDAO.getOperationsByDeviceAndStatus(device.getId(), dtoOperationList.addAll(
policyOperationDAO.getOperationsByDeviceAndStatus(enrolmentId,
org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING)); org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation.Status.PENDING));
Operation operation; Operation operation;

@ -22,15 +22,15 @@ import java.util.List;
public class PolicyOperation extends Operation { public class PolicyOperation extends Operation {
public static final String POLICY_OPERATION_CODE = "POLICY_BUNDLE";
private List<ProfileOperation> profileOperations;
public List<ProfileOperation> getProfileOperations() { public List<ProfileOperation> getProfileOperations() {
return profileOperations; return profileOperations;
} }
public static final String POLICY_OPERATION_CODE = "POLICY_BUNDLE";
public void setProfileOperations(List<ProfileOperation> profileOperations) { public void setProfileOperations(List<ProfileOperation> profileOperations) {
this.profileOperations = profileOperations; this.profileOperations = profileOperations;
} }
private List<ProfileOperation> profileOperations;
} }

@ -18,7 +18,6 @@
*/ */
package org.wso2.carbon.device.mgt.core.operation.mgt.dao; package org.wso2.carbon.device.mgt.core.operation.mgt.dao;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation;
import java.util.List; import java.util.List;
@ -33,18 +32,18 @@ public interface OperationDAO {
Operation getOperation(int operationId) throws OperationManagementDAOException; 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; 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; throws OperationManagementDAOException;
void addOperationResponse(int deviceId, int operationId, Object operationResponse) void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException; throws OperationManagementDAOException;
} }

@ -130,7 +130,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId, public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -146,11 +146,11 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "Select co.OPERATION_ID,ENABLED from DM_COMMAND_OPERATION co " + String sql = "Select co.OPERATION_ID,ENABLED from DM_COMMAND_OPERATION co " +
"INNER JOIN " + "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"; "AND STATUS=? ) dm ON dm.OPERATION_ID = co.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -169,7 +169,7 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
} }
} catch (SQLException 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(); "' with status '" + status.toString();
log.error(errorMsg); log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);

@ -168,7 +168,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId, public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -184,11 +184,11 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "Select co.OPERATION_ID, co.OPERATION_CONFIG from DM_CONFIG_OPERATION co " + String sql = "Select co.OPERATION_ID, co.OPERATION_CONFIG from DM_CONFIG_OPERATION co " +
"INNER JOIN " + "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"; "AND STATUS=?) dm ON dm.OPERATION_ID = co.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -211,7 +211,7 @@ public class ConfigOperationDAOImpl extends OperationDAOImpl {
log.error(errorMsg, e); log.error(errorMsg, e);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);
} catch (SQLException 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(); "' with status '" + status.toString();
log.error(errorMsg); log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e); 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 { throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("UPDATE DM_DEVICE_OPERATION_MAPPING O SET O.STATUS=? " + stmt = connection.prepareStatement("UPDATE DM_ENROLMENT_OPERATION_MAPPING O SET O.STATUS=? " +
"WHERE O.DEVICE_ID=? and O.OPERATION_ID=?"); "WHERE O.ENROLMENT_ID=? and O.OPERATION_ID=?");
stmt.setString(1, status.toString()); stmt.setString(1, status.toString());
stmt.setInt(2, deviceId); stmt.setInt(2, enrolmentId);
stmt.setInt(3, operationId); stmt.setInt(3, operationId);
stmt.executeUpdate(); stmt.executeUpdate();
@ -111,7 +111,7 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public void addOperationResponse(int deviceId, int operationId, Object operationResponse) public void addOperationResponse(int enrolmentId, int operationId, Object operationResponse)
throws OperationManagementDAOException { throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -129,7 +129,7 @@ public class OperationDAOImpl implements OperationDAO {
oos.writeObject(operationResponse); oos.writeObject(operationResponse);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setInt(2, deviceId); stmt.setInt(2, enrolmentId);
stmt.setBytes(3, bao.toByteArray()); stmt.setBytes(3, bao.toByteArray());
stmt.executeUpdate(); stmt.executeUpdate();
@ -214,7 +214,7 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public Operation getOperationByDeviceAndId(int deviceId, int operationId) throws OperationManagementDAOException { public Operation getOperationByDeviceAndId(int enrolmentId, int operationId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = 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 " + 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," + " From (SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, STATUS," +
"OPERATION_CODE FROM DM_OPERATION WHERE id=?) o INNER JOIN (Select * from " + "OPERATION_CODE FROM DM_OPERATION WHERE id=?) o INNER JOIN (Select * from " +
"DM_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 "; "ON o.ID = om.OPERATION_ID ";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, operationId); stmt.setInt(1, operationId);
stmt.setInt(2, operationId); stmt.setInt(2, operationId);
stmt.setInt(3, deviceId); stmt.setInt(3, enrolmentId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
@ -247,7 +247,7 @@ public class OperationDAOImpl implements OperationDAO {
operation.setCode(rs.getString("OPERATION_CODE")); operation.setCode(rs.getString("OPERATION_CODE"));
} }
} catch (SQLException 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 id '" + operationId; "' with id '" + operationId;
log.error(errorMsg); log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);
@ -259,7 +259,7 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId, public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -272,11 +272,11 @@ public class OperationDAOImpl implements OperationDAO {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
"FROM DM_OPERATION o " + "FROM DM_OPERATION o " +
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " + "INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
"where dm.DEVICE_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; "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 = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -296,7 +296,7 @@ public class OperationDAOImpl implements OperationDAO {
operationList.add(operation); operationList.add(operation);
} }
} catch (SQLException 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(); "' with status '" + status.toString();
log.error(errorMsg); log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);
@ -308,7 +308,7 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public List<? extends Operation> getOperationsForDevice(int deviceId) public List<? extends Operation> getOperationsForDevice(int enrolmentId)
throws OperationManagementDAOException { throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -321,11 +321,11 @@ public class OperationDAOImpl implements OperationDAO {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
"OPERATION_CODE,dm.STATUS FROM DM_OPERATION o " + "OPERATION_CODE,dm.STATUS FROM DM_OPERATION o " +
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " + "INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
"where dm.DEVICE_ID=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; "where dm.ENROLMENT_ID=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, enrolmentId);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -344,7 +344,7 @@ public class OperationDAOImpl implements OperationDAO {
operationList.add(operation); operationList.add(operation);
} }
} catch (SQLException 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 '"; "' with status '";
log.error(errorMsg); log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);
@ -356,7 +356,7 @@ public class OperationDAOImpl implements OperationDAO {
} }
@Override @Override
public Operation getNextOperation(int deviceId) throws OperationManagementDAOException { public Operation getNextOperation(int enrolmentId) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
@ -365,11 +365,11 @@ public class OperationDAOImpl implements OperationDAO {
Connection connection = OperationManagementDAOFactory.getConnection(); Connection connection = OperationManagementDAOFactory.getConnection();
stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " + stmt = connection.prepareStatement("SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, " +
"OPERATION_CODE FROM DM_OPERATION o " + "OPERATION_CODE FROM DM_OPERATION o " +
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " + "INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
"where dm.DEVICE_ID=? AND dm.STATUS=?) om ON o.ID = om.OPERATION_ID " + "where dm.ENROLMENT_ID=? AND dm.STATUS=?) om ON o.ID = om.OPERATION_ID " +
"ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1"); "ORDER BY o.CREATED_TIMESTAMP ASC LIMIT 1");
stmt.setInt(1, deviceId); stmt.setInt(1, enrolmentId);
stmt.setString(2, Operation.Status.PENDING.toString()); stmt.setString(2, Operation.Status.PENDING.toString());
rs = stmt.executeQuery(); 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 { Operation.Status status, Operation.Type type) throws OperationManagementDAOException {
PreparedStatement stmt = null; 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 " + String sql = "SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE FROM " +
"(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " + "(SELECT o.ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE " +
"FROM DM_OPERATION o WHERE o.TYPE=?) o " + "FROM DM_OPERATION o WHERE o.TYPE=?) o " +
"INNER JOIN (Select * from DM_DEVICE_OPERATION_MAPPING dm " + "INNER JOIN (Select * from DM_ENROLMENT_OPERATION_MAPPING dm " +
"where dm.DEVICE_ID=? and dm.STATUS=?) om ON o.ID = om.OPERATION_ID ORDER BY o.CREATED_TIMESTAMP ASC"; "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 = conn.prepareStatement(sql);
stmt.setString(1, type.toString()); stmt.setString(1, type.toString());
stmt.setInt(2, deviceId); stmt.setInt(2, enrolmentId);
stmt.setString(3, status.toString()); stmt.setString(3, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -436,7 +436,7 @@ public class OperationDAOImpl implements OperationDAO {
operationList.add(operation); operationList.add(operation);
} }
} catch (SQLException 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(); "' with status '" + status.toString();
log.error(errorMsg); log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);

@ -35,7 +35,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); 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 = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
stmt.setInt(2, operationId); stmt.setInt(2, operationId);
@ -54,7 +54,7 @@ public class OperationMappingDAOImpl implements OperationMappingDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); 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 = conn.prepareStatement(sql);
stmt.setInt(1, 0); stmt.setInt(1, 0);
stmt.setInt(2, operationId); stmt.setInt(2, operationId);

@ -171,7 +171,7 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId, public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -187,11 +187,11 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_POLICY_OPERATION po " + String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_POLICY_OPERATION po " +
"INNER JOIN " + "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"; "AND STATUS=?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -214,7 +214,7 @@ public class PolicyOperationDAOImpl extends OperationDAOImpl {
log.error(errorMsg, e); log.error(errorMsg, e);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);
} catch (SQLException 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(); "' with status '" + status.toString();
log.error(errorMsg); log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);

@ -167,7 +167,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
} }
@Override @Override
public List<? extends Operation> getOperationsByDeviceAndStatus(int deviceId, public List<? extends Operation> getOperationsByDeviceAndStatus(int enrolmentId,
Operation.Status status) throws OperationManagementDAOException { Operation.Status status) throws OperationManagementDAOException {
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -183,11 +183,11 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_PROFILE_OPERATION po " + String sql = "Select po.OPERATION_ID, ENABLED, OPERATION_DETAILS from DM_PROFILE_OPERATION po " +
"INNER JOIN " + "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"; "AND STATUS=?) dm ON dm.OPERATION_ID = po.OPERATION_ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, deviceId); stmt.setInt(1, enrolmentId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
@ -210,7 +210,7 @@ public class ProfileOperationDAOImpl extends OperationDAOImpl {
log.error(errorMsg, e); log.error(errorMsg, e);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);
} catch (SQLException 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(); "' with status '" + status.toString();
log.error(errorMsg); log.error(errorMsg);
throw new OperationManagementDAOException(errorMsg, e); throw new OperationManagementDAOException(errorMsg, e);

@ -67,6 +67,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementServiceComponent.registerPluginInitializationListener(this); DeviceManagementServiceComponent.registerPluginInitializationListener(this);
} }
/**
* This constructor calls from unit tests
*
* @param pluginRepo
*/
DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test) { DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test) {
this.pluginRepository = pluginRepo; this.pluginRepository = pluginRepo;
initDataAccessObjects(); initDataAccessObjects();
@ -106,23 +111,50 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override @Override
public boolean enrollDevice(Device device) throws DeviceManagementException { public boolean enrollDevice(Device device) throws DeviceManagementException {
boolean status = false;
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType());
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager(); this.getPluginRepository().getDeviceManagementService(device.getType()).getDeviceManager();
boolean status = dms.enrollDevice(device); dms.enrollDevice(device);
try { try {
if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) { if (dms.isClaimable(deviceIdentifier)) {
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.INACTIVE); device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.INACTIVE);
} else { } else {
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE); device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE);
} }
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
Device existingDevice = this.getDevice(deviceIdentifier);
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(); DeviceManagementDAOFactory.beginTransaction();
int enrolmentId = enrolmentDAO.addEnrollment(existingDevice.getId(), newEnrolmentInfo, tenantId);
DeviceManagementDAOFactory.commitTransaction();
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()); DeviceType type = deviceTypeDAO.getDeviceType(device.getType());
int deviceId = deviceDAO.addDevice(type.getId(), device, tenantId); int deviceId = deviceDAO.addDevice(type.getId(), device, tenantId);
int enrolmentId = enrolmentDAO.addEnrollment(deviceId, device.getEnrolmentInfo(), tenantId); int enrolmentId = enrolmentDAO.addEnrollment(deviceId, device.getEnrolmentInfo(), tenantId);
DeviceManagementDAOFactory.commitTransaction();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("An enrolment is successfully created with the id '" + enrolmentId + "' associated with " + log.debug("An enrolment is successfully created with the id '" + enrolmentId + "' associated with " +
@ -130,7 +162,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
"platform '" + device.getType() + " upon the user '" + "platform '" + device.getType() + " upon the user '" +
device.getEnrolmentInfo().getOwner() + "'"); device.getEnrolmentInfo().getOwner() + "'");
} }
DeviceManagementDAOFactory.commitTransaction(); status = true;
}
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
try { try {
DeviceManagementDAOFactory.rollbackTransaction(); DeviceManagementDAOFactory.rollbackTransaction();
@ -150,7 +184,6 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
@Override @Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException { public boolean modifyEnrollment(Device device) throws DeviceManagementException {
DeviceManager dms = DeviceManager dms =
@ -194,6 +227,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED); device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
enrolmentDAO.updateEnrollment(device.getId(), device.getEnrolmentInfo(), tenantId);
deviceDAO.updateDevice(deviceType.getId(), device, tenantId); deviceDAO.updateDevice(deviceType.getId(), device, tenantId);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
@ -772,6 +806,4 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
return devices; 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 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 ( CREATE TABLE IF NOT EXISTS DM_ENROLMENT (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER 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 CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION 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 ( CREATE TABLE IF NOT EXISTS DM_APPLICATION (
ID INTEGER AUTO_INCREMENT NOT NULL, ID INTEGER AUTO_INCREMENT NOT NULL,
NAME VARCHAR(50) 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.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.io.Serializable;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.util.List; import java.util.List;
@XmlRootElement @XmlRootElement
public class Profile { public class Profile implements Serializable {
private int profileId; private int profileId;
private String profileName; private String profileName;

@ -89,12 +89,12 @@ public interface PolicyDAO {
List<String> getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException; List<String> getPolicyAppliedUsers(int policyId) throws PolicyManagerDAOException;
void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures) void addEffectivePolicyToDevice(int deviceId, Policy policy)
throws PolicyManagerDAOException; throws PolicyManagerDAOException;
void setPolicyApplied(int deviceId) 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; throws PolicyManagerDAOException;
boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException; boolean checkPolicyAvailable(int deviceId) throws PolicyManagerDAOException;

@ -749,7 +749,7 @@ public class PolicyDAOImpl implements PolicyDAO {
@Override @Override
public void addEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures) public void addEffectivePolicyToDevice(int deviceId, Policy policy)
throws PolicyManagerDAOException { throws PolicyManagerDAOException {
Connection conn; Connection conn;
@ -761,8 +761,8 @@ public class PolicyDAOImpl implements PolicyDAO {
"(DEVICE_ID, POLICY_ID, POLICY_CONTENT, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?, ?, ?)"; "(DEVICE_ID, POLICY_ID, POLICY_CONTENT, CREATED_TIME, UPDATED_TIME) VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
stmt.setInt(2, policyId); stmt.setInt(2, policy.getId());
stmt.setObject(3, profileFeatures); stmt.setObject(3, policy);
stmt.setTimestamp(4, currentTimestamp); stmt.setTimestamp(4, currentTimestamp);
stmt.setTimestamp(5, currentTimestamp); stmt.setTimestamp(5, currentTimestamp);
@ -805,7 +805,7 @@ public class PolicyDAOImpl implements PolicyDAO {
@Override @Override
public void updateEffectivePolicyToDevice(int deviceId, int policyId, List<ProfileFeature> profileFeatures) public void updateEffectivePolicyToDevice(int deviceId, Policy policy)
throws PolicyManagerDAOException { throws PolicyManagerDAOException {
Connection conn; Connection conn;
@ -816,8 +816,8 @@ public class PolicyDAOImpl implements PolicyDAO {
String query = "UPDATE DM_DEVICE_POLICY_APPLIED SET POLICY_ID = ?, POLICY_CONTENT = ?, UPDATED_TIME = ?, " + 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 = conn.prepareStatement(query);
stmt.setInt(1, policyId); stmt.setInt(1, policy.getId());
stmt.setObject(2, profileFeatures); stmt.setObject(2, policy);
stmt.setTimestamp(3, currentTimestamp); stmt.setTimestamp(3, currentTimestamp);
stmt.setBoolean(4, false); stmt.setBoolean(4, false);
stmt.setInt(5, deviceId); stmt.setInt(5, deviceId);
@ -1245,10 +1245,11 @@ public class PolicyDAOImpl implements PolicyDAO {
stmt.setInt(1, deviceId); stmt.setInt(1, deviceId);
resultSet = stmt.executeQuery(); resultSet = stmt.executeQuery();
ByteArrayInputStream bais = null; ByteArrayInputStream bais = null;
ObjectInputStream ois = null; ObjectInputStream ois = null;
byte[] contentBytes; byte[] contentBytes;
while (resultSet.next()) {
try { try {
contentBytes = (byte[]) resultSet.getBytes("POLICY_CONTENT"); contentBytes = (byte[]) resultSet.getBytes("POLICY_CONTENT");
bais = new ByteArrayInputStream(contentBytes); bais = new ByteArrayInputStream(contentBytes);
@ -1270,6 +1271,7 @@ public class PolicyDAOImpl implements PolicyDAO {
} }
} }
} }
}
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while getting the applied policy."; String msg = "Error occurred while getting the applied policy.";

@ -60,8 +60,8 @@ public interface PolicyManager {
List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException; List<Device> getPolicyAppliedDevicesIds(int policyId) throws PolicyManagementException;
void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, List<ProfileFeature> void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
profileFeatures) throws PolicyManagementException; throws PolicyManagementException;
void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException; void addAppliedPolicyToDevice(DeviceIdentifier deviceIdentifier, Policy policy) throws PolicyManagementException;

@ -214,7 +214,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
Map<Integer, ComplianceData> tempMap = new HashMap<>(); Map<Integer, ComplianceData> tempMap = new HashMap<>();
if (complianceDatas != null) {
for (ComplianceData complianceData : complianceDatas) { for (ComplianceData complianceData : complianceDatas) {
tempMap.put(complianceData.getDeviceId(), complianceData); tempMap.put(complianceData.getDeviceId(), complianceData);
@ -231,6 +231,7 @@ public class MonitoringManagerImpl implements MonitoringManager {
deviceIds.get(complianceData.getDeviceId())); deviceIds.get(complianceData.getDeviceId()));
} }
} }
}
for (Device device : devices) { for (Device device : devices) {
if (!tempMap.containsKey(device.getId())) { if (!tempMap.containsKey(device.getId())) {

@ -708,8 +708,8 @@ public class PolicyManagerImpl implements PolicyManager {
} }
@Override @Override
public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, int policyId, public void addAppliedPolicyFeaturesToDevice(DeviceIdentifier deviceIdentifier, Policy policy)
List<ProfileFeature> profileFeatures) throws PolicyManagementException { throws PolicyManagementException {
int deviceId = -1; int deviceId = -1;
try { try {
@ -719,9 +719,9 @@ public class PolicyManagerImpl implements PolicyManager {
boolean exist = policyDAO.checkPolicyAvailable(deviceId); boolean exist = policyDAO.checkPolicyAvailable(deviceId);
PolicyManagementDAOFactory.beginTransaction(); PolicyManagementDAOFactory.beginTransaction();
if (exist) { if (exist) {
policyDAO.updateEffectivePolicyToDevice(deviceId, policyId, profileFeatures); policyDAO.updateEffectivePolicyToDevice(deviceId, policy);
} else { } else {
policyDAO.addEffectivePolicyToDevice(deviceId, policyId, profileFeatures); policyDAO.addEffectivePolicyToDevice(deviceId, policy);
} }
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
@ -731,7 +731,7 @@ public class PolicyManagerImpl implements PolicyManager {
log.warn("Error occurred while roll backing the transaction."); log.warn("Error occurred while roll backing the transaction.");
} }
String msg = "Error occurred while adding the evaluated policy to device (" + String msg = "Error occurred while adding the evaluated policy to device (" +
deviceId + " - " + policyId + ")"; deviceId + " - " + policy.getId() + ")";
log.error(msg, e); log.error(msg, e);
throw new PolicyManagementException(msg, e); throw new PolicyManagementException(msg, e);
} catch (DeviceManagementException e) { } catch (DeviceManagementException e) {
@ -756,12 +756,10 @@ public class PolicyManagerImpl implements PolicyManager {
if (exist) { if (exist) {
Policy policySaved = policyDAO.getAppliedPolicy(deviceId); Policy policySaved = policyDAO.getAppliedPolicy(deviceId);
if (!policy.equals(policySaved)) { if (!policy.equals(policySaved)) {
policyDAO.updateEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile(). policyDAO.updateEffectivePolicyToDevice(deviceId, policy);
getProfileFeaturesList());
} }
} else { } else {
policyDAO.addEffectivePolicyToDevice(deviceId, policy.getId(), policy.getProfile(). policyDAO.addEffectivePolicyToDevice(deviceId, policy);
getProfileFeaturesList());
} }
PolicyManagementDAOFactory.commitTransaction(); PolicyManagementDAOFactory.commitTransaction();
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {

@ -79,14 +79,14 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION 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, ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
STATUS VARCHAR(50) NULL, STATUS VARCHAR(50) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );

@ -64,14 +64,28 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_OPERATION (
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION 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, ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER 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, OPERATION_ID INTEGER NOT NULL,
STATUS VARCHAR(50) NULL, STATUS VARCHAR(50) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
@ -353,6 +367,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_APPLICATION_MAPPING (
DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_APPLICATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );
-- POLICY RELATED TABLES FINISHED -- -- 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 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, ID INTEGER AUTO_INCREMENT NOT NULL,
DEVICE_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL,
OPERATION_ID INTEGER NOT NULL, OPERATION_ID INTEGER NOT NULL,
STATUS VARCHAR(50) NULL, STATUS VARCHAR(50) NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (DEVICE_ID) REFERENCES CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES
DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES
DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
); );

Loading…
Cancel
Save