Search in sources :

Example 71 with APIMgtResourceNotFoundException

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

the class SubscriptionsApiServiceImpl method subscriptionsSubscriptionIdGet.

/**
 * Retrieves a single subscription
 *
 * @param subscriptionId  ID of the subscription
 * @param ifNoneMatch     If-Match header value
 * @param ifModifiedSince If-Modified-Since value
 * @param request         ms4j request object
 * @return Requested subscription details
 * @throws NotFoundException When the particular resource does not exist in the system
 */
@Override
public Response subscriptionsSubscriptionIdGet(String subscriptionId, String ifNoneMatch, String ifModifiedSince, Request request) throws NotFoundException {
    String username = RestApiUtil.getLoggedInUsername(request);
    try {
        APIPublisher apiPublisher = RestAPIPublisherUtil.getApiPublisher(username);
        String existingFingerprint = subscriptionsSubscriptionIdGetFingerprint(subscriptionId, ifNoneMatch, ifModifiedSince, request);
        if (!StringUtils.isEmpty(ifNoneMatch) && !StringUtils.isEmpty(existingFingerprint) && ifNoneMatch.contains(existingFingerprint)) {
            return Response.notModified().build();
        }
        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();
        }
        SubscriptionDTO subscriptionDTO = MappingUtil.fromSubscription(subscription);
        return Response.ok().header(HttpHeaders.ETAG, "\"" + existingFingerprint + "\"").entity(subscriptionDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while getting 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) 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)

Example 72 with APIMgtResourceNotFoundException

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

the class ApiProductsApiServiceImpl method deleteAPIProductLifecycleStatePendingTasks.

@Override
public Response deleteAPIProductLifecycleStatePendingTasks(String apiProductId, MessageContext messageContext) throws APIManagementException {
    try {
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        APIProductIdentifier productIdentifier = APIUtil.getAPIProductIdentifierFromUUID(apiProductId);
        if (productIdentifier == null) {
            throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API Product with UUID: " + apiProductId, ExceptionCodes.from(ExceptionCodes.API_PRODUCT_NOT_FOUND, apiProductId));
        }
        apiProvider.deleteWorkflowTask(productIdentifier);
        return Response.ok().build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while deleting task ";
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
Also used : APIProductIdentifier(org.wso2.carbon.apimgt.api.model.APIProductIdentifier) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 73 with APIMgtResourceNotFoundException

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

the class ApisApiServiceImpl method getAPISpecificOperationPolicyContentByPolicyId.

/**
 * Download the operation policy specification and definition for a given API specific policy
 *
 * @param apiId             API UUID
 * @param operationPolicyId UUID of the operation policy
 * @param messageContext    message context
 * @return A zip file containing both (if exists) operation policy specification and policy definition
 */
@Override
public Response getAPISpecificOperationPolicyContentByPolicyId(String apiId, String operationPolicyId, MessageContext messageContext) {
    try {
        APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
        String organization = RestApiUtil.getValidatedOrganization(messageContext);
        // validate if api exists
        validateAPIExistence(apiId);
        OperationPolicyData policyData = apiProvider.getAPISpecificOperationPolicyByPolicyId(operationPolicyId, apiId, organization, true);
        if (policyData != null) {
            File file = RestApiPublisherUtils.exportOperationPolicyData(policyData);
            return Response.ok(file).header(RestApiConstants.HEADER_CONTENT_DISPOSITION, "attachment; filename=\"" + file.getName() + "\"").build();
        } else {
            throw new APIMgtResourceNotFoundException("Couldn't retrieve an existing operation policy with ID: " + operationPolicyId + " for API " + apiId, ExceptionCodes.from(ExceptionCodes.OPERATION_POLICY_NOT_FOUND, operationPolicyId));
        }
    } catch (APIManagementException e) {
        if (RestApiUtil.isDueToResourceNotFound(e) || RestApiUtil.isDueToAuthorizationFailure(e)) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_PATH_OPERATION_POLICIES, operationPolicyId, e, log);
        } else {
            String errorMessage = "Error while getting an API specific operation policy with ID :" + operationPolicyId + " for API " + apiId + " " + e.getMessage();
            RestApiUtil.handleInternalServerError(errorMessage, e, log);
        }
    } catch (Exception e) {
        RestApiUtil.handleInternalServerError("An Error has occurred while exporting the API specific" + " operation policy with ID" + operationPolicyId + " for API " + apiId, e, log);
    }
    return null;
}
Also used : OperationPolicyData(org.wso2.carbon.apimgt.api.model.OperationPolicyData) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider) ResourceFile(org.wso2.carbon.apimgt.api.model.ResourceFile) File(java.io.File) JSONException(org.json.JSONException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) SdkClientException(com.amazonaws.SdkClientException) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) URISyntaxException(java.net.URISyntaxException) BadRequestException(org.wso2.carbon.apimgt.rest.api.util.exception.BadRequestException) CryptoException(org.wso2.carbon.core.util.CryptoException) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) FaultGatewaysException(org.wso2.carbon.apimgt.api.FaultGatewaysException) APIMgtResourceAlreadyExistsException(org.wso2.carbon.apimgt.api.APIMgtResourceAlreadyExistsException) MonetizationException(org.wso2.carbon.apimgt.api.MonetizationException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) ParseException(org.json.simple.parser.ParseException) MalformedURLException(java.net.MalformedURLException)

Example 74 with APIMgtResourceNotFoundException

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

the class ApisApiServiceImpl method generateMockScripts.

/**
 * Generates Mock response examples for Inline prototyping
 * of a swagger
 *
 * @param apiId API Id
 * @param ifNoneMatch If-None-Match header value
 * @param messageContext message context
 * @return apiDefinition
 * @throws APIManagementException
 */
@Override
public Response generateMockScripts(String apiId, String ifNoneMatch, MessageContext messageContext) throws APIManagementException {
    APIIdentifier apiIdentifierFromTable = APIMappingUtil.getAPIIdentifierFromUUID(apiId);
    if (apiIdentifierFromTable == null) {
        throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with API UUID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
    }
    String organization = RestApiUtil.getValidatedOrganization(messageContext);
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    API originalAPI = apiProvider.getAPIbyUUID(apiId, organization);
    String apiDefinition = apiProvider.getOpenAPIDefinition(apiId, organization);
    apiDefinition = String.valueOf(OASParserUtil.generateExamples(apiDefinition).get(APIConstants.SWAGGER));
    apiProvider.saveSwaggerDefinition(originalAPI, apiDefinition, organization);
    return Response.ok().entity(apiDefinition).build();
}
Also used : APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) API(org.wso2.carbon.apimgt.api.model.API) ImportExportAPI(org.wso2.carbon.apimgt.impl.importexport.ImportExportAPI) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

Example 75 with APIMgtResourceNotFoundException

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

the class ApisApiServiceImpl method validateAPIExistence.

/**
 * Validate whether the given API with UUID exists in the DB
 *
 * @param apiId API UUID
 * @return API details
 * @throws APIManagementException if the API doesn't exists in the DB
 */
private APIInfo validateAPIExistence(String apiId) throws APIManagementException {
    APIProvider apiProvider = RestApiCommonUtil.getLoggedInUserProvider();
    APIInfo apiInfo = apiProvider.getAPIInfoByUUID(apiId);
    if (apiInfo == null) {
        throw new APIMgtResourceNotFoundException("Couldn't retrieve existing API with API UUID: " + apiId, ExceptionCodes.from(ExceptionCodes.API_NOT_FOUND, apiId));
    }
    return apiInfo;
}
Also used : APIInfo(org.wso2.carbon.apimgt.api.model.APIInfo) APIMgtResourceNotFoundException(org.wso2.carbon.apimgt.api.APIMgtResourceNotFoundException) APIProvider(org.wso2.carbon.apimgt.api.APIProvider)

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