Merge branch 'application-mgt-new' of https://gitlab.com/entgra/carbon-device-mgt into application-mgt-new

feature/appm-store/pbac
Jayasanka 5 years ago
commit 4ad87b4e6d

@ -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 releaseUuid UUID of the application release.
* @param entAppReleaseWrapper {@link ApplicationReleaseDTO} * @param entAppReleaseWrapper {@link ApplicationReleaseDTO}
* @param applicationArtifact {@link ApplicationArtifact} * @param applicationArtifact {@link ApplicationArtifact}
* @return If the application release is updated correctly True returns, otherwise retuen False * @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; ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
boolean updatePubAppRelease(String deviceType, String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper, boolean updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException; ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
boolean updateWebAppRelease(String deviceType, String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper, boolean updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException; ApplicationArtifact applicationArtifact) throws ApplicationManagementException;
/*** /***
@ -254,7 +253,7 @@ public interface ApplicationManager {
String getInstallableLifecycleState() throws ApplicationManagementException; 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 * @return {@link Review} Added review
* @throws ReviewManagementException Exceptions of the reviewTmp management. * @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; throws ReviewManagementException, ApplicationManagementException;
boolean addReplyComment(ReviewWrapper reviewWrapper, String uuid, int parentReviewId) boolean addReplyComment(ReviewWrapper reviewWrapper, String uuid, int parentReviewId)

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

@ -27,18 +27,18 @@ import org.wso2.carbon.device.application.mgt.core.exception.ApplicationManageme
import java.util.List; 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 { 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. * @param applicationDTO ApplicationDTO that need to be created.
* @return Created Application. * @return Primary key of the created application.
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. * @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. * 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(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; void deleteApplicationTags(int applicationId, int tenantId) throws ApplicationManagementDAOException;
@ -82,7 +82,7 @@ public interface ApplicationDAO {
List<CategoryDTO> getAllCategories(int tenantId) throws ApplicationManagementDAOException; 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; throws ApplicationManagementDAOException;
List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException; List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException;
@ -94,7 +94,10 @@ public interface ApplicationDAO {
void addCategoryMapping(List<Integer> categoryIds, int applicationId, int tenantId) void addCategoryMapping(List<Integer> categoryIds, int applicationId, int tenantId)
throws ApplicationManagementDAOException; 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; 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; 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 * To get the application with the given id
* *
@ -127,7 +122,7 @@ public interface ApplicationDAO {
* @return the application * @return the application
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. * @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 * To get the application with the given uuid
@ -137,7 +132,15 @@ public interface ApplicationDAO {
* @return the application * @return the application
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. * @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 * 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 * @return count of the applications
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/ */
int getApplicationCount(Filter filter, int tenantId) throws ApplicationManagementDAOException; int getApplicationCount(Filter filter, int deviceTypeId, 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;
void deleteApplication(int appId, 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 ApplicationReleaseDTO createRelease(ApplicationReleaseDTO applicationRelease, int appId, int tenantId) throws
ApplicationManagementDAOException; 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. * To update an ApplicationDTO release.
* *
@ -108,8 +70,6 @@ public interface ApplicationReleaseDAO {
List<Double> getReleaseRatings(String uuid, int tenantId) throws ApplicationManagementDAOException; List<Double> getReleaseRatings(String uuid, int tenantId) throws ApplicationManagementDAOException;
/** /**
* To delete a particular release. * To delete a particular release.
* *
@ -120,30 +80,8 @@ public interface ApplicationReleaseDAO {
void deleteReleases(List<Integer> applicationReleaseIds) throws ApplicationManagementDAOException; 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; 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. * 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 * @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception. * @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; 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.response.Review;
import org.wso2.carbon.device.application.mgt.common.PaginationRequest; 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.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 org.wso2.carbon.device.application.mgt.core.exception.ReviewManagementDAOException;
import java.sql.SQLException;
import java.util.List; import java.util.List;
/** /**
@ -43,7 +40,7 @@ import java.util.List;
* @return If reviewTmp is added successfully, it return true otherwise false * @return If reviewTmp is added successfully, it return true otherwise false
* @throws ReviewManagementDAOException Exceptions of the reviewTmp management DAO. * @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. * To verify whether user has already commented for the application release or not.
@ -76,9 +73,7 @@ import java.util.List;
* @return {@link Review} * @return {@link Review}
* @throws ReviewManagementDAOException Exceptions of the review management DAO. * @throws ReviewManagementDAOException Exceptions of the review management DAO.
*/ */
ReviewDTO getReview(int reviewId) throws ReviewManagementDAOException; ReviewDTO getReview(int reviewId, int tenantId) throws ReviewManagementDAOException;
ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException;
/** /**
@ -113,51 +108,16 @@ import java.util.List;
List<Integer> getAllAppRatingValues(List<String> uuids, int tenantId) throws ReviewManagementDAOException; 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. * To delete review using review id and uuid of the application release.
* *
* @param reviewId id of the review * @param reviewId id of the review
* @return If review is successfully deleted return 1, otherwise returns 0.
* @throws ReviewManagementDAOException Review management DAO exception. * @throws ReviewManagementDAOException Review management DAO exception.
*/ */
void deleteReview(int reviewId, int tenantId) throws ReviewManagementDAOException; void deleteReview(int reviewId, int tenantId) throws ReviewManagementDAOException;
void deleteReviews(List<Integer> reviewIds, int tenantId) throws ReviewManagementDAOException; void deleteReviews(List<Integer> reviewIds, int tenantId) throws ReviewManagementDAOException;
void deleteAllChildCommentsOfReview(int rootParentId, 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; 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.ApplicationReleaseDTO;
import org.wso2.carbon.device.application.mgt.common.dto.DeviceSubscriptionDTO; 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.application.mgt.core.exception.ApplicationManagementDAOException;
import org.wso2.carbon.device.mgt.common.Device;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -81,6 +79,9 @@ public interface SubscriptionDAO {
List<Integer> getSubscribedDeviceIds(List<Integer> deviceIds, int tenantId) throws ApplicationManagementDAOException; 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); private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class);
@Override @Override
public int createApplication(ApplicationDTO application, int tenantId) throws ApplicationManagementDAOException { public int createApplication(ApplicationDTO applicationDTO, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to create an application"); log.debug("Request received in DAO Layer to create an application");
log.debug("ApplicationDTO Details : "); 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; String sql = "INSERT INTO AP_APP "
PreparedStatement stmt = null; + "(NAME, "
ResultSet rs = null; + "DESCRIPTION, "
+ "TYPE, "
+ "SUB_TYPE, "
+ "TENANT_ID, "
+ "DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?)";
int applicationId = -1; int applicationId = -1;
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
stmt = conn.prepareStatement("INSERT INTO AP_APP " try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
+ "(NAME, " stmt.setString(1, applicationDTO.getName());
+ "DESCRIPTION, " stmt.setString(2, applicationDTO.getDescription());
+ "TYPE, " stmt.setString(3, applicationDTO.getType());
+ "SUB_TYPE, " stmt.setString(4, applicationDTO.getSubType());
+ "TENANT_ID, " stmt.setInt(5, tenantId);
+ "DEVICE_TYPE_ID) VALUES (?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); stmt.setInt(6, applicationDTO.getDeviceTypeId());
stmt.setString(1, application.getName()); stmt.executeUpdate();
stmt.setString(2, application.getDescription()); try (ResultSet rs = stmt.getGeneratedKeys()) {
stmt.setString(3, application.getType()); if (rs.next()) {
stmt.setString(4, application.getSubType()); applicationId = rs.getInt(1);
stmt.setInt(5, tenantId); }
stmt.setInt(6, application.getDeviceTypeId()); return applicationId;
stmt.executeUpdate(); }
rs = stmt.getGeneratedKeys();
if (rs.next()) {
applicationId = rs.getInt(1);
} }
return applicationId;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection to create an application which has "
"Error occurred while obtaining the DB connection when application creation", e); + "application name " + applicationDTO.getName();
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding the application", e); String msg = "Error occurred while executing SQL to create an application which has application name "
} finally { + applicationDTO.getName();
DAOUtil.cleanupResources(stmt, rs); 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())); log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset()));
} }
int paramIndex = 1; int paramIndex = 1;
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "SELECT " String sql = "SELECT "
+ "AP_APP.ID AS APP_ID, " + "AP_APP.ID AS APP_ID, "
+ "AP_APP.NAME AS APP_NAME, " + "AP_APP.NAME AS APP_NAME, "
@ -139,7 +138,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "WHERE AP_APP.TENANT_ID = ?"; + "WHERE AP_APP.TENANT_ID = ?";
if (filter == null) { 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())) { if (!StringUtils.isEmpty(filter.getAppType())) {
@ -179,57 +180,59 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
sql += " ORDER BY APP_ID " + sortingOrder +" LIMIT ? OFFSET ? "; sql += " ORDER BY APP_ID " + sortingOrder +" LIMIT ? OFFSET ? ";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
stmt = conn.prepareStatement(sql); try (PreparedStatement stmt = conn.prepareStatement(sql);
stmt.setInt(paramIndex++, tenantId); ){
stmt.setInt(paramIndex++, tenantId);
if (filter.getAppType() != null && !filter.getAppType().isEmpty()) { if (filter.getAppType() != null && !filter.getAppType().isEmpty()) {
stmt.setString(paramIndex++, filter.getAppType()); stmt.setString(paramIndex++, filter.getAppType());
} }
if (filter.getAppName() != null && !filter.getAppName().isEmpty()) { if (filter.getAppName() != null && !filter.getAppName().isEmpty()) {
if (filter.isFullMatch()) { if (filter.isFullMatch()) {
stmt.setString(paramIndex++, filter.getAppName().toLowerCase()); 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);
}
if (filter.getLimit() == 0) {
stmt.setInt(paramIndex++, 100);
} else { } else {
stmt.setString(paramIndex++, "%" + filter.getAppName().toLowerCase() + "%"); stmt.setInt(paramIndex++, filter.getLimit());
}
stmt.setInt(paramIndex, filter.getOffset());
try (ResultSet rs = stmt.executeQuery() ) {
return DAOUtil.loadApplications(rs);
} }
} }
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);
}
if (filter.getLimit() == 0) {
stmt.setInt(paramIndex++, 100);
} else {
stmt.setInt(paramIndex++, filter.getLimit());
}
stmt.setInt(paramIndex, filter.getOffset());
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) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection while " String msg = "Error occurred while obtaining the DB connection while getting application list for the "
+ "getting application list for the tenant " + tenantId, + "tenant " + tenantId;
e); log.error(msg);
} catch (JSONException e) { throw new ApplicationManagementDAOException(msg, e);
throw new ApplicationManagementDAOException("Error occurred while parsing JSON ", e); } catch (SQLException e) {
} finally { String msg = "Error occurred while getting application list for the tenant " + tenantId + ". While "
DAOUtil.cleanupResources(stmt, rs); + "executing " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -269,52 +272,107 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public int getApplicationCount(Filter filter, int tenantId) throws ApplicationManagementDAOException { public int getApplicationCount(Filter filter,int deviceTypeId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application count from the database"); log.debug("Getting application count for filtering app data from the database");
log.debug(String.format("Filter: limit=%s, offset=%s", filter.getLimit(), filter.getOffset()));
} }
int paramIndex = 1; int paramIndex = 1;
Connection conn; Connection conn;
PreparedStatement stmt = null; PreparedStatement stmt = null;
ResultSet rs = null; ResultSet rs = null;
String sql = ""; String sql = "SELECT count(AP_APP.ID) AS APP_COUNT "
int count = 0; + "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) { if (filter == null) {
throw new ApplicationManagementDAOException("Filter need to be instantiated"); throw new ApplicationManagementDAOException("Filter need to be instantiated");
} }
try { if (!StringUtils.isEmpty(filter.getAppType())) {
conn = this.getDBConnection(); sql += " AND AP_APP.TYPE = ?";
sql += "SELECT count(APP.ID) AS APP_COUNT FROM AP_APP AS APP WHERE TENANT_ID = ?"; }
if (!StringUtils.isEmpty(filter.getAppName())) {
if (filter.getAppName() != null) { sql += " AND LOWER (AP_APP.NAME) ";
sql += " AND LOWER (APP.NAME) LIKE ? "; if (filter.isFullMatch()) {
sql += "= ?";
} else {
sql += "LIKE ?";
} }
sql += ";"; }
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 = ?";
}
try {
conn = this.getDBConnection();
stmt = conn.prepareStatement(sql); stmt = conn.prepareStatement(sql);
stmt.setInt(paramIndex++, tenantId); 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(); rs = stmt.executeQuery();
if (rs.next()) { if (rs.next()) {
count = rs.getInt("APP_COUNT"); return rs.getInt("APP_COUNT");
} }
return 0;
} catch (SQLException e) { } 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) { } 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 { } finally {
DAOUtil.cleanupResources(stmt, rs); DAOUtil.cleanupResources(stmt, rs);
} }
return count;
} }
@Override @Override
public ApplicationDTO getApplicationByUUID(String releaseUuid, int tenantId) public ApplicationDTO getApplication(String releaseUuid, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application with the release UUID: " + releaseUuid + " from the database"); 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( throw new ApplicationManagementDAOException(
"Error occurred while getting application details with app release uuid " + releaseUuid + "Error occurred while getting application details with app release uuid " + releaseUuid +
" while executing query.", e); " while executing query.", e);
} catch (JSONException e) {
throw new ApplicationManagementDAOException("Error occurred while parsing JSON", e);
} catch (DBConnectionException 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.", e);
} catch (UnexpectedServerErrorException e) { } catch (UnexpectedServerErrorException e) {
@ -389,7 +445,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public ApplicationDTO getApplicationById(int applicationId, int tenantId) public ApplicationDTO getApplication(int applicationId, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application with the id (" + applicationId + ") from the database"); log.debug("Getting application with the id (" + applicationId + ") from the database");
@ -811,16 +867,16 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public void deleteCategoryMapping (int applicationId, int tenantId) throws ApplicationManagementDAOException{ public void deleteAppCategories(int applicationId, int tenantId) throws ApplicationManagementDAOException{
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Category mappings."); log.debug("Request received in DAO Layer to delete Category mappings.");
} }
Connection conn; Connection conn;
String sql = "DELETE FROM " String sql = "DELETE FROM "
+ "AP_APP_CATEGORY_MAPPING cm " + "AP_APP_CATEGORY_MAPPING "
+ "WHERE " + "WHERE "
+ "cm.AP_APP_ID = ? AND " + "AP_APP_ID = ? AND "
+ "cm.TENANT_ID = ?"; + "TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){ 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 @Override
public void deleteCategory(int categoryId, int tenantId) throws ApplicationManagementDAOException { public void deleteCategory(int categoryId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -845,10 +932,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
Connection conn; Connection conn;
String sql = "DELETE FROM " + String sql = "DELETE FROM " +
"AP_APP_CATEGORY cat " + "AP_APP_CATEGORY " +
"WHERE " + "WHERE " +
"cat.ID = ? AND " + "ID = ? AND " +
"cat.TENANT_ID = ?"; "TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1120,11 +1207,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
Connection conn; Connection conn;
String sql = "DELETE FROM " String sql = "DELETE FROM "
+ "AP_APP_TAG_MAPPING tm " + "AP_APP_TAG_MAPPING WHERE "
+ "WHERE " + "AP_APP_TAG_ID = ? AND "
+ "tm.AP_APP_TAG_ID = ? AND " + "AP_APP_ID = ? AND "
+ "tm.AP_APP_ID = ? AND " + "TENANT_ID = ?";
+ "tm.TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){ try (PreparedStatement stmt = conn.prepareStatement(sql)){
@ -1145,17 +1231,17 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @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()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Tag mapping."); log.debug("Request received in DAO Layer to delete Tag mapping.");
} }
Connection conn; Connection conn;
String sql = "DELETE FROM " String sql = "DELETE FROM "
+ "AP_APP_TAG_MAPPING tm " + "AP_APP_TAG_MAPPING "
+ "WHERE " + "WHERE "
+ "tm.AP_APP_TAG_ID = ? AND " + "AP_APP_TAG_ID = ? AND "
+ "tm.AP_APP_ID = ? AND " + "AP_APP_ID = ? AND "
+ "tm.TENANT_ID = ?"; + "TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1179,10 +1265,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
Connection conn; Connection conn;
String sql = "DELETE FROM " String sql = "DELETE FROM "
+ "AP_APP_TAG_MAPPING tm " + "AP_APP_TAG_MAPPING "
+ "WHERE " + "WHERE "
+ "tm.AP_APP_ID = ? AND " + "AP_APP_ID = ? AND "
+ "tm.TENANT_ID = ?"; + "TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1207,10 +1293,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
Connection conn; Connection conn;
String sql = "DELETE FROM " + String sql = "DELETE FROM " +
"AP_APP_TAG_MAPPING tm " + "AP_APP_TAG_MAPPING " +
"WHERE " + "WHERE " +
"tm.AP_APP_ID = ? AND " + "AP_APP_ID = ? AND " +
"tm.TENANT_ID = ?"; "TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
@ -1235,10 +1321,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
Connection conn; Connection conn;
String sql = "DELETE FROM " + String sql = "DELETE FROM " +
"AP_APP_TAG tag " + "AP_APP_TAG " +
"WHERE " + "WHERE " +
"tag.ID = ? AND " + "ID = ? AND " +
"tag.TENANT_ID = ?"; "TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { 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 @Override
public boolean isExistingAppName(String appName, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException { public boolean isExistingAppName(String appName, int deviceTypeId, int tenantId) throws ApplicationManagementDAOException {
Connection conn; 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 @Override
public void deleteApplication(int appId, int tenantId) throws ApplicationManagementDAOException { public void deleteApplication(int appId, int tenantId) throws ApplicationManagementDAOException {
Connection conn; Connection conn;
String sql; String sql;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
sql = "DELETE AP_APP ap " sql = "DELETE FROM AP_APP "
+ "WHERE ap.ID = ? AND " + "WHERE ID = ? AND "
+ "ap.TENANT_ID = ?"; + "TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)){ try (PreparedStatement stmt = conn.prepareStatement(sql)){
stmt.setInt(1, appId); stmt.setInt(1, appId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);

@ -33,30 +33,20 @@ import java.sql.Connection;
import java.sql.PreparedStatement; import java.sql.PreparedStatement;
import java.sql.ResultSet; import java.sql.ResultSet;
import java.sql.SQLException; import java.sql.SQLException;
import java.sql.Statement;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; 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 { public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements ApplicationReleaseDAO {
private static final Log log = LogFactory.getLog(GenericApplicationReleaseDAOImpl.class); private static final Log log = LogFactory.getLog(GenericApplicationReleaseDAOImpl.class);
/** @Override
* To insert the ApplicationDTO Release Details. public ApplicationReleaseDTO createRelease(ApplicationReleaseDTO applicationReleaseDTO, int appId, int tenantId)
*
* @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)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
String sql = "INSERT INTO AP_APP_RELEASE " String sql = "INSERT INTO AP_APP_RELEASE "
+ "(DESCRIPTION," + "(DESCRIPTION,"
+ "VERSION," + "VERSION,"
@ -77,178 +67,77 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
+ "SUPPORTED_OS_VERSIONS," + "SUPPORTED_OS_VERSIONS,"
+ "CURRENT_STATE," + "CURRENT_STATE,"
+ "AP_APP_ID) " + "AP_APP_ID) "
+ "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?);"; + "VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
String generatedColumns[] = { "ID" };
try {
connection = this.getDBConnection();
statement = connection.prepareStatement(sql, generatedColumns);
statement.setString(1, applicationReleaseDTO.getDescription());
statement.setString(2, applicationReleaseDTO.getVersion());
statement.setInt(3, tenantId);
statement.setString(4, applicationReleaseDTO.getUuid());
statement.setString(5, String.valueOf(applicationReleaseDTO.getReleaseType()));
statement.setString(6, String.valueOf(applicationReleaseDTO.getPackageName()));
statement.setDouble(7, applicationReleaseDTO.getPrice());
statement.setString(8, applicationReleaseDTO.getInstallerName());
statement.setString(9, applicationReleaseDTO.getIconName());
statement.setString(10, applicationReleaseDTO.getBannerName());
statement.setString(11, applicationReleaseDTO.getScreenshotName1());
statement.setString(12, applicationReleaseDTO.getScreenshotName2());
statement.setString(13, applicationReleaseDTO.getScreenshotName3());
statement.setString(14, applicationReleaseDTO.getAppHashValue());
statement.setBoolean(15, applicationReleaseDTO.getIsSharedWithAllTenants());
statement.setString(16, applicationReleaseDTO.getMetaData());
statement.setString(17, applicationReleaseDTO.getSupportedOsVersions());
statement.setString(18, applicationReleaseDTO.getCurrentState().toUpperCase());
statement.setInt(19, appId);
statement.executeUpdate();
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 { try {
connection = this.getDBConnection(); Connection connection = this.getDBConnection();
statement = connection.prepareStatement(sql); try (PreparedStatement statement = connection.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)){
statement.setInt(1, applicationId); statement.setString(1, applicationReleaseDTO.getDescription());
statement.setString(2, releaseUuid); statement.setString(2, applicationReleaseDTO.getVersion());
statement.setInt(3, tenantId); statement.setInt(3, tenantId);
resultSet = statement.executeQuery(); statement.setString(4, applicationReleaseDTO.getUuid());
statement.setString(5, String.valueOf(applicationReleaseDTO.getReleaseType()));
if (resultSet.next()) { statement.setString(6, String.valueOf(applicationReleaseDTO.getPackageName()));
return DAOUtil.loadApplicationRelease(resultSet); statement.setDouble(7, applicationReleaseDTO.getPrice());
statement.setString(8, applicationReleaseDTO.getInstallerName());
statement.setString(9, applicationReleaseDTO.getIconName());
statement.setString(10, applicationReleaseDTO.getBannerName());
statement.setString(11, applicationReleaseDTO.getScreenshotName1());
statement.setString(12, applicationReleaseDTO.getScreenshotName2());
statement.setString(13, applicationReleaseDTO.getScreenshotName3());
statement.setString(14, applicationReleaseDTO.getAppHashValue());
statement.setBoolean(15, applicationReleaseDTO.getIsSharedWithAllTenants());
statement.setString(16, applicationReleaseDTO.getMetaData());
statement.setString(17, applicationReleaseDTO.getSupportedOsVersions());
statement.setString(18, applicationReleaseDTO.getCurrentState().toUpperCase());
statement.setInt(19, appId);
statement.executeUpdate();
try(ResultSet resultSet = statement.getGeneratedKeys()){
if (resultSet.next()) {
applicationReleaseDTO.setId(resultSet.getInt(1));
}
return applicationReleaseDTO;
}
} }
return null;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Database Connection error occurred while trying to release a new version for application which"
"Database connection exception while trying to get the release details of the " + "application id: " + " has app ID: " + appId;
+ applicationId + "and UUID of the application release: " + releaseUuid, e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "SQL Exception while trying to release an application by executing the query " + sql;
"Error while getting release details of the application id: " + applicationId log.error(msg);
+ " and theUUID of the application " + "release: " + releaseUuid + " , while executing the query " + sql, e); throw new ApplicationManagementDAOException(msg, e);
} finally {
DAOUtil.cleanupResources(statement, resultSet);
} }
} }
@Override @Override
public ApplicationReleaseDTO getReleaseByUUID( String uuid, int tenantId) throws ApplicationManagementDAOException { public ApplicationReleaseDTO getReleaseByUUID( String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection connection; String sql = "SELECT "
String sql = + "AR.ID AS RELEASE_ID, "
"SELECT AR.ID AS RELEASE_ID, " + "AR.DESCRIPTION AS RELEASE_DESCRIPTION, "
+ "AR.DESCRIPTION AS RELEASE_DESCRIPTION, " + "AR.VERSION AS RELEASE_VERSION, "
+ "AR.VERSION AS RELEASE_VERSION, " + "AR.UUID AS RELEASE_UUID, "
+ "AR.UUID AS RELEASE_UUID, " + "AR.RELEASE_TYPE AS RELEASE_TYPE, "
+ "AR.RELEASE_TYPE AS RELEASE_TYPE, " + "AR.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, "
+ "AR.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, " + "AR.ICON_LOCATION AS AP_RELEASE_ICON_LOC, "
+ "AR.ICON_LOCATION AS AP_RELEASE_ICON_LOC, " + "AR.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, "
+ "AR.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, " + "AR.SC_1_LOCATION AS AP_RELEASE_SC1, "
+ "AR.SC_1_LOCATION AS AP_RELEASE_SC1, " + "AR.SC_2_LOCATION AS AP_RELEASE_SC2, "
+ "AR.SC_2_LOCATION AS AP_RELEASE_SC2, " + "AR.SC_3_LOCATION AS AP_RELEASE_SC3, "
+ "AR.SC_3_LOCATION AS AP_RELEASE_SC3, " + "AR.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
+ "AR.APP_HASH_VALUE AS RELEASE_HASH_VALUE, " + "AR.APP_PRICE AS RELEASE_PRICE, "
+ "AR.APP_PRICE AS RELEASE_PRICE, " + "AR.APP_META_INFO AS RELEASE_META_INFO, "
+ "AR.APP_META_INFO AS RELEASE_META_INFO, " + "AR.PACKAGE_NAME AS PACKAGE_NAME, "
+ "AR.PACKAGE_NAME AS PACKAGE_NAME, " + "AR.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
+ "AR.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, " + "AR.RATING AS RELEASE_RATING, "
+ "AR.RATING AS RELEASE_RATING, " + "AR.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
+ "AR.CURRENT_STATE AS RELEASE_CURRENT_STATE, " + "AR.RATED_USERS AS RATED_USER_COUNT "
+ "AR.RATED_USERS AS RATED_USER_COUNT "
+ "FROM AP_APP_RELEASE AS AR " + "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.UUID = ? AND AR.TENANT_ID = ?"; + "WHERE AR.UUID = ? AND AR.TENANT_ID = ?";
try { try {
connection = this.getDBConnection(); Connection connection = this.getDBConnection();
try (PreparedStatement statement = connection.prepareStatement(sql)) { try (PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, uuid); statement.setString(1, uuid);
statement.setInt(2, tenantId); statement.setInt(2, tenantId);
@ -260,146 +149,58 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Database connection error occurred while trying to get application release details which has "
"Database connection exception while trying to get the release details of the UUID of the application release: " + "UUID: " + uuid;
+ uuid, e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg =
"Error while getting release details of the UUID of the application " + "release: " + uuid "Error while getting application release details which has UUID: " + uuid + " , while executing"
+ " , while executing the query " + sql, e); + " the query " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, 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);
} 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);
}
}
//todo this has to be removed
@Override @Override
public List<ApplicationReleaseDTO> getReleaseByState(int appId, int tenantId, String state) throws public void updateRatingValue(String uuid, double rating, int ratedUsers) throws ApplicationManagementDAOException {
ApplicationManagementDAOException { String sql = "UPDATE "
Connection connection; + "AP_APP_RELEASE "
PreparedStatement statement = null; + "SET "
ResultSet resultSet = null; + "RATING = ?, "
List<ApplicationReleaseDTO> applicationReleases = new ArrayList<>(); + "RATED_USERS = ? "
String sql = "SELECT AR.ID AS RELEASE_ID, AR.VERSION AS RELEASE_VERSION, AR.UUID AS UUID, AR.RELEASE_TYPE AS " + "WHERE UUID = ?";
+ "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 { try {
connection = this.getDBConnection(); Connection connection = this.getDBConnection();
statement = connection.prepareStatement(sql); try (PreparedStatement statement = connection.prepareStatement(sql)){
statement.setInt(1, appId); statement.setDouble(1, rating);
statement.setString(2, state); statement.setInt(2, ratedUsers);
statement.setInt(3, tenantId); statement.setString(3, uuid);
resultSet = statement.executeQuery(); statement.executeUpdate();
while (resultSet.next()) {
ApplicationReleaseDTO appRelease = DAOUtil.loadApplicationRelease(resultSet);
applicationReleases.add(appRelease);
} }
return applicationReleases;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Database connection exception while trying to get the " String msg = "Database connection error occurred while trying to update the application release rating "
+ "release details of the application with id " + appId, e); + "value for UUID: " + uuid;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "SQL exception occured while updating the release rating value. Executed query " + sql;
"Error while getting all the release details of the app id" + appId + " application" log.error(msg);
+ ", while executing the query " + sql, e); throw new ApplicationManagementDAOException(msg, 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 = ?;";
try {
connection = this.getDBConnection();
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);
} 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);
}
}
/**
* To retrieve rating of an application release.
*
* @param uuid UUID of the application Release.
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
@Override @Override
public Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException { public Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection connection; Connection connection;
PreparedStatement statement = null; PreparedStatement statement = null;
ResultSet resultSet = null; ResultSet resultSet = null;
Rating rating = 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 { try {
connection = this.getDBConnection(); connection = this.getDBConnection();
statement = connection.prepareStatement(sql); statement = connection.prepareStatement(sql);
@ -639,44 +440,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
@Override @Override
public boolean verifyReleaseExistence(int appId, 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 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 {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Verifying application release existence by application release uuid: " + uuid); 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.PaginationRequest;
import org.wso2.carbon.device.application.mgt.common.dto.ReviewDTO; 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.common.exception.DBConnectionException;
import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO; import org.wso2.carbon.device.application.mgt.core.dao.ReviewDAO;
import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException; import org.wso2.carbon.device.application.mgt.core.exception.UnexpectedServerErrorException;
@ -52,7 +51,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
private String sql; private String sql;
@Override @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()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add review for application release. Application Release UUID: " log.debug("Request received in DAO Layer to add review for application release. Application Release UUID: "
+ appReleaseId); + appReleaseId);
@ -69,11 +68,11 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
+ "AP_APP_RELEASE_ID) " + "AP_APP_RELEASE_ID) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )"; + "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ? )";
try { try {
int reviewId = -1;
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
Connection conn = this.getDBConnection(); 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.setInt(1, tenantId);
statement.setString(2, reviewDTO.getContent()); statement.setString(2, reviewDTO.getContent());
statement.setInt(3, reviewDTO.getRootParentId()); statement.setInt(3, reviewDTO.getRootParentId());
@ -85,16 +84,22 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(9, appReleaseId); statement.setInt(9, appReleaseId);
statement.executeUpdate(); statement.executeUpdate();
try (ResultSet rs = statement.getGeneratedKeys()) { try (ResultSet rs = statement.getGeneratedKeys()) {
return rs.next(); if (rs.next()) {
reviewId = rs.getInt(1);
}
} }
return reviewId;
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occurred while obtaining the DB connection while " String msg = "Error occurred while obtaining the DB connection to add a review for application release which"
+ "adding review for application release which has ID: "+ appReleaseId + "Tenant Id: " + tenantId, e); + " has ID: "+ appReleaseId + " and Tenant Id: " + tenantId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException( String msg = "Error occurred while executing SQL statement to add application review. Application ID: "
"Error occurred while executing SQL statement to add application review. Application ID: " + appReleaseId + " and tenant " + tenantId;
+ appReleaseId + " tenant " + tenantId, e); 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) public boolean hasUerReviewedApp(List<Integer> appReleaseIds, String username, int tenantId)
throws ReviewManagementDAOException { throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { 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); + "application. Commenting user: " + username + " and tenant-id: " + tenantId);
} }
Connection conn;
int index = 1;
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
StringJoiner joiner = new StringJoiner(",", StringJoiner joiner = new StringJoiner(",",
"SELECT rv.ID FROM AP_APP_REVIEW rv WHERE rv.AP_APP_RELEASE_ID IN (", "SELECT rv.ID FROM AP_APP_REVIEW rv WHERE rv.AP_APP_RELEASE_ID IN (",
") AND rv.USERNAME = ? AND rv.TENANT_ID = ?"); ") AND rv.USERNAME = ? AND rv.TENANT_ID = ?");
appReleaseIds.stream().map(ignored -> "?").forEach(joiner::add); appReleaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString(); String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) { try (PreparedStatement ps = conn.prepareStatement(query)) {
int index = 1;
for (Integer deviceId : appReleaseIds) { for (Integer deviceId : appReleaseIds) {
ps.setObject(index++, deviceId); ps.setObject(index++, deviceId);
} }
@ -124,25 +128,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
return rs.next(); 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) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the database connection when checking " String msg = "Error occured while getting the database connection when checking whether user has already "
+ "whether user has already commented for the application ro not", e); + "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 @Override
public int updateReview(ReviewDTO reviewDTO, int reviewId, boolean isActiveReview, int tenantId) public int updateReview(ReviewDTO reviewDTO, int reviewId, boolean isActiveReview, int tenantId)
throws ReviewManagementDAOException { throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { 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 " sql = "UPDATE "
+ "AP_APP_REVIEW " + "AP_APP_REVIEW "
+ "SET " + "SET "
@ -150,109 +154,73 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
+ "RATING = ?, " + "RATING = ?, "
+ "MODIFIED_AT = ?, " + "MODIFIED_AT = ?, "
+ "ACTIVE_REVIEW = ? " + "ACTIVE_REVIEW = ? "
+ "WHERE ID = ? AND " + "WHERE ID = ? AND TENANT_ID = ?";
+ "TENANT_ID = ?";
try { try {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
Timestamp timestamp = new Timestamp(calendar.getTime().getTime()); Timestamp timestamp = new Timestamp(calendar.getTime().getTime());
connection = this.getDBConnection(); Connection connection = this.getDBConnection();
statement = connection.prepareStatement(sql); try (PreparedStatement statement = connection.prepareStatement(sql)){
statement.setString(1, reviewDTO.getContent()); statement.setString(1, reviewDTO.getContent());
statement.setInt(2, reviewDTO.getRating()); statement.setInt(2, reviewDTO.getRating());
statement.setTimestamp(3, timestamp); statement.setTimestamp(3, timestamp);
statement.setBoolean(4, isActiveReview); statement.setBoolean(4, isActiveReview);
statement.setInt(5, reviewId); statement.setInt(5, reviewId);
statement.setInt(6, tenantId); statement.setInt(6, tenantId);
return statement.executeUpdate(); return statement.executeUpdate();
} catch (SQLException e) { }
throw new ReviewManagementDAOException("Error occurred while executing reviewTmp updating query");
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException("Error occured while getting the db connection to update reviewTmp"); String msg = "Error occured while getting the db connection to update review for review ID: " + reviewId;
} finally { log.error(msg);
DAOUtil.cleanupResources(statement, rs); throw new ReviewManagementDAOException(msg, e);
}
}
@Override
public ReviewDTO getReview(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 "
+ "AP_APP_REVIEW.ID AS ID, "
+ "AP_APP_REVIEW.COMMENT AS COMMENT, "
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
+ "AP_APP_REVIEW.RATING AS RATING, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
+ "AP_APP_RELEASE.UUID AS UUID, "
+ "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);
statement.setInt(1, reviewId);
rs = statement.executeQuery();
return DAOUtil.loadReview(rs);
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException( String msg = "Error occurred while executing review updating query for review ID: " + reviewId;
"SQL Error occurred while retrieving information of the reviewTmp " + reviewId, e); log.error(msg);
} catch (DBConnectionException e) { throw new ReviewManagementDAOException(msg, 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 @Override
public ReviewDTO getReview(int appReleaseId, int reviewId) throws ReviewManagementDAOException { public ReviewDTO getReview(int reviewId, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { 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; sql = "SELECT "
PreparedStatement statement = null; + "AP_APP_REVIEW.ID AS ID, "
ResultSet rs = null; + "AP_APP_REVIEW.COMMENT AS COMMENT, "
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
+ "AP_APP_REVIEW.RATING AS RATING, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
+ "AP_APP_RELEASE.UUID AS UUID, "
+ "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 = ? AND AP_APP_REVIEW.TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
sql = "SELECT " try (PreparedStatement statement = conn.prepareStatement(sql)) {
+ "ID, " statement.setInt(1, reviewId);
+ "COMMENT," statement.setInt(2, tenantId);
+ "ROOT_PARENT_ID," try (ResultSet rs = statement.executeQuery()) {
+ "IMMEDIATE_PARENT_ID, " return DAOUtil.loadReview(rs);
+ "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) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException( String msg = "DB Connection Exception occurred while retrieving information of the review for review ID: "
"DB Connection Exception occurred while retrieving information of the reviewTmp " + reviewId, e); + 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) { } catch (UnexpectedServerErrorException e) {
throw new ReviewManagementDAOException("Found more than one review for review ID: " + reviewId, e); String msg = "Found more than one review for review ID: " + reviewId;
} finally { log.error(msg);
DAOUtil.cleanupResources(statement, rs); throw new ReviewManagementDAOException(msg, e);
} }
} }
@ -260,31 +228,28 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
@Override @Override
public List<ReviewDTO> getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId) public List<ReviewDTO> getAllReleaseReviews(int releaseId, PaginationRequest request, int tenantId)
throws ReviewManagementDAOException { throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { 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; sql = "SELECT "
List<ReviewDTO> reviewDTOs; + "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, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
+ "AP_APP_REVIEW.RATING AS RATING, "
+ "AP_APP_RELEASE.UUID AS UUID, "
+ "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.AP_APP_RELEASE_ID = ? AND "
+ "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "LIMIT ? OFFSET ?";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
sql = "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, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, "
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
+ "AP_APP_REVIEW.RATING AS RATING, "
+ "AP_APP_RELEASE.UUID AS UUID, "
+ "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.AP_APP_RELEASE_ID = ? AND "
+ "AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_REVIEW.TENANT_ID = ? "
+ "LIMIT ? OFFSET ?";
try (PreparedStatement statement = conn.prepareStatement(sql)) { try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, releaseId); statement.setInt(1, releaseId);
statement.setInt(2, Constants.REVIEW_PARENT_ID); statement.setInt(2, Constants.REVIEW_PARENT_ID);
@ -292,86 +257,83 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(4, request.getLimit()); statement.setInt(4, request.getLimit());
statement.setInt(5, request.getOffSet()); statement.setInt(5, request.getOffSet());
try (ResultSet rs = statement.executeQuery()) { try (ResultSet rs = statement.executeQuery()) {
reviewDTOs = DAOUtil.loadReviews(rs); return DAOUtil.loadReviews(rs);
} }
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException( String msg = "Error occurred while obtaining the DB connection to get all app release reviews for "
"Error occurred while obtaining the DB connection when verifying application existence", e); + "application release ID: " + releaseId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException("DB connection error occurred while getting all reviewTmps", e); String msg = "Error occurred while executing the SQL statement to get all app release reviews for "
} return reviewDTOs; + "application release ID: " + releaseId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
} }
@Override @Override
public List<ReviewDTO> getAllActiveAppReviews(List<Integer> releaseIds, PaginationRequest request, int tenantId) public List<ReviewDTO> getAllActiveAppReviews(List<Integer> releaseIds, PaginationRequest request, int tenantId)
throws ReviewManagementDAOException { throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { 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; try {
List<ReviewDTO> reviewDTOs; Connection conn = this.getDBConnection();
int index = 1; StringJoiner joiner = new StringJoiner(",",
"SELECT " + "AP_APP_REVIEW.ID AS ID, "
try { + "AP_APP_REVIEW.COMMENT AS COMMENT, "
conn = this.getDBConnection(); + "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, "
StringJoiner joiner = new StringJoiner(",", + "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, "
"SELECT " + "AP_APP_REVIEW.USERNAME AS USERNAME, "
+ "AP_APP_REVIEW.ID AS ID, " + "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, "
+ "AP_APP_REVIEW.COMMENT AS COMMENT, " + "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, "
+ "AP_APP_REVIEW.CREATED_AT AS CREATED_AT, " + "AP_APP_REVIEW.RATING AS RATING, "
+ "AP_APP_REVIEW.MODIFIED_AT AS MODIFIED_AT, " + "AP_APP_RELEASE.UUID AS UUID, "
+ "AP_APP_REVIEW.USERNAME AS USERNAME, " + "AP_APP_RELEASE.VERSION AS VERSION "
+ "AP_APP_REVIEW.ROOT_PARENT_ID AS ROOT_PARENT_ID, " + "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON "
+ "AP_APP_REVIEW.IMMEDIATE_PARENT_ID AS IMMEDIATE_PARENT_ID, " + "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID "
+ "AP_APP_REVIEW.RATING AS RATING, " + "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID IN (",
+ "AP_APP_RELEASE.UUID AS UUID, " ") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND "
+ "AP_APP_RELEASE.VERSION AS VERSION " + "AP_APP_REVIEW.ACTIVE_REVIEW = true AND "
+ "FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON " + "AP_APP_REVIEW.TENANT_ID = ? "
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID = AP_APP_RELEASE.ID " + "LIMIT ? OFFSET ?");
+ "WHERE AP_APP_REVIEW.AP_APP_RELEASE_ID IN (", releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
") AND AP_APP_REVIEW.ROOT_PARENT_ID = ? AND " String query = joiner.toString();
+ "AP_APP_REVIEW.ACTIVE_REVIEW = true AND " try (PreparedStatement ps = conn.prepareStatement(query)) {
+ "AP_APP_REVIEW.TENANT_ID = ? " int index = 1;
+ "LIMIT ? OFFSET ?"); for (Integer releaseId : releaseIds) {
releaseIds.stream().map(ignored -> "?").forEach(joiner::add); ps.setObject(index++, releaseId);
String query = joiner.toString(); }
try (PreparedStatement ps = conn.prepareStatement(query)) { ps.setInt(index++, Constants.REVIEW_PARENT_ID);
for (Integer releaseId : releaseIds) { ps.setInt(index++, tenantId);
ps.setObject(index++, releaseId); ps.setInt(index++, request.getLimit());
} ps.setInt(index, request.getOffSet());
ps.setInt(index++, Constants.REVIEW_PARENT_ID); try (ResultSet rs = ps.executeQuery()) {
ps.setInt(index++, tenantId); return DAOUtil.loadReviews(rs);
ps.setInt(index++, request.getLimit());
ps.setInt(index, request.getOffSet());
try (ResultSet rs = ps.executeQuery()) {
reviewDTOs = DAOUtil.loadReviews(rs);
}
} }
} }
catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException( String msg = "Error occurred while obtaining the DB connection to get all active app reviews.";
"Error occurred while obtaining the DB connection when verifying application existence.", e); log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException("DB connection error occurred while getting all reviews.", e); String msg = "Error occurred while executing SQL to get all active app reviews.";
} return reviewDTOs; log.error(msg);
throw new ReviewManagementDAOException(msg, e);
}
} }
@Override @Override
public List<ReviewDTO> getAllActiveAppReviewsOfUser(List<Integer> releaseIds, PaginationRequest request, public List<ReviewDTO> getAllActiveAppReviewsOfUser(List<Integer> releaseIds, PaginationRequest request,
String username, int tenantId) String username, int tenantId)
throws ReviewManagementDAOException { throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { 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 { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
StringJoiner joiner = new StringJoiner(",", StringJoiner joiner = new StringJoiner(",",
"SELECT " "SELECT "
+ "AP_APP_REVIEW.ID AS ID, " + "AP_APP_REVIEW.ID AS ID, "
@ -395,6 +357,7 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
releaseIds.stream().map(ignored -> "?").forEach(joiner::add); releaseIds.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString(); String query = joiner.toString();
try (PreparedStatement ps = conn.prepareStatement(query)) { try (PreparedStatement ps = conn.prepareStatement(query)) {
int index = 1;
for (Integer releaseId : releaseIds) { for (Integer releaseId : releaseIds) {
ps.setObject(index++, releaseId); ps.setObject(index++, releaseId);
} }
@ -404,29 +367,28 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
ps.setInt(index++, request.getLimit()); ps.setInt(index++, request.getLimit());
ps.setInt(index, request.getOffSet()); ps.setInt(index, request.getOffSet());
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
reviewDTOs = DAOUtil.loadReviews(rs); return DAOUtil.loadReviews(rs);
} }
} }
} } catch (DBConnectionException e) {
catch (DBConnectionException e) { String msg = "Error occurred while obtaining the DB connection to get all active app reviews of user "
throw new ReviewManagementDAOException( + username;
"Error occurred while obtaining the DB connection when application review of user: " + username , e); log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ReviewManagementDAOException("DB connection error occurred while getting application reviews of " String msg = "Error occurred while executing SQL to get all active app reviews of user " + username;
+ "user:" + username, e); log.error(msg);
} return reviewDTOs; throw new ReviewManagementDAOException(msg, e);
}
} }
@Override @Override
public List<ReviewDTO> getReplyComments(int parentId, int tenantId) throws ReviewManagementDAOException { public List<ReviewDTO> getReplyComments(int parentId, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { 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 { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
sql = "SELECT " sql = "SELECT "
+ "AP_APP_REVIEW.ID AS ID, " + "AP_APP_REVIEW.ID AS ID, "
+ "AP_APP_REVIEW.COMMENT AS COMMENT, " + "AP_APP_REVIEW.COMMENT AS COMMENT, "
@ -446,66 +408,70 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
try (PreparedStatement statement = conn.prepareStatement(sql)) { try (PreparedStatement statement = conn.prepareStatement(sql)) {
statement.setInt(1, parentId); statement.setInt(1, parentId);
statement.setInt(2, tenantId); statement.setInt(2, tenantId);
try (ResultSet rs = statement.executeQuery();) { try (ResultSet rs = statement.executeQuery()) {
reviewDTOs = DAOUtil.loadReviews(rs); return DAOUtil.loadReviews(rs);
} }
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException( String msg = "Error occurred while obtaining the DB connection when getting reply comments for a review "
"Error occurred while obtaining the DB connection when getting reply comments for a review.", e); + "which has reviw ID: " + parentId;
log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} catch (SQLException 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 @Override
public List<Integer> getAllAppReleaseRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException { public List<Integer> getAllAppReleaseRatingValues(String uuid, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { 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; sql = "SELECT "
PreparedStatement statement = null; + "AP_APP_REVIEW.RATING AS RATING "
ResultSet rs = null; + "FROM AP_APP_REVIEW, AP_APP_RELEASE "
List<Integer> reviews = new ArrayList<>(); + "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 { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
sql = "SELECT AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW, AP_APP_RELEASE WHERE " try (PreparedStatement statement = conn.prepareStatement(sql)) {
+ "AP_APP_REVIEW.AP_APP_RELEASE_ID=AP_APP_RELEASE.ID AND AP_APP_RELEASE.UUID =? AND " statement.setString(1, uuid);
+ "AP_APP_REVIEW.TENANT_ID = AP_APP_RELEASE.TENANT_ID AND AP_APP_REVIEW.TENANT_ID = ?"; statement.setInt(2, tenantId);
statement = conn.prepareStatement(sql); try (ResultSet rs = statement.executeQuery()) {
statement.setString(1, uuid); List<Integer> reviews = new ArrayList<>();
statement.setInt(2, tenantId); while (rs.next()) {
rs = statement.executeQuery(); reviews.add(rs.getInt("RATING"));
while (rs.next()) { }
reviews.add(rs.getInt("RATING")); return reviews;
}
} }
} catch (SQLException e) {
throw new ReviewManagementDAOException(
"Error occured while getting all rating values for the application release. App release UUID: "
+ uuid, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException( String msg = "Error occured while getting DB connection to retrieve all rating values for the application "
"Error occured while getting DB connection to retrieve all rating values for the application release. App release UUID: " + "release which has UUID:" + uuid;
+ uuid, e); log.error(msg);
} finally { throw new ReviewManagementDAOException(msg, e);
DAOUtil.cleanupResources(statement, rs); } 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 @Override
public List<Integer> getAllAppRatingValues(List<String> uuids, int tenantId) throws ReviewManagementDAOException { public List<Integer> getAllAppRatingValues(List<String> uuids, int tenantId) throws ReviewManagementDAOException {
if (log.isDebugEnabled()) { 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 { try {
int index = 1; int index = 1;
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
StringJoiner joiner = new StringJoiner(",", StringJoiner joiner = new StringJoiner(",",
"SELECT AP_APP_REVIEW.RATING AS RATING FROM AP_APP_REVIEW INNER JOIN AP_APP_RELEASE ON " "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 (", + "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); ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
List<Integer> reviews = new ArrayList<>();
while (rs.next()) { while (rs.next()) {
reviews.add(rs.getInt("RATING")); reviews.add(rs.getInt("RATING"));
} } }
} return reviews;
} 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) { } catch (DBConnectionException e) {
throw new ReviewManagementDAOException("DB Connection Exception occurred while retrieving review counts", e); String msg = "Error occured while getting DB connection to retrieve all rating values for an application.";
} finally { log.error(msg);
DAOUtil.cleanupResources(statement, rs); throw new ReviewManagementDAOException(msg, e);
} } catch (SQLException e) {
return commentCount; String msg = "Error occured while executing SQL to get all rating values for the application.";
} log.error(msg);
throw new ReviewManagementDAOException(msg, e);
@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);
} }
return commentCount;
} }
@Override @Override
public void deleteReview(int reviewId, int tenantId) throws ReviewManagementDAOException { 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 { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
sql = "DELETE " sql = "DELETE "
+ "FROM AP_APP_REVIEW " + "FROM AP_APP_REVIEW "
+ "WHERE " + "WHERE "
@ -610,19 +519,25 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(2, tenantId); statement.setInt(2, tenantId);
statement.executeUpdate(); statement.executeUpdate();
} }
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
} catch (DBConnectionException 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 @Override
public void deleteReviews(List<Integer> reviewIds, int tenantId) throws ReviewManagementDAOException{ 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 { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
sql = "DELETE " sql = "DELETE "
+ "FROM AP_APP_REVIEW " + "FROM AP_APP_REVIEW "
+ "WHERE " + "WHERE "
@ -636,19 +551,24 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
} }
stmt.executeBatch(); stmt.executeBatch();
} }
} catch (SQLException e) {
throw new ReviewManagementDAOException("Error occured while accessing the Database", e);
} catch (DBConnectionException 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 @Override
public void deleteAllChildCommentsOfReview(int rootParentId, int tenantId) throws ReviewManagementDAOException { 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 { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
sql = "DELETE " sql = "DELETE "
+ "FROM AP_APP_REVIEW " + "FROM AP_APP_REVIEW "
+ "WHERE " + "WHERE "
@ -659,39 +579,16 @@ public class ReviewDAOImpl extends AbstractDAOImpl implements ReviewDAO {
statement.setInt(2, tenantId); statement.setInt(2, tenantId);
statement.executeUpdate(); 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) { } 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) { } catch (SQLException e) {
throw new ReviewManagementException("SQL Error occurred while deleting comments", e); String msg = "Error occured while executing SQL to delete all child comments of a review which has ID: "
} finally { + rootParentId;
DAOUtil.cleanupResources(statement, null); log.error(msg);
throw new ReviewManagementDAOException(msg, e);
} }
} }
} }

@ -48,17 +48,17 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
String subscribedFrom, String installStatus, int releaseId, int tenantId) String subscribedFrom, String installStatus, int releaseId, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection conn; Connection conn;
String sql = "INSERT INTO "
+ "AP_DEVICE_SUBSCRIPTION("
+ "SUBSCRIBED_BY, "
+ "SUBSCRIBED_TIMESTAMP, "
+ "ACTION_TRIGGERED_FROM, "
+ "STATUS, "
+ "DM_DEVICE_ID, "
+ "AP_APP_RELEASE_ID,"
+ "TENANT_ID) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?)";
try { try {
String sql = "INSERT INTO "
+ "AP_DEVICE_SUBSCRIPTION("
+ "SUBSCRIBED_BY, "
+ "SUBSCRIBED_TIMESTAMP, "
+ "ACTION_TRIGGERED_FROM, "
+ "STATUS, "
+ "DM_DEVICE_ID, "
+ "AP_APP_RELEASE_ID,"
+ "TENANT_ID) "
+ "VALUES (?, ?, ?, ?, ?, ?, ?)";
conn = this.getDBConnection(); conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
Calendar calendar = Calendar.getInstance(); Calendar calendar = Calendar.getInstance();
@ -73,18 +73,30 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
stmt.setInt(7, tenantId); stmt.setInt(7, tenantId);
stmt.addBatch(); stmt.addBatch();
if (log.isDebugEnabled()) { 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(); stmt.executeBatch();
try (ResultSet rs = stmt.getGeneratedKeys()) {
List<Integer> deviceSubIds = new ArrayList<>();
while (rs.next()) {
deviceSubIds.add(rs.getInt(1));
}
return deviceSubIds;
}
} }
} catch (SQLException | DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while adding device application mapping to DB", String msg = "Error occured while obtaining database connection to add device subscription for application "
e); + "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 @Override
@ -95,12 +107,12 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
Connection conn; Connection conn;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "UPDATE AP_USER_SUBSCRIPTION " + "SET "; String sql = "UPDATE AP_DEVICE_SUBSCRIPTION SET ";
if (isUnsubscribed) { if (isUnsubscribed) {
sql += "UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ? "; sql += "UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ?, ";
} else { } else {
sql += "SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ? "; sql += "SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ?, ";
} }
sql += "ACTION_TRIGGERED_FROM = ?, " + sql += "ACTION_TRIGGERED_FROM = ?, " +
"STATUS = ? " + "STATUS = ? " +
@ -120,8 +132,16 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
stmt.setInt(5, deviceId); stmt.setInt(5, deviceId);
stmt.setInt(6, releaseId); stmt.setInt(6, releaseId);
stmt.setInt(7, tenantId); stmt.setInt(7, tenantId);
stmt.addBatch();
} }
stmt.executeBatch(); 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) { } catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to update the device subscriptions of application."; 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); log.error(msg);
throw new ApplicationManagementDAOException(msg, e); throw new ApplicationManagementDAOException(msg, e);
} }
return deviceIds;
} }
@Override public void addOperationMapping(int operationId, List<Integer> deviceSubscriptionIds, int tenantId) @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); ps.setInt(index, tenantId);
try (ResultSet rs = ps.executeQuery()) { try (ResultSet rs = ps.executeQuery()) {
while (rs.next()) { 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(); conn = this.getDBConnection();
String sql = "UPDATE "; String sql = "UPDATE ";
if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) { if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) {
sql += "AP_USER_SUBSCRIPTION "; sql += "AP_USER_SUBSCRIPTION SET ";
} else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) { } else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) {
sql += "AP_ROLE_SUBSCRIPTION "; sql += "AP_ROLE_SUBSCRIPTION SET ";
} else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) { } else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) {
sql += "AP_GROUP_SUBSCRIPTION "; sql += "AP_GROUP_SUBSCRIPTION SET ";
} }
if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) { if (SubAction.UNINSTALL.toString().equalsIgnoreCase(action)) {
sql += "SET UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ? "; sql += "UNSUBSCRIBED = true, UNSUBSCRIBED_BY = ?, UNSUBSCRIBED_TIMESTAMP = ? ";
} else { } else {
sql += "SET SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ? "; sql += "SUBSCRIBED_BY = ?, SUBSCRIBED_TIMESTAMP = ? ";
} }
sql += "WHERE ";
if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) { if (SubsciptionType.USER.toString().equalsIgnoreCase(subType)) {
sql += "USER_NAME = ? "; sql += "WHERE USER_NAME = ? ";
} else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) { } else if (SubsciptionType.ROLE.toString().equalsIgnoreCase(subType)) {
sql += "ROLE_NAME = ? "; sql += "WHERE ROLE_NAME = ? ";
} else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) { } else if (SubsciptionType.GROUP.toString().equalsIgnoreCase(subType)) {
sql += "GROUP_NAME = ? "; sql += "WHERE GROUP_NAME = ? ";
} }
sql += "AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?"; sql += "AND AP_APP_RELEASE_ID = ? AND TENANT_ID = ?";
@ -577,20 +594,61 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
} }
@Override @Override
public boolean updateDeviceSubStatus (int operationId, String status, int tenantId) throws ApplicationManagementDAOException { public List<Integer> getDeviceSubIdsForOperation(int operationId, int tenantId)
throws ApplicationManagementDAOException {
Connection conn; Connection conn;
try { try {
conn = this.getDBConnection(); conn = this.getDBConnection();
String sql = "UPDATE AP_DEVICE_SUBSCRIPTION " List<Integer> deviceSubIds = new ArrayList<>();
+ "SET STATUS = ? " String sql = "SELECT "
+ "ID "
+ "FROM AP_APP_SUB_OP_MAPPING "
+ "WHERE " + "WHERE "
+ "AP_APP_RELEASE_ID = (SELECT AP_DEVICE_SUBSCRIPTION_ID FROM AP_APP_SUB_OP_MAPPING WHERE OPERATION_ID = ?) " + "OPERATION_ID = ? AND "
+ "AND TENANT_ID = ?"; + "TENANT_ID = ?";
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, status); stmt.setInt(1, operationId);
stmt.setInt(2, operationId); stmt.setInt(2, tenantId);
stmt.setInt(3, tenantId); try (ResultSet rs = stmt.executeQuery()) {
return stmt.executeUpdate() != 0; 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) { } catch (DBConnectionException e) {
String msg = "Error occurred while obtaining the DB connection to update the subscription status of the " 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.ForbiddenException;
import org.wso2.carbon.device.application.mgt.core.exception.LifeCycleManagementDAOException; 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.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.exception.VisibilityManagementDAOException;
import org.wso2.carbon.device.application.mgt.core.internal.DataHolder; import org.wso2.carbon.device.application.mgt.core.internal.DataHolder;
import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager; import org.wso2.carbon.device.application.mgt.core.lifecycle.LifecycleStateManager;
@ -143,7 +142,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper); ApplicationDTO applicationDTO = APIUtil.convertToAppDTO(applicationWrapper);
ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0); ApplicationReleaseDTO applicationReleaseDTO = applicationDTO.getApplicationReleaseDTOs().get(0);
if (!isValidOsVersions(applicationReleaseDTO.getSupportedOsVersions(), applicationWrapper.getDeviceType())) { if (!isValidOsVersions(applicationReleaseDTO.getSupportedOsVersions(), applicationWrapper.getDeviceType())) {
String msg = "You are trying to create application which has an application release contains invalid or " 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 pagination = new Pagination();
pagination.setCount(applications.size()); pagination.setCount(applicationDAO.getApplicationCount(filter, deviceType.getId(), tenantId));
pagination.setSize(applications.size()); pagination.setSize(applications.size());
pagination.setOffset(filter.getOffset()); pagination.setOffset(filter.getOffset());
pagination.setLimit(filter.getLimit()); pagination.setLimit(filter.getLimit());
@ -820,7 +818,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationById(applicationId, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplication(applicationId, tenantId);
if (applicationDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't find application for the application Id: " + applicationId; String msg = "Couldn't find application for the application Id: " + applicationId;
log.error(msg); log.error(msg);
@ -953,7 +951,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(releaseUuid, tenantId); ApplicationDTO applicationDTO = applicationDAO.getApplication(releaseUuid, tenantId);
if (applicationDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't found an application for application release UUID: " + releaseUuid; String msg = "Couldn't found an application for application release UUID: " + releaseUuid;
@ -1009,7 +1007,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = applicationDAO.getApplicationByUUID(releaseUuid, tenantId); ApplicationDTO applicationDTO = applicationDAO.getApplication(releaseUuid, tenantId);
if (applicationDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't found an application for application release UUID: " + releaseUuid; 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.lifecycleStateDAO.deleteLifecycleStates(deletingAppReleaseIds);
this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds); this.applicationReleaseDAO.deleteReleases(deletingAppReleaseIds);
this.applicationDAO.deleteApplicationTags(applicationId, tenantId); this.applicationDAO.deleteApplicationTags(applicationId, tenantId);
this.applicationDAO.deleteCategoryMapping(applicationId, tenantId); this.applicationDAO.deleteAppCategories(applicationId, tenantId);
this.applicationDAO.deleteApplication(applicationId, tenantId); this.applicationDAO.deleteApplication(applicationId, tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
@ -1401,7 +1399,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
if (applicationDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't found an application which has application release for UUID: " + releaseUuid; String msg = "Couldn't found an application which has application release for UUID: " + releaseUuid;
log.error(msg); log.error(msg);
@ -1616,15 +1614,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
if (!StringUtils.isEmpty(applicationUpdateWrapper.getName())){ if (!StringUtils.isEmpty(applicationUpdateWrapper.getName())){
Filter filter = new Filter(); if (applicationDAO
filter.setFullMatch(true); .isExistingAppName(applicationUpdateWrapper.getName().trim(), applicationDTO.getDeviceTypeId(),
filter.setAppName(applicationUpdateWrapper.getName().trim()); tenantId)) {
filter.setOffset(0);
filter.setLimit(1);
List<ApplicationDTO> applicationList = applicationDAO
.getApplications(filter, applicationDTO.getDeviceTypeId(), tenantId);
if (!applicationList.isEmpty()) {
String msg = "Already an application registered with same name " + applicationUpdateWrapper.getName() String msg = "Already an application registered with same name " + applicationUpdateWrapper.getName()
+ ". Hence you can't update the application name from " + applicationDTO.getName() + " to " + ". Hence you can't update the application name from " + applicationDTO.getName() + " to "
+ applicationUpdateWrapper.getName(); + applicationUpdateWrapper.getName();
@ -1633,29 +1625,29 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
applicationDTO.setName(applicationUpdateWrapper.getName()); applicationDTO.setName(applicationUpdateWrapper.getName());
} }
if (!StringUtils.isEmpty(applicationUpdateWrapper.getSubType()) && !applicationDTO.getSubType() if (!StringUtils.isEmpty(applicationUpdateWrapper.getSubMethod()) && !applicationDTO.getSubType()
.equals(applicationUpdateWrapper.getSubType())) { .equals(applicationUpdateWrapper.getSubMethod())) {
if (!ApplicationSubscriptionType.PAID.toString().equals(applicationUpdateWrapper.getSubType()) if (!ApplicationSubscriptionType.PAID.toString().equals(applicationUpdateWrapper.getSubMethod())
&& !ApplicationSubscriptionType.FREE.toString().equals(applicationUpdateWrapper.getSubType())) { && !ApplicationSubscriptionType.FREE.toString().equals(applicationUpdateWrapper.getSubMethod())) {
String msg = "Invalid application subscription type is found with application updating request " String msg = "Invalid application subscription type is found with application updating request "
+ applicationUpdateWrapper.getSubType(); + applicationUpdateWrapper.getSubMethod();
log.error(msg); log.error(msg);
throw new BadRequestException(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())) { && !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 \"\""; + "currency attribute in the application updating payload should be null or \"\"";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(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()) ){ && StringUtils.isEmpty(applicationUpdateWrapper.getPaymentCurrency()) ){
String msg = "If you are going to change Free app as Non-Free app, " String msg = "If you are going to change Free app as paid app, currency attribute in the application"
+ "currency attribute in the application payload should not be null or \"\""; + " payload should not be null or \"\"";
log.error(msg); log.error(msg);
throw new ApplicationManagementException(msg); throw new ApplicationManagementException(msg);
} }
applicationDTO.setSubType(applicationUpdateWrapper.getSubType()); applicationDTO.setSubType(applicationUpdateWrapper.getSubMethod());
applicationDTO.setPaymentCurrency(applicationUpdateWrapper.getPaymentCurrency()); applicationDTO.setPaymentCurrency(applicationUpdateWrapper.getPaymentCurrency());
} }
@ -1703,33 +1695,37 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
} }
applicationDTO.setUnrestrictedRoles(applicationUpdateWrapper.getUnrestrictedRoles()); applicationDTO.setUnrestrictedRoles(applicationUpdateWrapper.getUnrestrictedRoles());
List<String> updatingAppCategries = applicationUpdateWrapper.getCategories();
if (updatingAppCategries != null){
List<CategoryDTO> allCategories = this.applicationDAO.getAllCategories(tenantId);
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);
}
String updatingAppCategory = applicationUpdateWrapper.getAppCategory();
if ( updatingAppCategory != null){
List<String> appCategories = this.applicationDAO.getAppCategories(applicationId, tenantId); List<String> appCategories = this.applicationDAO.getAppCategories(applicationId, tenantId);
if (!appCategories.contains(updatingAppCategory)){ List<String> addingAppCategories = getDifference(updatingAppCategries, appCategories);
List<CategoryDTO> allCategories = this.applicationDAO.getAllCategories(tenantId); List<String> removingAppCategories = getDifference(appCategories, updatingAppCategries);
List<Integer> categoryIds = allCategories.stream() if (!addingAppCategories.isEmpty()) {
.filter(category -> category.getCategoryName().equals(updatingAppCategory)) List<Integer> categoryIds = this.applicationDAO.getCategoryIdsForCategoryNames(addingAppCategories, tenantId);
.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";
log.error(msg);
throw new BadRequestException(msg);
}
this.applicationDAO.addCategoryMapping(categoryIds, applicationId, 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(); List<String> updatingAppTags = applicationUpdateWrapper.getTags();
if ( updatingAppTags!= null){ if (updatingAppTags!= null){
List<String> appTags = this.applicationDAO.getAppTags(applicationId, tenantId); List<String> appTags = this.applicationDAO.getAppTags(applicationId, tenantId);
List<String> addingTagList = getDifference(appTags, updatingAppTags); List<String> addingTagList = getDifference(updatingAppTags, appTags);
List<String> removingTagList = getDifference(updatingAppTags, appTags); List<String> removingTagList = getDifference(appTags, updatingAppTags);
if (!addingTagList.isEmpty()) { if (!addingTagList.isEmpty()) {
List<TagDTO> allTags = this.applicationDAO.getAllTags(tenantId); List<TagDTO> allTags = this.applicationDAO.getAllTags(tenantId);
List<String> newTags = addingTagList.stream().filter(updatingTagName -> allTags.stream() List<String> newTags = addingTagList.stream().filter(updatingTagName -> allTags.stream()
@ -1743,7 +1739,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
if (!removingTagList.isEmpty()) { if (!removingTagList.isEmpty()) {
List<Integer> removingTagIds = this.applicationDAO.getTagIdsForTagNames(removingTagList, tenantId); List<Integer> removingTagIds = this.applicationDAO.getTagIdsForTagNames(removingTagList, tenantId);
this.applicationDAO.deleteApplicationTags(removingTagIds, applicationId, tenantId); this.applicationDAO.deleteApplicationTags(removingTagIds, applicationId, tenantId);
applicationDAO.deleteTags(removingTagList, applicationId, tenantId);
} }
} }
if (!applicationDAO.updateApplication(applicationDTO, tenantId)){ if (!applicationDAO.updateApplication(applicationDTO, tenantId)){
@ -1857,7 +1852,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
throw new NotFoundException(msg); throw new NotFoundException(msg);
} }
if (applicationDAO.hasTagMapping(tag.getId(), applicationDTO.getId(), tenantId)){ if (applicationDAO.hasTagMapping(tag.getId(), applicationDTO.getId(), tenantId)){
applicationDAO.deleteApplicationTags(tag.getId(), applicationDTO.getId(), tenantId); applicationDAO.deleteApplicationTag(tag.getId(), applicationDTO.getId(), tenantId);
ConnectionManagerUtil.commitDBTransaction(); ConnectionManagerUtil.commitDBTransaction();
} else { } else {
String msg = "Tag " + tagName + " is not an application tag. Application ID: " + appId; String msg = "Tag " + tagName + " is not an application tag. Application ID: " + appId;
@ -2289,13 +2284,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public boolean updateEntAppRelease(String deviceType, String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper, public boolean updateEntAppRelease(String releaseUuid, EntAppReleaseWrapper entAppReleaseWrapper,
ApplicationArtifact applicationArtifact) throws ApplicationManagementException { ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>( AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
applicationDTO.getApplicationReleaseDTOs().get(0)); applicationDTO.getApplicationReleaseDTOs().get(0));
@ -2355,14 +2350,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public boolean updatePubAppRelease(String deviceType, String releaseUuid, public boolean updatePubAppRelease(String releaseUuid, PublicAppReleaseWrapper publicAppReleaseWrapper,
PublicAppReleaseWrapper publicAppReleaseWrapper, ApplicationArtifact applicationArtifact) ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
validateAppReleaseUpdating(applicationDTO, ApplicationType.PUBLIC.toString()); validateAppReleaseUpdating(applicationDTO, ApplicationType.PUBLIC.toString());
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>( AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
applicationDTO.getApplicationReleaseDTOs().get(0)); applicationDTO.getApplicationReleaseDTOs().get(0));
@ -2423,14 +2417,13 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @Override
public boolean updateWebAppRelease(String deviceType, String releaseUuid, public boolean updateWebAppRelease(String releaseUuid, WebAppReleaseWrapper webAppReleaseWrapper,
WebAppReleaseWrapper webAppReleaseWrapper, ApplicationArtifact applicationArtifact) ApplicationArtifact applicationArtifact) throws ApplicationManagementException {
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
validateAppReleaseUpdating(applicationDTO, ApplicationType.WEB_CLIP.toString()); validateAppReleaseUpdating(applicationDTO, ApplicationType.WEB_CLIP.toString());
AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>( AtomicReference<ApplicationReleaseDTO> applicationReleaseDTO = new AtomicReference<>(
applicationDTO.getApplicationReleaseDTOs().get(0)); applicationDTO.getApplicationReleaseDTOs().get(0));
@ -2816,11 +2809,17 @@ public class ApplicationManagerImpl implements ApplicationManager {
} }
@Override @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(); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
try { try {
ConnectionManagerUtil.beginDBTransaction(); 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(); ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Didn't update an any app subscription of device for operation Id: " + operationId; String msg = "Didn't update an any app subscription of device for operation Id: " + operationId;
log.error(msg); log.error(msg);
@ -2850,7 +2849,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
ApplicationDTO applicationDTO = this.applicationDAO.getApplicationByUUID(releaseUuid, tenantId); ApplicationDTO applicationDTO = this.applicationDAO.getApplication(releaseUuid, tenantId);
if (applicationDTO == null) { if (applicationDTO == null) {
String msg = "Couldn't find application for the release UUID: " + releaseUuid; String msg = "Couldn't find application for the release UUID: " + releaseUuid;
log.error(msg); log.error(msg);

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

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

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

@ -412,9 +412,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@PUT @PUT
@Path("/ent-app-release/{deviceType}/{uuid}") @Path("/ent-app-release/{uuid}")
public Response updateEntAppRelease( public Response updateEntAppRelease(
@PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper, @Multipart("applicationRelease") EntAppReleaseWrapper entAppReleaseWrapper,
@Multipart(value = "binaryFile", required = false) Attachment binaryFile, @Multipart(value = "binaryFile", required = false) Attachment binaryFile,
@ -426,31 +425,31 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
if (!applicationManager.updateEntAppRelease(deviceType, applicationUUID, entAppReleaseWrapper, if (!applicationManager.updateEntAppRelease(applicationUUID, entAppReleaseWrapper,
constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) { constructApplicationArtifact(binaryFile, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. " String msg ="Ent app release updating is failed. Please contact the administrator. Application release "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType; + "UUID: " + applicationUUID;
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); 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) { } catch (BadRequestException e) {
String msg = 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); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = 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); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) { } 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; + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) { } 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); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -458,9 +457,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@PUT @PUT
@Path("/public-app-release/{deviceType}/{uuid}") @Path("/public-app-release/{uuid}")
public Response updatePubAppRelease( public Response updatePubAppRelease(
@PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") PublicAppReleaseWrapper publicAppReleaseWrapper, @Multipart("applicationRelease") PublicAppReleaseWrapper publicAppReleaseWrapper,
@Multipart(value = "icon", required = false) Attachment iconFile, @Multipart(value = "icon", required = false) Attachment iconFile,
@ -471,31 +469,30 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
if (!applicationManager.updatePubAppRelease(deviceType, applicationUUID, publicAppReleaseWrapper, if (!applicationManager.updatePubAppRelease(applicationUUID, publicAppReleaseWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) { constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. " String msg ="Public app release updating is failed. Please contact the administrator. "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType; + "Application release UUID: " + applicationUUID + ", Supported device type:";
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); 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) { } catch (BadRequestException e) {
String msg = String msg = "Invalid request to update public app release for application release UUID " + applicationUUID;
"Invalid request to update application release for application release UUID " + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = String msg = "Couldn't found public app or public app release for application release UUID "
"Couldn't found application or application release for application release UUID " + applicationUUID; + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) { } 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; + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) { } 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); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} }
@ -503,9 +500,8 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
@Override @Override
@PUT @PUT
@Path("/web-app-release/{deviceType}/{uuid}") @Path("/web-app-release/{uuid}")
public Response updateWebAppRelease( public Response updateWebAppRelease(
@PathParam("deviceType") String deviceType,
@PathParam("uuid") String applicationUUID, @PathParam("uuid") String applicationUUID,
@Multipart("applicationRelease") WebAppReleaseWrapper webAppReleaseWrapper, @Multipart("applicationRelease") WebAppReleaseWrapper webAppReleaseWrapper,
@Multipart(value = "icon", required = false) Attachment iconFile, @Multipart(value = "icon", required = false) Attachment iconFile,
@ -516,31 +512,29 @@ public class ApplicationManagementPublisherAPIImpl implements ApplicationManagem
ApplicationManager applicationManager = APIUtil.getApplicationManager(); ApplicationManager applicationManager = APIUtil.getApplicationManager();
List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3); List<Attachment> screenshots = constructAttachmentList(screenshot1, screenshot2, screenshot3);
try { try {
if (!applicationManager.updateWebAppRelease(deviceType, applicationUUID, webAppReleaseWrapper, if (!applicationManager.updateWebAppRelease(applicationUUID, webAppReleaseWrapper,
constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) { constructApplicationArtifact(null, iconFile, bannerFile, screenshots))) {
String msg ="Application release updating is failed. Please contact the administrator. " String msg ="web app release updating is failed. Please contact the administrator. Application "
+ "ApplicationDTO release UUID: " + applicationUUID + ", Supported device type: " + deviceType; + "release UUID: " + applicationUUID;
log.error(msg); log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); 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) { } catch (BadRequestException e) {
String msg = String msg = "Invalid request to update web app release for web app release UUID " + applicationUUID;
"Invalid request to update application release for application release UUID " + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = String msg = "Couldn't found web app or web app release for application release UUID " + applicationUUID;
"Couldn't found application or application release for application release UUID " + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (ForbiddenException e) { } 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; + applicationUUID;
log.error(msg, e); log.error(msg, e);
return Response.status(Response.Status.FORBIDDEN).entity(msg).build(); return Response.status(Response.Status.FORBIDDEN).entity(msg).build();
} catch (ApplicationManagementException e) { } 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); log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); 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); private static Log log = LogFactory.getLog(ReviewManagementAdminAPIImpl.class);
//todo remove this API
@Override @Override
@PUT @PUT
@Consumes("application/json") @Consumes("application/json")

@ -23,6 +23,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.application.mgt.common.PaginationResult; 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.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.services.ReviewManager;
import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper; import org.wso2.carbon.device.application.mgt.common.wrapper.ReviewWrapper;
import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException; import org.wso2.carbon.device.application.mgt.core.exception.BadRequestException;
@ -118,8 +119,8 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
@PathParam("uuid") String uuid) { @PathParam("uuid") String uuid) {
ReviewManager reviewManager = APIUtil.getReviewManager(); ReviewManager reviewManager = APIUtil.getReviewManager();
try { try {
boolean isReviewCreated = reviewManager.addReview(reviewWrapper, uuid, false); Review review = reviewManager.addReview(reviewWrapper, uuid, false);
if (isReviewCreated) { if (review != null) {
return Response.status(Response.Status.CREATED).entity(reviewWrapper).build(); return Response.status(Response.Status.CREATED).entity(reviewWrapper).build();
} else { } else {
String msg = "Review adding is failed. Please contact the administrator."; 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, STATUS VARCHAR(45) NOT NULL,
DM_DEVICE_ID INTEGER NOT NULL, DM_DEVICE_ID INTEGER NOT NULL,
AP_APP_RELEASE_ID INTEGER NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL,
AP_APP_ID INTEGER NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1 CONSTRAINT fk_AP_DEVICE_SUBSCRIPTION_AP_APP_RELEASE1
FOREIGN KEY (AP_APP_RELEASE_ID) FOREIGN KEY (AP_APP_RELEASE_ID)
@ -136,7 +135,6 @@ CREATE TABLE IF NOT EXISTS AP_GROUP_SUBSCRIPTION(
UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL,
GROUP_NAME VARCHAR(100) NOT NULL, GROUP_NAME VARCHAR(100) NOT NULL,
AP_APP_RELEASE_ID INTEGER NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL,
AP_APP_ID INTEGER NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_AP_GROUP_SUBSCRIPTION_AP_APP_RELEASE1 CONSTRAINT fk_AP_GROUP_SUBSCRIPTION_AP_APP_RELEASE1
FOREIGN KEY (AP_APP_RELEASE_ID) 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_BY VARCHAR(100) NULL DEFAULT NULL,
UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL,
AP_APP_RELEASE_ID INTEGER NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL,
AP_APP_ID INTEGER NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_AP_ROLE_SUBSCRIPTION_AP_APP_RELEASE1 CONSTRAINT fk_AP_ROLE_SUBSCRIPTION_AP_APP_RELEASE1
FOREIGN KEY (AP_APP_RELEASE_ID) 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_BY VARCHAR(100) NULL DEFAULT NULL,
UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, UNSUBSCRIBED_TIMESTAMP TIMESTAMP NULL DEFAULT NULL,
AP_APP_RELEASE_ID INTEGER NOT NULL, AP_APP_RELEASE_ID INTEGER NOT NULL,
AP_APP_ID INTEGER NOT NULL,
PRIMARY KEY (ID), PRIMARY KEY (ID),
CONSTRAINT fk_AP_USER_SUBSCRIPTION_AP_APP_RELEASE1 CONSTRAINT fk_AP_USER_SUBSCRIPTION_AP_APP_RELEASE1
FOREIGN KEY (AP_APP_RELEASE_ID) FOREIGN KEY (AP_APP_RELEASE_ID)

Loading…
Cancel
Save