Partial Commit

revert-70aa11f8
milanperera 9 years ago
parent 6f56e27f1d
commit 35ce4be1a1

@ -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"));

@ -21,9 +21,7 @@ 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.EnrolmentInfo; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
@ -32,7 +30,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 +88,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();
@ -128,20 +125,20 @@ public class OperationManagerImpl implements OperationManager {
try { try {
List<Operation> operations = new ArrayList<Operation>(); List<Operation> operations = new ArrayList<Operation>();
Device device = null; int enrolmentId = -1;
try { try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
device = deviceDAO.getDevice(deviceId, tenantId); enrolmentId = deviceDAO.getEnrolmentByStatus(deviceId, EnrolmentInfo.Status.ACTIVE, tenantId);
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
e.printStackTrace(); e.printStackTrace();
} }
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 = operationDAO List<? extends org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation> operationList = operationDAO
.getOperationsForDevice(device.getId()); .getOperationsForDevice(enrolmentId);
Operation operation; Operation 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);
@ -164,7 +161,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 =
@ -172,38 +169,23 @@ public class OperationManagerImpl implements OperationManager {
try { try {
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.getEnrolmentInfo().getStatus() !=null && !device.getEnrolmentInfo().getStatus().equals( if (enrolmentId < 0) {
EnrolmentInfo.Status.ACTIVE)){
try {
DeviceManagementDataHolder.getInstance().getDeviceManagementProvider()
.updateDeviceEnrolmentInfo(device,
EnrolmentInfo.Status.ACTIVE);
}catch (DeviceManagementException deviceMgtEx){
String errorMsg = "Error occurred while update enrol status: "+deviceId.toString();
log.error(errorMsg, deviceMgtEx);
throw new OperationManagementException(errorMsg, deviceMgtEx);
}
}
if (device == null) {
throw new OperationManagementException("Device not found for given device " + throw new OperationManagementException("Device not found for given device " +
"Identifier:" + deviceId.getId() + " and given type:" + deviceId.getType()); "Identifier:" + deviceId.getId() + " and given type:" + deviceId.getType());
} }
dtoOperationList.addAll(commandOperationDAO.getOperationsByDeviceAndStatus(device.getId(), dtoOperationList.addAll(commandOperationDAO.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(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;
@ -234,30 +216,17 @@ public class OperationManagerImpl implements OperationManager {
+ "]"); + "]");
} }
Operation operation = null; Operation operation = null;
Device device; int enrolmentId = -1;
try { try {
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 deviceMgtEx){
String errorMsg = "Error occurred while update enrol status: "+deviceId.toString();
log.error(errorMsg, deviceMgtEx);
throw new OperationManagementException(errorMsg, deviceMgtEx);
}
}
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
@ -303,11 +272,11 @@ public class OperationManagerImpl implements OperationManager {
try { try {
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()));
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
@ -315,7 +284,7 @@ public class OperationManagerImpl implements OperationManager {
if (operation.getOperationResponse() != null){ if (operation.getOperationResponse() != null){
OperationManagementDAOFactory.beginTransaction(); OperationManagementDAOFactory.beginTransaction();
operationDAO.addOperationResponse(device.getId(), operationId, operation.getOperationResponse()); operationDAO.addOperationResponse(enrolmentId, operationId, operation.getOperationResponse());
OperationManagementDAOFactory.commitTransaction(); OperationManagementDAOFactory.commitTransaction();
} }
} catch (OperationManagementDAOException ex) { } catch (OperationManagementDAOException ex) {
@ -362,7 +331,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()) {
@ -372,13 +341,13 @@ public class OperationManagerImpl implements OperationManager {
try { try {
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)) {
@ -400,7 +369,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) {
@ -427,24 +396,27 @@ public class OperationManagerImpl implements OperationManager {
new ArrayList<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation>(); new ArrayList<org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation>();
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;

@ -70,9 +70,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
/** /**
* This constructor calls from unit tests * This constructor calls from unit tests
*
* @param pluginRepo * @param pluginRepo
*/ */
DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test){ DeviceManagementProviderServiceImpl(DeviceManagementPluginRepository pluginRepo, boolean test) {
this.pluginRepository = pluginRepo; this.pluginRepository = pluginRepo;
initDataAccessObjects(); initDataAccessObjects();
isTest = test; isTest = test;
@ -98,23 +99,49 @@ 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 = getTenantId(); int tenantId = 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)) {
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 " +
@ -122,7 +149,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();
@ -142,7 +171,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 =
@ -181,7 +209,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManager dms = DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager(); this.getPluginRepository().getDeviceManagementService(deviceId.getType()).getDeviceManager();
try { try {
Device device = deviceDAO.getDevice(deviceId,tenantId); Device device = deviceDAO.getDevice(deviceId, tenantId);
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType()); DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
@ -190,7 +218,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} catch (DeviceManagementDAOException e) { } catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while fetch device for device Identifier:"; String errorMsg = "Error occurred while fetch device for device Identifier:";
log.error(errorMsg + deviceId.toString(),e); log.error(errorMsg + deviceId.toString(), e);
throw new DeviceManagementException(errorMsg, e); throw new DeviceManagementException(errorMsg, e);
} }
@ -689,8 +717,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime()); device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
device.getEnrolmentInfo().setStatus(status); device.getEnrolmentInfo().setStatus(status);
deviceDAO.updateDevice(deviceType.getId(), device, tenantId); deviceDAO.updateDevice(deviceType.getId(), device, tenantId);
}catch (DeviceManagementDAOException deviceDaoEx){ } catch (DeviceManagementDAOException deviceDaoEx) {
String errorMsg = "Error occured update device enrolment status : "+device.getId(); String errorMsg = "Error occured update device enrolment status : " + device.getId();
log.error(errorMsg, deviceDaoEx); log.error(errorMsg, deviceDaoEx);
throw new DeviceManagementException(errorMsg, deviceDaoEx); throw new DeviceManagementException(errorMsg, deviceDaoEx);
} }
@ -754,15 +782,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
private int getTenantId() { private int getTenantId() {
ThreadLocal<Integer> tenantId = new ThreadLocal<Integer>(); ThreadLocal<Integer> tenantId = new ThreadLocal<Integer>();
int tenant = 0; int tenant = 0;
if (isTest){ if (isTest) {
tenant = DeviceManagerUtil.currentTenant.get(); tenant = DeviceManagerUtil.currentTenant.get();
}else{ } else {
tenant = CarbonContext.getThreadLocalCarbonContext().getTenantId(); tenant = CarbonContext.getThreadLocalCarbonContext().getTenantId();
} }
return tenant; return tenant;

Loading…
Cancel
Save