Format APPM source

merge-requests/168/head
lasanthaDLPDS 5 years ago
parent a5d39e76b5
commit 30a6b3ee28

@ -840,26 +840,28 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
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;
String sql = "DELETE FROM " String sql = "DELETE FROM "
+ "AP_APP_CATEGORY_MAPPING " + "AP_APP_CATEGORY_MAPPING "
+ "WHERE " + "WHERE "
+ "AP_APP_ID = ? AND " + "AP_APP_ID = ? AND "
+ "TENANT_ID = ?"; + "TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)){ try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, applicationId); stmt.setInt(1, applicationId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when deleting category mapping of "
"Error occurred while obtaining the DB connection when deleting category mapping of application ID: " + "application ID: " + applicationId;
+ applicationId , e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred when deleting category mapping of application ID: " String msg = "SQL Error occurred when deleting category mapping of application ID: " + applicationId
+ applicationId, e); + " Executed query: " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -867,16 +869,15 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
public void deleteAppCategories(List<Integer> categoryIds, int applicationId, int tenantId) public void deleteAppCategories(List<Integer> categoryIds, int applicationId, int tenantId)
throws ApplicationManagementDAOException { throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete Tag mappings."); log.debug("Request received in DAO Layer to delete application category.");
} }
Connection conn;
String sql = "DELETE FROM " String sql = "DELETE FROM "
+ "AP_APP_CATEGORY_MAPPING WHERE " + "AP_APP_CATEGORY_MAPPING WHERE "
+ "AP_APP_CATEGORY_ID = ? AND " + "AP_APP_CATEGORY_ID = ? AND "
+ "AP_APP_ID = ? AND " + "AP_APP_ID = ? AND "
+ "TENANT_ID = ?"; + "TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement 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);
@ -887,10 +888,13 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.executeBatch(); stmt.executeBatch();
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when deleting category mapping.";
"Error occurred while obtaining the DB connection when deleting category mapping", e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("Error occurred when deleting category mapping", e); String msg = "SQL Error occurred when deleting category mapping. Executed query: " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -899,26 +903,28 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to delete category."); log.debug("Request received in DAO Layer to delete category.");
} }
Connection conn;
String sql = "DELETE FROM " + String sql = "DELETE FROM " +
"AP_APP_CATEGORY " + "AP_APP_CATEGORY " +
"WHERE " + "WHERE " +
"ID = ? AND " + "ID = ? AND " +
"TENANT_ID = ?"; "TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, categoryId); stmt.setInt(1, categoryId);
stmt.setInt(2, tenantId); stmt.setInt(2, tenantId);
stmt.executeUpdate(); stmt.executeUpdate();
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when deleting category which has ID: "
"Error occurred while obtaining the DB connection when deleting category which has ID: " + categoryId;
+ categoryId, e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "SQL Error occurred when deleting category which has ID: " + categoryId + ". Executed query: "
"Error occurred when deleting category which has ID: " + categoryId, e); + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -927,7 +933,6 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to update a category."); log.debug("Request received in DAO Layer to update a category.");
} }
Connection conn;
String sql = "UPDATE " + String sql = "UPDATE " +
"AP_APP_CATEGORY cat " + "AP_APP_CATEGORY cat " +
"SET cat.CATEGORY = ? " + "SET cat.CATEGORY = ? " +
@ -935,7 +940,7 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
"cat.ID = ? AND " + "cat.ID = ? AND " +
"cat.TENANT_ID = ?"; "cat.TENANT_ID = ?";
try { try {
conn = this.getDBConnection(); Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) { try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, categoryDTO.getCategoryName()); stmt.setString(1, categoryDTO.getCategoryName());
stmt.setInt(2, categoryDTO.getId()); stmt.setInt(2, categoryDTO.getId());
@ -943,12 +948,15 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
stmt.executeUpdate(); stmt.executeUpdate();
} }
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when updating category which has ID: "
"Error occurred while obtaining the DB connection when updating category which has ID: " + categoryDTO.getId();
+ categoryDTO.getId(), e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred when updating category which has ID: " + categoryDTO.getId() + ". Executed "
"Error occurred when updating category which has ID: " + categoryDTO.getId(), e); + "query: " + sql;
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@ -963,7 +971,8 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
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_TAG.ID AS ID FROM AP_APP_TAG WHERE AP_APP_TAG.TAG IN (", ") AND TENANT_ID = ?"); "SELECT AP_APP_TAG.ID AS ID FROM AP_APP_TAG WHERE AP_APP_TAG.TAG IN (",
") AND TENANT_ID = ?");
tagNames.stream().map(ignored -> "?").forEach(joiner::add); tagNames.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)) {
@ -979,17 +988,20 @@ 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 tag IDs for given tag names.";
"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 tag IDs for given tag names";
log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override @Override
public TagDTO getTagForTagName(String tagName, int tenantId) throws ApplicationManagementDAOException { public TagDTO getTagForTagName(String tagName, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get tag id for given tag name."); log.debug("Request received in DAO Layer to get tag for given tag name.");
} }
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();
@ -1011,17 +1023,19 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
} }
return null; return null;
} catch (DBConnectionException e) { } catch (DBConnectionException e) {
throw new ApplicationManagementDAOException( String msg = "Error occurred while obtaining the DB connection when getting tag for given tag name";
"Error occurred while obtaining the DB connection when getting tag Id for given tag name", e); log.error(msg);
throw new ApplicationManagementDAOException(msg, e);
} catch (SQLException e) { } catch (SQLException e) {
throw new ApplicationManagementDAOException("SQL Error occurred while getting tag Id for tag name.", e); String msg = "SQL Error occurred while getting tag for tag name.";
throw new ApplicationManagementDAOException(msg, e);
} }
} }
@Override @Override
public List<Integer> getDistinctTagIdsInTagMapping() throws ApplicationManagementDAOException { public List<Integer> getDistinctTagIdsInTagMapping() throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get distinct tag ids for given tag names"); log.debug("Request received in DAO Layer to get distinct tag ids in tag mapping.");
} }
try { try {
Connection conn = this.getDBConnection(); Connection conn = this.getDBConnection();

@ -235,7 +235,6 @@ public class ReviewManagementAPIImpl implements ReviewManagementAPI {
try { try {
reviewManager.deleteReview(uuid, reviewId, false); reviewManager.deleteReview(uuid, reviewId, false);
return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build(); return Response.status(Response.Status.OK).entity("Review is deleted successfully.").build();
} catch (NotFoundException e) { } catch (NotFoundException e) {
String msg = "Couldn't found an application review to delete which match with the request."; String msg = "Couldn't found an application review to delete which match with the request.";
log.error(msg, e); log.error(msg, e);

Loading…
Cancel
Save