Search in sources :

Example 1 with AdditionalSubscriptionInfoSolaceURLsDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO in project carbon-apimgt by wso2.

the class AdditionalSubscriptionInfoMappingUtil method mapSolaceURLsToStoreDTO.

/**
 * Sets the Endpoint URLs For Solace API according to the protocols
 *
 * @param organizationName Solace broker organization name
 * @param environmentName      Name of the  Solace environment
 * @param availableProtocols List of available protocols
 * @return List containing AdditionalSubscriptionInfoSolaceURLsDTO
 * @throws APIManagementException if error occurred when retrieving protocols URLs from Solace broker
 */
private static List<AdditionalSubscriptionInfoSolaceURLsDTO> mapSolaceURLsToStoreDTO(String organizationName, String environmentName, List<String> availableProtocols) throws APIManagementException {
    Map<String, Environment> gatewayEnvironments = APIUtil.getReadOnlyGatewayEnvironments();
    Environment solaceEnvironment = null;
    // Get Solace broker environment details
    for (Map.Entry<String, Environment> entry : gatewayEnvironments.entrySet()) {
        if (SolaceConstants.SOLACE_ENVIRONMENT.equals(entry.getValue().getProvider())) {
            solaceEnvironment = entry.getValue();
        }
    }
    if (solaceEnvironment != null) {
        List<SolaceURLsDTO> solaceURLsDTOEntries = SolaceStoreUtils.getSolaceURLsInfo(solaceEnvironment, organizationName, environmentName, availableProtocols);
        List<AdditionalSubscriptionInfoSolaceURLsDTO> solaceURLsDTOs = new ArrayList<>();
        for (SolaceURLsDTO entry : solaceURLsDTOEntries) {
            AdditionalSubscriptionInfoSolaceURLsDTO subscriptionInfoSolaceProtocolURLsDTO = new AdditionalSubscriptionInfoSolaceURLsDTO();
            subscriptionInfoSolaceProtocolURLsDTO.setProtocol(entry.getProtocol());
            subscriptionInfoSolaceProtocolURLsDTO.setEndpointURL(entry.getEndpointURL());
            solaceURLsDTOs.add(subscriptionInfoSolaceProtocolURLsDTO);
        }
        return solaceURLsDTOs;
    } else {
        throw new APIManagementException("Solace Environment configurations are not provided properly");
    }
}
Also used : APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) ArrayList(java.util.ArrayList) Environment(org.wso2.carbon.apimgt.api.model.Environment) AdditionalSubscriptionInfoSolaceURLsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO) SolaceURLsDTO(org.wso2.carbon.apimgt.solace.dtos.SolaceURLsDTO) Map(java.util.Map) AdditionalSubscriptionInfoSolaceURLsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO)

Example 2 with AdditionalSubscriptionInfoSolaceURLsDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO in project carbon-apimgt by wso2.

the class AdditionalSubscriptionInfoMappingUtil method fromAdditionalSubscriptionInfoToDTO.

/**
 * Converts a AdditionalSubscriptionInfo object into AdditionalSubscriptionInfoDTO
 *
 * @param subscription SubscribedAPI object
 * @param organization Identifier of the organization
 * @return SubscriptionDTO corresponds to SubscribedAPI object
 */
public static AdditionalSubscriptionInfoDTO fromAdditionalSubscriptionInfoToDTO(SubscribedAPI subscription, String organization) throws APIManagementException {
    String username = RestApiCommonUtil.getLoggedInUsername();
    APIConsumer apiConsumer = RestApiCommonUtil.getLoggedInUserConsumer();
    AdditionalSubscriptionInfoDTO additionalSubscriptionInfoDTO = new AdditionalSubscriptionInfoDTO();
    additionalSubscriptionInfoDTO.setSubscriptionId(subscription.getUUID());
    APIIdentifier apiId = subscription.getApiId();
    API api = null;
    if (apiId != null) {
        try {
            api = apiConsumer.getLightweightAPIByUUID(apiId.getUUID(), organization);
        } catch (APIManagementException e) {
            String msg = "User :" + username + " does not have access to the API " + apiId;
            RestApiUtil.handleInternalServerError(msg, e, log);
        }
    }
    additionalSubscriptionInfoDTO.setApiId(api.getUuid());
    // Set Application information
    Application application = subscription.getApplication();
    application = apiConsumer.getApplicationByUUID(application.getUUID());
    additionalSubscriptionInfoDTO.setApplicationId(subscription.getApplication().getUUID());
    additionalSubscriptionInfoDTO.setApplicationName(application.getName());
    additionalSubscriptionInfoDTO.setIsSolaceAPI(SolaceNotifierUtils.checkWhetherAPIDeployedToSolaceUsingRevision(api));
    if (additionalSubscriptionInfoDTO.isIsSolaceAPI()) {
        // Set Solace organization details if API is a Solace API
        additionalSubscriptionInfoDTO.setSolaceOrganization(SolaceNotifierUtils.getThirdPartySolaceBrokerOrganizationNameOfAPIDeployment(api));
        Map<String, Environment> gatewayEnvironmentMap = APIUtil.getReadOnlyGatewayEnvironments();
        Environment solaceEnvironment = null;
        for (Map.Entry<String, Environment> entry : gatewayEnvironmentMap.entrySet()) {
            if (SolaceConstants.SOLACE_ENVIRONMENT.equals(entry.getValue().getProvider())) {
                solaceEnvironment = entry.getValue();
            }
        }
        if (solaceEnvironment != null) {
            List<SolaceDeployedEnvironmentDTO> solaceDeployedEnvironmentsDTOS = SolaceStoreUtils.getSolaceDeployedEnvsInfo(solaceEnvironment, additionalSubscriptionInfoDTO.getSolaceOrganization(), application.getUUID());
            List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> solaceEnvironments = new ArrayList<>();
            for (SolaceDeployedEnvironmentDTO solaceDeployedEnvironmentEntry : solaceDeployedEnvironmentsDTOS) {
                // Set Solace environment details
                AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO solaceDeployedEnvironmentsDTO = new AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO();
                solaceDeployedEnvironmentsDTO.setEnvironmentName(solaceDeployedEnvironmentEntry.getEnvironmentName());
                solaceDeployedEnvironmentsDTO.setEnvironmentDisplayName(solaceDeployedEnvironmentEntry.getEnvironmentDisplayName());
                solaceDeployedEnvironmentsDTO.setOrganizationName(solaceDeployedEnvironmentEntry.getOrganizationName());
                // Set Solace URLs
                List<AdditionalSubscriptionInfoSolaceURLsDTO> endpointUrls = new ArrayList<>();
                List<SolaceURLsDTO> solaceURLsDTOS = solaceDeployedEnvironmentEntry.getSolaceURLs();
                for (SolaceURLsDTO entry : solaceURLsDTOS) {
                    AdditionalSubscriptionInfoSolaceURLsDTO solaceURLsDTO = new AdditionalSubscriptionInfoSolaceURLsDTO();
                    solaceURLsDTO.setProtocol(entry.getProtocol());
                    solaceURLsDTO.setEndpointURL(entry.getEndpointURL());
                    endpointUrls.add(solaceURLsDTO);
                }
                solaceDeployedEnvironmentsDTO.setSolaceURLs(endpointUrls);
                // Set Solace Topic Objects
                solaceDeployedEnvironmentsDTO.setSolaceTopicsObject(mapSolaceTopicObjects(solaceDeployedEnvironmentEntry.getSolaceTopicsObject()));
                solaceEnvironments.add(solaceDeployedEnvironmentsDTO);
            }
            additionalSubscriptionInfoDTO.setSolaceDeployedEnvironments(solaceEnvironments);
        }
    }
    return additionalSubscriptionInfoDTO;
}
Also used : AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO) ArrayList(java.util.ArrayList) AdditionalSubscriptionInfoSolaceURLsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO) SolaceURLsDTO(org.wso2.carbon.apimgt.solace.dtos.SolaceURLsDTO) AdditionalSubscriptionInfoSolaceURLsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO) AdditionalSubscriptionInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) Environment(org.wso2.carbon.apimgt.api.model.Environment) APIIdentifier(org.wso2.carbon.apimgt.api.model.APIIdentifier) API(org.wso2.carbon.apimgt.api.model.API) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI) APIConsumer(org.wso2.carbon.apimgt.api.APIConsumer) Application(org.wso2.carbon.apimgt.api.model.Application) Map(java.util.Map) SolaceDeployedEnvironmentDTO(org.wso2.carbon.apimgt.solace.dtos.SolaceDeployedEnvironmentDTO)

Example 3 with AdditionalSubscriptionInfoSolaceURLsDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO in project carbon-apimgt by wso2.

the class AdditionalSubscriptionInfoMappingUtil method setEndpointURLsForApiDto.

/**
 * Sets the Endpoint URLs for the APIDTO object using solace protocols
 *
 * @param api          API object
 * @param tenantDomain Tenant Domain
 * @return List containing AdditionalSubscriptionInfoSolaceEndpointURLsDTOs
 * @throws APIManagementException if error occurred when retrieving protocols URLs
 */
public static List<String> setEndpointURLsForApiDto(API api, String tenantDomain) throws APIManagementException {
    List<AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO> urlsList = setSolaceEnvironmentDetailsForSubscription(api, tenantDomain);
    List<String> urlsStringList = new ArrayList<>();
    if (!urlsList.isEmpty()) {
        for (AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO item : urlsList) {
            List<AdditionalSubscriptionInfoSolaceURLsDTO> protocols = item.getSolaceURLs();
            for (AdditionalSubscriptionInfoSolaceURLsDTO protocol : protocols) {
                // Create Json string to return
                JSONObject asyncProtocolsObj = new JSONObject();
                asyncProtocolsObj.put("protocol", protocol.getProtocol());
                asyncProtocolsObj.put("endPointUrl", protocol.getEndpointURL());
                urlsStringList.add(asyncProtocolsObj.toString());
            }
        }
    }
    return urlsStringList;
}
Also used : AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) AdditionalSubscriptionInfoSolaceURLsDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO)

Aggregations

ArrayList (java.util.ArrayList)3 AdditionalSubscriptionInfoSolaceURLsDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO)3 Map (java.util.Map)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 Environment (org.wso2.carbon.apimgt.api.model.Environment)2 AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO)2 SolaceURLsDTO (org.wso2.carbon.apimgt.solace.dtos.SolaceURLsDTO)2 JSONObject (org.json.JSONObject)1 APIConsumer (org.wso2.carbon.apimgt.api.APIConsumer)1 API (org.wso2.carbon.apimgt.api.model.API)1 APIIdentifier (org.wso2.carbon.apimgt.api.model.APIIdentifier)1 Application (org.wso2.carbon.apimgt.api.model.Application)1 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)1 AdditionalSubscriptionInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoDTO)1 SolaceDeployedEnvironmentDTO (org.wso2.carbon.apimgt.solace.dtos.SolaceDeployedEnvironmentDTO)1