Search in sources :

Example 1 with AdditionalSubscriptionInfoDTO

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

the class AdditionalSubscriptionInfoMappingUtil method fromAdditionalSubscriptionInfoListToDTO.

/**
 * Converts a List object of SubscribedAPIs into a DTO
 *
 * @param subscriptions a list of SubscribedAPI objects
 * @param limit         max number of objects returned
 * @param offset        starting index
 * @param organization  identifier of the organization
 * @return SubscriptionListDTO object containing SubscriptionDTOs
 * @throws APIManagementException if error occurred when creating AdditionalSubscriptionInfoListDTO
 */
public static AdditionalSubscriptionInfoListDTO fromAdditionalSubscriptionInfoListToDTO(List<SubscribedAPI> subscriptions, Integer limit, Integer offset, String organization) throws APIManagementException {
    AdditionalSubscriptionInfoListDTO additionalSubscriptionInfoListDTO = new AdditionalSubscriptionInfoListDTO();
    List<AdditionalSubscriptionInfoDTO> additionalSubscriptionInfoDTOs = additionalSubscriptionInfoListDTO.getList();
    if (additionalSubscriptionInfoDTOs == null) {
        additionalSubscriptionInfoDTOs = new ArrayList<>();
        additionalSubscriptionInfoListDTO.setList(additionalSubscriptionInfoDTOs);
    }
    // Identifying the proper start and end indexes
    int size = subscriptions.size();
    int start = offset < size && offset >= 0 ? offset : Integer.MAX_VALUE;
    int end = offset + limit - 1 <= size - 1 ? offset + limit - 1 : size - 1;
    for (int i = start; i <= end; i++) {
        try {
            SubscribedAPI subscription = subscriptions.get(i);
            additionalSubscriptionInfoDTOs.add(fromAdditionalSubscriptionInfoToDTO(subscription, organization));
        } catch (APIManagementException e) {
            log.error("Error while obtaining additional info of subscriptions", e);
        }
    }
    // Set count for list
    additionalSubscriptionInfoListDTO.setCount(additionalSubscriptionInfoDTOs.size());
    return additionalSubscriptionInfoListDTO;
}
Also used : AdditionalSubscriptionInfoDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoDTO) AdditionalSubscriptionInfoListDTO(org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoListDTO) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) SubscribedAPI(org.wso2.carbon.apimgt.api.model.SubscribedAPI)

Example 2 with AdditionalSubscriptionInfoDTO

use of org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoDTO 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)

Aggregations

APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 SubscribedAPI (org.wso2.carbon.apimgt.api.model.SubscribedAPI)2 AdditionalSubscriptionInfoDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoDTO)2 ArrayList (java.util.ArrayList)1 Map (java.util.Map)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 Environment (org.wso2.carbon.apimgt.api.model.Environment)1 AdditionalSubscriptionInfoListDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoListDTO)1 AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceDeployedEnvironmentsDTO)1 AdditionalSubscriptionInfoSolaceURLsDTO (org.wso2.carbon.apimgt.rest.api.store.v1.dto.AdditionalSubscriptionInfoSolaceURLsDTO)1 SolaceDeployedEnvironmentDTO (org.wso2.carbon.apimgt.solace.dtos.SolaceDeployedEnvironmentDTO)1 SolaceURLsDTO (org.wso2.carbon.apimgt.solace.dtos.SolaceURLsDTO)1