From e747c0bdb0bc9c1757cb7f6ede16b19729b0fdb5 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 18 Apr 2019 17:52:08 +0530 Subject: [PATCH] Add API for getting applications --- .../mgt/common/ApplicationList.java | 7 +- .../device/application/mgt/common/Filter.java | 107 ++++++-- .../common/config/RatingConfiguration.java | 42 +++ .../common/services/ApplicationManager.java | 2 +- .../mgt/core/config/Configuration.java | 11 +- .../mgt/core/dao/ApplicationDAO.java | 8 +- .../application/mgt/core/dao/common/Util.java | 48 ++-- .../GenericApplicationDAOImpl.java | 254 ++++++++---------- .../visibility/GenericVisibilityDAOImpl.java | 4 +- .../mgt/core/impl/ApplicationManagerImpl.java | 227 +++++++++++----- .../core/lifecycle/LifecycleStateManager.java | 11 +- .../application/mgt/core/util/APIUtil.java | 46 ++-- .../services/ApplicationManagementAPI.java | 50 +--- .../impl/ApplicationManagementAPIImpl.java | 19 +- .../impl/ApplicationManagementAPIImpl.java | 10 +- .../main/resources/conf/application-mgt.xml | 5 + 16 files changed, 507 insertions(+), 344 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/RatingConfiguration.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationList.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationList.java index 6c0f1ff515..e9a16d84d5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationList.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationList.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.application.mgt.common; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; +import org.wso2.carbon.device.application.mgt.common.response.Application; import java.util.List; @@ -27,15 +28,15 @@ import java.util.List; */ public class ApplicationList { - private List applications; + private List applications; private Pagination pagination; - public List getApplications() { + public List getApplications() { return applications; } - public void setApplications(List applications) { + public void setApplications(List applications) { this.applications = applications; } 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 f77749ed06..a240bbbb3f 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 @@ -18,25 +18,68 @@ */ package org.wso2.carbon.device.application.mgt.common; +import java.util.List; + /** * Filter represents a criteria that can be used for searching applications. */ public class Filter { - /** - * Name of the application + /*** + * Supported device type for the application. + * e.g :- Android, iOS, Windows + */ + private String deviceType; + + /*** + * Name of the application. */ private String appName; - /** - * Type of the application + /*** + * Type of the application. + * e.g :- ENTERPRISE, PUBLIC */ private String appType; + /*** + * Subscription type of the application. + * e.g :- FREE, PAID etc + */ + private String subscriptionType; + + /*** + * Minimum rating of the application. + * e.g :- 4,5 + */ + private int minimumRating; + + /*** + * Application release version. + */ + private String version; + + /*** + * Release type of the application release. + * e.g :- Alpha, Beta + */ + private String appReleaseType; + + /** + * Category list of the application + */ + private List appCategories; + /** - * Category of the application + * Tag list of the application + */ + private List tags; + + /*** + * Unrestricted role list. Visibility of the application can restricted through user roles and users can view the + * application who has at least one role in unrestricted role list */ - private String appCategory; + private List unrestrictedRoles; /** * Checking the application name matches fully with given name @@ -59,14 +102,10 @@ public class Filter { private String sortBy; /** - * Set as True if required to have only published application release, otherwise set to False + * Current application release state. + * e.g :- CREATED. IN_REVIEW, PUBLISHED etc */ - private String currentAppReleaseState; - - /*** - * Supported device type for the application. i.e Android, iOS, Windows etc - */ - private int deviceTypeId; + private String appReleaseState; public int getLimit() { return limit; @@ -116,21 +155,43 @@ public class Filter { this.appType = appType; } - public String getAppCategory() { - return appCategory; + public List getAppCategories() { + return appCategories; } - public void setAppCategory(String appCategory) { - this.appCategory = appCategory; + public void setAppCategories(List appCategories) { + this.appCategories = appCategories; } - public String getCurrentAppReleaseState() { return currentAppReleaseState; } + public List getTags() { return tags; } - public void setCurrentAppReleaseState(String currentAppReleaseState) { - this.currentAppReleaseState = currentAppReleaseState; - } + public void setTags(List tags) { this.tags = tags; } + + public List getUnrestrictedRoles() { return unrestrictedRoles; } + + public void setUnrestrictedRoles(List unrestrictedRoles) { this.unrestrictedRoles = unrestrictedRoles; } + + public String getAppReleaseState() { return appReleaseState; } + + public void setAppReleaseState(String appReleaseState) { this.appReleaseState = appReleaseState; } + + public String getDeviceType() { return deviceType; } + + public void setDeviceType(String deviceType) { this.deviceType = deviceType; } + + public String getSubscriptionType() { return subscriptionType; } + + public void setSubscriptionType(String subscriptionType) { this.subscriptionType = subscriptionType; } + + public int getMinimumRating() { return minimumRating; } + + public void setMinimumRating(int minimumRating) { this.minimumRating = minimumRating; } + + public String getVersion() { return version; } + + public void setVersion(String version) { this.version = version; } - public int getDeviceTypeId() { return deviceTypeId; } + public String getAppReleaseType() { return appReleaseType; } - public void setDeviceTypeId(int deviceTypeId) { this.deviceTypeId = deviceTypeId; } + public void setAppReleaseType(String appReleaseType) { this.appReleaseType = appReleaseType; } } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/RatingConfiguration.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/RatingConfiguration.java new file mode 100644 index 0000000000..cd117e0b03 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/RatingConfiguration.java @@ -0,0 +1,42 @@ +package org.wso2.carbon.device.application.mgt.common.config;/* Copyright (c) 2019, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +import javax.xml.bind.annotation.XmlElement; + +public class RatingConfiguration { + + private int minRatingValue; + private int maxRatingValue; + + @XmlElement(name = "MinRatingValue") + public int getMinRatingValue() { + return minRatingValue; + } + + public void setMinRatingValue(int minRatingValue) { + this.minRatingValue = minRatingValue; + } + + @XmlElement(name = "MaxRatingValue") + public int getMaxRatingValue() { + return maxRatingValue; + } + + public void setMaxRatingValue(int maxRatingValue) { + this.maxRatingValue = maxRatingValue; + } +} 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 eda97c6aa6..5cca6efd57 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 @@ -83,7 +83,7 @@ public interface ApplicationManager { * @return Applications that matches the given filter criteria. * @throws ApplicationManagementException ApplicationDTO Management Exception */ - ApplicationList getApplications(Filter filter, String deviceTypeName) throws ApplicationManagementException; + ApplicationList getApplications(Filter filter) throws ApplicationManagementException; /** * To get the ApplicationDTO for given Id. diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java index 26ef886ab5..364dd81ac4 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/config/Configuration.java @@ -18,6 +18,7 @@ */ package org.wso2.carbon.device.application.mgt.core.config; +import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration; import org.wso2.carbon.device.application.mgt.common.config.UIConfiguration; import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; @@ -48,6 +49,8 @@ public class Configuration { private String artifactDownloadEndpoint; + private RatingConfiguration ratingConfiguration; + @XmlElement(name = "DatasourceName", required = true) public String getDatasourceName() { return datasourceName; @@ -82,15 +85,21 @@ public class Configuration { this.lifecycleStates = lifecycleStates; } + @XmlElement(name = "UIConfigs") public UIConfiguration getUiConfiguration() { return uiConfiguration; } - @XmlElement(name = "UIConfigs") public void setUiConfiguration(UIConfiguration uiConfiguration) { this.uiConfiguration = uiConfiguration; } + @XmlElement(name = "RatingConfig") + public RatingConfiguration getRatingConfiguration() { return ratingConfiguration; } + + public void setRatingConfiguration( + RatingConfiguration ratingConfiguration) { this.ratingConfiguration = ratingConfiguration; } + @XmlElement(name = "ArtifactDownloadEndpoint", required = true) public String getArtifactDownloadEndpoint() { return artifactDownloadEndpoint; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java index 312b02b8f7..feaa04b72c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java @@ -54,6 +54,11 @@ public interface ApplicationDAO { void addTagMapping (List tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException; + List getAppTags(int appId, int tenantId) throws ApplicationManagementDAOException; + + List getAppCategories (int appId, int tenantId) throws ApplicationManagementDAOException; + + List getAllCategories(int tenantId) throws ApplicationManagementDAOException; @@ -76,11 +81,12 @@ public interface ApplicationDAO { * To get the applications that satisfy the given criteria. * * @param filter Filter criteria. + * @param deviceTypeId ID of the device type * @param tenantId Id of the tenant. * @return ApplicationDTO list * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. */ - ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException; + List getApplications(Filter filter, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException; /** * To get the UUID of latest app release that satisfy the given criteria. 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 79f9c7cc43..8386301900 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 @@ -74,7 +74,7 @@ public class Util { // application.setId(applicationId); // application.setName(rs.getString("APP_NAME")); // application.setType(rs.getString("APP_TYPE")); -// application.setAppCategory(rs.getString("APP_CATEGORY")); +// application.setAppCategories(rs.getString("APP_CATEGORY")); // application.setSubType(rs.getString("SUB_TYPE")); // application.setPaymentCurrency(rs.getString("CURRENCY")); // application.setIsRestricted(rs.getBoolean("RESTRICTED")); @@ -139,25 +139,10 @@ public class Util { application.setStatus(rs.getString("APP_STATUS")); application.setAppRating(rs.getInt("APP_RATING")); application.setDeviceTypeId(rs.getInt("APP_DEVICE_TYPE_ID")); + application.getApplicationReleases().add(loadAppRelease(rs)); } else { - ApplicationReleaseDTO appRelease = new ApplicationReleaseDTO(); - appRelease.setDescription(rs.getString("RELEASE_DESCRIPTION")); - appRelease.setUuid(rs.getString("RELEASE_UUID")); - appRelease.setReleaseType(rs.getString("RELEASE_TYPE")); - appRelease.setVersion(rs.getString("RELEASE_VERSION")); - appRelease.setInstallerName(rs.getString("AP_RELEASE_STORED_LOC")); - appRelease.setBannerName(rs.getString("RELEASE_BANNER_LOC")); - appRelease.setScreenshotName1("RELEASE_SC1"); - appRelease.setScreenshotName2("RELEASE_SC2"); - appRelease.setScreenshotName3("RELEASE_SC3"); - appRelease.setPrice(rs.getDouble(" RELEASE_PRICE")); - appRelease.setMetaData(rs.getString("RELEASE_META_INFO")); - appRelease.setSupportedOsVersions(rs.getString("RELEASE_SUP_OS_VERSIONS")); - appRelease.setRating(rs.getDouble("RELEASE_RATING")); - appRelease.setCurrentState(rs.getString("RELEASE_CURRENT_STATE")); - appRelease.setRatedUsers(rs.getInt("RATED_USER_COUNT")); if (application != null && application.getApplicationReleases() != null) { - application.getApplicationReleases().add(appRelease); + application.getApplicationReleases().add(loadAppRelease(rs)); } } hasNext = rs.next(); @@ -168,6 +153,33 @@ public class Util { return applications; } + /** + * Populates {@link ApplicationReleaseDTO} object with the result obtained from the database. + * + * @param rs {@link ResultSet} from obtained from the database + * @return {@link ApplicationReleaseDTO} object populated with the data + * @throws SQLException If unable to populate {@link ApplicationReleaseDTO} object with the data + */ + public static ApplicationReleaseDTO loadAppRelease(ResultSet rs) throws SQLException { + ApplicationReleaseDTO appRelease = new ApplicationReleaseDTO(); + appRelease.setDescription(rs.getString("RELEASE_DESCRIPTION")); + appRelease.setUuid(rs.getString("RELEASE_UUID")); + appRelease.setReleaseType(rs.getString("RELEASE_TYPE")); + appRelease.setVersion(rs.getString("RELEASE_VERSION")); + appRelease.setInstallerName(rs.getString("AP_RELEASE_STORED_LOC")); + appRelease.setBannerName(rs.getString("AP_RELEASE_BANNER_LOC")); + appRelease.setScreenshotName1("AP_RELEASE_SC1"); + appRelease.setScreenshotName2("AP_RELEASE_SC2"); + appRelease.setScreenshotName3("AP_RELEASE_SC3"); + appRelease.setPrice(rs.getDouble("RELEASE_PRICE")); + appRelease.setMetaData(rs.getString("RELEASE_META_INFO")); + appRelease.setSupportedOsVersions(rs.getString("RELEASE_SUP_OS_VERSIONS")); + appRelease.setRating(rs.getDouble("RELEASE_RATING")); + appRelease.setCurrentState(rs.getString("RELEASE_CURRENT_STATE")); + appRelease.setRatedUsers(rs.getInt("RATED_USER_COUNT")); + return appRelease; + } + /** * To create application object from the result set retrieved from the Database. 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 4d49b4c8be..7d2327f115 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 @@ -18,6 +18,7 @@ */ package org.wso2.carbon.device.application.mgt.core.dao.impl.application; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.json.JSONException; @@ -124,119 +125,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } -// @Override -// public ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException { -// if (log.isDebugEnabled()) { -// log.debug("Getting application data from the database"); -// log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset())); -// } -// int paramIndex = 1; -// Connection conn; -// PreparedStatement stmt = null; -// ResultSet rs = null; -// ApplicationList applicationList = new ApplicationList(); -// Pagination pagination = new Pagination(); -// 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," -// + " 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.TENANT_ID = ?"; -// -// -// if (filter == null) { -// throw new ApplicationManagementDAOException("Filter need to be instantiated"); -// } -// if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { -// sql += " AND AP_APP.TYPE "; -// sql += "= ?"; -// } -// if (filter.getAppCategory() != null && !filter.getAppCategory().isEmpty()) { -// sql += " AND AP_APP.APP_CATEGORY "; -// sql += "= ?"; -// } -// if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { -// sql += " AND LOWER (AP_APP.NAME) "; -// if (filter.isFullMatch()) { -// sql += "= ?"; -// } else { -// sql += "LIKE ?"; -// } -// } -// if (filter.getDeviceTypeName() != null ) { -// sql += " AND AP_APP.DEVICE_TYPE_ID "; -// sql += "= ?"; -// } -// -// String defaultSortOrder = "ASC"; -// if (filter.getSortBy() != null && !filter.getSortBy().isEmpty()) { -// defaultSortOrder = filter.getSortBy(); -// } -// sql += " ORDER BY APP_ID " + defaultSortOrder +" LIMIT ? OFFSET ? "; -// -// pagination.setLimit(filter.getLimit()); -// pagination.setOffset(filter.getOffset()); -// -// try { -// conn = this.getDBConnection(); -// stmt = conn.prepareStatement(sql); -// stmt.setInt(paramIndex++, tenantId); -// -// if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { -// stmt.setString(paramIndex++, filter.getAppType()); -// } -// if (filter.getAppCategory() != null && !filter.getAppCategory().isEmpty()) { -// stmt.setString(paramIndex++, filter.getAppCategory()); -// } -// if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { -// if (filter.isFullMatch()) { -// stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); -// } else { -// stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); -// } -// } -// if (filter.getDeviceTypeName() != null ) { -// stmt.setInt(paramIndex++, filter.getDeviceTypeName().getId()); -// } -// -// -// if (filter.getLimit() == 0) { -// stmt.setInt(paramIndex++, 100); -// } else { -// stmt.setInt(paramIndex++, filter.getLimit()); -// } -// stmt.setInt(paramIndex, filter.getOffset()); -// rs = stmt.executeQuery(); -// applicationList.setApplications(Util.loadApplications(rs)); -// applicationList.setPagination(pagination); -// applicationList.getPagination().setSize(filter.getOffset()); -// applicationList.getPagination().setCount(applicationList.getApplications().size()); -// -// } catch (SQLException e) { -// throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant" -// + " " + tenantId + ". While executing " + sql, e); -// } catch (DBConnectionException e) { -// throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection while " -// + "getting application list for the tenant " + tenantId, -// e); -// } catch (JSONException e) { -// throw new ApplicationManagementDAOException("Error occurred while parsing JSON ", e); -// } finally { -// Util.cleanupResources(stmt, rs); -// } -// return applicationList; -// } - - @Override - public ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException { + public List getApplications(Filter filter,int deviceTypeId, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { log.debug("Getting application data from the database"); log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset())); @@ -245,8 +135,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic Connection conn; PreparedStatement stmt = null; ResultSet rs = null; - ApplicationList applicationList = new ApplicationList(); - Pagination pagination = new Pagination(); String sql = "SELECT " + "AP_APP.ID AS APP_ID, " + "AP_APP.NAME AS APP_NAME, " @@ -281,15 +169,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (filter == null) { throw new ApplicationManagementDAOException("Filter need to be instantiated"); } - if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { - sql += " AND AP_APP.TYPE "; - sql += "= ?"; - } - if (filter.getAppCategory() != null && !filter.getAppCategory().isEmpty()) { - sql += " AND AP_APP.APP_CATEGORY "; - sql += "= ?"; + + if (!StringUtils.isEmpty(filter.getAppType())) { + sql += " AND AP_APP.TYPE = ?"; } - if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { + if (!StringUtils.isEmpty(filter.getAppName())) { sql += " AND LOWER (AP_APP.NAME) "; if (filter.isFullMatch()) { sql += "= ?"; @@ -297,19 +181,30 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic sql += "LIKE ?"; } } - if (filter.getDeviceTypeId() > 0 ) { - sql += " AND AP_APP.DEVICE_TYPE_ID "; - sql += "= ?"; + if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + sql += " AND AP_APP.SUB_TYPE = ?"; } - - String defaultSortOrder = "ASC"; - if (filter.getSortBy() != null && !filter.getSortBy().isEmpty()) { - defaultSortOrder = filter.getSortBy(); + if (filter.getMinimumRating() > 0) { + sql += " AND AP_APP.RATING >= ?"; + } + if (!StringUtils.isEmpty(filter.getVersion())) { + sql += " AND AP_APP_RELEASE.VERSION = ?"; + } + if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + sql += " AND AP_APP_RELEASE.RELEASE_TYPE = ?"; + } + if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?"; + } + if (deviceTypeId > 0) { + sql += " AND AP_APP.DEVICE_TYPE_ID = ?"; } - sql += " ORDER BY APP_ID " + defaultSortOrder +" LIMIT ? OFFSET ? "; - pagination.setLimit(filter.getLimit()); - pagination.setOffset(filter.getOffset()); + String sortingOrder = "ASC"; + if (!StringUtils.isEmpty(filter.getSortBy() )) { + sortingOrder = filter.getSortBy(); + } + sql += " ORDER BY APP_ID " + sortingOrder +" LIMIT ? OFFSET ? "; try { conn = this.getDBConnection(); @@ -319,9 +214,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { stmt.setString(paramIndex++, filter.getAppType()); } - if (filter.getAppCategory() != null && !filter.getAppCategory().isEmpty()) { - stmt.setString(paramIndex++, filter.getAppCategory()); - } if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { if (filter.isFullMatch()) { stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); @@ -329,11 +221,24 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); } } - if (filter.getDeviceTypeId() > 0 ) { - stmt.setInt(paramIndex++, filter.getDeviceTypeId()); + if (!StringUtils.isEmpty(filter.getSubscriptionType())) { + stmt.setString(paramIndex++, filter.getSubscriptionType()); + } + if (filter.getMinimumRating() > 0) { + stmt.setInt(paramIndex++, filter.getMinimumRating()); + } + if (!StringUtils.isEmpty(filter.getVersion())) { + stmt.setString(paramIndex++, filter.getVersion()); + } + if (!StringUtils.isEmpty(filter.getAppReleaseType())) { + stmt.setString(paramIndex++, filter.getAppReleaseType()); + } + if (!StringUtils.isEmpty(filter.getAppReleaseState())) { + stmt.setString(paramIndex++, filter.getAppReleaseState()); + } + if (deviceTypeId > 0 ) { + stmt.setInt(paramIndex++, deviceTypeId); } - - if (filter.getLimit() == 0) { stmt.setInt(paramIndex++, 100); } else { @@ -341,11 +246,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } stmt.setInt(paramIndex, filter.getOffset()); rs = stmt.executeQuery(); - applicationList.setApplications(Util.loadApplications(rs)); - applicationList.setPagination(pagination); - applicationList.getPagination().setSize(filter.getOffset()); - applicationList.getPagination().setCount(applicationList.getApplications().size()); - + return Util.loadApplications(rs); } catch (SQLException e) { throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant" + " " + tenantId + ". While executing " + sql, e); @@ -358,7 +259,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } finally { Util.cleanupResources(stmt, rs); } - return applicationList; } @Override @@ -972,6 +872,70 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } + @Override + public List getAppTags(int appId, int tenantId) throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get tags for given application."); + } + Connection conn; + List tags = new ArrayList<>(); + String sql = "SELECT tag.TAG AS TAG " + + "FROM " + + "AP_APP_TAG tag INNER JOIN AP_APP_TAG_MAPPING tag_map ON tag.ID = tag_map.AP_APP_TAG_ID " + + "INNER JOIN AP_APP app ON tag_map.AP_APP_ID = app.ID " + + "WHERE app.ID = ? and app.TENANT_ID = ?"; + try { + conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)){ + stmt.setInt(1, appId); + stmt.setInt(2, tenantId); + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + tags.add(rs.getString("TAG")); + } + } + } + return tags; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when adding tags", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("Error occurred while adding tags", e); + } + } + + @Override + public List getAppCategories(int appId, int tenantId) throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to get categories for given application."); + } + Connection conn; + List categories = new ArrayList<>(); + String sql = "SELECT CATEGORY " + + "FROM " + + "AP_APP_CATEGORY cat INNER JOIN AP_APP_CATEGORY_MAPPING cat_map ON cat.ID = cat_map.AP_APP_CATEGORY_ID " + + "INNER JOIN AP_APP app ON cat_map.AP_APP_ID = app.ID " + + "WHERE app.ID = ? and app.TENANT_ID = ?"; + try { + conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)){ + stmt.setInt(1, appId); + stmt.setInt(2, tenantId); + try (ResultSet rs = stmt.executeQuery()) { + while (rs.next()) { + categories.add(rs.getString("CATEGORY")); + } + } + } + return categories; + } catch (DBConnectionException e) { + throw new ApplicationManagementDAOException( + "Error occurred while obtaining the DB connection when adding tags", e); + } catch (SQLException e) { + throw new ApplicationManagementDAOException("Error occurred while adding tags", e); + } + } + @Override public void deleteTags(List tags, int applicationId, int tenantId) 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/visibility/GenericVisibilityDAOImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java index dc568a7b82..51360b4a47 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/visibility/GenericVisibilityDAOImpl.java @@ -79,7 +79,9 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil PreparedStatement stmt = null; ResultSet rs = null; List unrestrictedRoles = new ArrayList<>(); - String sql = "SELECT ID, ROLE FROM AP_UNRESTRICTED_ROLE WHERE AP_APP_ID = ? AND TENANT_ID = ?;"; + String sql = "SELECT ROLE " + + "FROM AP_UNRESTRICTED_ROLE " + + "WHERE AP_APP_ID = ? AND TENANT_ID = ?"; try{ conn = this.getDBConnection(); conn.setAutoCommit(false); 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 d2aa18c541..1047c0f6e9 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 @@ -30,6 +30,8 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.AppLifecycleState; import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact; import org.wso2.carbon.device.application.mgt.common.ApplicationInstaller; +import org.wso2.carbon.device.application.mgt.common.Pagination; +import org.wso2.carbon.device.application.mgt.common.config.RatingConfiguration; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; @@ -158,15 +160,15 @@ public class ApplicationManagerImpl implements ApplicationManager { filter.setFullMatch(true); filter.setAppName(applicationDTO.getName().trim()); - filter.setDeviceTypeId(applicationDTO.getDeviceTypeId()); filter.setOffset(0); filter.setLimit(1); ConnectionManagerUtil.beginDBTransaction(); - ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId); - if (!applicationList.getApplications().isEmpty()) { + List applicationList = applicationDAO + .getApplications(filter, applicationDTO.getDeviceTypeId(), tenantId); + if (!applicationList.isEmpty()) { String msg = - "Already an application registered with same name - " + applicationList.getApplications().get(0) + "Already an application registered with same name - " + applicationList.get(0) .getName(); log.error(msg); throw new RequestValidatingException(msg); @@ -411,52 +413,110 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public ApplicationList getApplications(Filter filter, String deviceTypeName) - throws ApplicationManagementException { + public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - ApplicationList applicationList; - List apps; - List releases; - DeviceType deviceType; - - filter = validateFilter(filter); - if (filter == null) { - throw new ApplicationManagementException("Filter validation failed, Please verify the request payload"); - } + ApplicationList applicationList = new ApplicationList(); + List appDTOs; + List applications = new ArrayList<>(); + List filteredApplications = new ArrayList<>(); + DeviceType deviceType = null; try { - if (!StringUtils.isEmpty(deviceTypeName)){ - try { - deviceType = getDeviceTypeData(deviceTypeName); - filter.setDeviceTypeId(deviceType.getId()); - } catch (UnexpectedServerErrorException e){ - throw new ApplicationManagementException(e.getMessage(), e); - } + validateFilter(filter); + + //set default values + if (StringUtils.isEmpty(filter.getSortBy())) { + filter.setSortBy("ASC"); + } + if (filter.getLimit() == 0) { + filter.setLimit(20); + } + String deviceTypename = filter.getDeviceType(); + if (!StringUtils.isEmpty(deviceTypename)) { + deviceType = getDeviceTypeData(deviceTypename); } ConnectionManagerUtil.openDBConnection(); -// todo modify this logic, join app n release tables - applicationList = applicationDAO.getApplications(filter, tenantId); - apps = applicationList.getApplications(); - for ( ApplicationDTO app : apps){ - if (AppLifecycleState.REMOVED.toString().equals(app.getStatus())){ - apps.remove(app); - } + if (deviceType == null) { + appDTOs = applicationDAO.getApplications(filter, 0, tenantId); + } else { + appDTOs = applicationDAO.getApplications(filter, deviceType.getId(), tenantId); } - applicationList.setApplications(apps); - if (applicationList.getApplications() != null && !applicationList - .getApplications().isEmpty()) { - if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { - applicationList = getRoleRestrictedApplicationList(applicationList, userName); + + for (ApplicationDTO app : appDTOs) { + boolean isSearchingApp = true; + List tags = filter.getTags(); + List categories = filter.getAppCategories(); + List unrestrictedRoles = filter.getUnrestrictedRoles(); + + if (lifecycleStateManager.getEndState().equals(app.getStatus())) { + isSearchingApp = false; } - for (ApplicationDTO application : applicationList.getApplications()) { - releases = getReleases(application, filter.getCurrentAppReleaseState()); - application.setApplicationReleases(releases); + if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) { + + if (!isRoleExists(unrestrictedRoles, userName)) { + String msg = "At least one filtering role is not assigned for the user: " + userName + + ". Hence user " + userName + + " Can't filter applications by giving these unrestriced role list"; + log.error(msg); + throw new BadRequestException(msg); + } + List appUnrestrictedRoles = visibilityDAO.getUnrestrictedRoles(app.getId(), tenantId); + boolean isUnrestrictedRoleExistForApp = false; + for (String role : unrestrictedRoles) { + if (appUnrestrictedRoles.contains(role)) { + isUnrestrictedRoleExistForApp = true; + break; + } + } + if (!isUnrestrictedRoleExistForApp) { + isSearchingApp = false; + } + } + if (tags != null && !tags.isEmpty()) { + List appTagList = applicationDAO.getAppTags(app.getId(), tenantId); + boolean isTagExistForApp = false; + for (String tag : tags) { + if (appTagList.contains(tag)) { + isTagExistForApp = true; + break; + } + } + if (!isTagExistForApp) { + isSearchingApp = false; + } + } + if (categories != null && !categories.isEmpty()) { + List appTagList = applicationDAO.getAppCategories(app.getId(), tenantId); + boolean isCategoryExistForApp = false; + for (String category : categories) { + if (appTagList.contains(category)) { + isCategoryExistForApp = true; + break; + } + } + if (!isCategoryExistForApp) { + isSearchingApp = false; + } + } + if (isSearchingApp) { + filteredApplications.add(app); } } + + for(ApplicationDTO appDTO : filteredApplications){ + applications.add(appDtoToAppResponse(appDTO)); + } + applicationList.setApplications(applications); + Pagination pagination = new Pagination(); + applicationList.setPagination(pagination); + applicationList.getPagination().setSize(filter.getOffset()); + applicationList.getPagination().setCount(applicationList.getApplications().size()); return applicationList; - } catch (UserStoreException e) { + } catch (UnexpectedServerErrorException e){ + throw new ApplicationManagementException(e.getMessage(), e); + }catch (UserStoreException e) { throw new ApplicationManagementException( "User-store exception while checking whether the user " + userName + " of tenant " + tenantId + " has the publisher permission", e); @@ -1165,26 +1225,26 @@ public class ApplicationManagerImpl implements ApplicationManager { * @param userName user name * @return ApplicationDTO related with the UUID */ - private ApplicationList getRoleRestrictedApplicationList(ApplicationList applicationList, String userName) - throws ApplicationManagementException { - ApplicationList roleRestrictedApplicationList = new ApplicationList(); - ArrayList unRestrictedApplications = new ArrayList<>(); - for (ApplicationDTO application : applicationList.getApplications()) { - if (application.getUnrestrictedRoles().isEmpty()) { - unRestrictedApplications.add(application); - } else { - try { - if (isRoleExists(application.getUnrestrictedRoles(), userName)) { - unRestrictedApplications.add(application); - } - } catch (UserStoreException e) { - throw new ApplicationManagementException("Role restriction verifying is failed"); - } - } - } - roleRestrictedApplicationList.setApplications(unRestrictedApplications); - return roleRestrictedApplicationList; - } +// private ApplicationList getRoleRestrictedApplicationList(ApplicationList applicationList, String userName) +// throws ApplicationManagementException { +// ApplicationList roleRestrictedApplicationList = new ApplicationList(); +// ArrayList unRestrictedApplications = new ArrayList<>(); +// for (ApplicationDTO application : applicationList.getApplications()) { +// if (application.getUnrestrictedRoles().isEmpty()) { +// unRestrictedApplications.add(application); +// } else { +// try { +// if (isRoleExists(application.getUnrestrictedRoles(), userName)) { +// unRestrictedApplications.add(application); +// } +// } catch (UserStoreException e) { +// throw new ApplicationManagementException("Role restriction verifying is failed"); +// } +// } +// } +// roleRestrictedApplicationList.setApplications(unRestrictedApplications); +// return roleRestrictedApplicationList; +// } /** * To validate a app release creating request and app updating request to make sure all the pre-conditions @@ -1397,20 +1457,55 @@ public class ApplicationManagerImpl implements ApplicationManager { } } - private Filter validateFilter(Filter filter) { - if (filter != null && filter.getAppType() != null) { - boolean isValidRequest = false; + private void validateFilter(Filter filter) throws BadRequestException { + if (filter == null) { + String msg = "Filter validation is failed, Filter shouldn't be null, hence please verify the request payload"; + log.error(msg); + throw new BadRequestException(msg); + } + String appType = filter.getAppType(); + + if (!StringUtils.isEmpty(appType)) { + boolean isValidAppType = false; for (ApplicationType applicationType : ApplicationType.values()) { - if (applicationType.toString().equals(filter.getAppType())) { - isValidRequest = true; + if (applicationType.toString().equals(appType)) { + isValidAppType = true; break; } } - if (!isValidRequest) { - return null; + if (!isValidAppType) { + String msg = + "Filter validation is failed, Invalid application type is found in filter. Application Type: " + + appType + " Please verify the request payload"; + log.error(msg); + throw new BadRequestException(msg); } } - return filter; + + RatingConfiguration ratingConfiguration = ConfigurationManager.getInstance().getConfiguration() + .getRatingConfiguration(); + + int defaultMinRating = ratingConfiguration.getMinRatingValue(); + int defaultMaxRating = ratingConfiguration.getMaxRatingValue(); + int filteringMinRating = filter.getMinimumRating(); + + if (filteringMinRating != 0 && (filteringMinRating < defaultMinRating || filteringMinRating > defaultMaxRating)) + { + String msg = "Filter validation is failed, Minimum rating value: " + filteringMinRating + + " is not in the range of default minimum rating value " + defaultMaxRating + + " and default maximum rating " + defaultMaxRating; + log.error(msg); + throw new BadRequestException(msg); + } + + String appReleaseState = filter.getAppReleaseState(); + if (!StringUtils.isEmpty(appReleaseState) && !lifecycleStateManager.isStateExist(appReleaseState)) { + String msg = "Filter validation is failed, Requesting to filter by invalid app release state: " + + appReleaseState; + log.error(msg); + throw new BadRequestException(msg); + } + } private List getDifference(List list1, Collection list2) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java index 70b82615cf..139e8367ed 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/lifecycle/LifecycleStateManager.java @@ -172,7 +172,7 @@ public class LifecycleStateManager { return initialState; } - public String getEntState() throws LifecycleManagementException { + public String getEndState() throws LifecycleManagementException { String endState = null; for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { if (stringStateEntry.getValue().isEndState()) { @@ -189,6 +189,15 @@ public class LifecycleStateManager { return endState; } + public boolean isStateExist(String currentState) { + for (Map.Entry stringStateEntry : lifecycleStates.entrySet()) { + if (stringStateEntry.getKey().equalsIgnoreCase(currentState)) { + return true; + } + } + return false; + } + public void setLifecycleStates(Map lifecycleStates) { this.lifecycleStates = lifecycleStates; } diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java index 21fc719134..d4cc2f72c7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/util/APIUtil.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.application.mgt.core.util; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; @@ -164,26 +165,29 @@ public class APIUtil { return appmDataHandler; } - public static Filter constructFilter( String appName, String appType, String appCategory, - boolean isFullMatch, String releaseState, int offset, int limit, String sortBy) { - Filter filter = new Filter(); - filter.setOffset(offset); - filter.setLimit(limit); - filter.setSortBy(sortBy); - filter.setFullMatch(isFullMatch); - if (appName != null && !appName.isEmpty()) { - filter.setAppName(appName); - } - if (appType != null && !appType.isEmpty()) { - filter.setAppType(appType); - } - if (appCategory != null && !appCategory.isEmpty()) { - filter.setAppCategory(appCategory); - } - if (releaseState != null && !releaseState.isEmpty()) { - filter.setCurrentAppReleaseState(releaseState); - } - return filter; - } +// public static Filter constructFilter( String appName, String appType, String appCategory, String tags, +// boolean isFullMatch, String releaseState, int offset, int limit, String sortBy) { +// Filter filter = new Filter(); +// filter.setOffset(offset); +// filter.setLimit(limit); +// filter.setSortBy(sortBy); +// filter.setFullMatch(isFullMatch); +// if (!StringUtils.isEmpty(appName)) { +// filter.setAppName(appName); +// } +// if (!StringUtils.isEmpty(appType)) { +// filter.setAppType(appType); +// } +// if (!StringUtils.isEmpty(appCategory)) { +// filter.setAppCategories(appCategory); +// } +// if (!StringUtils.isEmpty(tags)) { +// filter.setAppCategories(appCategory); +// } +// if (!StringUtils.isEmpty(releaseState)) { +// filter.setAppReleaseState(releaseState); +// } +// return filter; +// } } 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 819ac72b71..7808f5ee08 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 @@ -95,7 +95,7 @@ public interface ApplicationManagementAPI { String SCOPE = "scope"; - @GET + @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @ApiOperation( @@ -125,48 +125,12 @@ public interface ApplicationManagementAPI { code = 500, message = "Internal Server Error. \n Error occurred while getting the application list.", response = ErrorResponse.class) - }) - Response getApplications( - @ApiParam( - name = "deviceType", - value = "Supporting device Type of the application") - @QueryParam("device-type") String deviceType, - @ApiParam( - name = "name", - value = "Name of the application") - @QueryParam("name") String appName, - @ApiParam( - name = "type", - value = "Type of the application") - @QueryParam("type") String appType, - @ApiParam( - name = "category", - value = "CategoryDTO of the application") - @QueryParam("category") String appCategory, - @ApiParam( - name = "exact-match", - value = "Is it requesting exactly matching application or partially matching application.") - @QueryParam("exact-match") boolean isFullMatch, - @ApiParam( - name = "release-state", - value = "Current state of the application release") - @QueryParam("release-state") String releaseState, - @ApiParam( - name = "offset", - value = "offset", - defaultValue = "0") - @QueryParam("offset") int offset, - @ApiParam( - name = "limit", - value = "limit", - defaultValue = "20") - @QueryParam("limit") int limit, - @ApiParam( - name = "sort", - value = "Sorting type", - defaultValue = "AES") - @QueryParam("sort") String sortBy - ); + }) Response getApplications( + @ApiParam( + name = "Filter", + value = "Get application filter", + required = true) + @Valid Filter filter); @GET @Path("/{appId}") 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 04c04f144d..196339caf9 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,33 +70,22 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); - @GET + @POST @Override @Consumes("application/json") public Response getApplications( - @QueryParam("device-type") String deviceType, - @QueryParam("name") String appName, - @QueryParam("type") String appType, - @QueryParam("category") String appCategory, - @QueryParam("exact-match") boolean isFullMatch, - @QueryParam("release-state") String releaseState, - @DefaultValue("0") @QueryParam("offset") int offset, - @DefaultValue("20") @QueryParam("limit") int limit, - @DefaultValue("ASC") @QueryParam("sort") String sortBy) { + @Valid Filter filter ){ ApplicationManager applicationManager = APIUtil.getApplicationManager(); try { - Filter filter = APIUtil - .constructFilter(appName, appType, appCategory, isFullMatch, releaseState, offset, - limit, sortBy); - ApplicationList applications = applicationManager.getApplications(filter, deviceType); + ApplicationList applications = applicationManager.getApplications(filter); if (applications.getApplications().isEmpty()) { return Response.status(Response.Status.NOT_FOUND) .entity("Couldn't find any application for the requested query.").build(); } return Response.status(Response.Status.OK).entity(applications).build(); } catch(BadRequestException e){ - String msg = "Couldn't found a device type for " + deviceType; + String msg = "Incompatible request payload is found. Please try with valid reuest payload."; log.error(msg, e); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); }catch (ApplicationManagementException e) { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java index 785e15e442..3a2e11d08f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/ApplicationManagementAPIImpl.java @@ -67,17 +67,17 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { filter.setLimit(limit); filter.setSortBy(sortBy); filter.setFullMatch(isFullMatch); - filter.setCurrentAppReleaseState(AppLifecycleState.PUBLISHED.toString()); + filter.setAppReleaseState(AppLifecycleState.PUBLISHED.toString()); if (appName != null && !appName.isEmpty()) { filter.setAppName(appName); } if (appType != null && !appType.isEmpty()) { filter.setAppType(appType); } - if (appCategory != null && !appCategory.isEmpty()) { - filter.setAppCategory(appCategory); - } - ApplicationList applications = applicationManager.getApplications(filter, null); +// if (appCategory != null && !appCategory.isEmpty()) { +// filter.setAppCategories(appCategory); +// } + ApplicationList applications = applicationManager.getApplications(filter); if (applications.getApplications().isEmpty()) { return Response.status(Response.Status.NOT_FOUND) .entity("Couldn't find any application for requested query.").build(); diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index 214a6e5b46..b2361dc189 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -174,4 +174,9 @@ EMM IoT + + + 1 + 10 +