Add API for getting applications

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent e467453fd3
commit e747c0bdb0

@ -19,6 +19,7 @@
package org.wso2.carbon.device.application.mgt.common; 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.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.response.Application;
import java.util.List; import java.util.List;
@ -27,15 +28,15 @@ import java.util.List;
*/ */
public class ApplicationList { public class ApplicationList {
private List<ApplicationDTO> applications; private List<Application> applications;
private Pagination pagination; private Pagination pagination;
public List<ApplicationDTO> getApplications() { public List<Application> getApplications() {
return applications; return applications;
} }
public void setApplications(List<ApplicationDTO> applications) { public void setApplications(List<Application> applications) {
this.applications = applications; this.applications = applications;
} }

@ -18,25 +18,68 @@
*/ */
package org.wso2.carbon.device.application.mgt.common; package org.wso2.carbon.device.application.mgt.common;
import java.util.List;
/** /**
* Filter represents a criteria that can be used for searching applications. * Filter represents a criteria that can be used for searching applications.
*/ */
public class Filter { 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; private String appName;
/** /***
* Type of the application * Type of the application.
* e.g :- ENTERPRISE, PUBLIC
*/ */
private String appType; 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<String> appCategories;
/** /**
* Category of the application * Tag list of the application
*/
private List<String> 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<String> unrestrictedRoles;
/** /**
* Checking the application name matches fully with given name * Checking the application name matches fully with given name
@ -59,14 +102,10 @@ public class Filter {
private String sortBy; 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; private String appReleaseState;
/***
* Supported device type for the application. i.e Android, iOS, Windows etc
*/
private int deviceTypeId;
public int getLimit() { public int getLimit() {
return limit; return limit;
@ -116,21 +155,43 @@ public class Filter {
this.appType = appType; this.appType = appType;
} }
public String getAppCategory() { public List<String> getAppCategories() {
return appCategory; return appCategories;
} }
public void setAppCategory(String appCategory) { public void setAppCategories(List<String> appCategories) {
this.appCategory = appCategory; this.appCategories = appCategories;
} }
public String getCurrentAppReleaseState() { return currentAppReleaseState; } public List<String> getTags() { return tags; }
public void setCurrentAppReleaseState(String currentAppReleaseState) { public void setTags(List<String> tags) { this.tags = tags; }
this.currentAppReleaseState = currentAppReleaseState;
} public List<String> getUnrestrictedRoles() { return unrestrictedRoles; }
public void setUnrestrictedRoles(List<String> 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; }
} }

@ -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;
}
}

@ -83,7 +83,7 @@ public interface ApplicationManager {
* @return Applications that matches the given filter criteria. * @return Applications that matches the given filter criteria.
* @throws ApplicationManagementException ApplicationDTO Management Exception * @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. * To get the ApplicationDTO for given Id.

@ -18,6 +18,7 @@
*/ */
package org.wso2.carbon.device.application.mgt.core.config; 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.common.config.UIConfiguration;
import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState; import org.wso2.carbon.device.application.mgt.core.lifecycle.config.LifecycleState;
@ -48,6 +49,8 @@ public class Configuration {
private String artifactDownloadEndpoint; private String artifactDownloadEndpoint;
private RatingConfiguration ratingConfiguration;
@XmlElement(name = "DatasourceName", required = true) @XmlElement(name = "DatasourceName", required = true)
public String getDatasourceName() { public String getDatasourceName() {
return datasourceName; return datasourceName;
@ -82,15 +85,21 @@ public class Configuration {
this.lifecycleStates = lifecycleStates; this.lifecycleStates = lifecycleStates;
} }
@XmlElement(name = "UIConfigs")
public UIConfiguration getUiConfiguration() { public UIConfiguration getUiConfiguration() {
return uiConfiguration; return uiConfiguration;
} }
@XmlElement(name = "UIConfigs")
public void setUiConfiguration(UIConfiguration uiConfiguration) { public void setUiConfiguration(UIConfiguration uiConfiguration) {
this.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) @XmlElement(name = "ArtifactDownloadEndpoint", required = true)
public String getArtifactDownloadEndpoint() { public String getArtifactDownloadEndpoint() {
return artifactDownloadEndpoint; return artifactDownloadEndpoint;

@ -54,6 +54,11 @@ public interface ApplicationDAO {
void addTagMapping (List<Integer> tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException; void addTagMapping (List<Integer> tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException;
List<String> getAppTags(int appId, int tenantId) throws ApplicationManagementDAOException;
List<String> getAppCategories (int appId, int tenantId) throws ApplicationManagementDAOException;
List<CategoryDTO> getAllCategories(int tenantId) throws ApplicationManagementDAOException; List<CategoryDTO> getAllCategories(int tenantId) throws ApplicationManagementDAOException;
@ -76,11 +81,12 @@ public interface ApplicationDAO {
* To get the applications that satisfy the given criteria. * To get the applications that satisfy the given criteria.
* *
* @param filter Filter criteria. * @param filter Filter criteria.
* @param deviceTypeId ID of the device type
* @param tenantId Id of the tenant. * @param tenantId Id of the tenant.
* @return ApplicationDTO list * @return ApplicationDTO list
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/ */
ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException; List<ApplicationDTO> getApplications(Filter filter, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException;
/** /**
* To get the UUID of latest app release that satisfy the given criteria. * To get the UUID of latest app release that satisfy the given criteria.

@ -74,7 +74,7 @@ public class Util {
// application.setId(applicationId); // application.setId(applicationId);
// application.setName(rs.getString("APP_NAME")); // application.setName(rs.getString("APP_NAME"));
// application.setType(rs.getString("APP_TYPE")); // 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.setSubType(rs.getString("SUB_TYPE"));
// application.setPaymentCurrency(rs.getString("CURRENCY")); // application.setPaymentCurrency(rs.getString("CURRENCY"));
// application.setIsRestricted(rs.getBoolean("RESTRICTED")); // application.setIsRestricted(rs.getBoolean("RESTRICTED"));
@ -139,33 +139,45 @@ public class Util {
application.setStatus(rs.getString("APP_STATUS")); application.setStatus(rs.getString("APP_STATUS"));
application.setAppRating(rs.getInt("APP_RATING")); application.setAppRating(rs.getInt("APP_RATING"));
application.setDeviceTypeId(rs.getInt("APP_DEVICE_TYPE_ID")); application.setDeviceTypeId(rs.getInt("APP_DEVICE_TYPE_ID"));
application.getApplicationReleases().add(loadAppRelease(rs));
} else { } else {
if (application != null && application.getApplicationReleases() != null) {
application.getApplicationReleases().add(loadAppRelease(rs));
}
}
hasNext = rs.next();
if (!hasNext) {
applications.add(application);
}
}
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(); ApplicationReleaseDTO appRelease = new ApplicationReleaseDTO();
appRelease.setDescription(rs.getString("RELEASE_DESCRIPTION")); appRelease.setDescription(rs.getString("RELEASE_DESCRIPTION"));
appRelease.setUuid(rs.getString("RELEASE_UUID")); appRelease.setUuid(rs.getString("RELEASE_UUID"));
appRelease.setReleaseType(rs.getString("RELEASE_TYPE")); appRelease.setReleaseType(rs.getString("RELEASE_TYPE"));
appRelease.setVersion(rs.getString("RELEASE_VERSION")); appRelease.setVersion(rs.getString("RELEASE_VERSION"));
appRelease.setInstallerName(rs.getString("AP_RELEASE_STORED_LOC")); appRelease.setInstallerName(rs.getString("AP_RELEASE_STORED_LOC"));
appRelease.setBannerName(rs.getString("RELEASE_BANNER_LOC")); appRelease.setBannerName(rs.getString("AP_RELEASE_BANNER_LOC"));
appRelease.setScreenshotName1("RELEASE_SC1"); appRelease.setScreenshotName1("AP_RELEASE_SC1");
appRelease.setScreenshotName2("RELEASE_SC2"); appRelease.setScreenshotName2("AP_RELEASE_SC2");
appRelease.setScreenshotName3("RELEASE_SC3"); appRelease.setScreenshotName3("AP_RELEASE_SC3");
appRelease.setPrice(rs.getDouble("RELEASE_PRICE")); appRelease.setPrice(rs.getDouble("RELEASE_PRICE"));
appRelease.setMetaData(rs.getString("RELEASE_META_INFO")); appRelease.setMetaData(rs.getString("RELEASE_META_INFO"));
appRelease.setSupportedOsVersions(rs.getString("RELEASE_SUP_OS_VERSIONS")); appRelease.setSupportedOsVersions(rs.getString("RELEASE_SUP_OS_VERSIONS"));
appRelease.setRating(rs.getDouble("RELEASE_RATING")); appRelease.setRating(rs.getDouble("RELEASE_RATING"));
appRelease.setCurrentState(rs.getString("RELEASE_CURRENT_STATE")); appRelease.setCurrentState(rs.getString("RELEASE_CURRENT_STATE"));
appRelease.setRatedUsers(rs.getInt("RATED_USER_COUNT")); appRelease.setRatedUsers(rs.getInt("RATED_USER_COUNT"));
if (application != null && application.getApplicationReleases() != null) { return appRelease;
application.getApplicationReleases().add(appRelease);
}
}
hasNext = rs.next();
if (!hasNext) {
applications.add(application);
}
}
return applications;
} }

@ -18,6 +18,7 @@
*/ */
package org.wso2.carbon.device.application.mgt.core.dao.impl.application; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.json.JSONException; 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 @Override
public ApplicationList getApplications(Filter filter, int tenantId) throws ApplicationManagementDAOException { public List<ApplicationDTO> getApplications(Filter filter,int deviceTypeId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application data from the database"); log.debug("Getting application data from the database");
log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset())); 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; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
ApplicationList applicationList = new ApplicationList();
Pagination pagination = new Pagination();
String sql = "SELECT " String sql = "SELECT "
+ "AP_APP.ID AS APP_ID, " + "AP_APP.ID AS APP_ID, "
+ "AP_APP.NAME AS APP_NAME, " + "AP_APP.NAME AS APP_NAME, "
@ -281,15 +169,11 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (filter == null) { if (filter == null) {
throw new ApplicationManagementDAOException("Filter need to be instantiated"); throw new ApplicationManagementDAOException("Filter need to be instantiated");
} }
if (filter.getAppType() != null && !filter.getAppType().isEmpty()) {
sql += " AND AP_APP.TYPE "; if (!StringUtils.isEmpty(filter.getAppType())) {
sql += "= ?"; sql += " AND AP_APP.TYPE = ?";
}
if (filter.getAppCategory() != null && !filter.getAppCategory().isEmpty()) {
sql += " AND AP_APP.APP_CATEGORY ";
sql += "= ?";
} }
if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { if (!StringUtils.isEmpty(filter.getAppName())) {
sql += " AND LOWER (AP_APP.NAME) "; sql += " AND LOWER (AP_APP.NAME) ";
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
sql += "= ?"; sql += "= ?";
@ -297,19 +181,30 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
sql += "LIKE ?"; sql += "LIKE ?";
} }
} }
if (filter.getDeviceTypeId() > 0 ) { if (!StringUtils.isEmpty(filter.getSubscriptionType())) {
sql += " AND AP_APP.DEVICE_TYPE_ID "; sql += " AND AP_APP.SUB_TYPE = ?";
sql += "= ?";
} }
if (filter.getMinimumRating() > 0) {
String defaultSortOrder = "ASC"; sql += " AND AP_APP.RATING >= ?";
if (filter.getSortBy() != null && !filter.getSortBy().isEmpty()) { }
defaultSortOrder = filter.getSortBy(); 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()); String sortingOrder = "ASC";
pagination.setOffset(filter.getOffset()); if (!StringUtils.isEmpty(filter.getSortBy() )) {
sortingOrder = filter.getSortBy();
}
sql += " ORDER BY APP_ID " + sortingOrder +" LIMIT ? OFFSET ? ";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
@ -319,9 +214,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { if (filter.getAppType() != null && !filter.getAppType().isEmpty()) {
stmt.setString(paramIndex++, filter.getAppType()); 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.getAppName() != null && !filter.getAppName().isEmpty()) {
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); stmt.setString(paramIndex++, filter.getAppName().toLowerCase());
@ -329,11 +221,24 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%");
} }
} }
if (filter.getDeviceTypeId() > 0 ) { if (!StringUtils.isEmpty(filter.getSubscriptionType())) {
stmt.setInt(paramIndex++, filter.getDeviceTypeId()); 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) { if (filter.getLimit() == 0) {
stmt.setInt(paramIndex++, 100); stmt.setInt(paramIndex++, 100);
} else { } else {
@ -341,11 +246,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
stmt.setInt(paramIndex, filter.getOffset()); stmt.setInt(paramIndex, filter.getOffset());
rs = stmt.executeQuery(); rs = stmt.executeQuery();
applicationList.setApplications(Util.loadApplications(rs)); return Util.loadApplications(rs);
applicationList.setPagination(pagination);
applicationList.getPagination().setSize(filter.getOffset());
applicationList.getPagination().setCount(applicationList.getApplications().size());
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant" throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant"
+ " " + tenantId + ". While executing " + sql, e); + " " + tenantId + ". While executing " + sql, e);
@ -358,7 +259,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} finally { } finally {
Util.cleanupResources(stmt, rs); Util.cleanupResources(stmt, rs);
} }
return applicationList;
} }
@Override @Override
@ -972,6 +872,70 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
} }
@Override
public List<String> 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<String> 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<String> 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<String> 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 @Override
public void deleteTags(List<String> tags, int applicationId, int tenantId) throws ApplicationManagementDAOException { public void deleteTags(List<String> tags, int applicationId, int tenantId) throws ApplicationManagementDAOException {

@ -79,7 +79,9 @@ public class GenericVisibilityDAOImpl extends AbstractDAOImpl implements Visibil
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
List<String> unrestrictedRoles = new ArrayList<>(); List<String> 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{ try{
conn = this.getDBConnection(); conn = this.getDBConnection();
conn.setAutoCommit(false); conn.setAutoCommit(false);

@ -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.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact; 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.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.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.ApplicationList;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
@ -158,15 +160,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
filter.setFullMatch(true); filter.setFullMatch(true);
filter.setAppName(applicationDTO.getName().trim()); filter.setAppName(applicationDTO.getName().trim());
filter.setDeviceTypeId(applicationDTO.getDeviceTypeId());
filter.setOffset(0); filter.setOffset(0);
filter.setLimit(1); filter.setLimit(1);
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationList applicationList = applicationDAO.getApplications(filter, tenantId); List<ApplicationDTO> applicationList = applicationDAO
if (!applicationList.getApplications().isEmpty()) { .getApplications(filter, applicationDTO.getDeviceTypeId(), tenantId);
if (!applicationList.isEmpty()) {
String msg = String msg =
"Already an application registered with same name - " + applicationList.getApplications().get(0) "Already an application registered with same name - " + applicationList.get(0)
.getName(); .getName();
log.error(msg); log.error(msg);
throw new RequestValidatingException(msg); throw new RequestValidatingException(msg);
@ -411,51 +413,109 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public ApplicationList getApplications(Filter filter, String deviceTypeName) public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ApplicationList applicationList; ApplicationList applicationList = new ApplicationList();
List<ApplicationDTO> apps; List<ApplicationDTO> appDTOs;
List<ApplicationReleaseDTO> releases; List<Application> applications = new ArrayList<>();
DeviceType deviceType; List<ApplicationDTO> filteredApplications = new ArrayList<>();
DeviceType deviceType = null;
filter = validateFilter(filter);
if (filter == null) {
throw new ApplicationManagementException("Filter validation failed, Please verify the request payload");
}
try {
if (!StringUtils.isEmpty(deviceTypeName)){
try { try {
deviceType = getDeviceTypeData(deviceTypeName); validateFilter(filter);
filter.setDeviceTypeId(deviceType.getId());
} catch (UnexpectedServerErrorException e){ //set default values
throw new ApplicationManagementException(e.getMessage(), e); 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(); ConnectionManagerUtil.openDBConnection();
// todo modify this logic, join app n release tables if (deviceType == null) {
applicationList = applicationDAO.getApplications(filter, tenantId); appDTOs = applicationDAO.getApplications(filter, 0, tenantId);
apps = applicationList.getApplications(); } else {
for ( ApplicationDTO app : apps){ appDTOs = applicationDAO.getApplications(filter, deviceType.getId(), tenantId);
if (AppLifecycleState.REMOVED.toString().equals(app.getStatus())){
apps.remove(app);
} }
for (ApplicationDTO app : appDTOs) {
boolean isSearchingApp = true;
List<String> tags = filter.getTags();
List<String> categories = filter.getAppCategories();
List<String> unrestrictedRoles = filter.getUnrestrictedRoles();
if (lifecycleStateManager.getEndState().equals(app.getStatus())) {
isSearchingApp = false;
} }
applicationList.setApplications(apps); if (unrestrictedRoles != null && !unrestrictedRoles.isEmpty()) {
if (applicationList.getApplications() != null && !applicationList
.getApplications().isEmpty()) { if (!isRoleExists(unrestrictedRoles, userName)) {
if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { String msg = "At least one filtering role is not assigned for the user: " + userName
applicationList = getRoleRestrictedApplicationList(applicationList, userName); + ". Hence user " + userName
+ " Can't filter applications by giving these unrestriced role list";
log.error(msg);
throw new BadRequestException(msg);
}
List<String> appUnrestrictedRoles = visibilityDAO.getUnrestrictedRoles(app.getId(), tenantId);
boolean isUnrestrictedRoleExistForApp = false;
for (String role : unrestrictedRoles) {
if (appUnrestrictedRoles.contains(role)) {
isUnrestrictedRoleExistForApp = true;
break;
} }
for (ApplicationDTO application : applicationList.getApplications()) {
releases = getReleases(application, filter.getCurrentAppReleaseState());
application.setApplicationReleases(releases);
} }
if (!isUnrestrictedRoleExistForApp) {
isSearchingApp = false;
} }
}
if (tags != null && !tags.isEmpty()) {
List<String> 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<String> 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; return applicationList;
} catch (UnexpectedServerErrorException e){
throw new ApplicationManagementException(e.getMessage(), e);
}catch (UserStoreException e) { }catch (UserStoreException e) {
throw new ApplicationManagementException( throw new ApplicationManagementException(
"User-store exception while checking whether the user " + userName + " of tenant " + tenantId "User-store exception while checking whether the user " + userName + " of tenant " + tenantId
@ -1165,26 +1225,26 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @param userName user name * @param userName user name
* @return ApplicationDTO related with the UUID * @return ApplicationDTO related with the UUID
*/ */
private ApplicationList getRoleRestrictedApplicationList(ApplicationList applicationList, String userName) // private ApplicationList getRoleRestrictedApplicationList(ApplicationList applicationList, String userName)
throws ApplicationManagementException { // throws ApplicationManagementException {
ApplicationList roleRestrictedApplicationList = new ApplicationList(); // ApplicationList roleRestrictedApplicationList = new ApplicationList();
ArrayList<ApplicationDTO> unRestrictedApplications = new ArrayList<>(); // ArrayList<ApplicationDTO> unRestrictedApplications = new ArrayList<>();
for (ApplicationDTO application : applicationList.getApplications()) { // for (ApplicationDTO application : applicationList.getApplications()) {
if (application.getUnrestrictedRoles().isEmpty()) { // if (application.getUnrestrictedRoles().isEmpty()) {
unRestrictedApplications.add(application); // unRestrictedApplications.add(application);
} else { // } else {
try { // try {
if (isRoleExists(application.getUnrestrictedRoles(), userName)) { // if (isRoleExists(application.getUnrestrictedRoles(), userName)) {
unRestrictedApplications.add(application); // unRestrictedApplications.add(application);
} // }
} catch (UserStoreException e) { // } catch (UserStoreException e) {
throw new ApplicationManagementException("Role restriction verifying is failed"); // throw new ApplicationManagementException("Role restriction verifying is failed");
} // }
} // }
} // }
roleRestrictedApplicationList.setApplications(unRestrictedApplications); // roleRestrictedApplicationList.setApplications(unRestrictedApplications);
return roleRestrictedApplicationList; // return roleRestrictedApplicationList;
} // }
/** /**
* To validate a app release creating request and app updating request to make sure all the pre-conditions * 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) { private void validateFilter(Filter filter) throws BadRequestException {
if (filter != null && filter.getAppType() != null) { if (filter == null) {
boolean isValidRequest = false; 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()) { for (ApplicationType applicationType : ApplicationType.values()) {
if (applicationType.toString().equals(filter.getAppType())) { if (applicationType.toString().equals(appType)) {
isValidRequest = true; isValidAppType = true;
break; break;
} }
} }
if (!isValidRequest) { if (!isValidAppType) {
return null; 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 <T> List<T> getDifference(List<T> list1, Collection<T> list2) { private <T> List<T> getDifference(List<T> list1, Collection<T> list2) {

@ -172,7 +172,7 @@ public class LifecycleStateManager {
return initialState; return initialState;
} }
public String getEntState() throws LifecycleManagementException { public String getEndState() throws LifecycleManagementException {
String endState = null; String endState = null;
for (Map.Entry<String, State> stringStateEntry : lifecycleStates.entrySet()) { for (Map.Entry<String, State> stringStateEntry : lifecycleStates.entrySet()) {
if (stringStateEntry.getValue().isEndState()) { if (stringStateEntry.getValue().isEndState()) {
@ -189,6 +189,15 @@ public class LifecycleStateManager {
return endState; return endState;
} }
public boolean isStateExist(String currentState) {
for (Map.Entry<String, State> stringStateEntry : lifecycleStates.entrySet()) {
if (stringStateEntry.getKey().equalsIgnoreCase(currentState)) {
return true;
}
}
return false;
}
public void setLifecycleStates(Map<String, State> lifecycleStates) { public void setLifecycleStates(Map<String, State> lifecycleStates) {
this.lifecycleStates = lifecycleStates; this.lifecycleStates = lifecycleStates;
} }

@ -18,6 +18,7 @@
package org.wso2.carbon.device.application.mgt.core.util; 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.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -164,26 +165,29 @@ public class APIUtil {
return appmDataHandler; return appmDataHandler;
} }
public static Filter constructFilter( String appName, String appType, String appCategory, // public static Filter constructFilter( String appName, String appType, String appCategory, String tags,
boolean isFullMatch, String releaseState, int offset, int limit, String sortBy) { // boolean isFullMatch, String releaseState, int offset, int limit, String sortBy) {
Filter filter = new Filter(); // Filter filter = new Filter();
filter.setOffset(offset); // filter.setOffset(offset);
filter.setLimit(limit); // filter.setLimit(limit);
filter.setSortBy(sortBy); // filter.setSortBy(sortBy);
filter.setFullMatch(isFullMatch); // filter.setFullMatch(isFullMatch);
if (appName != null && !appName.isEmpty()) { // if (!StringUtils.isEmpty(appName)) {
filter.setAppName(appName); // filter.setAppName(appName);
} // }
if (appType != null && !appType.isEmpty()) { // if (!StringUtils.isEmpty(appType)) {
filter.setAppType(appType); // filter.setAppType(appType);
} // }
if (appCategory != null && !appCategory.isEmpty()) { // if (!StringUtils.isEmpty(appCategory)) {
filter.setAppCategory(appCategory); // filter.setAppCategories(appCategory);
} // }
if (releaseState != null && !releaseState.isEmpty()) { // if (!StringUtils.isEmpty(tags)) {
filter.setCurrentAppReleaseState(releaseState); // filter.setAppCategories(appCategory);
} // }
return filter; // if (!StringUtils.isEmpty(releaseState)) {
} // filter.setAppReleaseState(releaseState);
// }
// return filter;
// }
} }

@ -95,7 +95,7 @@ public interface ApplicationManagementAPI {
String SCOPE = "scope"; String SCOPE = "scope";
@GET @POST
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
@ -125,48 +125,12 @@ public interface ApplicationManagementAPI {
code = 500, code = 500,
message = "Internal Server Error. \n Error occurred while getting the application list.", message = "Internal Server Error. \n Error occurred while getting the application list.",
response = ErrorResponse.class) response = ErrorResponse.class)
}) }) Response getApplications(
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( @ApiParam(
name = "exact-match", name = "Filter",
value = "Is it requesting exactly matching application or partially matching application.") value = "Get application filter",
@QueryParam("exact-match") boolean isFullMatch, required = true)
@ApiParam( @Valid Filter filter);
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
);
@GET @GET
@Path("/{appId}") @Path("/{appId}")

@ -70,33 +70,22 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class); private static Log log = LogFactory.getLog(ApplicationManagementAPIImpl.class);
@GET @POST
@Override @Override
@Consumes("application/json") @Consumes("application/json")
public Response getApplications( public Response getApplications(
@QueryParam("device-type") String deviceType, @Valid Filter filter ){
@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) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
Filter filter = APIUtil ApplicationList applications = applicationManager.getApplications(filter);
.constructFilter(appName, appType, appCategory, isFullMatch, releaseState, offset,
limit, sortBy);
ApplicationList applications = applicationManager.getApplications(filter, deviceType);
if (applications.getApplications().isEmpty()) { if (applications.getApplications().isEmpty()) {
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND)
.entity("Couldn't find any application for the requested query.").build(); .entity("Couldn't find any application for the requested query.").build();
} }
return Response.status(Response.Status.OK).entity(applications).build(); return Response.status(Response.Status.OK).entity(applications).build();
} catch(BadRequestException e){ } 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); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}catch (ApplicationManagementException e) { }catch (ApplicationManagementException e) {

@ -67,17 +67,17 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
filter.setLimit(limit); filter.setLimit(limit);
filter.setSortBy(sortBy); filter.setSortBy(sortBy);
filter.setFullMatch(isFullMatch); filter.setFullMatch(isFullMatch);
filter.setCurrentAppReleaseState(AppLifecycleState.PUBLISHED.toString()); filter.setAppReleaseState(AppLifecycleState.PUBLISHED.toString());
if (appName != null && !appName.isEmpty()) { if (appName != null && !appName.isEmpty()) {
filter.setAppName(appName); filter.setAppName(appName);
} }
if (appType != null && !appType.isEmpty()) { if (appType != null && !appType.isEmpty()) {
filter.setAppType(appType); filter.setAppType(appType);
} }
if (appCategory != null && !appCategory.isEmpty()) { // if (appCategory != null && !appCategory.isEmpty()) {
filter.setAppCategory(appCategory); // filter.setAppCategories(appCategory);
} // }
ApplicationList applications = applicationManager.getApplications(filter, null); ApplicationList applications = applicationManager.getApplications(filter);
if (applications.getApplications().isEmpty()) { if (applications.getApplications().isEmpty()) {
return Response.status(Response.Status.NOT_FOUND) return Response.status(Response.Status.NOT_FOUND)
.entity("Couldn't find any application for requested query.").build(); .entity("Couldn't find any application for requested query.").build();

@ -174,4 +174,9 @@
<Category>EMM</Category> <Category>EMM</Category>
<Category>IoT</Category> <Category>IoT</Category>
</AppCategories> </AppCategories>
<RatingConfig>
<MinRatingValue>1</MinRatingValue>
<MaxRatingValue>10</MaxRatingValue>
</RatingConfig>
</ApplicationManagementConfiguration> </ApplicationManagementConfiguration>

Loading…
Cancel
Save