Merge pull request #27 from milanperera/master

Fixing issues of previous PRs
4.x.x
Prabath Abeysekara 9 years ago
commit ee0e9af4cb

@ -20,7 +20,7 @@ package org.wso2.carbon.device.mgt.common;
import java.io.Serializable; import java.io.Serializable;
public class EnrolmentInfo implements Serializable{ public class EnrolmentInfo implements Serializable {
private static final long serialVersionUID = 1998101712L; private static final long serialVersionUID = 1998101712L;
@ -40,7 +40,8 @@ public class EnrolmentInfo implements Serializable{
private Status status; private Status status;
private String owner; private String owner;
public EnrolmentInfo() {} public EnrolmentInfo() {
}
public EnrolmentInfo(Device device, String owner, OwnerShip ownership, Status status) { public EnrolmentInfo(Device device, String owner, OwnerShip ownership, Status status) {
this.device = device; this.device = device;
@ -109,19 +110,12 @@ public class EnrolmentInfo implements Serializable{
public boolean equals(Object obj) { public boolean equals(Object obj) {
if (obj instanceof EnrolmentInfo) { if (obj instanceof EnrolmentInfo) {
EnrolmentInfo tempInfo = (EnrolmentInfo) obj; EnrolmentInfo tempInfo = (EnrolmentInfo) obj;
if (owner != null && ownership != null if (this.owner != null && this.ownership != null) {
&& tempInfo.getOwner() != null && tempInfo.getOwnership() != null) { if (this.owner.equals(tempInfo.getOwner()) && this.ownership.equals(tempInfo.getOwnership())) {
if (owner.equals(tempInfo.getOwner()) && ownership.equals(tempInfo.getOwnership())) {
return true; return true;
} else {
return false;
} }
} else {
return false;
} }
} else {
return false;
} }
return false;
} }
} }

@ -31,38 +31,160 @@ import java.util.List;
*/ */
public interface DeviceDAO { public interface DeviceDAO {
/**
* This method is used to add a device.
*
* @param typeId device type id.
* @param device device object.
* @param tenantId tenant id.
* @return returns the id of the persisted device record.
* @throws DeviceManagementDAOException
*/
int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException; int addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to update a given device.
*
* @param typeId device type id.
* @param device device object.
* @param tenantId tenant id.
* @return returns the id of updated device.
* @throws DeviceManagementDAOException
*/
int updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException; int updateDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to remove a device.
*
* @param deviceId id of the device that should be removed.
* @param tenantId tenant id.
* @return returns the id of removed device.
* @throws DeviceManagementDAOException
*/
int removeDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException; int removeDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve a device of a given id.
*
* @param deviceId device id.
* @param tenantId tenant id.
* @return returns the device object.
* @throws DeviceManagementDAOException
*/
Device getDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException; Device getDevice(DeviceIdentifier deviceId, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve all the devices of a given tenant.
*
* @param tenantId tenant id.
* @return returns a list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevices(int tenantId) throws DeviceManagementDAOException; List<Device> getDevices(int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve all the devices of a given tenant and device type.
*
* @param type device type.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevices(String type, int tenantId) throws DeviceManagementDAOException; List<Device> getDevices(String type, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve devices of a given user.
* @param username user name.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevicesOfUser(String username, int tenantId) throws DeviceManagementDAOException; List<Device> getDevicesOfUser(String username, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve the device count of a given tenant.
*
* @param tenantId tenant id.
* @return returns the device count.
* @throws DeviceManagementDAOException
*/
int getDeviceCount(int tenantId) throws DeviceManagementDAOException; int getDeviceCount(int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve devices of a given device name.
* @param deviceName device name.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException; List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to add an enrollment information of a given device.
*
* @param device device object.
* @param tenantId tenant id.
* @return returns the id of the enrollment.
* @throws DeviceManagementDAOException
*/
int addEnrollment(Device device, int tenantId) throws DeviceManagementDAOException; int addEnrollment(Device device, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to set the current enrollment status of given device and user.
*
* @param deviceId device id.
* @param currentOwner current user name.
* @param status device status.
* @param tenantId tenant id.
* @return returns true if success.
* @throws DeviceManagementDAOException
*/
boolean setEnrolmentStatus(DeviceIdentifier deviceId, String currentOwner, Status status, boolean setEnrolmentStatus(DeviceIdentifier deviceId, String currentOwner, Status status,
int tenantId) throws DeviceManagementDAOException; int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to get the status of current enrollment of a given user and device.
*
* @param deviceId device id.
* @param currentOwner device owner.
* @param tenantId tenant id.
* @return returns current enrollment status.
* @throws DeviceManagementDAOException
*/
Status getEnrolmentStatus(DeviceIdentifier deviceId, String currentOwner, Status getEnrolmentStatus(DeviceIdentifier deviceId, String currentOwner,
int tenantId) throws DeviceManagementDAOException; int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve current enrollment of a given device and user.
*
* @param deviceId device id.
* @param currentUser user name.
* @param tenantId tenant id.
* @return returns EnrolmentInfo object.
* @throws DeviceManagementDAOException
*/
EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser, EnrolmentInfo getEnrolment(DeviceIdentifier deviceId, String currentUser,
int tenantId) throws DeviceManagementDAOException; int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve devices of a given enrollment status.
*
* @param status enrollment status.
* @param tenantId tenant id.
* @return returns list of devices.
* @throws DeviceManagementDAOException
*/
List<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException; List<Device> getDevicesByStatus(EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve the enrollment id of a given device and status.
*
* @param deviceId device id.
* @param status enrollment status.
* @param tenantId tenant id.
* @return returns the id of current enrollment.
* @throws DeviceManagementDAOException
*/
int getEnrolmentByStatus(DeviceIdentifier deviceId, Status status, int getEnrolmentByStatus(DeviceIdentifier deviceId, Status status,
int tenantId) throws DeviceManagementDAOException; int tenantId) throws DeviceManagementDAOException;
} }

@ -42,9 +42,8 @@ public class DeviceDAOImpl implements DeviceDAO {
int deviceId = -1; int deviceId = -1;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) " +
"INSERT INTO DM_DEVICE(DESCRIPTION, NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) " + "VALUES (?, ?, ?, ?, ?)";
"VALUES (?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, device.getDescription()); stmt.setString(1, device.getDescription());
stmt.setString(2, device.getName()); stmt.setString(2, device.getName());
@ -74,9 +73,8 @@ public class DeviceDAOImpl implements DeviceDAO {
int deviceId = -1; int deviceId = -1;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " +
"UPDATE DM_DEVICE SET DESCRIPTION = ?, NAME = ? WHERE DEVICE_IDENTIFICATION = ? AND " + "DEVICE_TYPE_ID = ? AND TENANT_ID = ?";
"DEVICE_TYPE_ID = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, device.getDescription()); stmt.setString(1, device.getDescription());
stmt.setString(2, device.getName()); stmt.setString(2, device.getName());
@ -111,13 +109,12 @@ public class DeviceDAOImpl implements DeviceDAO {
Device device = null; Device device = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " +
"FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, " + "t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " +
"t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE " + "t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " +
"t.NAME = ? AND d.DEVICE_IDENTIFICATION = ? AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID " + "AND TENANT_ID = ?";
"AND TENANT_ID = ?";
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());
@ -144,12 +141,12 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = null; List<Device> devices = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"SELECT d1.DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, " +
"FROM DM_ENROLMENT e, (SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME," + "d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
"d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t " + "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; "WHERE d1.DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
@ -176,12 +173,12 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = null; List<Device> devices = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, " +
"FROM DM_ENROLMENT e, (SELECT d.ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION, t.NAME " + "d.NAME, d.DEVICE_IDENTIFICATION, t.NAME AS DEVICE_TYPE FROM DM_DEVICE d, " +
"AS DEVICE_TYPE FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " + "DM_DEVICE_TYPE t WHERE DEVICE_TYPE_ID = t.ID AND t.NAME = ? " +
"AND d.TENANT_ID = ?) d1 WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; "AND d.TENANT_ID = ?) d1 WHERE d1.ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, type); stmt.setString(1, type);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
@ -207,13 +204,12 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, " +
"e.DATE_OF_ENROLMENT , e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT t.NAME AS DEVICE_TYPE, d.ID, d.DESCRIPTION, " + "d.ID, d.DESCRIPTION, d.NAME, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t " +
"d.NAME, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t " + "WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?) d1 " + "WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? AND e.OWNER = ?";
"WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ? AND e.OWNER = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
@ -281,12 +277,12 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, " +
"SELECT d1.ID AS DEVICE_ID, d1.DESCRIPTION, d1.NAME AS DEVICE_NAME, d1.DEVICE_TYPE, d1.DEVICE_IDENTIFICATION, " + "d1.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID " + "e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, " +
"FROM DM_ENROLMENT e, (SELECT d.ID, d.NAME, d.DESCRIPTION, t.NAME AS DEVICE_TYPE, " + "d.DESCRIPTION, t.NAME AS DEVICE_TYPE, d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, " +
"d.DEVICE_IDENTIFICATION FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " + "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 " +
"AND d.NAME LIKE ? AND d.TENANT_ID = ?) d1 WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?"; "WHERE DEVICE_ID = e.DEVICE_ID AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceName + "%"); stmt.setString(1, deviceName + "%");
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
@ -314,9 +310,8 @@ public class DeviceDAOImpl implements DeviceDAO {
int enrolmentId = -1; int enrolmentId = -1;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, " +
"INSERT INTO DM_ENROLMENT(DEVICE_ID, OWNER, OWNERSHIP, STATUS,DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, " + "DATE_OF_LAST_UPDATE, TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
"TENANT_ID) VALUES(?, ?, ?, ?, ?, ?, ?)";
stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS); stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS);
stmt.setInt(1, device.getId()); stmt.setInt(1, device.getId());
stmt.setString(2, device.getEnrolmentInfo().getOwner()); stmt.setString(2, device.getEnrolmentInfo().getOwner());
@ -346,10 +341,9 @@ public class DeviceDAOImpl implements DeviceDAO {
PreparedStatement stmt = null; PreparedStatement stmt = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "UPDATE DM_ENROLMENT SET STATUS = ? WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " +
"UPDATE DM_ENROLMENT SET STATUS = ? WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " + "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " + "AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?";
"AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, status.toString()); stmt.setString(1, status.toString());
stmt.setString(2, deviceId.getId()); stmt.setString(2, deviceId.getId());
@ -375,10 +369,9 @@ public class DeviceDAOImpl implements DeviceDAO {
Status status = null; Status status = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " +
"SELECT STATUS FROM DM_ENROLMENT WHERE DEVICE_ID = " + "DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? " +
"(SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND " + "AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?";
"d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getId()); stmt.setString(1, deviceId.getId());
stmt.setString(2, deviceId.getType()); stmt.setString(2, deviceId.getType());
@ -407,11 +400,11 @@ public class DeviceDAOImpl implements DeviceDAO {
EnrolmentInfo enrolmentInfo = null; EnrolmentInfo enrolmentInfo = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, " +
"SELECT ID AS ENROLMENT_ID, DEVICE_ID, OWNER, OWNERSHIP, STATUS, DATE_OF_ENROLMENT, DATE_OF_LAST_UPDATE, " + "DATE_OF_LAST_UPDATE, TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
"TENANT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, DM_DEVICE_TYPE t " + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
"WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " + "AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
"AND OWNER = ? AND TENANT_ID = ?"; "AND OWNER = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getId()); stmt.setString(1, deviceId.getId());
stmt.setString(2, deviceId.getType()); stmt.setString(2, deviceId.getType());
@ -438,10 +431,10 @@ public class DeviceDAOImpl implements DeviceDAO {
ResultSet rs = null; ResultSet rs = null;
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "SELECT ID AS ENROLMENT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID " +
"SELECT ID AS ENROLMENT_ID FROM DM_ENROLMENT WHERE DEVICE_ID = (SELECT d.ID FROM DM_DEVICE d, " + "FROM DM_DEVICE d, DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID " +
"DM_DEVICE_TYPE t WHERE d.DEVICE_TYPE_ID = t.ID AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? " + "AND d.DEVICE_IDENTIFICATION = ? AND t.NAME = ? AND d.TENANT_ID = ?) " +
"AND d.TENANT_ID = ?) AND STATUS = ? AND TENANT_ID = ?"; "AND STATUS = ? AND TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setString(1, deviceId.getId()); stmt.setString(1, deviceId.getId());
stmt.setString(2, deviceId.getType()); stmt.setString(2, deviceId.getType());
@ -491,13 +484,12 @@ public class DeviceDAOImpl implements DeviceDAO {
List<Device> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();
try { try {
conn = this.getConnection(); conn = this.getConnection();
String sql = String sql = "SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " +
"SELECT d.ID AS DEVICE_ID, d.DESCRIPTION, d.NAME AS DEVICE_NAME, t.NAME AS DEVICE_TYPE, " + "d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " +
"d.DEVICE_IDENTIFICATION, e.OWNER, e.OWNERSHIP, e.STATUS, e.DATE_OF_LAST_UPDATE, " + "e.DATE_OF_ENROLMENT FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " +
"e.DATE_OF_ENROLMENT, e.ID AS ENROLMENT_ID FROM (SELECT e.ID, e.DEVICE_ID, e.OWNER, e.OWNERSHIP, e.STATUS, " + "e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE, e.ID AS ENROLMENT_ID FROM DM_ENROLMENT e " +
"e.DATE_OF_ENROLMENT, e.DATE_OF_LAST_UPDATE FROM DM_ENROLMENT e WHERE TENANT_ID = ? " + "WHERE TENANT_ID = ? AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t " +
"AND STATUS = ?) e, DM_DEVICE d, DM_DEVICE_TYPE t WHERE DEVICE_ID = e.DEVICE_ID " + "WHERE DEVICE_ID = e.DEVICE_ID AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
"AND d.DEVICE_TYPE_ID = t.ID AND d.TENANT_ID = ?";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
stmt.setString(2, status.toString()); stmt.setString(2, status.toString());

@ -120,9 +120,11 @@ public class CommandOperationDAOImpl extends OperationDAOImpl {
List<CommandOperation> commandOperations = new ArrayList<>(); List<CommandOperation> commandOperations = new ArrayList<>();
try { try {
Connection conn = OperationManagementDAOFactory.getConnection(); Connection conn = OperationManagementDAOFactory.getConnection();
String sql = "SELECT o.ID, co1.ENABLED, co1.STATUS, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, o.OPERATION_CODE FROM (SELECT co.OPERATION_ID, co.ENABLED, dm.STATUS FROM DM_COMMAND_OPERATION co " + String sql = "SELECT o.ID, co1.ENABLED, co1.STATUS, o.TYPE, o.CREATED_TIMESTAMP, o.RECEIVED_TIMESTAMP, " +
"INNER JOIN (SELECT ENROLMENT_ID, OPERATION_ID, STATUS FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? " + "o.OPERATION_CODE FROM (SELECT co.OPERATION_ID, co.ENABLED, dm.STATUS " +
"AND STATUS = ?) dm ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN DM_OPERATION o ON co1.OPERATION_ID = o.ID"; "FROM DM_COMMAND_OPERATION co INNER JOIN (SELECT ENROLMENT_ID, OPERATION_ID, STATUS " +
"FROM DM_ENROLMENT_OPERATION_MAPPING WHERE ENROLMENT_ID = ? AND STATUS = ?) dm " +
"ON dm.OPERATION_ID = co.OPERATION_ID) co1 INNER JOIN DM_OPERATION o ON co1.OPERATION_ID = o.ID";
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(1, enrolmentId); stmt.setInt(1, enrolmentId);

@ -93,7 +93,7 @@ public interface DeviceManagementProviderService extends OperationManager {
void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException; void updateDeviceEnrolmentInfo(Device device, EnrolmentInfo.Status active) throws DeviceManagementException;
/** /**
* This method is used to retrieve list of devices based on the device status * This method is used to retrieve list of devices based on the device status.
* *
* @param status Device status * @param status Device status
* @return List of devices * @return List of devices

@ -414,7 +414,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBody = messageBody.trim() + System.getProperty("line.separator") + messageBody = messageBody.trim() + System.getProperty("line.separator") +
System.getProperty("line.separator") + url.replaceAll("\\{" System.getProperty("line.separator") + url.replaceAll("\\{"
+ EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}", + EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}",
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
@ -469,8 +469,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
messageBody = messageBody.trim().replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants messageBody = messageBody.trim().replaceAll("\\{" + EmailConstants.EnrolmentEmailConstants
.USERNAME .USERNAME
+ "\\}", + "\\}",
URLEncoder.encode(emailMessageProperties.getUserName(), EmailConstants.EnrolmentEmailConstants URLEncoder.encode(emailMessageProperties.getUserName(), EmailConstants.EnrolmentEmailConstants
.ENCODED_SCHEME)); .ENCODED_SCHEME));
@ -479,7 +479,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
.ENCODED_SCHEME)); .ENCODED_SCHEME));
messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{" messageBody = messageBody + System.getProperty("line.separator") + url.replaceAll("\\{"
+ EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}", + EmailConstants.EnrolmentEmailConstants.DOWNLOAD_URL + "\\}",
URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(), URLDecoder.decode(emailMessageProperties.getEnrolmentUrl(),
EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME)); EmailConstants.EnrolmentEmailConstants.ENCODED_SCHEME));
@ -748,10 +748,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : userDevices) { for (Device device : userDevices) {
Device dmsDevice = Device dmsDevice = this.getDeviceManager(device.getType()).
this.getPluginRepository().getDeviceManagementService( getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties()); device.setProperties(dmsDevice.getProperties());
@ -792,10 +790,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
for (Device device : allDevices) { for (Device device : allDevices) {
Device dmsDevice = Device dmsDevice = this.getDeviceManager(device.getType()).
this.getPluginRepository().getDeviceManagementService( getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties()); device.setProperties(dmsDevice.getProperties());
@ -865,10 +861,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
for (Device device : allDevices) { for (Device device : allDevices) {
Device dmsDevice = Device dmsDevice = this.getDeviceManager(device.getType()).
this.getPluginRepository().getDeviceManagementService( getDevice(new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
device.getType()).getDeviceManager().getDevice(
new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()));
if (dmsDevice != null) { if (dmsDevice != null) {
device.setFeatures(dmsDevice.getFeatures()); device.setFeatures(dmsDevice.getFeatures());
device.setProperties(dmsDevice.getProperties()); device.setProperties(dmsDevice.getProperties());

@ -128,6 +128,10 @@ public class DynamicClientRegistrationUtil {
serviceProvider.setDescription("Service Provider for application " + applicationName); serviceProvider.setDescription("Service Provider for application " + applicationName);
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance(); ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
if (appMgtService == null) {
throw new IllegalStateException("Error occurred while retrieving Application Management" +
"Service");
}
appMgtService.createApplication(serviceProvider); appMgtService.createApplication(serviceProvider);
ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName); ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName);
@ -228,6 +232,11 @@ public class DynamicClientRegistrationUtil {
oAuthAdminService.removeOAuthApplicationData(consumerKey); oAuthAdminService.removeOAuthApplicationData(consumerKey);
ApplicationManagementService appMgtService = ApplicationManagementService.getInstance(); ApplicationManagementService appMgtService = ApplicationManagementService.getInstance();
if (appMgtService == null) {
throw new IllegalStateException("Error occurred while retrieving Application Management" +
"Service");
}
ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName); ServiceProvider createdServiceProvider = appMgtService.getApplication(applicationName);
if (createdServiceProvider == null) { if (createdServiceProvider == null) {

@ -45,9 +45,24 @@ public interface RegistrationService {
} }
} }
/**
* This method is used to register an Oauth application.
*
* @param profile contains the necessary attributes that are
* needed in order to register an app.
* @return Status 200 if success including consumerKey and consumerSecret.
*/
@POST @POST
Response register(RegistrationProfile profile); Response register(RegistrationProfile profile);
/**
* This method is used to remove already registered Oauth application.
*
* @param applicationName name of the application.
* @param userId name of the application owner.
* @param consumerKey provided consumerKey for the registered application.
* @return Status 200 if success.
*/
@DELETE @DELETE
public Response unregister(@QueryParam("applicationName") String applicationName, public Response unregister(@QueryParam("applicationName") String applicationName,
@QueryParam("userId") String userId, @QueryParam("userId") String userId,

@ -164,6 +164,4 @@ public class RegistrationProfile {
public void setGrantType(String grantType) { public void setGrantType(String grantType) {
this.grantType = grantType; this.grantType = grantType;
} }
} }

@ -25,34 +25,102 @@ import org.wso2.carbon.policy.mgt.common.ProfileFeature;
import java.util.List; import java.util.List;
/**
* This interface represents the key operations related to profile features of device policies.
*/
public interface FeatureDAO { public interface FeatureDAO {
/* Feature addFeature(Feature feature) throws FeatureManagerDAOException; /**
* This method is used to add a feature related to given profile.
List<Feature> addFeatures(List<Feature> feature) throws FeatureManagerDAOException; *
* @param feature consists of device specific configurations.
Feature updateFeature(Feature feature) throws FeatureManagerDAOException;*/ * @param profileId id of the profile.
* @return returns ProfileFeature object.
* @throws FeatureManagerDAOException
*/
ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException; ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException;
/**
* This method is used to update a feature related to given profile.
* @param feature consists of device specific configurations.
* @param profileId id of the profile.
* @return returns updated ProfileFeature object.
* @throws FeatureManagerDAOException
*/
ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException; ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException;
/**
* This method is used to add set of features to a given profile.
*
* @param features consists of device specific configurations.
* @param profileId id of the profile.
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException; FeatureManagerDAOException;
/**
* This method is used to update set of features to a given profile.
*
* @param features consists of device specific configurations.
* @param profileId id of the profile.
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId) throws
FeatureManagerDAOException; FeatureManagerDAOException;
/**
* This method is used to retrieve all the profile features.
*
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException; List<ProfileFeature> getAllProfileFeatures() throws FeatureManagerDAOException;
/**
* This method is used to retrieve all the profile features based on device type.
*
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<Feature> getAllFeatures(String deviceType) throws FeatureManagerDAOException; List<Feature> getAllFeatures(String deviceType) throws FeatureManagerDAOException;
List<ProfileFeature> getFeaturesForProfile(int ProfileId) throws FeatureManagerDAOException; /**
* This method is used to retrieve all the profile features of given profile.
*
* @param profileId id of the profile.
* @return returns list of ProfileFeature objects.
* @throws FeatureManagerDAOException
*/
List<ProfileFeature> getFeaturesForProfile(int profileId) throws FeatureManagerDAOException;
/**
* This method is used remove a feature.
*
* @param featureId id of the removing feature.
* @return returns true if success.
* @throws FeatureManagerDAOException
*/
boolean deleteFeature(int featureId) throws FeatureManagerDAOException; boolean deleteFeature(int featureId) throws FeatureManagerDAOException;
/**
* This method is used to remove set of features of given profile.
*
* @param profile that contains features to be removed.
* @return returns true if success.
* @throws FeatureManagerDAOException
*/
boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException; boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException;
/**
* This method is used to remove set of features of given profile id.
*
* @param profileId id of the profile.
* @return returns true if success.
* @throws FeatureManagerDAOException
*/
boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException; boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException;
} }

@ -24,20 +24,67 @@ import org.wso2.carbon.policy.mgt.common.Profile;
import java.util.List; import java.util.List;
/**
* This interface represents the key operations related to policy profile.
*/
public interface ProfileDAO { public interface ProfileDAO {
/**
* This method is used to add a profile.
*
* @param profile profile object.
* @return returns added profile object.
* @throws ProfileManagerDAOException
*/
Profile addProfile(Profile profile) throws ProfileManagerDAOException; Profile addProfile(Profile profile) throws ProfileManagerDAOException;
/**
* This method is used to update a profile
* @param profile profile object.
* @return returns updated profile object.
* @throws ProfileManagerDAOException
*/
Profile updateProfile(Profile profile) throws ProfileManagerDAOException; Profile updateProfile(Profile profile) throws ProfileManagerDAOException;
/**
* This method is used to remove a profile.
* @param profile profile object
* @return returns true if success.
* @throws ProfileManagerDAOException
*/
boolean deleteProfile(Profile profile) throws ProfileManagerDAOException; boolean deleteProfile(Profile profile) throws ProfileManagerDAOException;
/**
* This method is used to remove a profile of given policy id.
* @param policyId policy id.
* @return returns true if success.
* @throws ProfileManagerDAOException
*/
boolean deleteProfile(int policyId) throws ProfileManagerDAOException; boolean deleteProfile(int policyId) throws ProfileManagerDAOException;
Profile getProfiles(int profileId) throws ProfileManagerDAOException; /**
* This method is used to retrieve a profile when id is given.
* @param profileId profile id.
* @return returns profile object.
* @throws ProfileManagerDAOException
*/
Profile getProfile(int profileId) throws ProfileManagerDAOException;
/**
* This method is used to retrieve all the profiles.
*
* @return returns a list of profile objects.
* @throws ProfileManagerDAOException
*/
List<Profile> getAllProfiles() throws ProfileManagerDAOException; List<Profile> getAllProfiles() throws ProfileManagerDAOException;
/**
* This method is used to retrieve all the profile of given device type.
*
* @param deviceType device type object.
* @return retruns list of profiles.
* @throws ProfileManagerDAOException
*/
List<Profile> getProfilesOfDeviceType(DeviceType deviceType) throws ProfileManagerDAOException; List<Profile> getProfilesOfDeviceType(DeviceType deviceType) throws ProfileManagerDAOException;
} }

@ -43,115 +43,6 @@ public class FeatureDAOImpl implements FeatureDAO {
private static final Log log = LogFactory.getLog(FeatureDAOImpl.class); private static final Log log = LogFactory.getLog(FeatureDAOImpl.class);
/* @Override
public Feature addFeature(Feature feature) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
try {
conn = this.getConnection();
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
stmt.setString(1, feature.getName());
stmt.setString(2, feature.getCode());
stmt.setString(3, feature.getDescription());
int affectedRows = stmt.executeUpdate();
if (log.isDebugEnabled()) {
log.debug(affectedRows + " feature is added.");
}
generatedKeys = stmt.getGeneratedKeys();
while (generatedKeys.next()) {
feature.setId(generatedKeys.getInt(1));
}
} catch (SQLException e) {
String msg = "Error occurred while adding feature to the database.";
log.error(msg, e);
throw new FeatureManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
}
return feature;
}*/
/* @Override
public List<Feature> addFeatures(List<Feature> features) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet generatedKeys = null;
List<Feature> featureList = new ArrayList<Feature>();
try {
conn = this.getConnection();
String query = "INSERT INTO DM_FEATURES (NAME, CODE, DESCRIPTION) VALUES (?, ?, ?)";
stmt = conn.prepareStatement(query, PreparedStatement.RETURN_GENERATED_KEYS);
for (Feature feature : features) {
stmt.setString(1, feature.getName());
stmt.setString(2, feature.getCode());
stmt.setString(3, feature.getDescription());
stmt.addBatch();
}
int[] affectedRows = stmt.executeBatch();
generatedKeys = stmt.getGeneratedKeys();
if (log.isDebugEnabled()) {
log.debug(affectedRows.length + " features are added to the database.");
}
generatedKeys = stmt.getGeneratedKeys();
int i = 0;
while (generatedKeys.next()) {
features.get(i).setId(generatedKeys.getInt(1));
i++;
}
} catch (SQLException e) {
String msg = "Error occurred while adding feature to the database.";
log.error(msg, e);
throw new FeatureManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, generatedKeys);
}
return featureList;
}*/
/* @Override
public Feature updateFeature(Feature feature) throws FeatureManagerDAOException {
Connection conn;
PreparedStatement stmt = null;
try {
conn = this.getConnection();
String query = "UPDATE DM_FEATURES SET NAME = ?, CODE = ?, DESCRIPTION = ? WHERE ID = ?";
stmt = conn.prepareStatement(query);
stmt.setString(1, feature.getName());
stmt.setString(2, feature.getCode());
stmt.setString(3, feature.getDescription());
stmt.setInt(4, feature.getId());
stmt.executeUpdate();
} catch (SQLException e) {
String msg = "Error occurred while updating feature " + feature.getName() + " (Feature Name) to the
database.";
log.error(msg, e);
throw new FeatureManagerDAOException(msg, e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
}
return feature;
}*/
@Override @Override
public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException { public ProfileFeature addProfileFeature(ProfileFeature feature, int profileId) throws FeatureManagerDAOException {
return null; return null;
@ -247,7 +138,6 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override @Override
public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException { public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -258,9 +148,10 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, profile.getProfileId()); stmt.setInt(1, profile.getProfileId());
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.executeUpdate(); if (stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e); throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
} finally { } finally {
@ -270,7 +161,6 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override @Override
public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException { public boolean deleteFeaturesOfProfile(int profileId) throws FeatureManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -280,9 +170,10 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId); stmt.setInt(1, profileId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.executeUpdate(); if (stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e); throw new FeatureManagerDAOException("Error occurred while deleting the feature related to a profile.", e);
} finally { } finally {
@ -448,7 +339,6 @@ public class FeatureDAOImpl implements FeatureDAO {
@Override @Override
public boolean deleteFeature(int featureId) throws FeatureManagerDAOException { public boolean deleteFeature(int featureId) throws FeatureManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -459,9 +349,10 @@ public class FeatureDAOImpl implements FeatureDAO {
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, featureId); stmt.setInt(1, featureId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.executeUpdate(); if(stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " + throw new FeatureManagerDAOException("Unable to delete the feature " + featureId + " (Feature ID) " +
"from database.", e); "from database.", e);

@ -132,7 +132,6 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override @Override
public boolean deleteProfile(Profile profile) throws ProfileManagerDAOException { public boolean deleteProfile(Profile profile) throws ProfileManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
@ -141,9 +140,10 @@ public class ProfileDAOImpl implements ProfileDAO {
String query = "DELETE FROM DM_PROFILE WHERE ID = ?"; String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, profile.getProfileId()); stmt.setInt(1, profile.getProfileId());
stmt.executeUpdate(); if (stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while deleting the profile from the data base."; String msg = "Error occurred while deleting the profile from the data base.";
log.error(msg); log.error(msg);
@ -163,9 +163,10 @@ public class ProfileDAOImpl implements ProfileDAO {
String query = "DELETE FROM DM_PROFILE WHERE ID = ?"; String query = "DELETE FROM DM_PROFILE WHERE ID = ?";
stmt = conn.prepareStatement(query); stmt = conn.prepareStatement(query);
stmt.setInt(1, profileId); stmt.setInt(1, profileId);
stmt.executeUpdate(); if (stmt.executeUpdate() > 0) {
return true; return true;
}
return false;
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred while deleting the profile from the data base."; String msg = "Error occurred while deleting the profile from the data base.";
log.error(msg); log.error(msg);
@ -177,8 +178,7 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override @Override
public Profile getProfiles(int profileId) throws ProfileManagerDAOException { public Profile getProfile(int profileId) throws ProfileManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet resultSet = null; ResultSet resultSet = null;
@ -216,7 +216,6 @@ public class ProfileDAOImpl implements ProfileDAO {
@Override @Override
public List<Profile> getAllProfiles() throws ProfileManagerDAOException { public List<Profile> getAllProfiles() throws ProfileManagerDAOException {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet resultSet = null; ResultSet resultSet = null;

@ -362,7 +362,6 @@ public class MonitoringManagerImpl implements MonitoringManager {
DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl(); DeviceManagementProviderService service = new DeviceManagementProviderServiceImpl();
service.addOperation(monitoringOperation, deviceIdentifiers); service.addOperation(monitoringOperation, deviceIdentifiers);
} }
private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) { private List<DeviceIdentifier> getDeviceIdentifiersFromDevices(List<Device> devices) {

@ -439,7 +439,7 @@ public class PolicyManagerImpl implements PolicyManager {
policy = policyDAO.getPolicyByProfileID(profileId); policy = policyDAO.getPolicyByProfileID(profileId);
roleNames = policyDAO.getPolicyAppliedRoles(policy.getId()); roleNames = policyDAO.getPolicyAppliedRoles(policy.getId());
profile = profileDAO.getProfiles(profileId); profile = profileDAO.getProfile(profileId);
policy.setProfile(profile); policy.setProfile(profile);
policy.setRoles(roleNames); policy.setRoles(roleNames);
@ -474,7 +474,7 @@ public class PolicyManagerImpl implements PolicyManager {
policy = policyDAO.getPolicy(policyId); policy = policyDAO.getPolicy(policyId);
roleNames = policyDAO.getPolicyAppliedRoles(policyId); roleNames = policyDAO.getPolicyAppliedRoles(policyId);
Profile profile = profileDAO.getProfiles(policy.getProfileId()); Profile profile = profileDAO.getProfile(policy.getProfileId());
policy.setProfile(profile); policy.setProfile(profile);
policy.setRoles(roleNames); policy.setRoles(roleNames);
@ -871,12 +871,9 @@ public class PolicyManagerImpl implements PolicyManager {
@Override @Override
public int getPolicyCount() throws PolicyManagementException { public int getPolicyCount() throws PolicyManagementException {
int policyCount;
try { try {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
policyCount = policyDAO.getPolicyCount(); return policyDAO.getPolicyCount();
return policyCount;
} catch (PolicyManagerDAOException e) { } catch (PolicyManagerDAOException e) {
throw new PolicyManagementException("Error occurred while getting policy count", e); throw new PolicyManagementException("Error occurred while getting policy count", e);
} catch (SQLException e) { } catch (SQLException e) {

@ -147,7 +147,7 @@ public class ProfileManagerImpl implements ProfileManager {
try { try {
PolicyManagementDAOFactory.openConnection(); PolicyManagementDAOFactory.openConnection();
profile = profileDAO.getProfiles(profileId); profile = profileDAO.getProfile(profileId);
featureList = featureDAO.getFeaturesForProfile(profileId); featureList = featureDAO.getFeaturesForProfile(profileId);
profile.setProfileFeaturesList(featureList); profile.setProfileFeaturesList(featureList);
} catch (ProfileManagerDAOException e) { } catch (ProfileManagerDAOException e) {

@ -37,14 +37,6 @@
<description>This feature contains oauth functionality <description>This feature contains oauth functionality
</description> </description>
<!--<dependencies>-->
<!--<dependency>-->
<!--<groupId>org.wso2.mdm</groupId>-->
<!--<artifactId>dynamic-client-manager</artifactId>-->
<!--</dependency>-->
<!--</dependencies>-->
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
@ -101,8 +93,6 @@
</executions> </executions>
</plugin> </plugin>
<plugin> <plugin>
<groupId>org.wso2.maven</groupId> <groupId>org.wso2.maven</groupId>
<artifactId>carbon-p2-plugin</artifactId> <artifactId>carbon-p2-plugin</artifactId>
@ -123,20 +113,6 @@
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef> <propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
</properties> </properties>
</adviceFile> </adviceFile>
<!--<bundles>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.core:${carbon.device.mgt.version}-->
<!--</bundleDef>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.policy.mgt.common:${carbon.device.mgt.version}-->
<!--</bundleDef>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.simple.policy.decision.point:${carbon.device.mgt.version}-->
<!--</bundleDef>-->
<!--<bundleDef>-->
<!--org.wso2.carbon.devicemgt:org.wso2.carbon.policy.information.point:${carbon.device.mgt.version}-->
<!--</bundleDef>-->
<!--</bundles>-->
<importFeatures> <importFeatures>
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version} <importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}
</importFeatureDef> </importFeatureDef>
@ -145,10 +121,6 @@
</execution> </execution>
</executions> </executions>
</plugin> </plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

Loading…
Cancel
Save