From 07e7d014c5f4ccf67ba96067ca8b606ca7794166 Mon Sep 17 00:00:00 2001 From: "tcdlpds@gmail.com" Date: Sat, 23 May 2020 00:19:02 +0530 Subject: [PATCH] Fix incorrect app release loading issue in app store --- .../GenericApplicationDAOImpl.java | 30 ++++++------- .../application/OracleApplicationDAOImpl.java | 30 ++++++------- .../SQLServerApplicationDAOImpl.java | 30 ++++++------- .../mgt/core/impl/ApplicationManagerImpl.java | 43 ++++++++----------- 4 files changed, 64 insertions(+), 69 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java index 8ad0152096..1059fe4580 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -138,16 +138,16 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "INNER JOIN AP_APP_RELEASE ON " + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " + "INNER JOIN (SELECT AP_APP.ID FROM AP_APP "; - if (!StringUtils.isEmpty(filter.getVersion()) || !StringUtils.isEmpty(filter.getAppReleaseState()) - || !StringUtils.isEmpty(filter.getAppReleaseType())) { + if (StringUtils.isNotEmpty(filter.getVersion()) || StringUtils.isNotEmpty(filter.getAppReleaseState()) + || StringUtils.isNotEmpty(filter.getAppReleaseType())) { sql += "INNER JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "; } sql += "WHERE AP_APP.TENANT_ID = ? "; - if (!StringUtils.isEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType())) { sql += "AND AP_APP.TYPE = ? "; } - if (!StringUtils.isEmpty(filter.getAppName())) { + if (StringUtils.isNotEmpty(filter.getAppName())) { sql += "AND LOWER (AP_APP.NAME) "; if (filter.isFullMatch()) { sql += "= ? "; @@ -155,26 +155,26 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic sql += "LIKE ? "; } } - if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + if (StringUtils.isNotEmpty(filter.getSubscriptionType())) { sql += "AND AP_APP.SUB_TYPE = ? "; } if (filter.getMinimumRating() > 0) { sql += "AND AP_APP.RATING >= ? "; } - if (!StringUtils.isEmpty(filter.getVersion())) { + if (StringUtils.isNotEmpty(filter.getVersion())) { sql += "AND AP_APP_RELEASE.VERSION = ? "; } - if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseType())) { sql += "AND AP_APP_RELEASE.RELEASE_TYPE = ? "; } - if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseState())) { sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? "; } if (deviceTypeId != -1) { sql += "AND AP_APP.DEVICE_TYPE_ID = ? "; } sql += "GROUP BY AP_APP.ID "; - if (!StringUtils.isEmpty(filter.getSortBy())) { + if (StringUtils.isNotEmpty(filter.getSortBy())) { sql += "ORDER BY ID " + filter.getSortBy() +" "; } if (filter.getLimit() != -1) { @@ -186,29 +186,29 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIndex = 1; stmt.setInt(paramIndex++, tenantId); - if (!StringUtils.isEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType())) { stmt.setString(paramIndex++, filter.getAppType()); } - if (!StringUtils.isEmpty(filter.getAppName())) { + if (StringUtils.isNotEmpty(filter.getAppName())) { if (filter.isFullMatch()) { stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); } else { stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); } } - if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + if (StringUtils.isNotEmpty(filter.getSubscriptionType())) { stmt.setString(paramIndex++, filter.getSubscriptionType()); } if (filter.getMinimumRating() > 0) { stmt.setInt(paramIndex++, filter.getMinimumRating()); } - if (!StringUtils.isEmpty(filter.getVersion())) { + if (StringUtils.isNotEmpty(filter.getVersion())) { stmt.setString(paramIndex++, filter.getVersion()); } - if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseType())) { stmt.setString(paramIndex++, filter.getAppReleaseType()); } - if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseState())) { stmt.setString(paramIndex++, filter.getAppReleaseState()); } if (deviceTypeId > 0) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java index d39469eedf..b570c10fab 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/OracleApplicationDAOImpl.java @@ -85,14 +85,14 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { + "INNER JOIN AP_APP_RELEASE ON " + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " + "INNER JOIN (SELECT AP_APP.ID FROM AP_APP ORDER BY ID "; - if (!StringUtils.isEmpty(filter.getVersion()) || !StringUtils.isEmpty(filter.getAppReleaseState()) - || !StringUtils.isEmpty(filter.getAppReleaseType())) { + if (StringUtils.isNotEmpty(filter.getVersion()) || StringUtils.isNotEmpty(filter.getAppReleaseState()) + || StringUtils.isNotEmpty(filter.getAppReleaseType())) { 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 = ? "; } - if (!StringUtils.isEmpty(filter.getAppName())) { + if (StringUtils.isNotEmpty(filter.getAppName())) { sql += " AND LOWER (AP_APP.NAME) "; if (filter.isFullMatch()) { sql += "= ? "; @@ -100,26 +100,26 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { sql += "LIKE ? "; } } - if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + if (StringUtils.isNotEmpty(filter.getSubscriptionType())) { sql += "AND AP_APP.SUB_TYPE = ? "; } if (filter.getMinimumRating() > 0) { sql += "AND AP_APP.RATING >= ? "; } - if (!StringUtils.isEmpty(filter.getVersion())) { + if (StringUtils.isNotEmpty(filter.getVersion())) { sql += "AND AP_APP_RELEASE.VERSION = ? "; } - if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseType())) { sql += "AND AP_APP_RELEASE.RELEASE_TYPE = ? "; } - if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseState())) { sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? "; } if (deviceTypeId != -1) { sql += "AND AP_APP.DEVICE_TYPE_ID = ? "; } sql += "GROUP BY AP_APP.ID "; - if (!StringUtils.isEmpty(filter.getSortBy())) { + if (StringUtils.isNotEmpty(filter.getSortBy())) { sql += "ORDER BY ID " + filter.getSortBy() + " "; } if (filter.getLimit() != -1) { @@ -131,29 +131,29 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { Connection conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIndex = 1; - if (!StringUtils.isEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType())) { stmt.setString(paramIndex++, filter.getAppType()); } - if (!StringUtils.isEmpty(filter.getAppName())) { + if (StringUtils.isNotEmpty(filter.getAppName())) { if (filter.isFullMatch()) { stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); } else { stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); } } - if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + if (StringUtils.isNotEmpty(filter.getSubscriptionType())) { stmt.setString(paramIndex++, filter.getSubscriptionType()); } if (filter.getMinimumRating() > 0) { stmt.setInt(paramIndex++, filter.getMinimumRating()); } - if (!StringUtils.isEmpty(filter.getVersion())) { + if (StringUtils.isNotEmpty(filter.getVersion())) { stmt.setString(paramIndex++, filter.getVersion()); } - if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseType())) { stmt.setString(paramIndex++, filter.getAppReleaseType()); } - if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseState())) { stmt.setString(paramIndex++, filter.getAppReleaseState()); } if (deviceTypeId > 0) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java index 9e07d8ccea..8825b20579 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/SQLServerApplicationDAOImpl.java @@ -84,14 +84,14 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { + "INNER JOIN AP_APP_RELEASE ON " + "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID " + "INNER JOIN (SELECT AP_APP.ID FROM AP_APP "; - if (!StringUtils.isEmpty(filter.getVersion()) || !StringUtils.isEmpty(filter.getAppReleaseState()) - || !StringUtils.isEmpty(filter.getAppReleaseType())) { + if (StringUtils.isNotEmpty(filter.getVersion()) || StringUtils.isNotEmpty(filter.getAppReleaseState()) + || StringUtils.isNotEmpty(filter.getAppReleaseType())) { 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 = ? "; } - if (!StringUtils.isEmpty(filter.getAppName())) { + if (StringUtils.isNotEmpty(filter.getAppName())) { sql += " AND LOWER (AP_APP.NAME) "; if (filter.isFullMatch()) { sql += "= ? "; @@ -99,26 +99,26 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { sql += "LIKE ? "; } } - if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + if (StringUtils.isNotEmpty(filter.getSubscriptionType())) { sql += "AND AP_APP.SUB_TYPE = ? "; } if (filter.getMinimumRating() > 0) { sql += "AND AP_APP.RATING >= ? "; } - if (!StringUtils.isEmpty(filter.getVersion())) { + if (StringUtils.isNotEmpty(filter.getVersion())) { sql += "AND AP_APP_RELEASE.VERSION = ? "; } - if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseType())) { sql += "AND AP_APP_RELEASE.RELEASE_TYPE = ? "; } - if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseState())) { sql += "AND AP_APP_RELEASE.CURRENT_STATE = ? "; } if (deviceTypeId != -1) { sql += "AND AP_APP.DEVICE_TYPE_ID = ? "; } sql += "GROUP BY AP_APP.ID "; - if (!StringUtils.isEmpty(filter.getSortBy())) { + if (StringUtils.isNotEmpty(filter.getSortBy())) { sql += "ORDER BY ID " + filter.getSortBy() + " "; } if (filter.getLimit() != -1) { @@ -130,29 +130,29 @@ public class SQLServerApplicationDAOImpl extends GenericApplicationDAOImpl { Connection conn = this.getDBConnection(); try (PreparedStatement stmt = conn.prepareStatement(sql)) { int paramIndex = 1; - if (!StringUtils.isEmpty(filter.getAppType())) { + if (StringUtils.isNotEmpty(filter.getAppType())) { stmt.setString(paramIndex++, filter.getAppType()); } - if (!StringUtils.isEmpty(filter.getAppName())) { + if (StringUtils.isNotEmpty(filter.getAppName())) { if (filter.isFullMatch()) { stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); } else { stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); } } - if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + if (StringUtils.isNotEmpty(filter.getSubscriptionType())) { stmt.setString(paramIndex++, filter.getSubscriptionType()); } if (filter.getMinimumRating() > 0) { stmt.setInt(paramIndex++, filter.getMinimumRating()); } - if (!StringUtils.isEmpty(filter.getVersion())) { + if (StringUtils.isNotEmpty(filter.getVersion())) { stmt.setString(paramIndex++, filter.getVersion()); } - if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseType())) { stmt.setString(paramIndex++, filter.getAppReleaseType()); } - if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + if (StringUtils.isNotEmpty(filter.getAppReleaseState())) { stmt.setString(paramIndex++, filter.getAppReleaseState()); } if (deviceTypeId > 0) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java index 55ddd7d3f3..a2a92062f5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/impl/ApplicationManagerImpl.java @@ -618,41 +618,36 @@ public class ApplicationManagerImpl implements ApplicationManager { } //Set application categories, tags and unrestricted roles to the application DTO. - applicationDTO.setUnrestrictedRoles(visibilityDAO - .getUnrestrictedRoles(applicationDTO.getId(), tenantId)); + applicationDTO + .setUnrestrictedRoles(visibilityDAO.getUnrestrictedRoles(applicationDTO.getId(), tenantId)); applicationDTO.setAppCategories(applicationDAO.getAppCategories(applicationDTO.getId(), tenantId)); applicationDTO.setTags(applicationDAO.getAppTags(applicationDTO.getId(), tenantId)); if (isFilteringApp(applicationDTO, filter)) { + boolean isHideableApp = isHideableApp(applicationDTO.getApplicationReleaseDTOs()); + boolean isDeletableApp = isDeletableApp(applicationDTO.getApplicationReleaseDTOs()); + List filteredApplicationReleaseDTOs = new ArrayList<>(); - AtomicBoolean isDeletableApp = new AtomicBoolean(true); for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) { - String appReleaseCurrentState = applicationReleaseDTO.getCurrentState(); - if (!lifecycleStateManager.getEndState().equals(appReleaseCurrentState)) { - if (isDeletableApp.get() && !lifecycleStateManager.isDeletableState(appReleaseCurrentState)) { - isDeletableApp.set(false); - } - filteredApplicationReleaseDTOs.add(applicationReleaseDTO); + if (StringUtils.isNotEmpty(filter.getVersion()) && !filter.getVersion() + .equals(applicationReleaseDTO.getVersion())) { + continue; + } + 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); Application application = APIUtil.appDtoToAppResponse(applicationDTO); - - /* - * 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())); - } - } + application.setDeletableApp(isDeletableApp); + application.setHideableApp(isHideableApp); applications.add(application); } }