Search in sources :

Example 1 with ExternalEnvironment

use of org.wso2.carbon.apimgt.impl.ExternalEnvironment in project carbon-apimgt by wso2.

the class EnvironmentMappingUtil method fromEnvironmentToDTO.

/**
 * Converts an Environment object into EnvironmentDTO.
 *
 * @param environment Environment object
 * @return EnvironmentDTO object corresponding to the given Environment object
 */
public static EnvironmentDTO fromEnvironmentToDTO(Environment environment) {
    EnvironmentDTO environmentDTO = new EnvironmentDTO();
    environmentDTO.setId(environment.getUuid());
    environmentDTO.setName(environment.getName());
    environmentDTO.setDisplayName(environment.getDisplayName());
    environmentDTO.setType(environment.getType());
    environmentDTO.setServerUrl(environment.getServerURL());
    environmentDTO.setShowInApiConsole(environment.isShowInConsole());
    environmentDTO.setProvider(environment.getProvider());
    environmentDTO.setVhosts(environment.getVhosts().stream().map(EnvironmentMappingUtil::fromVHostToVHostDTO).collect(Collectors.toList()));
    environmentDTO.setAdditionalProperties(fromAdditionalPropertiesToAdditionalPropertiesDTO(environment.getAdditionalProperties()));
    ExternalEnvironment parser = APIUtil.getExternalEnvironment(environment.getProvider());
    if (parser != null) {
        List<GatewayEnvironmentProtocolURIDTO> endpointsList = new ArrayList<>();
        List<AsyncProtocolEndpoint> endpointUrlsList = parser.getExternalEndpointURLs(environment);
        if (endpointUrlsList != null || endpointUrlsList.size() > 0) {
            for (AsyncProtocolEndpoint asyncProtocolEndpoint : endpointUrlsList) {
                GatewayEnvironmentProtocolURIDTO gatewayEnvironmentProtocolURIDTO = new GatewayEnvironmentProtocolURIDTO();
                gatewayEnvironmentProtocolURIDTO.setProtocol(asyncProtocolEndpoint.getProtocol());
                gatewayEnvironmentProtocolURIDTO.setEndpointURI(asyncProtocolEndpoint.getProtocolUrl());
                endpointsList.add(gatewayEnvironmentProtocolURIDTO);
            }
            environmentDTO.setEndpointURIs(endpointsList);
        }
    }
    return environmentDTO;
}
Also used : EnvironmentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentDTO) ArrayList(java.util.ArrayList) GatewayEnvironmentProtocolURIDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GatewayEnvironmentProtocolURIDTO) ExternalEnvironment(org.wso2.carbon.apimgt.impl.ExternalEnvironment) AsyncProtocolEndpoint(org.wso2.carbon.apimgt.api.model.AsyncProtocolEndpoint)

Aggregations

ArrayList (java.util.ArrayList)1 AsyncProtocolEndpoint (org.wso2.carbon.apimgt.api.model.AsyncProtocolEndpoint)1 ExternalEnvironment (org.wso2.carbon.apimgt.impl.ExternalEnvironment)1 EnvironmentDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentDTO)1 GatewayEnvironmentProtocolURIDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.GatewayEnvironmentProtocolURIDTO)1