Search in sources :

Example 1 with ErrorMessage

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;
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with ErrorMessage

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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DedicatedGateway(org.wso2.carbon.apimgt.core.models.DedicatedGateway)

Example 3 with ErrorMessage

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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 4 with ErrorMessage

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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 5 with ErrorMessage

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);
    }
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)209 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)153 HashMap (java.util.HashMap)142 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)135 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)101 ArrayList (java.util.ArrayList)73 SQLException (java.sql.SQLException)65 IOException (java.io.IOException)63 Connection (java.sql.Connection)62 URISyntaxException (java.net.URISyntaxException)56 Map (java.util.Map)53 UserStoreException (org.wso2.carbon.user.api.UserStoreException)52 URI (java.net.URI)50 API (org.wso2.carbon.apimgt.api.model.API)46 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)43 PreparedStatement (java.sql.PreparedStatement)41 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)40 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)40 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)36 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)35