Search in sources :

Example 11 with APIMgtResourceNotFoundException

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();
}
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.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());
    }
}
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.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());
    }
}
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.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());
    }
}
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.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();
        }
    }
}
Also used : GenericArtifact(org.wso2.carbon.governance.api.generic.dataobjects.GenericArtifact) GenericArtifactManager(org.wso2.carbon.governance.api.generic.GenericArtifactManager) ApiTypeWrapper(org.wso2.carbon.apimgt.api.model.ApiTypeWrapper) UserRegistry(org.wso2.carbon.registry.core.session.UserRegistry) Registry(org.wso2.carbon.registry.core.Registry) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) RegistryException(org.wso2.carbon.registry.core.exceptions.RegistryException) APIProduct(org.wso2.carbon.apimgt.api.model.APIProduct) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) UserStoreException(org.wso2.carbon.user.core.UserStoreException) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) PublisherAPI(org.wso2.carbon.apimgt.persistence.dto.PublisherAPI) API(org.wso2.carbon.apimgt.api.model.API)

Aggregations

APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException)67 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)48 API (org.wso2.carbon.apimgt.api.model.API)22 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)22 APIMgtResourceNotFoundException (org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException)22 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)21 Organization (org.wso2.carbon.apimgt.persistence.dto.Organization)21 HashMap (java.util.HashMap)19 APIProvider (org.wso2.carbon.apimgt.api.APIProvider)19 APIPersistenceException (org.wso2.carbon.apimgt.persistence.exceptions.APIPersistenceException)17 APIManagementException (org.wso2.carbon.apimgt.core.exception.APIManagementException)16 APIProductIdentifier (org.wso2.carbon.apimgt.api.model.APIProductIdentifier)14 ErrorDTO (org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO)14 APIMgtDAOException (org.wso2.carbon.apimgt.core.exception.APIMgtDAOException)12 APIRevision (org.wso2.carbon.apimgt.api.model.APIRevision)11 DeployedAPIRevision (org.wso2.carbon.apimgt.api.model.DeployedAPIRevision)11 APIProduct (org.wso2.carbon.apimgt.api.model.APIProduct)10 ParseException (org.json.simple.parser.ParseException)9 APIRevisionDeployment (org.wso2.carbon.apimgt.api.model.APIRevisionDeployment)9 ImportExportAPI (org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI)8