diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java index d4f5e6a5f8..9bd1b56a36 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/Application.java @@ -38,7 +38,7 @@ public class Application { private String type; - private int isFree; + private String subType; private String paymentCurrency; @@ -105,12 +105,12 @@ public class Application { this.type = type; } - public int getIsFree() { - return isFree; + public String getSubType() { + return subType; } - public void setIsFree(int isFree) { - this.isFree = isFree; + public void setSubType(String subType) { + this.subType = subType; } public String getPaymentCurrency() { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java index b46aa0d07d..64cda383d2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/ApplicationRelease.java @@ -84,6 +84,8 @@ public class ApplicationRelease { private String url; + private boolean isPublishedRelease; + public int getNoOfRatedUsers() { return noOfRatedUsers; } @@ -299,4 +301,12 @@ public class ApplicationRelease { public void setUrl(String url) { this.url = url; } + + public boolean isPublishedRelease() { + return isPublishedRelease; + } + + public void setPublishedRelease(boolean publishedRelease) { + isPublishedRelease = publishedRelease; + } } 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 8edab08af3..dd58090713 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 @@ -68,7 +68,8 @@ public class Util { application.setName(rs.getString("APP_NAME")); application.setType(rs.getString("APP_TYPE")); application.setAppCategory(rs.getString("APP_CATEGORY")); - application.setIsFree(rs.getInt("IS_FREE")); + application.setSubType(rs.getString("SUB_TYPE")); + application.setPaymentCurrency(rs.getString("CURRENCY")); application.setIsRestricted(rs.getInt("RESTRICTED")); List tags = new ArrayList<>(); @@ -127,7 +128,8 @@ public class Util { application.setName(rs.getString("APP_NAME")); application.setType(rs.getString("APP_TYPE")); application.setAppCategory(rs.getString("APP_CATEGORY")); - application.setIsFree(rs.getInt("IS_FREE")); + application.setSubType(rs.getString("SUB_TYPE")); + application.setPaymentCurrency(rs.getString("CURRENCY")); application.setIsRestricted(rs.getInt("RESTRICTED")); } 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 a431dcbf29..9956202e00 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/application/GenericApplicationDAOImpl.java @@ -66,12 +66,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { conn = this.getDBConnection(); stmt = conn.prepareStatement("INSERT INTO AP_APP (NAME, TYPE, APP_CATEGORY, " - + "IS_FREE, PAYMENT_CURRENCY, RESTRICTED, TENANT_ID) VALUES " + + "SUB_TYPE, PAYMENT_CURRENCY, RESTRICTED, TENANT_ID) VALUES " + "(?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); stmt.setString(1, application.getName()); stmt.setString(2, application.getType()); stmt.setString(3, application.getAppCategory()); - stmt.setInt(4, application.getIsFree()); + stmt.setString(4, application.getSubType()); stmt.setString(5, application.getPaymentCurrency()); stmt.setInt(6, application.getIsRestricted()); stmt.setInt(7, application.getUser().getTenantId()); @@ -133,7 +133,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic 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; @@ -141,8 +141,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic 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.IS_FREE, AP_APP.RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, " + - "AP_UNRESTRICTED_ROLES.ROLE " + " AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " + + "AP_APP.RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE " + "AS APP_UNRESTRICTED_ROLES FROM ((AP_APP LEFT JOIN AP_APP_TAG ON AP_APP.ID = AP_APP_TAG.AP_APP_ID) " + "LEFT JOIN AP_UNRESTRICTED_ROLES ON AP_APP.ID = AP_UNRESTRICTED_ROLES.AP_APP_ID) " + "WHERE AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?"; @@ -165,7 +165,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } - sql += " LIMIT ? OFFSET ? ORDER BY " + filter.getSortBy() + " APP_ID"; + sql += " LIMIT ? OFFSET ? ORDER BY " + filter.getSortBy() + " APP_ID;"; pagination.setLimit(filter.getLimit()); pagination.setOffset(filter.getOffset()); @@ -173,22 +173,22 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic try { conn = this.getDBConnection(); stmt = conn.prepareStatement(sql); - stmt.setInt(1, tenantId); - stmt.setString(2, AppLifecycleState.REMOVED.toString()); + stmt.setInt(paramIndex, tenantId); + stmt.setString(paramIndex++, AppLifecycleState.REMOVED.toString()); if (filter.getAppType() != null) { - stmt.setString(3, filter.getAppType()); + stmt.setString(paramIndex++, filter.getAppType()); } if (filter.getAppName() != null) { if (filter.isFullMatch()) { - stmt.setString(4, filter.getAppName().toLowerCase()); + stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); } else { - stmt.setString(4, "%" + filter.getAppName().toLowerCase() + "%"); + stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); } } - stmt.setInt(5, filter.getLimit()); - stmt.setInt(6, filter.getOffset()); + stmt.setInt(paramIndex++, filter.getLimit()); + stmt.setInt(paramIndex, filter.getOffset()); rs = stmt.executeQuery(); applicationList.setApplications(Util.loadApplications(rs)); applicationList.setPagination(pagination); @@ -251,7 +251,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic log.debug("Getting application count 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; @@ -272,9 +272,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic sql += ";"; stmt = conn.prepareStatement(sql); - stmt.setInt(1, tenantId); + stmt.setInt(paramIndex++, tenantId); if (filter.getAppName() != null) { - stmt.setString(2, "%" + filter.getAppName().toLowerCase() + "%"); + stmt.setString(paramIndex, "%" + filter.getAppName().toLowerCase() + "%"); } rs = stmt.executeQuery(); if (rs.next()) { @@ -304,9 +304,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " - + "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, " + - "AP_APP_TAG.TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, " + - "AP_UNRESTRICTED_ROLES WHERE AP_APP.NAME=? AND AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;"; + + "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_ROLES.ROLE " + + "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.NAME=? AND " + + "AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;"; stmt = conn.prepareStatement(sql); stmt.setString(1, appName); @@ -347,9 +348,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " - + "AS APP_CATEGORY, AP_APP.IS_FREE AS IS_FREE, AP_APP.RESTRICTED AS RESTRICTED, AP_APP_TAG" - + ".TAG AS APP_TAG, AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, " + - "AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=? AND AP_APP.TENANT_ID=?;"; + + "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_ROLES.ROLE " + + "AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID=? AND " + + "AP_APP.TENANT_ID=?;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, applicationId); @@ -389,8 +391,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic conn = this.getDBConnection(); String sql = "SELECT AP_APP.ID AS APP_ID, AP_APP.NAME AS APP_NAME, AP_APP.TYPE AS APP_TYPE, AP_APP.APP_CATEGORY " - + "AS APP_CATEGORY, AP_APP.IS_FREE, AP_APP_TAG.TAG, AP_UNRESTRICTED_ROLES.ROLE AS RELESE_ID" - + " FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES WHERE AP_APP.ID = ?;"; + + "AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP_TAG.TAG AS TAG, " + + "AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_APP_TAG, AP_UNRESTRICTED_ROLES " + + "WHERE AP_APP.ID = ?;"; stmt = conn.prepareStatement(sql); stmt.setInt(1, appId); @@ -419,6 +422,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic @Override public Application editApplication(Application application, int tenantId) throws ApplicationManagementException { + int paramIndex = 1; Connection conn; PreparedStatement stmt = null; Application existingApplication = this.getApplication(application.getName(), application.getType(), tenantId); @@ -443,31 +447,30 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic if (application.getIsRestricted() != existingApplication.getIsRestricted()) { sql += "RESTRICTED = ? "; } - if (application.getIsFree() != existingApplication.getIsFree()) { - sql += "IS_FREE = ? "; + if (!application.getSubType().equals(existingApplication.getSubType())) { + sql += "SUB_TYPE = ? "; } sql += "WHERE ID = ?"; stmt = conn.prepareStatement(sql); if (application.getName() != null && !application.getName().equals(existingApplication.getName())) { - stmt.setString(1, application.getName()); + stmt.setString(paramIndex++, application.getName()); } if (application.getType() != null && !application.getType().equals(existingApplication.getType())) { - stmt.setString(2, application.getType()); + stmt.setString(paramIndex++, application.getType()); } if (application.getAppCategory() != null && !application.getAppCategory().equals( existingApplication.getAppCategory())) { - stmt.setString(3, application.getAppCategory()); + stmt.setString(paramIndex++, application.getAppCategory()); } if (application.getIsRestricted() != existingApplication.getIsRestricted()) { - stmt.setInt(4, application.getIsRestricted()); + stmt.setInt(paramIndex++, application.getIsRestricted()); } - if (application.getIsFree() != existingApplication.getIsFree()) { - stmt.setInt(5, application.getIsFree()); + if (!application.getSubType().equals(existingApplication.getSubType())) { + stmt.setString(paramIndex++, application.getSubType()); } - - stmt.setInt(6, application.getId()); + stmt.setInt(paramIndex, application.getId()); stmt.executeUpdate(); return application; } catch (DBConnectionException e) { @@ -580,8 +583,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic + "AP_APP_RELEASE.CREATED_AT, AP_APP_RELEASE.PUBLISHED_BY, AP_APP_RELEASE.PUBLISHED_AT, " + "AP_APP_RELEASE.STARS," + "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.IS_FREE, AP_UNRESTRICTED_ROLES.ROLE AS ROLE " - + "FROM AP_APP, AP_UNRESTRICTED_ROLES, AP_APP_RELEASE " + + "AP_APP.APP_CATEGORY AS APP_CATEGORY, AP_APP.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " + + "AP_UNRESTRICTED_ROLES.ROLE AS ROLE FROM AP_APP, AP_UNRESTRICTED_ROLES, AP_APP_RELEASE " + "WHERE AP_APP_RELEASE.UUID=? AND AP_APP.TENANT_ID=?;"; stmt = conn.prepareStatement(sql); @@ -602,7 +605,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic application.setName(rs.getString("APP_NAME")); application.setType(rs.getString("APP_TYPE")); application.setAppCategory(rs.getString("APP_CATEGORY")); - application.setIsFree(rs.getInt("IS_FREE")); + application.setSubType(rs.getString("SUB_TYPE")); + application.setPaymentCurrency(rs.getString("CURRENCY")); application.setIsRestricted(rs.getInt("RESTRICTED")); UnrestrictedRole unrestrictedRole = new UnrestrictedRole(); 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/OracleApplicationDAOImpl.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/OracleApplicationDAOImpl.java index f7c15cf0fe..0e49ea4a06 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/OracleApplicationDAOImpl.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/OracleApplicationDAOImpl.java @@ -43,85 +43,5 @@ public class OracleApplicationDAOImpl extends GenericApplicationDAOImpl { private static final Log log = LogFactory.getLog(OracleApplicationDAOImpl.class); - @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())); - } - - 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.IS_FREE, AP_APP.RESTRICTED, AP_APP_TAG.TAG AS APP_TAG, " + - "AP_UNRESTRICTED_ROLES.ROLE AS APP_UNRESTRICTED_ROLES FROM ((AP_APP LEFT JOIN AP_APP_TAG ON " + - "AP_APP.ID = AP_APP_TAG.AP_APP_ID) LEFT JOIN AP_UNRESTRICTED_ROLES ON " + - "AP_APP.ID = AP_UNRESTRICTED_ROLES.AP_APP_ID) WHERE AP_APP.TENANT_ID = ? AND AP_APP.STATUS != ?"; - - - if (filter == null) { - throw new ApplicationManagementDAOException("Filter need to be instantiated"); - } - - if (filter.getAppType() != null) { - sql += " AND AP_APP.TYPE "; - sql += "= ?"; - } - if (filter.getAppName() != null) { - sql += " AND LOWER (AP_APP.NAME) "; - if (filter.isFullMatch()) { - sql += "= ?"; - } else { - sql += "LIKE ?"; - } - } - - sql += " AND rownum <= ? OFFSET ? " + filter.getSortBy() + " APP_ID"; - - pagination.setLimit(filter.getLimit()); - pagination.setOffset(filter.getOffset()); - - try { - conn = this.getDBConnection(); - stmt = conn.prepareStatement(sql); - stmt.setInt(1, tenantId); - stmt.setString(2, AppLifecycleState.REMOVED.toString()); - - if (filter.getAppType() != null) { - stmt.setString(3, filter.getAppType()); - } - if (filter.getAppName() != null) { - if (filter.isFullMatch()) { - stmt.setString(4, filter.getAppName().toLowerCase()); - } else { - stmt.setString(4, "%" + filter.getAppName().toLowerCase() + "%"); - } - } - - stmt.setInt(5, filter.getLimit()); - stmt.setInt(6, 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; - } } 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 1f80ac0fb2..dbe358a5a9 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 @@ -108,7 +108,7 @@ public class ApplicationManagerImpl implements ApplicationManager { application.setDevicetype(deviceType); int appId = this.applicationDAO.createApplication(application, deviceType.getId()); - if (appId != -1) { + if (appId == -1) { log.error("Application creation Failed"); ConnectionManagerUtil.rollbackDBTransaction(); return null; @@ -350,6 +350,10 @@ public class ApplicationManagerImpl implements ApplicationManager { applicationReleases = ApplicationManagementDAOFactory.getApplicationReleaseDAO() .getReleases(application.getName(), application.getType(), tenantId); for (ApplicationRelease applicationRelease : applicationReleases) { + if (AppLifecycleState.PUBLISHED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO(). + getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())){ + applicationRelease.setPublishedRelease(true); + } if (!AppLifecycleState.REMOVED.toString().equals(ApplicationManagementDAOFactory.getLifecycleStateDAO(). getLatestLifeCycleStateByReleaseID(applicationRelease.getId()).getCurrentState())) { filteredApplicationReleases.add(applicationRelease); @@ -834,14 +838,14 @@ public class ApplicationManagerImpl implements ApplicationManager { "please remove this application and publish " + "new application with type: " + application.getType()); } - if (existingApplication.getIsFree() != application.getIsFree()) { - if (existingApplication.getIsFree() == 1) { + if (existingApplication.getSubType() != application.getSubType()) { + if ("PAID".equals(existingApplication.getSubType())) { if (application.getPaymentCurrency() != null || !application.getPaymentCurrency().equals("")) { throw new ApplicationManagementException("If you are going to change Non-Free app as Free app, " + "currency attribute in the application updating " + "payload should be null or \"\""); } - } else if (existingApplication.getIsFree() == 0) { + } else if ("FREE".equals(existingApplication.getSubType())) { if (application.getPaymentCurrency() == null || application.getPaymentCurrency().equals("")) { throw new ApplicationManagementException("If you are going to change Free app as Non-Free app, " + "currency attribute in the application payload " + @@ -903,7 +907,7 @@ public class ApplicationManagerImpl implements ApplicationManager { return null; } if (filter.getAppType() != null) { - Boolean isValidRequest = false; + boolean isValidRequest = false; for (ApplicationType applicationType : ApplicationType.values()) { if (applicationType.toString().equals(filter.getAppType())) { isValidRequest = true; 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/APIUtil.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java index d3fdff9ea7..b850d5c0c7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/APIUtil.java @@ -39,7 +39,6 @@ public class APIUtil { private static SubscriptionManager subscriptionManager; private static UnrestrictedRoleManager unrestrictedRoleManager; - public static ApplicationManager getApplicationManager() { if (applicationManager == null) { synchronized (APIUtil.class) { @@ -55,7 +54,6 @@ public class APIUtil { } } } - return applicationManager; } 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 69fc0e9a64..daa7ac85e2 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 @@ -222,9 +222,13 @@ public interface ApplicationManagementAPI { @ApiResponses( value = { @ApiResponse( - code = 201, + code = 200, message = "OK. \n Successfully edited the application.", response = Application.class), + @ApiResponse( + code = 400, + message = "Bad Request. \n " + + "Application updating payload contains unacceptable or vulnerable data"), @ApiResponse( code = 500, message = "Internal Server Error. \n Error occurred while editing the application.", @@ -235,7 +239,8 @@ public interface ApplicationManagementAPI { name = "application", value = "The application that need to be edited.", required = true) - @Valid Application application); + @Valid Application application + ); @POST @Produces(MediaType.APPLICATION_JSON) @@ -265,7 +270,7 @@ public interface ApplicationManagementAPI { "Application creating payload contains unacceptable or vulnerable data"), @ApiResponse( code = 500, - message = "Internal Server Error. \n Error occurred while getting the application list.", + message = "Internal Server Error. \n Error occurred while creating the application.", response = ErrorResponse.class) }) Response createApplication( @@ -297,7 +302,8 @@ public interface ApplicationManagementAPI { name = "screenshot", value = "Screen Shots of the uploading application", required = true) - @Multipart(value = "screenshot") List attachmentList); + @Multipart(value = "screenshot") List attachmentList + ); @DELETE @Consumes("application/json") @@ -331,7 +337,8 @@ public interface ApplicationManagementAPI { name = "UUID", value = "Unique identifier of the Application", required = true) - @PathParam("appid") int applicationId); + @PathParam("appid") int applicationId + ); @POST @Path("/image-artifacts/{appId}/{uuid}") @@ -353,8 +360,15 @@ public interface ApplicationManagementAPI { @ApiResponses( value = { @ApiResponse( - code = 201, - message = "OK. \n Successfully uploaded artifacts."), + code = 200, + message = "OK. \n Successfully updated artifacts."), + @ApiResponse( + code = 403, + message = "FORBIDDEN. \n Can't Update the application release in PUBLISHED or DEPRECATED " + + "state. Hence please demote the application and update the application release"), + @ApiResponse( + code = 404, + message = "NOT FOUND. \n Error occurred while updating the application."), @ApiResponse( code = 500, message = "Internal Server Error. \n Error occurred while getting the application list.", @@ -367,10 +381,11 @@ public interface ApplicationManagementAPI { @PathParam("uuid") String applicationUUID, @Multipart(value = "icon") Attachment iconFile, @Multipart(value = "banner") Attachment bannerFile, - @Multipart(value = "screenshot") List screenshots); + @Multipart(value = "screenshot") List screenshots + ); @PUT - @Path("/app-artifacts/{appId}/{uuid}") + @Path("/app-artifacts/{appType}/{appId}/{uuid}") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.MULTIPART_FORM_DATA) @ApiOperation( @@ -391,6 +406,10 @@ public interface ApplicationManagementAPI { @ApiResponse( code = 201, message = "OK. \n Successfully uploaded artifacts."), + @ApiResponse( + code = 400, + message = "Bad Request. \n " + + "Application artifact updating payload contains unacceptable or vulnerable data"), @ApiResponse( code = 500, message = "Internal Server Error. \n Error occurred while getting the application list.", @@ -399,11 +418,12 @@ public interface ApplicationManagementAPI { Response updateApplicationArtifact( @ApiParam(name = "appType", value = "Type of the application i.e Android, IOS etc", required = true) @PathParam("appType") String appType, - @ApiParam(name = "id", value = "Id of the application", required = true) - @PathParam("uuid") int applicationId, + @ApiParam(name = "appId", value = "Id of the application", required = true) + @PathParam("appId") int applicationId, @ApiParam(name = "uuid", value = "UUID of the application", required = true) @PathParam("uuid") String applicationUUID, - @Multipart("binaryFile") Attachment binaryFile); + @Multipart("binaryFile") Attachment binaryFile + ); @PUT @Path("/{appId}/{uuid}") @@ -428,6 +448,10 @@ public interface ApplicationManagementAPI { code = 201, message = "OK. \n Successfully created an application release.", response = ApplicationRelease.class), + @ApiResponse( + code = 400, + message = "Bad Request. \n " + + "Application release updating payload contains unacceptable or vulnerable data"), @ApiResponse( code = 500, message = "Internal Server Error. \n Error occurred while releasing the application.", @@ -495,11 +519,6 @@ public interface ApplicationManagementAPI { code = 201, message = "OK. \n Successfully add a lifecycle state.", response = Application.class), - @ApiResponse( - code = 304, - message = "Not Modified. \n " + - "Empty body because the client already has the latest version of the requested " - + "resource."), @ApiResponse( code = 500, message = "Internal Server Error. \n Error occurred adding a lifecycle state.", 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 21f8aef0e2..bedb342eb1 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 @@ -79,7 +79,7 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { } catch (ApplicationManagementException e) { String msg = "Error occurred while getting the application list for publisher "; log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } @@ -120,34 +120,16 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { List attachments = new ArrayList<>(); List applicationReleases = new ArrayList<>(); try { - if (iconFile == null) { - log.error("Icon file is not uploaded for the application release of " + application.getName() + - " of application type " + application.getType()); - return Response.status(Response.Status.BAD_REQUEST).build(); - } - - if (bannerFile == null) { - log.error("Banner file is not uploaded for the application release of " + application.getName() + - " of application type " + application.getType()); - return Response.status(Response.Status.BAD_REQUEST).build(); - } - if (attachmentList == null || attachmentList.isEmpty()) { - log.error("Screenshots are not uploaded for the application release of " + application.getName() + - " of application type " + application.getType()); + if (!isValidAppCreatingRequest(binaryFile, iconFile, bannerFile, attachmentList, application)) { return Response.status(Response.Status.BAD_REQUEST).build(); - } - - if (binaryFile == null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())) { - log.error("Binary file is not uploaded for the application release of " + application.getName() + - " of application type " + application.getType()); - return Response.status(Response.Status.BAD_REQUEST).build(); - }else if(binaryFile == null && ApplicationType.WEB_CLIP.toString().equals(application.getType())){ - applicationRelease = applicationStorageManager.uploadReleaseArtifact(applicationRelease, application.getType(), - null); - }else if (binaryFile != null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())){ - applicationRelease = applicationStorageManager.uploadReleaseArtifact(applicationRelease, application.getType(), - binaryFile.getDataHandler().getInputStream()); + } else if (binaryFile == null && ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + applicationRelease = applicationStorageManager + .uploadReleaseArtifact(applicationRelease, application.getType(), null); + } else if (binaryFile != null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + applicationRelease = applicationStorageManager + .uploadReleaseArtifact(applicationRelease, application.getType(), + binaryFile.getDataHandler().getInputStream()); } iconFileStream = iconFile.getDataHandler().getInputStream(); @@ -240,13 +222,13 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { log.error(msg, e); return APIUtil.getResponse(e, Response.Status.NOT_FOUND); } catch (ApplicationManagementException e) { - String msg = "Error occurred while updating the application"; + String msg = "Error occurred while updating the application."; log.error(msg, e); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } catch (IOException e) { - log.error("Exception while trying to read icon, banner files for the application " + applicationUuid); - return APIUtil.getResponse(new ApplicationManagementException( - "Exception while trying to read icon, " + "banner files for the application " + applicationUuid, e), + String msg = "Exception while trying to read icon, banner files for the application " + applicationUuid; + log.error(msg); + return APIUtil.getResponse(new ApplicationManagementException(msg, e), Response.Status.INTERNAL_SERVER_ERROR); } catch (ResourceManagementException e) { log.error("Error occurred while uploading the image artifacts of the application with the uuid " @@ -278,11 +260,12 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { binaryFile.getDataHandler().getInputStream()); applicationManager.updateRelease(applicationId, applicationRelease); return Response.status(Response.Status.OK) - .entity("Successfully uploaded artifacts for the application " + applicationUuid).build(); + .entity("Successfully uploaded artifacts for the application release. UUID is " + applicationUuid).build(); } catch (IOException e) { - log.error("Exception while trying to read icon, banner files for the application " + applicationUuid); - return APIUtil.getResponse(new ApplicationManagementException( - "Exception while trying to read icon, banner files for the application " + applicationUuid, e), + String msg = + "Exception while trying to read icon, banner files for the application release" + applicationUuid; + log.error(msg); + return APIUtil.getResponse(new ApplicationManagementException(msg, e), Response.Status.BAD_REQUEST); } catch (ResourceManagementException e) { log.error("Error occurred while uploading the image artifacts of the application with the uuid " @@ -453,4 +436,32 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { return Response.status(Response.Status.CREATED).entity("Lifecycle state added successfully.").build(); } + private boolean isValidAppCreatingRequest(Attachment binaryFile, Attachment iconFile, Attachment bannerFile, + List attachmentList, Application application){ + + if (iconFile == null) { + log.error("Icon file is not found for the application release. Application name: " + + application.getName() + " and type: " + application.getType()); + return false; + } + + if (bannerFile == null) { + log.error("Banner file is not found for the application release. Application name: " + + application.getName() + " and application type: " + application.getType()); + return false; + } + + if (attachmentList == null || attachmentList.isEmpty()) { + log.error("Screenshots are not found for the application release. Application name: " + + application.getName() + " Application type: " + application.getType()); + return false; + } + + if (binaryFile == null && !ApplicationType.WEB_CLIP.toString().equals(application.getType())) { + log.error("Binary file is not found for the application release. Application name: " + + application.getName() + " Application type: " + application.getType()); + return false; + } + return true; + } } 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/ApplicationManagementAPI.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/ApplicationManagementAPI.java index b3ec06d16b..49c75b16c7 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/ApplicationManagementAPI.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/ApplicationManagementAPI.java @@ -32,6 +32,7 @@ import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Multipart; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.publisher.api.beans.ErrorResponse; import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.ApplicationList; @@ -159,9 +160,10 @@ public interface ApplicationManagementAPI { }) Response getApplications( @ApiParam( - name = "searchQuery", - value = "Relevant search query to search on", defaultValue = "*") - @QueryParam("query") String searchQuery, + name = "filter", + value = "Filter to get application list", + required = true) + @Valid Filter filter, @ApiParam( name = "offset", value = "Provide from which position apps should return", defaultValue = "20") @@ -217,35 +219,5 @@ public interface ApplicationManagementAPI { @QueryParam("appName") String appName ); - @GET - @Path("/release/{uuid}") - @Produces(MediaType.APPLICATION_JSON) - @Consumes(MediaType.APPLICATION_JSON) - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Get all the releases or specific release of an application", - notes = "This will retrieve the all the releases or specific release of an application", - tags = "Application Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:application:get") - }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully retrieved the Application release."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while releasing the application.", - response = ErrorResponse.class) - }) - Response getApplicationRelease( - @ApiParam(name = "ID", value = "Identifier of the Application", required = true) @PathParam("uuid") String applicationUUID, - @ApiParam(name = "version", value = "Version of the application", required = false) @QueryParam("version") String version); - } +} 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 9c87bfbe81..e49a649179 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 @@ -20,25 +20,26 @@ package org.wso2.carbon.device.application.mgt.store.api.services.impl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.ApplicationRelease; import org.wso2.carbon.device.application.mgt.store.api.APIUtil; import org.wso2.carbon.device.application.mgt.common.Application; import org.wso2.carbon.device.application.mgt.common.ApplicationList; import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.services.ApplicationManager; -import org.wso2.carbon.device.application.mgt.common.services.ApplicationStorageManager; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.store.api.services.ApplicationManagementAPI; +import javax.validation.Valid; import javax.ws.rs.Consumes; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.PathParam; import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; - +import java.util.ArrayList; +import java.util.List; /** * Implementation of Application Management related APIs. @@ -54,33 +55,37 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @Consumes("application/json") @Override public Response getApplications( - @QueryParam("query") String searchQuery, + @Valid Filter filter, @QueryParam("offset") int offset, @QueryParam("limit") int limit) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); try { if (limit == 0) { limit = DEFAULT_LIMIT; } - Filter filter = new Filter(); filter.setOffset(offset); filter.setLimit(limit); - filter.setAppName(searchQuery); ApplicationList applications = applicationManager.getApplications(filter); + List publishedApplicationRelease = new ArrayList<>(); for (Application application : applications.getApplications()) { -// ToDo : use better approach to solve this - String uuId = applicationManager.getUuidOfLatestRelease(application.getId()); - if (uuId != null){ - application.setUuidOfLatestRelease(uuId); -// ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0); -// application.setIconOfLatestRelease(imageArtifact); - }else{ -// ToDo set default icon + + for (ApplicationRelease appRelease: application.getApplicationReleases()){ + if (appRelease.isPublishedRelease()){ + publishedApplicationRelease.add(appRelease); + } } + if (publishedApplicationRelease.size()>1){ + String msg = "Application " + application.getName() + + " has more than one PUBLISHED application releases"; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR) + .entity(msg).build(); + } + application.setApplicationReleases(publishedApplicationRelease); + publishedApplicationRelease.clear(); } return Response.status(Response.Status.OK).entity(applications).build(); } catch (NotFoundException e) { @@ -95,57 +100,41 @@ public class ApplicationManagementAPIImpl implements ApplicationManagementAPI { @GET @Consumes("application/json") @Path("/{appType}") - public Response getApplication(@PathParam("appType") String appType, @QueryParam("appName") String appName) { + public Response getApplication( + @PathParam("appType") String appType, + @QueryParam("appName") String appName) { ApplicationManager applicationManager = APIUtil.getApplicationManager(); - ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager(); + List publishedApplicationRelease = new ArrayList<>(); try { Application application = applicationManager.getApplication(appType, appName); if (application == null) { return Response.status(Response.Status.NOT_FOUND) - .entity("Application with UUID " + appType + " not found").build(); + .entity("Application with application type: " + appType + " not found").build(); } - // ToDo : use better approach to solve this - String uuId = applicationManager.getUuidOfLatestRelease(application.getId()); - if (uuId != null){ - application.setUuidOfLatestRelease(uuId); -// ImageArtifact imageArtifact = applicationStorageManager.getImageArtifact(uuId, Constants.IMAGE_ARTIFACTS[0], 0); -// application.setIconOfLatestRelease(imageArtifact); - }else{ - // ToDo set default icon + for (ApplicationRelease appRelease : application.getApplicationReleases()) { + if (appRelease.isPublishedRelease()) { + publishedApplicationRelease.add(appRelease); + } } + if (publishedApplicationRelease.size() > 1) { + String msg = + "Application " + application.getName() + " has more than one PUBLISHED application releases"; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + application.setApplicationReleases(publishedApplicationRelease); return Response.status(Response.Status.OK).entity(application).build(); } catch (NotFoundException e) { return Response.status(Response.Status.NOT_FOUND).build(); } catch (ApplicationManagementException e) { - log.error("Error occurred while getting application with the uuid " + appType, e); + log.error("Error occurred while getting application with the application type: " + appType + + " and application name: " + appName, e); return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); } } - //todo WIP - @Override - @Path("/{uuid}") - @GET - public Response getApplicationRelease(@PathParam("uuid") String applicationUUID, - @QueryParam("version") String version) { - return null; - // try { - // if (version == null || version.isEmpty()) { - //// List applicationReleases = applicationReleaseManager.getReleases(applicationUUID); - //// return Response.status(Response.Status.OK).entity(applicationReleases).build(); - // } else { - //// ApplicationRelease applicationRelease = applicationReleaseManager.getRelease(applicationUUID, version); - //// return Response.status(Response.Status.OK).entity(applicationRelease).build(); - // } - // } catch (NotFoundException e) { - // return Response.status(Response.Status.NOT_FOUND).build(); - // } catch (ApplicationManagementException e) { - // log.error("Error while getting all the application releases for the application with the UUID " - // + applicationUUID, e); - // return APIUtil.getResponse(e, Response.Status.INTERNAL_SERVER_ERROR); - // } - } +// todo --> get applications by category }