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

Improve APPM review management

See merge request entgra/carbon-device-mgt!146
feature/appm-store/pbac
Dharmakeerthi Lasantha 6 years ago
commit ef8e7314b7

@ -2,7 +2,7 @@ package org.wso2.carbon.device.application.mgt.common.config;
import javax.xml.bind.annotation.XmlElement; import javax.xml.bind.annotation.XmlElement;
public class FailureCallback { public class ErrorCallback {
private String badRequest; private String badRequest;
private String unauthorized; private String unauthorized;

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

@ -9,7 +9,7 @@ public class UIConfiguration {
private AppRegistration appRegistration; private AppRegistration appRegistration;
private List<String> scopes; private List<String> scopes;
private boolean isSsoEnable; private boolean isSsoEnable;
private LoginResponse loginResponse; private ErrorCallback errorCallback;
@XmlElement(name = "AppRegistration", required=true) @XmlElement(name = "AppRegistration", required=true)
public AppRegistration getAppRegistration() { public AppRegistration getAppRegistration() {
@ -39,12 +39,8 @@ public class UIConfiguration {
isSsoEnable = ssoEnable; isSsoEnable = ssoEnable;
} }
public LoginResponse getLoginResponse() { @XmlElement(name = "ErrorCallback", required=true)
return loginResponse; public ErrorCallback getErrorCallback() { return errorCallback; }
}
@XmlElement(name = "LoginResponse", required=true) public void setErrorCallback(ErrorCallback errorCallback) { this.errorCallback = errorCallback; }
public void setLoginResponse(LoginResponse loginResponse) {
this.loginResponse = loginResponse;
}
} }

@ -45,15 +45,16 @@ import java.util.List;
*/ */
public interface ApplicationManager { 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. * @param applicationWrapper Application that need to be created.
* @return Created application * @param applicationArtifact contains artifact data. i.e image name and stream, icon name and stream etc.
* @throws ApplicationManagementException ApplicationDTO Management Exception * @return {@link Application}
* @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException}
*/ */
Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact) Application createApplication(ApplicationWrapper applicationWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException, RequestValidatingException; throws ApplicationManagementException;
Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact) Application createWebClip(WebAppWrapper webAppWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException; throws ApplicationManagementException;
@ -134,15 +135,6 @@ public interface ApplicationManager {
*/ */
Application getApplicationByUuid(String uuid, String state) throws ApplicationManagementException; 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. * To get lifecycle state change flow of a particular Application Release.
* *

@ -54,7 +54,9 @@ public class ApplicationReleaseWrapper {
private String metaData; private String metaData;
@ApiModelProperty(name = "supportedOsVersions", @ApiModelProperty(name = "supportedOsVersions",
value = "ApplicationDTO release supported OS versions") value = "Application release supported OS versions",
required = true,
example = "4.0-10.0")
@NotNull @NotNull
private String supportedOsVersions; private String supportedOsVersions;

@ -66,7 +66,9 @@ public class PublicAppReleaseWrapper {
private String packageName; private String packageName;
@ApiModelProperty(name = "supportedOsVersions", @ApiModelProperty(name = "supportedOsVersions",
value = "ApplicationDTO release supported OS versions") value = "Application release supported OS versions",
required = true,
example = "4.0-10.0")
@NotNull @NotNull
private String supportedOsVersions; private String supportedOsVersions;

@ -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.*;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.CategoryDTO; 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.common.dto.TagDTO;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException; 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; 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. * To get the applications that satisfy the given criteria.
* *
@ -132,27 +119,6 @@ public interface ApplicationDAO {
*/ */
String getUuidOfLatestRelease(int appId) throws ApplicationManagementDAOException; 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 * To get the application with the given id
* *
@ -173,16 +139,6 @@ public interface ApplicationDAO {
*/ */
ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId) throws ApplicationManagementDAOException; 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 * Verify whether application exist for given application name and device type. Because a name and device type is
* unique for an application. * unique for an application.
@ -193,7 +149,7 @@ public interface ApplicationDAO {
* @return ID of the ApplicationDTO. * @return ID of the ApplicationDTO.
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @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. * To edit the given application.
@ -236,16 +192,6 @@ public interface ApplicationDAO {
*/ */
void deleteTags(List<String> tags, int applicationId, int tenantId) throws ApplicationManagementDAOException; void deleteTags(List<String> 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; String getApplicationSubTypeByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException;
void deleteApplication(int appId, int tenantId) throws ApplicationManagementDAOException; void deleteApplication(int appId, int tenantId) throws ApplicationManagementDAOException;

@ -24,7 +24,6 @@ import org.apache.commons.logging.LogFactory;
import org.json.JSONException; import org.json.JSONException;
import org.wso2.carbon.device.application.mgt.common.AppLifecycleState; import org.wso2.carbon.device.application.mgt.common.AppLifecycleState;
import org.wso2.carbon.device.application.mgt.common.dto.ApplicationDTO; 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.CategoryDTO;
import org.wso2.carbon.device.application.mgt.common.Filter; import org.wso2.carbon.device.application.mgt.common.Filter;
import org.wso2.carbon.device.application.mgt.common.dto.TagDTO; 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 @Override
public List<ApplicationDTO> getApplications(Filter filter,int deviceTypeId, int tenantId) throws ApplicationManagementDAOException { public List<ApplicationDTO> getApplications(Filter filter,int deviceTypeId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -344,96 +313,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
return count; 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 @Override
public ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId) public ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId)
throws ApplicationManagementDAOException { 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 @Override
public boolean updateApplication(ApplicationDTO applicationDTO, int tenantId) public boolean updateApplication(ApplicationDTO applicationDTO, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
@ -1532,76 +1378,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public ApplicationDTO getApplicationByRelease(String appReleaseUUID, int tenantId) public boolean isExistingAppName(String appName, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException {
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<String> unrestrictedRoleList = new ArrayList<>();
unrestrictedRoleList.add(unrestrictedRole);
application.setUnrestrictedRoles(unrestrictedRoleList);
List<ApplicationReleaseDTO> 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 {
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;

@ -25,7 +25,6 @@ import org.apache.commons.validator.routines.UrlValidator;
import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext; import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact; import org.wso2.carbon.device.application.mgt.common.ApplicationArtifact;
@ -88,9 +87,9 @@ 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.common.exceptions.DeviceManagementException;
import org.wso2.carbon.device.mgt.core.dto.DeviceType; 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.UserRealm;
import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.utils.multitenancy.MultitenantUtils;
import java.io.ByteArrayInputStream; import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
@ -131,21 +130,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO(); 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 RequestValidatingException if application creating request is invalid,
* @throws ApplicationManagementException Catch all other throwing exceptions and throw {@link ApplicationManagementException}
*/
@Override @Override
public Application createApplication(ApplicationWrapper applicationWrapper, public Application createApplication(ApplicationWrapper applicationWrapper,
ApplicationArtifact applicationArtifact) throws RequestValidatingException, ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (log.isDebugEnabled()) { 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); + userName);
} }
@ -154,6 +146,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
//uploading application artifacts //uploading application artifacts
try { try {
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); 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(), applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
applicationWrapper.getDeviceType(), applicationReleaseDTO, applicationArtifact, false); applicationWrapper.getDeviceType(), applicationReleaseDTO, applicationArtifact, false);
applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact); applicationReleaseDTO = addImageArtifacts(applicationReleaseDTO, applicationArtifact);
@ -169,7 +168,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
private void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException { private void deleteApplicationArtifacts(List<String> directoryPaths) throws ApplicationManagementException {
ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager(); ApplicationStorageManager applicationStorageManager = DAOUtil.getApplicationStorageManager();
try { try {
applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths); applicationStorageManager.deleteAllApplicationReleaseArtifacts(directoryPaths);
} catch (ApplicationStorageManagementException e) { } catch (ApplicationStorageManagementException e) {
@ -425,7 +423,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper); ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(webAppWrapper);
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
String uuid = UUID.randomUUID().toString(); String uuid = UUID.randomUUID().toString();
//todo check installer name exists or not, do it in the validation method
String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName()); String md5 = DigestUtils.md5Hex(applicationReleaseDTO.getInstallerName());
applicationReleaseDTO.setUuid(uuid); applicationReleaseDTO.setUuid(uuid);
applicationReleaseDTO.setAppHashValue(md5); applicationReleaseDTO.setAppHashValue(md5);
@ -455,6 +452,14 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ userName); + 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())) { if (DeviceTypes.ANDROID.toString().equals(publicAppWrapper.getDeviceType())) {
publicAppStorePath = Constants.GOOGLE_PLAY_STORE_URL; publicAppStorePath = Constants.GOOGLE_PLAY_STORE_URL;
} else if (DeviceTypes.IOS.toString().equals(publicAppWrapper.getDeviceType())) { } else if (DeviceTypes.IOS.toString().equals(publicAppWrapper.getDeviceType())) {
@ -758,8 +763,15 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new BadRequestException(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, ApplicationReleaseDTO applicationReleaseDTO = uploadReleaseArtifacts(applicationReleaseWrapper,
applicationDTO, applicationArtifact); applicationDTO, applicationArtifact, deviceType.getName());
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
String initialstate = lifecycleStateManager.getInitialState(); String initialstate = lifecycleStateManager.getInitialState();
applicationReleaseDTO.setCurrentState(initialstate); applicationReleaseDTO.setCurrentState(initialstate);
@ -818,12 +830,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
private ApplicationReleaseDTO uploadReleaseArtifacts(ApplicationReleaseWrapper applicationReleaseWrapper, private ApplicationReleaseDTO uploadReleaseArtifacts(ApplicationReleaseWrapper applicationReleaseWrapper,
ApplicationDTO applicationDTO, ApplicationArtifact applicationArtifact) ApplicationDTO applicationDTO, ApplicationArtifact applicationArtifact, String deviceTypeName)
throws ApplicationManagementException { throws ApplicationManagementException {
try { try {
DeviceType deviceType = getDeviceTypeData(applicationDTO.getDeviceTypeId());
ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(), ApplicationReleaseDTO applicationReleaseDTO = addApplicationReleaseArtifacts(applicationDTO.getType(),
deviceType.getName(), APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact, deviceTypeName, APIUtil.releaseWrapperToReleaseDTO(applicationReleaseWrapper), applicationArtifact,
true); true);
return addImageArtifacts(applicationReleaseDTO, applicationArtifact); return addImageArtifacts(applicationReleaseDTO, applicationArtifact);
} catch (ResourceManagementException e) { } catch (ResourceManagementException e) {
@ -834,6 +845,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 @Override
public Application getApplicationById(int appId, String state) throws ApplicationManagementException { public Application getApplicationById(int appId, String state) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -1070,107 +1105,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
return roleList; 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<ApplicationReleaseDTO> 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<ApplicationReleaseDTO> getReleases(ApplicationDTO application, String releaseState)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
List<ApplicationReleaseDTO> 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 @Override
public void deleteApplication(int applicationId) throws ApplicationManagementException { public void deleteApplication(int applicationId) throws ApplicationManagementException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -1320,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 @Override
public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException { throws ApplicationManagementException {
@ -2251,7 +2152,11 @@ public class ApplicationManagerImpl implements ApplicationManager {
String supportedOSVersions = applicationReleaseWrapper.getSupportedOsVersions(); String supportedOSVersions = applicationReleaseWrapper.getSupportedOsVersions();
if (!StringUtils.isEmpty(supportedOSVersions)) { 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); applicationReleaseDTO.setSupportedOsVersions(supportedOSVersions);
} }
if (!StringUtils.isEmpty(applicationReleaseWrapper.getDescription())) { if (!StringUtils.isEmpty(applicationReleaseWrapper.getDescription())) {
@ -2451,7 +2356,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId); List<CategoryDTO> registeredCategories = this.applicationDAO.getAllCategories(tenantId);
if (registeredCategories.isEmpty()) { if (registeredCategories.isEmpty()) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Registered application category set is empty. Since it is mandatory to add application " 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."; + "category when adding new application, registered application category list shouldn't be null.";
log.error(msg); log.error(msg);
@ -2482,7 +2386,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
} catch (UserStoreException e) { } catch (UserStoreException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred when validating the unrestricted roles given for the web clip"; String msg = "Error occurred when validating the unrestricted roles given for the web clip";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg, e); throw new ApplicationManagementException(msg, e);
@ -2551,7 +2454,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
@Override @Override
public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile,
List<Attachment> attachmentList) throws RequestValidatingException { List<Attachment> attachmentList) throws RequestValidatingException {

@ -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.dto.ApplicationsDTO;
import org.wso2.carbon.device.application.mgt.core.impl.ApplicationManagerImpl; 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.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.File;
import java.io.FileInputStream; import java.io.FileInputStream;
@ -45,7 +49,7 @@ public class ApplicationManagementTest extends BaseTestCase {
ConnectionManagerUtil.closeDBConnection(); ConnectionManagerUtil.closeDBConnection();
} }
@Test(dependsOnMethods = ("addAplicationCategories")) @Test(dependsOnMethods = ("addApplicationCategories"))
public void createApplication() throws Exception { public void createApplication() throws Exception {
log.debug("Creating the first application ....!"); log.debug("Creating the first application ....!");
@ -75,7 +79,7 @@ public class ApplicationManagementTest extends BaseTestCase {
releaseWrapper.setMetaData("Just meta data"); releaseWrapper.setMetaData("Just meta data");
releaseWrapper.setReleaseType("free"); releaseWrapper.setReleaseType("free");
releaseWrapper.setPrice(5.7); releaseWrapper.setPrice(5.7);
releaseWrapper.setSupportedOsVersions("5.7, 6.1"); releaseWrapper.setSupportedOsVersions("4.0-7.0");
applicationReleaseWrappers.add(releaseWrapper); applicationReleaseWrappers.add(releaseWrapper);
applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers); applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers);
@ -196,9 +200,8 @@ public class ApplicationManagementTest extends BaseTestCase {
} }
@Test @Test(dependsOnMethods = ("addDeviceVersions"))
public void addAplicationCategories() throws ApplicationManagementException { public void addApplicationCategories() throws ApplicationManagementException {
List<String> categories = new ArrayList<>(); List<String> categories = new ArrayList<>();
categories.add("Test Category"); categories.add("Test Category");
categories.add("Test Category2"); categories.add("Test Category2");
@ -207,6 +210,41 @@ public class ApplicationManagementTest extends BaseTestCase {
} }
@Test
public void addDeviceVersions() throws ApplicationManagementException {
List<DeviceTypeVersion> deviceTypeVersions = new ArrayList<>();
List<String> 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<DeviceType> 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 @Test
public List<Tag> getRegisteredTags() throws ApplicationManagementException { public List<Tag> getRegisteredTags() throws ApplicationManagementException {
return null; return null;

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

@ -14,24 +14,30 @@
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * 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 io.swagger.annotations.ApiParam;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.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.ApplicationManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException; 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.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper; 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.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.util.APIUtil; 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.Consumes;
import javax.ws.rs.DELETE; import javax.ws.rs.DELETE;
import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.PUT; import javax.ws.rs.PUT;
import javax.ws.rs.Path; import javax.ws.rs.Path;
import javax.ws.rs.PathParam; import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.Response; 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(); 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();
}
} }

@ -26,6 +26,7 @@
<jaxrs:server id="applicationMgtService" address="/"> <jaxrs:server id="applicationMgtService" address="/">
<jaxrs:serviceBeans> <jaxrs:serviceBeans>
<ref bean="applicationMgtServiceBean"/> <ref bean="applicationMgtServiceBean"/>
<ref bean="reviewMgtAdminServiceBean"/>
<ref bean="applicationMgtAdminServiceBean"/> <ref bean="applicationMgtAdminServiceBean"/>
<ref bean="swaggerResource"/> <ref bean="swaggerResource"/>
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
@ -55,6 +56,7 @@
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.publisher.api.services.impl.ApplicationManagementPublisherAPIImpl"/> <bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.publisher.api.services.impl.ApplicationManagementPublisherAPIImpl"/>
<bean id="applicationMgtAdminServiceBean" class="org.wso2.carbon.device.application.mgt.publisher.api.services.impl.admin.ApplicationManagementPublisherAdminAPIImpl"/> <bean id="applicationMgtAdminServiceBean" class="org.wso2.carbon.device.application.mgt.publisher.api.services.impl.admin.ApplicationManagementPublisherAdminAPIImpl"/>
<bean id="reviewMgtAdminServiceBean" class="org.wso2.carbon.device.application.mgt.publisher.api.services.impl.admin.ReviewManagementAdminAPIImpl" />
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.addons.JSONMessageHandler"/> <bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.addons.JSONMessageHandler"/>
<bean id="multipartProvider" class="org.wso2.carbon.device.application.mgt.addons.MultipartCustomProvider"/> <bean id="multipartProvider" class="org.wso2.carbon.device.application.mgt.addons.MultipartCustomProvider"/>

@ -49,9 +49,9 @@ import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
/** /**
* APIs to handle review management related tasks. * APIs to handle review management related tasks.
*/ */
@SwaggerDefinition( @SwaggerDefinition(
info = @Info( info = @Info(
@ -60,7 +60,7 @@ import java.util.List;
extensions = { extensions = {
@Extension(properties = { @Extension(properties = {
@ExtensionProperty(name = "name", value = "ReviewManagementService"), @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"),
}) })
} }
), ),
@ -91,55 +91,6 @@ import java.util.List;
public interface ReviewManagementAPI { public interface ReviewManagementAPI {
String SCOPE = "scope"; String SCOPE = "scope";
@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 = "Store Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = SCOPE, value = "perm: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 @GET
@Path("/app/user/{uuid}") @Path("/app/user/{uuid}")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)
@ -441,47 +392,6 @@ public interface ReviewManagementAPI {
required = true) required = true)
@PathParam("reviewId") int reviewId); @PathParam("reviewId") int reviewId);
@GET
@Path("/{uuid}/release-rating")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "get ratings",
notes = "Get all 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 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 @GET
@Path("/{uuid}/app-rating") @Path("/{uuid}/app-rating")
@Produces(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON)

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

@ -53,33 +53,6 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
private static Log log = LogFactory.getLog(ReviewManagementAPIImpl.class); 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 @Override
@GET @GET
@Path("/app/user/{uuid}") @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 @Override
@GET @GET
@Path("/{uuid}/app-rating") @Path("/{uuid}/app-rating")

@ -26,7 +26,6 @@
<jaxrs:serviceBeans> <jaxrs:serviceBeans>
<ref bean="applicationMgtServiceBean"/> <ref bean="applicationMgtServiceBean"/>
<ref bean="reviewMgtServiceBean"/> <ref bean="reviewMgtServiceBean"/>
<ref bean="reviewMgtAdminServiceBean"/>
<ref bean="subscriptionMgtServiceBean"/> <ref bean="subscriptionMgtServiceBean"/>
<ref bean="swaggerResource"/> <ref bean="swaggerResource"/>
</jaxrs:serviceBeans> </jaxrs:serviceBeans>
@ -56,7 +55,6 @@
<bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.ApplicationManagementAPIImpl"/> <bean id="applicationMgtServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.ApplicationManagementAPIImpl"/>
<bean id="reviewMgtServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.ReviewManagementAPIImpl" /> <bean id="reviewMgtServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.ReviewManagementAPIImpl" />
<bean id="reviewMgtAdminServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.admin.ReviewManagementAdminAPIImpl" />
<bean id="subscriptionMgtServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.SubscriptionManagementAPIImpl"/> <bean id="subscriptionMgtServiceBean" class="org.wso2.carbon.device.application.mgt.store.api.services.impl.SubscriptionManagementAPIImpl"/>
<bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.addons.JSONMessageHandler"/> <bean id="jsonProvider" class="org.wso2.carbon.device.application.mgt.addons.JSONMessageHandler"/>
<bean id="multipartProvider" class="org.wso2.carbon.device.application.mgt.addons.MultipartCustomProvider"/> <bean id="multipartProvider" class="org.wso2.carbon.device.application.mgt.addons.MultipartCustomProvider"/>

@ -131,8 +131,7 @@ public class LoginHandler extends HttpServlet {
clientAppResponse.getData(), scopes)) { clientAppResponse.getData(), scopes)) {
ProxyResponse proxyResponse = new ProxyResponse(); ProxyResponse proxyResponse = new ProxyResponse();
proxyResponse.setCode(HttpStatus.SC_OK); proxyResponse.setCode(HttpStatus.SC_OK);
proxyResponse.setUrl(serverUrl + "/" + platform + uiConfigJsonObject.get(HandlerConstants.LOGIN_RESPONSE_KEY) proxyResponse.setUrl(serverUrl + "/" + platform);
.getAsJsonObject().get("successCallback").getAsString());
HandlerUtil.handleSuccess(req, resp, serverUrl, platform, proxyResponse); HandlerUtil.handleSuccess(req, resp, serverUrl, platform, proxyResponse);
return; return;
} }

@ -32,8 +32,7 @@ public class HandlerConstants {
public static final String UI_CONFIG_KEY = "ui-config"; public static final String UI_CONFIG_KEY = "ui-config";
public static final String PLATFORM = "platform"; public static final String PLATFORM = "platform";
public static final String DEFAULT_ERROR_CALLBACK = "/pages/error/default"; public static final String DEFAULT_ERROR_CALLBACK = "/pages/error/default";
public static final String LOGIN_RESPONSE_KEY = "loginResponse"; public static final String ERROR_CALLBACK_KEY = "errorCallback";
public static final String FAILURE_CALLBACK_KEY = "failureCallback";
public static final String API_COMMON_CONTEXT = "/api"; public static final String API_COMMON_CONTEXT = "/api";
public static final String EXECUTOR_EXCEPTION_PREFIX = "ExecutorException-"; public static final String EXECUTOR_EXCEPTION_PREFIX = "ExecutorException-";
public static final String TOKEN_IS_EXPIRED = "ACCESS_TOKEN_IS_EXPIRED"; public static final String TOKEN_IS_EXPIRED = "ACCESS_TOKEN_IS_EXPIRED";

@ -20,6 +20,7 @@ package io.entgra.ui.request.interceptor.util;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
@ -171,8 +172,7 @@ public class HandlerUtil {
if (uiConfig == null){ if (uiConfig == null){
proxyResponse.setUrl(serverUrl + "/" + platform + HandlerConstants.DEFAULT_ERROR_CALLBACK); proxyResponse.setUrl(serverUrl + "/" + platform + HandlerConstants.DEFAULT_ERROR_CALLBACK);
} else{ } else{
proxyResponse.setUrl(serverUrl + uiConfig.get(HandlerConstants.LOGIN_RESPONSE_KEY).getAsJsonObject() proxyResponse.setUrl(serverUrl + uiConfig.get(HandlerConstants.ERROR_CALLBACK_KEY).getAsJsonObject()
.get(HandlerConstants.FAILURE_CALLBACK_KEY).getAsJsonObject()
.get(proxyResponse.getExecutorResponse().split(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)[1]) .get(proxyResponse.getExecutorResponse().split(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)[1])
.getAsString()); .getAsString());
} }

@ -135,7 +135,6 @@
<UIConfigs> <UIConfigs>
<EnableOAuth>true</EnableOAuth> <EnableOAuth>true</EnableOAuth>
<EnableSSO>false</EnableSSO> <EnableSSO>false</EnableSSO>
<EnableSSO>false</EnableSSO>
<AppRegistration> <AppRegistration>
<Tags> <Tags>
<Tag>application_management</Tag> <Tag>application_management</Tag>
@ -154,14 +153,13 @@
<Scope>perm:app:subscription:install</Scope> <Scope>perm:app:subscription:install</Scope>
<Scope>perm:app:subscription:uninstall</Scope> <Scope>perm:app:subscription:uninstall</Scope>
<Scope>perm:admin:app:review:update</Scope> <Scope>perm:admin:app:review:update</Scope>
<Scope>perm:admin:app:review:view</Scope>
<Scope>perm:admin:app:publisher:update</Scope> <Scope>perm:admin:app:publisher:update</Scope>
</Scopes> </Scopes>
<SSOConfiguration> <SSOConfiguration>
<Issuer>app-mgt</Issuer> <Issuer>app-mgt</Issuer>
</SSOConfiguration> </SSOConfiguration>
<LoginResponse> <ErrorCallback>
<SuccessCallback>/apps</SuccessCallback>
<FailureCallback>
<BadRequest>/pages/error/client-errors/400</BadRequest> <BadRequest>/pages/error/client-errors/400</BadRequest>
<Unauthorized>/pages/error/client-errors/401</Unauthorized> <Unauthorized>/pages/error/client-errors/401</Unauthorized>
<Forbidden>/pages/error/client-errors/403</Forbidden> <Forbidden>/pages/error/client-errors/403</Forbidden>
@ -171,8 +169,7 @@
<UnsupportedMediaType>/pages/error/client-errors/415</UnsupportedMediaType> <UnsupportedMediaType>/pages/error/client-errors/415</UnsupportedMediaType>
<InternalServerError>/pages/error/server-errors/500</InternalServerError> <InternalServerError>/pages/error/server-errors/500</InternalServerError>
<DefaultPage>/pages/error/default</DefaultPage> <DefaultPage>/pages/error/default</DefaultPage>
</FailureCallback> </ErrorCallback>
</LoginResponse>
</UIConfigs> </UIConfigs>
<ArtifactDownloadEndpoint>https://localhost:9443/api/application-mgt/v1.0/artifact</ArtifactDownloadEndpoint> <ArtifactDownloadEndpoint>https://localhost:9443/api/application-mgt/v1.0/artifact</ArtifactDownloadEndpoint>

Loading…
Cancel
Save