Search in sources :

Example 11 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class APIStoreImpl method addComment.

@Override
public String addComment(Comment comment, String apiId) throws APICommentException, APIMgtResourceNotFoundException {
    validateCommentMaxCharacterLength(comment.getCommentText());
    String generatedUuid = UUID.randomUUID().toString();
    comment.setUuid(generatedUuid);
    try {
        failIfApiNotExists(apiId);
        getApiDAO().addComment(comment, apiId);
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while adding comment for api - " + apiId;
        log.error(errorMsg, e);
        throw new APICommentException(errorMsg, e, e.getErrorHandler());
    }
    return comment.getUuid();
}
Also used : APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APICommentException(org.wso2.carbon.apimgt.core.exception.APICommentException)

Example 12 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class APIStoreImpl method getRatingsListForApi.

@Override
public List<Rating> getRatingsListForApi(String apiId) throws APIRatingException, APIMgtResourceNotFoundException {
    try {
        failIfApiNotExists(apiId);
        List<Rating> ratingsListForApi = getApiDAO().getRatingsListForApi(apiId);
        return ratingsListForApi;
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while retrieving ratings list for api_id " + apiId;
        log.error(errorMsg, e);
        throw new APIRatingException(errorMsg, e, e.getErrorHandler());
    }
}
Also used : APIRatingException(org.wso2.carbon.apimgt.core.exception.APIRatingException) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) Rating(org.wso2.carbon.apimgt.core.models.Rating)

Example 13 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class APIStoreImpl method deleteComment.

@Override
public void deleteComment(String commentId, String apiId, String username) throws APICommentException, APIMgtResourceNotFoundException {
    try {
        ApiDAO apiDAO = getApiDAO();
        failIfApiNotExists(apiId);
        Comment comment = apiDAO.getCommentByUUID(commentId, apiId);
        if (comment != null) {
            // if the delete operation is done by a user who isn't the owner of the comment
            if (!comment.getCommentedUser().equals(username)) {
                checkIfUserIsCommentModerator(username);
            }
            apiDAO.deleteComment(commentId, apiId);
        } else {
            String errorMsg = "Couldn't find comment with comment_id : " + commentId;
            log.error(errorMsg);
            throw new APIMgtResourceNotFoundException(errorMsg, ExceptionCodes.COMMENT_NOT_FOUND);
        }
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while deleting comment " + commentId;
        log.error(errorMsg, e);
        throw new APICommentException(errorMsg, e, e.getErrorHandler());
    }
}
Also used : Comment(org.wso2.carbon.apimgt.core.models.Comment) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException) APICommentException(org.wso2.carbon.apimgt.core.exception.APICommentException) ApiDAO(org.wso2.carbon.apimgt.core.dao.ApiDAO)

Example 14 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class APIStoreImpl method addRating.

@Override
public String addRating(String apiId, Rating rating) throws APIRatingException, APIMgtResourceNotFoundException {
    try {
        validateMaxMinRatingValue(rating.getRating());
        failIfApiNotExists(apiId);
        String generatedUuid = UUID.randomUUID().toString();
        rating.setUuid(generatedUuid);
        getApiDAO().addRating(apiId, rating);
        return rating.getUuid();
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while adding rating for user " + getUsername() + " for api " + apiId;
        log.error(errorMsg, e);
        throw new APIRatingException(errorMsg, e, e.getErrorHandler());
    }
}
Also used : APIRatingException(org.wso2.carbon.apimgt.core.exception.APIRatingException) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)

Example 15 with APIMgtResourceNotFoundException

use of org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.

the class PolicyDAOImpl method getSimplifiedPolicyByLevelAndName.

@Override
public Policy getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel policyLevel, String policyName) throws APIMgtDAOException, APIMgtResourceNotFoundException {
    Policy policy = null;
    final String apiPolicyQuery = "SELECT UUID,NAME FROM AM_API_POLICY WHERE NAME = ?";
    final String applicationPolicyQuery = "SELECT UUID,NAME FROM AM_APPLICATION_POLICY WHERE NAME = ?";
    final String subscriptionPolicyQuery = "SELECT UUID,NAME FROM AM_SUBSCRIPTION_POLICY WHERE NAME = ?";
    try (Connection connection = DAOUtil.getConnection()) {
        if (policyLevel.equals(APIMgtAdminService.PolicyLevel.api)) {
            try (PreparedStatement statement = connection.prepareStatement(apiPolicyQuery)) {
                statement.setString(1, policyName);
                try (ResultSet resultSet = statement.executeQuery()) {
                    if (resultSet.next()) {
                        policy = new APIPolicy(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_UUID), resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_NAME));
                    }
                }
            }
        } else if (policyLevel.equals(APIMgtAdminService.PolicyLevel.application)) {
            try (PreparedStatement statement = connection.prepareStatement(applicationPolicyQuery)) {
                statement.setString(1, policyName);
                try (ResultSet resultSet = statement.executeQuery()) {
                    if (resultSet.next()) {
                        policy = new ApplicationPolicy(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_UUID), resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_NAME));
                    }
                }
            }
        } else {
            try (PreparedStatement statement = connection.prepareStatement(subscriptionPolicyQuery)) {
                statement.setString(1, policyName);
                try (ResultSet resultSet = statement.executeQuery()) {
                    if (resultSet.next()) {
                        policy = new SubscriptionPolicy(resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_UUID), resultSet.getString(APIMgtConstants.ThrottlePolicyConstants.COLUMN_NAME));
                    }
                }
            }
        }
    } catch (SQLException e) {
        String msg = "Error while retrieving policies";
        log.error(msg, e);
        throw new APIMgtDAOException(msg, ExceptionCodes.APIMGT_DAO_EXCEPTION);
    }
    if (policy == null) {
        throw new APIMgtResourceNotFoundException("Policy " + policyLevel + "Couldn't found " + policyName, ExceptionCodes.POLICY_NOT_FOUND);
    }
    return policy;
}
Also used : ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) Policy(org.wso2.carbon.apimgt.core.models.policy.Policy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) CustomPolicy(org.wso2.carbon.apimgt.core.models.policy.CustomPolicy) QuotaPolicy(org.wso2.carbon.apimgt.core.models.policy.QuotaPolicy) APIMgtDAOException(org.wso2.carbon.apimgt.core.exception.APIMgtDAOException) SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) SQLException(java.sql.SQLException) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)

Aggregations

APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)22 HashMap (java.util.HashMap)16 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)16 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)14 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)12 APIPublisher (org.wso2.carbon.apimgt.core.api.APIPublisher)5 APIStore (org.wso2.carbon.apimgt.core.api.APIStore)5 APICommentException (org.wso2.carbon.apimgt.core.exception.APICommentException)5 APIRatingException (org.wso2.carbon.apimgt.core.exception.APIRatingException)5 Subscription (org.wso2.carbon.apimgt.core.models.Subscription)5 Comment (org.wso2.carbon.apimgt.core.models.Comment)4 DedicatedGateway (org.wso2.carbon.apimgt.core.models.DedicatedGateway)4 Map (java.util.Map)3 GatewayException (org.wso2.carbon.apimgt.core.exception.GatewayException)3 Application (org.wso2.carbon.apimgt.core.models.Application)3 Rating (org.wso2.carbon.apimgt.core.models.Rating)3 SubscriptionDTO (org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionDTO)3 APIMgtAdminService (org.wso2.carbon.apimgt.core.api.APIMgtAdminService)2 WorkflowExecutor (org.wso2.carbon.apimgt.core.api.WorkflowExecutor)2 WorkflowResponse (org.wso2.carbon.apimgt.core.api.WorkflowResponse)2