Fix SQL issues

feature/appm-store/pbac
lasanthaDLPDS 6 years ago
parent 6f020076c5
commit 94d3f1b3b1

@ -40,6 +40,8 @@ public class Filter {
required = false)
private String appType;
private String appCategory;
@ApiModelProperty(
name = "isFullMatch",
value = "Checking the application name matches fully with given name",
@ -111,4 +113,12 @@ public class Filter {
public void setAppType(String appType) {
this.appType = appType;
}
public String getAppCategory() {
return appCategory;
}
public void setAppCategory(String appCategory) {
this.appCategory = appCategory;
}
}

@ -147,11 +147,17 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException("Filter need to be instantiated");
}
if (filter.getAppType() != null) {
if (filter.getAppType() != null && !filter.getAppType().isEmpty()) {
sql += " AND AP_APP.TYPE ";
sql += "= ?";
}
if (filter.getAppName() != null) {
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 += "= ?";
@ -175,10 +181,13 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.setInt(paramIndex++, tenantId);
stmt.setString(paramIndex++, AppLifecycleState.REMOVED.toString());
if (filter.getAppType() != null) {
if (filter.getAppType() != null && !filter.getAppType().isEmpty()) {
stmt.setString(paramIndex++, filter.getAppType());
}
if (filter.getAppName() != null) {
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 {

@ -215,7 +215,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
ConnectionManagerUtil.getDBConnection();
applicationList = applicationDAO.getApplications(filter, tenantId);
if(applicationList != null && applicationList.getApplications() != null && applicationList
.getApplications().size() > 0) {
.getApplications().isEmpty()) {
if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationList = getRoleRestrictedApplicationList(applicationList, userName);
}

@ -39,6 +39,7 @@ import java.util.List;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
@ -125,10 +126,21 @@ public interface ApplicationManagementAPI {
})
Response getApplications(
@ApiParam(
name = "filter",
value = "Filter to get application list",
required = true)
@Valid Filter filter,
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 = "Category 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 = "offset",
value = "offset",
@ -138,11 +150,16 @@ public interface ApplicationManagementAPI {
name = "limit",
value = "limit",
defaultValue = "20")
@QueryParam("limit") int limit
@QueryParam("limit") int limit,
@ApiParam(
name = "sort",
value = "Sorting type",
defaultValue = "AES")
@QueryParam("sort") String sortBy
);
@GET
@Path("/{appType}")
@Path("/{appId}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@ApiOperation(

@ -41,6 +41,7 @@ import java.util.UUID;
import javax.validation.Valid;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
@ -64,14 +65,30 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Override
@Consumes("application/json")
public Response getApplications(
@Valid Filter filter,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
@QueryParam("name") String appName,
@QueryParam("type") String appType,
@QueryParam("category") String appCategory,
@QueryParam("exact-match") boolean isFullMatch,
@DefaultValue("0") @QueryParam("offset") int offset,
@DefaultValue("20") @QueryParam("limit") int limit,
@DefaultValue("ASC") @QueryParam("sort") String sortBy) {
ApplicationManager applicationManager = APIUtil.getApplicationManager();
try {
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);
}
ApplicationList applications = applicationManager.getApplications(filter);
if (applications.getApplications().isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).entity

@ -20,17 +20,18 @@ CREATE TABLE IF NOT EXISTS AP_APP (
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS AP_APP_RELEASE (
ID INT(11) NOT NULL AUTO_INCREMENT,
VERSION VARCHAR(10) NOT NULL,
VERSION VARCHAR(25) NOT NULL,
TENANT_ID VARCHAR(45) NOT NULL,
UUID VARCHAR(200) NOT NULL,
RELEASE_TYPE VARCHAR(45) NOT NULL,
PACKAGE_NAME VARCHAR(45) NOT NULL,
APP_PRICE DECIMAL(6,2) NULL DEFAULT NULL,
STORED_LOCATION VARCHAR(45) NOT NULL,
BANNER_LOCATION VARCHAR(45) NOT NULL,
SC_1_LOCATION VARCHAR(45) NOT NULL,
SC_2_LOCATION VARCHAR(45) NULL DEFAULT NULL,
SC_3_LOCATION VARCHAR(45) NULL DEFAULT NULL,
APP_HASH_VALUE VARCHAR(1000) NOT NULL,
STORED_LOCATION VARCHAR(100) NOT NULL,
BANNER_LOCATION VARCHAR(100) NOT NULL,
SC_1_LOCATION VARCHAR(100) NOT NULL,
SC_2_LOCATION VARCHAR(100) NULL DEFAULT NULL,
SC_3_LOCATION VARCHAR(100) NULL DEFAULT NULL,
APP_HASH_VALUE VARCHAR(100) NOT NULL,
SHARED_WITH_ALL_TENANTS INT(11) NULL DEFAULT NULL,
APP_META_INFO VARCHAR(20000) NULL DEFAULT NULL,
RATING DOUBLE NULL DEFAULT NULL,

@ -32,17 +32,18 @@ CREATE TABLE IF NOT EXISTS `AP_APP` (
-- -----------------------------------------------------
CREATE TABLE IF NOT EXISTS `AP_APP_RELEASE` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`VERSION` VARCHAR(10) NOT NULL,
`VERSION` VARCHAR(25) NOT NULL,
`TENANT_ID` VARCHAR(45) NOT NULL,
`UUID` VARCHAR(200) NOT NULL,
`RELEASE_TYPE` VARCHAR(45) NOT NULL,
`PACKAGE_NAME` VARCHAR(45) NOT NULL,
`APP_PRICE` DECIMAL(6,2) NULL DEFAULT NULL,
`STORED_LOCATION` VARCHAR(45) NOT NULL,
`BANNER_LOCATION` VARCHAR(45) NOT NULL,
`SC_1_LOCATION` VARCHAR(45) NOT NULL,
`SC_2_LOCATION` VARCHAR(45) NULL DEFAULT NULL,
`SC_3_LOCATION` VARCHAR(45) NULL DEFAULT NULL,
`APP_HASH_VALUE` VARCHAR(1000) NOT NULL,
`STORED_LOCATION` VARCHAR(100) NOT NULL,
`BANNER_LOCATION` VARCHAR(100) NOT NULL,
`SC_1_LOCATION` VARCHAR(100) NOT NULL,
`SC_2_LOCATION` VARCHAR(100) NULL DEFAULT NULL,
`SC_3_LOCATION` VARCHAR(100) NULL DEFAULT NULL,
`APP_HASH_VALUE` VARCHAR(100) NOT NULL,
`SHARED_WITH_ALL_TENANTS` INT(11) NULL DEFAULT NULL,
`APP_META_INFO` VARCHAR(20000) NULL DEFAULT NULL,
`RATING` DOUBLE NULL DEFAULT NULL,

Loading…
Cancel
Save