use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class ApiDAOImpl method getUserRatingForApiFromUser.
@Override
public Rating getUserRatingForApiFromUser(String apiId, String userId) throws APIMgtDAOException {
final String query = "SELECT UUID, API_ID, RATING, USER_IDENTIFIER, " + "CREATED_BY, CREATED_TIME, UPDATED_BY, LAST_UPDATED_TIME " + "FROM AM_API_RATINGS WHERE USER_IDENTIFIER = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
statement.setString(1, userId);
statement.setString(2, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
return constructRatingFromResultSet(rs);
}
}
} catch (SQLException e) {
String errorMessage = "getting User Rating for API: " + apiId + ", User: " + userId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
} catch (SQLException e) {
String errorMessage = "getting User Rating for API: " + apiId + ", User: " + userId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
return null;
}
use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class ApiDAOImpl method getDedicatedGateway.
/**
* @see ApiDAO#getDedicatedGateway(String)
*/
@Override
public DedicatedGateway getDedicatedGateway(String apiId) throws APIMgtDAOException {
final String query = "SELECT HAS_OWN_GATEWAY FROM AM_API WHERE UUID = ?";
DedicatedGateway dedicatedGateway;
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
try {
statement.setString(1, apiId);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next()) {
dedicatedGateway = new DedicatedGateway();
dedicatedGateway.setEnabled(rs.getBoolean(ContainerBasedGatewayConstants.IS_DEDICATED_GATEWAY_ENABLED));
return dedicatedGateway;
} else {
throw new APIMgtDAOException("Couldn't Find Dedicated Gateway details ", ExceptionCodes.DEDICATED_GATEWAY_DETAILS_NOT_FOUND);
}
}
} catch (SQLException e) {
String errorMessage = "Error while retrieving dedicated gateway details of API : " + apiId;
throw new APIMgtDAOException(errorMessage, e);
}
} catch (SQLException e) {
String message = "Error while creating database connection/prepared-statement";
throw new APIMgtDAOException(message, e);
}
}
use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class ApiDAOImpl method isAPIVersionsExist.
@Override
public boolean isAPIVersionsExist(String apiName) throws APIMgtDAOException {
final String query = "SELECT COUNT (NAME) FROM AM_API WHERE NAME = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(query)) {
statement.setString(1, apiName);
statement.execute();
try (ResultSet rs = statement.getResultSet()) {
if (rs.next() && rs.getInt(1) > 1) {
return true;
} else {
return false;
}
}
} catch (SQLException e) {
String errorMessage = "getting existence of versioned API: " + apiName;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class ApiDAOImpl method deleteComment.
@Override
public void deleteComment(String commentId, String apiId) throws APIMgtDAOException {
final String deleteCommentQuery = "DELETE FROM AM_API_COMMENTS WHERE UUID = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(deleteCommentQuery)) {
try {
connection.setAutoCommit(false);
statement.setString(1, commentId);
statement.setString(2, apiId);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMessage = "deleting comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
use of org.wso2.carbon.identity.api.server.application.management.common.ApplicationManagementConstants.ErrorMessage in project carbon-apimgt by wso2.
the class ApiDAOImpl method updateComment.
@Override
public void updateComment(Comment comment, String commentId, String apiId) throws APIMgtDAOException {
final String updateCommentQuery = "UPDATE AM_API_COMMENTS SET COMMENT_TEXT = ? " + ", UPDATED_BY = ? , LAST_UPDATED_TIME = ?" + " WHERE UUID = ? AND API_ID = ?";
try (Connection connection = DAOUtil.getConnection();
PreparedStatement statement = connection.prepareStatement(updateCommentQuery)) {
try {
connection.setAutoCommit(false);
statement.setString(1, comment.getCommentText());
statement.setString(2, comment.getUpdatedUser());
statement.setTimestamp(3, Timestamp.valueOf(LocalDateTime.now()));
statement.setString(4, commentId);
statement.setString(5, apiId);
statement.execute();
connection.commit();
} catch (SQLException e) {
connection.rollback();
String errorMessage = "updating comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
} finally {
connection.setAutoCommit(DAOUtil.isAutoCommit());
}
} catch (SQLException e) {
String errorMessage = "updating comment for API " + apiId + ", Comment " + commentId;
throw new APIMgtDAOException(DAOUtil.DAO_ERROR_PREFIX + errorMessage, e);
}
}
Aggregations