Merge branch 'application-mgt-new' into 'application-mgt-new'

Fix SQL issues

See merge request entgra/carbon-device-mgt!15
4.x.x
Madawa Soysa 6 years ago
commit 36cb2f615a

@ -18,52 +18,51 @@
*/ */
package org.wso2.carbon.device.application.mgt.common; package org.wso2.carbon.device.application.mgt.common;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
/** /**
* Filter represents a criteria that can be used for searching applications. * Filter represents a criteria that can be used for searching applications.
*/ */
@ApiModel(value = "Filter", description = "This is related to the application filtering.")
public class Filter { public class Filter {
@ApiModelProperty( /**
name = "appName", * Name of the application
value = "Name of the application", */
required = false)
private String appName; private String appName;
@ApiModelProperty( /**
name = "appType", * Type of the application
value = "Type of the application", */
required = false)
private String appType; private String appType;
@ApiModelProperty( /**
name = "isFullMatch", * Category of the application
value = "Checking the application name matches fully with given name", */
required = false) private String appCategory;
/**
* Checking the application name matches fully with given name
*/
private boolean isFullMatch; private boolean isFullMatch;
@ApiModelProperty( /**
name = "limit", * Limit of the applications
value = "Limit of the applications", */
required = false)
private int limit; private int limit;
@ApiModelProperty( /**
name = "offset", * Started from
value = "Started from", */
required = false)
private int offset; private int offset;
@ApiModelProperty( /**
name = "sortBy", * Ascending or descending order
value = "Ascending or descending order", */
required = false)
private String sortBy; private String sortBy;
/**
* Set as True if required to have only published application release, otherwise set to False
*/
private boolean requirePublishedRelease;
public int getLimit() { public int getLimit() {
return limit; return limit;
} }
@ -111,4 +110,20 @@ public class Filter {
public void setAppType(String appType) { public void setAppType(String appType) {
this.appType = appType; this.appType = appType;
} }
public String getAppCategory() {
return appCategory;
}
public void setAppCategory(String appCategory) {
this.appCategory = appCategory;
}
public boolean isRequirePublishedRelease() {
return requirePublishedRelease;
}
public void setRequirePublishedRelease(boolean requirePublishedRelease) {
this.requirePublishedRelease = requirePublishedRelease;
}
} }

@ -90,10 +90,11 @@ public interface ApplicationManager {
* To get Application with the given Id. * To get Application with the given Id.
* *
* @param id id of the Application * @param id id of the Application
* @param requirePublishedReleases If it is required to have only published application release set to True, otherwise set to false
* @return the Application identified by the UUID * @return the Application identified by the UUID
* @throws ApplicationManagementException Application Management Exception. * @throws ApplicationManagementException Application Management Exception.
*/ */
Application getApplicationById(int id) throws ApplicationManagementException; Application getApplicationById(int id, boolean requirePublishedReleases) throws ApplicationManagementException;
/** /**
* To get an application associated with the release. * To get an application associated with the release.
@ -121,14 +122,15 @@ public interface ApplicationManager {
*/ */
Boolean isUserAllowable(List<UnrestrictedRole> unrestrictedRoles, String userName) throws ApplicationManagementException; Boolean isUserAllowable(List<UnrestrictedRole> unrestrictedRoles, String userName) throws ApplicationManagementException;
/** // todo
* To get all the releases of a particular Application. // /**
* // * To get all the releases of a particular Application.
* @param applicationId ID of the Application to get all the releases. // *
* @return the List of the Application releases related with the particular Application. // * @param applicationId ID of the Application to get all the releases.
* @throws ApplicationManagementException Application Management Exception. // * @return the List of the Application releases related with the particular Application.
*/ // * @throws ApplicationManagementException Application Management Exception.
List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException; // */
// List<ApplicationRelease> getinstallableReleases(int applicationId) throws ApplicationManagementException;
/** /**
* To get all the releases of a particular Application. * To get all the releases of a particular Application.

@ -58,13 +58,12 @@ public interface ApplicationReleaseDAO {
/** /**
* To get all the releases of a particular application. * To get all the releases of a particular application.
* *
* @param applicationName Name of the Application * @param applicationId Id of the Application
* @param applicationType Type of the Application
* @param tenantId tenant id of the application * @param tenantId tenant id of the application
* @return list of the application releases * @return list of the application releases
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
List<ApplicationRelease> getReleases(String applicationName, String applicationType, int tenantId) throws List<ApplicationRelease> getReleases(int applicationId, int tenantId) throws
ApplicationManagementDAOException; ApplicationManagementDAOException;
/** /**

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

@ -118,7 +118,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS " String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS "
+ "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS " + "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS "
+ "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, "
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS "
@ -169,7 +169,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE," String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE,"
+ " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, " + " AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, "
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " + + "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS " +
"HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR" + "HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO, AR.CREATED_BY, AR.CREATED_AT, AR" +
@ -208,33 +208,29 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
/** /**
* To insert the application release properties. * To insert the application release properties.
* *
* @param applicationName Name of the application. * @param applicationId Id of the application.
* @param applicationType Type of the application.
* @param tenantId Tenant Id * @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @throws ApplicationManagementDAOException Application Management DAO Exception.
*/ */
@Override @Override
public List<ApplicationRelease> getReleases(String applicationName, String applicationType, int tenantId) public List<ApplicationRelease> getReleases(int applicationId, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
List<ApplicationRelease> applicationReleases = new ArrayList<>(); List<ApplicationRelease> applicationReleases = new ArrayList<>();
String sql = "SELECT AR.ID AS RELESE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE " String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE "
+ "AS RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, " + "AS RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, "
+ "AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, " + "AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, "
+ "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, " + "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, "
+ "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO, " + "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO, "
+ "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=(SELECT ID FROM AP_APP " + "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=? AND AR.TENANT_ID = ?;";
+ "WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?) AND AR.TENANT_ID = ?;";
try { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
statement.setString(1, applicationName); statement.setInt(1, applicationId);
statement.setString(2, applicationType); statement.setInt(2, tenantId);
statement.setInt(3, tenantId);
statement.setInt(4, tenantId);
resultSet = statement.executeQuery(); resultSet = statement.executeQuery();
while (resultSet.next()) { while (resultSet.next()) {
@ -245,10 +241,10 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
return applicationReleases; return applicationReleases;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to get the " throw new ApplicationManagementDAOException("Database connection exception while trying to get the "
+ "release details of the application with Name " + applicationName, e); + "release details of the application with app ID: " + applicationId, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( throw new ApplicationManagementDAOException(
"Error while getting all the release details of the " + applicationName + " application" "Error while getting all the release details of the app ID: " + applicationId
+ ", while executing the query " + sql, e); + ", while executing the query " + sql, e);
} finally { } finally {
Util.cleanupResources(statement, resultSet); Util.cleanupResources(statement, resultSet);

@ -31,7 +31,6 @@ import org.wso2.carbon.device.application.mgt.common.ApplicationSubscriptionType
import org.wso2.carbon.device.application.mgt.common.ApplicationType; import org.wso2.carbon.device.application.mgt.common.ApplicationType;
import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.LifecycleState; import org.wso2.carbon.device.application.mgt.common.LifecycleState;
import org.wso2.carbon.device.application.mgt.common.SortingOrder;
import org.wso2.carbon.device.application.mgt.common.Tag; import org.wso2.carbon.device.application.mgt.common.Tag;
import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole; import org.wso2.carbon.device.application.mgt.common.UnrestrictedRole;
import org.wso2.carbon.device.application.mgt.common.User; import org.wso2.carbon.device.application.mgt.common.User;
@ -51,7 +50,6 @@ import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManger;
import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil;
import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException;
import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceTypeDAO;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.dto.DeviceType;
import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserRealm;
@ -214,13 +212,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.getDBConnection(); ConnectionManagerUtil.getDBConnection();
applicationList = applicationDAO.getApplications(filter, tenantId); applicationList = applicationDAO.getApplications(filter, tenantId);
if(applicationList != null && applicationList.getApplications() != null && applicationList if(applicationList != null && applicationList.getApplications() != null && !applicationList
.getApplications().size() > 0) { .getApplications().isEmpty()) {
if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationList = getRoleRestrictedApplicationList(applicationList, userName); applicationList = getRoleRestrictedApplicationList(applicationList, userName);
} }
for (Application application : applicationList.getApplications()) { for (Application application : applicationList.getApplications()) {
applicationReleases = getReleases(application.getId()); applicationReleases = getReleases(application, filter.isRequirePublishedRelease());
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);
} }
} }
@ -277,7 +275,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public Application getApplicationById(int id) throws ApplicationManagementException { public Application getApplicationById(int id, boolean requirePublishedReleases) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
Application application; Application application;
@ -288,7 +286,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
application = ApplicationManagementDAOFactory.getApplicationDAO() application = ApplicationManagementDAOFactory.getApplicationDAO()
.getApplicationById(id, tenantId); .getApplicationById(id, tenantId);
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application.getId()); applicationReleases = getReleases(application, requirePublishedReleases);
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);
return application; return application;
} }
@ -305,7 +303,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return null; return null;
} }
applicationReleases = getReleases(application.getId()); applicationReleases = getReleases(application, requirePublishedReleases);
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);
return application; return application;
} catch (UserStoreException e) { } catch (UserStoreException e) {
@ -352,7 +350,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
application = ApplicationManagementDAOFactory.getApplicationDAO() application = ApplicationManagementDAOFactory.getApplicationDAO()
.getApplication(appName, appType, tenantId); .getApplication(appName, appType, tenantId);
if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
applicationReleases = getReleases(application.getId()); applicationReleases = getReleases(application, false);
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);
return application; return application;
} }
@ -369,7 +367,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
return null; return null;
} }
applicationReleases = getReleases(application.getId()); applicationReleases = getReleases(application, false);
application.setApplicationReleases(applicationReleases); application.setApplicationReleases(applicationReleases);
return application; return application;
} catch (UserStoreException e) { } catch (UserStoreException e) {
@ -424,11 +422,38 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
@Override // todo
public List<ApplicationRelease> getReleases(int applicationId) throws ApplicationManagementException { // public List<ApplicationRelease> getinstallableReleases(int applicationId) throws ApplicationManagementException {
// int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
//
// Application application = getApplicationIfAccessible(applicationId);
// List<ApplicationRelease> applicationReleases;
// List<ApplicationRelease> filteredApplicationReleases = new ArrayList<>();
// if (log.isDebugEnabled()) {
// log.debug("Request is received to retrieve all the releases related with the application " + application
// .toString());
// }
// ConnectionManagerUtil.getDBConnection();
// applicationReleases = this.applicationReleaseDAO.getReleases(application.getName(), application.getType(), tenantId);
// for (ApplicationRelease applicationRelease : applicationReleases) {
// LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO().
// getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
// if (lifecycleState != null) {
// applicationRelease.setLifecycleState(lifecycleState);
//
// if (!AppLifecycleState.REMOVED.toString()
// .equals(applicationRelease.getLifecycleState().getCurrentState())) {
// filteredApplicationReleases.add(applicationRelease);
// }
// }
// }
// return filteredApplicationReleases;
//
// }
private List<ApplicationRelease> getReleases(Application application, boolean requirePublishedRelease)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
Application application = getApplicationIfAccessible(applicationId);
List<ApplicationRelease> applicationReleases; List<ApplicationRelease> applicationReleases;
List<ApplicationRelease> filteredApplicationReleases = new ArrayList<>(); List<ApplicationRelease> filteredApplicationReleases = new ArrayList<>();
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -436,7 +461,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
.toString()); .toString());
} }
ConnectionManagerUtil.getDBConnection(); ConnectionManagerUtil.getDBConnection();
applicationReleases = this.applicationReleaseDAO.getReleases(application.getName(), application.getType(), tenantId); applicationReleases = this.applicationReleaseDAO.getReleases(application.getId(), tenantId);
for (ApplicationRelease applicationRelease : applicationReleases) { for (ApplicationRelease applicationRelease : applicationReleases) {
LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO(). LifecycleState lifecycleState = ApplicationManagementDAOFactory.getLifecycleStateDAO().
getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); getLatestLifeCycleStateByReleaseID(applicationRelease.getId());
@ -445,19 +470,34 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (!AppLifecycleState.REMOVED.toString() if (!AppLifecycleState.REMOVED.toString()
.equals(applicationRelease.getLifecycleState().getCurrentState())) { .equals(applicationRelease.getLifecycleState().getCurrentState())) {
if (requirePublishedRelease){
if (AppLifecycleState.PUBLISHED.toString()
.equals(applicationRelease.getLifecycleState().getCurrentState())){
filteredApplicationReleases.add(applicationRelease);
}
}else{
filteredApplicationReleases.add(applicationRelease); filteredApplicationReleases.add(applicationRelease);
} }
} }
} }
}
if (requirePublishedRelease && filteredApplicationReleases.size() > 1) {
log.error("There are more than one published application releases for application ID: " + application
.getId());
}
return filteredApplicationReleases; return filteredApplicationReleases;
} }
@Override @Override
public List<String> deleteApplication(int applicationId) throws ApplicationManagementException { public List<String> deleteApplication(int applicationId) throws ApplicationManagementException {
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
List<String> storedLocations = new ArrayList<>(); List<String> storedLocations = new ArrayList<>();
Application application;
try { try {
if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { if (!isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) {
@ -466,10 +506,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
"need to have admin permission"); "need to have admin permission");
} }
if (getApplicationIfAccessible(applicationId) == null) { application = getApplicationIfAccessible(applicationId);
if ( application == null) {
throw new ApplicationManagementException("Invalid Application"); throw new ApplicationManagementException("Invalid Application");
} }
List<ApplicationRelease> applicationReleases = getReleases(applicationId); List<ApplicationRelease> applicationReleases = getReleases(application, false);
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request is received to delete applications which are related with the application id " + log.debug("Request is received to delete applications which are related with the application id " +
applicationId); applicationId);

@ -39,6 +39,7 @@ import java.util.List;
import javax.validation.Valid; import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
@ -125,10 +126,25 @@ public interface ApplicationManagementAPI {
}) })
Response getApplications( Response getApplications(
@ApiParam( @ApiParam(
name = "filter", name = "name",
value = "Filter to get application list", value = "Name of the application")
required = true) @QueryParam("name") String appName,
@Valid Filter filter, @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 = "published-release",
value = "If set to True, only get published release for the application")
@QueryParam("published-release") boolean requirePublishedReleases,
@ApiParam( @ApiParam(
name = "offset", name = "offset",
value = "offset", value = "offset",
@ -138,11 +154,16 @@ public interface ApplicationManagementAPI {
name = "limit", name = "limit",
value = "limit", value = "limit",
defaultValue = "20") defaultValue = "20")
@QueryParam("limit") int limit @QueryParam("limit") int limit,
@ApiParam(
name = "sort",
value = "Sorting type",
defaultValue = "AES")
@QueryParam("sort") String sortBy
); );
@GET @GET
@Path("/{appType}") @Path("/{appId}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON)
@ApiOperation( @ApiOperation(
@ -173,6 +194,10 @@ public interface ApplicationManagementAPI {
response = ErrorResponse.class) response = ErrorResponse.class)
}) })
Response getApplication( Response getApplication(
@ApiParam(
name = "published-release",
value = "If set to True, only get published release for the application")
@QueryParam("published-release") boolean requirePublishedReleases,
@ApiParam( @ApiParam(
name = "appId", name = "appId",
value = "application Id", value = "application Id",

@ -41,6 +41,7 @@ import java.util.UUID;
import javax.validation.Valid; import javax.validation.Valid;
import javax.ws.rs.Consumes; import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET; import javax.ws.rs.GET;
import javax.ws.rs.POST; import javax.ws.rs.POST;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
@ -48,7 +49,6 @@ import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.Produces; import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam; import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
/** /**
@ -64,14 +64,32 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Override @Override
@Consumes("application/json") @Consumes("application/json")
public Response getApplications( public Response getApplications(
@Valid Filter filter, @QueryParam("name") String appName,
@QueryParam("offset") int offset, @QueryParam("type") String appType,
@QueryParam("limit") int limit) { @QueryParam("category") String appCategory,
@QueryParam("exact-match") boolean isFullMatch,
@QueryParam("published-release") boolean requirePublishedReleases,
@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 = new Filter();
filter.setOffset(offset); filter.setOffset(offset);
filter.setLimit(limit); filter.setLimit(limit);
filter.setSortBy(sortBy);
filter.setFullMatch(isFullMatch);
filter.setRequirePublishedRelease(requirePublishedReleases);
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); ApplicationList applications = applicationManager.getApplications(filter);
if (applications.getApplications().isEmpty()) { if (applications.getApplications().isEmpty()) {
return Response.status(Response.Status.NOT_FOUND).entity return Response.status(Response.Status.NOT_FOUND).entity
@ -90,10 +108,11 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI {
@Consumes("application/json") @Consumes("application/json")
@Path("/{appId}") @Path("/{appId}")
public Response getApplication( public Response getApplication(
@QueryParam("published-release") boolean requirePublishedReleases,
@PathParam("appId") int appId) { @PathParam("appId") int appId) {
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
try { try {
Application application = applicationManager.getApplicationById(appId); Application application = applicationManager.getApplicationById(appId, requirePublishedReleases);
if (application == null) { if (application == null) {
return Response.status(Response.Status.NOT_FOUND).entity return Response.status(Response.Status.NOT_FOUND).entity
("Application with application id: " + appId + " not found").build(); ("Application with application id: " + appId + " not found").build();

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

Loading…
Cancel
Save