save public & enterprise app icon info

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

@ -1286,6 +1286,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
applicationDTO.setId(appId); applicationDTO.setId(appId);
applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities);
if (applicationDTO.getType().equals("ENTERPRISE") || applicationDTO.getType().equals("PUBLIC") ) {
persistAppIconInfo(applicationReleaseDTO);
}
return APIUtil.appDtoToAppResponse(applicationDTO); return APIUtil.appDtoToAppResponse(applicationDTO);
} }
} catch (LifeCycleManagementDAOException e) { } catch (LifeCycleManagementDAOException e) {
@ -1312,6 +1315,23 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
private void persistAppIconInfo(ApplicationReleaseDTO applicationReleaseDTO)
throws ApplicationManagementException {
try{
String iconPath = APIUtil.createAppIconPath(applicationReleaseDTO);
DataHolder.getInstance().getDeviceManagementService().saveApplicationIcon(iconPath,
String.valueOf(applicationReleaseDTO.getPackageName()), applicationReleaseDTO.getVersion());
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating iconPath";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (DeviceManagementException e) {
String msg = "Error occurred while saving application icon info";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
@Override @Override
public <T> ApplicationRelease createRelease(ApplicationDTO applicationDTO, ApplicationReleaseDTO applicationReleaseDTO, public <T> ApplicationRelease createRelease(ApplicationDTO applicationDTO, ApplicationReleaseDTO applicationReleaseDTO,
ApplicationType type, boolean isPublished) ApplicationType type, boolean isPublished)
@ -1358,6 +1378,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
ApplicationRelease applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO); ApplicationRelease applicationRelease = APIUtil.releaseDtoToRelease(applicationReleaseDTO);
DataHolder.getInstance().getDeviceManagementService().saveApplicationIcon(applicationReleaseDTO.getIconName(),
String.valueOf(applicationReleaseDTO.getPackageName()), applicationReleaseDTO.getVersion());
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
return applicationRelease; return applicationRelease;
} catch (TransactionManagementException e) { } catch (TransactionManagementException e) {
@ -1381,6 +1403,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
String msg = "Error occurred while adding new application release for application " + applicationDTO.getId(); String msg = "Error occurred while adding new application release for application " + applicationDTO.getId();
log.error(msg, e); log.error(msg, e);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (DeviceManagementException e) {
throw new RuntimeException(e);
} finally { } finally {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }

@ -510,4 +510,12 @@ public class APIUtil {
return mdmConfig.getArtifactDownloadProtocol() + "://" + host + ":" + port return mdmConfig.getArtifactDownloadProtocol() + "://" + host + ":" + port
+ artifactDownloadEndpoint + Constants.FORWARD_SLASH; + artifactDownloadEndpoint + Constants.FORWARD_SLASH;
} }
public static String createAppIconPath(ApplicationReleaseDTO applicationReleaseDTO) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + applicationReleaseDTO
.getAppHashValue() + Constants.FORWARD_SLASH;
String iconPath = basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName();
return iconPath;
}
} }

@ -64,4 +64,20 @@ public interface ApplicationDAO {
* @throws DeviceManagementDAOException If any database error occured * @throws DeviceManagementDAOException If any database error occured
*/ */
List<String> getAppVersions(int tenantId, String packageName) throws DeviceManagementDAOException; List<String> getAppVersions(int tenantId, String packageName) throws DeviceManagementDAOException;
/**
* This method is used to save application icon information.
* @param iconPath Icon path of the application
* @param packageName Package name of the application
* @param version version of the application
* @throws DeviceManagementDAOException If any database error occurred
*/
void saveApplicationIcon(String iconPath, String packageName, String version) throws DeviceManagementDAOException;
/**
* This method is used to check the package existence.
* @param packageName Package name of the application
* @throws DeviceManagementDAOException If any database error occurred
*/
int getApplicationPackageCount(String packageName) throws DeviceManagementDAOException;
} }

@ -395,4 +395,44 @@ public class ApplicationDAOImpl implements ApplicationDAO {
return application; return application;
} }
@Override
public void saveApplicationIcon(String iconPath, String packageName, String version)
throws DeviceManagementDAOException{
Connection conn;
PreparedStatement stmt = null;
try{
conn = this.getConnection();
stmt = conn.prepareStatement("INSERT INTO DM_APP_ICONS (ICON_PATH, PACKAGE_NAME, VERSION) " +
"VALUES (?, ?, ?)");
stmt.setString(1,iconPath);
stmt.setString(2,packageName);
stmt.setString(3,version);
stmt.executeUpdate();
} catch(SQLException e){
throw new DeviceManagementDAOException("Error occurred while saving application icon details");
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}
}
@Override
public int getApplicationPackageCount(String packageName) throws DeviceManagementDAOException{
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try{
conn = this.getConnection();
stmt = conn.prepareStatement("SELECT COUNT(*) AS APP_PACKAGE_COUNT FROM DM_APP_ICONS WHERE PACKAGE_NAME = ?");
stmt.setString(1, packageName);
rs = stmt.executeQuery();
if (rs.next()) {
return rs.getInt("APP_PACKAGE_COUNT");
}
return 0;
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while saving application icon details");
} finally {
DeviceManagementDAOUtil.cleanupResources(stmt, null);
}
}
} }

@ -1034,4 +1034,14 @@ public interface DeviceManagementProviderService {
throws DeviceManagementException; throws DeviceManagementException;
Boolean sendDeviceNameChangedNotification(Device device) throws DeviceManagementException; Boolean sendDeviceNameChangedNotification(Device device) throws DeviceManagementException;
/**
* This method is for saving application icon info
* @param iconPath Icon path of the application
* @param packageName Package name of the application
* @param version Version of the application
* @throws DeviceManagementException if any service level or DAO level error occurs
*/
void saveApplicationIcon(String iconPath, String packageName, String version)
throws DeviceManagementException;
} }

Loading…
Cancel
Save