Java Code Examples for org.wso2.carbon.apimgt.api.model.API#getId()

The following examples show how to use org.wso2.carbon.apimgt.api.model.API#getId() . 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: SearchResultMappingUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Get API result representation for content search
 *
 * @param api API
 * @return APISearchResultDTO
 */
public static APISearchResultDTO fromAPIToAPIResultDTO(API api) {

    APISearchResultDTO apiResultDTO = new APISearchResultDTO();
    apiResultDTO.setId(api.getUUID());
    APIIdentifier apiId = api.getId();
    apiResultDTO.setName(apiId.getApiName());
    apiResultDTO.setVersion(apiId.getVersion());
    apiResultDTO.setProvider(APIUtil.replaceEmailDomainBack(apiId.getProviderName()));
    String context = api.getContextTemplate();
    if (context.endsWith("/" + RestApiConstants.API_VERSION_PARAM)) {
        context = context.replace("/" + RestApiConstants.API_VERSION_PARAM, "");
    }
    apiResultDTO.setContext(context);
    apiResultDTO.setType(SearchResultDTO.TypeEnum.API);
    apiResultDTO.setTransportType(api.getType());
    apiResultDTO.setDescription(api.getDescription());
    apiResultDTO.setStatus(api.getStatus());
    apiResultDTO.setThumbnailUri(api.getThumbnailUrl());
    return apiResultDTO;
}
 
Example 2
Source File: SearchResultMappingUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Get Document result representation for content search
 *
 * @param document Api Document
 * @return DocumentSearchResultDTO
 */
public static DocumentSearchResultDTO fromDocumentationToDocumentResultDTO(Documentation document, API api) {

    DocumentSearchResultDTO docResultDTO = new DocumentSearchResultDTO();
    docResultDTO.setId(document.getId());
    docResultDTO.setName(document.getName());
    docResultDTO.setDocType(DocumentSearchResultDTO.DocTypeEnum.valueOf(document.getType().toString()));
    docResultDTO.setType(SearchResultDTO.TypeEnum.DOC);
    docResultDTO.setSummary(document.getSummary());
    docResultDTO.associatedType(APIConstants.AuditLogConstants.API);
    docResultDTO.setVisibility(DocumentSearchResultDTO.VisibilityEnum.valueOf(document.getVisibility().toString()));
    docResultDTO.setSourceType(DocumentSearchResultDTO.SourceTypeEnum.valueOf(document.getSourceType().toString()));
    docResultDTO.setOtherTypeName(document.getOtherTypeName());
    APIIdentifier apiId = api.getId();
    docResultDTO.setApiName(apiId.getApiName());
    docResultDTO.setApiVersion(apiId.getVersion());
    docResultDTO.setApiProvider(APIUtil.replaceEmailDomainBack(apiId.getProviderName()));
    docResultDTO.setApiUUID(api.getUUID());
    return docResultDTO;
}
 
Example 3
Source File: AlertsMappingUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Get a map of API name, version list. This is used to filter the retrieved alert configurations as there can be
 * api visibility restrictions.
 * @return A map with [api name, version list]
 * */
public static Map<String, List<String>> getAllowedAPIInfo() throws APIManagementException {
    APIProvider apiProvider = RestApiUtil.getLoggedInUserProvider();
    List<API> allowedAPIs = apiProvider.getAllAPIs();
    Map<String, List<String>> allowedAPINameVersionMap = new HashMap<>();

    for (API api : allowedAPIs) {
        List<String> versions;
        APIIdentifier identifier = api.getId();
        if (allowedAPINameVersionMap.containsKey(identifier.getApiName())) {
            versions = allowedAPINameVersionMap.get(identifier.getApiName());
            versions.add(identifier.getVersion());
            allowedAPINameVersionMap.put(identifier.getApiName(), versions);
        } else {
            versions = new ArrayList<>();
            versions.add(identifier.getVersion());
            allowedAPINameVersionMap.put(identifier.getApiName(), versions);
        }
    }
    return allowedAPINameVersionMap;
}
 
Example 4
Source File: SearchResultMappingUtil.java    From carbon-apimgt with Apache License 2.0 6 votes vote down vote up
/**
 * Get Document result representation for content search
 * @param document
 * @return
 */
public static DocumentSearchResultDTO fromDocumentationToDocumentResultDTO(Documentation document, API api) {
    DocumentSearchResultDTO docResultDTO = new DocumentSearchResultDTO();
    docResultDTO.setId(document.getId());
    docResultDTO.setName(document.getName());
    docResultDTO.setDocType(DocumentSearchResultDTO.DocTypeEnum.valueOf(document.getType().toString()));
    docResultDTO.setType(SearchResultDTO.TypeEnum.DOC);
    docResultDTO.setSummary(document.getSummary());
    docResultDTO.setVisibility(DocumentSearchResultDTO.VisibilityEnum.valueOf(document.getVisibility().toString()));
    docResultDTO.setSourceType(DocumentSearchResultDTO.SourceTypeEnum.valueOf(document.getSourceType().toString()));
    docResultDTO.setOtherTypeName(document.getOtherTypeName());
    APIIdentifier apiId = api.getId();
    docResultDTO.setApiName(apiId.getApiName());
    docResultDTO.setApiVersion(apiId.getVersion());
    docResultDTO.setApiProvider(apiId.getProviderName());
    docResultDTO.setApiUUID(api.getUUID());
    return docResultDTO;
}
 
Example 5
Source File: SharedScopeMappingUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Converts SharedScopeUsage object into SharedScopeUsageDTO object.
 *
 * @param sharedScopeUsage SharedScopeUsage object
 * @return SharedScopeUsageDTO object
 */
public static SharedScopeUsageDTO fromSharedScopeUsageToDTO(SharedScopeUsage sharedScopeUsage) {

    SharedScopeUsageDTO sharedScopeUsageDTO = new SharedScopeUsageDTO();
    sharedScopeUsageDTO.setId(sharedScopeUsage.getId());
    sharedScopeUsageDTO.setName(sharedScopeUsage.getName());

    List<SharedScopeUsedAPIInfoDTO> usedAPIInfoDTOList = new ArrayList<>();
    for (API api: sharedScopeUsage.getApis()) {
        APIIdentifier apiIdentifier = api.getId();
        SharedScopeUsedAPIInfoDTO usedAPIInfoDTO = new SharedScopeUsedAPIInfoDTO();
        usedAPIInfoDTO.setName(apiIdentifier.getName());
        usedAPIInfoDTO.setVersion(apiIdentifier.getVersion());
        usedAPIInfoDTO.setProvider(apiIdentifier.getProviderName());
        usedAPIInfoDTO.setContext(api.getContext());

        List<SharedScopeUsedAPIResourceInfoDTO> usedAPIResourceInfoDTOList = new ArrayList<>();
        for (URITemplate uriTemplate: api.getUriTemplates()) {
            SharedScopeUsedAPIResourceInfoDTO usedAPIResourceInfoDTO = new SharedScopeUsedAPIResourceInfoDTO();
            usedAPIResourceInfoDTO.setTarget(uriTemplate.getUriTemplate());
            usedAPIResourceInfoDTO.setVerb(uriTemplate.getHTTPVerb());
            usedAPIResourceInfoDTOList.add(usedAPIResourceInfoDTO);
        }
        usedAPIInfoDTO.setUsedResourceList(usedAPIResourceInfoDTOList);
        usedAPIInfoDTOList.add(usedAPIInfoDTO);
    }
    sharedScopeUsageDTO.setUsedApiList(usedAPIInfoDTOList);

    return sharedScopeUsageDTO;
}
 
Example 6
Source File: APIGatewayManager.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
public Map<String, String> removeDefaultAPIFromGateway(API api, String tenantDomain) {

        Map<String, String> failedEnvironmentsMap = new HashMap<String, String>(0);
        LocalEntryAdminClient localEntryAdminClient;
        String localEntryUUId = api.getUUID();
        if (api.getEnvironments() != null) {
            for (String environmentName : api.getEnvironments()) {
                try {
                    Environment environment = environments.get(environmentName);
                    APIGatewayAdminClient client = new APIGatewayAdminClient(environment);
                    APIIdentifier id = api.getId();
                    if (client.getDefaultApi(tenantDomain, id) != null) {
                        if (debugEnabled) {
                            log.debug("Removing Default API " + api.getId().getApiName() + " From environment " +
                                    environment.getName());
                        }
                        client.deleteDefaultApi(tenantDomain, api.getId());
                    }
                    if (APIConstants.APITransportType.GRAPHQL.toString().equals(api.getType())) {
                        localEntryUUId = localEntryUUId + APIConstants.GRAPHQL_LOCAL_ENTRY_EXTENSION;
                    }
                    localEntryAdminClient = new LocalEntryAdminClient(environment, tenantDomain);
                    localEntryAdminClient.deleteEntry(localEntryUUId);
                } catch (AxisFault axisFault) {
                    /*
                didn't throw this exception to handle multiple gateway publishing
                if gateway is unreachable we collect that environments into map with issue and show on popup in ui
                therefore this didn't break the gateway unpublisihing if one gateway unreachable
                 */
                    log.error("Error occurred when removing default api from gateway " + environmentName, axisFault);
                    failedEnvironmentsMap.put(environmentName, axisFault.getMessage());
                }
            }
        }
        return failedEnvironmentsMap;
    }
 
Example 7
Source File: APIGatewayManager.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Checks whether the API has been published.
 *
 * @param api          - The API to be checked.
 * @param tenantDomain - Tenant Domain of the publisher
 * @return True if the API is available in at least one Gateway. False if available in none.
 */
public boolean isAPIPublished(API api, String tenantDomain) throws APIManagementException {

    if (gatewayArtifactSynchronizerProperties.isPublishDirectlyToGatewayEnabled()) {
        for (Environment environment : environments.values()) {
            try {
                APIGatewayAdminClient client = new APIGatewayAdminClient(environment);
                // If the API exists in at least one environment, consider as
                // published and return true.
                APIIdentifier id = api.getId();
                if (client.getApi(tenantDomain, id) != null) {
                    return true;
                }
            } catch (AxisFault axisFault) {
                /*
                didn't throw this exception to check api available in all the environments
                therefore we didn't throw exception to avoid if gateway unreachable affect
                */
                if (!APIConstants.CREATED.equals(api.getStatus())) {
                    log.error("Error occurred when check api is published on gateway" + environment.getName(),
                            axisFault);
                }
            }
        }
    } else {
        if (saveArtifactsToStorage){
            return artifactSaver.isAPIPublished(api.getUUID());
        }
    }
    return false;
}
 
Example 8
Source File: APIGatewayManager.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Get the endpoint Security type of the published API
 *
 * @param api          - The API to be checked.
 * @param tenantDomain - Tenant Domain of the publisher
 * @return Endpoint security type; Basic or Digest
 */
public String getAPIEndpointSecurityType(API api, String tenantDomain) throws APIManagementException {

    for (Environment environment : environments.values()) {
        try {
            APIGatewayAdminClient client = new APIGatewayAdminClient(environment);
            APIIdentifier id = api.getId();
            APIData apiData = client.getApi(tenantDomain, id);
            if (apiData != null) {
                ResourceData[] resourceData = apiData.getResources();
                for (ResourceData resource : resourceData) {
                    if (resource != null && resource.getInSeqXml() != null) {
                        if(resource.getInSeqXml().contains("DigestAuthMediator")) {
                            return APIConstants.APIEndpointSecurityConstants.DIGEST_AUTH;
                        } else if(resource.getInSeqXml().contains("OAuthMediator")) {
                            return APIConstants.APIEndpointSecurityConstants.OAUTH;
                        }
                    }
                }
            }
        } catch (AxisFault axisFault) {
            // didn't throw this exception to check api available in all the environments
            // therefore we didn't throw exception to avoid if gateway unreachable affect
            if (!APIConstants.CREATED.equals(api.getStatus())) {
                log.error("Error occurred when check api endpoint security type on gateway"
                        + environment.getName(), axisFault);
            }
        }
    }
    return APIConstants.APIEndpointSecurityConstants.BASIC_AUTH;
}
 
Example 9
Source File: APIImportUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * This method adds API sequences to the imported API. If the sequence is a newly defined one, it is added.
 *
 * @param pathToArchive location of the extracted folder of the API
 */
private static void addSOAPToREST(String pathToArchive, API importedApi, Registry registry)
        throws APIImportExportException {

    String inFlowFileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + IN;
    String outFlowFileLocation = pathToArchive + File.separator + SOAPTOREST + File.separator + OUT;

    //Adding in-sequence, if any
    if (CommonUtil.checkFileExistence(inFlowFileLocation)) {
        APIIdentifier apiId = importedApi.getId();
        String soapToRestLocationIn =
                APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiId.getProviderName()
                        + RegistryConstants.PATH_SEPARATOR + apiId.getApiName() + RegistryConstants.PATH_SEPARATOR
                        + apiId.getVersion() + RegistryConstants.PATH_SEPARATOR
                        + SOAPToRESTConstants.SequenceGen.SOAP_TO_REST_IN_RESOURCE;
        String soapToRestLocationOut =
                APIConstants.API_ROOT_LOCATION + RegistryConstants.PATH_SEPARATOR + apiId.getProviderName()
                        + RegistryConstants.PATH_SEPARATOR + apiId.getApiName() + RegistryConstants.PATH_SEPARATOR
                        + apiId.getVersion() + RegistryConstants.PATH_SEPARATOR
                        + SOAPToRESTConstants.SequenceGen.SOAP_TO_REST_OUT_RESOURCE;
        try {
            // Import inflow mediation logic
            Path inFlowDirectory = Paths.get(inFlowFileLocation);
            ImportMediationLogic(inFlowDirectory, registry, soapToRestLocationIn);

            // Import outflow mediation logic
            Path outFlowDirectory = Paths.get(outFlowFileLocation);
            ImportMediationLogic(outFlowDirectory, registry, soapToRestLocationOut);

        } catch (DirectoryIteratorException e) {
            throw new APIImportExportException("Error in importing SOAP to REST mediation logic", e);
        }
    }
}
 
Example 10
Source File: SearchResultMappingUtil.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Get API result representation for content search
 * @param api API
 * @return
 */
public static APISearchResultDTO fromAPIToAPIResultDTO(API api) {
    APISearchResultDTO apiResultDTO = new APISearchResultDTO();
    apiResultDTO.setId(api.getUUID());
    APIIdentifier apiId = api.getId();
    apiResultDTO.setName(apiId.getApiName());
    apiResultDTO.setVersion(apiId.getVersion());
    apiResultDTO.setProvider(APIUtil.replaceEmailDomainBack(apiId.getProviderName()));
    String context = api.getContextTemplate();
    if (context.endsWith("/" + RestApiConstants.API_VERSION_PARAM)) {
        context = context.replace("/" + RestApiConstants.API_VERSION_PARAM, "");
    }
    apiResultDTO.setContext(context);
    apiResultDTO.setAvgRating(String.valueOf(api.getRating()));
    APIBusinessInformationDTO apiBusinessInformationDTO = new APIBusinessInformationDTO();
    apiBusinessInformationDTO.setBusinessOwner(api.getBusinessOwner());
    apiBusinessInformationDTO.setBusinessOwnerEmail(api.getBusinessOwnerEmail());
    apiBusinessInformationDTO.setTechnicalOwner(api.getTechnicalOwner());
    apiBusinessInformationDTO.setTechnicalOwnerEmail(api.getTechnicalOwnerEmail());
    apiResultDTO.setBusinessInformation(apiBusinessInformationDTO);
    apiResultDTO.setType(SearchResultDTO.TypeEnum.API);
    apiResultDTO.setTransportType(api.getType());
    apiResultDTO.setDescription(api.getDescription());
    apiResultDTO.setStatus(api.getStatus());
    apiResultDTO.setThumbnailUri(api.getThumbnailUrl());
    return apiResultDTO;
}
 
Example 11
Source File: ApisApiServiceImpl.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
@Override
public Response getWSDLOfAPI(String apiId, String labelName, String environmentName, String ifNoneMatch,
                             String xWSO2Tenant, MessageContext messageContext) throws APIManagementException {
    APIConsumer apiConsumer = RestApiUtil.getLoggedInUserConsumer();
    API api = apiConsumer.getLightweightAPIByUUID(apiId, xWSO2Tenant);
    APIIdentifier apiIdentifier = api.getId();

    List<Environment> environments = APIUtil.getEnvironmentsOfAPI(api);
    if (environments != null && environments.size() > 0) {
        if (StringUtils.isEmpty(labelName) && StringUtils.isEmpty(environmentName)) {
            environmentName = api.getEnvironments().iterator().next();
        }

        Environment selectedEnvironment = null;
        for (Environment environment: environments) {
           if (environment.getName().equals(environmentName)) {
               selectedEnvironment = environment;
               break;
           }
        }

        if (selectedEnvironment == null) {
            throw new APIManagementException(ExceptionCodes.from(ExceptionCodes.GATEWAY_ENVIRONMENT_NOT_FOUND,
                    environmentName));
        }
        ResourceFile wsdl = apiConsumer.getWSDL(apiIdentifier, selectedEnvironment.getName(),
                selectedEnvironment.getType());

        return RestApiUtil.getResponseFromResourceFile(apiIdentifier.toString(), wsdl);
    } else {
        throw new APIManagementException(ExceptionCodes.from(ExceptionCodes.NO_GATEWAY_ENVIRONMENTS_ADDED,
                apiIdentifier.toString()));
    }
}
 
Example 12
Source File: ApplicationImportExportManager.java    From carbon-apimgt with Apache License 2.0 5 votes vote down vote up
/**
 * Check whether a target Tier is available to subscribe
 *
 * @param targetTier Target Tier
 * @param api        - {@link org.wso2.carbon.apimgt.api.model.API}
 * @return true, if the target tier is available
 */
private boolean isTierAvailable(Tier targetTier, API api) {
    APIIdentifier apiId = api.getId();
    Set<Tier> availableTiers = api.getAvailableTiers();
    if (availableTiers.contains(targetTier)) {
        return true;
    } else {
        log.error("Tier:" + targetTier.getName() + " is not available for API " + apiId.getApiName() + "-" +
                apiId.getVersion());
        return false;
    }
}
 
Example 13
Source File: APIExportUtil.java    From carbon-apimgt with Apache License 2.0 4 votes vote down vote up
/**
 * Retrieve available custom sequences and API specific sequences for API export.
 *
 * @param api      exporting API
 * @param registry current tenant registry
 * @throws APIImportExportException If an error occurs while exporting sequences
 */
private static void exportSequences(String archivePath, API api, Registry registry) throws APIImportExportException {

    Map<String, String> sequences = new HashMap<>();
    APIIdentifier apiIdentifier = api.getId();
    String seqArchivePath = archivePath.concat(File.separator + "Sequences");

    if (api.getInSequence() != null) {
        sequences.put(APIConstants.API_CUSTOM_SEQUENCE_TYPE_IN, api.getInSequence());
    }

    if (api.getOutSequence() != null) {
        sequences.put(APIConstants.API_CUSTOM_SEQUENCE_TYPE_OUT, api.getOutSequence());
    }

    if (api.getFaultSequence() != null) {
        sequences.put(APIConstants.API_CUSTOM_SEQUENCE_TYPE_FAULT, api.getFaultSequence());
    }

    if (!sequences.isEmpty()) {
        CommonUtil.createDirectory(seqArchivePath);
        for (Map.Entry<String, String> sequence : sequences.entrySet()) {
            AbstractMap.SimpleEntry<String, OMElement> sequenceDetails;
            String sequenceName = sequence.getValue();
            String direction = sequence.getKey();
            String pathToExportedSequence = seqArchivePath + File.separator + direction + "-sequence" + File.separator;
            if (sequenceName != null) {
                sequenceDetails = getCustomSequence(sequenceName, direction, registry);
                if (sequenceDetails == null) {
                    //If sequence doesn't exist in 'apimgt/customsequences/{in/out/fault}' directory check in API
                    //specific registry path
                    sequenceDetails = getAPISpecificSequence(api.getId(), sequenceName, direction, registry);
                    pathToExportedSequence += APIImportExportConstants.CUSTOM_TYPE + File.separator;
                }
                writeSequenceToFile(pathToExportedSequence, sequenceDetails, apiIdentifier);
            }
        }
    } else if (log.isDebugEnabled()) {
        log.debug("No custom sequences available for API: " + apiIdentifier.getApiName() + StringUtils.SPACE
                + APIConstants.API_DATA_VERSION + ": " + apiIdentifier.getVersion()
                + ". Skipping custom sequence export.");
    }
}
 
Example 14
Source File: RestAPIStoreUtils.java    From carbon-apimgt with Apache License 2.0 3 votes vote down vote up
/**
 * Retrieves the API Identifier object from given API UUID and tenant domain
 *
 * @param apiId API Identifier UUID
 * @param requestedTenantDomain tenant which API resides
 * @return API Identifier object 
 * @throws APIManagementException if the retrieval fails
 */
public static APIIdentifier getAPIIdentifierFromUUID(String apiId, String requestedTenantDomain)
        throws APIManagementException {
    APIConsumer apiConsumer = RestApiUtil.getLoggedInUserConsumer();
    API api = apiConsumer.getLightweightAPIByUUID(apiId, requestedTenantDomain);
    return  api.getId();
}