retrieve app icon info

pull/111/head
Thashmi-nil 2 years ago
parent bd3eea49a8
commit 6cf960ce4c

@ -855,4 +855,13 @@ public interface DeviceDAO {
* @throws DeviceManagementDAOException * @throws DeviceManagementDAOException
*/ */
List<String> getAgentVersions(int tenantId) throws DeviceManagementDAOException; List<String> getAgentVersions(int tenantId) throws DeviceManagementDAOException;
/**
* This method is used to retrieve the icon info of an installed app in device.
*
* @param applicationIdentifier application identifier.
* @return returns the application icon path.
* @throws DeviceManagementDAOException
*/
String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException;
} }

@ -3236,4 +3236,27 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
} }
return agentVersions; return agentVersions;
} }
@Override
public String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException{
Connection conn;
PreparedStatement stmt = null;
String iconPath = null;
try{
conn = this.getConnection();
stmt = conn.prepareStatement("SELECT ICON_PATH FROM DM_APP_ICONS" +
" WHERE PACKAGE_NAME = ?");
stmt.setString(1,applicationIdentifier);
try (ResultSet rs = stmt.executeQuery()) {
if (rs.next()) {
iconPath = rs.getString("ICON_PATH");
}
return iconPath;
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while retrieving app icon path");
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}
}
} }

@ -3707,6 +3707,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} finally { } finally {
DeviceManagementDAOFactory.closeConnection(); DeviceManagementDAOFactory.closeConnection();
} }
if (applications != null){
this.getInstalledAppIconInfo(device);
}
return applications; return applications;
} }
@ -4921,4 +4924,48 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
throw new DeviceManagementException(msg, e); throw new DeviceManagementException(msg, e);
} }
} }
@Override
public void saveApplicationIcon(String iconPath, String packageName, String version) throws DeviceManagementException{
try{
DeviceManagementDAOFactory.beginTransaction();
if(applicationDAO.getApplicationPackageCount(packageName) == 0){
applicationDAO.saveApplicationIcon(iconPath, packageName, version);
}
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {
String msg = "Error occurred while initiating transaction";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while saving app icon info";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
private void getInstalledAppIconInfo(Device device) throws DeviceManagementException {
List<Application> applications = device.getApplications();
String iconPath;
try {
DeviceManagementDAOFactory.openConnection();
for (Application app : applications) {
iconPath = deviceDAO.getIconPath(app.getApplicationIdentifier());
app.setImageUrl(iconPath);
}
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving installed app icon info";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
} }

Loading…
Cancel
Save