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 java.util.List;
@XmlRootElement
public class Device {
private int id;
private String name;
private String type;
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 owner;
private List<Feature> features;
private List<Device.Property> properties;
private EnrolmentInfo enrolmentInfo;
private List<Feature> features;
private List<Device.Property> properties;
public enum Status {
ACTIVE, INACTIVE, UNCLAIMED
}
public enum OwnerShip {
BYOD, COPE
}
@XmlElement
public int getId() {
return id;
}
@ -55,70 +40,30 @@ public class Device {
this.id = id;
}
@XmlElement
public String getDescription() {
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 String getName() {
return name;
}
public void setOwnership(String ownership) {
this.ownership = ownership;
}
public void setName(String name) {
this.name = name;
}
@XmlElement
public Status getStatus() {
return status;
}
public String getType() {
return type;
}
public void setStatus(Status status) {
this.status = status;
}
public void setType(String type) {
this.type = type;
}
@XmlElement
public String getDeviceType() {
return deviceType;
public String getDescription() {
return description;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
public void setDescription(String description) {
this.description = description;
}
@XmlElement
public String getDeviceIdentifier() {
return deviceIdentifier;
}
@ -127,16 +72,14 @@ public class Device {
this.deviceIdentifier = deviceIdentifier;
}
@XmlElement
public String getOwner() {
return owner;
}
public EnrolmentInfo getEnrolmentInfo() {
return enrolmentInfo;
}
public void setOwner(String owner) {
this.owner = owner;
}
public void setEnrolmentInfo(EnrolmentInfo enrolmentInfo) {
this.enrolmentInfo = enrolmentInfo;
}
@XmlElement
public List<Feature> getFeatures() {
return features;
}
@ -145,16 +88,6 @@ public class Device {
this.features = features;
}
@XmlElement
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
@XmlElement
public List<Device.Property> getProperties() {
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.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.Device.Status;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo.Status;
import java.util.List;

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

@ -28,8 +28,9 @@ import org.testng.annotations.Parameters;
import org.testng.annotations.Test;
import org.w3c.dom.Document;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.Device.OwnerShip;
import org.wso2.carbon.device.mgt.common.Device.Status;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
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.core.TestUtils;
import org.wso2.carbon.device.mgt.core.common.DBTypes;
@ -148,17 +149,19 @@ public class DeviceManagementDAOTests {
DeviceDAO deviceMgtDAO = DeviceManagementDAOFactory.getDeviceDAO();
Device device = new Device();
device.setDateOfEnrolment(new Date().getTime());
device.setDateOfLastUpdate(new Date().getTime());
EnrolmentInfo enrolmentInfo = new EnrolmentInfo();
enrolmentInfo.setDateOfEnrolment(new Date().getTime());
enrolmentInfo.setDateOfLastUpdate(new Date().getTime());
device.setEnrolmentInfo(enrolmentInfo);
device.setDescription("test description");
device.setStatus(Status.ACTIVE);
device.getEnrolmentInfo().setStatus(Status.ACTIVE);
device.setDeviceIdentifier("111");
DeviceType deviceType = new DeviceType();
deviceType.setId(Integer.parseInt("1"));
device.setOwnership(OwnerShip.BYOD.toString());
device.setOwner("111");
device.getEnrolmentInfo().setOwnership(OwnerShip.BYOD);
device.getEnrolmentInfo().setOwner("111");
deviceMgtDAO.addDevice(deviceType.getId(), device, -1234);
Connection conn = null;
@ -169,7 +172,7 @@ public class DeviceManagementDAOTests {
String status = null;
try {
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.setString(1, "111");

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

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

Loading…
Cancel
Save