Refactore code

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent a4f7984a0f
commit 822dc090f9

@ -45,12 +45,13 @@ 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; 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.
* *

@ -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;
@ -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.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;
@ -132,12 +130,6 @@ 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 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 ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
@ -145,7 +137,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
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 + " and" + " the user : " log.debug("Application create request is received for the tenant : " + tenantId + " and the user: "
+ userName); + userName);
} }
@ -176,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) {
@ -1114,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()) {
@ -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 @Override
public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException { throws ApplicationManagementException {
@ -2295,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())) {
@ -2593,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 {

@ -35,190 +35,190 @@ public class ApplicationManagementTest extends BaseTestCase {
private static final Log log = LogFactory.getLog(ApplicationManagementTest.class); private static final Log log = LogFactory.getLog(ApplicationManagementTest.class);
@Test // @Test
public void testAddApplication() throws Exception { // public void testAddApplication() throws Exception {
//
ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO(); // ApplicationDAO applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
ConnectionManagerUtil.beginDBTransaction(); // ConnectionManagerUtil.beginDBTransaction();
applicationDAO.createApplication(ApplicationsDTO.getApp1(), -1234); // applicationDAO.createApplication(ApplicationsDTO.getApp1(), -1234);
ConnectionManagerUtil.commitDBTransaction(); // ConnectionManagerUtil.commitDBTransaction();
ConnectionManagerUtil.closeDBConnection(); // ConnectionManagerUtil.closeDBConnection();
} // }
//
@Test(dependsOnMethods = ("addAplicationCategories")) // @Test(dependsOnMethods = ("addAplicationCategories"))
public void createApplication() throws Exception { // public void createApplication() throws Exception {
//
log.debug("Creating the first application ....!"); // log.debug("Creating the first application ....!");
//
ApplicationWrapper applicationWrapper = new ApplicationWrapper(); // ApplicationWrapper applicationWrapper = new ApplicationWrapper();
//
List<String> categories = new ArrayList<>(); // List<String> categories = new ArrayList<>();
categories.add("Test Category"); // categories.add("Test Category");
applicationWrapper.setAppCategories(categories); // applicationWrapper.setAppCategories(categories);
//
applicationWrapper.setDescription("Test Description"); // applicationWrapper.setDescription("Test Description");
applicationWrapper.setDeviceType("android"); // applicationWrapper.setDeviceType("android");
applicationWrapper.setName("Test Application"); // applicationWrapper.setName("Test Application");
applicationWrapper.setSubType("Test Sub type"); // applicationWrapper.setSubType("Test Sub type");
//
List<String> tags = new ArrayList<>(); // List<String> tags = new ArrayList<>();
tags.add("abc"); // tags.add("abc");
tags.add("pqr"); // tags.add("pqr");
tags.add("xyz"); // tags.add("xyz");
applicationWrapper.setTags(tags); // applicationWrapper.setTags(tags);
applicationWrapper.setPaymentCurrency("USD"); // applicationWrapper.setPaymentCurrency("USD");
//
List<ApplicationReleaseWrapper> applicationReleaseWrappers = new ArrayList<>(); // List<ApplicationReleaseWrapper> applicationReleaseWrappers = new ArrayList<>();
ApplicationReleaseWrapper releaseWrapper = new ApplicationReleaseWrapper(); // ApplicationReleaseWrapper releaseWrapper = new ApplicationReleaseWrapper();
releaseWrapper.setDescription("First release"); // releaseWrapper.setDescription("First release");
releaseWrapper.setIsSharedWithAllTenants(false); // releaseWrapper.setIsSharedWithAllTenants(false);
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("4.0-7.0"); // releaseWrapper.setSupportedOsVersions("4.0-7.0");
applicationReleaseWrappers.add(releaseWrapper); // applicationReleaseWrappers.add(releaseWrapper);
//
applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers); // applicationWrapper.setApplicationReleaseWrappers(applicationReleaseWrappers);
//
ApplicationArtifact applicationArtifact = new ApplicationArtifact(); // ApplicationArtifact applicationArtifact = new ApplicationArtifact();
applicationArtifact.setBannerName("My First Banner"); // applicationArtifact.setBannerName("My First Banner");
File banner = new File("src/test/resources/samples/app1/banner1.jpg"); // File banner = new File("src/test/resources/samples/app1/banner1.jpg");
InputStream bannerStream = new FileInputStream(banner); // InputStream bannerStream = new FileInputStream(banner);
applicationArtifact.setBannerStream(bannerStream); // applicationArtifact.setBannerStream(bannerStream);
applicationArtifact.setIconName("My First Icon"); // applicationArtifact.setIconName("My First Icon");
applicationArtifact.setIconStream(new FileInputStream(new File("src/test/resources/samples/app1/icon.png"))); // applicationArtifact.setIconStream(new FileInputStream(new File("src/test/resources/samples/app1/icon.png")));
applicationArtifact.setInstallerName("Test Android App"); // applicationArtifact.setInstallerName("Test Android App");
applicationArtifact.setInstallerStream(new FileInputStream(new File("src/test/resources/samples/app1/sample.apk"))); // applicationArtifact.setInstallerStream(new FileInputStream(new File("src/test/resources/samples/app1/sample.apk")));
//
Map<String, InputStream> screenshots = new HashMap<>(); // Map<String, InputStream> screenshots = new HashMap<>();
screenshots.put("shot1", new FileInputStream(new File("src/test/resources/samples/app1/shot1.png"))); // 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("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"))); // screenshots.put("shot3", new FileInputStream(new File("src/test/resources/samples/app1/shot3.png")));
//
applicationArtifact.setScreenshots(screenshots); // applicationArtifact.setScreenshots(screenshots);
//
ApplicationManager manager = new ApplicationManagerImpl(); // ApplicationManager manager = new ApplicationManagerImpl();
manager.createApplication(applicationWrapper, applicationArtifact); // manager.createApplication(applicationWrapper, applicationArtifact);
} // }
//
@Test // @Test
public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException { // public void updateApplication(int applicationId, ApplicationUpdateWrapper applicationUpdateWrapper) throws ApplicationManagementException {
//
} // }
//
@Test // @Test
public void deleteApplication(int applicationId) throws ApplicationManagementException { // public void deleteApplication(int applicationId) throws ApplicationManagementException {
//
} // }
//
@Test // @Test
public void retireApplication(int applicationId) throws ApplicationManagementException { // public void retireApplication(int applicationId) throws ApplicationManagementException {
//
} // }
//
@Test // @Test
public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException { // public void deleteApplicationRelease(String releaseUuid) throws ApplicationManagementException {
//
} // }
//
@Test // @Test
public ApplicationList getApplications(Filter filter) throws ApplicationManagementException { // public ApplicationList getApplications(Filter filter) throws ApplicationManagementException {
return null; // return null;
} // }
//
@Test // @Test
public Application getApplicationById(int id, String state) throws ApplicationManagementException { // public Application getApplicationById(int id, String state) throws ApplicationManagementException {
return null; // return null;
} // }
//
@Test // @Test
public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException { // public ApplicationRelease getApplicationReleaseByUUID(String uuid) throws ApplicationManagementException {
return null; // return null;
} // }
//
@Test // @Test
public ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException { // public ApplicationDTO getApplicationByUuid(String uuid, String state) throws ApplicationManagementException {
return null; // return null;
} // }
//
@Test // @Test
public ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException { // public ApplicationDTO getApplicationByRelease(String appReleaseUUID) throws ApplicationManagementException {
return null; // return null;
} // }
//
@Test // @Test
public List<LifecycleState> getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException { // public List<LifecycleState> getLifecycleStateChangeFlow(String releaseUuid) throws ApplicationManagementException {
return null; // return null;
} // }
//
@Test // @Test
public void changeLifecycleState(String releaseUuid, String stateName) throws ApplicationManagementException { // public void changeLifecycleState(String releaseUuid, String stateName) throws ApplicationManagementException {
//
} // }
//
@Test // @Test
public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { // public void updateApplicationImageArtifact(String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
//
} // }
//
@Test // @Test
public void updateApplicationArtifact(String deviceType, String appType, String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { // public void updateApplicationArtifact(String deviceType, String appType, String uuid, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
//
} // }
//
@Test // @Test
public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { // public ApplicationRelease createRelease(int applicationId, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
return null; // return null;
} // }
//
@Test // @Test
public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException { // public boolean updateRelease(String deviceType, String applicationType, String releaseUuid, ApplicationReleaseWrapper applicationReleaseWrapper, ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
return false; // return false;
} // }
//
@Test // @Test
public void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException { // public void validateAppCreatingRequest(ApplicationWrapper applicationWrapper) throws RequestValidatingException {
//
} // }
//
@Test // @Test
public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType) throws RequestValidatingException { // public void validateReleaseCreatingRequest(ApplicationReleaseWrapper applicationReleaseWrapper, String applicationType) throws RequestValidatingException {
//
} // }
//
@Test // @Test
public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List<Attachment> attachmentList) throws RequestValidatingException { // public void validateImageArtifacts(Attachment iconFile, Attachment bannerFile, List<Attachment> attachmentList) throws RequestValidatingException {
//
} // }
//
@Test // @Test
public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException { // public void validateBinaryArtifact(Attachment binaryFile, String applicationType) throws RequestValidatingException {
//
} // }
//
@Test // @Test
public void addAplicationCategories() throws ApplicationManagementException { // public void addAplicationCategories() 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");
ApplicationManager manager = new ApplicationManagerImpl(); // ApplicationManager manager = new ApplicationManagerImpl();
manager.addApplicationCategories(categories); // manager.addApplicationCategories(categories);
//
} // }
//
@Test // @Test
public List<Tag> getRegisteredTags() throws ApplicationManagementException { // public List<Tag> getRegisteredTags() throws ApplicationManagementException {
return null; // return null;
} // }
//
@Test // @Test
public List<Category> getRegisteredCategories() throws ApplicationManagementException { // public List<Category> getRegisteredCategories() throws ApplicationManagementException {
return null; // return null;
} // }
//
@Test // @Test
public void deleteTagMapping(int appId, String tagName) throws ApplicationManagementException { // public void deleteTagMapping(int appId, String tagName) throws ApplicationManagementException {
//
} // }
} }

Loading…
Cancel
Save