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

Improve APPM device sub updating logic

See merge request entgra/carbon-device-mgt!163
merge-requests/164/head^2
Dharmakeerthi Lasantha 5 years ago
commit b827ba063e

@ -189,19 +189,18 @@ public interface ApplicationManager {
/***
*
* @param deviceType Device type which is supported for the Application.
* @param releaseUuid UUID of the application release.
* @param entAppReleaseWrapper {@link ApplicationReleaseDTO}
* @param applicationArtifact {@link ApplicationArtifact}
* @return If the application release is updated correctly True returns, otherwise retuen False
*/
boolean updateEntAppRelease(String deviceType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
boolean updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
boolean updatePubAppRelease(String deviceType, String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
boolean updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
boolean updateWebAppRelease(String deviceType, String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
boolean updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
/***
@ -254,7 +253,7 @@ public interface ApplicationManager {
String getInstallableLifecycleState() throws ApplicationManagementException;
void updateSubsStatus (int operationId, String status) throws ApplicationManagementException;
void updateSubsStatus (int deviceId, int operationId, String status) throws ApplicationManagementException;
/**

@ -39,7 +39,7 @@ public interface ReviewManager {
* @return {@link Review} Added review
* @throws ReviewManagementException Exceptions of the reviewTmp management.
*/
boolean addReview(ReviewWrapper reviewWrapper, String uuid, boolean allowMultipleReviews)
Review addReview(ReviewWrapper reviewWrapper, String uuid, boolean allowMultipleReviews)
throws ReviewManagementException, ApplicationManagementException;
boolean addReplyComment(ReviewWrapper reviewWrapper, String uuid, int parentReviewId)

@ -35,17 +35,17 @@ public class ApplicationUpdateWrapper {
required = true)
private String description;
@ApiModelProperty(name = "appCategory",
value = "CategoryDTO of the application",
@ApiModelProperty(name = "categories",
value = "List of app categories.",
required = true,
example = "Educational, Gaming, Travel, Entertainment etc")
private String appCategory;
private List<String> categories;
@ApiModelProperty(name = "subType",
@ApiModelProperty(name = "subMethod",
value = "Subscription type of the application",
required = true,
example = "PAID, FREE")
private String subType;
private String subMethod;
@ApiModelProperty(name = "paymentCurrency",
value = "Payment currency of the application",
@ -67,21 +67,19 @@ public class ApplicationUpdateWrapper {
public void setName(String name) { this.name = name; }
public String getAppCategory() {
return appCategory;
}
public List<String> getCategories() { return categories; }
public void setAppCategory(String appCategory) {
this.appCategory = appCategory;
public void setCategories(List<String> categories) {
this.categories = categories;
}
public List<String> getTags() { return tags; }
public void setTags(List<String> tags) { this.tags = tags; }
public String getSubType() { return subType; }
public String getSubMethod() { return subMethod; }
public void setSubType(String subType) { this.subType = subType; }
public void setSubMethod(String subMethod) { this.subMethod = subMethod; }
public String getPaymentCurrency() { return paymentCurrency; }

@ -27,18 +27,18 @@ import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManageme
import java.util.List;
/**
* ApplicationDAO is responsible for handling all the Database related operations related with ApplicationDTO Management.
* ApplicationDAO is responsible for handling all the Database related operations related with Application Management.
*/
public interface ApplicationDAO {
/**
* To create an application.
* Use to create an application for given application data and tenant.
*
* @param application ApplicationDTO that need to be created.
* @return Created Application.
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
* @param applicationDTO ApplicationDTO that need to be created.
* @return Primary key of the created application.
* @throws ApplicationManagementDAOException if error occurred wile executing query to inser app data into database.
*/
int createApplication(ApplicationDTO application, int tenantId) throws ApplicationManagementDAOException;
int createApplication(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementDAOException;
/**
* To add tags for a particular application.
@ -66,7 +66,7 @@ public interface ApplicationDAO {
void deleteApplicationTags(List<Integer> tagIds, int applicationId, int tenantId) throws ApplicationManagementDAOException;
void deleteApplicationTags(Integer tagId, int applicationId, int tenantId) throws ApplicationManagementDAOException;
void deleteApplicationTag(Integer tagId, int applicationId, int tenantId) throws ApplicationManagementDAOException;
void deleteApplicationTags(int applicationId, int tenantId) throws ApplicationManagementDAOException;
@ -82,7 +82,7 @@ public interface ApplicationDAO {
List<CategoryDTO> getAllCategories(int tenantId) throws ApplicationManagementDAOException;
List<Integer> getCategoryIdsForCategoryNames(List<String> CatgeoryNames, int tenantId)
List<Integer> getCategoryIdsForCategoryNames(List<String> categoryNames, int tenantId)
throws ApplicationManagementDAOException;
List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException;
@ -94,7 +94,10 @@ public interface ApplicationDAO {
void addCategoryMapping(List<Integer> categoryIds, int applicationId, int tenantId)
throws ApplicationManagementDAOException;
void deleteCategoryMapping (int applicationId, int tenantId) throws ApplicationManagementDAOException;
void deleteAppCategories(int applicationId, int tenantId) throws ApplicationManagementDAOException;
void deleteAppCategories(List<Integer> categoryIds, int applicationId, int tenantId)
throws ApplicationManagementDAOException;
void deleteCategory(int categoryId, int tenantId) throws ApplicationManagementDAOException;
@ -111,14 +114,6 @@ public interface ApplicationDAO {
*/
List<ApplicationDTO> getApplications(Filter filter, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException;
/**
* To get the UUID of latest app release that satisfy the given criteria.
*
* @param appId application id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
String getUuidOfLatestRelease(int appId) throws ApplicationManagementDAOException;
/**
* To get the application with the given id
*
@ -127,7 +122,7 @@ public interface ApplicationDAO {
* @return the application
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
ApplicationDTO getApplicationById(int applicationId, int tenantId) throws ApplicationManagementDAOException;
ApplicationDTO getApplication(int applicationId, int tenantId) throws ApplicationManagementDAOException;
/**
* To get the application with the given uuid
@ -137,7 +132,15 @@ public interface ApplicationDAO {
* @return the application
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId) throws ApplicationManagementDAOException;
ApplicationDTO getApplication(String releaseUuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To get the UUID of latest app release that satisfy the given criteria.
*
* @param appId application id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
String getUuidOfLatestRelease(int appId) throws ApplicationManagementDAOException;
/**
* Verify whether application exist for given application name and device type. Because a name and device type is
@ -180,19 +183,7 @@ public interface ApplicationDAO {
* @return count of the applications
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
int getApplicationCount(Filter filter, int tenantId) throws ApplicationManagementDAOException;
/**
* To delete the tags of a application.
*
* @param tags Tags which are going to delete.
* @param applicationId ID of the application to delete the tags.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
void deleteTags(List<String> tags, int applicationId, int tenantId) throws ApplicationManagementDAOException;
String getApplicationSubTypeByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException;
int getApplicationCount(Filter filter, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException;
void deleteApplication(int appId, int tenantId) throws ApplicationManagementDAOException;

@ -39,44 +39,6 @@ public interface ApplicationReleaseDAO {
ApplicationReleaseDTO createRelease(ApplicationReleaseDTO applicationRelease, int appId, int tenantId) throws
ApplicationManagementDAOException;
/**
* To get a release details with the particular version.
* @param applicationName name of the application to get the release.
* @param versionName Name of the version
* @param applicationType Type of the application release
* @param releaseType type of the release
* @param tenantId tenantId of the application
* @return ApplicationReleaseDTO for the particular version of the given application
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
ApplicationReleaseDTO getRelease(String applicationName,String applicationType, String versionName,
String releaseType, int tenantId) throws
ApplicationManagementDAOException;
/**
* To get all the releases of a particular application.
*
* @param applicationId Id of the application
* @param tenantId tenant id of the application
* @return list of the application releases
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
List<ApplicationReleaseDTO> getReleases(int applicationId, int tenantId) throws
ApplicationManagementDAOException;
/**
* To get the release by state.
*
* @param appId Id of the ApplicationDTO
* @param tenantId tenant id of the application
* @param state state of the application
* @return list of the application releases
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
List<ApplicationReleaseDTO> getReleaseByState(int appId, int tenantId, String state)
throws ApplicationManagementDAOException;
/**
* To update an ApplicationDTO release.
*
@ -108,8 +70,6 @@ public interface ApplicationReleaseDAO {
List<Double> getReleaseRatings(String uuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To delete a particular release.
*
@ -120,30 +80,8 @@ public interface ApplicationReleaseDAO {
void deleteReleases(List<Integer> applicationReleaseIds) throws ApplicationManagementDAOException;
/**
* To get release details of a specific application.
*
* @param applicationId ID of the application.
* @param releaseUuid UUID of the application release.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
ApplicationReleaseDTO getReleaseByIds(int applicationId, String releaseUuid, int tenantId) throws
ApplicationManagementDAOException;
ApplicationReleaseDTO getReleaseByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To verify whether application release exist or not.
*
* @param appId ID of the application.
* @param uuid UUID of the application release.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
boolean verifyReleaseExistence(int appId, String uuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To verify whether application release exist or not for the given app release version.
*
@ -170,7 +108,7 @@ public interface ApplicationReleaseDAO {
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
boolean verifyReleaseExistenceByUuid(String uuid, int tenantId) throws ApplicationManagementDAOException;
boolean isReleaseExist(String uuid, int tenantId) throws ApplicationManagementDAOException;
String getReleaseHashValue(String uuid, int tenantId) throws ApplicationManagementDAOException;

@ -21,11 +21,8 @@ package org.wso2.carbon.device.application.mgt.core.dao;
import org.wso2.carbon.device.application.mgt.common.response.Review;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException;
import java.sql.SQLException;
import java.util.List;
/**
@ -43,7 +40,7 @@ import java.util.List;
* @return If reviewTmp is added successfully, it return true otherwise false
* @throws ReviewManagementDAOException Exceptions of the reviewTmp management DAO.
*/
boolean addReview(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException;
int addReview(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException;
/**
* To verify whether user has already commented for the application release or not.
@ -76,9 +73,7 @@ import java.util.List;
* @return {@link Review}
* @throws ReviewManagementDAOException Exceptions of the review management DAO.
*/
ReviewDTO getReview(int reviewId) throws ReviewManagementDAOException;
ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException;
ReviewDTO getReview(int reviewId, int tenantId) throws ReviewManagementDAOException;
/**
@ -113,51 +108,16 @@ import java.util.List;
List<Integer> getAllAppRatingValues(List<String> uuids, int tenantId) throws ReviewManagementDAOException;
/**
* To get count of comments by application details.
*
* @param appType type of the commented application.
* @param appName name of the commented application.
* @param version version of the commented application.
* @return Count of the comments
* @throws ReviewManagementException Exceptions of the comment management.
* @throws DBConnectionException db connection exception.
* @throws SQLException sql exception
*/
int getReviewCountByApp(String appType, String appName, String version)
throws ReviewManagementException, DBConnectionException, SQLException;
/**
* To delete review using review id and uuid of the application release.
*
* @param reviewId id of the review
* @return If review is successfully deleted return 1, otherwise returns 0.
* @throws ReviewManagementDAOException Review management DAO exception.
*/
void deleteReview(int reviewId, int tenantId) throws ReviewManagementDAOException;
void deleteReviews(List<Integer> reviewIds, int tenantId) throws ReviewManagementDAOException;
void deleteAllChildCommentsOfReview(int rootParentId, int tenantId) throws ReviewManagementDAOException;
/**
* To delete comments using application details.
*
* @param appType type of the commented application.
* @param appName name of the commented application.
* @param version version of the commented application.
* @throws ReviewManagementException Exceptions of the comment management.
*/
void deleteReviews(String appType, String appName, String version) throws ReviewManagementException;
/**
* To get review count for a specific application release
*
* @param uuid uuid of the application release
* @return Review count
* @throws ReviewManagementDAOException Review management DAO exception
*/
int getReviewCount(String uuid) throws ReviewManagementDAOException;
}

@ -18,11 +18,9 @@
*/
package org.wso2.carbon.device.application.mgt.core.dao;
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.DeviceSubscriptionDTO;
import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.mgt.common.Device;
import java.util.List;
import java.util.Map;
@ -81,6 +79,9 @@ public interface SubscriptionDAO {
List<Integer> getSubscribedDeviceIds(List<Integer> deviceIds, int tenantId) throws ApplicationManagementDAOException;
boolean updateDeviceSubStatus (int operationId, String status, int tenantcId) throws ApplicationManagementDAOException;
List<Integer> getDeviceSubIdsForOperation (int operationId, int tenantId) throws ApplicationManagementDAOException;
boolean updateDeviceSubStatus(int deviceId, List<Integer> deviceSubIds, String status, int tenantcId)
throws ApplicationManagementDAOException;
}

@ -51,45 +51,47 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
@Override
public int createApplication(ApplicationDTO application, int tenantId) throws ApplicationManagementDAOException {
public int createApplication(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to create an application");
log.debug("ApplicationDTO Details : ");
log.debug("App Name : " + application.getName() + " App Type : " + application.getType());
log.debug("App Name : " + applicationDTO.getName() + " App Type : " + applicationDTO.getType());
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
int applicationId = -1;
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement("INSERT INTO AP_APP "
String sql = "INSERT INTO AP_APP "
+ "(NAME, "
+ "DESCRIPTION, "
+ "TYPE, "
+ "SUB_TYPE, "
+ "TENANT_ID, "
+ "DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS);
stmt.setString(1, application.getName());
stmt.setString(2, application.getDescription());
stmt.setString(3, application.getType());
stmt.setString(4, application.getSubType());
+ "DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?)";
int applicationId = -1;
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
stmt.setString(1, applicationDTO.getName());
stmt.setString(2, applicationDTO.getDescription());
stmt.setString(3, applicationDTO.getType());
stmt.setString(4, applicationDTO.getSubType());
stmt.setInt(5, tenantId);
stmt.setInt(6, application.getDeviceTypeId());
stmt.setInt(6, applicationDTO.getDeviceTypeId());
stmt.executeUpdate();
rs = stmt.getGeneratedKeys();
try (ResultSet rs = stmt.getGeneratedKeys()) {
if (rs.next()) {
applicationId = rs.getInt(1);
}
return applicationId;
}
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when application creation", e);
String msg = "Error occurred while obtaining the DB connection to create an application which has "
+ "application name " + applicationDTO.getName();
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding the application", e);
} finally {
DAOUtil.cleanupResources(stmt, rs);
String msg = "Error occurred while executing SQL to create an application which has application name "
+ applicationDTO.getName();
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
@ -100,9 +102,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset()));
}
int paramIndex = 1;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT "
+ "AP_APP.ID AS APP_ID, "
+ "AP_APP.NAME AS APP_NAME, "
@ -139,7 +138,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "WHERE AP_APP.TENANT_ID = ?";
if (filter == null) {
throw new ApplicationManagementDAOException("Filter need to be instantiated");
String msg = "Filter is not instantiated.";
log.error(msg);
throw new ApplicationManagementDAOException(msg);
}
if (!StringUtils.isEmpty(filter.getAppType())) {
@ -179,8 +180,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
sql += " ORDER BY APP_ID " + sortingOrder +" LIMIT ? OFFSET ? ";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql);
){
stmt.setInt(paramIndex++, tenantId);
if (filter.getAppType() != null && !filter.getAppType().isEmpty()) {
@ -217,19 +219,20 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.setInt(paramIndex++, filter.getLimit());
}
stmt.setInt(paramIndex, filter.getOffset());
rs = stmt.executeQuery();
try (ResultSet rs = stmt.executeQuery() ) {
return DAOUtil.loadApplications(rs);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant"
+ " " + tenantId + ". While executing " + sql, e);
}
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection while "
+ "getting application list for the tenant " + tenantId,
e);
} catch (JSONException e) {
throw new ApplicationManagementDAOException("Error occurred while parsing JSON ", e);
} finally {
DAOUtil.cleanupResources(stmt, rs);
String msg = "Error occurred while obtaining the DB connection while getting application list for the "
+ "tenant " + tenantId;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while getting application list for the tenant " + tenantId + ". While "
+ "executing " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
@ -269,52 +272,107 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
@Override
public int getApplicationCount(Filter filter, int tenantId) throws ApplicationManagementDAOException {
public int getApplicationCount(Filter filter,int deviceTypeId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting application count from the database");
log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset()));
log.debug("Getting application count for filtering app data from the database");
}
int paramIndex = 1;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
int count = 0;
String sql = "SELECT count(AP_APP.ID) AS APP_COUNT "
+ "FROM AP_APP "
+ "INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP.ID = AP_APP_RELEASE.AP_APP_ID AND "
+ "AP_APP.TENANT_ID = AP_APP_RELEASE.TENANT_ID "
+ "WHERE AP_APP.TENANT_ID = ?";
if (filter == null) {
throw new ApplicationManagementDAOException("Filter need to be instantiated");
}
try {
conn = this.getDBConnection();
sql += "SELECT count(APP.ID) AS APP_COUNT FROM AP_APP AS APP WHERE TENANT_ID = ?";
if (filter.getAppName() != null) {
sql += " AND LOWER (APP.NAME) LIKE ? ";
if (!StringUtils.isEmpty(filter.getAppType())) {
sql += " AND AP_APP.TYPE = ?";
}
if (!StringUtils.isEmpty(filter.getAppName())) {
sql += " AND LOWER (AP_APP.NAME) ";
if (filter.isFullMatch()) {
sql += "= ?";
} else {
sql += "LIKE ?";
}
}
if (!StringUtils.isEmpty(filter.getSubscriptionType())) {
sql += " AND AP_APP.SUB_TYPE = ?";
}
if (filter.getMinimumRating() > 0) {
sql += " AND AP_APP.RATING >= ?";
}
if (!StringUtils.isEmpty(filter.getVersion())) {
sql += " AND AP_APP_RELEASE.VERSION = ?";
}
if (!StringUtils.isEmpty(filter.getAppReleaseType())) {
sql += " AND AP_APP_RELEASE.RELEASE_TYPE = ?";
}
if (!StringUtils.isEmpty(filter.getAppReleaseState())) {
sql += " AND AP_APP_RELEASE.CURRENT_STATE = ?";
}
if (deviceTypeId != -1) {
sql += " AND AP_APP.DEVICE_TYPE_ID = ?";
}
sql += ";";
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql);
stmt.setInt(paramIndex++, tenantId);
if (filter.getAppName() != null) {
stmt.setString(paramIndex, "%" + filter.getAppName().toLowerCase() + "%");
if (filter.getAppType() != null && !filter.getAppType().isEmpty()) {
stmt.setString(paramIndex++, filter.getAppType());
}
if (filter.getAppName() != null && !filter.getAppName().isEmpty()) {
if (filter.isFullMatch()) {
stmt.setString(paramIndex++, filter.getAppName().toLowerCase());
} else {
stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%");
}
}
if (!StringUtils.isEmpty(filter.getSubscriptionType())) {
stmt.setString(paramIndex++, filter.getSubscriptionType());
}
if (filter.getMinimumRating() > 0) {
stmt.setInt(paramIndex++, filter.getMinimumRating());
}
if (!StringUtils.isEmpty(filter.getVersion())) {
stmt.setString(paramIndex++, filter.getVersion());
}
if (!StringUtils.isEmpty(filter.getAppReleaseType())) {
stmt.setString(paramIndex++, filter.getAppReleaseType());
}
if (!StringUtils.isEmpty(filter.getAppReleaseState())) {
stmt.setString(paramIndex++, filter.getAppReleaseState());
}
if (deviceTypeId > 0 ) {
stmt.setInt(paramIndex, deviceTypeId);
}
rs = stmt.executeQuery();
if (rs.next()) {
count = rs.getInt("APP_COUNT");
return rs.getInt("APP_COUNT");
}
return 0;
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting application List", e);
throw new ApplicationManagementDAOException("Error occurred while getting application list for the tenant"
+ " " + tenantId + ". While executing " + sql, e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection while "
+ "getting application list for the tenant " + tenantId,
e);
} finally {
DAOUtil.cleanupResources(stmt, rs);
}
return count;
}
@Override
public ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId)
public ApplicationDTO getApplication(String releaseUuid, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting application with the release UUID: " + releaseUuid + " from the database");
@ -377,8 +435,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
throw new ApplicationManagementDAOException(
"Error occurred while getting application details with app release uuid " + releaseUuid +
" 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) {
@ -389,7 +445,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
@Override
public ApplicationDTO getApplicationById(int applicationId, int tenantId)
public ApplicationDTO getApplication(int applicationId, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting application with the id (" + applicationId + ") from the database");
@ -811,16 +867,16 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
@Override
public void deleteCategoryMapping (int applicationId, int tenantId) throws ApplicationManagementDAOException{
public void deleteAppCategories(int applicationId, int tenantId) throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Category mappings.");
}
Connection conn;
String sql = "DELETE FROM "
+ "AP_APP_CATEGORY_MAPPING cm "
+ "AP_APP_CATEGORY_MAPPING "
+ "WHERE "
+ "cm.AP_APP_ID = ? AND "
+ "cm.TENANT_ID = ?";
+ "AP_APP_ID = ? AND "
+ "TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){
@ -838,6 +894,37 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
}
@Override
public void deleteAppCategories(List<Integer> categoryIds, int applicationId, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Tag mappings.");
}
Connection conn;
String sql = "DELETE FROM "
+ "AP_APP_CATEGORY_MAPPING WHERE "
+ "AP_APP_CATEGORY_ID = ? AND "
+ "AP_APP_ID = ? AND "
+ "TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){
for (Integer categoryId : categoryIds){
stmt.setInt(1, categoryId);
stmt.setInt(2, applicationId);
stmt.setInt(3, tenantId);
stmt.addBatch();
}
stmt.executeBatch();
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Error occurred while obtaining the DB connection when deleting category mapping", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred when deleting category mapping", e);
}
}
@Override
public void deleteCategory(int categoryId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
@ -845,10 +932,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
Connection conn;
String sql = "DELETE FROM " +
"AP_APP_CATEGORY cat " +
"AP_APP_CATEGORY " +
"WHERE " +
"cat.ID = ? AND " +
"cat.TENANT_ID = ?";
"ID = ? AND " +
"TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1120,11 +1207,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
Connection conn;
String sql = "DELETE FROM "
+ "AP_APP_TAG_MAPPING tm "
+ "WHERE "
+ "tm.AP_APP_TAG_ID = ? AND "
+ "tm.AP_APP_ID = ? AND "
+ "tm.TENANT_ID = ?";
+ "AP_APP_TAG_MAPPING WHERE "
+ "AP_APP_TAG_ID = ? AND "
+ "AP_APP_ID = ? AND "
+ "TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){
@ -1145,17 +1231,17 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
@Override
public void deleteApplicationTags(Integer tagId, int applicationId, int tenantId) throws ApplicationManagementDAOException{
public void deleteApplicationTag (Integer tagId, int applicationId, int tenantId) throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Tag mapping.");
}
Connection conn;
String sql = "DELETE FROM "
+ "AP_APP_TAG_MAPPING tm "
+ "AP_APP_TAG_MAPPING "
+ "WHERE "
+ "tm.AP_APP_TAG_ID = ? AND "
+ "tm.AP_APP_ID = ? AND "
+ "tm.TENANT_ID = ?";
+ "AP_APP_TAG_ID = ? AND "
+ "AP_APP_ID = ? AND "
+ "TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1179,10 +1265,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
Connection conn;
String sql = "DELETE FROM "
+ "AP_APP_TAG_MAPPING tm "
+ "AP_APP_TAG_MAPPING "
+ "WHERE "
+ "tm.AP_APP_ID = ? AND "
+ "tm.TENANT_ID = ?";
+ "AP_APP_ID = ? AND "
+ "TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1207,10 +1293,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
Connection conn;
String sql = "DELETE FROM " +
"AP_APP_TAG_MAPPING tm " +
"AP_APP_TAG_MAPPING " +
"WHERE " +
"tm.AP_APP_ID = ? AND " +
"tm.TENANT_ID = ?";
"AP_APP_ID = ? AND " +
"TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1235,10 +1321,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
Connection conn;
String sql = "DELETE FROM " +
"AP_APP_TAG tag " +
"AP_APP_TAG " +
"WHERE " +
"tag.ID = ? AND " +
"tag.TENANT_ID = ?";
"ID = ? AND " +
"TENANT_ID = ?";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1348,35 +1434,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
}
@Override
public void deleteTags(List<String> tags, int applicationId, int tenantId) throws ApplicationManagementDAOException {
Connection conn;
PreparedStatement stmt = null;
String sql = "DELETE FROM AP_APP_TAG WHERE TAG = ? AND AP_APP_ID = ? AND TENANT_ID = ?;";
try{
conn = this.getDBConnection();
conn.setAutoCommit(false);
stmt = conn.prepareStatement(sql);
for (String tag : tags) {
stmt.setString(1, tag);
stmt.setInt(2, applicationId);
stmt.setInt(3, tenantId);
stmt.addBatch();
}
stmt.executeBatch();
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while deleting tags of application: " + applicationId, e);
} finally {
DAOUtil.cleanupResources(stmt, null);
}
}
@Override
public boolean isExistingAppName(String appName, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException {
Connection conn;
@ -1406,51 +1463,15 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
}
}
@Override
public String getApplicationSubTypeByUUID(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection conn;
String sql;
try {
conn = this.getDBConnection();
sql = "SELECT AP_APP.SUB_TYPE AS SUB_TYPE "
+ "FROM AP_APP "
+ "WHERE "
+ "AP_APP.ID = (SELECT AP_APP_RELEASE.AP_APP_ID "
+ " FROM AP_APP_RELEASE "
+ " WHERE AP_APP_RELEASE.UUID = ?) "
+ "AND AP_APP.TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)){
stmt.setString(1, uuid);
stmt.setInt(2, tenantId);
try(ResultSet rs = stmt.executeQuery()){
if (rs.next()){
return rs.getString("SUB_TYPE");
}
return null;
}
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get subscription type of the application "
+ "for given application release uuid. UUID:." + uuid;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while getting application subscribe type for given application release UUID: "
+ uuid + " from database.";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public void deleteApplication(int appId, int tenantId) throws ApplicationManagementDAOException {
Connection conn;
String sql;
try {
conn = this.getDBConnection();
sql = "DELETE AP_APP ap "
+ "WHERE ap.ID = ? AND "
+ "ap.TENANT_ID = ?";
sql = "DELETE FROM AP_APP "
+ "WHERE ID = ? AND "
+ "TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)){
stmt.setInt(1, appId);
stmt.setInt(2, tenantId);

@ -33,30 +33,20 @@ import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList;
import java.util.List;
/**
* GenericApplicationReleaseDAOImpl holds the implementation of ApplicationReleaseDTO related DAO operations.
* GenericApplicationReleaseDAOImpl holds the implementation of ApplicationRelease related DAO operations.
*/
public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ApplicationReleaseDAO {
private static final Log log = LogFactory.getLog(GenericApplicationReleaseDAOImpl.class);
/**
* To insert the ApplicationDTO Release Details.
*
* @param appId Id of the application
* @param applicationReleaseDTO ApplicationDTO Release the properties of which that need to be inserted.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
@Override public ApplicationReleaseDTO createRelease(ApplicationReleaseDTO applicationReleaseDTO, int appId, int tenantId)
@Override
public ApplicationReleaseDTO createRelease(ApplicationReleaseDTO applicationReleaseDTO, int appId, int tenantId)
throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
String sql = "INSERT INTO AP_APP_RELEASE "
+ "(DESCRIPTION,"
+ "VERSION,"
@ -77,12 +67,11 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
+ "SUPPORTED_OS_VERSIONS,"
+ "CURRENT_STATE,"
+ "AP_APP_ID) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
String generatedColumns[] = { "ID" };
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql, generatedColumns);
Connection connection = this.getDBConnection();
try (PreparedStatement statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)){
statement.setString(1, applicationReleaseDTO.getDescription());
statement.setString(2, applicationReleaseDTO.getVersion());
statement.setInt(3, tenantId);
@ -103,129 +92,29 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
statement.setString(18, applicationReleaseDTO.getCurrentState().toUpperCase());
statement.setInt(19, appId);
statement.executeUpdate();
resultSet = statement.getGeneratedKeys();
try(ResultSet resultSet = statement.getGeneratedKeys()){
if (resultSet.next()) {
applicationReleaseDTO.setId(resultSet.getInt(1));
}
return applicationReleaseDTO;
} catch (SQLException e) {
log.error("SQL Exception while trying to release an application by executing the query " + sql, e);
throw new ApplicationManagementDAOException(
"SQL Exception while trying to release an application by executing the query " + sql, e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database Connection Exception while trying to release a new version", e);
} finally {
DAOUtil.cleanupResources(statement, resultSet);
}
}
/**
* To get latest updated app release details of a specific application.
*
* @param applicationName Name of the application.
* @param applicationType Type of the application.
* @param versionName version name of the application.
* @param releaseType type of the application release.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
@Override public ApplicationReleaseDTO getRelease(String applicationName, String applicationType, String versionName,
String releaseType, int tenantId) throws ApplicationManagementDAOException {
//todo no usage
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS "
+ "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS "
+ "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, AR.ICON_LOCATION AS "
+ "ICON_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, "
+ "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS "
+ "AS SHARED, AR.APP_META_INFO AS APP_META_INFO, AR.RATING AS RATING, AL.CURRENT_STATE, "
+ "AL.PREVIOUS_STATE, AL.UPDATED_BY, AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE "
+ "AS AL WHERE AR.AP_APP_ID=(SELECT ID FROM AP_APP WHERE NAME=? AND TYPE=? AND TENANT_ID=?) "
+ "AND AR.VERSION=? AND AR.RELEASE_TYPE=? AND AL.AP_APP_RELEASE_ID=AR.ID "
+ "AND AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
statement.setString(1, applicationName);
statement.setString(2, applicationType);
statement.setInt(3, tenantId);
statement.setString(4, versionName);
statement.setString(5, releaseType);
resultSet = statement.executeQuery();
if (resultSet.next()) {
return DAOUtil.loadApplicationRelease(resultSet);
}
return null;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to get the "
+ "release details of the application with " + applicationName + " and version " + versionName, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error while getting release details of the application " + applicationName + " and version " + versionName + " , while executing the query " + sql, e);
} finally {
DAOUtil.cleanupResources(statement, resultSet);
}
}
/**
* To get release details of a specific application.
*
* @param applicationId ID of the application.
* @param releaseUuid UUID of the application release.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
@Override public ApplicationReleaseDTO getReleaseByIds(int applicationId, String releaseUuid, int tenantId)
throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
String sql =
"SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE, AR.APP_PRICE, "
+ "AR.STORED_LOCATION, AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, ICON_LOCATION,"
+ "AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.PACKAGE_NAME AS "
+ "PACKAGE_NAME, AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, "
+ "AR.APP_META_INFO AS APP_META_INFO, AR.RATING AS RATING, AL.CURRENT_STATE, AL.PREVIOUS_STATE, "
+ "AL.UPDATED_BY, AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL "
+ "WHERE AR.AP_APP_ID = ? AND AR.UUID = ? AND AR.TENANT_ID = ? AND AL.AP_APP_RELEASE_ID=AR.ID "
+ "AND AL.TENANT_ID = AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
statement.setInt(1, applicationId);
statement.setString(2, releaseUuid);
statement.setInt(3, tenantId);
resultSet = statement.executeQuery();
if (resultSet.next()) {
return DAOUtil.loadApplicationRelease(resultSet);
}
return null;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database connection exception while trying to get the release details of the " + "application id: "
+ applicationId + "and UUID of the application release: " + releaseUuid, e);
String msg = "Database Connection error occurred while trying to release a new version for application which"
+ " has app ID: " + appId;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error while getting release details of the application id: " + applicationId
+ " and theUUID of the application " + "release: " + releaseUuid + " , while executing the query " + sql, e);
} finally {
DAOUtil.cleanupResources(statement, resultSet);
String msg = "SQL Exception while trying to release an application by executing the query " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public ApplicationReleaseDTO getReleaseByUUID( String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection connection;
String sql =
"SELECT AR.ID AS RELEASE_ID, "
String sql = "SELECT "
+ "AR.ID AS RELEASE_ID, "
+ "AR.DESCRIPTION AS RELEASE_DESCRIPTION, "
+ "AR.VERSION AS RELEASE_VERSION, "
+ "AR.UUID AS RELEASE_UUID, "
@ -248,7 +137,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
+ "WHERE AR.UUID = ? AND AR.TENANT_ID = ?";
try {
connection = this.getDBConnection();
Connection connection = this.getDBConnection();
try (PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, uuid);
statement.setInt(2, tenantId);
@ -260,146 +149,58 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
}
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database connection exception while trying to get the release details of the UUID of the application release: "
+ uuid, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error while getting release details of the UUID of the application " + "release: " + uuid
+ " , while executing the query " + sql, e);
}
}
/**
* To insert the application release properties.
*
* @param applicationId Id of the application.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
@Override public List<ApplicationReleaseDTO> getReleases(int applicationId, int tenantId)
throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
List<ApplicationReleaseDTO> applicationReleases = new ArrayList<>();
String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID, AR.RELEASE_TYPE "
+ "AS RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE, AR.STORED_LOCATION, AR.ICON_LOCATION, "
+ "AR.BANNER_LOCATION, AR.SC_1_LOCATION AS SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, "
+ "AR.SC_3_LOCATION AS SCREEN_SHOT_3, AR.APP_HASH_VALUE AS HASH_VALUE, "
+ "AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS APP_META_INFO, "
+ "AR.RATING AS RATING FROM AP_APP_RELEASE AS AR where AR.AP_APP_ID=? AND AR.TENANT_ID = ?;";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
statement.setInt(1, applicationId);
statement.setInt(2, tenantId);
resultSet = statement.executeQuery();
while (resultSet.next()) {
ApplicationReleaseDTO applicationRelease = DAOUtil.loadApplicationRelease(resultSet);
applicationReleases.add(applicationRelease);
}
return applicationReleases;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to get the "
+ "release details of the application with app ID: " + applicationId, e);
String msg = "Database connection error occurred while trying to get application release details which has "
+ "UUID: " + uuid;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error while getting all the release details of the app ID: " + applicationId
+ ", while executing the query " + sql, e);
} finally {
DAOUtil.cleanupResources(statement, resultSet);
String msg =
"Error while getting application release details which has UUID: " + uuid + " , while executing"
+ " the query " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
//todo this has to be removed
@Override
public List<ApplicationReleaseDTO> getReleaseByState(int appId, int tenantId, String state) throws
ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
List<ApplicationReleaseDTO> applicationReleases = new ArrayList<>();
String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS "
+ "RELEASE_TYPE, AR.PACKAGE_NAME AS PACKAGE_NAME, AR.APP_PRICE AS APP_PRICE, AR.STORED_LOCATION AS "
+ "STORED_LOCATION, AR.BANNER_LOCATION AS BANNER_LOCATION, ICON_LOCATION, AR.SC_1_LOCATION AS "
+ "SCREEN_SHOT_1, AR.SC_2_LOCATION AS SCREEN_SHOT_2, AR.SC_3_LOCATION AS SCREEN_SHOT_3, "
+ "AR.APP_HASH_VALUE AS HASH_VALUE, AR.SHARED_WITH_ALL_TENANTS AS SHARED, AR.APP_META_INFO AS "
+ "APP_META_INFO , AR.RATING AS RATING, AL.CURRENT_STATE, AL.PREVIOUS_STATE, AL.UPDATED_BY, "
+ "AL.UPDATED_AT FROM AP_APP_RELEASE AS AR, AP_APP_LIFECYCLE_STATE AS AL "
+ "WHERE AR.AP_APP_ID=? AND AL.AP_APP_RELEASE_ID=AR.ID AND AL.CURRENT_STATE=? AND AR.TENANT_ID=? AND "
+ "AL.TENANT_ID=AR.TENANT_ID ORDER BY AL.UPDATED_AT DESC;";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
statement.setInt(1, appId);
statement.setString(2, state);
statement.setInt(3, tenantId);
resultSet = statement.executeQuery();
while (resultSet.next()) {
ApplicationReleaseDTO appRelease = DAOUtil.loadApplicationRelease(resultSet);
applicationReleases.add(appRelease);
}
return applicationReleases;
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to get the "
+ "release details of the application with id " + appId, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error while getting all the release details of the app id" + appId + " application"
+ ", while executing the query " + sql, e);
} finally {
DAOUtil.cleanupResources(statement, resultSet);
}
}
/**
* To Update starts of an application release.
*
* @param uuid UUID of the application Release.
* @param rating given stars for the application release.
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
@Override public void updateRatingValue(String uuid, double rating, int ratedUsers)
throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "UPDATE AP_APP_RELEASE SET RATING = ?, RATED_USERS = ? WHERE UUID = ?;";
public void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException {
String sql = "UPDATE "
+ "AP_APP_RELEASE "
+ "SET "
+ "RATING = ?, "
+ "RATED_USERS = ? "
+ "WHERE UUID = ?";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
Connection connection = this.getDBConnection();
try (PreparedStatement statement = connection.prepareStatement(sql)){
statement.setDouble(1, rating);
statement.setInt(2, ratedUsers);
statement.setString(3, uuid);
statement.executeUpdate();
}
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException(
"Database connection exception while trying to update the application release rating value", e);
String msg = "Database connection error occurred while trying to update the application release rating "
+ "value for UUID: " + uuid;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"SQL exception while updating the release rating value ,while executing the query " + sql, e);
} finally {
DAOUtil.cleanupResources(statement, null);
String msg = "SQL exception occured while updating the release rating value. Executed query " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
/**
* To retrieve rating of an application release.
*
* @param uuid UUID of the application Release.
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
@Override
public Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
Rating rating = null;
String sql = "SELECT RATING, RATED_USERS FROM AP_APP_RELEASE WHERE UUID = ? AND TENANT_ID=?;";
String sql = "SELECT "
+ "RATING, "
+ "RATED_USERS "
+ "FROM AP_APP_RELEASE "
+ "WHERE UUID = ? AND TENANT_ID = ?";
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
@ -639,44 +440,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
}
@Override
public boolean verifyReleaseExistence(int appId, String uuid, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Verifying application release existence by application id:" + appId
+ " and application release uuid: " + uuid);
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
String sql =
"SELECT AR.ID AS RELEASE_ID FROM AP_APP_RELEASE AS AR WHERE AR.AP_APP_ID = ? AND AR.UUID = ? AND "
+ "AR.TENANT_ID = ?;";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, appId);
stmt.setString(2, uuid);
stmt.setInt(3, tenantId);
rs = stmt.executeQuery();
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application release with the application ID "
+ appId + " ApplicationDTO release uuid: " + uuid);
}
return rs.next();
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while getting application release details with app ID: " + appId
+ " App release uuid: " + uuid + " While executing query ", e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
DAOUtil.cleanupResources(stmt, rs);
}
}
@Override
public boolean verifyReleaseExistenceByUuid(String uuid, int tenantId) throws ApplicationManagementDAOException {
public boolean isReleaseExist(String uuid, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Verifying application release existence by application release uuid: " + uuid);
}

@ -23,7 +23,6 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO;
import org.wso2.carbon.device.application.mgt.common.exception.ReviewManagementException;
import org.wso2.carbon.device.application.mgt.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
@ -52,7 +51,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
private String sql;
@Override
public boolean addReview(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException {
public int addReview(ReviewDTO reviewDTO, int appReleaseId, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add review for application release. Application Release UUID: "
+ appReleaseId);
@ -69,11 +68,11 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
+ "AP_APP_RELEASE_ID) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )";
try {
int reviewId = -1;
Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
Connection conn = this.getDBConnection();
try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" });) {
try (PreparedStatement statement = conn.prepareStatement(sql, new String[] { "id" })) {
statement.setInt(1, tenantId);
statement.setString(2, reviewDTO.getContent());
statement.setInt(3, reviewDTO.getRootParentId());
@ -85,16 +84,22 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(9, appReleaseId);
statement.executeUpdate();
try (ResultSet rs = statement.getGeneratedKeys()) {
return rs.next();
if (rs.next()) {
reviewId = rs.getInt(1);
}
}
return reviewId;
}
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occurred while obtaining the DB connection while "
+ "adding review for application release which has ID: "+ appReleaseId + "Tenant Id: " + tenantId, e);
String msg = "Error occurred while obtaining the DB connection to add a review for application release which"
+ " has ID: "+ appReleaseId + " and Tenant Id: " + tenantId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ReviewManagementDAOException(
"Error occurred while executing SQL statement to add application review. Application ID: "
+ appReleaseId + " tenant " + tenantId, e);
String msg = "Error occurred while executing SQL statement to add application review. Application ID: "
+ appReleaseId + " and tenant " + tenantId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
@ -102,19 +107,18 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
public boolean hasUerReviewedApp(List<Integer> appReleaseIds, String username, int tenantId)
throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to check whether user have already reviewed or not for the "
log.debug("Request received to DAO Layer to check whether user have already reviewed or not for the "
+ "application. Commenting user: " + username + " and tenant-id: " + tenantId);
}
Connection conn;
int index = 1;
try {
conn = this.getDBConnection();
Connection conn = this.getDBConnection();
StringJoiner joiner = new StringJoiner(",",
"SELECT rv.ID FROM AP_APP_REVIEW rv WHERE rv.AP_APP_RELEASE_ID IN (",
") AND rv.USERNAME = ? AND rv.TENANT_ID = ?");
appReleaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {
int index = 1;
for (Integer deviceId : appReleaseIds) {
ps.setObject(index++, deviceId);
}
@ -124,25 +128,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
return rs.next();
}
}
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database when checking whether "
+ "user has already commented for the application ro not", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection when checking "
+ "whether user has already commented for the application ro not", e);
String msg = "Error occured while getting the database connection when checking whether user has already "
+ "commented for the application or not";
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occured while executing the SQL statement to check whether user has already commented "
+ "for the application or not";
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
@Override
public int updateReview(ReviewDTO reviewDTO, int reviewId, boolean isActiveReview, int tenantId)
throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to update the Review with ID (" + reviewId + ")");
log.debug("Request received to DAO Layer to update the Review which has ID " + reviewId);
}
Connection connection;
PreparedStatement statement = null;
ResultSet rs = null;
sql = "UPDATE "
+ "AP_APP_REVIEW "
+ "SET "
@ -150,14 +154,13 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
+ "RATING = ?, "
+ "MODIFIED_AT = ?, "
+ "ACTIVE_REVIEW = ? "
+ "WHERE ID = ? AND "
+ "TENANT_ID = ?";
+ "WHERE ID = ? AND TENANT_ID = ?";
try {
Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
connection = this.getDBConnection();
statement = connection.prepareStatement(sql);
Connection connection = this.getDBConnection();
try (PreparedStatement statement = connection.prepareStatement(sql)){
statement.setString(1, reviewDTO.getContent());
statement.setInt(2, reviewDTO.getRating());
statement.setTimestamp(3, timestamp);
@ -165,26 +168,23 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(5, reviewId);
statement.setInt(6, tenantId);
return statement.executeUpdate();
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occurred while executing reviewTmp updating query");
}
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the db connection to update reviewTmp");
} finally {
DAOUtil.cleanupResources(statement, rs);
String msg = "Error occured while getting the db connection to update review for review ID: " + reviewId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing review updating query for review ID: " + reviewId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
@Override
public ReviewDTO getReview(int reviewId) throws ReviewManagementDAOException {
public ReviewDTO getReview(int reviewId, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting reviewDTO with the review id(" + reviewId + ") from the database");
log.debug("Request received to DAO Layer to get review for review ID: " + reviewId);
}
Connection conn;
PreparedStatement statement = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
sql = "SELECT "
+ "AP_APP_REVIEW.ID AS ID, "
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
@ -198,61 +198,29 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
+ "AP_APP_RELEASE.VERSION AS VERSION "
+ "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID "
+ "WHERE AP_APP_REVIEW.ID = ?";
statement = conn.prepareStatement(sql);
+ "WHERE AP_APP_REVIEW.ID = ? AND AP_APP_REVIEW.TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, reviewId);
rs = statement.executeQuery();
statement.setInt(2, tenantId);
try (ResultSet rs = statement.executeQuery()) {
return DAOUtil.loadReview(rs);
} catch (SQLException e) {
throw new ReviewManagementDAOException(
"SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e);
} catch (UnexpectedServerErrorException e) {
throw new ReviewManagementDAOException("Found more than one review for review ID: " + reviewId, e);
} finally {
DAOUtil.cleanupResources(statement, rs);
}
}
@Override
public ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting reviewDTO with the review id(" + reviewId + ") from the database");
}
Connection conn;
PreparedStatement statement = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
sql = "SELECT "
+ "ID, "
+ "COMMENT,"
+ "ROOT_PARENT_ID,"
+ "IMMEDIATE_PARENT_ID, "
+ "CREATED_AT, "
+ "MODIFIED_AT, "
+ "RATING, "
+ "USERNAME "
+ "FROM AP_APP_REVIEW "
+ "WHERE ID = ? AND "
+ "AP_APP_RELEASE_ID = ?";
statement = conn.prepareStatement(sql);
statement.setInt(1, reviewId);
statement.setInt(2, appReleaseId);
rs = statement.executeQuery();
return DAOUtil.loadReview(rs);
} catch (SQLException e) {
throw new ReviewManagementDAOException(
"SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e);
String msg = "DB Connection Exception occurred while retrieving information of the review for review ID: "
+ reviewId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occured while executing SQL statement to get review data for review ID: " + reviewId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (UnexpectedServerErrorException e) {
throw new ReviewManagementDAOException("Found more than one review for review ID: " + reviewId, e);
} finally {
DAOUtil.cleanupResources(statement, rs);
String msg = "Found more than one review for review ID: " + reviewId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
@ -260,14 +228,9 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
@Override
public List<ReviewDTO> getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId)
throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting comment of the application release (" + releaseId + ") from the database");
log.debug("Getting all application release reviews for the application release ID: " + releaseId);
}
Connection conn;
List<ReviewDTO> reviewDTOs;
try {
conn = this.getDBConnection();
sql = "SELECT "
+ "AP_APP_REVIEW.ID AS ID, "
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
@ -285,6 +248,8 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
+ "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "LIMIT ? OFFSET ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, releaseId);
statement.setInt(2, Constants.REVIEW_PARENT_ID);
@ -292,33 +257,32 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(4, request.getLimit());
statement.setInt(5, request.getOffSet());
try (ResultSet rs = statement.executeQuery()) {
reviewDTOs = DAOUtil.loadReviews(rs);
return DAOUtil.loadReviews(rs);
}
}
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"Error occurred while obtaining the DB connection when verifying application existence", e);
String msg = "Error occurred while obtaining the DB connection to get all app release reviews for "
+ "application release ID: " + releaseId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ReviewManagementDAOException("DB connection error occurred while getting all reviewTmps", e);
} return reviewDTOs;
String msg = "Error occurred while executing the SQL statement to get all app release reviews for "
+ "application release ID: " + releaseId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
@Override
public List<ReviewDTO> getAllActiveAppReviews(List<Integer> releaseIds, PaginationRequest request, int tenantId)
throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting reviews of the application from the database.");
log.debug("DAO request is received to Get all active application reviews.");
}
Connection conn;
List<ReviewDTO> reviewDTOs;
int index = 1;
try {
conn = this.getDBConnection();
Connection conn = this.getDBConnection();
StringJoiner joiner = new StringJoiner(",",
"SELECT "
+ "AP_APP_REVIEW.ID AS ID, "
"SELECT " + "AP_APP_REVIEW.ID AS ID, "
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
@ -338,6 +302,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {
int index = 1;
for (Integer releaseId : releaseIds) {
ps.setObject(index++, releaseId);
}
@ -346,32 +311,29 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
ps.setInt(index++, request.getLimit());
ps.setInt(index, request.getOffSet());
try (ResultSet rs = ps.executeQuery()) {
reviewDTOs = DAOUtil.loadReviews(rs);
}
return DAOUtil.loadReviews(rs);
}
}
catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"Error occurred while obtaining the DB connection when verifying application existence.", e);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get all active app reviews.";
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ReviewManagementDAOException("DB connection error occurred while getting all reviews.", e);
} return reviewDTOs;
String msg = "Error occurred while executing SQL to get all active app reviews.";
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
@Override
public List<ReviewDTO> getAllActiveAppReviewsOfUser(List<Integer> releaseIds, PaginationRequest request,
String username, int tenantId)
throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting reviews of the application for given user from the database.");
log.debug("DAO request is received to Get all active application reviews of user " + username);
}
Connection conn;
List<ReviewDTO> reviewDTOs;
int index = 1;
try {
conn = this.getDBConnection();
Connection conn = this.getDBConnection();
StringJoiner joiner = new StringJoiner(",",
"SELECT "
+ "AP_APP_REVIEW.ID AS ID, "
@ -395,6 +357,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {
int index = 1;
for (Integer releaseId : releaseIds) {
ps.setObject(index++, releaseId);
}
@ -404,29 +367,28 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
ps.setInt(index++, request.getLimit());
ps.setInt(index, request.getOffSet());
try (ResultSet rs = ps.executeQuery()) {
reviewDTOs = DAOUtil.loadReviews(rs);
}
return DAOUtil.loadReviews(rs);
}
}
catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"Error occurred while obtaining the DB connection when application review of user: " + username , e);
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get all active app reviews of user "
+ username;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ReviewManagementDAOException("DB connection error occurred while getting application reviews of "
+ "user:" + username, e);
} return reviewDTOs;
String msg = "Error occurred while executing SQL to get all active app reviews of user " + username;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
@Override
public List<ReviewDTO> getReplyComments(int parentId, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting comment of the application release (" + parentId + ") from the database");
log.debug("Getting all reply comments for review which has review ID: " + parentId);
}
Connection conn;
List<ReviewDTO> reviewDTOs;
try {
conn = this.getDBConnection();
Connection conn = this.getDBConnection();
sql = "SELECT "
+ "AP_APP_REVIEW.ID AS ID, "
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
@ -446,66 +408,70 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, parentId);
statement.setInt(2, tenantId);
try (ResultSet rs = statement.executeQuery();) {
reviewDTOs = DAOUtil.loadReviews(rs);
try (ResultSet rs = statement.executeQuery()) {
return DAOUtil.loadReviews(rs);
}
}
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"Error occurred while obtaining the DB connection when getting reply comments for a review.", e);
String msg = "Error occurred while obtaining the DB connection when getting reply comments for a review "
+ "which has reviw ID: " + parentId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ReviewManagementDAOException("DB connection error occurred while getting reply comments", e);
String msg = "Error occurred while executing SQL to ge reply comments for a review which has reviw ID: "
+ parentId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
return reviewDTOs;
}
@Override
public List<Integer> getAllAppReleaseRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting comment of the application release (" + uuid + ") from the database");
log.debug("Getting all app release rating values for app release UUID: " + uuid);
}
Connection conn;
PreparedStatement statement = null;
ResultSet rs = null;
List<Integer> reviews = new ArrayList<>();
sql = "SELECT "
+ "AP_APP_REVIEW.RATING AS RATING "
+ "FROM AP_APP_REVIEW, AP_APP_RELEASE "
+ "WHERE "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID AND "
+ "AP_APP_RELEASE.UUID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND "
+ "AP_APP_REVIEW.TENANT_ID = ?";
try {
conn = this.getDBConnection();
sql = "SELECT AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND "
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND AP_APP_REVIEW.TENANT_ID = ?";
statement = conn.prepareStatement(sql);
Connection conn = this.getDBConnection();
try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setString(1, uuid);
statement.setInt(2, tenantId);
rs = statement.executeQuery();
try (ResultSet rs = statement.executeQuery()) {
List<Integer> reviews = new ArrayList<>();
while (rs.next()) {
reviews.add(rs.getInt("RATING"));
}
} catch (SQLException e) {
throw new ReviewManagementDAOException(
"Error occured while getting all rating values for the application release. App release UUID: "
+ uuid, e);
return reviews;
}
}
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"Error occured while getting DB connection to retrieve all rating values for the application release. App release UUID: "
+ uuid, e);
} finally {
DAOUtil.cleanupResources(statement, rs);
String msg = "Error occured while getting DB connection to retrieve all rating values for the application "
+ "release which has UUID:" + uuid;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occured while executing SQL to retrieve all rating values for the application release "
+ "which has UUID:" + uuid;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
return reviews;
}
@Override
public List<Integer> getAllAppRatingValues(List<String> uuids, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting rating values of the application from the database");
log.debug("DAO request is received to Get all application rating values of an application.");
}
Connection conn;
List<Integer> reviews = new ArrayList<>();
try {
int index = 1;
conn = this.getDBConnection();
Connection conn = this.getDBConnection();
StringJoiner joiner = new StringJoiner(",",
"SELECT AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID WHERE AP_APP_RELEASE.UUID IN (",
@ -518,88 +484,31 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
}
ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) {
List<Integer> reviews = new ArrayList<>();
while (rs.next()) {
reviews.add(rs.getInt("RATING"));
} }
}
} catch (SQLException e) {
throw new ReviewManagementDAOException(
"Error occured while getting all rating values for the application.", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException(
"Error occured while getting DB connection to retrieve all rating values for the application.", e);
}
return reviews;
}
@Override
public int getReviewCount(String uuid) throws ReviewManagementDAOException {
int commentCount = 0;
Connection conn;
PreparedStatement statement = null;
ResultSet rs = null;
boolean isUuidProvided = false;
try {
conn = this.getDBConnection();
if (uuid != null) {
isUuidProvided = true;
}
if (isUuidProvided) {
sql = "SELECT COUNT(AP_APP_REVIEW.ID) AS REVIEW_COUNT FROM AP_APP_REVIEW,AP_APP_RELEASE "
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID= AP_APP_RELEASE.ID AND "
+ "AP_APP_REVIEW.AP_APP_ID= AP_APP_RELEASE.AP_APP_ID AND AP_APP_RELEASE.UUID=?;";
statement = conn.prepareStatement(sql);
statement.setString(1, uuid);
rs = statement.executeQuery();
if (rs.next()) {
commentCount = rs.getInt("REVIEW_COUNT");
}
}
} catch (SQLException e) {
throw new ReviewManagementDAOException("SQL Error occurred while retrieving review counts", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("DB Connection Exception occurred while retrieving review counts", e);
} finally {
DAOUtil.cleanupResources(statement, rs);
}
return commentCount;
}
@Override
public int getReviewCountByApp(String appType, String appName, String version)
throws ReviewManagementException, DBConnectionException, SQLException {
Connection conn;
PreparedStatement statement = null;
ResultSet rs = null;
int commentCount = 0;
try {
//todo need to reconstruct the query
conn = this.getDBConnection();
sql = "SELECT COUNT(ID) AS COMMENT_COUNT FROM AP_APP_COMMENT C, "
+ "(SELECT ID AS RELEASE_ID, AP_APP_ID AS RELEASE_AP_APP_ID FROM AP_APP_RELEASE R WHERE VERSION=? )R,"
+ "(SELECT ID AS APP_ID FROM AP_APP P WHERE NAME=? and TYPE=?)P "
+ "WHERE AP_APP_RELEASE_ID=RELEASE_ID AND RELEASE_AP_APP_ID=APP_ID AND AP_APP_ID=RELEASE_AP_APP_ID;";
statement = conn.prepareStatement(sql);
statement.setString(1, version);
statement.setString(2, appName);
statement.setString(3, appType);
rs = statement.executeQuery();
if (rs.next()) {
commentCount = rs.getInt("COMMENT_COUNT");
}
} finally {
DAOUtil.cleanupResources(statement, rs);
String msg = "Error occured while getting DB connection to retrieve all rating values for an application.";
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occured while executing SQL to get all rating values for the application.";
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
return commentCount;
}
@Override
public void deleteReview(int reviewId, int tenantId) throws ReviewManagementDAOException {
Connection conn;
if (log.isDebugEnabled()) {
log.debug("DAO request is received to delete review which has review ID: " + reviewId);
}
try {
conn = this.getDBConnection();
Connection conn = this.getDBConnection();
sql = "DELETE "
+ "FROM AP_APP_REVIEW "
+ "WHERE "
@ -610,19 +519,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(2, tenantId);
statement.executeUpdate();
}
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
String msg = "Error occured while getting the database connection to delete review which has review ID: "
+ reviewId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occured while executing SQL to delete review which has review ID: " + reviewId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
@Override
public void deleteReviews(List<Integer> reviewIds, int tenantId) throws ReviewManagementDAOException{
Connection conn;
if (log.isDebugEnabled()) {
log.debug("DAO request is received to delete reviews for requesting review Ids.");
}
try {
conn = this.getDBConnection();
Connection conn = this.getDBConnection();
sql = "DELETE "
+ "FROM AP_APP_REVIEW "
+ "WHERE "
@ -636,19 +551,24 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
}
stmt.executeBatch();
}
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
String msg = "Error occurred while getting the database connection to delete reviews for given review Ids.";
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to delete reviews for given review Ids.";
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
@Override
public void deleteAllChildCommentsOfReview(int rootParentId, int tenantId) throws ReviewManagementDAOException {
Connection conn;
if (log.isDebugEnabled()) {
log.debug("DAO request is received to delete child comments of a review.");
}
try {
conn = this.getDBConnection();
Connection conn = this.getDBConnection();
sql = "DELETE "
+ "FROM AP_APP_REVIEW "
+ "WHERE "
@ -659,39 +579,16 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(2, tenantId);
statement.executeUpdate();
}
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
} catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection", e);
}
}
@Override
public void deleteReviews(String appType, String appName, String version) throws ReviewManagementException {
Connection conn;
PreparedStatement statement = null;
try {
conn = this.getDBConnection();
//todo need to reconstruct the query,
sql = "DELETE FROM AP_APP_COMMENT WHERE "
+ "(SELECT AP_APP_RELEASE_ID FROM AP_APP_RELEASE WHERE VERSION=? AND "
+ "(SELECT AP_APP_ID FROM AP_APP WHERE NAME=? AND TYPE=?)) AND "
+ "(SELECT AP_APP_ID FROM AP_APP AND NAME=? AND TYPE=?);";
statement = conn.prepareStatement(sql);
statement.setString(1, version);
statement.setString(2, appName);
statement.setString(3, appType);
statement.setString(4, appName);
statement.setString(5, appType);
statement.executeUpdate();
} catch (DBConnectionException e) {
log.error("DB Connection Exception occurred while deleting comments", e);
String msg = "Error occured while getting the database connection to delete all child comments of a review "
+ "which has ID: " + rootParentId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) {
throw new ReviewManagementException("SQL Error occurred while deleting comments", e);
} finally {
DAOUtil.cleanupResources(statement, null);
String msg = "Error occured while executing SQL to delete all child comments of a review which has ID: "
+ rootParentId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
}
}

@ -48,7 +48,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
String subscribedFrom, String installStatus, int releaseId, int tenantId)
throws ApplicationManagementDAOException {
Connection conn;
try {
String sql = "INSERT INTO "
+ "AP_DEVICE_SUBSCRIPTION("
+ "SUBSCRIBED_BY, "
@ -59,6 +58,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
+ "AP_APP_RELEASE_ID,"
+ "TENANT_ID) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?)";
try {
conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
Calendar calendar = Calendar.getInstance();
@ -73,18 +73,30 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
stmt.setInt(7, tenantId);
stmt.addBatch();
if (log.isDebugEnabled()) {
log.debug("Adding a mapping to device[" + deviceId + "] to the application release[" + releaseId
+ "]");
log.debug("Adding a device subscription for device id " + deviceId + " and application "
+ "release which has release id" + releaseId);
}
}
stmt.executeBatch();
try (ResultSet rs = stmt.getGeneratedKeys()) {
List<Integer> deviceSubIds = new ArrayList<>();
while (rs.next()) {
deviceSubIds.add(rs.getInt(1));
}
} catch (SQLException | DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB",
e);
return deviceSubIds;
}
}
} catch (DBConnectionException e) {
String msg = "Error occured while obtaining database connection to add device subscription for application "
+ "release which has release Id" + releaseId;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occured when processing SQL to add device subscription for application release which"
+ " has release Id " + releaseId;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
return deviceIds;
}
@Override
@ -95,12 +107,12 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
Connection conn;
try {
conn = this.getDBConnection();
String sql = "UPDATE AP_USER_SUBSCRIPTION " + "SET ";
String sql = "UPDATE AP_DEVICE_SUBSCRIPTION SET ";
if (isUnsubscribed) {
sql += "UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ? ";
sql += "UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ?, ";
} else {
sql += "SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ? ";
sql += "SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ?, ";
}
sql += "ACTION_TRIGGERED_FROM = ?, " +
"STATUS = ? " +
@ -120,8 +132,16 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
stmt.setInt(5, deviceId);
stmt.setInt(6, releaseId);
stmt.setInt(7, tenantId);
stmt.addBatch();
}
stmt.executeBatch();
try (ResultSet rs = stmt.getGeneratedKeys()){
List<Integer> updatedDeviceSubIds = new ArrayList<>();
while (rs.next()) {
updatedDeviceSubIds.add(rs.getInt(1));
}
return updatedDeviceSubIds;
}
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to update the device subscriptions of application.";
@ -132,7 +152,6 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
return deviceIds;
}
@Override public void addOperationMapping(int operationId, List<Integer> deviceSubscriptionIds, int tenantId)
@ -505,7 +524,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) {
subscribedDevices.add(rs.getInt("DM_DEVICE_I"));
subscribedDevices.add(rs.getInt("DM_DEVICE_ID"));
}
}
}
@ -527,27 +546,25 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
conn = this.getDBConnection();
String sql = "UPDATE ";
if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) {
sql += "AP_USER_SUBSCRIPTION ";
sql += "AP_USER_SUBSCRIPTION SET ";
} else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) {
sql += "AP_ROLE_SUBSCRIPTION ";
sql += "AP_ROLE_SUBSCRIPTION SET ";
} else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) {
sql += "AP_GROUP_SUBSCRIPTION ";
sql += "AP_GROUP_SUBSCRIPTION SET ";
}
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
sql += "SET UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ? ";
sql += "UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ? ";
} else {
sql += "SET SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ? ";
sql += "SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ? ";
}
sql += "WHERE ";
if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) {
sql += "USER_NAME = ? ";
sql += "WHERE USER_NAME = ? ";
} else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) {
sql += "ROLE_NAME = ? ";
sql += "WHERE ROLE_NAME = ? ";
} else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) {
sql += "GROUP_NAME = ? ";
sql += "WHERE GROUP_NAME = ? ";
}
sql += "AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
@ -577,20 +594,61 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
}
@Override
public boolean updateDeviceSubStatus (int operationId, String status, int tenantId) throws ApplicationManagementDAOException {
public List<Integer> getDeviceSubIdsForOperation(int operationId, int tenantId)
throws ApplicationManagementDAOException {
Connection conn;
try {
conn = this.getDBConnection();
String sql = "UPDATE AP_DEVICE_SUBSCRIPTION "
+ "SET STATUS = ? "
List<Integer> deviceSubIds = new ArrayList<>();
String sql = "SELECT "
+ "ID "
+ "FROM AP_APP_SUB_OP_MAPPING "
+ "WHERE "
+ "AP_APP_RELEASE_ID = (SELECT AP_DEVICE_SUBSCRIPTION_ID FROM AP_APP_SUB_OP_MAPPING WHERE OPERATION_ID = ?) "
+ "AND TENANT_ID = ?";
+ "OPERATION_ID = ? AND "
+ "TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, status);
stmt.setInt(2, operationId);
stmt.setInt(3, tenantId);
return stmt.executeUpdate() != 0;
stmt.setInt(1, operationId);
stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
deviceSubIds.add(rs.getInt("ID"));
}
}
return deviceSubIds;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to get app device subscription ids for given "
+ "operation.";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred when processing SQL to get app device subscription ids for given operation.";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
}
}
@Override
public boolean updateDeviceSubStatus(int deviceId, List<Integer> deviceSubIds, String status, int tenantId)
throws ApplicationManagementDAOException {
Connection conn;
try {
conn = this.getDBConnection();
int index = 1;
StringJoiner joiner = new StringJoiner(",",
"UPDATE AP_DEVICE_SUBSCRIPTION SET STATUS = ? "
+ "WHERE ID IN (",
") AND DM_DEVICE_ID = ? AND TENANT_ID = ?");
deviceSubIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) {
ps.setString(index++, status);
for (Integer deviceSubId : deviceSubIds) {
ps.setObject(index++, deviceSubId);
}
ps.setInt(index++, deviceId);
ps.setInt(index, tenantId);
return ps.executeUpdate() != 0;
}
} catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to update the subscription status of the "

@ -77,7 +77,6 @@ import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException
import org.wso2.carbon.device.application.mgt.core.exception.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.exception.NotFoundException;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
import org.wso2.carbon.device.application.mgt.core.exception.VisibilityManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
@ -143,7 +142,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
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 "
@ -571,7 +569,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
Pagination pagination = new Pagination();
pagination.setCount(applications.size());
pagination.setCount(applicationDAO.getApplicationCount(filter, deviceType.getId(), tenantId));
pagination.setSize(applications.size());
pagination.setOffset(filter.getOffset());
pagination.setLimit(filter.getLimit());
@ -820,7 +818,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationById(applicationId, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(applicationId, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't find application for the application Id: " + applicationId;
log.error(msg);
@ -953,7 +951,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
ApplicationDTO applicationDTO = applicationDAO.getApplication(releaseUuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't found an application for application release UUID: " + releaseUuid;
@ -1009,7 +1007,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
ApplicationDTO applicationDTO = applicationDAO.getApplication(releaseUuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't found an application for application release UUID: " + releaseUuid;
@ -1172,7 +1170,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
this.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds);
this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds);
this.applicationDAO.deleteApplicationTags(applicationId, tenantId);
this.applicationDAO.deleteCategoryMapping(applicationId, tenantId);
this.applicationDAO.deleteAppCategories(applicationId, tenantId);
this.applicationDAO.deleteApplication(applicationId, tenantId);
ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
@ -1401,7 +1399,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't found an application which has application release for UUID: " + releaseUuid;
log.error(msg);
@ -1616,15 +1614,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
try {
ConnectionManagerUtil.beginDBTransaction();
if (!StringUtils.isEmpty(applicationUpdateWrapper.getName())){
Filter filter = new Filter();
filter.setFullMatch(true);
filter.setAppName(applicationUpdateWrapper.getName().trim());
filter.setOffset(0);
filter.setLimit(1);
List<ApplicationDTO> applicationList = applicationDAO
.getApplications(filter, applicationDTO.getDeviceTypeId(), tenantId);
if (!applicationList.isEmpty()) {
if (applicationDAO
.isExistingAppName(applicationUpdateWrapper.getName().trim(), applicationDTO.getDeviceTypeId(),
tenantId)) {
String msg = "Already an application registered with same name " + applicationUpdateWrapper.getName()
+ ". Hence you can't update the application name from " + applicationDTO.getName() + " to "
+ applicationUpdateWrapper.getName();
@ -1633,29 +1625,29 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
applicationDTO.setName(applicationUpdateWrapper.getName());
}
if (!StringUtils.isEmpty(applicationUpdateWrapper.getSubType()) && !applicationDTO.getSubType()
.equals(applicationUpdateWrapper.getSubType())) {
if (!ApplicationSubscriptionType.PAID.toString().equals(applicationUpdateWrapper.getSubType())
&& !ApplicationSubscriptionType.FREE.toString().equals(applicationUpdateWrapper.getSubType())) {
if (!StringUtils.isEmpty(applicationUpdateWrapper.getSubMethod()) && !applicationDTO.getSubType()
.equals(applicationUpdateWrapper.getSubMethod())) {
if (!ApplicationSubscriptionType.PAID.toString().equals(applicationUpdateWrapper.getSubMethod())
&& !ApplicationSubscriptionType.FREE.toString().equals(applicationUpdateWrapper.getSubMethod())) {
String msg = "Invalid application subscription type is found with application updating request "
+ applicationUpdateWrapper.getSubType();
+ applicationUpdateWrapper.getSubMethod();
log.error(msg);
throw new BadRequestException(msg);
} else if (ApplicationSubscriptionType.FREE.toString().equals(applicationUpdateWrapper.getSubType())
} else if (ApplicationSubscriptionType.FREE.toString().equals(applicationUpdateWrapper.getSubMethod())
&& !StringUtils.isEmpty(applicationUpdateWrapper.getPaymentCurrency())) {
String msg = "If you are going to change Non-Free app as Free app, "
String msg = "If you are going to change paid app as Free app, "
+ "currency attribute in the application updating payload should be null or \"\"";
log.error(msg);
throw new ApplicationManagementException(msg);
} else if (ApplicationSubscriptionType.PAID.toString().equals(applicationUpdateWrapper.getSubType())
} else if (ApplicationSubscriptionType.PAID.toString().equals(applicationUpdateWrapper.getSubMethod())
&& StringUtils.isEmpty(applicationUpdateWrapper.getPaymentCurrency()) ){
String msg = "If you are going to change Free app as Non-Free app, "
+ "currency attribute in the application payload should not be null or \"\"";
String msg = "If you are going to change Free app as paid app, currency attribute in the application"
+ " payload should not be null or \"\"";
log.error(msg);
throw new ApplicationManagementException(msg);
}
applicationDTO.setSubType(applicationUpdateWrapper.getSubType());
applicationDTO.setSubType(applicationUpdateWrapper.getSubMethod());
applicationDTO.setPaymentCurrency(applicationUpdateWrapper.getPaymentCurrency());
}
@ -1703,33 +1695,37 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
}
applicationDTO.setUnrestrictedRoles(applicationUpdateWrapper.getUnrestrictedRoles());
List<String> updatingAppCategries = applicationUpdateWrapper.getCategories();
String updatingAppCategory = applicationUpdateWrapper.getAppCategory();
if ( updatingAppCategory != null){
List<String> appCategories = this.applicationDAO.getAppCategories(applicationId, tenantId);
if (!appCategories.contains(updatingAppCategory)){
if (updatingAppCategries != null){
List<CategoryDTO> allCategories = this.applicationDAO.getAllCategories(tenantId);
List<Integer> categoryIds = allCategories.stream()
.filter(category -> category.getCategoryName().equals(updatingAppCategory))
.map(CategoryDTO::getId).collect(Collectors.toList());
if (categoryIds.isEmpty()){
ConnectionManagerUtil.rollbackDBTransaction();
String msg =
"You are trying to update application category into invalid application category, "
+ "it is not registered in the system. Therefore please register the category "
+ updatingAppCategory + " and perform the action";
List<String> allCategoryName = allCategories.stream().map(CategoryDTO::getCategoryName)
.collect(Collectors.toList());
if (!getDifference(updatingAppCategries, allCategoryName).isEmpty()){
String msg = "Application update request contains invalid category names. Hence please verify the request payload";
log.error(msg);
throw new BadRequestException(msg);
}
List<String> appCategories = this.applicationDAO.getAppCategories(applicationId, tenantId);
List<String> addingAppCategories = getDifference(updatingAppCategries, appCategories);
List<String> removingAppCategories = getDifference(appCategories, updatingAppCategries);
if (!addingAppCategories.isEmpty()) {
List<Integer> categoryIds = this.applicationDAO.getCategoryIdsForCategoryNames(addingAppCategories, tenantId);
this.applicationDAO.addCategoryMapping(categoryIds, applicationId, tenantId);
}
if (!removingAppCategories.isEmpty()) {
List<Integer> categoryIds = this.applicationDAO.getCategoryIdsForCategoryNames(removingAppCategories, tenantId);
this.applicationDAO.deleteAppCategories(categoryIds, applicationId, tenantId);
}
}
List<String> updatingAppTags = applicationUpdateWrapper.getTags();
if (updatingAppTags!= null){
List<String> appTags = this.applicationDAO.getAppTags(applicationId, tenantId);
List<String> addingTagList = getDifference(appTags, updatingAppTags);
List<String> removingTagList = getDifference(updatingAppTags, appTags);
List<String> addingTagList = getDifference(updatingAppTags, appTags);
List<String> removingTagList = getDifference(appTags, updatingAppTags);
if (!addingTagList.isEmpty()) {
List<TagDTO> allTags = this.applicationDAO.getAllTags(tenantId);
List<String> newTags = addingTagList.stream().filter(updatingTagName -> allTags.stream()
@ -1743,7 +1739,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (!removingTagList.isEmpty()) {
List<Integer> removingTagIds = this.applicationDAO.getTagIdsForTagNames(removingTagList, tenantId);
this.applicationDAO.deleteApplicationTags(removingTagIds, applicationId, tenantId);
applicationDAO.deleteTags(removingTagList, applicationId, tenantId);
}
}
if (!applicationDAO.updateApplication(applicationDTO, tenantId)){
@ -1857,7 +1852,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new NotFoundException(msg);
}
if (applicationDAO.hasTagMapping(tag.getId(), applicationDTO.getId(), tenantId)){
applicationDAO.deleteApplicationTags(tag.getId(), applicationDTO.getId(), tenantId);
applicationDAO.deleteApplicationTag(tag.getId(), applicationDTO.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction();
} else {
String msg = "Tag " + tagName + " is not an application tag. Application ID: " + appId;
@ -2289,13 +2284,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public boolean updateEntAppRelease(String deviceType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
public boolean updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
applicationDTO.getApplicationReleaseDTOs().get(0));
@ -2355,14 +2350,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public boolean updatePubAppRelease(String deviceType, String releaseUuid,
PublicAppReleaseWrapper publicAppReleaseWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException {
public boolean updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
validateAppReleaseUpdating(applicationDTO, ApplicationType.PUBLIC.toString());
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
applicationDTO.getApplicationReleaseDTOs().get(0));
@ -2423,14 +2417,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public boolean updateWebAppRelease(String deviceType, String releaseUuid,
WebAppReleaseWrapper webAppReleaseWrapper, ApplicationArtifact applicationArtifact)
throws ApplicationManagementException {
public boolean updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
validateAppReleaseUpdating(applicationDTO, ApplicationType.WEB_CLIP.toString());
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
applicationDTO.getApplicationReleaseDTOs().get(0));
@ -2816,11 +2809,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
}
@Override
public void updateSubsStatus (int operationId, String status) throws ApplicationManagementException {
public void updateSubsStatus (int deviceId, int operationId, String status) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
ConnectionManagerUtil.beginDBTransaction();
if (!subscriptionDAO.updateDeviceSubStatus(operationId, status, tenantId)){
List<Integer> deviceSubIds = subscriptionDAO.getDeviceSubIdsForOperation(operationId, tenantId);
if (deviceSubIds.isEmpty()){
String msg = "Couldn't find device subscription for operation id " + operationId;
log.error(msg);
throw new ApplicationManagementException(msg);
}
if (!subscriptionDAO.updateDeviceSubStatus(deviceId, deviceSubIds, status, tenantId)){
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Didn't update an any app subscription of device for operation Id: " + operationId;
log.error(msg);
@ -2850,7 +2849,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't find application for the release UUID: " + releaseUuid;
log.error(msg);

@ -74,7 +74,7 @@ public class ReviewManagerImpl implements ReviewManager {
}
@Override
public boolean addReview(ReviewWrapper reviewWrapper, String uuid,boolean allowMultipleReviews)
public Review addReview(ReviewWrapper reviewWrapper, String uuid, boolean allowMultipleReviews)
throws ReviewManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
@ -92,7 +92,7 @@ public class ReviewManagerImpl implements ReviewManager {
}
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(uuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't find an application which has the application release of UUID: " + uuid;
log.error(msg);
@ -100,9 +100,13 @@ public class ReviewManagerImpl implements ReviewManager {
}
List<Integer> applicationReleaseIds = new ArrayList<>();
int associatedAppReleaseId = -1;
String associatedVersion = null;
String associatedReleaseUuid = null;
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
if (applicationReleaseDTO.getUuid().equals(uuid)) {
associatedAppReleaseId = applicationReleaseDTO.getId();
associatedVersion = applicationReleaseDTO.getVersion();
associatedReleaseUuid = applicationReleaseDTO.getUuid();
}
Integer id = applicationReleaseDTO.getId();
applicationReleaseIds.add(id);
@ -121,14 +125,19 @@ public class ReviewManagerImpl implements ReviewManager {
reviewDTO.setUsername(username);
reviewDTO.setRootParentId(-1);
reviewDTO.setImmediateParentId(-1);
if (this.reviewDAO.addReview(reviewDTO, associatedAppReleaseId, tenantId)) {
reviewDTO.setReleaseVersion(associatedVersion);
reviewDTO.setReleaseUuid(associatedReleaseUuid);
int reviewId = this.reviewDAO.addReview(reviewDTO, associatedAppReleaseId, tenantId);
reviewDTO.setId(reviewId);
if (reviewId != -1) {
ConnectionManagerUtil.commitDBTransaction();
Runnable task = () -> calculateRating(reviewWrapper.getRating(), -12345, uuid, tenantId);
new Thread(task).start();
return true;
return reviewDTOToReview(reviewDTO);
}
ConnectionManagerUtil.rollbackDBTransaction();
return false;
return null;
} catch (DBConnectionException e) {
String msg = "DB Connection error occurs when adding Review for application release with UUID: " + uuid
+ " is failed";
@ -155,6 +164,7 @@ public class ReviewManagerImpl implements ReviewManager {
}
@Override
//todo return object
public boolean addReplyComment(ReviewWrapper reviewWrapper, String uuid, int parentReviewId)
throws ReviewManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
@ -166,7 +176,7 @@ public class ReviewManagerImpl implements ReviewManager {
throw new BadRequestException(msg);
}
ReviewDTO parentReview = getReview(parentReviewId);
ReviewDTO parentReview = getReview(parentReviewId, tenantId);
if (parentReview == null) {
String msg = "Couldn't find an review which has review ID: " + parentReviewId
+ " for application release which has UUID: " + uuid;
@ -195,7 +205,7 @@ public class ReviewManagerImpl implements ReviewManager {
try {
ConnectionManagerUtil.beginDBTransaction();
ApplicationReleaseDTO applicationReleaseDTO = this.applicationReleaseDAO.getReleaseByUUID(uuid, tenantId);
if (this.reviewDAO.addReview(replyComment, applicationReleaseDTO.getId(), tenantId)) {
if (this.reviewDAO.addReview(replyComment, applicationReleaseDTO.getId(), tenantId) != -1) {
ConnectionManagerUtil.commitDBTransaction();
return true;
}
@ -248,10 +258,10 @@ public class ReviewManagerImpl implements ReviewManager {
return review;
}
private ReviewDTO getReview(int reviewId) throws ReviewManagementException {
private ReviewDTO getReview(int reviewId, int tenantId) throws ReviewManagementException {
try {
ConnectionManagerUtil.openDBConnection();
return this.reviewDAO.getReview(reviewId);
return this.reviewDAO.getReview(reviewId, tenantId);
} catch (DBConnectionException e) {
String msg = "DB Connection error occurs updating reviewTmp with reviewTmp id " + reviewId + ".";
log.error(msg);
@ -266,7 +276,7 @@ public class ReviewManagerImpl implements ReviewManager {
boolean isPrivilegedUser) throws ReviewManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
ReviewDTO reviewDTO = getReview(reviewId);
ReviewDTO reviewDTO = getReview(reviewId, tenantId);
if (reviewDTO == null) {
String msg = "Couldn't found a review for review ID: " + reviewId;
log.error(msg);
@ -302,7 +312,7 @@ public class ReviewManagerImpl implements ReviewManager {
if (updateReviewInDB(reviewDTO, reviewId, isActiveReview, tenantId)) {
if (!isActiveReview) {
if (addReview(updatingReview, uuid, true)) {
if (addReview(updatingReview, uuid, true) != null) {
return true;
} else {
if (updateReviewInDB(reviewDTO, reviewId, true, tenantId)) {
@ -441,7 +451,7 @@ public class ReviewManagerImpl implements ReviewManager {
throws ReviewManagementException, ApplicationManagementException {
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(uuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't find an application which has the application release of UUID: " + uuid;
log.error(msg);
@ -553,7 +563,7 @@ public class ReviewManagerImpl implements ReviewManager {
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try {
ConnectionManagerUtil.beginDBTransaction();
ReviewDTO existingReview = this.reviewDAO.getReview(reviewId);
ReviewDTO existingReview = this.reviewDAO.getReview(reviewId, tenantId);
if (existingReview == null) {
String msg = "Cannot delete a non-existing review for the application with review id" + reviewId;
log.error(msg);
@ -648,7 +658,7 @@ public class ReviewManagerImpl implements ReviewManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(appReleaseUuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(appReleaseUuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't found an application for application release UUID: " + appReleaseUuid;
log.error(msg);
@ -752,7 +762,7 @@ public class ReviewManagerImpl implements ReviewManager {
private void updateAppRating(String uuid, int tenantId) throws ApplicationManagementException {
try {
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
ApplicationDTO applicationDTO = this.applicationDAO.getApplication(uuid, tenantId);
List<String> uuids = applicationDTO.getApplicationReleaseDTOs().stream().map(ApplicationReleaseDTO::getUuid)
.collect(Collectors.toList());
List<Integer> appRatings = this.reviewDAO.getAllAppRatingValues(uuids, tenantId);

@ -296,7 +296,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try {
ConnectionManagerUtil.openDBConnection();
applicationDTO = this.applicationDAO.getApplicationByUUID(uuid, tenantId);
applicationDTO = this.applicationDAO.getApplication(uuid, tenantId);
if (applicationDTO == null) {
String msg = "Couldn't fond an application for application release UUID: " + uuid;
log.error(msg);
@ -333,23 +333,23 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
try {
ConnectionManagerUtil.beginDBTransaction();
List<Integer> deviceIds = new ArrayList<>();
List<Integer> deviceSubIds = new ArrayList<>();
List<String> subscribedEntities = new ArrayList<>();
if (SubsciptionType.USER.toString().equals(subType)) {
if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedUserNames(params, tenantId);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
params.removeAll(subscribedEntities);
subscriptionDAO.addUserSubscriptions(tenantId, username, params, applicationReleaseId);
}
} else if (SubsciptionType.ROLE.toString().equals(subType)) {
} else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedRoleNames(params, tenantId);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
params.removeAll(subscribedEntities);
subscriptionDAO.addRoleSubscriptions(tenantId, username, params, applicationReleaseId);
}
} else if (SubsciptionType.GROUP.toString().equals(subType)) {
} else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) {
subscribedEntities = subscriptionDAO.getSubscribedGroupNames(params, tenantId);
if (SubAction.INSTALL.toString().equalsIgnoreCase(action)) {
params.removeAll(subscribedEntities);
@ -371,19 +371,19 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
.updateDeviceSubscription(username, alreadySubscribedDevices, false, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
operationAddedDeviceIds.removeAll(alreadySubscribedDevices);
deviceIds.addAll(deviceResubscribingIds);
deviceSubIds.addAll(deviceResubscribingIds);
}
List<Integer> subscribingDevices = subscriptionDAO
.addDeviceSubscription(username, operationAddedDeviceIds, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
deviceIds.addAll(subscribingDevices);
deviceSubIds.addAll(subscribingDevices);
} else if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action) && !alreadySubscribedDevices.isEmpty()) {
List<Integer> deviceResubscribingIds = subscriptionDAO
.updateDeviceSubscription(username, alreadySubscribedDevices, false, subType,
Operation.Status.PENDING.toString(), applicationReleaseId, tenantId);
deviceIds.addAll(deviceResubscribingIds);
deviceSubIds.addAll(deviceResubscribingIds);
}
subscriptionDAO.addOperationMapping(operationId, deviceIds, tenantId);
subscriptionDAO.addOperationMapping(operationId, deviceSubIds, tenantId);
}
ConnectionManagerUtil.commitDBTransaction();
} catch (ApplicationManagementDAOException e) {

@ -693,7 +693,7 @@ public interface ApplicationManagementPublisherAPI {
);
@PUT
@Path("/ent-app-release/{deviceType}/{uuid}")
@Path("/ent-app-release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
@ -725,11 +725,6 @@ public interface ApplicationManagementPublisherAPI {
response = ErrorResponse.class)
})
Response updateEntAppRelease(
@ApiParam(
name = "deviceType",
value = "Supported device type of the application",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(
name = "UUID",
value = "Unique identifier of the ApplicationDTO Release",
@ -769,7 +764,7 @@ public interface ApplicationManagementPublisherAPI {
@Multipart(value = "screenshot3") Attachment screenshot3);
@PUT
@Path("/pub-app-release/{deviceType}/{uuid}")
@Path("/pub-app-release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
@ -801,11 +796,6 @@ public interface ApplicationManagementPublisherAPI {
response = ErrorResponse.class)
})
Response updatePubAppRelease(
@ApiParam(
name = "deviceType",
value = "Supported device type of the application",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(
name = "UUID",
value = "Unique identifier of the ApplicationDTO Release",
@ -840,7 +830,7 @@ public interface ApplicationManagementPublisherAPI {
@Multipart(value = "screenshot3") Attachment screenshot3);
@PUT
@Path("/web-app-release/{deviceType}/{uuid}")
@Path("/web-app-release/{uuid}")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.MULTIPART_FORM_DATA)
@ApiOperation(
@ -872,11 +862,6 @@ public interface ApplicationManagementPublisherAPI {
response = ErrorResponse.class)
})
Response updateWebAppRelease(
@ApiParam(
name = "deviceType",
value = "Supported device type of the application",
required = true)
@PathParam("deviceType") String deviceType,
@ApiParam(
name = "UUID",
value = "Unique identifier of the ApplicationDTO Release",

@ -412,9 +412,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override
@PUT
@Path("/ent-app-release/{deviceType}/{uuid}")
@Path("/ent-app-release/{uuid}")
public Response updateEntAppRelease(
@PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper,
@Multipart(value = "binaryFile", required = false) Attachment binaryFile,
@ -426,31 +425,31 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
if (!applicationManager.updateEntAppRelease(deviceType, applicationUUID, entAppReleaseWrapper,
if (!applicationManager.updateEntAppRelease(applicationUUID, entAppReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType;
String msg ="Ent app release updating is failed. Please contact the administrator. Application release "
+ "UUID: " + applicationUUID;
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity("Application release is successfully updated.").build();
return Response.status(Response.Status.OK).entity("Ent app release is successfully updated.").build();
} catch (BadRequestException e) {
String msg =
"Invalid request to update application release for application release UUID " + applicationUUID;
"Invalid request to update ent app release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg =
"Couldn't found application or application release for application release UUID " + applicationUUID;
"Couldn't found an ent app or ent app release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to update the application release which has UUID "
String msg = "You don't have require permission to update the ent app release which has UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error while updating the application release of the application with UUID " + applicationUUID;
String msg = "Error occurred while updating the ent app release which has UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -458,9 +457,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override
@PUT
@Path("/public-app-release/{deviceType}/{uuid}")
@Path("/public-app-release/{uuid}")
public Response updatePubAppRelease(
@PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") PublicAppReleaseWrapper publicAppReleaseWrapper,
@Multipart(value = "icon", required = false) Attachment iconFile,
@ -471,31 +469,30 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
if (!applicationManager.updatePubAppRelease(deviceType, applicationUUID, publicAppReleaseWrapper,
if (!applicationManager.updatePubAppRelease(applicationUUID, publicAppReleaseWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType;
String msg ="Public app release updating is failed. Please contact the administrator. "
+ "Application release UUID: " + applicationUUID + ", Supported device type:";
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity("Application release is successfully updated.").build();
return Response.status(Response.Status.OK).entity("Public app release is successfully updated.").build();
} catch (BadRequestException e) {
String msg =
"Invalid request to update application release for application release UUID " + applicationUUID;
String msg = "Invalid request to update public app release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg =
"Couldn't found application or application release for application release UUID " + applicationUUID;
String msg = "Couldn't found public app or public app release for application release UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to update the application release which has UUID "
String msg = "You don't have require permission to update the public app release which has UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error while updating the application release of the application with UUID " + applicationUUID;
String msg = "Error occurred while updating the public app release which has UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
@ -503,9 +500,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override
@PUT
@Path("/web-app-release/{deviceType}/{uuid}")
@Path("/web-app-release/{uuid}")
public Response updateWebAppRelease(
@PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") WebAppReleaseWrapper webAppReleaseWrapper,
@Multipart(value = "icon", required = false) Attachment iconFile,
@ -516,31 +512,29 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try {
if (!applicationManager.updateWebAppRelease(deviceType, applicationUUID, webAppReleaseWrapper,
if (!applicationManager.updateWebAppRelease(applicationUUID, webAppReleaseWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType;
String msg ="web app release updating is failed. Please contact the administrator. Application "
+ "release UUID: " + applicationUUID;
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
return Response.status(Response.Status.OK).entity("Application release is successfully updated.").build();
return Response.status(Response.Status.OK).entity("Web app release is successfully updated.").build();
} catch (BadRequestException e) {
String msg =
"Invalid request to update application release for application release UUID " + applicationUUID;
String msg = "Invalid request to update web app release for web app release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) {
String msg =
"Couldn't found application or application release for application release UUID " + applicationUUID;
String msg = "Couldn't found web app or web app release for application release UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) {
String msg = "You don't have require permission to update the application release which has UUID "
String msg = "You don't have require permission to update the web app release which has UUID "
+ applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) {
String msg = "Error while updating the application release of the application with UUID " + applicationUUID;
String msg = "Error occurred while updating the web app release which has UUID " + applicationUUID;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}

@ -48,6 +48,7 @@ public class ReviewManagementAdminAPIImpl implements ReviewManagementAdminAPI {
private static Log log = LogFactory.getLog(ReviewManagementAdminAPIImpl.class);
//todo remove this API
@Override
@PUT
@Consumes("application/json")

@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
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.response.Review;
import org.wso2.carbon.device.application.mgt.common.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
@ -118,8 +119,8 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
@PathParam("uuid") String uuid) {
ReviewManager reviewManager = APIUtil.getReviewManager();
try {
boolean isReviewCreated = reviewManager.addReview(reviewWrapper, uuid, false);
if (isReviewCreated) {
Review review = reviewManager.addReview(reviewWrapper, uuid, false);
if (review != null) {
return Response.status(Response.Status.CREATED).entity(reviewWrapper).build();
} else {
String msg = "Review adding is failed. Please contact the administrator.";

@ -115,7 +115,6 @@ CREATE TABLE IF NOT EXISTS AP_DEVICE_SUBSCRIPTION(
STATUS VARCHAR(45) NOT NULL,
DM_DEVICE_ID INTEGER NOT NULL,
AP_APP_RELEASE_ID INTEGER NOT NULL,
AP_APP_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1
FOREIGN KEY (AP_APP_RELEASE_ID)
@ -136,7 +135,6 @@ CREATE TABLE IF NOT EXISTS AP_GROUP_SUBSCRIPTION(
UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL,
GROUP_NAME VARCHAR(100) NOT NULL,
AP_APP_RELEASE_ID INTEGER NOT NULL,
AP_APP_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_AP_GROUP_SUBSCRIPTION_AP_APP_RELEASE1
FOREIGN KEY (AP_APP_RELEASE_ID)
@ -157,7 +155,6 @@ CREATE TABLE IF NOT EXISTS AP_ROLE_SUBSCRIPTION(
UNSUBSCRIBED_BY VARCHAR(100) NULL DEFAULT NULL,
UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL,
AP_APP_RELEASE_ID INTEGER NOT NULL,
AP_APP_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_AP_ROLE_SUBSCRIPTION_AP_APP_RELEASE1
FOREIGN KEY (AP_APP_RELEASE_ID)
@ -193,7 +190,6 @@ CREATE TABLE IF NOT EXISTS AP_USER_SUBSCRIPTION(
UNSUBSCRIBED_BY VARCHAR(100) NULL DEFAULT NULL,
UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL,
AP_APP_RELEASE_ID INTEGER NOT NULL,
AP_APP_ID INTEGER NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_AP_USER_SUBSCRIPTION_AP_APP_RELEASE1
FOREIGN KEY (AP_APP_RELEASE_ID)

Loading…
Cancel
Save