Added a method to retrieve list of applications installed on a device

revert-70aa11f8
harshanl 10 years ago
parent e4d156a77e
commit 20a9d1222f

@ -75,5 +75,22 @@ public interface DeviceDAO {
*/
List<Device> getDevicesByName(String deviceName, int tenantId) throws DeviceManagementDAOException;
/**
* Get the list of devices that matches with the given device name.
*
* @param id Name of the device
* @param applications List of applications
* @throws DeviceManagementDAOException
*/
void addDeviceApplications(int id, Object applications) throws DeviceManagementDAOException;
/**
* Get the list of devices that matches with the given device name.
*
* @param deviceId device id of the device
* @return List of Applications that are installed on the given device.
* @throws DeviceManagementDAOException
*/
List<Application> getInstalledApplications(int deviceId)
throws DeviceManagementDAOException;
}

@ -18,6 +18,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.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
@ -29,7 +31,11 @@ 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 org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
@ -40,6 +46,8 @@ import java.util.List;
public class DeviceDAOImpl implements DeviceDAO {
private static final Log log = LogFactory.getLog(DeviceDAOImpl.class);
@Override
public void addDevice(int typeId, Device device, int tenantId) throws DeviceManagementDAOException {
Connection conn;
@ -317,6 +325,50 @@ public class DeviceDAOImpl implements DeviceDAO {
}
}
@Override
public List<Application> getInstalledApplications(int deviceId)
throws DeviceManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
List<Application> applications = new ArrayList<Application>();
Application application;
ByteArrayInputStream bais;
ObjectInputStream ois;
try {
conn = this.getConnection();
stmt = conn.prepareStatement(
"SELECT DEVICE_ID, APPLICATIONS FROM DM_DEVICE_APPLICATIONS WHERE DEVICE_ID = ?");
stmt.setInt(1, deviceId);
ResultSet rs = stmt.executeQuery();
while (rs.next()) {
byte[] applicationDetails = rs.getBytes("APPLICATIONS");
bais = new ByteArrayInputStream(applicationDetails);
ois = new ObjectInputStream(bais);
application = (Application) ois.readObject();
applications.add(application);
}
}catch (IOException e) {
String errorMsg = "IO Error occurred while de serialize the Application object";
log.error(errorMsg, e);
throw new DeviceManagementDAOException(errorMsg, e);
} catch (ClassNotFoundException e) {
String errorMsg = "Class not found error occurred while de serialize the Application object";
log.error(errorMsg, e);
throw new DeviceManagementDAOException(errorMsg, e);
} catch (SQLException e) {
String errorMsg = "SQL Error occurred while retrieving the list of Applications installed in device id '"
+ deviceId;
log.error(errorMsg, e);
throw new DeviceManagementDAOException(errorMsg, e);
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}
return applications;
}
private Device loadDevice(ResultSet rs) throws SQLException {
Device device = new Device();

@ -82,7 +82,7 @@ public interface DeviceManagementProviderService extends DeviceManager, LicenseM
* The method to get application list installed for the device.
*
* @param deviceIdentifier
* @return
* @return List of applications installed on the device
* @throws DeviceManagementException
*/
List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException;

@ -648,7 +648,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
@Override
public List<Application> getApplicationListForDevice(DeviceIdentifier deviceIdentifier)
throws DeviceManagementException {
return null;
Device device = null;
try {
device = this.getDevice(deviceIdentifier);
return deviceDAO.getInstalledApplications(device.getId());
}catch (DeviceManagementDAOException deviceDaoEx){
String errorMsg = "Error occured while fetching the Application List of device : " + device.getId();
log.error(errorMsg, deviceDaoEx);
throw new DeviceManagementException(errorMsg, deviceDaoEx);
}
}
@Override

Loading…
Cancel
Save