Merge pull request #2 from dulichan/master

Implements the getDevice method of DeviceManager
revert-70aa11f8
Prabath Abeysekara 10 years ago
commit 0ffa15f463

@ -47,8 +47,7 @@ public class DeviceManagerImpl implements DeviceManager {
this.deviceTypeDAO = DeviceManagementDAOFactory.getDeviceTypeDAO();
}
@Override
public boolean enrollDevice(Device device) throws DeviceManagementException {
@Override public boolean enrollDevice(Device device) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
boolean status = dms.enrollDevice(device);
@ -59,13 +58,13 @@ public class DeviceManagerImpl implements DeviceManager {
this.getDeviceDAO().addDevice(deviceDto);
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'", e);
throw new DeviceManagementException("Error occurred while enrolling the device '" + device.getId() + "'",
e);
}
return status;
}
@Override
public boolean modifyEnrollment(Device device) throws DeviceManagementException {
@Override public boolean modifyEnrollment(Device device) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
boolean status = dms.modifyEnrollment(device);
try {
@ -77,47 +76,37 @@ public class DeviceManagerImpl implements DeviceManager {
return status;
}
@Override
public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
@Override public boolean disenrollDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.disenrollDevice(deviceId);
}
@Override
public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
@Override public boolean isEnrolled(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.isEnrolled(deviceId);
}
@Override
public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
@Override public boolean isActive(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.isActive(deviceId);
}
@Override
public boolean setActive(DeviceIdentifier deviceId, boolean status)
throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
@Override public boolean setActive(DeviceIdentifier deviceId, boolean status) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.setActive(deviceId, status);
}
@Override
public List<Device> getAllDevices(String type) throws DeviceManagementException {
DeviceManagerService dms =
this.getPluginRepository().getDeviceManagementProvider(type);
@Override public List<Device> getAllDevices(String type) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(type);
List<Device> devicesList = new ArrayList<Device>();
try {
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(type);
List<org.wso2.carbon.device.mgt.core.dto.Device> devices =
this.getDeviceDAO().getDevices(deviceTypeId);
List<org.wso2.carbon.device.mgt.core.dto.Device> devices = this.getDeviceDAO().getDevices(deviceTypeId);
for (org.wso2.carbon.device.mgt.core.dto.Device device : devices) {
DeviceType deviceType = this.deviceTypeDAO.getDeviceType(device.getDeviceTypeId());
Device convertedDevice = DeviceManagementDAOUtil.convertDevice(device, deviceType);
DeviceIdentifier deviceIdentifier =
DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
DeviceIdentifier deviceIdentifier = DeviceManagementDAOUtil.createDeviceIdentifier(device, deviceType);
Device dmsDevice = dms.getDevice(deviceIdentifier);
if (dmsDevice != null) {
convertedDevice.setProperties(dmsDevice.getProperties());
@ -126,26 +115,41 @@ public class DeviceManagerImpl implements DeviceManager {
devicesList.add(convertedDevice);
}
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'",
e);
throw new DeviceManagementException("Error occurred while obtaining the device for type '" + type + "'", e);
}
return devicesList;
}
@Override
public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
@Override public Device getDevice(DeviceIdentifier deviceId) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.getDevice(deviceId);
Device convertedDevice = null;
try {
Integer deviceTypeId = this.getDeviceTypeDAO().getDeviceTypeIdByDeviceTypeName(deviceId.getType());
org.wso2.carbon.device.mgt.core.dto.Device device =
this.getDeviceDAO().getDeviceByDeviceIdentifier(deviceTypeId, deviceId.getId());
if (device != null) {
convertedDevice = DeviceManagementDAOUtil
.convertDevice(device, this.getDeviceTypeDAO().getDeviceType(deviceTypeId));
Device dmsDevice = dms.getDevice(deviceId);
if (dmsDevice != null) {
convertedDevice.setProperties(dmsDevice.getProperties());
convertedDevice.setFeatures(dmsDevice.getFeatures());
}
}
} catch (DeviceManagementDAOException e) {
throw new DeviceManagementException(
"Error occurred while obtaining the device for id '" + deviceId.getId() + "'", e);
}
return convertedDevice;
}
@Override
public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
@Override public boolean updateDeviceInfo(Device device) throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(device.getType());
return dms.updateDeviceInfo(device);
}
@Override
public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType) throws DeviceManagementException {
@Override public boolean setOwnership(DeviceIdentifier deviceId, String ownershipType)
throws DeviceManagementException {
DeviceManagerService dms = this.getPluginRepository().getDeviceManagementProvider(deviceId.getType());
return dms.setOwnership(deviceId, ownershipType);
}

@ -38,6 +38,14 @@ public interface DeviceDAO {
Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException;
/**
* @param type - Device type.
* @param identifier - Device identifier.
* @return
* @throws DeviceManagementDAOException
*/
Device getDeviceByDeviceIdentifier(Integer type, String identifier) throws DeviceManagementDAOException;
List<Device> getDevices() throws DeviceManagementDAOException;
/**

@ -21,8 +21,8 @@ package org.wso2.carbon.device.mgt.core.dao.impl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.core.dao.DeviceDAO;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.wso2.carbon.device.mgt.core.dto.Device;
import org.wso2.carbon.device.mgt.core.dto.Status;
@ -40,13 +40,11 @@ public class DeviceDAOImpl implements DeviceDAO {
private DataSource dataSource;
private static final Log log = LogFactory.getLog(DeviceDAOImpl.class);
public DeviceDAOImpl(DataSource dataSource) {
this.dataSource = dataSource;
}
@Override
public void addDevice(Device device) throws DeviceManagementDAOException {
@Override public void addDevice(Device device) throws DeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
try {
@ -77,29 +75,64 @@ public class DeviceDAOImpl implements DeviceDAO {
}
}
@Override
public void updateDevice(Device device) throws DeviceManagementDAOException {
@Override public void updateDevice(Device device) throws DeviceManagementDAOException {
}
@Override
public void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException {
@Override public void updateDeviceStatus(Long deviceId, Status status) throws DeviceManagementDAOException {
}
@Override
public void deleteDevice(Long deviceId) throws DeviceManagementDAOException {
@Override public void deleteDevice(Long deviceId) throws DeviceManagementDAOException {
}
@Override
public Device getDeviceByDeviceId(Long deviceId)
throws DeviceManagementDAOException {
@Override public Device getDeviceByDeviceId(Long deviceId) throws DeviceManagementDAOException {
return null;
}
@Override
public List<Device> getDevices() throws DeviceManagementDAOException {
@Override public Device getDeviceByDeviceIdentifier(Integer type, String identifier)
throws DeviceManagementDAOException {
Connection conn = null;
PreparedStatement stmt = null;
ResultSet resultSet = null;
Device device = null;
try {
conn = this.getConnection();
String selectDBQueryForType = "SELECT ID, DESCRIPTION, NAME, DATE_OF_ENROLLMENT, " +
"DATE_OF_LAST_UPDATE, OWNERSHIP, STATUS, DEVICE_TYPE_ID, " +
"DEVICE_IDENTIFICATION, OWNER, TENANT_ID FROM DM_DEVICE " +
"WHERE DM_DEVICE.DEVICE_TYPE_ID=? AND DM_DEVICE.DEVICE_IDENTIFICATION=?";
stmt = conn.prepareStatement(selectDBQueryForType);
stmt.setInt(1, type);
stmt.setString(2, identifier);
resultSet = stmt.executeQuery();
while (resultSet.next()) {
device = new Device();
device.setId(resultSet.getInt(1));
device.setDescription(resultSet.getString(2));
device.setName(resultSet.getString(3));
device.setDateOfEnrollment(resultSet.getLong(4));
device.setDateOfLastUpdate(resultSet.getLong(5));
//TODO:- Ownership is not a enum in DeviceDAO
device.setOwnerShip(resultSet.getString(6));
device.setStatus(Status.valueOf(resultSet.getString(7)));
device.setDeviceTypeId(resultSet.getInt(8));
device.setDeviceIdentificationId(resultSet.getString(9));
device.setOwnerId(resultSet.getString(10));
device.setTenantId(resultSet.getInt(11));
}
} catch (SQLException e) {
String msg = "Error occurred while listing devices for type '" + type + "'";
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(conn, stmt, resultSet);
}
return device;
}
@Override public List<Device> getDevices() throws DeviceManagementDAOException {
return null;
}

@ -223,13 +223,15 @@
<outputDirectory>${project.artifactId}-${project.version}/repository/resources
</outputDirectory>
</fileSet>
<!-- copy cdm jaggery app -->
<fileSet>
<directory>src/repository/jaggeryapps</directory>
<outputDirectory>wso2cdm-${project.version}/repository/deployment/server/jaggeryapps
</outputDirectory>
<fileMode>755</fileMode>
</fileSet>
<!-- copy cdm jaggery app
Commented the section since the repo was moved to MDM
-->
<!--<fileSet>-->
<!--<directory>src/repository/jaggeryapps</directory>-->
<!--<outputDirectory>wso2cdm-${project.version}/repository/deployment/server/jaggeryapps-->
<!--</outputDirectory>-->
<!--<fileMode>755</fileMode>-->
<!--</fileSet>-->
</fileSets>
<dependencySets>

Loading…
Cancel
Save