Fix incorrect app release loading issue in app store

reporting
tcdlpds@gmail.com 5 years ago
parent cf3bacc31d
commit 07e7d014c5

@ -138,16 +138,16 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "INNER JOIN AP_APP_RELEASE ON " + "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "
+ "INNER JOIN (SELECT AP_APP.ID FROM AP_APP "; + "INNER JOIN (SELECT AP_APP.ID FROM AP_APP ";
if (!StringUtils.isEmpty(filter.getVersion()) || !StringUtils.isEmpty(filter.getAppReleaseState()) if (StringUtils.isNotEmpty(filter.getVersion()) || StringUtils.isNotEmpty(filter.getAppReleaseState())
|| !StringUtils.isEmpty(filter.getAppReleaseType())) { || StringUtils.isNotEmpty(filter.getAppReleaseType())) {
sql += "INNER JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "; sql += "INNER JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID ";
} }
sql += "WHERE AP_APP.TENANT_ID = ? "; sql += "WHERE AP_APP.TENANT_ID = ? ";
if (!StringUtils.isEmpty(filter.getAppType())) { if (StringUtils.isNotEmpty(filter.getAppType())) {
sql += "AND AP_APP.TYPE = ? "; sql += "AND AP_APP.TYPE = ? ";
} }
if (!StringUtils.isEmpty(filter.getAppName())) { if (StringUtils.isNotEmpty(filter.getAppName())) {
sql += "AND LOWER (AP_APP.NAME) "; sql += "AND LOWER (AP_APP.NAME) ";
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
sql += "= ? "; sql += "= ? ";
@ -155,26 +155,26 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
sql += "LIKE ? "; sql += "LIKE ? ";
} }
} }
if (!StringUtils.isEmpty(filter.getSubscriptionType())) { if (StringUtils.isNotEmpty(filter.getSubscriptionType())) {
sql += "AND AP_APP.SUB_TYPE = ? "; sql += "AND AP_APP.SUB_TYPE = ? ";
} }
if (filter.getMinimumRating() > 0) { if (filter.getMinimumRating() > 0) {
sql += "AND AP_APP.RATING >= ? "; sql += "AND AP_APP.RATING >= ? ";
} }
if (!StringUtils.isEmpty(filter.getVersion())) { if (StringUtils.isNotEmpty(filter.getVersion())) {
sql += "AND AP_APP_RELEASE.VERSION = ? "; sql += "AND AP_APP_RELEASE.VERSION = ? ";
} }
if (!StringUtils.isEmpty(filter.getAppReleaseType())) { if (StringUtils.isNotEmpty(filter.getAppReleaseType())) {
sql += "AND AP_APP_RELEASE.RELEASE_TYPE = ? "; sql += "AND AP_APP_RELEASE.RELEASE_TYPE = ? ";
} }
if (!StringUtils.isEmpty(filter.getAppReleaseState())) { if (StringUtils.isNotEmpty(filter.getAppReleaseState())) {
sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? "; sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? ";
} }
if (deviceTypeId != -1) { if (deviceTypeId != -1) {
sql += "AND AP_APP.DEVICE_TYPE_ID = ? "; sql += "AND AP_APP.DEVICE_TYPE_ID = ? ";
} }
sql += "GROUP BY AP_APP.ID "; sql += "GROUP BY AP_APP.ID ";
if (!StringUtils.isEmpty(filter.getSortBy())) { if (StringUtils.isNotEmpty(filter.getSortBy())) {
sql += "ORDER BY ID " + filter.getSortBy() +" "; sql += "ORDER BY ID " + filter.getSortBy() +" ";
} }
if (filter.getLimit() != -1) { if (filter.getLimit() != -1) {
@ -186,29 +186,29 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int paramIndex = 1; int paramIndex = 1;
stmt.setInt(paramIndex++, tenantId); stmt.setInt(paramIndex++, tenantId);
if (!StringUtils.isEmpty(filter.getAppType())) { if (StringUtils.isNotEmpty(filter.getAppType())) {
stmt.setString(paramIndex++, filter.getAppType()); stmt.setString(paramIndex++, filter.getAppType());
} }
if (!StringUtils.isEmpty(filter.getAppName())) { if (StringUtils.isNotEmpty(filter.getAppName())) {
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); stmt.setString(paramIndex++, filter.getAppName().toLowerCase());
} else { } else {
stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%");
} }
} }
if (!StringUtils.isEmpty(filter.getSubscriptionType())) { if (StringUtils.isNotEmpty(filter.getSubscriptionType())) {
stmt.setString(paramIndex++, filter.getSubscriptionType()); stmt.setString(paramIndex++, filter.getSubscriptionType());
} }
if (filter.getMinimumRating() > 0) { if (filter.getMinimumRating() > 0) {
stmt.setInt(paramIndex++, filter.getMinimumRating()); stmt.setInt(paramIndex++, filter.getMinimumRating());
} }
if (!StringUtils.isEmpty(filter.getVersion())) { if (StringUtils.isNotEmpty(filter.getVersion())) {
stmt.setString(paramIndex++, filter.getVersion()); stmt.setString(paramIndex++, filter.getVersion());
} }
if (!StringUtils.isEmpty(filter.getAppReleaseType())) { if (StringUtils.isNotEmpty(filter.getAppReleaseType())) {
stmt.setString(paramIndex++, filter.getAppReleaseType()); stmt.setString(paramIndex++, filter.getAppReleaseType());
} }
if (!StringUtils.isEmpty(filter.getAppReleaseState())) { if (StringUtils.isNotEmpty(filter.getAppReleaseState())) {
stmt.setString(paramIndex++, filter.getAppReleaseState()); stmt.setString(paramIndex++, filter.getAppReleaseState());
} }
if (deviceTypeId > 0) { if (deviceTypeId > 0) {

@ -85,14 +85,14 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
+ "INNER JOIN AP_APP_RELEASE ON " + "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "
+ "INNER JOIN (SELECT AP_APP.ID FROM AP_APP ORDER BY ID "; + "INNER JOIN (SELECT AP_APP.ID FROM AP_APP ORDER BY ID ";
if (!StringUtils.isEmpty(filter.getVersion()) || !StringUtils.isEmpty(filter.getAppReleaseState()) if (StringUtils.isNotEmpty(filter.getVersion()) || StringUtils.isNotEmpty(filter.getAppReleaseState())
|| !StringUtils.isEmpty(filter.getAppReleaseType())) { || StringUtils.isNotEmpty(filter.getAppReleaseType())) {
sql += "INNER JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "; sql += "INNER JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID ";
} }
if (!StringUtils.isEmpty(filter.getAppType())) { if (StringUtils.isNotEmpty(filter.getAppType())) {
sql += "AND AP_APP.TYPE = ? "; sql += "AND AP_APP.TYPE = ? ";
} }
if (!StringUtils.isEmpty(filter.getAppName())) { if (StringUtils.isNotEmpty(filter.getAppName())) {
sql += " AND LOWER (AP_APP.NAME) "; sql += " AND LOWER (AP_APP.NAME) ";
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
sql += "= ? "; sql += "= ? ";
@ -100,26 +100,26 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
sql += "LIKE ? "; sql += "LIKE ? ";
} }
} }
if (!StringUtils.isEmpty(filter.getSubscriptionType())) { if (StringUtils.isNotEmpty(filter.getSubscriptionType())) {
sql += "AND AP_APP.SUB_TYPE = ? "; sql += "AND AP_APP.SUB_TYPE = ? ";
} }
if (filter.getMinimumRating() > 0) { if (filter.getMinimumRating() > 0) {
sql += "AND AP_APP.RATING >= ? "; sql += "AND AP_APP.RATING >= ? ";
} }
if (!StringUtils.isEmpty(filter.getVersion())) { if (StringUtils.isNotEmpty(filter.getVersion())) {
sql += "AND AP_APP_RELEASE.VERSION = ? "; sql += "AND AP_APP_RELEASE.VERSION = ? ";
} }
if (!StringUtils.isEmpty(filter.getAppReleaseType())) { if (StringUtils.isNotEmpty(filter.getAppReleaseType())) {
sql += "AND AP_APP_RELEASE.RELEASE_TYPE = ? "; sql += "AND AP_APP_RELEASE.RELEASE_TYPE = ? ";
} }
if (!StringUtils.isEmpty(filter.getAppReleaseState())) { if (StringUtils.isNotEmpty(filter.getAppReleaseState())) {
sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? "; sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? ";
} }
if (deviceTypeId != -1) { if (deviceTypeId != -1) {
sql += "AND AP_APP.DEVICE_TYPE_ID = ? "; sql += "AND AP_APP.DEVICE_TYPE_ID = ? ";
} }
sql += "GROUP BY AP_APP.ID "; sql += "GROUP BY AP_APP.ID ";
if (!StringUtils.isEmpty(filter.getSortBy())) { if (StringUtils.isNotEmpty(filter.getSortBy())) {
sql += "ORDER BY ID " + filter.getSortBy() + " "; sql += "ORDER BY ID " + filter.getSortBy() + " ";
} }
if (filter.getLimit() != -1) { if (filter.getLimit() != -1) {
@ -131,29 +131,29 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int paramIndex = 1; int paramIndex = 1;
if (!StringUtils.isEmpty(filter.getAppType())) { if (StringUtils.isNotEmpty(filter.getAppType())) {
stmt.setString(paramIndex++, filter.getAppType()); stmt.setString(paramIndex++, filter.getAppType());
} }
if (!StringUtils.isEmpty(filter.getAppName())) { if (StringUtils.isNotEmpty(filter.getAppName())) {
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); stmt.setString(paramIndex++, filter.getAppName().toLowerCase());
} else { } else {
stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%");
} }
} }
if (!StringUtils.isEmpty(filter.getSubscriptionType())) { if (StringUtils.isNotEmpty(filter.getSubscriptionType())) {
stmt.setString(paramIndex++, filter.getSubscriptionType()); stmt.setString(paramIndex++, filter.getSubscriptionType());
} }
if (filter.getMinimumRating() > 0) { if (filter.getMinimumRating() > 0) {
stmt.setInt(paramIndex++, filter.getMinimumRating()); stmt.setInt(paramIndex++, filter.getMinimumRating());
} }
if (!StringUtils.isEmpty(filter.getVersion())) { if (StringUtils.isNotEmpty(filter.getVersion())) {
stmt.setString(paramIndex++, filter.getVersion()); stmt.setString(paramIndex++, filter.getVersion());
} }
if (!StringUtils.isEmpty(filter.getAppReleaseType())) { if (StringUtils.isNotEmpty(filter.getAppReleaseType())) {
stmt.setString(paramIndex++, filter.getAppReleaseType()); stmt.setString(paramIndex++, filter.getAppReleaseType());
} }
if (!StringUtils.isEmpty(filter.getAppReleaseState())) { if (StringUtils.isNotEmpty(filter.getAppReleaseState())) {
stmt.setString(paramIndex++, filter.getAppReleaseState()); stmt.setString(paramIndex++, filter.getAppReleaseState());
} }
if (deviceTypeId > 0) { if (deviceTypeId > 0) {

@ -84,14 +84,14 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl {
+ "INNER JOIN AP_APP_RELEASE ON " + "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "
+ "INNER JOIN (SELECT AP_APP.ID FROM AP_APP "; + "INNER JOIN (SELECT AP_APP.ID FROM AP_APP ";
if (!StringUtils.isEmpty(filter.getVersion()) || !StringUtils.isEmpty(filter.getAppReleaseState()) if (StringUtils.isNotEmpty(filter.getVersion()) || StringUtils.isNotEmpty(filter.getAppReleaseState())
|| !StringUtils.isEmpty(filter.getAppReleaseType())) { || StringUtils.isNotEmpty(filter.getAppReleaseType())) {
sql += "INNER JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "; sql += "INNER JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID ";
} }
if (!StringUtils.isEmpty(filter.getAppType())) { if (StringUtils.isNotEmpty(filter.getAppType())) {
sql += "AND AP_APP.TYPE = ? "; sql += "AND AP_APP.TYPE = ? ";
} }
if (!StringUtils.isEmpty(filter.getAppName())) { if (StringUtils.isNotEmpty(filter.getAppName())) {
sql += " AND LOWER (AP_APP.NAME) "; sql += " AND LOWER (AP_APP.NAME) ";
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
sql += "= ? "; sql += "= ? ";
@ -99,26 +99,26 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl {
sql += "LIKE ? "; sql += "LIKE ? ";
} }
} }
if (!StringUtils.isEmpty(filter.getSubscriptionType())) { if (StringUtils.isNotEmpty(filter.getSubscriptionType())) {
sql += "AND AP_APP.SUB_TYPE = ? "; sql += "AND AP_APP.SUB_TYPE = ? ";
} }
if (filter.getMinimumRating() > 0) { if (filter.getMinimumRating() > 0) {
sql += "AND AP_APP.RATING >= ? "; sql += "AND AP_APP.RATING >= ? ";
} }
if (!StringUtils.isEmpty(filter.getVersion())) { if (StringUtils.isNotEmpty(filter.getVersion())) {
sql += "AND AP_APP_RELEASE.VERSION = ? "; sql += "AND AP_APP_RELEASE.VERSION = ? ";
} }
if (!StringUtils.isEmpty(filter.getAppReleaseType())) { if (StringUtils.isNotEmpty(filter.getAppReleaseType())) {
sql += "AND AP_APP_RELEASE.RELEASE_TYPE = ? "; sql += "AND AP_APP_RELEASE.RELEASE_TYPE = ? ";
} }
if (!StringUtils.isEmpty(filter.getAppReleaseState())) { if (StringUtils.isNotEmpty(filter.getAppReleaseState())) {
sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? "; sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? ";
} }
if (deviceTypeId != -1) { if (deviceTypeId != -1) {
sql += "AND AP_APP.DEVICE_TYPE_ID = ? "; sql += "AND AP_APP.DEVICE_TYPE_ID = ? ";
} }
sql += "GROUP BY AP_APP.ID "; sql += "GROUP BY AP_APP.ID ";
if (!StringUtils.isEmpty(filter.getSortBy())) { if (StringUtils.isNotEmpty(filter.getSortBy())) {
sql += "ORDER BY ID " + filter.getSortBy() + " "; sql += "ORDER BY ID " + filter.getSortBy() + " ";
} }
if (filter.getLimit() != -1) { if (filter.getLimit() != -1) {
@ -130,29 +130,29 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int paramIndex = 1; int paramIndex = 1;
if (!StringUtils.isEmpty(filter.getAppType())) { if (StringUtils.isNotEmpty(filter.getAppType())) {
stmt.setString(paramIndex++, filter.getAppType()); stmt.setString(paramIndex++, filter.getAppType());
} }
if (!StringUtils.isEmpty(filter.getAppName())) { if (StringUtils.isNotEmpty(filter.getAppName())) {
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); stmt.setString(paramIndex++, filter.getAppName().toLowerCase());
} else { } else {
stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%");
} }
} }
if (!StringUtils.isEmpty(filter.getSubscriptionType())) { if (StringUtils.isNotEmpty(filter.getSubscriptionType())) {
stmt.setString(paramIndex++, filter.getSubscriptionType()); stmt.setString(paramIndex++, filter.getSubscriptionType());
} }
if (filter.getMinimumRating() > 0) { if (filter.getMinimumRating() > 0) {
stmt.setInt(paramIndex++, filter.getMinimumRating()); stmt.setInt(paramIndex++, filter.getMinimumRating());
} }
if (!StringUtils.isEmpty(filter.getVersion())) { if (StringUtils.isNotEmpty(filter.getVersion())) {
stmt.setString(paramIndex++, filter.getVersion()); stmt.setString(paramIndex++, filter.getVersion());
} }
if (!StringUtils.isEmpty(filter.getAppReleaseType())) { if (StringUtils.isNotEmpty(filter.getAppReleaseType())) {
stmt.setString(paramIndex++, filter.getAppReleaseType()); stmt.setString(paramIndex++, filter.getAppReleaseType());
} }
if (!StringUtils.isEmpty(filter.getAppReleaseState())) { if (StringUtils.isNotEmpty(filter.getAppReleaseState())) {
stmt.setString(paramIndex++, filter.getAppReleaseState()); stmt.setString(paramIndex++, filter.getAppReleaseState());
} }
if (deviceTypeId > 0) { if (deviceTypeId > 0) {

@ -618,41 +618,36 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
//Set application categories, tags and unrestricted roles to the application DTO. //Set application categories, tags and unrestricted roles to the application DTO.
applicationDTO.setUnrestrictedRoles(visibilityDAO applicationDTO
.getUnrestrictedRoles(applicationDTO.getId(), tenantId)); .setUnrestrictedRoles(visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId));
applicationDTO.setAppCategories(applicationDAO.getAppCategories(applicationDTO.getId(), tenantId)); applicationDTO.setAppCategories(applicationDAO.getAppCategories(applicationDTO.getId(), tenantId));
applicationDTO.setTags(applicationDAO.getAppTags(applicationDTO.getId(), tenantId)); applicationDTO.setTags(applicationDAO.getAppTags(applicationDTO.getId(), tenantId));
if (isFilteringApp(applicationDTO, filter)) { if (isFilteringApp(applicationDTO, filter)) {
boolean isHideableApp = isHideableApp(applicationDTO.getApplicationReleaseDTOs());
boolean isDeletableApp = isDeletableApp(applicationDTO.getApplicationReleaseDTOs());
List<ApplicationReleaseDTO> filteredApplicationReleaseDTOs = new ArrayList<>(); List<ApplicationReleaseDTO> filteredApplicationReleaseDTOs = new ArrayList<>();
AtomicBoolean isDeletableApp = new AtomicBoolean(true);
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) { for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
String appReleaseCurrentState = applicationReleaseDTO.getCurrentState(); if (StringUtils.isNotEmpty(filter.getVersion()) && !filter.getVersion()
if (!lifecycleStateManager.getEndState().equals(appReleaseCurrentState)) { .equals(applicationReleaseDTO.getVersion())) {
if (isDeletableApp.get() && !lifecycleStateManager.isDeletableState(appReleaseCurrentState)) { continue;
isDeletableApp.set(false);
} }
filteredApplicationReleaseDTOs.add(applicationReleaseDTO); if (StringUtils.isNotEmpty(filter.getAppReleaseState()) && !filter.getAppReleaseState()
.equals(applicationReleaseDTO.getCurrentState())) {
continue;
} }
if (StringUtils.isNotEmpty(filter.getAppReleaseType()) && !filter.getAppReleaseType()
.equals(applicationReleaseDTO.getReleaseType())) {
continue;
}
filteredApplicationReleaseDTOs.add(applicationReleaseDTO);
} }
applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs); applicationDTO.setApplicationReleaseDTOs(filteredApplicationReleaseDTOs);
Application application = APIUtil.appDtoToAppResponse(applicationDTO); Application application = APIUtil.appDtoToAppResponse(applicationDTO);
application.setDeletableApp(isDeletableApp);
/* application.setHideableApp(isHideableApp);
* Load the entire application again if the searched application is either deletable or all the app
* releases are in the end state of the app lifecycle. App has to be reloaded because when searching
* applications it may not contains all the application releases of an application.
*/
if (isDeletableApp.get() || filteredApplicationReleaseDTOs.isEmpty()){
ApplicationDTO entireApp = applicationDAO.getApplication(applicationDTO.getId(), tenantId);
if (filteredApplicationReleaseDTOs.isEmpty()){
application.setHideableApp(isHideableApp(entireApp.getApplicationReleaseDTOs()));
}
if (isDeletableApp.get()) {
application.setDeletableApp(isDeletableApp(entireApp.getApplicationReleaseDTOs()));
}
}
applications.add(application); applications.add(application);
} }
} }

Loading…
Cancel
Save