From 74be4d8a821f1d8b28c98c0018788fa262837825 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Mon, 1 Oct 2018 18:24:12 +0530 Subject: [PATCH 1/2] Improve application releases getting logic --- .../common/services/ApplicationManager.java | 9 --- .../application/mgt/core/dao/common/Util.java | 52 ++++++++------- .../GenericApplicationDAOImpl.java | 2 +- .../GenericApplicationReleaseDAOImpl.java | 63 ++++++------------- .../mgt/core/impl/ApplicationManagerImpl.java | 48 +++++++------- 5 files changed, 76 insertions(+), 98 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 33a05562ae..81c5af0898 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -131,15 +131,6 @@ public interface ApplicationManager { */ Boolean isUserAllowable(List unrestrictedRoles, String userName) throws ApplicationManagementException; - /** - * To get the release of a particular Application. - * - * @param applicationId ID of the Application. - * @param state state of the Application. - * @return the List of the Application releases related with the particular Application. - * @throws ApplicationManagementException Application Management Exception. - */ - List getReleaseInState(int applicationId, String state) throws ApplicationManagementException; /** * To get all the releases of a particular Application. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index 1722a42070..32a4cd36e7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -59,17 +59,17 @@ public class Util { List applications = new ArrayList<>(); Application application = null; - int applicatioId = -1; + int applicationId = -1; while (rs.next()) { - if (applicatioId != rs.getInt("APP_ID")) { + if (applicationId != rs.getInt("APP_ID")) { if (application != null) { applications.add(application); } - applicatioId = rs.getInt("APP_ID"); + applicationId = rs.getInt("APP_ID"); application = new Application(); - application.setId(applicatioId); + application.setId(applicationId); application.setName(rs.getString("APP_NAME")); application.setType(rs.getString("APP_TYPE")); application.setAppCategory(rs.getString("APP_CATEGORY")); @@ -160,29 +160,37 @@ public class Util { /** * Populates {@link ApplicationRelease} object with the result obtained from the database. * - * @param rs {@link ResultSet} from obtained from the database + * @param resultSet {@link ResultSet} from obtained from the database * @return {@link ApplicationRelease} object populated with the data * @throws SQLException If unable to populate {@link ApplicationRelease} object with the data */ - public static ApplicationRelease readApplicationRelease(ResultSet rs) throws SQLException { - ApplicationRelease appRelease = new ApplicationRelease(); + public static ApplicationRelease loadApplicationRelease(ResultSet resultSet) throws SQLException { + ApplicationRelease applicationRelease = new ApplicationRelease(); + applicationRelease.setId(resultSet.getInt("RELEASE_ID")); + applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION")); + applicationRelease.setUuid(resultSet.getString("UUID")); + applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE")); + applicationRelease.setPackageName(resultSet.getString("PACKAGE_NAME")); + applicationRelease.setPrice(resultSet.getDouble("APP_PRICE")); + applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION")); + applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION")); + applicationRelease.setIconLoc(resultSet.getString("ICON_LOCATION")); + applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1")); + applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2")); + applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3")); + applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE")); + applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED")); + applicationRelease.setMetaData(resultSet.getString("APP_META_INFO")); + applicationRelease.setRating(resultSet.getDouble("RATING")); - appRelease.setId(rs.getInt("RELEASE_ID")); - appRelease.setVersion(rs.getString("VERSION")); - appRelease.setUuid(rs.getString("UUID")); - appRelease.setReleaseType(rs.getString("RELEASE_TYPE")); - appRelease.setPrice(rs.getDouble("APP_PRICE")); - appRelease.setAppHashValue(rs.getString("APP_HASH_VALUE")); - appRelease.setAppStoredLoc(rs.getString("STORED_LOCATION")); - appRelease.setBannerLoc(rs.getString("BANNER_LOCATION")); - appRelease.setRating(rs.getDouble("RATING")); - appRelease.setIsSharedWithAllTenants(rs.getInt("SHARED_WITH_ALL_TENANTS")); - appRelease.setMetaData(rs.getString("APP_META_INFO")); - appRelease.setScreenshotLoc1(rs.getString("SC_1_LOCATION")); - appRelease.setScreenshotLoc2(rs.getString("SC_2_LOCATION")); - appRelease.setScreenshotLoc3(rs.getString("SC_3_LOCATION")); + LifecycleState lifecycleState = new LifecycleState(); + lifecycleState.setCurrentState(resultSet.getString("CURRENT_STATE")); + lifecycleState.setPreviousState(resultSet.getString("PREVIOUS_STATE")); + lifecycleState.setUpdatedBy(resultSet.getString("UPDATED_BY")); + lifecycleState.setUpdatedAt(resultSet.getTimestamp("UPDATED_AT")); - return appRelease; + applicationRelease.setLifecycleState(lifecycleState); + return applicationRelease; } /** 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 1f365f86ff..8da2734775 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 @@ -644,7 +644,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic Application application = null; while (rs.next()) { - ApplicationRelease appRelease = Util.readApplicationRelease(rs); + ApplicationRelease appRelease = Util.loadApplicationRelease(rs); application = new Application(); application.setId(rs.getInt("APP_ID")); 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java index a6ae8c2f71..81acab2454 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java @@ -138,7 +138,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements resultSet = statement.executeQuery(); if (resultSet.next()) { - return constructApplicationRelease(resultSet); + return Util.loadApplicationRelease(resultSet); } return null; } catch (DBConnectionException e) { @@ -185,7 +185,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements resultSet = statement.executeQuery(); if (resultSet.next()) { - return constructApplicationRelease(resultSet); + return Util.loadApplicationRelease(resultSet); } return null; } catch (DBConnectionException e) { @@ -219,7 +219,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements + "AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, " + "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO, " - + "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=? AND AR.TENANT_ID = ?;"; + + "AR.RATING AS RATING AL.CURRENT_STATE AS CURRENT_STATE, AL.PREVIOUS_STATE AS PREVIOUSE_STATE, " + + "AL.UPDATED_BY AS UPDATED_BY, AL.UPDATED_AT AS UPDATED_AT FROM AP_APP_RELEASE " + + "AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE AR.AP_APP_ID=? AND AL.AP_APP_RELEASE_ID=AR.ID AND " + + "AR.TENANT_ID=? AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC LIMIT 1;"; try { connection = this.getDBConnection(); @@ -229,9 +232,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements resultSet = statement.executeQuery(); while (resultSet.next()) { - ApplicationRelease applicationRelease = constructApplicationRelease(resultSet); + ApplicationRelease applicationRelease = Util.loadApplicationRelease(resultSet); applicationReleases.add(applicationRelease); - } return applicationReleases; } catch (DBConnectionException e) { @@ -253,24 +255,26 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements PreparedStatement statement = null; ResultSet resultSet = null; List applicationReleases = new ArrayList<>(); - String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," - + " AR.STORED_LOCATION, AR.ICON_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR" + - ".SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " - + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.RATING FROM AP_APP_RELEASE AS " - + "AR where AR.TENANT_ID = ? AND AR.AP_APP_ID=(SELECT AP_APP_ID" + - " FROM AP_APP_LIFECYCLE_STATE WHERE AP_APP_ID = ? AND CURRENT_STATE = ? AND TENANT_ID = ?);"; + String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS " + + "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS " + + "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, ICON_LOCATION, AR.SC_1_LOCATION AS " + + "SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, " + + "AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS " + + "APP_META_INFO , AR.RATING AS RATING, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, " + + "AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL " + + "WHERE AR.AP_APP_ID=? AND AL.AP_APP_RELEASE_ID=AR.ID AND AL.CURRENT_STATE=? AND AR.TENANT_ID=? AND " + + "AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; try { connection = this.getDBConnection(); statement = connection.prepareStatement(sql); - statement.setInt(1, tenantId); - statement.setInt(2, appId); - statement.setString(3, state); - statement.setInt(4, tenantId); + statement.setInt(1, appId); + statement.setString(2, state); + statement.setInt(3, tenantId); resultSet = statement.executeQuery(); while (resultSet.next()) { - ApplicationRelease appRelease = constructApplicationRelease(resultSet); + ApplicationRelease appRelease = Util.loadApplicationRelease(resultSet); applicationReleases.add(appRelease); } return applicationReleases; @@ -499,31 +503,4 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements Util.cleanupResources(stmt, rs); } } - - /** - * This method is capable to construct {@link ApplicationRelease} and return the object - * - * @param resultSet result set obtained from the query executing. - * @throws SQLException SQL exception while accessing result set data. - */ - private ApplicationRelease constructApplicationRelease(ResultSet resultSet) throws SQLException { - ApplicationRelease applicationRelease = new ApplicationRelease(); - applicationRelease.setId(resultSet.getInt("RELEASE_ID")); - applicationRelease.setVersion(resultSet.getString("RELEASE_VERSION")); - applicationRelease.setUuid(resultSet.getString("UUID")); - applicationRelease.setReleaseType(resultSet.getString("RELEASE_TYPE")); - applicationRelease.setPackageName(resultSet.getString("PACKAGE_NAME")); - applicationRelease.setPrice(resultSet.getDouble("APP_PRICE")); - applicationRelease.setAppStoredLoc(resultSet.getString("STORED_LOCATION")); - applicationRelease.setBannerLoc(resultSet.getString("BANNER_LOCATION")); - applicationRelease.setIconLoc(resultSet.getString("ICON_LOCATION")); - applicationRelease.setScreenshotLoc1(resultSet.getString("SCREEN_SHOT_1")); - applicationRelease.setScreenshotLoc2(resultSet.getString("SCREEN_SHOT_2")); - applicationRelease.setScreenshotLoc3(resultSet.getString("SCREEN_SHOT_3")); - applicationRelease.setAppHashValue(resultSet.getString("HASH_VALUE")); - applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED")); - applicationRelease.setMetaData(resultSet.getString("APP_META_INFO")); - applicationRelease.setRating(resultSet.getDouble("RATING")); - return applicationRelease; - } } \ No newline at end of file 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 8733402785..9e2082dca0 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 @@ -117,6 +117,11 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.rollbackDBTransaction(); return null; } + if (!application.getUnrestrictedRoles().isEmpty()) { + application.setIsRestricted(true); + } else { + application.setIsRestricted(false); + } // Insert to application table int appId = this.applicationDAO.createApplication(application, deviceType.getId()); @@ -134,18 +139,12 @@ public class ApplicationManagerImpl implements ApplicationManager { log.debug("New tags entry added to AP_APP_TAG table. App Id:" + appId); } } - if (!application.getUnrestrictedRoles().isEmpty()) { - application.setIsRestricted(true); + if (application.getIsRestricted()) { this.visibilityDAO.addUnrestrictedRoles(application.getUnrestrictedRoles(), appId, tenantId); if(log.isDebugEnabled()){ log.debug("New restricted roles to app ID mapping added to AP_UNRESTRICTED_ROLE table." + " App Id:" + appId); } - } else { - if(log.isDebugEnabled()){ - log.debug("App is not restricted to role. App Id:" + appId); - } - application.setIsRestricted(false); } if (application.getApplicationReleases().size() > 1 ){ throw new ApplicationManagementException( @@ -284,10 +283,9 @@ public class ApplicationManagerImpl implements ApplicationManager { if (handleConnections) { ConnectionManagerUtil.openDBConnection(); } - application = ApplicationManagementDAOFactory.getApplicationDAO() - .getApplicationById(appId, tenantId); + application = this.applicationDAO.getApplicationById(appId, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { - applicationReleases = getReleaseInState(appId, state); + applicationReleases = getReleaseInState(appId, state, tenantId); application.setApplicationReleases(applicationReleases); return application; } @@ -303,9 +301,7 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!isAppAllowed) { return null; } - if (state != null) { - applicationReleases = getReleaseInState(appId, state); - } + applicationReleases = getReleaseInState(appId, state, tenantId); application.setApplicationReleases(applicationReleases); return application; } catch (UserStoreException e) { @@ -439,8 +435,7 @@ public class ApplicationManagerImpl implements ApplicationManager { for (ApplicationRelease applicationRelease : applicationReleases) { LifecycleState lifecycleState = null; try { - lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO(). - getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); + lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); } catch (LifeCycleManagementDAOException e) { throw new ApplicationManagementException( "Error occurred while getting the latest lifecycle state for the application release UUID: " @@ -471,20 +466,27 @@ public class ApplicationManagerImpl implements ApplicationManager { } + private List getReleaseInState(int applicationId, String state, int tenantId) + throws ApplicationManagementException { + List applicationReleases; + List filteredReleases = new ArrayList<>(); - - @Override - public List getReleaseInState(int applicationId, String state) throws - ApplicationManagementException { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - + // todo check whether this rquired or not Application application = getApplicationIfAccessible(applicationId); if (log.isDebugEnabled()) { log.debug("Request is received to retrieve all the releases related with the application " + application .toString()); } - ConnectionManagerUtil.getDBConnection(); - return this.applicationReleaseDAO.getReleaseByState(applicationId, tenantId, state); + applicationReleases = this.applicationReleaseDAO.getReleases(applicationId, tenantId); + if (state != null && !state.isEmpty()) { + for (ApplicationRelease applicationRelease : applicationReleases) { + if (state.equals(applicationRelease.getLifecycleState().getCurrentState())) { + filteredReleases.add(applicationRelease); + } + } + return filteredReleases; + } + return applicationReleases; } @Override From cd28edc6a35c4c5a37aad16a721b9eb3b4646792 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Tue, 2 Oct 2018 17:35:09 +0530 Subject: [PATCH 2/2] Filx application getting API issue --- .../device/application/mgt/common/Filter.java | 10 +-- .../device/application/mgt/common/Tag.java | 10 --- .../common/services/ApplicationManager.java | 5 +- .../mgt/core/dao/ApplicationReleaseDAO.java | 1 - .../application/mgt/core/dao/common/Util.java | 8 -- .../GenericApplicationDAOImpl.java | 16 ++-- .../GenericApplicationReleaseDAOImpl.java | 26 +++--- .../GenericLifecycleStateDAOImpl.java | 14 +++- .../mgt/core/impl/ApplicationManagerImpl.java | 82 ++++++++----------- .../services/ApplicationManagementAPI.java | 6 +- .../impl/ApplicationManagementAPIImpl.java | 25 +++--- .../dbscripts/cdm/application-mgt/h2.sql | 2 +- .../dbscripts/cdm/application-mgt/mysql.sql | 2 +- 13 files changed, 89 insertions(+), 118 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java index 0d1c5b693c..732fd0a611 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Filter.java @@ -61,7 +61,7 @@ public class Filter { /** * Set as True if required to have only published application release, otherwise set to False */ - private boolean requirePublishedRelease; + private String currentAppReleaseState; public int getLimit() { return limit; @@ -119,11 +119,11 @@ public class Filter { this.appCategory = appCategory; } - public boolean isRequirePublishedRelease() { - return requirePublishedRelease; + public String getCurrentAppReleaseState() { + return currentAppReleaseState; } - public void setRequirePublishedRelease(boolean requirePublishedRelease) { - this.requirePublishedRelease = requirePublishedRelease; + public void setCurrentAppReleaseState(String currentAppReleaseState) { + this.currentAppReleaseState = currentAppReleaseState; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Tag.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Tag.java index 9227f2ebfd..b40e88714b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Tag.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Tag.java @@ -26,8 +26,6 @@ public class Tag { private int id; - private String tenantId; - private String tagName; private Application application; @@ -40,14 +38,6 @@ public class Tag { this.id = id; } - public String getTenantId() { - return tenantId; - } - - public void setTenantId(String tenantId) { - this.tenantId = tenantId; - } - public String getTagName() { return tagName; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 81c5af0898..0b34ed971e 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -97,13 +97,10 @@ public interface ApplicationManager { * * @param id id of the Application * @param state state of the Application - * @param handleConnections Whether it is required to handle DB connections within(true), or if there are - * existing connection(false) * @return the Application identified by the ID * @throws ApplicationManagementException Application Management Exception. */ - Application getApplicationById(int id, String state, boolean handleConnections) throws - ApplicationManagementException; + Application getApplicationById(int id, String state) throws ApplicationManagementException; /** * To get an application associated with the release. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java index d7128a9d29..12d868e663 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationReleaseDAO.java @@ -18,7 +18,6 @@ */ package org.wso2.carbon.device.application.mgt.core.dao; -import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java index 32a4cd36e7..d38488ec45 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/common/Util.java @@ -182,14 +182,6 @@ public class Util { applicationRelease.setIsSharedWithAllTenants(resultSet.getInt("SHARED")); applicationRelease.setMetaData(resultSet.getString("APP_META_INFO")); applicationRelease.setRating(resultSet.getDouble("RATING")); - - LifecycleState lifecycleState = new LifecycleState(); - lifecycleState.setCurrentState(resultSet.getString("CURRENT_STATE")); - lifecycleState.setPreviousState(resultSet.getString("PREVIOUS_STATE")); - lifecycleState.setUpdatedBy(resultSet.getString("UPDATED_BY")); - lifecycleState.setUpdatedAt(resultSet.getTimestamp("UPDATED_AT")); - - applicationRelease.setLifecycleState(lifecycleState); return applicationRelease; } 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 8da2734775..96ab3d7efb 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 @@ -66,7 +66,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { conn = this.getDBConnection(); stmt = conn.prepareStatement("INSERT INTO AP_APP (NAME, TYPE, APP_CATEGORY, SUB_TYPE, RESTRICTED, " - + "TENANT_ID, DM_DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?, ?)", + + "TENANT_ID, DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, application.getName()); stmt.setString(2, application.getType()); @@ -401,16 +401,18 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { conn = this.getDBConnection(); String sql = - "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, " + - "AP_APP.APP_CATEGORY AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE ," + - "AP_APP.CURRENCY AS CURRENCY, AP_APP.RESTRICTED AS RESTRICTED, " + - "DM_DEVICE_TYPE_ID AS DEVICE_TYPE_ID " + - "FROM AP_APP " + - "WHERE AP_APP.ID=? AND AP_APP.TENANT_ID=?;"; + "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " + + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " + + "AP_APP.RESTRICTED AS RESTRICTED, AP_APP.DEVICE_TYPE_ID AS DEVICE_TYPE_ID, " + + "AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLE.ROLE AS ROLE FROM " + + "((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) " + + "LEFT JOIN AP_UNRESTRICTED_ROLE ON AP_APP.ID = AP_UNRESTRICTED_ROLE.AP_APP_ID) WHERE " + + "AP_APP.ID = ? AND AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, applicationId); stmt.setInt(2, tenantId); + stmt.setString(3, AppLifecycleState.REMOVED.toString()); rs = stmt.executeQuery(); if (log.isDebugEnabled()) { 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java index 81acab2454..4e5ca14683 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/release/GenericApplicationReleaseDAOImpl.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/release/GenericApplicationReleaseDAOImpl.java @@ -112,20 +112,20 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements */ @Override public ApplicationRelease getRelease(String applicationName, String applicationType, String versionName, String releaseType, int tenantId) throws ApplicationManagementDAOException { - + //todo no usage Connection connection; PreparedStatement statement = null; ResultSet resultSet = null; String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS " + "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS " - + "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, ICON_LOCATION, AR.SC_1_LOCATION AS " + - "SCREEN_SHOT_1, " - + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " - + "HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO , " - + "AR.RATING AS RATING, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM " - + "AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE " - + "NAME=? AND TYPE=? AND TENANT_ID=?) AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND " - + "AL.AP_APP_RELEASE_ID=AR.ID AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; + + "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, AR.ICON_LOCATION AS " + + "ICON_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, " + + "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS " + + "AS SHARED, AR.APP_META_INFO AS APP_META_INFO, AR.RATING AS RATING, AL.CURRENT_STATE, " + + "AL.PREVIOUS_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE " + + "AS AL WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?) " + + "AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND AL.AP_APP_RELEASE_ID=AR.ID " + + "AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;"; try { connection = this.getDBConnection(); @@ -215,14 +215,11 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ResultSet resultSet = null; List applicationReleases = new ArrayList<>(); String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE " - + "AS RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, ICON_LOCATION" + + "AS RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, AR.ICON_LOCATION, " + "AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, " + "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO, " - + "AR.RATING AS RATING AL.CURRENT_STATE AS CURRENT_STATE, AL.PREVIOUS_STATE AS PREVIOUSE_STATE, " - + "AL.UPDATED_BY AS UPDATED_BY, AL.UPDATED_AT AS UPDATED_AT FROM AP_APP_RELEASE " - + "AS AR, AP_APP_LIFECYCLE_STATE AS AL WHERE AR.AP_APP_ID=? AND AL.AP_APP_RELEASE_ID=AR.ID AND " - + "AR.TENANT_ID=? AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC LIMIT 1;"; + + "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=? AND AR.TENANT_ID = ?;"; try { connection = this.getDBConnection(); @@ -248,6 +245,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements } } + //todo this has to be removed @Override public List getReleaseByState(int appId, int tenantId, String state) throws ApplicationManagementDAOException { 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/lifecyclestate/GenericLifecycleStateDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java index 515379ede3..ee2f65d4ba 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/lifecyclestate/GenericLifecycleStateDAOImpl.java @@ -29,7 +29,9 @@ 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.Calendar; import java.util.List; /** @@ -129,14 +131,20 @@ public class GenericLifecycleStateDAOImpl extends AbstractDAOImpl implements Lif try { conn = this.getDBConnection(); String sql = "INSERT INTO AP_APP_LIFECYCLE_STATE (CURRENT_STATE, PREVIOUS_STATE, TENANT_ID, UPDATED_BY, " - + "AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?,(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?),?);"; + + "UPDATED_AT, AP_APP_RELEASE_ID, AP_APP_ID) VALUES (?,?, ?, ?, ?, " + + "(SELECT ID FROM AP_APP_RELEASE WHERE UUID=?),?);"; + + Calendar calendar = Calendar.getInstance(); + Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); + stmt = conn.prepareStatement(sql); stmt.setString(1, state.getCurrentState().toUpperCase()); stmt.setString(2, state.getPreviousState().toUpperCase()); stmt.setInt(3, tenantId); stmt.setString(4, state.getUpdatedBy()); - stmt.setString(5, uuid); - stmt.setInt(6, appId); + stmt.setTimestamp(5, timestamp); + stmt.setString(6, uuid); + stmt.setInt(7, appId); stmt.executeUpdate(); } catch (DBConnectionException e) { 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 9e2082dca0..c330f7308a 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 @@ -101,7 +101,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } ConnectionManagerUtil.openDBConnection(); - validateAppCreatingRequest(application); + validateAppCreatingRequest(application, tenantId); validateAppReleasePayload(application.getApplicationReleases().get(0)); DeviceType deviceType; ApplicationRelease applicationRelease; @@ -210,7 +210,7 @@ public class ApplicationManagerImpl implements ApplicationManager { } try { - ConnectionManagerUtil.getDBConnection(); + ConnectionManagerUtil.openDBConnection(); applicationList = applicationDAO.getApplications(filter, tenantId); if(applicationList != null && applicationList.getApplications() != null && !applicationList .getApplications().isEmpty()) { @@ -218,7 +218,7 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationList = getRoleRestrictedApplicationList(applicationList, userName); } for (Application application : applicationList.getApplications()) { - applicationReleases = getReleases(application, filter.isRequirePublishedRelease()); + applicationReleases = getReleases(application, filter.getCurrentAppReleaseState()); application.setApplicationReleases(applicationReleases); } } @@ -230,6 +230,8 @@ public class ApplicationManagerImpl implements ApplicationManager { } catch (ApplicationManagementDAOException e) { throw new ApplicationManagementException( "DAO exception while getting applications for the user " + userName + " of tenant " + tenantId, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); } } @@ -273,19 +275,24 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public Application getApplicationById(int appId, String state, boolean handleConnections) throws ApplicationManagementException { + public Application getApplicationById(int appId, String state) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); Application application; boolean isAppAllowed = false; + boolean isOpenConnection = false; List applicationReleases = null; try { - if (handleConnections) { + if (state != null) { ConnectionManagerUtil.openDBConnection(); + isOpenConnection = true; } application = this.applicationDAO.getApplicationById(appId, tenantId); + if (application == null) { + throw new NotFoundException("Couldn't find an application for application Id: " + appId); + } if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { - applicationReleases = getReleaseInState(appId, state, tenantId); + applicationReleases = getReleases(application, state); application.setApplicationReleases(applicationReleases); return application; } @@ -301,14 +308,14 @@ public class ApplicationManagerImpl implements ApplicationManager { if (!isAppAllowed) { return null; } - applicationReleases = getReleaseInState(appId, state, tenantId); + applicationReleases = getReleases(application, state); application.setApplicationReleases(applicationReleases); return application; } catch (UserStoreException e) { throw new ApplicationManagementException( "User-store exception while getting application with the application id " + appId); } finally { - if (handleConnections) { + if (isOpenConnection) { ConnectionManagerUtil.closeDBConnection(); } } @@ -349,7 +356,7 @@ public class ApplicationManagerImpl implements ApplicationManager { ConnectionManagerUtil.openDBConnection(); application = this.applicationDAO.getApplication(appName, appType, tenantId); if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { - applicationReleases = getReleases(application, false); + applicationReleases = getReleases(application, null); application.setApplicationReleases(applicationReleases); return application; } @@ -366,7 +373,7 @@ public class ApplicationManagerImpl implements ApplicationManager { return null; } - applicationReleases = getReleases(application, false); + applicationReleases = getReleases(application, null); application.setApplicationReleases(applicationReleases); return application; } catch (UserStoreException e) { @@ -421,16 +428,14 @@ public class ApplicationManagerImpl implements ApplicationManager { } } - private List getReleases(Application application, boolean requirePublishedRelease) + private List getReleases(Application application, String releaseState) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); List applicationReleases; - List filteredApplicationReleases = new ArrayList<>(); if (log.isDebugEnabled()) { log.debug("Request is received to retrieve all the releases related with the application " + application .toString()); } - ConnectionManagerUtil.getDBConnection(); applicationReleases = this.applicationReleaseDAO.getReleases(application.getId(), tenantId); for (ApplicationRelease applicationRelease : applicationReleases) { LifecycleState lifecycleState = null; @@ -443,47 +448,26 @@ public class ApplicationManagerImpl implements ApplicationManager { } if (lifecycleState != null) { applicationRelease.setLifecycleState(lifecycleState); - - if (!AppLifecycleState.REMOVED.toString() - .equals(applicationRelease.getLifecycleState().getCurrentState())) { - if (requirePublishedRelease){ - if (AppLifecycleState.PUBLISHED.toString() - .equals(applicationRelease.getLifecycleState().getCurrentState())){ - filteredApplicationReleases.add(applicationRelease); - } - }else{ - filteredApplicationReleases.add(applicationRelease); - } - } } } - - if (requirePublishedRelease && filteredApplicationReleases.size() > 1) { - log.error("There are more than one published application releases for application ID: " + application - .getId()); - } - return filteredApplicationReleases; - + return filterAppReleaseByCurrentState(applicationReleases, releaseState); } - private List getReleaseInState(int applicationId, String state, int tenantId) - throws ApplicationManagementException { - List applicationReleases; + private List filterAppReleaseByCurrentState(List applicationReleases, + String state) { List filteredReleases = new ArrayList<>(); - // todo check whether this rquired or not - Application application = getApplicationIfAccessible(applicationId); - if (log.isDebugEnabled()) { - log.debug("Request is received to retrieve all the releases related with the application " + application - .toString()); - } - applicationReleases = this.applicationReleaseDAO.getReleases(applicationId, tenantId); if (state != null && !state.isEmpty()) { for (ApplicationRelease applicationRelease : applicationReleases) { if (state.equals(applicationRelease.getLifecycleState().getCurrentState())) { filteredReleases.add(applicationRelease); } } + + if (AppLifecycleState.PUBLISHED.toString() + .equals(state) && filteredReleases.size() > 1) { + log.warn("There are more than one application releases is found which is in PUBLISHED state"); + } return filteredReleases; } return applicationReleases; @@ -507,7 +491,7 @@ public class ApplicationManagerImpl implements ApplicationManager { if ( application == null) { throw new ApplicationManagementException("Invalid Application"); } - List applicationReleases = getReleases(application, false); + List applicationReleases = getReleases(application, null); if (log.isDebugEnabled()) { log.debug("Request is received to delete applications which are related with the application id " + applicationId); @@ -589,7 +573,7 @@ public class ApplicationManagerImpl implements ApplicationManager { * @param application Application that need to be created * @throws ValidationException Validation Exception */ - private void validateAppCreatingRequest(Application application) throws ValidationException { + private void validateAppCreatingRequest(Application application, int tenantId) throws ValidationException { Boolean isValidApplicationType; try { @@ -611,7 +595,7 @@ public class ApplicationManagerImpl implements ApplicationManager { "App Type contains in the application creating payload doesn't match with supported app types"); } - validateApplicationExistence(application); + validateApplicationExistence(application, tenantId); } catch (ApplicationManagementException e) { throw new ValidationException("Error occured while validating whether there is already an application " + "registered with same name.", e); @@ -633,14 +617,14 @@ public class ApplicationManagerImpl implements ApplicationManager { * @param application Application that need to be validated * @throws ValidationException Validation Exception */ - private void validateApplicationExistence(Application application) throws ApplicationManagementException { + private void validateApplicationExistence(Application application, int tenantId) throws ApplicationManagementException { Filter filter = new Filter(); filter.setFullMatch(true); filter.setAppName(application.getName().trim()); filter.setOffset(0); filter.setLimit(1); - ApplicationList applicationList = getApplications(filter); + ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId); if (applicationList != null && applicationList.getApplications() != null && !applicationList.getApplications() .isEmpty()) { throw new ApplicationManagementException( @@ -765,10 +749,10 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationStorageManager applicationStorageManager = Util.getApplicationStorageManager(); ApplicationRelease applicationRelease; try { - ConnectionManagerUtil.getDBConnection(); + ConnectionManagerUtil.openDBConnection(); applicationRelease = getAppReleaseIfExists(appId, uuid); - Application application = getApplicationById(appId, null, false); + Application application = getApplicationById(appId, null); List deviceTypes = Util.getDeviceManagementService().getDeviceTypes(); for (DeviceType deviceType:deviceTypes) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java index 9da0a697e7..d46e8a0b1a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/ApplicationManagementAPI.java @@ -141,9 +141,9 @@ public interface ApplicationManagementAPI { value = "Is it requesting exactly matching application or partially matching application.") @QueryParam("exact-match") boolean isFullMatch, @ApiParam( - name = "published-release", - value = "If set to True, only get published release for the application") - @QueryParam("published-release") boolean requirePublishedReleases, + name = "release-state", + value = "Current state of the application release") + @QueryParam("release-state") String releaseState, @ApiParam( name = "offset", value = "offset", diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java index bda214825a..959b471c30 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/ApplicationManagementAPIImpl.java @@ -70,7 +70,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @QueryParam("type") String appType, @QueryParam("category") String appCategory, @QueryParam("exact-match") boolean isFullMatch, - @QueryParam("published-release") boolean requirePublishedReleases, + @QueryParam("release-state") String releaseState, @DefaultValue("0") @QueryParam("offset") int offset, @DefaultValue("20") @QueryParam("limit") int limit, @DefaultValue("ASC") @QueryParam("sort") String sortBy) { @@ -82,7 +82,6 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { filter.setLimit(limit); filter.setSortBy(sortBy); filter.setFullMatch(isFullMatch); - filter.setRequirePublishedRelease(requirePublishedReleases); if (appName != null && !appName.isEmpty()) { filter.setAppName(appName); } @@ -92,6 +91,9 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { if (appCategory != null && !appCategory.isEmpty()) { filter.setAppCategory(appCategory); } + if (releaseState != null && !releaseState.isEmpty()) { + filter.setCurrentAppReleaseState(releaseState); + } ApplicationList applications = applicationManager.getApplications(filter); if (applications.getApplications().isEmpty()) { return Response.status(Response.Status.NOT_FOUND).entity @@ -105,25 +107,24 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } } - @GET @Consumes("application/json") @Path("/{appId}") public Response getApplication( @PathParam("appId") int appId, - @QueryParam("state") String state) { + @DefaultValue("PUBLISHED") @QueryParam("state") String state) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - Application application = applicationManager.getApplicationById(appId, state, true); - if (application == null) { - return Response.status(Response.Status.NOT_FOUND).entity - ("Application with application id: " + appId + " not found").build(); - } - + Application application = applicationManager.getApplicationById(appId, state); return Response.status(Response.Status.OK).entity(application).build(); + } catch (NotFoundException e) { + String msg = "Application with application id: " + appId + " not found"; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); } catch (ApplicationManagementException e) { - log.error("Error occurred while getting application with the id " + appId, e); - return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); + String msg = "Error occurred while getting application with the id " + appId; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql index 0d18bc2ed7..a33659ae07 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/h2.sql @@ -11,7 +11,7 @@ CREATE TABLE IF NOT EXISTS AP_APP ( STATUS VARCHAR(45) NOT NULL DEFAULT 'ACTIVE', SUB_TYPE VARCHAR(45) NOT NULL, CURRENCY VARCHAR(45) NULL DEFAULT '$', - DM_DEVICE_TYPE_ID INT(11) NOT NULL, + DEVICE_TYPE_ID INT(11) NOT NULL, PRIMARY KEY (ID)); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql index 6ca495e2df..e854d459e1 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/dbscripts/cdm/application-mgt/mysql.sql @@ -21,7 +21,7 @@ CREATE TABLE IF NOT EXISTS `AP_APP` ( `STATUS` VARCHAR(45) NOT NULL DEFAULT 'ACTIVE', `SUB_TYPE` VARCHAR(45) NOT NULL, `CURRENCY` VARCHAR(45) NULL DEFAULT '$', - `DM_DEVICE_TYPE_ID` INT(11) NOT NULL, + `DEVICE_TYPE_ID` INT(11) NOT NULL, PRIMARY KEY (`ID`)) ENGINE = InnoDB DEFAULT CHARACTER SET = utf8;