Committing fix for JIRA- EMM-860

revert-70aa11f8
Kasun Delgolla 9 years ago
parent 6f2d1ad065
commit c00b1ee713

@ -23,6 +23,7 @@ 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.PaginationResult;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.util.HashMap;
import java.util.List;
@ -163,6 +164,14 @@ public interface DeviceDAO {
*/
int getDeviceCount(int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve the available device types of a given tenant.
*
* @return returns list of device types.
* @throws DeviceManagementDAOException
*/
List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException;
/**
* This method is used to retrieve devices of a given device name.
*

@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
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.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -120,6 +121,32 @@ public class GenericDeviceDAOImpl extends AbstractDeviceDAOImpl {
return result;
}
@Override
public List<DeviceType> getDeviceTypes()
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<DeviceType> deviceTypes;
try {
conn = this.getConnection();
String sql = "SELECT t.ID, t.NAME " +
"FROM DM_DEVICE_TYPE t";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
deviceTypes = new ArrayList<>();
while (rs.next()) {
DeviceType deviceType = DeviceManagementDAOUtil.loadDeviceType(rs);
deviceTypes.add(deviceType);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing device types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return deviceTypes;
}
private Connection getConnection() throws SQLException {
return DeviceManagementDAOFactory.getConnection();
}

@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
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.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -116,6 +117,30 @@ public class OracleDeviceDAOImpl extends AbstractDeviceDAOImpl {
return result;
}
@Override public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<DeviceType> deviceTypes;
try {
conn = this.getConnection();
String sql = "SELECT t.ID, t.NAME " +
"FROM DM_DEVICE_TYPE t";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
deviceTypes = new ArrayList<>();
while (rs.next()) {
DeviceType deviceType = DeviceManagementDAOUtil.loadDeviceType(rs);
deviceTypes.add(deviceType);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing device types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return deviceTypes;
}
private Connection getConnection() throws SQLException {
return DeviceManagementDAOFactory.getConnection();
}

@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
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.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -116,6 +117,30 @@ public class PostgreSQLDeviceDAOImpl extends AbstractDeviceDAOImpl {
return result;
}
@Override public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<DeviceType> deviceTypes;
try {
conn = this.getConnection();
String sql = "SELECT t.ID, t.NAME " +
"FROM DM_DEVICE_TYPE t";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
deviceTypes = new ArrayList<>();
while (rs.next()) {
DeviceType deviceType = DeviceManagementDAOUtil.loadDeviceType(rs);
deviceTypes.add(deviceType);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing device types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return deviceTypes;
}
private Connection getConnection() throws SQLException {
return DeviceManagementDAOFactory.getConnection();
}

@ -23,6 +23,7 @@ import org.wso2.carbon.device.mgt.common.PaginationResult;
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.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.sql.Connection;
import java.sql.PreparedStatement;
@ -116,6 +117,31 @@ public class SQLServerDeviceDAOImpl extends AbstractDeviceDAOImpl {
return result;
}
@Override
public List<DeviceType> getDeviceTypes() throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
List<DeviceType> deviceTypes;
try {
conn = this.getConnection();
String sql = "SELECT t.ID, t.NAME " +
"FROM DM_DEVICE_TYPE t";
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
deviceTypes = new ArrayList<>();
while (rs.next()) {
DeviceType deviceType = DeviceManagementDAOUtil.loadDeviceType(rs);
deviceTypes.add(deviceType);
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while listing device types.", e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
}
return deviceTypes;
}
private Connection getConnection() throws SQLException {
return DeviceManagementDAOFactory.getConnection();
}

@ -23,6 +23,7 @@ import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.tenant.TenantManager;
@ -153,4 +154,11 @@ public final class DeviceManagementDAOUtil {
device.setEnrolmentInfo(loadEnrolment(rs));
return device;
}
public static DeviceType loadDeviceType(ResultSet rs) throws SQLException {
DeviceType deviceType = new DeviceType();
deviceType.setId(rs.getInt("ID"));
deviceType.setName(rs.getString("NAME"));
return deviceType;
}
}

@ -24,6 +24,8 @@ import org.wso2.carbon.device.mgt.common.configuration.mgt.TenantConfiguration;
import org.wso2.carbon.device.mgt.common.license.mgt.License;
import org.wso2.carbon.device.mgt.common.license.mgt.LicenseManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import java.util.List;
/**
@ -127,6 +129,8 @@ public interface DeviceManagementProviderService extends OperationManager {
Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException;
List<DeviceType> getAvailableDeviceTypes() throws DeviceManagementException;
boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException;
boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException;

@ -617,6 +617,22 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
return device;
}
@Override
public List<DeviceType> getAvailableDeviceTypes() throws DeviceManagementException {
List<DeviceType> deviceTypes;
try {
DeviceManagementDAOFactory.openConnection();
deviceTypes = deviceDAO.getDeviceTypes();
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device types.", e);
} catch (SQLException e) {
throw new DeviceManagementException("Error occurred while opening a connection to the data source", e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
return deviceTypes;
}
@Override
public boolean updateDeviceInfo(DeviceIdentifier deviceId, Device device) throws DeviceManagementException {
DeviceManager deviceManager = this.getDeviceManager(deviceId.getType());

Loading…
Cancel
Save