From a4f7984a0f406c5f21c6fa4b2c41e94531cce8df Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 20 Jun 2019 15:43:58 +0530 Subject: [PATCH 1/4] Improve app creating method by validating supported OS types in the request. --- .../common/services/ApplicationManager.java | 2 +- .../wrapper/ApplicationReleaseWrapper.java | 4 +- .../wrapper/PublicAppReleaseWrapper.java | 4 +- .../mgt/core/impl/ApplicationManagerImpl.java | 62 ++++++++++++++++--- .../management/ApplicationManagementTest.java | 2 +- 5 files changed, 60 insertions(+), 14 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index 90f65a44a5..ed6d77a61c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -53,7 +53,7 @@ public interface ApplicationManager { * @throws ApplicationManagementException ApplicationDTO Management Exception */ Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) - throws ApplicationManagementException, RequestValidatingException; + throws ApplicationManagementException; Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java index fb7def9963..4314be9659 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/ApplicationReleaseWrapper.java @@ -54,7 +54,9 @@ public class ApplicationReleaseWrapper { private String metaData; @ApiModelProperty(name = "supportedOsVersions", - value = "ApplicationDTO release supported OS versions") + value = "Application release supported OS versions", + required = true, + example = "4.0-10.0") @NotNull private String supportedOsVersions; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppReleaseWrapper.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppReleaseWrapper.java index 46f274dd2d..badbdf30d5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppReleaseWrapper.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/wrapper/PublicAppReleaseWrapper.java @@ -66,7 +66,9 @@ public class PublicAppReleaseWrapper { private String packageName; @ApiModelProperty(name = "supportedOsVersions", - value = "ApplicationDTO release supported OS versions") + value = "Application release supported OS versions", + required = true, + example = "4.0-10.0") @NotNull private String supportedOsVersions; 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 dab6fdf57f..c940fa7ab4 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 @@ -88,6 +88,7 @@ import org.wso2.carbon.device.application.mgt.core.util.StorageManagementUtil; import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; @@ -135,17 +136,16 @@ public class ApplicationManagerImpl implements ApplicationManager { * The responsbility of this method is the creating an application. * @param applicationWrapper ApplicationDTO that need to be created. * @return {@link ApplicationDTO} - * @throws RequestValidatingException if application creating request is invalid, * @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException} */ @Override public Application createApplication(ApplicationWrapper applicationWrapper, - ApplicationArtifact applicationArtifact) throws RequestValidatingException, ApplicationManagementException { + ApplicationArtifact applicationArtifact) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); if (log.isDebugEnabled()) { - log.debug("Application create request is received for the tenant : " + tenantId + " From" + " the user : " + log.debug("Application create request is received for the tenant : " + tenantId + " and" + " the user : " + userName); } @@ -154,6 +154,13 @@ public class ApplicationManagerImpl implements ApplicationManager { //uploading application artifacts try { ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); + if (!isValidOsVersions(applicationReleaseDTO.getSupportedOsVersions(), applicationWrapper.getDeviceType())){ + String msg = "You are trying to create application which has an application release contains invalid or " + + "unsupported OS versions in the supportedOsVersions section. Hence, please re-evaluate the " + + "request payload."; + log.error(msg); + throw new BadRequestException(msg); + } applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(), applicationWrapper.getDeviceType(), applicationReleaseDTO, applicationArtifact, false); applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact); @@ -425,7 +432,6 @@ public class ApplicationManagerImpl implements ApplicationManager { ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); String uuid = UUID.randomUUID().toString(); - //todo check installer name exists or not, do it in the validation method String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName()); applicationReleaseDTO.setUuid(uuid); applicationReleaseDTO.setAppHashValue(md5); @@ -455,6 +461,14 @@ public class ApplicationManagerImpl implements ApplicationManager { + userName); } + if (!isValidOsVersions(publicAppWrapper.getPublicAppReleaseWrappers().get(0).getSupportedOsVersions(), + publicAppWrapper.getDeviceType())) { + String msg = "You are trying to add application release which has invalid or unsupported OS versions in " + + "the supportedOsVersions section. Hence, please re-evaluate the request payload."; + log.error(msg); + throw new BadRequestException(msg); + } + if (DeviceTypes.ANDROID.toString().equals(publicAppWrapper.getDeviceType())) { publicAppStorePath = Constants.GOOGLE_PLAY_STORE_URL; } else if (DeviceTypes.IOS.toString().equals(publicAppWrapper.getDeviceType())) { @@ -758,8 +772,15 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new BadRequestException(msg); } + DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); + if (!isValidOsVersions(applicationReleaseWrapper.getSupportedOsVersions(), deviceType.getName())){ + String msg = "You are trying to add application release which has invalid or unsupported OS versions in " + + "the supportedOsVersions section. Hence, please re-evaluate the request payload."; + log.error(msg); + throw new BadRequestException(msg); + } ApplicationReleaseDTO applicationReleaseDTO = uploadReleaseArtifacts(applicationReleaseWrapper, - applicationDTO, applicationArtifact); + applicationDTO, applicationArtifact, deviceType.getName()); ConnectionManagerUtil.beginDBTransaction(); String initialstate = lifecycleStateManager.getInitialState(); applicationReleaseDTO.setCurrentState(initialstate); @@ -818,12 +839,11 @@ public class ApplicationManagerImpl implements ApplicationManager { } private ApplicationReleaseDTO uploadReleaseArtifacts(ApplicationReleaseWrapper applicationReleaseWrapper, - ApplicationDTO applicationDTO, ApplicationArtifact applicationArtifact) + ApplicationDTO applicationDTO, ApplicationArtifact applicationArtifact, String deviceTypeName) throws ApplicationManagementException { try { - DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId()); ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(), - deviceType.getName(), APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact, + deviceTypeName, APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact, true); return addImageArtifacts(applicationReleaseDTO, applicationArtifact); } catch (ResourceManagementException e) { @@ -834,6 +854,30 @@ public class ApplicationManagerImpl implements ApplicationManager { } } + private boolean isValidOsVersions(String osRange, String deviceTypeName) + throws ApplicationManagementException { + String lowestSupportingOsVersion; + String highestSupportingOsVersion = null; + String[] supportedOsVersionValues = osRange.split("-"); + lowestSupportingOsVersion = supportedOsVersionValues[0].trim(); + if (!"ALL".equals(supportedOsVersionValues[1].trim())) { + highestSupportingOsVersion = supportedOsVersionValues[1].trim(); + } + + try { + DeviceManagementProviderService deviceManagementProviderService = DAOUtil.getDeviceManagementService(); + return deviceManagementProviderService.getDeviceTypeVersion(deviceTypeName, lowestSupportingOsVersion) + != null && (highestSupportingOsVersion == null + || deviceManagementProviderService.getDeviceTypeVersion(deviceTypeName, highestSupportingOsVersion) + != null); + } catch (DeviceManagementException e) { + String msg = + "Error occurred while getting supported device type versions for device type : " + deviceTypeName; + log.error(msg); + throw new ApplicationManagementException(msg); + } + } + @Override public Application getApplicationById(int appId, String state) throws ApplicationManagementException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); @@ -2451,7 +2495,6 @@ public class ApplicationManagerImpl implements ApplicationManager { List registeredCategories = this.applicationDAO.getAllCategories(tenantId); if (registeredCategories.isEmpty()) { - ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Registered application category set is empty. Since it is mandatory to add application " + "category when adding new application, registered application category list shouldn't be null."; log.error(msg); @@ -2482,7 +2525,6 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ApplicationManagementException(msg, e); } catch (UserStoreException e) { - ConnectionManagerUtil.rollbackDBTransaction(); String msg = "Error occurred when validating the unrestricted roles given for the web clip"; log.error(msg); throw new ApplicationManagementException(msg, e); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java index 04607486a7..9ec92e1820 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java @@ -75,7 +75,7 @@ public class ApplicationManagementTest extends BaseTestCase { releaseWrapper.setMetaData("Just meta data"); releaseWrapper.setReleaseType("free"); releaseWrapper.setPrice(5.7); - releaseWrapper.setSupportedOsVersions("5.7, 6.1"); + releaseWrapper.setSupportedOsVersions("4.0-7.0"); applicationReleaseWrappers.add(releaseWrapper); applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers); From 822dc090f9cee9b8ee370f1c11e11e40511e5caa Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Thu, 20 Jun 2019 20:09:23 +0530 Subject: [PATCH 2/4] Refactore code --- .../common/services/ApplicationManager.java | 18 +- .../mgt/core/dao/ApplicationDAO.java | 56 +-- .../GenericApplicationDAOImpl.java | 225 +---------- .../mgt/core/impl/ApplicationManagerImpl.java | 152 +------ .../management/ApplicationManagementTest.java | 372 +++++++++--------- 5 files changed, 199 insertions(+), 624 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java index ed6d77a61c..cf6e9904b7 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/services/ApplicationManager.java @@ -45,12 +45,13 @@ import java.util.List; */ public interface ApplicationManager { - /** - * Creates an application. + /*** + * The method is responsible to add new application into entgra App Manager. * * @param applicationWrapper Application that need to be created. - * @return Created application - * @throws ApplicationManagementException ApplicationDTO Management Exception + * @param applicationArtifact contains artifact data. i.e image name and stream, icon name and stream etc. + * @return {@link Application} + * @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException} */ Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException; @@ -134,15 +135,6 @@ public interface ApplicationManager { */ Application getApplicationByUuid(String uuid, String state) throws ApplicationManagementException; - /** - * To get an application associated with the release. - * - * @param appReleaseUUID UUID of the app release - * @return {@link ApplicationDTO} associated with the release - * @throws ApplicationManagementException If unable to retrieve {@link ApplicationDTO} associated with the given UUID - */ - ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException; - /** * To get lifecycle state change flow of a particular Application Release. * diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java index 30d7beb3e3..32a1d0d83c 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/ApplicationDAO.java @@ -20,7 +20,6 @@ package org.wso2.carbon.device.application.mgt.core.dao; import 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.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO; import org.wso2.carbon.device.application.mgt.common.dto.TagDTO; import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; @@ -101,18 +100,6 @@ public interface ApplicationDAO { void updateCategory(CategoryDTO categoryDTO, int tenantId) throws ApplicationManagementDAOException; - - - /** - * To check application existence. - * - * @param appName appName that need to identify application. - * @param type type that need to identify application. - * @param tenantId tenantId that need to identify application. - * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. - */ - boolean isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException; - /** * To get the applications that satisfy the given criteria. * @@ -132,27 +119,6 @@ public interface ApplicationDAO { */ String getUuidOfLatestRelease(int appId) throws ApplicationManagementDAOException; - /** - * To get the application with the given uuid - * - * @param appName name of the application to be retrieved. - * @param tenantId ID of the tenant. - * @param appType Type of the application. - * @return the application - * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. - */ - ApplicationDTO getApplication(String appName, String appType, int tenantId) throws ApplicationManagementDAOException; - - /** - * To get the application with the given id - * - * @param id ID of the application. - * @param tenantId ID of the tenant. - * @return the application - * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. - */ - ApplicationDTO getApplicationById(String id, int tenantId) throws ApplicationManagementDAOException; - /** * To get the application with the given id * @@ -173,16 +139,6 @@ public interface ApplicationDAO { */ ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId) throws ApplicationManagementDAOException; - /** - * To get the application with the given uuid - * - * @param appId ID of the application - * @param tenantId Tenant Id - * @return the boolean value - * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. - */ - boolean verifyApplicationExistenceById(int appId, int tenantId) throws ApplicationManagementDAOException; - /** * Verify whether application exist for given application name and device type. Because a name and device type is * unique for an application. @@ -193,7 +149,7 @@ public interface ApplicationDAO { * @return ID of the ApplicationDTO. * @throws ApplicationManagementDAOException Application Management DAO Exception. */ - boolean isValidAppName(String appName, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException; + boolean isExistingAppName(String appName, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException; /** * To edit the given application. @@ -236,16 +192,6 @@ public interface ApplicationDAO { */ void deleteTags(List tags, int applicationId, int tenantId) throws ApplicationManagementDAOException; - /** - * To get an {@link ApplicationDTO} associated with the given release - * - * @param appReleaseUUID UUID of the {@link ApplicationReleaseDTO} - * @param tenantId ID of the tenant - * @return {@link ApplicationDTO} associated with the given release UUID - * @throws ApplicationManagementDAOException if unable to fetch the ApplicationDTO from the data store. - */ - ApplicationDTO getApplicationByRelease(String appReleaseUUID, int tenantId) throws ApplicationManagementDAOException; - String getApplicationSubTypeByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException; void deleteApplication(int appId, int tenantId) throws ApplicationManagementDAOException; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/main/java/org/wso2/carbon/device/application/mgt/core/dao/impl/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 d3f79ab433..d69897fc4c 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 @@ -24,7 +24,6 @@ import org.apache.commons.logging.LogFactory; import org.json.JSONException; import org.wso2.carbon.device.application.mgt.common.AppLifecycleState; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; -import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO; import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO; import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.dto.TagDTO; @@ -94,36 +93,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } - @Override - public boolean isExistApplication(String appName, String type, int tenantId) throws ApplicationManagementDAOException { - if (log.isDebugEnabled()) { - log.debug("Request received in DAO Layer to verify whether the registering app is registered or not"); - } - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - String sql = "SELECT * FROM AP_APP WHERE NAME = ? AND TYPE = ? AND TENANT_ID = ?"; - try { - conn = this.getDBConnection(); - conn.setAutoCommit(false); - stmt = conn.prepareStatement(sql); - stmt.setString(1, appName); - stmt.setString(2, type); - stmt.setInt(3, tenantId); - rs = stmt.executeQuery(); - return rs.next(); - - } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException( - "Error occurred while obtaining the DB connection when verifying application existence", e); - } catch (SQLException e) { - throw new ApplicationManagementDAOException( - "DB connection error occured while checking whether application exist or not.", e); - } finally { - DAOUtil.cleanupResources(stmt, rs); - } - } - @Override public List getApplications(Filter filter,int deviceTypeId, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { @@ -344,96 +313,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic return count; } - @Override - public ApplicationDTO getApplication(String appName, String appType, int tenantId) throws - ApplicationManagementDAOException { - if (log.isDebugEnabled()) { - log.debug("Getting application with the type(" + appType + " and Name " + appName + - " ) from the database"); - } - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - 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.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, AP_APP_TAG, AP_UNRESTRICTED_ROLE WHERE AP_APP.NAME=? AND " - + "AP_APP.TYPE= ? AND AP_APP.TENANT_ID=?;"; - - stmt = conn.prepareStatement(sql); - stmt.setString(1, appName); - stmt.setString(2, appType); - stmt.setInt(3, tenantId); - rs = stmt.executeQuery(); - - if (log.isDebugEnabled()) { - log.debug("Successfully retrieved basic details of the application with the type " - + appType + "and app name " + appName); - } - - return DAOUtil.loadApplication(rs); - - } catch (SQLException e) { - throw new ApplicationManagementDAOException( - "Error occurred while getting application details with app name " + appName + - " while executing query.", e); - } catch (JSONException e) { - throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); - } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); - } catch (UnexpectedServerErrorException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); - } finally { - DAOUtil.cleanupResources(stmt, rs); - } - } - - @Override - public ApplicationDTO getApplicationById(String id, int tenantId) throws ApplicationManagementDAOException { - if (log.isDebugEnabled()) { - log.debug("Getting application with the id:" + id); - } - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - 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.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, AP_APP_TAG, AP_UNRESTRICTED_ROLE WHERE AP_APP.NAME=? AND " - + "AP_APP.APP_ID= ? AND AP_APP.TENANT_ID=?;"; - - stmt = conn.prepareStatement(sql); - stmt.setString(1, id); - stmt.setInt(2, tenantId); - rs = stmt.executeQuery(); - - if (log.isDebugEnabled()) { - log.debug("Successfully retrieved basic details of the application with the id:" + id); - } - - return DAOUtil.loadApplication(rs); - - } catch (SQLException e) { - throw new ApplicationManagementDAOException( - "Error occurred while getting application details with app id " + id + - " while executing query.", e); - } catch (JSONException e) { - throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); - } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); - } catch (UnexpectedServerErrorException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); - } finally { - DAOUtil.cleanupResources(stmt, rs); - } - } - @Override public ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId) throws ApplicationManagementDAOException { @@ -581,39 +460,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } } - @Override - public boolean verifyApplicationExistenceById(int appId, int tenantId) throws ApplicationManagementDAOException { - if (log.isDebugEnabled()) { - log.debug("Getting application with the application ID(" + appId + " ) from the database"); - } - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - conn = this.getDBConnection(); - String sql = - "SELECT AP_APP.ID AS APP_ID FROM AP_APP WHERE AP_APP.ID = ? AND AP_APP.TENANT_ID=?;"; - - stmt = conn.prepareStatement(sql); - stmt.setInt(1, appId); - stmt.setInt(2, tenantId); - rs = stmt.executeQuery(); - - if (log.isDebugEnabled()) { - log.debug("Successfully retrieved basic details of the application with the application ID " + appId); - } - return rs.next(); - } catch (SQLException e) { - throw new ApplicationManagementDAOException( - "Error occurred while getting application details with app ID " + appId + " while executing query.", - e); - } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); - } finally { - DAOUtil.cleanupResources(stmt, rs); - } - } - @Override public boolean updateApplication(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementDAOException { @@ -1532,76 +1378,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic } @Override - public ApplicationDTO getApplicationByRelease(String appReleaseUUID, int tenantId) - throws ApplicationManagementDAOException { - if (log.isDebugEnabled()) { - log.debug("Getting application with the UUID (" + appReleaseUUID + ") from the database"); - } - Connection conn; - PreparedStatement stmt = null; - ResultSet rs = null; - try { - conn = this.getDBConnection(); - String sql = "SELECT AP_APP_RELEASE.ID AS RELEASE_ID, AP_APP_RELEASE.VERSION, AP_APP_RELEASE.TENANT_ID," - + "AP_APP_RELEASE.UUID, AP_APP_RELEASE.RELEASE_TYPE, AP_APP_RELEASE.APP_PRICE, " - + "AP_APP_RELEASE.STORED_LOCATION, AP_APP_RELEASE.BANNER_LOCATION, AP_APP_RELEASE.SC_1_LOCATION," - + "AP_APP_RELEASE.SC_2_LOCATION, AP_APP_RELEASE.SC_3_LOCATION, AP_APP_RELEASE.APP_HASH_VALUE," - + "AP_APP_RELEASE.SHARED_WITH_ALL_TENANTS, AP_APP_RELEASE.APP_META_INFO, AP_APP_RELEASE.CREATED_BY," - + "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.SUB_TYPE AS SUB_TYPE, AP_APP.CURRENCY AS CURRENCY, " - + "AP_UNRESTRICTED_ROLE.ROLE AS ROLE FROM AP_APP, AP_UNRESTRICTED_ROLE, AP_APP_RELEASE " - + "WHERE AP_APP_RELEASE.UUID=? AND AP_APP.TENANT_ID=?;"; - - stmt = conn.prepareStatement(sql); - stmt.setString(1, appReleaseUUID); - stmt.setInt(2, tenantId); - rs = stmt.executeQuery(); - - if (log.isDebugEnabled()) { - log.debug("Successfully retrieved details of the application with the UUID " + appReleaseUUID); - } - - ApplicationDTO application = null; - while (rs.next()) { - ApplicationReleaseDTO appRelease = DAOUtil.loadApplicationRelease(rs); - application = new ApplicationDTO(); - - application.setId(rs.getInt("APP_ID")); - application.setName(rs.getString("APP_NAME")); - application.setType(rs.getString("APP_TYPE")); -// application.setAppCategories(rs.getString("APP_CATEGORY")); - application.setSubType(rs.getString("SUB_TYPE")); - application.setPaymentCurrency(rs.getString("CURRENCY")); -// application.setIsRestricted(rs.getBoolean("RESTRICTED")); - - String unrestrictedRole = rs.getString("ROLE").toLowerCase(); - List unrestrictedRoleList = new ArrayList<>(); - unrestrictedRoleList.add(unrestrictedRole); - - application.setUnrestrictedRoles(unrestrictedRoleList); - - List applicationReleaseList = new ArrayList<>(); - applicationReleaseList.add(appRelease); - - application.setApplicationReleaseDTOs(applicationReleaseList); - } - return application; - } catch (SQLException e) { - throw new ApplicationManagementDAOException("Error occurred while getting application details with UUID " - + appReleaseUUID + " while executing query.", e); - } catch (JSONException e) { - throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e); - } catch (DBConnectionException e) { - throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); - } finally { - DAOUtil.cleanupResources(stmt, rs); - } - } - - @Override - public boolean isValidAppName(String appName, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException { + public boolean isExistingAppName(String appName, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException { Connection conn; PreparedStatement stmt = null; ResultSet rs = null; 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 c940fa7ab4..4b3fff7d4a 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 @@ -25,7 +25,6 @@ import org.apache.commons.validator.routines.UrlValidator; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact; @@ -91,7 +90,6 @@ import org.wso2.carbon.device.mgt.core.dto.DeviceType; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; -import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -132,12 +130,6 @@ public class ApplicationManagerImpl implements ApplicationManager { this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO(); } - /*** - * The responsbility of this method is the creating an application. - * @param applicationWrapper ApplicationDTO that need to be created. - * @return {@link ApplicationDTO} - * @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException} - */ @Override public Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { @@ -145,7 +137,7 @@ public class ApplicationManagerImpl implements ApplicationManager { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); if (log.isDebugEnabled()) { - log.debug("Application create request is received for the tenant : " + tenantId + " and" + " the user : " + log.debug("Application create request is received for the tenant : " + tenantId + " and the user: " + userName); } @@ -176,7 +168,6 @@ public class ApplicationManagerImpl implements ApplicationManager { private void deleteApplicationArtifacts(List directoryPaths) throws ApplicationManagementException { ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); - try { applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths); } catch (ApplicationStorageManagementException e) { @@ -1114,107 +1105,6 @@ public class ApplicationManagerImpl implements ApplicationManager { return roleList; } - //todo no usage - public ApplicationDTO getApplication(String appType, String appName) throws ApplicationManagementException { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - ApplicationDTO application; - boolean isAppAllowed = false; - List applicationReleases; - try { - ConnectionManagerUtil.openDBConnection(); - application = this.applicationDAO.getApplication(appName, appType, tenantId); - if (isAdminUser(userName, tenantId, CarbonConstants.UI_ADMIN_PERMISSION_COLLECTION)) { - applicationReleases = getReleases(application, null); - application.setApplicationReleaseDTOs(applicationReleases); - return application; - } - - if (!application.getUnrestrictedRoles().isEmpty()) { - if (hasUserRole(application.getUnrestrictedRoles(), userName)) { - isAppAllowed = true; - } - } else { - isAppAllowed = true; - } - - if (!isAppAllowed) { - return null; - } - - applicationReleases = getReleases(application, null); - application.setApplicationReleaseDTOs(applicationReleases); - return application; - } catch (UserStoreException e) { - throw new ApplicationManagementException( - "User-store exception while getting application with the " + "application name " + appName); - } catch (ApplicationManagementDAOException e) { - //todo - throw new ApplicationManagementException(""); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } - } - - @Override public ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); - ApplicationDTO application; - try { - ConnectionManagerUtil.openDBConnection(); - application = this.applicationDAO.getApplicationByRelease(appReleaseUUID, tenantId); - - if (application.getUnrestrictedRoles().isEmpty() || hasUserRole(application.getUnrestrictedRoles(), - userName)) { - return application; - } - return null; - } catch (UserStoreException e) { - throw new ApplicationManagementException( - "User-store exception while getting application with the application UUID " + appReleaseUUID); - } catch (ApplicationManagementDAOException e) { - //todo - throw new ApplicationManagementException(""); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } - } - - // todo rethink about this method - private List getReleases(ApplicationDTO application, String releaseState) - throws ApplicationManagementException { - int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); - List applicationReleases; - if (log.isDebugEnabled()) { - log.debug("Request is received to retrieve all the releases related with the application " + application - .toString()); - } - //todo - applicationReleases = null; - try { - applicationReleases = this.applicationReleaseDAO.getReleases(application.getId(), tenantId); - } catch (ApplicationManagementDAOException e) { - //todo - throw new ApplicationManagementException(""); - } - for (ApplicationReleaseDTO applicationRelease : applicationReleases) { - LifecycleState lifecycleState = null; - try { - lifecycleState = this.lifecycleStateDAO.getLatestLifeCycleStateByReleaseID(applicationRelease.getId()); - } catch (LifeCycleManagementDAOException e) { - throw new ApplicationManagementException( - "Error occurred while getting the latest lifecycle state for the application release UUID: " - + applicationRelease.getUuid(), e); - } - if (lifecycleState != null) { - log.error("todo"); -// applicationRelease.setLifecycleState(lifecycleState); - } - } - return applicationReleases; -// return filterAppReleaseByCurrentState(applicationReleases, releaseState); - } - @Override public void deleteApplication(int applicationId) throws ApplicationManagementException { if (log.isDebugEnabled()) { @@ -1364,39 +1254,6 @@ public class ApplicationManagerImpl implements ApplicationManager { } } - /** - * To check whether current user has the permission to do some secured operation. - * - * @param username Name of the User. - * @param tenantId ID of the tenant. - * @param permission Permission that need to be checked. - * @return true if the current user has the permission, otherwise false. - * @throws UserStoreException UserStoreException - */ - private boolean isAdminUser(String username, int tenantId, String permission) throws UserStoreException { - UserRealm userRealm = DataHolder.getInstance().getRealmService().getTenantUserRealm(tenantId); - return userRealm != null && userRealm.getAuthorizationManager() != null && userRealm.getAuthorizationManager() - .isUserAuthorized(MultitenantUtils.getTenantAwareUsername(username), permission, - CarbonConstants.UI_PERMISSION_ACTION); - } - - /*** - * To verify whether application type is valid one or not - * @param appType application type {@link ApplicationType} - * @return true returns if appType is valid on, otherwise returns false - */ - private boolean isValidAppType(String appType) { - if (appType == null) { - return false; - } - for (ApplicationType applicationType : ApplicationType.values()) { - if (applicationType.toString().equals(appType)) { - return true; - } - } - return false; - } - @Override public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { @@ -2295,7 +2152,11 @@ public class ApplicationManagerImpl implements ApplicationManager { String supportedOSVersions = applicationReleaseWrapper.getSupportedOsVersions(); if (!StringUtils.isEmpty(supportedOSVersions)) { - //todo check OS versions are supported or not + if (!isValidOsVersions(supportedOSVersions, deviceType)){ + String msg = "You are trying to update application release which has invalid or unsupported OS " + + "versions in the supportedOsVersions section. Hence, please re-evaluate the request payload."; + log.error(msg); + throw new BadRequestException(msg); } applicationReleaseDTO.setSupportedOsVersions(supportedOSVersions); } if (!StringUtils.isEmpty(applicationReleaseWrapper.getDescription())) { @@ -2593,7 +2454,6 @@ public class ApplicationManagerImpl implements ApplicationManager { } } - @Override public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List attachmentList) throws RequestValidatingException { diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java index 9ec92e1820..3942735da2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java @@ -35,190 +35,190 @@ public class ApplicationManagementTest extends BaseTestCase { private static final Log log = LogFactory.getLog(ApplicationManagementTest.class); - @Test - public void testAddApplication() throws Exception { - - ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); - ConnectionManagerUtil.beginDBTransaction(); - applicationDAO.createApplication(ApplicationsDTO.getApp1(), -1234); - ConnectionManagerUtil.commitDBTransaction(); - ConnectionManagerUtil.closeDBConnection(); - } - - @Test(dependsOnMethods = ("addAplicationCategories")) - public void createApplication() throws Exception { - - log.debug("Creating the first application ....!"); - - ApplicationWrapper applicationWrapper = new ApplicationWrapper(); - - List categories = new ArrayList<>(); - categories.add("Test Category"); - applicationWrapper.setAppCategories(categories); - - applicationWrapper.setDescription("Test Description"); - applicationWrapper.setDeviceType("android"); - applicationWrapper.setName("Test Application"); - applicationWrapper.setSubType("Test Sub type"); - - List tags = new ArrayList<>(); - tags.add("abc"); - tags.add("pqr"); - tags.add("xyz"); - applicationWrapper.setTags(tags); - applicationWrapper.setPaymentCurrency("USD"); - - List applicationReleaseWrappers = new ArrayList<>(); - ApplicationReleaseWrapper releaseWrapper = new ApplicationReleaseWrapper(); - releaseWrapper.setDescription("First release"); - releaseWrapper.setIsSharedWithAllTenants(false); - releaseWrapper.setMetaData("Just meta data"); - releaseWrapper.setReleaseType("free"); - releaseWrapper.setPrice(5.7); - releaseWrapper.setSupportedOsVersions("4.0-7.0"); - applicationReleaseWrappers.add(releaseWrapper); - - applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers); - - ApplicationArtifact applicationArtifact = new ApplicationArtifact(); - applicationArtifact.setBannerName("My First Banner"); - File banner = new File("src/test/resources/samples/app1/banner1.jpg"); - InputStream bannerStream = new FileInputStream(banner); - applicationArtifact.setBannerStream(bannerStream); - applicationArtifact.setIconName("My First Icon"); - applicationArtifact.setIconStream(new FileInputStream(new File("src/test/resources/samples/app1/icon.png"))); - applicationArtifact.setInstallerName("Test Android App"); - applicationArtifact.setInstallerStream(new FileInputStream(new File("src/test/resources/samples/app1/sample.apk"))); - - Map screenshots = new HashMap<>(); - screenshots.put("shot1", new FileInputStream(new File("src/test/resources/samples/app1/shot1.png"))); - screenshots.put("shot2", new FileInputStream(new File("src/test/resources/samples/app1/shot2.png"))); - screenshots.put("shot3", new FileInputStream(new File("src/test/resources/samples/app1/shot3.png"))); - - applicationArtifact.setScreenshots(screenshots); - - ApplicationManager manager = new ApplicationManagerImpl(); - manager.createApplication(applicationWrapper, applicationArtifact); - } - - @Test - public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { - - } - - @Test - public void deleteApplication(int applicationId) throws ApplicationManagementException { - - } - - @Test - public void retireApplication(int applicationId) throws ApplicationManagementException { - - } - - @Test - public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException { - - } - - @Test - public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { - return null; - } - - @Test - public Application getApplicationById(int id, String state) throws ApplicationManagementException { - return null; - } - - @Test - public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException { - return null; - } - - @Test - public ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException { - return null; - } - - @Test - public ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException { - return null; - } - - @Test - public List getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException { - return null; - } - - @Test - public void changeLifecycleState(String releaseUuid, String stateName) throws ApplicationManagementException { - - } - - @Test - public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { - - } - - @Test - public void updateApplicationArtifact(String deviceType, String appType, String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { - - } - - @Test - public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { - return null; - } - - @Test - public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { - return false; - } - - @Test - public void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException { - - } - - @Test - public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType) throws RequestValidatingException { - - } - - @Test - public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List attachmentList) throws RequestValidatingException { - - } - - @Test - public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException { - - } - - @Test - public void addAplicationCategories() throws ApplicationManagementException { - - List categories = new ArrayList<>(); - categories.add("Test Category"); - categories.add("Test Category2"); - ApplicationManager manager = new ApplicationManagerImpl(); - manager.addApplicationCategories(categories); - - } - - @Test - public List getRegisteredTags() throws ApplicationManagementException { - return null; - } - - @Test - public List getRegisteredCategories() throws ApplicationManagementException { - return null; - } - - @Test - public void deleteTagMapping(int appId, String tagName) throws ApplicationManagementException { - - } +// @Test +// public void testAddApplication() throws Exception { +// +// ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); +// ConnectionManagerUtil.beginDBTransaction(); +// applicationDAO.createApplication(ApplicationsDTO.getApp1(), -1234); +// ConnectionManagerUtil.commitDBTransaction(); +// ConnectionManagerUtil.closeDBConnection(); +// } +// +// @Test(dependsOnMethods = ("addAplicationCategories")) +// public void createApplication() throws Exception { +// +// log.debug("Creating the first application ....!"); +// +// ApplicationWrapper applicationWrapper = new ApplicationWrapper(); +// +// List categories = new ArrayList<>(); +// categories.add("Test Category"); +// applicationWrapper.setAppCategories(categories); +// +// applicationWrapper.setDescription("Test Description"); +// applicationWrapper.setDeviceType("android"); +// applicationWrapper.setName("Test Application"); +// applicationWrapper.setSubType("Test Sub type"); +// +// List tags = new ArrayList<>(); +// tags.add("abc"); +// tags.add("pqr"); +// tags.add("xyz"); +// applicationWrapper.setTags(tags); +// applicationWrapper.setPaymentCurrency("USD"); +// +// List applicationReleaseWrappers = new ArrayList<>(); +// ApplicationReleaseWrapper releaseWrapper = new ApplicationReleaseWrapper(); +// releaseWrapper.setDescription("First release"); +// releaseWrapper.setIsSharedWithAllTenants(false); +// releaseWrapper.setMetaData("Just meta data"); +// releaseWrapper.setReleaseType("free"); +// releaseWrapper.setPrice(5.7); +// releaseWrapper.setSupportedOsVersions("4.0-7.0"); +// applicationReleaseWrappers.add(releaseWrapper); +// +// applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers); +// +// ApplicationArtifact applicationArtifact = new ApplicationArtifact(); +// applicationArtifact.setBannerName("My First Banner"); +// File banner = new File("src/test/resources/samples/app1/banner1.jpg"); +// InputStream bannerStream = new FileInputStream(banner); +// applicationArtifact.setBannerStream(bannerStream); +// applicationArtifact.setIconName("My First Icon"); +// applicationArtifact.setIconStream(new FileInputStream(new File("src/test/resources/samples/app1/icon.png"))); +// applicationArtifact.setInstallerName("Test Android App"); +// applicationArtifact.setInstallerStream(new FileInputStream(new File("src/test/resources/samples/app1/sample.apk"))); +// +// Map screenshots = new HashMap<>(); +// screenshots.put("shot1", new FileInputStream(new File("src/test/resources/samples/app1/shot1.png"))); +// screenshots.put("shot2", new FileInputStream(new File("src/test/resources/samples/app1/shot2.png"))); +// screenshots.put("shot3", new FileInputStream(new File("src/test/resources/samples/app1/shot3.png"))); +// +// applicationArtifact.setScreenshots(screenshots); +// +// ApplicationManager manager = new ApplicationManagerImpl(); +// manager.createApplication(applicationWrapper, applicationArtifact); +// } +// +// @Test +// public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { +// +// } +// +// @Test +// public void deleteApplication(int applicationId) throws ApplicationManagementException { +// +// } +// +// @Test +// public void retireApplication(int applicationId) throws ApplicationManagementException { +// +// } +// +// @Test +// public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException { +// +// } +// +// @Test +// public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { +// return null; +// } +// +// @Test +// public Application getApplicationById(int id, String state) throws ApplicationManagementException { +// return null; +// } +// +// @Test +// public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException { +// return null; +// } +// +// @Test +// public ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException { +// return null; +// } +// +// @Test +// public ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException { +// return null; +// } +// +// @Test +// public List getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException { +// return null; +// } +// +// @Test +// public void changeLifecycleState(String releaseUuid, String stateName) throws ApplicationManagementException { +// +// } +// +// @Test +// public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { +// +// } +// +// @Test +// public void updateApplicationArtifact(String deviceType, String appType, String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { +// +// } +// +// @Test +// public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { +// return null; +// } +// +// @Test +// public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { +// return false; +// } +// +// @Test +// public void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException { +// +// } +// +// @Test +// public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType) throws RequestValidatingException { +// +// } +// +// @Test +// public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List attachmentList) throws RequestValidatingException { +// +// } +// +// @Test +// public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException { +// +// } +// +// @Test +// public void addAplicationCategories() throws ApplicationManagementException { +// +// List categories = new ArrayList<>(); +// categories.add("Test Category"); +// categories.add("Test Category2"); +// ApplicationManager manager = new ApplicationManagerImpl(); +// manager.addApplicationCategories(categories); +// +// } +// +// @Test +// public List getRegisteredTags() throws ApplicationManagementException { +// return null; +// } +// +// @Test +// public List getRegisteredCategories() throws ApplicationManagementException { +// return null; +// } +// +// @Test +// public void deleteTagMapping(int appId, String tagName) throws ApplicationManagementException { +// +// } } From aa247bc1f25c64feed65af2b024f2a9ac3ee90a0 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 21 Jun 2019 15:10:18 +0530 Subject: [PATCH 3/4] Improve publisher review management --- .../management/ApplicationManagementTest.java | 410 ++++++++++-------- .../admin/ReviewManagementAdminAPI.java | 313 +++++++++++++ .../admin/ReviewManagementAdminAPIImpl.java | 79 +++- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 + .../api/services/ReviewManagementAPI.java | 214 +++------ .../admin/ReviewManagementAdminAPI.java | 174 -------- .../impl/ReviewManagementAPIImpl.java | 48 -- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 - .../main/resources/conf/application-mgt.xml | 1 + 9 files changed, 679 insertions(+), 564 deletions(-) create mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ReviewManagementAdminAPI.java rename components/application-mgt/{org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store => org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher}/api/services/impl/admin/ReviewManagementAdminAPIImpl.java (54%) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/ReviewManagementAdminAPI.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java index 3942735da2..fce6bc41a9 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.core/src/test/java/org.wso2.carbon.device.application.mgt.core/management/ApplicationManagementTest.java @@ -22,6 +22,10 @@ import org.wso2.carbon.device.application.mgt.core.dao.common.ApplicationManagem import org.wso2.carbon.device.application.mgt.core.dto.ApplicationsDTO; import org.wso2.carbon.device.application.mgt.core.impl.ApplicationManagerImpl; import org.wso2.carbon.device.application.mgt.core.util.ConnectionManagerUtil; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.core.dto.DeviceType; +import org.wso2.carbon.device.mgt.core.dto.DeviceTypeVersion; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderServiceImpl; import java.io.File; import java.io.FileInputStream; @@ -35,190 +39,224 @@ public class ApplicationManagementTest extends BaseTestCase { private static final Log log = LogFactory.getLog(ApplicationManagementTest.class); -// @Test -// public void testAddApplication() throws Exception { -// -// ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); -// ConnectionManagerUtil.beginDBTransaction(); -// applicationDAO.createApplication(ApplicationsDTO.getApp1(), -1234); -// ConnectionManagerUtil.commitDBTransaction(); -// ConnectionManagerUtil.closeDBConnection(); -// } -// -// @Test(dependsOnMethods = ("addAplicationCategories")) -// public void createApplication() throws Exception { -// -// log.debug("Creating the first application ....!"); -// -// ApplicationWrapper applicationWrapper = new ApplicationWrapper(); -// -// List categories = new ArrayList<>(); -// categories.add("Test Category"); -// applicationWrapper.setAppCategories(categories); -// -// applicationWrapper.setDescription("Test Description"); -// applicationWrapper.setDeviceType("android"); -// applicationWrapper.setName("Test Application"); -// applicationWrapper.setSubType("Test Sub type"); -// -// List tags = new ArrayList<>(); -// tags.add("abc"); -// tags.add("pqr"); -// tags.add("xyz"); -// applicationWrapper.setTags(tags); -// applicationWrapper.setPaymentCurrency("USD"); -// -// List applicationReleaseWrappers = new ArrayList<>(); -// ApplicationReleaseWrapper releaseWrapper = new ApplicationReleaseWrapper(); -// releaseWrapper.setDescription("First release"); -// releaseWrapper.setIsSharedWithAllTenants(false); -// releaseWrapper.setMetaData("Just meta data"); -// releaseWrapper.setReleaseType("free"); -// releaseWrapper.setPrice(5.7); -// releaseWrapper.setSupportedOsVersions("4.0-7.0"); -// applicationReleaseWrappers.add(releaseWrapper); -// -// applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers); -// -// ApplicationArtifact applicationArtifact = new ApplicationArtifact(); -// applicationArtifact.setBannerName("My First Banner"); -// File banner = new File("src/test/resources/samples/app1/banner1.jpg"); -// InputStream bannerStream = new FileInputStream(banner); -// applicationArtifact.setBannerStream(bannerStream); -// applicationArtifact.setIconName("My First Icon"); -// applicationArtifact.setIconStream(new FileInputStream(new File("src/test/resources/samples/app1/icon.png"))); -// applicationArtifact.setInstallerName("Test Android App"); -// applicationArtifact.setInstallerStream(new FileInputStream(new File("src/test/resources/samples/app1/sample.apk"))); -// -// Map screenshots = new HashMap<>(); -// screenshots.put("shot1", new FileInputStream(new File("src/test/resources/samples/app1/shot1.png"))); -// screenshots.put("shot2", new FileInputStream(new File("src/test/resources/samples/app1/shot2.png"))); -// screenshots.put("shot3", new FileInputStream(new File("src/test/resources/samples/app1/shot3.png"))); -// -// applicationArtifact.setScreenshots(screenshots); -// -// ApplicationManager manager = new ApplicationManagerImpl(); -// manager.createApplication(applicationWrapper, applicationArtifact); -// } -// -// @Test -// public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { -// -// } -// -// @Test -// public void deleteApplication(int applicationId) throws ApplicationManagementException { -// -// } -// -// @Test -// public void retireApplication(int applicationId) throws ApplicationManagementException { -// -// } -// -// @Test -// public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException { -// -// } -// -// @Test -// public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { -// return null; -// } -// -// @Test -// public Application getApplicationById(int id, String state) throws ApplicationManagementException { -// return null; -// } -// -// @Test -// public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException { -// return null; -// } -// -// @Test -// public ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException { -// return null; -// } -// -// @Test -// public ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException { -// return null; -// } -// -// @Test -// public List getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException { -// return null; -// } -// -// @Test -// public void changeLifecycleState(String releaseUuid, String stateName) throws ApplicationManagementException { -// -// } -// -// @Test -// public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { -// -// } -// -// @Test -// public void updateApplicationArtifact(String deviceType, String appType, String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { -// -// } -// -// @Test -// public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { -// return null; -// } -// -// @Test -// public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { -// return false; -// } -// -// @Test -// public void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException { -// -// } -// -// @Test -// public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType) throws RequestValidatingException { -// -// } -// -// @Test -// public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List attachmentList) throws RequestValidatingException { -// -// } -// -// @Test -// public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException { -// -// } -// -// @Test -// public void addAplicationCategories() throws ApplicationManagementException { -// -// List categories = new ArrayList<>(); -// categories.add("Test Category"); -// categories.add("Test Category2"); -// ApplicationManager manager = new ApplicationManagerImpl(); -// manager.addApplicationCategories(categories); -// -// } -// -// @Test -// public List getRegisteredTags() throws ApplicationManagementException { -// return null; -// } -// -// @Test -// public List getRegisteredCategories() throws ApplicationManagementException { -// return null; -// } -// -// @Test -// public void deleteTagMapping(int appId, String tagName) throws ApplicationManagementException { -// -// } + @Test + public void testAddApplication() throws Exception { + + ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); + ConnectionManagerUtil.beginDBTransaction(); + applicationDAO.createApplication(ApplicationsDTO.getApp1(), -1234); + ConnectionManagerUtil.commitDBTransaction(); + ConnectionManagerUtil.closeDBConnection(); + } + + @Test(dependsOnMethods = ("addApplicationCategories")) + public void createApplication() throws Exception { + + log.debug("Creating the first application ....!"); + + ApplicationWrapper applicationWrapper = new ApplicationWrapper(); + + List categories = new ArrayList<>(); + categories.add("Test Category"); + applicationWrapper.setAppCategories(categories); + + applicationWrapper.setDescription("Test Description"); + applicationWrapper.setDeviceType("android"); + applicationWrapper.setName("Test Application"); + applicationWrapper.setSubType("Test Sub type"); + + List tags = new ArrayList<>(); + tags.add("abc"); + tags.add("pqr"); + tags.add("xyz"); + applicationWrapper.setTags(tags); + applicationWrapper.setPaymentCurrency("USD"); + + List applicationReleaseWrappers = new ArrayList<>(); + ApplicationReleaseWrapper releaseWrapper = new ApplicationReleaseWrapper(); + releaseWrapper.setDescription("First release"); + releaseWrapper.setIsSharedWithAllTenants(false); + releaseWrapper.setMetaData("Just meta data"); + releaseWrapper.setReleaseType("free"); + releaseWrapper.setPrice(5.7); + releaseWrapper.setSupportedOsVersions("4.0-7.0"); + applicationReleaseWrappers.add(releaseWrapper); + + applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers); + + ApplicationArtifact applicationArtifact = new ApplicationArtifact(); + applicationArtifact.setBannerName("My First Banner"); + File banner = new File("src/test/resources/samples/app1/banner1.jpg"); + InputStream bannerStream = new FileInputStream(banner); + applicationArtifact.setBannerStream(bannerStream); + applicationArtifact.setIconName("My First Icon"); + applicationArtifact.setIconStream(new FileInputStream(new File("src/test/resources/samples/app1/icon.png"))); + applicationArtifact.setInstallerName("Test Android App"); + applicationArtifact.setInstallerStream(new FileInputStream(new File("src/test/resources/samples/app1/sample.apk"))); + + Map screenshots = new HashMap<>(); + screenshots.put("shot1", new FileInputStream(new File("src/test/resources/samples/app1/shot1.png"))); + screenshots.put("shot2", new FileInputStream(new File("src/test/resources/samples/app1/shot2.png"))); + screenshots.put("shot3", new FileInputStream(new File("src/test/resources/samples/app1/shot3.png"))); + + applicationArtifact.setScreenshots(screenshots); + + ApplicationManager manager = new ApplicationManagerImpl(); + manager.createApplication(applicationWrapper, applicationArtifact); + } + + @Test + public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { + + } + + @Test + public void deleteApplication(int applicationId) throws ApplicationManagementException { + + } + + @Test + public void retireApplication(int applicationId) throws ApplicationManagementException { + + } + + @Test + public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException { + + } + + @Test + public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { + return null; + } + + @Test + public Application getApplicationById(int id, String state) throws ApplicationManagementException { + return null; + } + + @Test + public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException { + return null; + } + + @Test + public ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException { + return null; + } + + @Test + public ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException { + return null; + } + + @Test + public List getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException { + return null; + } + + @Test + public void changeLifecycleState(String releaseUuid, String stateName) throws ApplicationManagementException { + + } + + @Test + public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { + + } + + @Test + public void updateApplicationArtifact(String deviceType, String appType, String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { + + } + + @Test + public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { + return null; + } + + @Test + public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { + return false; + } + + @Test + public void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException { + + } + + @Test + public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType) throws RequestValidatingException { + + } + + @Test + public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List attachmentList) throws RequestValidatingException { + + } + + @Test + public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException { + + } + + @Test(dependsOnMethods = ("addDeviceVersions")) + public void addApplicationCategories() throws ApplicationManagementException { + List categories = new ArrayList<>(); + categories.add("Test Category"); + categories.add("Test Category2"); + ApplicationManager manager = new ApplicationManagerImpl(); + manager.addApplicationCategories(categories); + + } + + @Test + public void addDeviceVersions() throws ApplicationManagementException { + List deviceTypeVersions = new ArrayList<>(); + List supportingVersions = new ArrayList<>(); + + //add supporting versions + supportingVersions.add("4.0"); + supportingVersions.add("5.0"); + supportingVersions.add("6.0"); + supportingVersions.add("7.0"); + supportingVersions.add("8.0"); + + DeviceManagementProviderServiceImpl deviceManagementProviderService = new DeviceManagementProviderServiceImpl(); + try { + List deviceTypes = deviceManagementProviderService.getDeviceTypes(); + + for (DeviceType deviceType: deviceTypes){ + for (String version : supportingVersions){ + DeviceTypeVersion deviceTypeVersion = new DeviceTypeVersion(); + deviceTypeVersion.setDeviceTypeId(deviceType.getId()); + deviceTypeVersion.setVersionName(version); + deviceTypeVersions.add(deviceTypeVersion); + } + } + + for (DeviceTypeVersion deviceTypeVersion : deviceTypeVersions){ + deviceManagementProviderService.addDeviceTypeVersion(deviceTypeVersion); + } + } catch (DeviceManagementException e) { + String msg = "Error Occured while adding device type versions"; + log.error(msg); + throw new ApplicationManagementException(msg); + } + } + + @Test + public List getRegisteredTags() throws ApplicationManagementException { + return null; + } + + @Test + public List getRegisteredCategories() throws ApplicationManagementException { + return null; + } + + @Test + public void deleteTagMapping(int appId, String tagName) throws ApplicationManagementException { + + } } 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/admin/ReviewManagementAdminAPI.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/admin/ReviewManagementAdminAPI.java new file mode 100644 index 0000000000..2ed8047ef7 --- /dev/null +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/admin/ReviewManagementAdminAPI.java @@ -0,0 +1,313 @@ +/* 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. + */ +package org.wso2.carbon.device.application.mgt.publisher.api.services.admin; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Info; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Tag; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.application.mgt.common.ErrorResponse; +import org.wso2.carbon.device.application.mgt.common.PaginationResult; +import org.wso2.carbon.device.application.mgt.common.response.Review; +import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper; + +import javax.validation.Valid; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.PUT; +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.List; + +/** +* APIs to handle admin review management related tasks in publisher. +*/ + +@SwaggerDefinition( +info = @Info( + version = "1.0.0", + title = "Publisher Review Management Admin Service", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "PublisherReviewManagementAdminService"), + @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/admin/review"), + }) + } +), +tags = { + @Tag(name = "review_management", description = "Publisher Review Management related Admin APIs") +} +) +@Scopes( +scopes = { + @Scope( + name = "Update a Review", + description = "Update a Review of applications.", + key = "perm:admin:app:review:update", + permissions = {"/app-mgt/publisher/admin/review/update"} + ), + @Scope( + name = "Get Review Details", + description = "Get review details of applications.", + key = "perm:admin:app:review:view", + permissions = {"/app-mgt/publisher/admin/review/view"} + ) +} +) + +@Path("/admin/reviews") +@Api(value = "Publisher Review Management Admin API") +@Produces(MediaType.APPLICATION_JSON) +public interface ReviewManagementAdminAPI { +String SCOPE = "scope"; + + @PUT + @Path("/{uuid}/{reviewId}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Edit a review", + notes = "This will edit the review", + tags = "Review Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:update") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully updated reviewTmp.", + response = Review.class), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while updating the new reviewTmp.", + response = ErrorResponse.class) + }) + Response updateReview( + @ApiParam( + name = "reviewTmp", + value = "The review that need to be updated.", + required = true) + @Valid ReviewWrapper updatingReview, + @ApiParam( + name = "uuid", + value = "uuid of the application release", + required = true) + @PathParam("uuid") String uuid, + @ApiParam( + name = "reviewId", + value = "review id of the updating reviewTmp.", + required = true) + @PathParam("reviewId") int reviewId); + + @DELETE + @Path("/{uuid}/{reviewId}") + @Produces(MediaType.APPLICATION_JSON) + @Consumes(MediaType.APPLICATION_JSON) + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "DELETE", + value = "Remove review", + notes = "Remove review", + tags = "Review Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:update") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully deleted the review"), + @ApiResponse( + code = 404, + message = "Not Found. \n No activity found with the given ID.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while deleting the review.", + response = ErrorResponse.class) + }) + + Response deleteReview( + @ApiParam( + name = "uuid", + value = "UUID of the application release.", + required = true) + @PathParam("uuid") String uuid, + @ApiParam( + name = "reviewId", + value = "Id of the review.", + required = true) + @PathParam("reviewId") int reviewId); + + @GET + @Path("/release/{uuid}") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "get app release reviews", + notes = "Get all app release reviews", + tags = "Review Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:view") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved app release reviews.", + response = PaginationResult.class, + responseContainer = "PaginationResult"), + @ApiResponse( + code = 404, + message = "Not Found. \n Not found an application release for requested UUID."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the review list.", + response = ErrorResponse.class) + }) + + Response getAllReleaseReviews( + @ApiParam( + name = "uuid", + value = "uuid of the application release.", + required = true) + @PathParam("uuid") String uuid, + @ApiParam( + name = "offset", + value = "Starting review number.", + defaultValue = "0") + @QueryParam("offSet") int offSet, + @ApiParam( + name = "limit", + value = "Limit of paginated reviews", + defaultValue = "20") + @QueryParam("limit") int limit); + + @GET + @Path("/{uuid}/release-rating") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "get ratings", + notes = "Get all ratings", + tags = "Review Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:view") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved ratings.", + response = List.class, + responseContainer = "List"), + @ApiResponse( + code = 404, + message = "Not Found. \n No Application release found for application release UUID.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting ratings", + response = ErrorResponse.class) + }) + + Response getAppReleaseRating( + @ApiParam( + name = "uuid", + value = "uuid of the application release", + required = true) + @PathParam("uuid") String uuid); + + @GET + @Path("/{uuid}/app-rating") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "get app ratings", + notes = "Get all app ratings", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:view") + }) + } + ) + + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved ratings.", + response = List.class, + responseContainer = "List"), + @ApiResponse( + code = 404, + message = "Not Found. \n No Application found which has application release of UUID.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting ratings", + response = ErrorResponse.class) + }) + + Response getAppRating( + @ApiParam( + name = "uuid", + value = "uuid of the application release", + required = true) + @PathParam("uuid") + String uuid); +} 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/admin/ReviewManagementAdminAPIImpl.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/admin/ReviewManagementAdminAPIImpl.java similarity index 54% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/impl/admin/ReviewManagementAdminAPIImpl.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/java/org/wso2/carbon/device/application/mgt/publisher/api/services/impl/admin/ReviewManagementAdminAPIImpl.java index 97bc433e17..f99e014baa 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/admin/ReviewManagementAdminAPIImpl.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/admin/ReviewManagementAdminAPIImpl.java @@ -14,24 +14,30 @@ * specific language governing permissions and limitations * under the License. */ -package org.wso2.carbon.device.application.mgt.store.api.services.impl.admin; +package org.wso2.carbon.device.application.mgt.publisher.api.services.impl.admin; import io.swagger.annotations.ApiParam; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.application.mgt.common.PaginationRequest; +import org.wso2.carbon.device.application.mgt.common.PaginationResult; +import org.wso2.carbon.device.application.mgt.common.Rating; import org.wso2.carbon.device.application.mgt.common.exception.ApplicationManagementException; import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; import org.wso2.carbon.device.application.mgt.common.services.ReviewManager; import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper; import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException; import org.wso2.carbon.device.application.mgt.core.util.APIUtil; -import org.wso2.carbon.device.application.mgt.store.api.services.admin.ReviewManagementAdminAPI; +import org.wso2.carbon.device.application.mgt.publisher.api.services.admin.ReviewManagementAdminAPI; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; import javax.ws.rs.PUT; import javax.ws.rs.Path; import javax.ws.rs.PathParam; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; /** @@ -99,4 +105,73 @@ public class ReviewManagementAdminAPIImpl implements ReviewManagementAdminAPI { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } + + @Override + @GET + @Path("/release/{uuid}") + public Response getAllReleaseReviews( + @PathParam("uuid") String uuid, + @DefaultValue("0") @QueryParam("offset") int offSet, + @DefaultValue("20") @QueryParam("limit") int limit) { + ReviewManager reviewManager = APIUtil.getReviewManager(); + PaginationRequest request = new PaginationRequest(offSet, limit); + try { + PaginationResult paginationResult = reviewManager.getAllReleaseReviews(request, uuid); + return Response.status(Response.Status.OK).entity(paginationResult).build(); + } catch (NotFoundException e) { + String msg = "Couldn't find an application release for UUID: " + uuid; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (ReviewManagementException e) { + String msg = "Error occurred while retrieving reviews for application UUID: " + uuid; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (ApplicationManagementException e) { + String msg = "Error occurred while retrieving application release details for application UUID: " + uuid; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } + + @Override + @GET + @Path("/{uuid}/release-rating") + public Response getAppReleaseRating( + @PathParam("uuid") String uuid) { + ReviewManager reviewManager = APIUtil.getReviewManager(); + Rating rating; + try { + rating = reviewManager.getAppReleaseRating(uuid); + } catch (NotFoundException e) { + String msg = "Couldn't found an application release for UUID: " + uuid; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (ReviewManagementException | ApplicationManagementException e) { + String msg = "Error occured while getting review data for application release UUID: " + uuid; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + return Response.status(Response.Status.OK).entity(rating).build(); + } + + @Override + @GET + @Path("/{uuid}/app-rating") + public Response getAppRating( + @PathParam("uuid") String uuid) { + ReviewManager reviewManager = APIUtil.getReviewManager(); + Rating rating; + try { + rating = reviewManager.getAppRating(uuid); + } catch (NotFoundException e) { + String msg = "Couldn't found an application for application release UUID: " + uuid; + log.error(msg, e); + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } catch (ReviewManagementException | ApplicationManagementException e) { + String msg = "Error occured while getting review data for application release UUID: " + uuid; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); + } + return Response.status(Response.Status.OK).entity(rating).build(); + } } \ No newline at end of file diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 661cc26f85..6f108fe514 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -26,6 +26,7 @@ + @@ -55,6 +56,7 @@ + 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/ReviewManagementAPI.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/ReviewManagementAPI.java index e840e02a6d..d72e9e4c27 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/ReviewManagementAPI.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/ReviewManagementAPI.java @@ -49,9 +49,9 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; - /** - * APIs to handle review management related tasks. - */ +/** +* APIs to handle review management related tasks. +*/ @SwaggerDefinition( info = @Info( @@ -60,7 +60,7 @@ import java.util.List; extensions = { @Extension(properties = { @ExtensionProperty(name = "name", value = "ReviewManagementService"), - @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/review"), + @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/store/review"), }) } ), @@ -92,13 +92,13 @@ public interface ReviewManagementAPI { String SCOPE = "scope"; @GET - @Path("/release/{uuid}") + @Path("/app/user/{uuid}") @Produces(MediaType.APPLICATION_JSON) @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", - value = "get app release reviews", - notes = "Get all app release reviews", + value = "get app reviews", + notes = "Get all app reviews", tags = "Store Management", extensions = { @Extension(properties = { @@ -111,19 +111,20 @@ public interface ReviewManagementAPI { value = { @ApiResponse( code = 200, - message = "OK. \n Successfully retrieved app release reviews.", + message = "OK. \n Successfully retrieved app reviews.", response = PaginationResult.class, responseContainer = "PaginationResult"), @ApiResponse( code = 404, - message = "Not Found. \n Not found an application release for requested UUID."), + message = "Not Found. \n Not found an application release associated with requested " + + "UUID."), @ApiResponse( code = 500, message = "Internal Server Error. \n Error occurred while getting the review list.", response = ErrorResponse.class) }) - Response getAllReleaseReviews( + Response getUserReviews( @ApiParam( name="uuid", value="uuid of the application release.", @@ -140,105 +141,55 @@ public interface ReviewManagementAPI { defaultValue = "20") @QueryParam("limit") int limit); - @GET - @Path("/app/user/{uuid}") - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "get app reviews", - notes = "Get all app reviews", - tags = "Store Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:review:view") - }) - } - ) - - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully retrieved app reviews.", - response = PaginationResult.class, - responseContainer = "PaginationResult"), - @ApiResponse( - code = 404, - message = "Not Found. \n Not found an application release associated with requested " - + "UUID."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while getting the review list.", - response = ErrorResponse.class) + @GET + @Path("/app/{uuid}") + @Produces(MediaType.APPLICATION_JSON) + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "get app reviews", + notes = "Get all app reviews", + tags = "Store Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = SCOPE, value = "perm:app:review:view") }) + } + ) - Response getUserReviews( - @ApiParam( - name="uuid", - value="uuid of the application release.", - required = true) - @PathParam("uuid") String uuid, - @ApiParam( - name="offset", - value="Starting review number.", - defaultValue = "0") - @QueryParam("offSet") int offSet, - @ApiParam( - name="limit", - value = "Limit of paginated reviews", - defaultValue = "20") - @QueryParam("limit") int limit); - - @GET - @Path("/app/{uuid}") - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "get app reviews", - notes = "Get all app reviews", - tags = "Store Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:review:view") - }) - } - ) - - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully retrieved app reviews.", - response = PaginationResult.class, - responseContainer = "PaginationResult"), - @ApiResponse( - code = 404, - message = "Not Found. \n Not found an application release associated with requested " - + "UUID."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while getting the review list.", - response = ErrorResponse.class) - }) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully retrieved app reviews.", + response = PaginationResult.class, + responseContainer = "PaginationResult"), + @ApiResponse( + code = 404, + message = "Not Found. \n Not found an application release associated with requested " + + "UUID."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error occurred while getting the review list.", + response = ErrorResponse.class) + }) - Response getAllAppReviews( - @ApiParam( - name="uuid", - value="uuid of the application release.", - required = true) - @PathParam("uuid") String uuid, - @ApiParam( - name="offset", - value="Starting review number.", - defaultValue = "0") - @QueryParam("offSet") int offSet, - @ApiParam( - name="limit", - value = "Limit of paginated reviews", - defaultValue = "20") - @QueryParam("limit") int limit); + Response getAllAppReviews( + @ApiParam( + name="uuid", + value="uuid of the application release.", + required = true) + @PathParam("uuid") String uuid, + @ApiParam( + name="offset", + value="Starting review number.", + defaultValue = "0") + @QueryParam("offSet") int offSet, + @ApiParam( + name="limit", + value = "Limit of paginated reviews", + defaultValue = "20") + @QueryParam("limit") int limit); @POST @Path("/{uuid}") @@ -442,13 +393,13 @@ public interface ReviewManagementAPI { @PathParam("reviewId") int reviewId); @GET - @Path("/{uuid}/release-rating") + @Path("/{uuid}/app-rating") @Produces(MediaType.APPLICATION_JSON) @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", - value = "get ratings", - notes = "Get all ratings", + value = "get app ratings", + notes = "Get all app ratings", tags = "Store Management", extensions = { @Extension(properties = { @@ -466,7 +417,7 @@ public interface ReviewManagementAPI { responseContainer = "List"), @ApiResponse( code = 404, - message = "Not Found. \n No Application release found for application release UUID.", + message = "Not Found. \n No Application found which has application release of UUID.", response = ErrorResponse.class), @ApiResponse( code = 500, @@ -474,52 +425,11 @@ public interface ReviewManagementAPI { response = ErrorResponse.class) }) - Response getAppReleaseRating( + Response getAppRating( @ApiParam( name = "uuid", value = "uuid of the application release", required = true) @PathParam("uuid") String uuid); - - @GET - @Path("/{uuid}/app-rating") - @Produces(MediaType.APPLICATION_JSON) - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "get app ratings", - notes = "Get all app ratings", - tags = "Store Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:app:review:view") - }) - } - ) - - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully retrieved ratings.", - response = List.class, - responseContainer = "List"), - @ApiResponse( - code = 404, - message = "Not Found. \n No Application found which has application release of UUID.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while getting ratings", - response = ErrorResponse.class) - }) - - Response getAppRating( - @ApiParam( - name = "uuid", - value = "uuid of the application release", - required = true) - @PathParam("uuid") - String uuid); } 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/admin/ReviewManagementAdminAPI.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/admin/ReviewManagementAdminAPI.java deleted file mode 100644 index 471924a122..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/java/org/wso2/carbon/device/application/mgt/store/api/services/admin/ReviewManagementAdminAPI.java +++ /dev/null @@ -1,174 +0,0 @@ -/* 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. - */ -package org.wso2.carbon.device.application.mgt.store.api.services.admin; - -import io.swagger.annotations.Api; -import io.swagger.annotations.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Extension; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.Info; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Tag; -import org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; -import org.wso2.carbon.device.application.mgt.common.ErrorResponse; -import org.wso2.carbon.device.application.mgt.common.response.Review; -import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper; - -import javax.validation.Valid; -import javax.ws.rs.Consumes; -import javax.ws.rs.DELETE; -import javax.ws.rs.PUT; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - -/** -* APIs to handle review management related tasks. -*/ - -@SwaggerDefinition( -info = @Info( - version = "1.0.0", - title = "Review Management Admin Service", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = "name", value = "ReviewManagementAdminService"), - @ExtensionProperty(name = "context", value = "/api/application-mgt/v1.0/admin/review"), - }) - } -), -tags = { - @Tag(name = "review_management", description = "Review Management related Admin APIs") -} -) -@Scopes( -scopes = { - @Scope( - name = "Update a Review", - description = "Update a Review from the application store.", - key = "perm:admin:app:review:update", - permissions = {"/app-mgt/store/admin/review/update"} - ) -} -) - -@Path("/admin/reviews") -@Api(value = "Review Management Admin API") -@Produces(MediaType.APPLICATION_JSON) -public interface ReviewManagementAdminAPI { -String SCOPE = "scope"; - -@PUT -@Path("/{uuid}/{reviewId}") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -@ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "PUT", - value = "Edit a reviewTmp", - notes = "This will edit the reviewTmp", - tags = "Store Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:update") - }) - } -) -@ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully updated reviewTmp.", - response = Review.class), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error."), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while updating the new reviewTmp.", - response = ErrorResponse.class) - }) -Response updateReview( - @ApiParam( - name = "reviewTmp", - value = "The reviewTmp that need to be updated.", - required = true) - @Valid ReviewWrapper updatingReview, - @ApiParam( - name = "uuid", - value = "uuid of the application release", - required = true) - @PathParam("uuid") String uuid, - @ApiParam( - name = "reviewId", - value = "reviewTmp id of the updating reviewTmp.", - required = true) - @PathParam("reviewId") int reviewId); - -@DELETE -@Path("/{uuid}/{reviewId}") -@Produces(MediaType.APPLICATION_JSON) -@Consumes(MediaType.APPLICATION_JSON) -@ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "DELETE", - value = "Remove comment", - notes = "Remove comment", - tags = "Store Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "perm:admin:app:review:update") - }) - } -) - -@ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully deleted the review"), - @ApiResponse( - code = 404, - message = "Not Found. \n No activity found with the given ID.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Error occurred while deleting the review.", - response = ErrorResponse.class) - }) - -Response deleteReview( - @ApiParam( - name = "uuid", - value = "UUID of the application release.", - required = true) - @PathParam("uuid") String uuid, - @ApiParam(name = "reviewId", - value = "Id of the review.", - required = true) - @PathParam("reviewId") int reviewId); - - -} 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/ReviewManagementAPIImpl.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/ReviewManagementAPIImpl.java index b35c00efd5..f4293bb00f 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/ReviewManagementAPIImpl.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/ReviewManagementAPIImpl.java @@ -53,33 +53,6 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { private static Log log = LogFactory.getLog(ReviewManagementAPIImpl.class); - @Override - @GET - @Path("/release/{uuid}") - public Response getAllReleaseReviews( - @PathParam("uuid") String uuid, - @DefaultValue("0") @QueryParam("offset") int offSet, - @DefaultValue("20") @QueryParam("limit") int limit) { - ReviewManager reviewManager = APIUtil.getReviewManager(); - PaginationRequest request = new PaginationRequest(offSet, limit); - try { - PaginationResult paginationResult = reviewManager.getAllReleaseReviews(request, uuid); - return Response.status(Response.Status.OK).entity(paginationResult).build(); - } catch (NotFoundException e) { - String msg = "Couldn't find an application release for UUID: " + uuid; - log.error(msg, e); - return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); - } catch (ReviewManagementException e) { - String msg = "Error occurred while retrieving reviews for application UUID: " + uuid; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } catch (ApplicationManagementException e) { - String msg = "Error occurred while retrieving application release details for application UUID: " + uuid; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); - } - } - @Override @GET @Path("/app/user/{uuid}") @@ -281,27 +254,6 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI { } } - @Override - @GET - @Path("/{uuid}/release-rating") - public Response getAppReleaseRating( - @PathParam("uuid") String uuid) { - ReviewManager reviewManager = APIUtil.getReviewManager(); - Rating rating; - try { - rating = reviewManager.getAppReleaseRating(uuid); - } catch (NotFoundException e) { - String msg = "Couldn't found an application release for UUID: " + uuid; - log.error(msg, e); - return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); - } catch (ReviewManagementException | ApplicationManagementException e) { - String msg = "Error occured while getting review data for application release UUID: " + uuid; - log.error(msg, e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } - return Response.status(Response.Status.OK).entity(rating).build(); - } - @Override @GET @Path("/{uuid}/app-rating") diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml index da49a119c7..da9e97ccea 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -26,7 +26,6 @@ - @@ -56,7 +55,6 @@ - diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index 11ce3c44c0..2e58edcc37 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -154,6 +154,7 @@ perm:app:subscription:install perm:app:subscription:uninstall perm:admin:app:review:update + perm:admin:app:review:view perm:admin:app:publisher:update From 340d28c03beff18b618f9cdd5ac479e06de7675e Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Fri, 21 Jun 2019 18:29:07 +0530 Subject: [PATCH 4/4] Improve UI intercepter response --- ...ailureCallback.java => ErrorCallback.java} | 2 +- .../mgt/common/config/LoginResponse.java | 27 ------------------- .../mgt/common/config/UIConfiguration.java | 12 +++------ .../ui/request/interceptor/LoginHandler.java | 3 +-- .../interceptor/util/HandlerConstants.java | 3 +-- .../request/interceptor/util/HandlerUtil.java | 4 +-- .../main/resources/conf/application-mgt.xml | 26 ++++++++---------- 7 files changed, 20 insertions(+), 57 deletions(-) rename components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/{FailureCallback.java => ErrorCallback.java} (98%) delete mode 100644 components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LoginResponse.java diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/FailureCallback.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/ErrorCallback.java similarity index 98% rename from components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/FailureCallback.java rename to components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/ErrorCallback.java index 46bb9e02aa..1a073c7059 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/FailureCallback.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/ErrorCallback.java @@ -2,7 +2,7 @@ package org.wso2.carbon.device.application.mgt.common.config; import javax.xml.bind.annotation.XmlElement; -public class FailureCallback { +public class ErrorCallback { private String badRequest; private String unauthorized; diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LoginResponse.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LoginResponse.java deleted file mode 100644 index a76e892b3e..0000000000 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/LoginResponse.java +++ /dev/null @@ -1,27 +0,0 @@ -package org.wso2.carbon.device.application.mgt.common.config; - -import javax.xml.bind.annotation.XmlElement; - -public class LoginResponse { - - private String successCallback; - private FailureCallback failureCallback; - - @XmlElement(name = "SuccessCallback", required=true) - public String getSuccessCallback() { - return successCallback; - } - - public void setSuccessCallback(String successCallback) { - this.successCallback = successCallback; - } - - @XmlElement(name = "FailureCallback", required=true) - public FailureCallback getFailureCallback() { - return failureCallback; - } - - public void setFailureCallback(FailureCallback failureCallback) { - this.failureCallback = failureCallback; - } -} diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/UIConfiguration.java b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/UIConfiguration.java index 8c5115926e..040c63465d 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/UIConfiguration.java +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.common/src/main/java/org/wso2/carbon/device/application/mgt/common/config/UIConfiguration.java @@ -9,7 +9,7 @@ public class UIConfiguration { private AppRegistration appRegistration; private List scopes; private boolean isSsoEnable; - private LoginResponse loginResponse; + private ErrorCallback errorCallback; @XmlElement(name = "AppRegistration", required=true) public AppRegistration getAppRegistration() { @@ -39,12 +39,8 @@ public class UIConfiguration { isSsoEnable = ssoEnable; } - public LoginResponse getLoginResponse() { - return loginResponse; - } + @XmlElement(name = "ErrorCallback", required=true) + public ErrorCallback getErrorCallback() { return errorCallback; } - @XmlElement(name = "LoginResponse", required=true) - public void setLoginResponse(LoginResponse loginResponse) { - this.loginResponse = loginResponse; - } + public void setErrorCallback(ErrorCallback errorCallback) { this.errorCallback = errorCallback; } } diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/LoginHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/LoginHandler.java index f35f0151e1..f7ed47811e 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/LoginHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/LoginHandler.java @@ -131,8 +131,7 @@ public class LoginHandler extends HttpServlet { clientAppResponse.getData(), scopes)) { ProxyResponse proxyResponse = new ProxyResponse(); proxyResponse.setCode(HttpStatus.SC_OK); - proxyResponse.setUrl(serverUrl + "/" + platform + uiConfigJsonObject.get(HandlerConstants.LOGIN_RESPONSE_KEY) - .getAsJsonObject().get("successCallback").getAsString()); + proxyResponse.setUrl(serverUrl + "/" + platform); HandlerUtil.handleSuccess(req, resp, serverUrl, platform, proxyResponse); return; } diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java index cf2cb4db60..f82fbe7677 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java @@ -32,8 +32,7 @@ public class HandlerConstants { public static final String UI_CONFIG_KEY = "ui-config"; public static final String PLATFORM = "platform"; public static final String DEFAULT_ERROR_CALLBACK = "/pages/error/default"; - public static final String LOGIN_RESPONSE_KEY = "loginResponse"; - public static final String FAILURE_CALLBACK_KEY = "failureCallback"; + public static final String ERROR_CALLBACK_KEY = "errorCallback"; public static final String API_COMMON_CONTEXT = "/api"; public static final String EXECUTOR_EXCEPTION_PREFIX = "ExecutorException-"; public static final String TOKEN_IS_EXPIRED = "ACCESS_TOKEN_IS_EXPIRED"; diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java index 399655ae0a..4093902327 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerUtil.java @@ -20,6 +20,7 @@ package io.entgra.ui.request.interceptor.util; import com.google.gson.Gson; import com.google.gson.JsonObject; +import com.google.gson.JsonParser; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -171,8 +172,7 @@ public class HandlerUtil { if (uiConfig == null){ proxyResponse.setUrl(serverUrl + "/" + platform + HandlerConstants.DEFAULT_ERROR_CALLBACK); } else{ - proxyResponse.setUrl(serverUrl + uiConfig.get(HandlerConstants.LOGIN_RESPONSE_KEY).getAsJsonObject() - .get(HandlerConstants.FAILURE_CALLBACK_KEY).getAsJsonObject() + proxyResponse.setUrl(serverUrl + uiConfig.get(HandlerConstants.ERROR_CALLBACK_KEY).getAsJsonObject() .get(proxyResponse.getExecutorResponse().split(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)[1]) .getAsString()); } diff --git a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml index 2e58edcc37..001c06ecbe 100644 --- a/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml +++ b/features/application-mgt/org.wso2.carbon.device.application.mgt.server.feature/src/main/resources/conf/application-mgt.xml @@ -135,7 +135,6 @@ true false - false application_management @@ -160,20 +159,17 @@ app-mgt - - /apps - - /pages/error/client-errors/400 - /pages/error/client-errors/401 - /pages/error/client-errors/403 - /pages/error/client-errors/404 - /pages/error/client-errors/405 - /pages/error/client-errors/406 - /pages/error/client-errors/415 - /pages/error/server-errors/500 - /pages/error/default - - + + /pages/error/client-errors/400 + /pages/error/client-errors/401 + /pages/error/client-errors/403 + /pages/error/client-errors/404 + /pages/error/client-errors/405 + /pages/error/client-errors/406 + /pages/error/client-errors/415 + /pages/error/server-errors/500 + /pages/error/default + https://localhost:9443/api/application-mgt/v1.0/artifact