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();
}
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());
}
}
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());
}
}
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());
}
}
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;
}
Aggregations