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

The following examples show how to use org.wso2.carbon.apimgt.api.APIProvider#getAPI() . 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: CellerySignedJWTGenerator.java    From cellery-security with Apache License 2.0 6 votes vote down vote up
private String getDestinationCell(TokenValidationContext validationContext) throws APIManagementException {

        String providerName = validationContext.getValidationInfoDTO().getApiPublisher();
        String apiName = validationContext.getValidationInfoDTO().getApiName();
        String apiVersion = removeDefaultVersion(validationContext);

        APIIdentifier apiIdentifier = new APIIdentifier(providerName, apiName, apiVersion);
        APIProvider apiProvider = APIManagerFactory.getInstance().getAPIProvider(providerName);
        API api = apiProvider.getAPI(apiIdentifier);

        Object cellName = api.getAdditionalProperties().get(CELL_NAME);
        if (cellName instanceof String) {
            String destinationCell = String.valueOf(cellName);
            log.debug("Destination Cell for API call is '" + destinationCell + "'");
            return destinationCell;
        } else {
            log.debug("Property:" + CELL_NAME + " was not found for the API. This API call is going to an API not " +
                    "published by a Cellery Cell.");
            return null;
        }
    }
 
Example 2
Source File: APIMappingUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * This method creates the API monetization information DTO
 *
 * @param apiIdentifier API identifier
 * @return monetization information DTO
 * @throws APIManagementException if failed to construct the DTO
 */
public static APIMonetizationInfoDTO getMonetizationInfoDTO(APIIdentifier apiIdentifier)
        throws APIManagementException {

    APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
    API api = apiProvider.getAPI(apiIdentifier);
    APIMonetizationInfoDTO apiMonetizationInfoDTO = new APIMonetizationInfoDTO();
    //set the information relatated to monetization to the DTO
    apiMonetizationInfoDTO.setEnabled(api.getMonetizationStatus());
    Map<String, String> monetizationPropertiesMap = new HashMap<>();

    if (api.getMonetizationProperties() != null) {
        JSONObject monetizationProperties = api.getMonetizationProperties();
        for (Object propertyKey : monetizationProperties.keySet()) {
            String key = (String) propertyKey;
            monetizationPropertiesMap.put(key, (String) monetizationProperties.get(key));
        }
    }
    apiMonetizationInfoDTO.setProperties(monetizationPropertiesMap);
    return apiMonetizationInfoDTO;
}
 
Example 3
Source File: APIMappingUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the API given the uuid or the id in {provider}-{api}-{version} format
 *
 * @param apiId                 uuid or the id in {provider}-{api}-{version} format
 * @param requestedTenantDomain tenant domain of the API
 * @return API which represents the given id
 * @throws APIManagementException
 */
public static API getAPIFromApiIdOrUUID(String apiId, String requestedTenantDomain)
        throws APIManagementException {

    API api;
    APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
    if (RestApiUtil.isUUID(apiId)) {
        api = apiProvider.getAPIbyUUID(apiId, requestedTenantDomain);
    } else {
        APIIdentifier apiIdentifier = getAPIIdentifierFromApiId(apiId);
        //Checks whether the logged in user's tenant and the API's tenant is equal
        RestApiUtil.validateUserTenantWithAPIIdentifier(apiIdentifier);
        api = apiProvider.getAPI(apiIdentifier);
    }
    return api;
}
 
Example 4
Source File: APIMappingUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Get map of monetized policies to plan mapping
 *
 * @param apiIdentifier API identifier
 * @param monetizedPoliciesToPlanMapping map of monetized policies to plan mapping
 * @return DTO of map of monetized policies to plan mapping
 * @throws APIManagementException if failed to construct the DTO
 */
public static APIMonetizationInfoDTO getMonetizedTiersDTO(APIIdentifier apiIdentifier,
                                                          Map<String, String> monetizedPoliciesToPlanMapping)
        throws APIManagementException {

    APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
    API api = apiProvider.getAPI(apiIdentifier);
    APIMonetizationInfoDTO apiMonetizationInfoDTO = new APIMonetizationInfoDTO();
    apiMonetizationInfoDTO.setEnabled(api.getMonetizationStatus());
    apiMonetizationInfoDTO.setProperties(monetizedPoliciesToPlanMapping);
    return apiMonetizationInfoDTO;
}
 
Example 5
Source File: APIProductExportUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Export dependent APIs by checking the resources of the API Product.
 *
 * @param archivePath               Temp location to save the API artifacts
 * @param apiProductToReturn        API Product which the resources should be considered
 * @param userName                  User name of the requester
 * @param provider                  API Product Provider
 * @param exportFormat              Export format of the API meta data, could be yaml or json
 * @param isStatusPreserved         Whether API status is preserved while export
 * @throws APIImportExportException If an error occurs while retrieving API related resources
 */
private static void exportDependentAPIs(String archivePath, APIProduct apiProductToReturn, ExportFormat exportFormat,
                                        APIProvider provider, String userName, Boolean isStatusPreserved) throws APIImportExportException, APIManagementException {
    String apisDirectoryPath = archivePath + File.separator + APIImportExportConstants.APIS_DIRECTORY;
    CommonUtil.createDirectory(apisDirectoryPath);

    List<APIProductResource> apiProductResources = apiProductToReturn.getProductResources();
    for (APIProductResource apiProductResource : apiProductResources) {
        APIIdentifier apiIdentifier = apiProductResource.getApiIdentifier();
        API api = provider.getAPI(apiIdentifier);
        APIExportUtil.retrieveApiToExport(apisDirectoryPath, api, provider, userName, isStatusPreserved, exportFormat);
    }
}
 
Example 6
Source File: APIExportUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Exports an API from API Manager for a given API ID. Meta information, API icon, documentation, WSDL
 * and sequences are exported. This service generates a zipped archive which contains all the above mentioned
 * resources for a given API.
 *
 * @param apiIdentifier
 * @param apiProvider
 * @param preserveStatus Preserve API status on export
 * @return Zipped file containing exported API
 */

public static File exportApi(APIProvider apiProvider, APIIdentifier apiIdentifier, String userName,
                             ExportFormat exportFormat, Boolean preserveStatus)
        throws APIImportExportException, APIManagementException {
    API api;
    APIImportExportManager apiImportExportManager;
    boolean isStatusPreserved = preserveStatus == null || preserveStatus;
    api = apiProvider.getAPI(apiIdentifier);
    ApiTypeWrapper apiTypeWrapper = new ApiTypeWrapper(api);
    apiImportExportManager = new APIImportExportManager(apiProvider, userName);
    return apiImportExportManager.exportAPIOrAPIProductArchive(apiTypeWrapper, isStatusPreserved, exportFormat);
}
 
Example 7
Source File: APIMappingUtil.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
public static DeploymentStatusListDTO fromDeploymentStatustoDTO ( APIIdentifier apiIdentifier) throws APIManagementException{
    //create DTO form the model
    APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
    API api = apiProvider.getAPI(apiIdentifier);

    DeploymentStatusListDTO deploymentStatusListDTO = new DeploymentStatusListDTO();
    DeploymentStatusDTO deploymentStatusDTO = new DeploymentStatusDTO();
    List<DeploymentStatusDTO> deploymentStatuses = new ArrayList<DeploymentStatusDTO>();
    List<DeploymentClusterStatusDTO> clustersList  = new ArrayList<DeploymentClusterStatusDTO>();


    List<DeploymentStatus> deploymentStatusList = apiProvider.getDeploymentStatus(apiIdentifier);

    for(DeploymentStatus status : deploymentStatusList){
        DeploymentClusterStatusDTO deploymentClusterStatusDTO = new DeploymentClusterStatusDTO();
        List<PodStatusDTO>  podStatusDTOList = new ArrayList<PodStatusDTO>();

        deploymentClusterStatusDTO.setClusterName(status.getClusterName());
        deploymentClusterStatusDTO.setPodsRunning(status.getPodsRunning());

        for (Map<String, String> getPodStatus : status.getPodStatus()){
            PodStatusDTO podStatusDTO = new PodStatusDTO();
            podStatusDTO.setName(getPodStatus.get("podName"));
            podStatusDTO.setStatus(getPodStatus.get("status"));
            podStatusDTO.setReady(getPodStatus.get("ready"));
            podStatusDTO.setCreationTimestamp(getPodStatus.get("creationTimestamp"));

            podStatusDTOList.add(podStatusDTO);
        }

        deploymentClusterStatusDTO.setHealthStatus(podStatusDTOList);
        clustersList.add(deploymentClusterStatusDTO);

    }
    deploymentStatusDTO.setClusters(clustersList);
    deploymentStatusDTO.setType("kubernetes");
    deploymentStatuses.add(deploymentStatusDTO);

    deploymentStatusListDTO.setList(deploymentStatuses);
    deploymentStatusListDTO.setCount(deploymentStatuses.size());

    return deploymentStatusListDTO;
}