Cleaned code and added comments

4.x.x
mharindu 9 years ago
parent abc16557dc
commit 69cf3f8939

@ -96,19 +96,14 @@ public class EnrolmentInfo {
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 (owner != null && ownership != null) {
&& tempInfo.getOwner() != null && tempInfo.getOwnership() != null) { if (tempInfo.getOwner() != null && tempInfo.getOwnership() != null) {
if (owner.equals(tempInfo.getOwner()) && 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;
} }

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

Loading…
Cancel
Save