use of org.wso2.carbon.apimgt.api.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.api.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.api.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.api.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.api.APIMgtResourceNotFoundException in project carbon-apimgt by wso2.
the class AbstractAPIManager method getAPIorAPIProductByUUID.
/**
* Get API or APIProduct by registry artifact id
*
* @param uuid Registry artifact id
* @param requestedTenantDomain tenantDomain for the registry
* @return ApiTypeWrapper wrapping the API or APIProduct of the provided artifact id
* @throws APIManagementException
*/
public ApiTypeWrapper getAPIorAPIProductByUUID(String uuid, String requestedTenantDomain) throws APIManagementException {
boolean tenantFlowStarted = false;
try {
Registry registry;
if (requestedTenantDomain != null) {
int id = getTenantManager().getTenantId(requestedTenantDomain);
startTenantFlow(requestedTenantDomain);
tenantFlowStarted = true;
if (APIConstants.WSO2_ANONYMOUS_USER.equals(this.username)) {
registry = getRegistryService().getGovernanceUserRegistry(this.username, id);
} else if (this.tenantDomain != null && !this.tenantDomain.equals(requestedTenantDomain)) {
registry = getRegistryService().getGovernanceSystemRegistry(id);
} else {
registry = this.registry;
}
} else {
registry = this.registry;
}
GenericArtifactManager artifactManager = getAPIGenericArtifactManagerFromUtil(registry, APIConstants.API_KEY);
GenericArtifact apiArtifact = artifactManager.getGenericArtifact(uuid);
if (apiArtifact != null) {
String type = apiArtifact.getAttribute(APIConstants.API_OVERVIEW_TYPE);
if (APIConstants.API_PRODUCT.equals(type)) {
APIProduct apiProduct = getApiProduct(registry, apiArtifact);
String productTenantDomain = getTenantDomain(apiProduct.getId());
if (APIConstants.API_GLOBAL_VISIBILITY.equals(apiProduct.getVisibility())) {
return new ApiTypeWrapper(apiProduct);
}
if (this.tenantDomain == null || !this.tenantDomain.equals(productTenantDomain)) {
throw new APIManagementException("User " + username + " does not have permission to view API Product : " + apiProduct.getId().getName());
}
return new ApiTypeWrapper(apiProduct);
} else {
API api = getApiForPublishing(registry, apiArtifact);
String apiTenantDomain = getTenantDomain(api.getId());
if (APIConstants.API_GLOBAL_VISIBILITY.equals(api.getVisibility())) {
return new ApiTypeWrapper(api);
}
if (this.tenantDomain == null || !this.tenantDomain.equals(apiTenantDomain)) {
throw new APIManagementException("User " + username + " does not have permission to view API : " + api.getId().getApiName());
}
return new ApiTypeWrapper(api);
}
} else {
String msg = "Failed to get API. API artifact corresponding to artifactId " + uuid + " does not exist";
throw new APIMgtResourceNotFoundException(msg);
}
} catch (RegistryException | org.wso2.carbon.user.api.UserStoreException e) {
String msg = "Failed to get API";
throw new APIManagementException(msg, e);
} finally {
if (tenantFlowStarted) {
endTenantFlow();
}
}
}
Aggregations