Set device enrolment status

revert-70aa11f8
manoj 10 years ago
parent 65620a7389
commit 6263a550ff

@ -26,11 +26,11 @@ public class EnrolmentInfo {
private Status status;
private String owner;
public enum Status {
public static enum Status {
CREATED, ACTIVE, INACTIVE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED
}
public enum OwnerShip {
public static enum OwnerShip {
BYOD, COPE
}

@ -76,12 +76,16 @@ public class DeviceDAOImpl implements DeviceDAO {
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String sql = "UPDATE DM_DEVICE SET STATUS = ?, OWNER = ? WHERE DEVICE_IDENTIFICATION = ? AND TENANT_ID = ?";
String sql = "UPDATE DM_DEVICE SET STATUS = ?, OWNER = ?, DATE_OF_ENROLLMENT=?, " +
"DATE_OF_LAST_UPDATE=? WHERE DEVICE_IDENTIFICATION = ? AND TENANT_ID = ? AND DEVICE_TYPE_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setString(1, device.getEnrolmentInfo().getStatus().toString());
stmt.setString(2, device.getEnrolmentInfo().getOwner());
stmt.setString(3, device.getDeviceIdentifier());
stmt.setInt(4, tenantId);
stmt.setLong(3, device.getEnrolmentInfo().getDateOfEnrolment());
stmt.setLong(4, device.getEnrolmentInfo().getDateOfLastUpdate());
stmt.setString(5, device.getDeviceIdentifier());
stmt.setInt(6, typeId);
stmt.setInt(7, tenantId);
stmt.executeUpdate();
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while enrolling device '" +

@ -44,6 +44,7 @@ import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, PluginInitializationListener {
@ -100,6 +101,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.beginTransaction();
DeviceType type = deviceTypeDAO.getDeviceType(device.getType());
device.getEnrolmentInfo().setDateOfEnrolment(new Date().getTime());
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
deviceDAO.addDevice(type.getId(), device, tenantId);
DeviceManagementDAOFactory.commitTransaction();
@ -121,6 +124,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return status;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
DeviceManager dms =
@ -130,9 +135,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManagementDAOFactory.beginTransaction();
DeviceType type = deviceTypeDAO.getDeviceType(device.getType());
deviceDAO.updateDevice(type.getId(), device, tenantId);
deviceDAO.updateDevice(type.getId(),device, tenantId);
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
@ -155,8 +159,24 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceManager dms =
this.getPluginRepository().getDeviceManagementService(deviceId.getType());
try {
Device device = deviceDAO.getDevice(deviceId,tenantId);
DeviceType deviceType = deviceTypeDAO.getDeviceType(device.getType());
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
deviceDAO.updateDevice(deviceType.getId(), device, tenantId);
} catch (DeviceManagementDAOException e) {
String errorMsg = "Error occurred while fetch device for device Identifier:";
log.error(errorMsg + deviceId.toString(),e);
throw new DeviceManagementException(errorMsg, e);
}
return dms.disenrollDevice(deviceId);
}

@ -30,6 +30,7 @@ import org.wso2.carbon.apimgt.impl.APIConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.core.api.mgt.APIConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig;
import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition;

Loading…
Cancel
Save