Format APPM source

feature/appm-store/pbac
lasanthaDLPDS 5 years ago
parent 1f175bc1c4
commit 7296e38608

@ -68,7 +68,7 @@ public class Filter {
/** /**
* Category list of the application * Category list of the application
*/ */
private List<String> appCategories; private List<String> categories;
/** /**
* Tag list of the application * Tag list of the application
@ -155,12 +155,12 @@ public class Filter {
this.appType = appType; this.appType = appType;
} }
public List<String> getAppCategories() { public List<String> getCategories() {
return appCategories; return categories;
} }
public void setAppCategories(List<String> appCategories) { public void setCategories(List<String> categories) {
this.appCategories = appCategories; this.categories = categories;
} }
public List<String> getTags() { return tags; } public List<String> getTags() { return tags; }

@ -134,14 +134,6 @@ public interface ApplicationDAO {
*/ */
ApplicationDTO getApplication(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
* unique for an application. * unique for an application.

@ -66,7 +66,7 @@ public interface ApplicationReleaseDAO {
* @param tenantId Tenant Id * @param tenantId Tenant Id
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception. * @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/ */
Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException; Rating getReleaseRating(String uuid, int tenantId) throws ApplicationManagementDAOException;
List<Double> getReleaseRatings(String uuid, int tenantId) throws ApplicationManagementDAOException; List<Double> getReleaseRatings(String uuid, int tenantId) throws ApplicationManagementDAOException;
@ -101,14 +101,6 @@ public interface ApplicationReleaseDAO {
*/ */
String getPackageName(String releaseUuid, int tenantId) throws ApplicationManagementDAOException; String getPackageName(String releaseUuid, int tenantId) throws ApplicationManagementDAOException;
/**
* To verify whether application release exist or not for given application release uuid.
*
* @param uuid UUID of the application release.
* @param tenantId Tenant Id
* @throws ApplicationManagementDAOException Application Management DAO Exception.
*/
boolean isReleaseExist(String uuid, int tenantId) throws ApplicationManagementDAOException;
String getReleaseHashValue(String uuid, int tenantId) throws ApplicationManagementDAOException; String getReleaseHashValue(String uuid, int tenantId) throws ApplicationManagementDAOException;

@ -236,41 +236,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
} }
@Override
public String getUuidOfLatestRelease(int appId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Getting UUID from the latest app release");
}
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String sql = "";
String uuId = null;
try {
conn = this.getDBConnection();
sql += "SELECT APP_RELEASE.UUID AS UUID FROM AP_APP_RELEASE AS APP_RELEASE, AP_APP_LIFECYCLE_STATE "
+ "AS LIFECYCLE WHERE APP_RELEASE.AP_APP_ID=? AND APP_RELEASE.ID = LIFECYCLE.AP_APP_RELEASE_ID "
+ "AND LIFECYCLE.CURRENT_STATE = ? ORDER BY APP_RELEASE.ID DESC;";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, appId);
stmt.setString(2, AppLifecycleState.PUBLISHED.toString());
rs = stmt.executeQuery();
if (rs.next()) {
uuId = rs.getString("UUID");
}
return uuId;
} catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting uuid of latest app release", e);
} catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection for "
+ "getting app release id", e);
} finally {
DAOUtil.cleanupResources(stmt, rs);
}
}
@Override @Override
public int getApplicationCount(Filter filter,int deviceTypeId, int tenantId) throws ApplicationManagementDAOException { public int getApplicationCount(Filter filter,int deviceTypeId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
@ -372,16 +337,10 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
@Override @Override
public ApplicationDTO getApplication(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");
} }
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
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, "
@ -418,29 +377,33 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "WHERE " + "WHERE "
+ "AP_APP.ID = (SELECT AP_APP_RELEASE.AP_APP_ID FROM AP_APP_RELEASE WHERE AP_APP_RELEASE.UUID = ?) " + "AP_APP.ID = (SELECT AP_APP_RELEASE.AP_APP_ID FROM AP_APP_RELEASE WHERE AP_APP_RELEASE.UUID = ?) "
+ "AND AP_APP.TENANT_ID = ?"; + "AND AP_APP.TENANT_ID = ?";
try {
stmt = conn.prepareStatement(sql); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){
stmt.setString(1, releaseUuid); stmt.setString(1, releaseUuid);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
rs = stmt.executeQuery(); try (ResultSet rs = stmt.executeQuery()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application for the application release UUID: " log.debug("Successfully retrieved basic details of the application for the application "
+ releaseUuid); + "release UUID: " + releaseUuid);
} }
return DAOUtil.loadApplication(rs); return DAOUtil.loadApplication(rs);
}
} catch (SQLException e) { }
throw new ApplicationManagementDAOException(
"Error occurred while getting application details with app release uuid " + releaseUuid +
" while executing query.", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); String msg = "Error occurred while obtaining the DB connection to get application for application release "
+ "UUID: " + releaseUuid;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while getting application details with app release uuid " + releaseUuid
+ " while executing query. Executed query: " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (UnexpectedServerErrorException e) { } catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); String msg = "Found more than one application for application release UUID: " + releaseUuid;
} finally { log.error(msg);
DAOUtil.cleanupResources(stmt, rs); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -450,11 +413,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
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");
} }
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
conn = this.getDBConnection();
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, "
@ -491,37 +449,39 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
+ "WHERE " + "WHERE "
+ "AP_APP.ID =? AND " + "AP_APP.ID =? AND "
+ "AP_APP.TENANT_ID = ?"; + "AP_APP.TENANT_ID = ?";
try {
stmt = conn.prepareStatement(sql); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, applicationId); stmt.setInt(1, applicationId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
rs = stmt.executeQuery(); try (ResultSet rs = stmt.executeQuery()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application with the id " log.debug("Successfully retrieved basic details of the application with the id "
+ applicationId); + applicationId);
} }
return DAOUtil.loadApplication(rs); return DAOUtil.loadApplication(rs);
} catch (SQLException e) { }
throw new ApplicationManagementDAOException( }
"Error occurred while getting application details with app id " + applicationId +
" 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); String msg = "Error occurred while obtaining the DB connection to get application for application ID: "
+ applicationId;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred to get application details with app id " + applicationId + " while executing "
+ "query. Query: " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (UnexpectedServerErrorException e) { } catch (UnexpectedServerErrorException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); String msg = "Found more than one application for application ID: " + applicationId;
} finally { log.error(msg);
DAOUtil.cleanupResources(stmt, rs); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override @Override
public boolean updateApplication(ApplicationDTO applicationDTO, int tenantId) public boolean updateApplication(ApplicationDTO applicationDTO, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection conn;
try {
conn = this.getDBConnection();
String sql = "UPDATE AP_APP AP " + String sql = "UPDATE AP_APP AP " +
"SET " + "SET " +
"AP.NAME = ?, " + "AP.NAME = ?, " +
@ -529,7 +489,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
"AP.SUB_TYPE = ?, " + "AP.SUB_TYPE = ?, " +
"AP.CURRENCY = ? " + "AP.CURRENCY = ? " +
"WHERE AP.ID = ? AND AP.TENANT_ID = ?"; "WHERE AP.ID = ? AND AP.TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, applicationDTO.getName()); stmt.setString(1, applicationDTO.getName());
stmt.setString(2, applicationDTO.getDescription()); stmt.setString(2, applicationDTO.getDescription());
@ -544,7 +505,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
log.error(msg); log.error(msg);
throw new ApplicationManagementDAOException(msg, e); throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
String msg = "Error occurred when obtaining database connection for updating the application."; String msg = "Error occurred when executing SQL to update an application. Executed query: " + sql;
log.error(msg); log.error(msg);
throw new ApplicationManagementDAOException(msg, e); throw new ApplicationManagementDAOException(msg, e);
} }
@ -553,16 +514,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override @Override
public void updateApplicationRating(String uuid, double rating, int tenantId) public void updateApplicationRating(String uuid, double rating, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection conn;
try {
conn = this.getDBConnection();
String sql = "UPDATE AP_APP AP " + String sql = "UPDATE AP_APP AP " +
"SET " + "SET " +
"AP.RATING = ? " + "AP.RATING = ? " +
"WHERE " + "WHERE " +
"AP.ID = (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID = ?) AND " + "AP.ID = (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID = ?) AND " +
"AP.TENANT_ID = ?"; "AP.TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setDouble(1, rating); stmt.setDouble(1, rating);
stmt.setString(2, uuid); stmt.setString(2, uuid);
@ -583,22 +542,27 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
@Override @Override
public void retireApplication(int appId) throws ApplicationManagementDAOException { public void retireApplication(int appId) throws ApplicationManagementDAOException {
Connection conn; String sql = "UPDATE "
PreparedStatement stmt = null; + "AP_APP "
+ "SET STATUS = ? "
+ "WHERE ID = ? ";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
String sql = "UPDATE AP_APP SET STATUS = ? WHERE ID = ? "; try (PreparedStatement stmt = conn.prepareStatement(sql)){
stmt = conn.prepareStatement(sql);
stmt.setString(1, AppLifecycleState.RETIRED.toString()); stmt.setString(1, AppLifecycleState.RETIRED.toString());
stmt.setInt(2, appId); stmt.setInt(2, appId);
stmt.executeUpdate(); stmt.executeUpdate();
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); String msg = "Error occurred while obtaining the DB connection to retire application which has application "
+ "ID: " + appId;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while deleting the application: ", e); String msg = "Error occurred while executing SQL to retire an application which has application ID "
} finally { + appId;
DAOUtil.cleanupResources(stmt, null); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -607,29 +571,28 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add tags"); log.debug("Request received in DAO Layer to add tags");
} }
Connection conn;
PreparedStatement stmt = null;
String sql = "INSERT INTO AP_APP_TAG " String sql = "INSERT INTO AP_APP_TAG "
+ "(TAG," + "(TAG, "
+ " TENANT_ID) " + " TENANT_ID) "
+ "VALUES (?, ?)"; + "VALUES (?, ?)";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
stmt = conn.prepareStatement(sql); try (PreparedStatement stmt = conn.prepareStatement(sql)) {
for (String tag : tags) { for (String tag : tags) {
stmt.setString(1, tag); stmt.setString(1, tag);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.addBatch(); stmt.addBatch();
} }
stmt.executeBatch(); stmt.executeBatch();
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when adding tags";
"Error occurred while obtaining the DB connection when adding tags", e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding tags", e); String msg = "SQL Error occurred while adding tags. Executed Query: " + sql;
} finally { log.error(msg);
DAOUtil.cleanupResources(stmt, null); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -638,72 +601,70 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get all tags"); log.debug("Request received in DAO Layer to get all tags");
} }
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
List<TagDTO> tagEntities = new ArrayList<>();
String sql = "SELECT " String sql = "SELECT "
+ "AP_APP_TAG.ID AS ID, " + "AP_APP_TAG.ID AS ID, "
+ "AP_APP_TAG.TAG AS TAG " + "AP_APP_TAG.TAG AS TAG "
+ "FROM AP_APP_TAG " + "FROM AP_APP_TAG "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
conn = this.getDBConnection(); try {
stmt = conn.prepareStatement(sql); List<TagDTO> tagEntities = new ArrayList<>();
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
rs = stmt.executeQuery(); try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
while(rs.next()){
TagDTO tagDTO = new TagDTO(); TagDTO tagDTO = new TagDTO();
tagDTO.setId(rs.getInt("ID")); tagDTO.setId(rs.getInt("ID"));
tagDTO.setTagName(rs.getString("TAG")); tagDTO.setTagName(rs.getString("TAG"));
tagEntities.add(tagDTO); tagEntities.add(tagDTO);
} }
return tagEntities; return tagEntities;
}
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when getting all tags";
"Error occurred while obtaining the DB connection when adding tags", e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding tags", e); String msg = "SQL Error occurred while getting all tags";
} finally { log.error(msg);
DAOUtil.cleanupResources(stmt, rs); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override @Override
public List<CategoryDTO> getAllCategories(int tenantId) throws ApplicationManagementDAOException { public List<CategoryDTO> getAllCategories(int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get all tags"); log.debug("Request received in DAO Layer to get all categories.");
} }
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
List<CategoryDTO> categories = new ArrayList<>();
String sql = "SELECT " String sql = "SELECT "
+ "AP_APP_CATEGORY.ID AS ID, " + "AP_APP_CATEGORY.ID AS ID, "
+ "AP_APP_CATEGORY.CATEGORY AS CATEGORY " + "AP_APP_CATEGORY.CATEGORY AS CATEGORY "
+ "FROM AP_APP_CATEGORY " + "FROM AP_APP_CATEGORY "
+ "WHERE TENANT_ID = ?"; + "WHERE TENANT_ID = ?";
conn = this.getDBConnection(); try {
stmt = conn.prepareStatement(sql); List<CategoryDTO> categories = new ArrayList<>();
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId); stmt.setInt(1, tenantId);
rs = stmt.executeQuery(); try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
while(rs.next()){
CategoryDTO category = new CategoryDTO(); CategoryDTO category = new CategoryDTO();
category.setId(rs.getInt("ID")); category.setId(rs.getInt("ID"));
category.setCategoryName(rs.getString("CATEGORY")); category.setCategoryName(rs.getString("CATEGORY"));
categories.add(category); categories.add(category);
} }
return categories; return categories;
}
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when getting all categories.";
"Error occurred while obtaining the DB connection when getting categories", e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting categories", e); String msg = "SQL Error occurred while getting all categories. Executed query: " + sql;
} finally { log.error(msg);
DAOUtil.cleanupResources(stmt, rs); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -711,14 +672,15 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
public List<Integer> getCategoryIdsForCategoryNames(List<String> categoryNames, int tenantId) public List<Integer> getCategoryIdsForCategoryNames(List<String> categoryNames, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get tag ids for given tag names"); log.debug("Request received in DAO Layer to get category ids for given category names");
} }
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
int index = 1; int index = 1;
List<Integer> tagIds = new ArrayList<>(); List<Integer> tagIds = new ArrayList<>();
StringJoiner joiner = new StringJoiner(",", StringJoiner joiner = new StringJoiner(",",
"SELECT AP_APP_CATEGORY.ID AS ID FROM AP_APP_CATEGORY WHERE AP_APP_CATEGORY.CATEGORY IN (", ") AND TENANT_ID = ?"); "SELECT AP_APP_CATEGORY.ID AS ID FROM AP_APP_CATEGORY WHERE AP_APP_CATEGORY.CATEGORY IN (",
") AND TENANT_ID = ?");
categoryNames.stream().map(ignored -> "?").forEach(joiner::add); categoryNames.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)) {
@ -734,17 +696,21 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
return tagIds; return tagIds;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when getting category ids for given "
"Error occurred while obtaining the DB connection when getting categories", e); + "category names";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while getting categories", e); String msg = "SQL Error occurred while getting all categories.";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override @Override
public List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException { public List<Integer> getDistinctCategoryIdsInCategoryMapping() throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get distinct category ids for given tag names"); log.debug("Request received in DAO Layer to get distinct category ids in category mapping.");
} }
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
@ -759,12 +725,14 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
return distinctCategoryIds; return distinctCategoryIds;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when getting distinct category ids in "
"Error occurred while obtaining the DB connection when getting distinct category ids in tag mapping", + "category mapping";
e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "SQL Error occurred while getting distinct category ids in category mapping.";
"Error occurred while getting distinct category ids in tag mapping", e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -773,12 +741,12 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get category for given category name."); log.debug("Request received in DAO Layer to get category for given category name.");
} }
try { String sql = "SELECT AP_APP_CATEGORY.ID AS ID "
Connection conn = this.getDBConnection(); + "FROM AP_APP_CATEGORY "
String sql = "SELECT AP_APP_CATEGORY.ID AS ID"
+ " FROM AP_APP_CATEGORY "
+ "WHERE AP_APP_CATEGORY.CATEGORY = ? AND " + "WHERE AP_APP_CATEGORY.CATEGORY = ? AND "
+ "AP_APP_CATEGORY.TENANT_ID = ?"; + "AP_APP_CATEGORY.TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement ps = conn.prepareStatement(sql)) { try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setString(1, categoryName); ps.setString(1, categoryName);
ps.setInt(2, tenantId); ps.setInt(2, tenantId);
@ -789,65 +757,65 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
categoryDTO.setCategoryName(categoryName); categoryDTO.setCategoryName(categoryName);
return categoryDTO; return categoryDTO;
} }
return null;
} }
} }
return null;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when getting category for given category "
"Error occurred while obtaining the DB connection when getting category Id for given category name", + "name.";
e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "SQL Error occurred while getting category for category name. Executed query " + sql;
"SQL Error occurred while getting category Id for category name.", e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override @Override
public void addCategories(List<String> categories, int tenantId) throws ApplicationManagementDAOException { public void addCategories(List<String> categories, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add tags"); log.debug("DAO Request received in DAO Layer to add categories.");
} }
Connection conn;
PreparedStatement stmt = null;
String sql = "INSERT INTO AP_APP_CATEGORY " String sql = "INSERT INTO AP_APP_CATEGORY "
+ "(CATEGORY," + "(CATEGORY,"
+ " TENANT_ID) " + " TENANT_ID) "
+ "VALUES (?, ?)"; + "VALUES (?, ?)";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
stmt = conn.prepareStatement(sql); try (PreparedStatement stmt = conn.prepareStatement(sql)) {
for (String category : categories) { for (String category : categories) {
stmt.setString(1, category); stmt.setString(1, category);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.addBatch(); stmt.addBatch();
} }
stmt.executeBatch(); stmt.executeBatch();
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when adding categories.";
"Error occurred while obtaining the DB connection when adding categories.", e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding categories.", e); String msg = "SQL Error occurred while adding categories. Executed query " + sql;
} finally { log.error(msg);
DAOUtil.cleanupResources(stmt, null); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override @Override
public void addCategoryMapping (List<Integer> categoryIds, int applicationId, int tenantId) throws ApplicationManagementDAOException { public void addCategoryMapping(List<Integer> categoryIds, int applicationId, int tenantId)
throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to add categories"); log.debug("Request received in DAO Layer to add category mappings");
} }
Connection conn;
PreparedStatement stmt = null;
String sql = "INSERT INTO AP_APP_CATEGORY_MAPPING " String sql = "INSERT INTO AP_APP_CATEGORY_MAPPING "
+ "(AP_APP_CATEGORY_ID, " + "(AP_APP_CATEGORY_ID, "
+ "AP_APP_ID, " + "AP_APP_ID, "
+ " TENANT_ID) " + " TENANT_ID) "
+ "VALUES (?, ?, ?)"; + "VALUES (?, ?, ?)";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
stmt = conn.prepareStatement(sql); try (PreparedStatement stmt = conn.prepareStatement(sql)) {
for (Integer categoryId : categoryIds) { for (Integer categoryId : categoryIds) {
stmt.setInt(1, categoryId); stmt.setInt(1, categoryId);
stmt.setInt(2, applicationId); stmt.setInt(2, applicationId);
@ -855,14 +823,15 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.addBatch(); stmt.addBatch();
} }
stmt.executeBatch(); stmt.executeBatch();
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when adding data into category mapping.";
"Error occurred while obtaining the DB connection when adding data into category mapping.", e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred while adding data into category mapping.", e); String msg = "SQL Error occurred while adding data into category mapping.";
} finally { log.error(msg);
DAOUtil.cleanupResources(stmt, null); throw new ApplicationManagementDAOException(msg, e);
} }
} }

@ -191,43 +191,42 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
@Override @Override
public Rating getRating(String uuid, int tenantId) throws ApplicationManagementDAOException { public Rating getReleaseRating(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
ResultSet resultSet = null;
Rating rating = null;
String sql = "SELECT " String sql = "SELECT "
+ "RATING, " + "RATING, "
+ "RATED_USERS " + "RATED_USERS "
+ "FROM AP_APP_RELEASE " + "FROM AP_APP_RELEASE "
+ "WHERE UUID = ? AND TENANT_ID = ?"; + "WHERE UUID = ? AND TENANT_ID = ?";
try { try {
connection = this.getDBConnection(); Connection connection = this.getDBConnection();
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);
resultSet = statement.executeQuery(); try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) { if (resultSet.next()) {
rating = new Rating(); Rating rating = new Rating();
rating.setRatingValue(resultSet.getDouble("RATING")); rating.setRatingValue(resultSet.getDouble("RATING"));
rating.setNoOfUsers(resultSet.getInt("RATED_USERS")); rating.setNoOfUsers(resultSet.getInt("RATED_USERS"));
}
return rating; return rating;
}
}
}
return null;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Database connection error occured when try to get application release rating which has "
"Database connection exception while trying to update the application release", e); + "application release UUID: " + uuid;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "SQL exception occured whn processing query: " + sql + " to get application release rating "
"SQL exception while updating the release ,while executing the query " + sql, e); + "which has application release uuid: " + uuid;
} finally { log.error(msg);
DAOUtil.cleanupResources(statement, resultSet); throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override @Override
public List<Double> getReleaseRatings(String uuid, int tenantId) throws ApplicationManagementDAOException { public List<Double> getReleaseRatings(String uuid, int tenantId) throws ApplicationManagementDAOException {
Connection connection;
List<Double> ratingValues = new ArrayList<>(); List<Double> ratingValues = new ArrayList<>();
String sql = "SELECT " String sql = "SELECT "
+ "RATING " + "RATING "
@ -236,7 +235,7 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
+ "AP_APP_ID = (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID = ?) AND " + "AP_APP_ID = (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID = ?) AND "
+ "TENANT_ID = ?"; + "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);
@ -247,26 +246,21 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
} }
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Database connection exception occurred when getting all release rating values for a "
"Database connection exception while trying to update the application release", e); + "particular application.";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "SQL exception occurred while getting all release rating values for a particular application. "
"SQL exception while updating the release ,while executing the query " + sql, e); + "Executed query is" + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
/**
* To insert the application release properties.
*
* @param applicationReleaseDTO ApplicationDTO Release the properties of which that need to be inserted.
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
*/
@Override @Override
public ApplicationReleaseDTO updateRelease(ApplicationReleaseDTO applicationReleaseDTO, int tenantId) public ApplicationReleaseDTO updateRelease(ApplicationReleaseDTO applicationReleaseDTO, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "UPDATE AP_APP_RELEASE " String sql = "UPDATE AP_APP_RELEASE "
+ "SET " + "SET "
+ "DESCRIPTION = ?, " + "DESCRIPTION = ?, "
@ -288,8 +282,8 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
+ "CURRENT_STATE = ? " + "CURRENT_STATE = ? "
+ "WHERE ID = ? AND TENANT_ID = ? "; + "WHERE ID = ? AND TENANT_ID = ? ";
try { try {
connection = this.getDBConnection(); Connection connection = this.getDBConnection();
statement = connection.prepareStatement(sql); try (PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setString(1, applicationReleaseDTO.getDescription()); statement.setString(1, applicationReleaseDTO.getDescription());
statement.setString(2, applicationReleaseDTO.getVersion()); statement.setString(2, applicationReleaseDTO.getVersion());
statement.setString(3, applicationReleaseDTO.getUuid()); statement.setString(3, applicationReleaseDTO.getUuid());
@ -312,63 +306,69 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
if (statement.executeUpdate() == 0) { if (statement.executeUpdate() == 0) {
return null; return null;
} }
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Database connection exception occured while trying to update the application release which "
"Database connection exception while trying to update the application release", e); + "has application release ID: " + applicationReleaseDTO.getId();
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 application release which has release ID: "
"SQL exception while updating the release ,while executing the query " + sql, e); + applicationReleaseDTO.getId() + ". Executed query is " + sql;
} finally { log.error(msg);
DAOUtil.cleanupResources(statement, null); throw new ApplicationManagementDAOException(msg, e);
} }
return applicationReleaseDTO; return applicationReleaseDTO;
} }
@Override @Override
public void deleteRelease(int id) throws ApplicationManagementDAOException { public void deleteRelease(int id) throws ApplicationManagementDAOException {
Connection connection;
PreparedStatement statement = null;
String sql = "DELETE " String sql = "DELETE "
+ "FROM AP_APP_RELEASE " + "FROM AP_APP_RELEASE "
+ "WHERE ID = ?"; + "WHERE ID = ?";
try { try {
connection = this.getDBConnection(); Connection connection = this.getDBConnection();
statement = connection.prepareStatement(sql); try (PreparedStatement statement = connection.prepareStatement(sql)) {
statement.setInt(1, id); statement.setInt(1, id);
statement.executeUpdate(); statement.executeUpdate();
}
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Database connection exception occurred while trying to delete the application release which "
"Database connection exception while trying to delete the release fore release ID: " + id, e); + "has ID: " + id;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "SQL exception occurred while deleting the release for release ID: " + id + ",while executing"
"SQL exception while deleting the release for release ID: " + id + ",while executing the query sql" + " the query sql " + sql;
, e); log.error(msg);
} finally { throw new ApplicationManagementDAOException(msg, e);
DAOUtil.cleanupResources(statement, null);
} }
} }
@Override @Override
public void deleteReleases(List<Integer> applicationReleaseIds) throws ApplicationManagementDAOException{ public void deleteReleases(List<Integer> applicationReleaseIds) throws ApplicationManagementDAOException{
Connection connection;
String sql = "DELETE " String sql = "DELETE "
+ "FROM AP_APP_RELEASE " + "FROM AP_APP_RELEASE "
+ "WHERE ID = ?"; + "WHERE ID = ?";
try { try {
connection = this.getDBConnection(); Connection connection = this.getDBConnection();
try (PreparedStatement statement = connection.prepareStatement(sql)){ try (PreparedStatement statement = connection.prepareStatement(sql)) {
for (Integer releaseId : applicationReleaseIds){ for (Integer releaseId : applicationReleaseIds) {
statement.setInt(1, releaseId); statement.setInt(1, releaseId);
statement.addBatch(); statement.addBatch();
} }
statement.executeBatch(); statement.executeBatch();
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Database connection exception occurred while trying to delete application releases for given "
"Database connection exception occurred while trying to delete given application release", e); + "application release ids";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "SQL exception occurred while execute delete query for deleting given application releases. "
"SQL exception occurred while execute delete query for deleting given application releases.", e); + "Executed query: " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -378,27 +378,30 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Verifying application release existence by application hash value: " + hashVal); log.debug("Verifying application release existence by application hash value: " + hashVal);
} }
Connection conn; String sql = "SELECT "
PreparedStatement stmt = null; + "AR.ID AS RELEASE_ID "
ResultSet rs = null; + "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.APP_HASH_VALUE = ? AND "
+ "AR.TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
String sql = "SELECT AR.ID AS RELEASE_ID FROM AP_APP_RELEASE AS AR WHERE AR.APP_HASH_VALUE = ? AND " try (PreparedStatement stmt = conn.prepareStatement(sql)) {
+ "AR.TENANT_ID = ?;";
stmt = conn.prepareStatement(sql);
stmt.setString(1, hashVal); stmt.setString(1, hashVal);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
rs = stmt.executeQuery(); try (ResultSet rs = stmt.executeQuery()) {
return rs.next(); return rs.next();
} catch (SQLException e) { }
throw new ApplicationManagementDAOException( }
"Error occurred while getting application release details for application release hash value: "
+ hashVal + " While executing query ", e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); String msg = "Database connection error occurred while verifying release existence for app release hash "
} finally { + "value. Hash value: " + hashVal;
DAOUtil.cleanupResources(stmt, rs); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while getting application release details for application release hash value: "
+ hashVal + " While executing query ";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -407,69 +410,37 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting package name of the application release by application id:" + releaseUuid); log.debug("Getting package name of the application release by application id:" + releaseUuid);
} }
Connection conn;
try {
conn = this.getDBConnection();
String sql = "SELECT " String sql = "SELECT "
+ "AR.PACKAGE_NAME AS PACKAGE_NAME " + "AR.PACKAGE_NAME AS PACKAGE_NAME "
+ "FROM AP_APP_RELEASE AS AR " + "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.UUID = ? " + "WHERE AR.UUID = ? "
+ "AND AR.TENANT_ID = ?"; + "AND AR.TENANT_ID = ?";
try {
try (PreparedStatement stmt = conn.prepareStatement(sql)){ Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, releaseUuid); stmt.setString(1, releaseUuid);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
try (ResultSet rs = stmt.executeQuery()){ try (ResultSet rs = stmt.executeQuery()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Successfully retrieved package name of the application release with the UUID: " log.debug("Successfully retrieved package name of the application release with the UUID: "
+ releaseUuid); + releaseUuid);
} }
if (rs.next()){ if (rs.next()) {
return rs.getString("PACKAGE_NAME"); return rs.getString("PACKAGE_NAME");
} }
return null; return null;
} }
} }
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while getting package name of the application release with app ID: " + releaseUuid, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection to get application release package name "
"Error occurred while obtaining the DB connection to get application release package name.", e); + "which has application release UUID: " + releaseUuid;
} log.error(msg);
} throw new ApplicationManagementDAOException(msg, e);
@Override
public boolean isReleaseExist(String uuid, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Verifying application release existence by 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.UUID = ? AND AR.TENANT_ID = ?;";
stmt = conn.prepareStatement(sql);
stmt.setString(1, uuid);
stmt.setInt(2, tenantId);
rs = stmt.executeQuery();
if (log.isDebugEnabled()) {
log.debug("Successfully retrieved basic details of the application release with the application UUID: "
+ uuid);
}
return rs.next();
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while getting package name of the application release with app UUID: "
"Error occurred when executing query to get application release details for App release uuid: " + releaseUuid;
+ uuid, e); log.error(msg);
} catch (DBConnectionException e) { throw new ApplicationManagementDAOException(msg, e);
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e);
} finally {
DAOUtil.cleanupResources(stmt, rs);
} }
} }
@ -478,45 +449,36 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Getting application release artifact stored location paths for: " + uuid); log.debug("Getting application release artifact stored location paths for: " + uuid);
} }
Connection conn;
PreparedStatement stmt = null;
ResultSet rs = null;
String releaseHashValue = null;
try {
conn = this.getDBConnection();
String sql = "SELECT " String sql = "SELECT "
+ "AR.APP_HASH_VALUE AS HASH_VALUE " + "AR.APP_HASH_VALUE AS HASH_VALUE "
+ "FROM AP_APP_RELEASE AR " + "FROM AP_APP_RELEASE AR "
+ "WHERE AR.UUID = ? AND AR.TENANT_ID = ?;"; + "WHERE AR.UUID = ? AND AR.TENANT_ID = ?";
try {
stmt = conn.prepareStatement(sql); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){
stmt.setString(1, uuid); stmt.setString(1, uuid);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
rs = stmt.executeQuery(); try (ResultSet rs = stmt.executeQuery()){
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug( log.debug("Successfully retrieved application release hash value for application release "
"Successfully retrieved application release artifact details of the application release with the application UUID: " + "which has release UUID: " + uuid);
+ uuid);
} }
if(rs.next()){
if (rs.getFetchSize() >1){ return rs.getString("HASH_VALUE");
String msg = "Found more than one application release for UUID: " + uuid; }
log.error(msg); return null;
throw new ApplicationManagementDAOException(msg);
} }
while(rs.next()){
releaseHashValue = rs.getString("HASH_VALUE");
} }
return releaseHashValue;
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred when executing query to get application release artifact paths for App release uuid: "
+ uuid, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); String msg = "Error occurred while obtaining the DB connection to get hash value for application release "
} finally { + "which has application release UUID: " + uuid;
DAOUtil.cleanupResources(stmt, rs); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred when executing query to get application release hash value which has "
+ "application release uuid: " + uuid + ". Executed query: " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -526,13 +488,13 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Verifying application release existence for package name:" + packageName); log.debug("Verifying application release existence for package name:" + packageName);
} }
Connection conn;
try {
conn = this.getDBConnection();
String sql = "SELECT AR.ID AS RELEASE_ID " String sql = "SELECT AR.ID AS RELEASE_ID "
+ "FROM AP_APP_RELEASE AS AR " + "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.PACKAGE_NAME = ? AND AR.CURRENT_STATE != ? AND AR.TENANT_ID = ? LIMIT 1"; + "WHERE AR.PACKAGE_NAME = ? AND "
+ "AR.CURRENT_STATE != ? AND "
+ "AR.TENANT_ID = ? LIMIT 1";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, packageName); stmt.setString(1, packageName);
stmt.setString(2, inactiveState); stmt.setString(2, inactiveState);
@ -541,11 +503,16 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
return rs.next(); return rs.next();
} }
} }
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while getting application release details for package name: " + packageName, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException("Error occurred while obtaining the DB connection.", e); String msg = "Error occurred while obtaining the DB connection to verify the existence of package name for "
+ "active application release. Package name: " + packageName;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "SQL error occurred while verifying the existence of package name for active application "
+ "release. package name: " + packageName;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -555,15 +522,13 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Verifying application release existence in the installable state: :" + installableStateName); log.debug("Verifying application release existence in the installable state: :" + installableStateName);
} }
Connection conn;
try {
conn = this.getDBConnection();
String sql = "SELECT AR.ID AS RELEASE_ID " String sql = "SELECT AR.ID AS RELEASE_ID "
+ "FROM AP_APP_RELEASE AS AR " + "FROM AP_APP_RELEASE AS AR "
+ "WHERE AR.CURRENT_STATE = ? AND " + "WHERE AR.CURRENT_STATE = ? AND "
+ "AR.AP_APP_ID = (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID = ?) AND " + "AR.AP_APP_ID = (SELECT AP_APP_ID FROM AP_APP_RELEASE WHERE UUID = ?) AND "
+ "AR.TENANT_ID = ?"; + "AR.TENANT_ID = ?";
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, installableStateName); stmt.setString(1, installableStateName);
stmt.setString(2, releaseUuid); stmt.setString(2, releaseUuid);
@ -572,15 +537,17 @@ public class GenericApplicationReleaseDAOImpl extends AbstractDAOImpl implements
return rs.next(); return rs.next();
} }
} }
} catch (SQLException e) {
throw new ApplicationManagementDAOException(
"Error occurred while getting application release details in installable state: "
+ installableStateName, e);
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection to verify the existence of app release for "
"Error occurred while obtaining the DB connection to get application release data in installable " + "application release uuid ;" + releaseUuid + " and application release state "
+ "state.", e); + installableStateName;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while executing SQL to verify the existence of app release for application "
+ "release uuid ;" + releaseUuid + " and application release state " + installableStateName;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
} }

@ -524,7 +524,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
for (ApplicationDTO applicationDTO : appDTOs) { for (ApplicationDTO applicationDTO : appDTOs) {
boolean isSearchingApp = true; boolean isSearchingApp = true;
List<String> filteringTags = filter.getTags(); List<String> filteringTags = filter.getTags();
List<String> filteringCategories = filter.getAppCategories(); List<String> filteringCategories = filter.getCategories();
List<String> filteringUnrestrictedRoles = filter.getUnrestrictedRoles(); List<String> filteringUnrestrictedRoles = filter.getUnrestrictedRoles();
if (!lifecycleStateManager.getEndState().equals(applicationDTO.getStatus())) { if (!lifecycleStateManager.getEndState().equals(applicationDTO.getStatus())) {
@ -2511,17 +2511,19 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ "price is " + price + " for " + applicationSubType + " application."); + "price is " + price + " for " + applicationSubType + " application.");
} }
if (!ApplicationType.WEB_CLIP.toString().equals(appType) && !ApplicationType.WEB_APP.toString()
.equals(appType)) {
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId()); DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
String supportedOSVersions = applicationReleaseDTO.getSupportedOsVersions(); String supportedOSVersions = applicationReleaseDTO.getSupportedOsVersions();
if (!ApplicationType.WEB_CLIP.toString().equals(appType) && !ApplicationType.WEB_APP.toString().equals(appType) if (!StringUtils.isEmpty(supportedOSVersions) && !isValidOsVersions(supportedOSVersions,
&& !StringUtils.isEmpty(supportedOSVersions) && !isValidOsVersions( deviceTypeObj.getName())) {
supportedOSVersions, deviceTypeObj.getName())) {
String msg = "You are trying to update application release which has invalid or unsupported OS " String msg = "You are trying to update application release which has invalid or unsupported OS "
+ "versions in the supportedOsVersions section. Hence, please re-evaluate the request payload."; + "versions in the supportedOsVersions section. Hence, please re-evaluate the request payload.";
log.error(msg); log.error(msg);
throw new BadRequestException(msg); throw new BadRequestException(msg);
} }
} }
}
@Override @Override

@ -626,7 +626,7 @@ public class ReviewManagerImpl implements ReviewManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
try { try {
ConnectionManagerUtil.openDBConnection(); ConnectionManagerUtil.openDBConnection();
Rating rating = this.applicationReleaseDAO.getRating(appReleaseUuid, tenantId); Rating rating = this.applicationReleaseDAO.getReleaseRating(appReleaseUuid, tenantId);
if (rating == null) { if (rating == null) {
throw new NotFoundException( throw new NotFoundException(
"Couldn't find rating for application release UUID: " + appReleaseUuid "Couldn't find rating for application release UUID: " + appReleaseUuid
@ -710,7 +710,7 @@ public class ReviewManagerImpl implements ReviewManager {
private void calculateRating(int newRatingVal, int oldRatingVal, String uuid, int tenantId) { private void calculateRating(int newRatingVal, int oldRatingVal, String uuid, int tenantId) {
try { try {
ConnectionManagerUtil.beginDBTransaction(); ConnectionManagerUtil.beginDBTransaction();
Rating rating = this.applicationReleaseDAO.getRating(uuid, tenantId); Rating rating = this.applicationReleaseDAO.getReleaseRating(uuid, tenantId);
if (rating == null) { if (rating == null) {
log.error("Couldn't find rating for application release uuid: " + uuid); log.error("Couldn't find rating for application release uuid: " + uuid);
} else { } else {

Loading…
Cancel
Save