Search in sources :

Example 66 with APIMgtResourceNotFoundException

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

the class APIStoreImpl method getRatingForApiFromUser.

@Override
public Rating getRatingForApiFromUser(String apiId, String userId) throws APIRatingException, APIMgtResourceNotFoundException {
    try {
        failIfApiNotExists(apiId);
        Rating userRatingForApi = getApiDAO().getUserRatingForApiFromUser(apiId, userId);
        return userRatingForApi;
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while retrieving ratings for user " + userId + " 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) Rating(org.wso2.carbon.apimgt.core.models.Rating)

Example 67 with APIMgtResourceNotFoundException

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

the class APIStoreImpl method getCommentByUUID.

@Override
public Comment getCommentByUUID(String commentId, String apiId) throws APICommentException, APIMgtResourceNotFoundException {
    Comment comment;
    try {
        failIfApiNotExists(apiId);
        comment = getApiDAO().getCommentByUUID(commentId, apiId);
        if (comment == null) {
            String errorMsg = "Couldn't find comment with comment_id - " + commentId + " for api_id " + apiId;
            log.error(errorMsg);
            throw new APIMgtResourceNotFoundException(errorMsg, ExceptionCodes.COMMENT_NOT_FOUND);
        }
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while retrieving comment for comment_id " + commentId + " for api_id " + apiId;
        log.error(errorMsg, e);
        throw new APICommentException(errorMsg, e, e.getErrorHandler());
    }
    return comment;
}
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)

Example 68 with APIMgtResourceNotFoundException

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

the class APIStoreImpl method getCommentsForApi.

@Override
public List<Comment> getCommentsForApi(String apiId) throws APICommentException, APIMgtResourceNotFoundException {
    try {
        failIfApiNotExists(apiId);
        List<Comment> commentList = getApiDAO().getCommentsForApi(apiId);
        return commentList;
    } catch (APIMgtDAOException e) {
        String errorMsg = "Error occurred while retrieving comments for api " + apiId;
        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) APICommentException(org.wso2.carbon.apimgt.core.exception.APICommentException)

Example 69 with APIMgtResourceNotFoundException

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

the class PolicyDAOImplIT method testGetPoliciesByLevel.

@Test
public void testGetPoliciesByLevel() throws Exception {
    PolicyDAO policyDAO = DAOFactory.getPolicyDAO();
    int policySize;
    // api policy by level
    policySize = policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.api).size();
    APIPolicy apiPolicy = SampleTestObjectCreator.createDefaultAPIPolicy();
    policyDAO.addApiPolicy(apiPolicy);
    Assert.assertTrue(policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.api).size() == policySize + 1);
    Assert.assertEquals(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName()).getUuid(), apiPolicy.getUuid());
    Assert.assertEquals(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, apiPolicy.getPolicyName()).getUuid(), apiPolicy.getUuid());
    // application policy by level
    policySize = policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application).size();
    ApplicationPolicy applicationPolicy = SampleTestObjectCreator.createDefaultApplicationPolicy();
    policyDAO.addApplicationPolicy(applicationPolicy);
    Assert.assertTrue(policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.application).size() == policySize + 1);
    Assert.assertEquals(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName()).getUuid(), applicationPolicy.getUuid());
    Assert.assertEquals(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.application, applicationPolicy.getPolicyName()).getUuid(), applicationPolicy.getUuid());
    // subscription policy by level
    policySize = policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.subscription).size();
    SubscriptionPolicy subscriptionPolicy = SampleTestObjectCreator.createDefaultSubscriptionPolicy();
    policyDAO.addSubscriptionPolicy(subscriptionPolicy);
    Assert.assertTrue(policyDAO.getPoliciesByLevel(APIMgtAdminService.PolicyLevel.subscription).size() == policySize + 1);
    Assert.assertEquals(policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, subscriptionPolicy.getPolicyName()).getUuid(), subscriptionPolicy.getUuid());
    Assert.assertEquals(policyDAO.getPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.subscription, subscriptionPolicy.getPolicyName()).getUuid(), subscriptionPolicy.getUuid());
    // When policy is not in the DB
    try {
        policyDAO.getSimplifiedPolicyByLevelAndName(APIMgtAdminService.PolicyLevel.api, "test");
    } catch (APIMgtResourceNotFoundException ex) {
        Assert.assertEquals(ex.getMessage(), "Policy " + APIMgtAdminService.PolicyLevel.api + "Couldn't found " + "test");
    }
}
Also used : SubscriptionPolicy(org.wso2.carbon.apimgt.core.models.policy.SubscriptionPolicy) ApplicationPolicy(org.wso2.carbon.apimgt.core.models.policy.ApplicationPolicy) APIPolicy(org.wso2.carbon.apimgt.core.models.policy.APIPolicy) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException) PolicyDAO(org.wso2.carbon.apimgt.core.dao.PolicyDAO) Test(org.testng.annotations.Test)

Example 70 with APIMgtResourceNotFoundException

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

the class SubscriptionsApiServiceImpl method subscriptionsUnblockSubscriptionPost.

/**
 * @param subscriptionId    ID of the subscription
 * @param ifMatch           If-Match header value
 * @param ifUnmodifiedSince If-Modified-Since value
 * @param request           ms4j request object
 * @return ms4j request object
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response subscriptionsUnblockSubscriptionPost(String subscriptionId, String ifMatch, String ifUnmodifiedSince, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        Subscription subscription = apiPublisher.getSubscriptionByUUID(subscriptionId);
        if (subscription == null) {
            String errorMessage = "Subscription not found : " + subscriptionId;
            APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.SUBSCRIPTION_NOT_FOUND);
            HashMap<String, String> paramList = new HashMap<String, String>();
            paramList.put(APIMgtConstants.ExceptionsConstants.SUBSCRIPTION_ID, subscriptionId);
            ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
            log.error(errorMessage, e);
            return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
        } else if (subscription.getStatus().equals(APIMgtConstants.SubscriptionStatus.REJECTED) || subscription.getStatus().equals(APIMgtConstants.SubscriptionStatus.ON_HOLD)) {
            String errorMessage = "Cannot update subcription from " + subscription.getStatus() + "to " + APIMgtConstants.SubscriptionStatus.ACTIVE;
            APIMgtResourceNotFoundException e = new APIMgtResourceNotFoundException(errorMessage, ExceptionCodes.SUBSCRIPTION_STATE_INVALID);
            ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler());
            log.error(errorMessage, e);
            return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
        }
        apiPublisher.updateSubscriptionStatus(subscriptionId, APIMgtConstants.SubscriptionStatus.ACTIVE);
        Subscription newSubscription = apiPublisher.getSubscriptionByUUID(subscriptionId);
        SubscriptionDTO subscriptionDTO = MappingUtil.fromSubscription(newSubscription);
        return Response.ok().entity(subscriptionDTO).build();
    } catch (GatewayException e) {
        String errorMessage = "Failed to unblock subscription :" + subscriptionId + " in gateway";
        log.error(errorMessage, e);
        return Response.status(Response.Status.ACCEPTED).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while unblocking the subscription " + subscriptionId;
        HashMap<String, String> paramList = new HashMap<String, String>();
        paramList.put(APIMgtConstants.ExceptionsConstants.SUBSCRIPTION_ID, subscriptionId);
        ErrorDTO errorDTO = RestApiUtil.getErrorDTO(e.getErrorHandler(), paramList);
        log.error(errorMessage, e);
        return Response.status(e.getErrorHandler().getHttpStatusCode()).entity(errorDTO).build();
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.core.exception.APIManagementException) HashMap(java.util.HashMap) ErrorDTO(org.wso2.carbon.apimgt.rest.api.common.dto.ErrorDTO) GatewayException(org.wso2.carbon.apimgt.core.exception.GatewayException) APIPublisher(org.wso2.carbon.apimgt.core.api.APIPublisher) Subscription(org.wso2.carbon.apimgt.core.models.Subscription) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.core.exception.APIMgtResourceNotFoundException) SubscriptionDTO(org.wso2.carbon.apimgt.rest.api.publisher.dto.SubscriptionDTO)

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