|
|
@ -30,7 +30,11 @@ import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUti
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.ByteArrayInputStream;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
import java.io.ObjectInputStream;
|
|
|
|
import java.sql.*;
|
|
|
|
import java.sql.Connection;
|
|
|
|
|
|
|
|
import java.sql.PreparedStatement;
|
|
|
|
|
|
|
|
import java.sql.ResultSet;
|
|
|
|
|
|
|
|
import java.sql.SQLException;
|
|
|
|
|
|
|
|
import java.sql.Timestamp;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.Date;
|
|
|
|
import java.util.List;
|
|
|
|
import java.util.List;
|
|
|
@ -396,42 +400,52 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
|
|
|
public void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId)
|
|
|
|
public void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId)
|
|
|
|
throws DeviceManagementDAOException{
|
|
|
|
throws DeviceManagementDAOException{
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
String sql = "INSERT INTO DM_APP_ICONS " +
|
|
|
|
try{
|
|
|
|
"(ICON_PATH, " +
|
|
|
|
|
|
|
|
"PACKAGE_NAME, " +
|
|
|
|
|
|
|
|
"VERSION, " +
|
|
|
|
|
|
|
|
"CREATED_TIMESTAMP, " +
|
|
|
|
|
|
|
|
"TENANT_ID) " +
|
|
|
|
|
|
|
|
"VALUES (?, ?, ?, ?, ?)";
|
|
|
|
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt = conn.prepareStatement("INSERT INTO DM_APP_ICONS (ICON_PATH, PACKAGE_NAME, VERSION, CREATED_TIMESTAMP, TENANT_ID) " +
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
"VALUES (?, ?, ?, ?, ?)");
|
|
|
|
stmt.setString(1,iconPath);
|
|
|
|
stmt.setString(1,iconPath);
|
|
|
|
stmt.setString(2,packageName);
|
|
|
|
stmt.setString(2,packageName);
|
|
|
|
stmt.setString(3,version);
|
|
|
|
stmt.setString(3,version);
|
|
|
|
stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
|
|
|
|
stmt.setTimestamp(4, new Timestamp(new Date().getTime()));
|
|
|
|
stmt.setInt(5, tenantId);
|
|
|
|
stmt.setInt(5, tenantId);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
}
|
|
|
|
} catch(SQLException e){
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while saving application icon details");
|
|
|
|
String msg = "Error occurred while saving application icon details";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public int getApplicationPackageCount(String packageName) throws DeviceManagementDAOException{
|
|
|
|
public int getApplicationPackageCount(String packageName) throws DeviceManagementDAOException{
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
String sql = "SELECT " +
|
|
|
|
ResultSet rs = null;
|
|
|
|
"COUNT(*) AS APP_PACKAGE_COUNT " +
|
|
|
|
try{
|
|
|
|
"FROM DM_APP_ICONS " +
|
|
|
|
|
|
|
|
"WHERE PACKAGE_NAME = ?";
|
|
|
|
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt = conn.prepareStatement("SELECT COUNT(*) AS APP_PACKAGE_COUNT FROM DM_APP_ICONS WHERE PACKAGE_NAME = ?");
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
stmt.setString(1, packageName);
|
|
|
|
stmt.setString(1, packageName);
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
return rs.getInt("APP_PACKAGE_COUNT");
|
|
|
|
return rs.getInt("APP_PACKAGE_COUNT");
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while saving application icon details");
|
|
|
|
String msg = "Error occurred while getting application icon details";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -439,63 +453,70 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
|
|
|
public void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version)
|
|
|
|
public void updateApplicationIcon(String iconPath, String oldPackageName, String newPackageName, String version)
|
|
|
|
throws DeviceManagementDAOException{
|
|
|
|
throws DeviceManagementDAOException{
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
String sql = "UPDATE DM_APP_ICONS " +
|
|
|
|
try{
|
|
|
|
"SET " +
|
|
|
|
|
|
|
|
"ICON_PATH= ?, " +
|
|
|
|
|
|
|
|
"PACKAGE_NAME = ?, " +
|
|
|
|
|
|
|
|
"VERSION = ? " +
|
|
|
|
|
|
|
|
"WHERE PACKAGE_NAME = ?";
|
|
|
|
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt = conn.prepareStatement("UPDATE DM_APP_ICONS " +
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
"SET " +
|
|
|
|
stmt.setString(1,iconPath);
|
|
|
|
"ICON_PATH= ?, " +
|
|
|
|
stmt.setString(2,newPackageName);
|
|
|
|
"PACKAGE_NAME = ?, " +
|
|
|
|
stmt.setString(3,version);
|
|
|
|
"VERSION = ? " +
|
|
|
|
stmt.setString(4,oldPackageName);
|
|
|
|
"WHERE PACKAGE_NAME = ?");
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.setString(1,iconPath);
|
|
|
|
}
|
|
|
|
stmt.setString(2,newPackageName);
|
|
|
|
} catch (SQLException e) {
|
|
|
|
stmt.setString(3,version);
|
|
|
|
String msg = "Error occurred while updating application icon details";
|
|
|
|
stmt.setString(4,oldPackageName);
|
|
|
|
log.error(msg, e);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
} catch(SQLException e){
|
|
|
|
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while updating application icon details");
|
|
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void deleteApplicationIcon(String packageName) throws DeviceManagementDAOException {
|
|
|
|
public void deleteApplicationIcon(String packageName) throws DeviceManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
String sql = "DELETE " +
|
|
|
|
try{
|
|
|
|
"FROM DM_APP_ICONS " +
|
|
|
|
|
|
|
|
"WHERE PACKAGE_NAME = ?";
|
|
|
|
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt = conn.prepareStatement("DELETE FROM DM_APP_ICONS WHERE PACKAGE_NAME = ?" );
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
stmt.setString(1, packageName);
|
|
|
|
stmt.setString(1, packageName);
|
|
|
|
stmt.executeUpdate();
|
|
|
|
stmt.executeUpdate();
|
|
|
|
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while deleting application icon details");
|
|
|
|
String msg = "Error occurred while deleting application icon details";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException{
|
|
|
|
public String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException{
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
String sql = "SELECT " +
|
|
|
|
|
|
|
|
"ICON_PATH " +
|
|
|
|
|
|
|
|
"FROM DM_APP_ICONS " +
|
|
|
|
|
|
|
|
"WHERE PACKAGE_NAME = ?";
|
|
|
|
String iconPath = null;
|
|
|
|
String iconPath = null;
|
|
|
|
try{
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt = conn.prepareStatement("SELECT ICON_PATH FROM DM_APP_ICONS" +
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
" WHERE PACKAGE_NAME = ?");
|
|
|
|
stmt.setString(1,applicationIdentifier);
|
|
|
|
stmt.setString(1,applicationIdentifier);
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
if (rs.next()) {
|
|
|
|
iconPath = rs.getString("ICON_PATH");
|
|
|
|
iconPath = rs.getString("ICON_PATH");
|
|
|
|
}
|
|
|
|
|
|
|
|
return iconPath;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return iconPath;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("Error occurred while retrieving app icon path");
|
|
|
|
String msg = "Error occurred while retrieving app icon path of the application";
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, null);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -503,30 +524,49 @@ public class ApplicationDAOImpl implements ApplicationDAO {
|
|
|
|
public List<Application> getInstalledApplicationListOnDevice(int deviceId, int enrolmentId, int offset, int limit, int tenantId)
|
|
|
|
public List<Application> getInstalledApplicationListOnDevice(int deviceId, int enrolmentId, int offset, int limit, int tenantId)
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
throws DeviceManagementDAOException {
|
|
|
|
Connection conn;
|
|
|
|
Connection conn;
|
|
|
|
PreparedStatement stmt = null;
|
|
|
|
|
|
|
|
List<Application> applicationList = new ArrayList<>();
|
|
|
|
List<Application> applicationList = new ArrayList<>();
|
|
|
|
Application application;
|
|
|
|
Application application;
|
|
|
|
ResultSet rs = null;
|
|
|
|
String sql = "SELECT " +
|
|
|
|
|
|
|
|
"ID, " +
|
|
|
|
|
|
|
|
"NAME, " +
|
|
|
|
|
|
|
|
"APP_IDENTIFIER, " +
|
|
|
|
|
|
|
|
"PLATFORM, " +
|
|
|
|
|
|
|
|
"CATEGORY, " +
|
|
|
|
|
|
|
|
"VERSION, " +
|
|
|
|
|
|
|
|
"TYPE, " +
|
|
|
|
|
|
|
|
"LOCATION_URL, " +
|
|
|
|
|
|
|
|
"IMAGE_URL, " +
|
|
|
|
|
|
|
|
"APP_PROPERTIES, " +
|
|
|
|
|
|
|
|
"MEMORY_USAGE, " +
|
|
|
|
|
|
|
|
"IS_ACTIVE, " +
|
|
|
|
|
|
|
|
"TENANT_ID " +
|
|
|
|
|
|
|
|
"FROM DM_APPLICATION " +
|
|
|
|
|
|
|
|
"WHERE DEVICE_ID = ? AND " +
|
|
|
|
|
|
|
|
"ENROLMENT_ID = ? AND " +
|
|
|
|
|
|
|
|
"TENANT_ID = ? " +
|
|
|
|
|
|
|
|
"LIMIT ? " +
|
|
|
|
|
|
|
|
"OFFSET ?";
|
|
|
|
try {
|
|
|
|
try {
|
|
|
|
conn = this.getConnection();
|
|
|
|
conn = this.getConnection();
|
|
|
|
stmt = conn.prepareStatement("SELECT ID, NAME, APP_IDENTIFIER, PLATFORM, CATEGORY, VERSION, TYPE, " +
|
|
|
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
|
|
"LOCATION_URL, IMAGE_URL, APP_PROPERTIES, MEMORY_USAGE, IS_ACTIVE, TENANT_ID FROM DM_APPLICATION " +
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
"WHERE DEVICE_ID = ? AND ENROLMENT_ID = ? AND TENANT_ID = ? LIMIT ? OFFSET ?");
|
|
|
|
stmt.setInt(2, enrolmentId);
|
|
|
|
stmt.setInt(1, deviceId);
|
|
|
|
stmt.setInt(3, tenantId);
|
|
|
|
stmt.setInt(2, enrolmentId);
|
|
|
|
stmt.setInt(4, limit);
|
|
|
|
stmt.setInt(3, tenantId);
|
|
|
|
stmt.setInt(5, offset);
|
|
|
|
stmt.setInt(4, limit);
|
|
|
|
try (ResultSet rs = stmt.executeQuery()) {
|
|
|
|
stmt.setInt(5, offset);
|
|
|
|
while (rs.next()) {
|
|
|
|
rs = stmt.executeQuery();
|
|
|
|
application = loadApplication(rs);
|
|
|
|
while (rs.next()) {
|
|
|
|
applicationList.add(application);
|
|
|
|
application = loadApplication(rs);
|
|
|
|
}
|
|
|
|
applicationList.add(application);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
} catch (SQLException e) {
|
|
|
|
} catch (SQLException e) {
|
|
|
|
throw new DeviceManagementDAOException("SQL Error occurred while retrieving the list of Applications " +
|
|
|
|
String msg = "SQL Error occurred while retrieving the list of Applications " +
|
|
|
|
"installed in device id '" + deviceId, e);
|
|
|
|
"installed in device id '" + deviceId;
|
|
|
|
} finally {
|
|
|
|
log.error(msg, e);
|
|
|
|
DeviceManagementDAOUtil.cleanupResources(stmt, rs);
|
|
|
|
throw new DeviceManagementDAOException(msg, e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return applicationList;
|
|
|
|
return applicationList;
|
|
|
|
}
|
|
|
|
}
|
|
|
|