Java Code Examples for org.wso2.carbon.apimgt.api.APIProvider#getAPIProductbyUUID()

The following examples show how to use org.wso2.carbon.apimgt.api.APIProvider#getAPIProductbyUUID() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ApiProductsApiServiceImpl.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Override public Response apiProductsApiProductIdGet(String apiProductId, String accept, String ifNoneMatch,
        MessageContext messageContext) {
    try {
        APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
        String username = RestApiUtil.getLoggedInUsername();
        String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(username));
        if (log.isDebugEnabled()) {
            log.debug("API Product request: Id " +apiProductId + " by " + username);
        }
        APIProduct apiProduct = apiProvider.getAPIProductbyUUID(apiProductId, tenantDomain);
        if (apiProduct == null) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API_PRODUCT, apiProductId, log);
        }

        APIProductDTO createdApiProductDTO = APIMappingUtil.fromAPIProducttoDTO(apiProduct);
        return Response.ok().entity(createdApiProductDTO).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API Product from Id  : " + apiProductId ;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
 
Example 2
Source File: ApiProductsApiServiceImpl.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
@Override public Response apiProductsApiProductIdSwaggerGet(String apiProductId, String accept, String ifNoneMatch,
        MessageContext messageContext) {
    try {
        String username = RestApiUtil.getLoggedInUsername();
        String tenantDomain = RestApiUtil.getLoggedInUserTenantDomain();
        APIProvider apiProvider = RestApiUtil.getProvider(username);
        APIProduct retrievedProduct = apiProvider.getAPIProductbyUUID(apiProductId, tenantDomain);
        if (retrievedProduct == null) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API_PRODUCT, apiProductId, log);
        }
        String apiSwagger = apiProvider.getAPIDefinitionOfAPIProduct(retrievedProduct);
        
        if (StringUtils.isEmpty(apiSwagger)) {
            apiSwagger = "";
        }
        return Response.ok().entity(apiSwagger).build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while retrieving API Product from Id  : " + apiProductId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
 
Example 3
Source File: ApiProductsApiServiceImpl.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Override public Response apiProductsApiProductIdDelete(String apiProductId, String ifMatch,
        MessageContext messageContext) {
    try {
        APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
        String username = RestApiUtil.getLoggedInUsername();
        String tenantDomain = MultitenantUtils.getTenantDomain(APIUtil.replaceEmailDomainBack(username));
        APIProductIdentifier apiProductIdentifier = APIMappingUtil.getAPIProductIdentifierFromUUID(apiProductId, tenantDomain);
        if (log.isDebugEnabled()) {
            log.debug("Delete API Product request: Id " +apiProductId + " by " + username);
        }
        APIProduct apiProduct = apiProvider.getAPIProductbyUUID(apiProductId, tenantDomain);
        if (apiProduct == null) {
            RestApiUtil.handleResourceNotFoundError(RestApiConstants.RESOURCE_API_PRODUCT, apiProductId, log);
        }

        List<SubscribedAPI> apiUsages = apiProvider.getAPIProductUsageByAPIProductId(apiProductIdentifier);
        if (apiUsages != null && apiUsages.size() > 0) {
            RestApiUtil.handleConflict("Cannot remove the API " + apiProductIdentifier + " as active subscriptions exist", log);
        }

        apiProvider.deleteAPIProduct(apiProduct.getId(), apiProductId);
        return Response.ok().build();
    } catch (APIManagementException e) {
        String errorMessage = "Error while deleting API Product : " + apiProductId;
        RestApiUtil.handleInternalServerError(errorMessage, e, log);
    }
    return null;
}
 
Example 4
Source File: APIMappingUtil.java    From carbon-apimgt with Apache License 2.0 3 votes vote down vote up
/**
 * Returns the APIProductIdentifier given the uuid
 *
 * @param productId                 API Product uuid
 * @param requestedTenantDomain tenant domain of the API
 * @return APIProductIdentifier which represents the given id
 * @throws APIManagementException
 */
public static APIProductIdentifier getAPIProductIdentifierFromUUID(String productId, String requestedTenantDomain)
        throws APIManagementException {

    APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
    APIProduct product = apiProvider.getAPIProductbyUUID(productId, requestedTenantDomain);
    return product.getId();
}