Introducing a separate bean to carry all enrolment data

revert-70aa11f8
prabathabey 10 years ago
parent 60960d80b4
commit 2526d87c21

@ -21,32 +21,17 @@ import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlRootElement;
import java.util.List; import java.util.List;
@XmlRootElement
public class Device { public class Device {
private int id; private int id;
private String name;
private String type; private String type;
private String description; private String description;
private String name;
private Long dateOfEnrolment;
private Long dateOfLastUpdate;
private String ownership;
private Status status;
private String deviceType;
private String deviceIdentifier; private String deviceIdentifier;
private String owner; private EnrolmentInfo enrolmentInfo;
private List<Feature> features; private List<Feature> features;
private List<Device.Property> properties; private List<Device.Property> properties;
public enum Status {
ACTIVE, INACTIVE, UNCLAIMED
}
public enum OwnerShip {
BYOD, COPE
}
@XmlElement
public int getId() { public int getId() {
return id; return id;
} }
@ -55,70 +40,30 @@ public class Device {
this.id = id; this.id = id;
} }
@XmlElement public String getName() {
public String getDescription() { return name;
return description; }
}
public void setDescription(String description) {
this.description = description;
}
@XmlElement
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
@XmlElement
public Long getDateOfEnrolment() {
return dateOfEnrolment;
}
public void setDateOfEnrolment(Long dateOfEnrolment) {
this.dateOfEnrolment = dateOfEnrolment;
}
@XmlElement
public Long getDateOfLastUpdate() {
return dateOfLastUpdate;
}
public void setDateOfLastUpdate(Long dateOfLastUpdate) {
this.dateOfLastUpdate = dateOfLastUpdate;
}
@XmlElement
public String getOwnership() {
return ownership;
}
public void setOwnership(String ownership) { public void setName(String name) {
this.ownership = ownership; this.name = name;
} }
@XmlElement public String getType() {
public Status getStatus() { return type;
return status; }
}
public void setStatus(Status status) { public void setType(String type) {
this.status = status; this.type = type;
} }
@XmlElement public String getDescription() {
public String getDeviceType() { return description;
return deviceType;
} }
public void setDeviceType(String deviceType) { public void setDescription(String description) {
this.deviceType = deviceType; this.description = description;
} }
@XmlElement
public String getDeviceIdentifier() { public String getDeviceIdentifier() {
return deviceIdentifier; return deviceIdentifier;
} }
@ -127,16 +72,14 @@ public class Device {
this.deviceIdentifier = deviceIdentifier; this.deviceIdentifier = deviceIdentifier;
} }
@XmlElement public EnrolmentInfo getEnrolmentInfo() {
public String getOwner() { return enrolmentInfo;
return owner; }
}
public void setOwner(String owner) { public void setEnrolmentInfo(EnrolmentInfo enrolmentInfo) {
this.owner = owner; this.enrolmentInfo = enrolmentInfo;
} }
@XmlElement
public List<Feature> getFeatures() { public List<Feature> getFeatures() {
return features; return features;
} }
@ -145,16 +88,6 @@ public class Device {
this.features = features; this.features = features;
} }
@XmlElement
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@XmlElement
public List<Device.Property> getProperties() { public List<Device.Property> getProperties() {
return properties; return properties;
} }

@ -0,0 +1,77 @@
/*
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.common;
public class EnrolmentInfo {
private Long dateOfEnrolment;
private Long dateOfLastUpdate;
private OwnerShip ownership;
private Status status;
private String owner;
public enum Status {
CREATED, ACTIVE, INACTIVE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED
}
public enum OwnerShip {
BYOD, COPE
}
public Long getDateOfEnrolment() {
return dateOfEnrolment;
}
public void setDateOfEnrolment(Long dateOfEnrolment) {
this.dateOfEnrolment = dateOfEnrolment;
}
public Long getDateOfLastUpdate() {
return dateOfLastUpdate;
}
public void setDateOfLastUpdate(Long dateOfLastUpdate) {
this.dateOfLastUpdate = dateOfLastUpdate;
}
public OwnerShip getOwnership() {
return ownership;
}
public void setOwnership(OwnerShip ownership) {
this.ownership = ownership;
}
public Status getStatus() {
return status;
}
public void setStatus(Status status) {
this.status = status;
}
public String getOwner() {
return owner;
}
public void setOwner(String owner) {
this.owner = owner;
}
}

@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.core.dao;
import org.wso2.carbon.device.mgt.common.Device; 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.Device.Status; import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
import java.util.List; import java.util.List;

@ -18,10 +18,11 @@
package org.wso2.carbon.device.mgt.core.dao.impl; package org.wso2.carbon.device.mgt.core.dao.impl;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.Device.Status;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.OwnerShip;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; 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;
@ -53,11 +54,11 @@ public class DeviceDAOImpl implements DeviceDAO {
stmt.setString(2, device.getName()); stmt.setString(2, device.getName());
stmt.setLong(3, new Date().getTime()); stmt.setLong(3, new Date().getTime());
stmt.setLong(4, new Date().getTime()); stmt.setLong(4, new Date().getTime());
stmt.setString(5, device.getOwnership()); stmt.setString(5, device.getEnrolmentInfo().getOwnership().toString());
stmt.setString(6, device.getStatus().toString()); stmt.setString(6, device.getEnrolmentInfo().getStatus().toString());
stmt.setInt(7, typeId); stmt.setInt(7, typeId);
stmt.setString(8, device.getDeviceIdentifier()); stmt.setString(8, device.getDeviceIdentifier());
stmt.setString(9, device.getOwner()); stmt.setString(9, device.getEnrolmentInfo().getOwner());
stmt.setInt(10, tenantId); stmt.setInt(10, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
@ -76,8 +77,8 @@ public class DeviceDAOImpl implements DeviceDAO {
conn = this.getConnection(); conn = this.getConnection();
String sql = "UPDATE DM_DEVICE SET STATUS=?, OWNER=? WHERE DEVICE_IDENTIFICATION = ?"; String sql = "UPDATE DM_DEVICE SET STATUS=?, OWNER=? WHERE DEVICE_IDENTIFICATION = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, device.getStatus().toString()); stmt.setString(1, device.getEnrolmentInfo().getStatus().toString());
stmt.setString(2, device.getOwner()); stmt.setString(2, device.getEnrolmentInfo().getOwner());
stmt.setString(3, device.getDeviceIdentifier()); stmt.setString(3, device.getDeviceIdentifier());
stmt.executeUpdate(); stmt.executeUpdate();
} catch (SQLException e) { } catch (SQLException e) {
@ -108,27 +109,15 @@ public class DeviceDAOImpl implements DeviceDAO {
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql =
"SELECT d.ID, d.DESCRIPTION, d.NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, " + "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, " +
"d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM DM_DEVICE d, DM_DEVICE_TYPE dt WHERE " + "d.DEVICE_TYPE_ID, d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM DM_DEVICE d, DM_DEVICE_TYPE dt WHERE " +
"dt.NAME = ? AND d.DEVICE_IDENTIFICATION = ?"; "dt.NAME = ? AND d.DEVICE_IDENTIFICATION = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getType()); stmt.setString(1, deviceId.getType());
stmt.setString(2, deviceId.getId()); stmt.setString(2, deviceId.getId());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
device = new Device(); device = this.loadDevice(rs);
device.setId(rs.getInt("ID"));
device.setDescription(rs.getString("DESCRIPTION"));
device.setName(rs.getString("NAME"));
device.setDateOfEnrolment(rs.getLong("DATE_OF_ENROLLMENT"));
device.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE"));
//TODO:- Ownership is not a enum in DeviceDAO
device.setOwnership(rs.getString("OWNERSHIP"));
device.setStatus(Status.valueOf(rs.getString("STATUS")));
device.setDeviceType(deviceId.getType());
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
device.setOwner(rs.getString("OWNER"));
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing devices for type " + throw new DeviceManagementDAOException("Error occurred while listing devices for type " +
@ -144,30 +133,19 @@ public class DeviceDAOImpl implements DeviceDAO {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
List<Device> devicesList = null; List<Device> devices = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, " + String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, " +
"d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " + "d.DATE_OF_LAST_UPDATE, d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " +
"d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID, t.NAME AS DEVICE_TYPE_NAME FROM DM_DEVICE d, DEVICE_TYPE t " + "d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID, t.NAME AS DEVICE_TYPE_NAME FROM DM_DEVICE d, DEVICE_TYPE t " +
"WHERE d.DEVICE_TYPE_ID = t.ID "; "WHERE d.DEVICE_TYPE_ID = t.ID ";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery(); rs = stmt.executeQuery();
devicesList = new ArrayList<Device>(); devices = new ArrayList<Device>();
while (rs.next()) { while (rs.next()) {
Device device = new Device(); Device device = this.loadDevice(rs);
device.setId(rs.getInt("DEVICE_ID")); devices.add(device);
device.setDescription(rs.getString("DESCRIPTION"));
device.setName(rs.getString("DEVICE_NAME"));
device.setDateOfEnrolment(rs.getLong("DATE_OF_ENROLLMENT"));
device.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE"));
//TODO:- Ownership is not a enum in DeviceDAO
device.setOwnership("OWNERSHIP");
device.setStatus(Status.valueOf(rs.getString("STATUS")));
device.setDeviceType("DEVICE_TYPE_NAME");
device.setDeviceIdentifier("DEVICE_IDENTIFICATION");
device.setOwner("OWNER");
devicesList.add(device);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving information of all " + throw new DeviceManagementDAOException("Error occurred while retrieving information of all " +
@ -175,7 +153,7 @@ public class DeviceDAOImpl implements DeviceDAO {
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
return devicesList; return devices;
} }
@Override @Override
@ -206,8 +184,8 @@ public class DeviceDAOImpl implements DeviceDAO {
public List<Device> getDevices(String type, int tenantId) throws DeviceManagementDAOException { public List<Device> getDevices(String type, int tenantId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet resultSet = null; ResultSet rs = null;
List<Device> devicesList = null; List<Device> devices = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String selectDBQueryForType = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " + String selectDBQueryForType = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " +
@ -215,62 +193,41 @@ public class DeviceDAOImpl implements DeviceDAO {
"WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ?"; "WHERE d.DM_DEVICE.DEVICE_TYPE_ID = t.ID AND t.NAME = ?";
stmt = conn.prepareStatement(selectDBQueryForType); stmt = conn.prepareStatement(selectDBQueryForType);
stmt.setString(1, type); stmt.setString(1, type);
resultSet = stmt.executeQuery(); rs = stmt.executeQuery();
devicesList = new ArrayList<Device>(); devices = new ArrayList<Device>();
while (resultSet.next()) { while (rs.next()) {
Device device = new Device(); Device device = this.loadDevice(rs);
device.setId(resultSet.getInt("DEVICE_ID")); devices.add(device);
device.setDescription(resultSet.getString("DESCRIPTION"));
device.setName(resultSet.getString("DEVICE_NAME"));
device.setDateOfEnrolment(resultSet.getLong("DATE_OF_ENROLLMENT"));
device.setDateOfLastUpdate(resultSet.getLong("DATE_OF_LAST_UPDATE"));
//TODO:- Ownership is not a enum in DeviceDAO
device.setOwnership(resultSet.getString("OWNERSHIP"));
device.setStatus(Status.valueOf(resultSet.getString("STATUS")));
device.setDeviceType(type);
device.setDeviceIdentifier(resultSet.getString("DEVICE_IDENTIFICATION"));
device.setOwner(resultSet.getString("OWNER"));
devicesList.add(device);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e); throw new DeviceManagementDAOException("Error occurred while listing devices for type '" + type + "'", e);
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, resultSet); DeviceManagementDAOUtil.cleanupResources(stmt, rs);
} }
return devicesList; return devices;
} }
@Override public List<Device> getDeviceListOfUser(String username, int tenantId) throws DeviceManagementDAOException { @Override
public List<Device> getDeviceListOfUser(String username, int tenantId) throws DeviceManagementDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
List<Device> deviceList = new ArrayList<Device>(); List<Device> devices = new ArrayList<Device>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
stmt = conn.prepareStatement( stmt = conn.prepareStatement(
"SELECT t.NAME AS DEVICE_TYPE_NAME, d.ID AS DEVICE_ID, d.DESCRIPTION, " + "SELECT t.NAME AS DEVICE_TYPE, d.ID AS DEVICE_ID, d.DESCRIPTION, " +
"d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " + "d.NAME AS DEVICE_NAME, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " +
"d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " + "d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " +
"d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM " + "d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " + "DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
"AND d.OWNER =? AND d.TENANT_ID =?"); "AND d.OWNER =? AND d.TENANT_ID =?");
stmt.setString(1, username); stmt.setString(1, username);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
ResultSet resultSet = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
while (resultSet.next()) { while (rs.next()) {
Device device = new Device(); Device device = this.loadDevice(rs);
device.setId(resultSet.getInt("DEVICE_ID")); devices.add(device);
device.setDescription(resultSet.getString("DESCRIPTION"));
device.setName(resultSet.getString("DEVICE_NAME"));
device.setDateOfEnrolment(resultSet.getLong("DATE_OF_ENROLLMENT"));
device.setDateOfLastUpdate(resultSet.getLong("DATE_OF_LAST_UPDATE"));
//TODO:- Ownership is not a enum in DeviceDAO
device.setOwnership(resultSet.getString("OWNERSHIP"));
device.setStatus(Status.valueOf(resultSet.getString("STATUS")));
device.setDeviceType("DEVICE_TYPE_NAME");
device.setDeviceIdentifier("DEVICE_IDENTIFICATION");
device.setOwner("OWNER");
deviceList.add(device);
} }
} catch (SQLException e) { } catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" + throw new DeviceManagementDAOException("Error occurred while fetching the list of devices belongs to '" +
@ -278,7 +235,7 @@ public class DeviceDAOImpl implements DeviceDAO {
} finally { } finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null); DeviceManagementDAOUtil.cleanupResources(stmt, null);
} }
return deviceList; return devices;
} }
private Connection getConnection() throws DeviceManagementDAOException { private Connection getConnection() throws DeviceManagementDAOException {
@ -287,6 +244,7 @@ public class DeviceDAOImpl implements DeviceDAO {
/** /**
* Get device count of all devices. * Get device count of all devices.
*
* @return device count * @return device count
* @throws DeviceManagementDAOException * @throws DeviceManagementDAOException
*/ */
@ -329,29 +287,17 @@ public class DeviceDAOImpl implements DeviceDAO {
conn = this.getConnection(); conn = this.getConnection();
stmt = conn.prepareStatement( stmt = conn.prepareStatement(
"SELECT d.ID AS DEVICE_ID, d.NAME AS DEVICE_NAME, t.ID AS DEVICE_TYPE_ID, d.DESCRIPTION, " + "SELECT d.ID AS DEVICE_ID, d.NAME AS DEVICE_NAME, t.ID AS DEVICE_TYPE_ID, d.DESCRIPTION, " +
"t.NAME AS DEVICE_TYPE, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " + "t.NAME AS DEVICE_TYPE, d.DATE_OF_ENROLLMENT, d.DATE_OF_LAST_UPDATE, " +
"d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " + "d.OWNERSHIP, d.STATUS, d.DEVICE_TYPE_ID, " +
"d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM " + "d.DEVICE_IDENTIFICATION, d.OWNER, d.TENANT_ID FROM " +
"DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " + "DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
"AND d.NAME LIKE ? AND d.TENANT_ID = ?"); "AND d.NAME LIKE ? AND d.TENANT_ID = ?");
stmt.setString(1, deviceName + "%"); stmt.setString(1, deviceName + "%");
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
Device device = new Device(); Device device = this.loadDevice(rs);
DeviceType deviceType = new DeviceType();
deviceType.setId(rs.getInt("ID"));
deviceType.setName(rs.getString("DEVICE_NAME"));
device.setId(rs.getInt("DEVICE_TYPE_ID"));
device.setDescription(rs.getString("DESCRIPTION"));
device.setDateOfEnrolment(rs.getLong("DATE_OF_ENROLLMENT"));
device.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE"));
device.setOwnership(rs.getString("OWNERSHIP"));
device.setStatus(Status.valueOf(rs.getString("STATUS")));
device.setDeviceType(rs.getString("DEVICE_TYPE"));
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
device.setOwner(rs.getString("OWNER"));
deviceList.add(device); deviceList.add(device);
} }
} catch (SQLException e) { } catch (SQLException e) {
@ -363,4 +309,25 @@ public class DeviceDAOImpl implements DeviceDAO {
return deviceList; return deviceList;
} }
private Device loadDevice(ResultSet rs) throws SQLException {
Device device = new Device();
DeviceType deviceType = new DeviceType();
deviceType.setId(rs.getInt("ID"));
deviceType.setName(rs.getString("DEVICE_NAME"));
device.setId(rs.getInt("DEVICE_TYPE_ID"));
device.setDescription(rs.getString("DESCRIPTION"));
device.setType(rs.getString("DEVICE_TYPE"));
device.setDeviceIdentifier(rs.getString("DEVICE_IDENTIFICATION"));
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(rs.getLong("DATE_OF_ENROLLMENT"));
enrolmentInfo.setDateOfLastUpdate(rs.getLong("DATE_OF_LAST_UPDATE"));
enrolmentInfo.setOwnership(OwnerShip.valueOf(rs.getString("OWNERSHIP")));
enrolmentInfo.setStatus(Status.valueOf(rs.getString("STATUS")));
enrolmentInfo.setOwner(rs.getString("OWNER"));
device.setEnrolmentInfo(enrolmentInfo);
return device;
}
} }

@ -86,10 +86,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
this.getPluginRepository().getDeviceManagementService(device.getType()); this.getPluginRepository().getDeviceManagementService(device.getType());
boolean status = dms.enrollDevice(device); boolean status = dms.enrollDevice(device);
try { try {
if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getDeviceType()))) { if (dms.isClaimable(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()))) {
device.setStatus(Device.Status.INACTIVE); device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.INACTIVE);
} else { } else {
device.setStatus(Device.Status.ACTIVE); device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.ACTIVE);
} }
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();

@ -28,8 +28,9 @@ import org.testng.annotations.Parameters;
import org.testng.annotations.Test; import org.testng.annotations.Test;
import org.w3c.dom.Document; import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.Device.OwnerShip; import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.common.Device.Status; import org.wso2.carbon.device.mgt.common.EnrolmentInfo.OwnerShip;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.TestUtils; import org.wso2.carbon.device.mgt.core.TestUtils;
import org.wso2.carbon.device.mgt.core.common.DBTypes; import org.wso2.carbon.device.mgt.core.common.DBTypes;
@ -148,17 +149,19 @@ public class DeviceManagementDAOTests {
DeviceDAO deviceMgtDAO = DeviceManagementDAOFactory.getDeviceDAO(); DeviceDAO deviceMgtDAO = DeviceManagementDAOFactory.getDeviceDAO();
Device device = new Device(); Device device = new Device();
device.setDateOfEnrolment(new Date().getTime()); EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
device.setDateOfLastUpdate(new Date().getTime()); enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
device.setEnrolmentInfo(enrolmentInfo);
device.setDescription("test description"); device.setDescription("test description");
device.setStatus(Status.ACTIVE); device.getEnrolmentInfo().setStatus(Status.ACTIVE);
device.setDeviceIdentifier("111"); device.setDeviceIdentifier("111");
DeviceType deviceType = new DeviceType(); DeviceType deviceType = new DeviceType();
deviceType.setId(Integer.parseInt("1")); deviceType.setId(Integer.parseInt("1"));
device.setOwnership(OwnerShip.BYOD.toString()); device.getEnrolmentInfo().setOwnership(OwnerShip.BYOD);
device.setOwner("111"); device.getEnrolmentInfo().setOwner("111");
deviceMgtDAO.addDevice(deviceType.getId(), device, -1234); deviceMgtDAO.addDevice(deviceType.getId(), device, -1234);
Connection conn = null; Connection conn = null;
@ -169,7 +172,7 @@ public class DeviceManagementDAOTests {
String status = null; String status = null;
try { try {
conn = this.getDataSource().getConnection(); conn = this.getDataSource().getConnection();
String sql = "SELECT ID, STATUS from DM_DEVICE DEVICE where DEVICE.DEVICE_IDENTIFICATION = ?"; String sql = "SELECT ID, STATUS FROM DM_DEVICE where DEVICE_IDENTIFICATION = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, "111"); stmt.setString(1, "111");

@ -71,8 +71,8 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
pipDevice.setRoles(getRoleOfDevice(device)); pipDevice.setRoles(getRoleOfDevice(device));
pipDevice.setDeviceType(deviceType); pipDevice.setDeviceType(deviceType);
pipDevice.setDeviceIdentifier(deviceIdentifier); pipDevice.setDeviceIdentifier(deviceIdentifier);
pipDevice.setUserId(device.getOwner()); pipDevice.setUserId(device.getEnrolmentInfo().getOwner());
pipDevice.setOwnershipType(device.getOwnership()); pipDevice.setOwnershipType(device.getEnrolmentInfo().getOwnership().toString());
// TODO : Find a way to retrieve the timestamp and location (lat, long) of the device // TODO : Find a way to retrieve the timestamp and location (lat, long) of the device
// pipDevice.setLongitude(); // pipDevice.setLongitude();
@ -118,7 +118,7 @@ public class PolicyInformationPointImpl implements PolicyInformationPoint {
private String[] getRoleOfDevice(Device device) throws PolicyManagementException { private String[] getRoleOfDevice(Device device) throws PolicyManagementException {
try { try {
return CarbonContext.getThreadLocalCarbonContext().getUserRealm(). return CarbonContext.getThreadLocalCarbonContext().getUserRealm().
getUserStoreManager().getRoleListOfUser(device.getOwner()); getUserStoreManager().getRoleListOfUser(device.getEnrolmentInfo().getOwner());
} catch (UserStoreException e) { } catch (UserStoreException e) {
String msg = "Error occurred when retrieving roles related to user name."; String msg = "Error occurred when retrieving roles related to user name.";
log.error(msg, e); log.error(msg, e);

@ -19,8 +19,8 @@
package org.wso2.carbon.policy.mgt.core.util; package org.wso2.carbon.policy.mgt.core.util;
import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.common.Device.Status;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
@ -31,37 +31,36 @@ public class DeviceCreator {
public static List<Device> getDeviceList(DeviceType deviceType) { public static List<Device> getDeviceList(DeviceType deviceType) {
Device device = new Device(); Device device = new Device();
device.setId(1); device.setId(1);
device.setDeviceType(deviceType.getName()); device.setType(deviceType.getName());
device.setName("Galaxy S6"); device.setName("Galaxy S6");
device.setOwner("geeth"); device.setDeviceIdentifier("abc123");
device.setOwnership("BYOD"); EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
device.setStatus(Status.ACTIVE); enrolmentInfo.setOwner("Geeth");
device.setDeviceIdentifier("aaaaaaaaaaaaaaaaaaaaaaaaaa"); enrolmentInfo.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE);
device.setEnrolmentInfo(enrolmentInfo);
Device device2 = new Device();
device2.setId(2); Device device1 = new Device();
device2.setDeviceType(deviceType.getName()); device1.setId(1);
device2.setName("Nexus 5"); device1.setType(deviceType.getName());
device2.setOwner("manoj"); device1.setName("Nexus 5");
device2.setOwnership("BYOD"); device1.setDeviceIdentifier("def456");
device.setStatus(Status.ACTIVE); EnrolmentInfo enrolmentInfo1 = new EnrolmentInfo();
device2.setDeviceIdentifier("bbbbbbbbbbbbbbbbbbbbbbbb"); enrolmentInfo1.setOwner("Manoj");
enrolmentInfo1.setOwnership(EnrolmentInfo.OwnerShip.BYOD);
enrolmentInfo1.setStatus(EnrolmentInfo.Status.ACTIVE);
device1.setEnrolmentInfo(enrolmentInfo);
deviceList.add(device); deviceList.add(device);
// deviceList.add(device2); // deviceList.add(device2);
return deviceList; return deviceList;
} }
public static Device getSingleDevice() { public static Device getSingleDevice() {
return deviceList.get(0); return deviceList.get(0);
} }
} }

Loading…
Cancel
Save