Search in sources :

Example 6 with EnvironmentDto

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto in project carbon-apimgt by wso2.

the class EnvironmentMappingUtil method fromEnvironmentCollectionToDTO.

/**
 * Converts a List object of SubscribedAPIs into a DTO.
 *
 * @param environmentCollection a collection of Environment objects
 * @return EnvironmentListDTO object containing EnvironmentDTOs
 */
public static EnvironmentListDTO fromEnvironmentCollectionToDTO(Collection<Environment> environmentCollection) {
    EnvironmentListDTO environmentListDTO = new EnvironmentListDTO();
    List<EnvironmentDTO> environmentDTOs = environmentListDTO.getList();
    if (environmentDTOs == null) {
        environmentDTOs = new ArrayList<>();
        environmentListDTO.setList(environmentDTOs);
    }
    for (Environment environment : environmentCollection) {
        environmentDTOs.add(fromEnvironmentToDTO(environment));
    }
    environmentListDTO.setCount(environmentDTOs.size());
    return environmentListDTO;
}
Also used : EnvironmentListDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentListDTO) EnvironmentDTO(org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentDTO) ExternalEnvironment(org.wso2.carbon.apimgt.impl.ExternalEnvironment) Environment(org.wso2.carbon.apimgt.api.model.Environment)

Example 7 with EnvironmentDto

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto in project carbon-apimgt by wso2.

the class RuntimeArtifactGeneratorUtil method generateMetadataArtifact.

public static RuntimeArtifactDto generateMetadataArtifact(String tenantDomain, String apiId, String gatewayLabel) throws APIManagementException {
    List<APIRuntimeArtifactDto> gatewayArtifacts = getRuntimeArtifacts(apiId, gatewayLabel, tenantDomain);
    if (gatewayArtifacts != null) {
        try {
            MetadataDescriptorDto metadataDescriptorDto = new MetadataDescriptorDto();
            Map<String, ApiMetadataProjectDto> deploymentsMap = new HashMap<>();
            // "tempDirectory" is the root artifact directory
            File tempDirectory = CommonUtil.createTempDirectory(null);
            for (APIRuntimeArtifactDto apiRuntimeArtifactDto : gatewayArtifacts) {
                if (apiRuntimeArtifactDto.isFile()) {
                    String fileName = apiRuntimeArtifactDto.getApiId().concat("-").concat(apiRuntimeArtifactDto.getRevision());
                    ApiMetadataProjectDto apiProjectDto = deploymentsMap.get(fileName);
                    if (apiProjectDto == null) {
                        apiProjectDto = new ApiMetadataProjectDto();
                        deploymentsMap.put(fileName, apiProjectDto);
                        apiProjectDto.setApiFile(fileName);
                        apiProjectDto.setEnvironments(new HashSet<>());
                        apiProjectDto.setOrganizationId(apiRuntimeArtifactDto.getOrganization());
                        apiProjectDto.setVersion(apiRuntimeArtifactDto.getVersion());
                        apiProjectDto.setApiContext(apiRuntimeArtifactDto.getContext());
                    }
                    EnvironmentDto environment = new EnvironmentDto();
                    environment.setName(apiRuntimeArtifactDto.getLabel());
                    environment.setVhost(apiRuntimeArtifactDto.getVhost());
                    apiProjectDto.getEnvironments().add(environment);
                }
            }
            metadataDescriptorDto.setMetadataDescriptor(new HashSet<>(deploymentsMap.values()));
            String descriptorFile = Paths.get(tempDirectory.getAbsolutePath(), APIConstants.GatewayArtifactConstants.DEPLOYMENT_DESCRIPTOR_FILE).toString();
            CommonUtil.writeDtoToFile(descriptorFile, ExportFormat.JSON, APIConstants.GatewayArtifactConstants.DEPLOYMENT_DESCRIPTOR_FILE_TYPE, metadataDescriptorDto);
            RuntimeArtifactDto runtimeArtifactDto = new RuntimeArtifactDto();
            runtimeArtifactDto.setArtifact(new File(descriptorFile.concat(APIConstants.JSON_FILE_EXTENSION)));
            runtimeArtifactDto.setFile(true);
            return runtimeArtifactDto;
        } catch (APIImportExportException | IOException e) {
            throw new APIManagementException("Error while Generating API artifact", e);
        }
    } else {
        throw new APIManagementException("No API Artifacts", ExceptionCodes.NO_API_ARTIFACT_FOUND);
    }
}
Also used : MetadataDescriptorDto(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.MetadataDescriptorDto) HashMap(java.util.HashMap) EnvironmentDto(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto) RuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.RuntimeArtifactDto) APIRuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto) IOException(java.io.IOException) ApiMetadataProjectDto(org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.ApiMetadataProjectDto) APIRuntimeArtifactDto(org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto) APIManagementException(org.wso2.carbon.apimgt.api.APIManagementException) APIImportExportException(org.wso2.carbon.apimgt.impl.importexport.APIImportExportException) File(java.io.File)

Example 8 with EnvironmentDto

use of org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto 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

Environment (org.wso2.carbon.apimgt.api.model.Environment)4 File (java.io.File)2 IOException (java.io.IOException)2 URI (java.net.URI)2 URISyntaxException (java.net.URISyntaxException)2 HashMap (java.util.HashMap)2 APIAdmin (org.wso2.carbon.apimgt.api.APIAdmin)2 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)2 APIAdminImpl (org.wso2.carbon.apimgt.impl.APIAdminImpl)2 ExternalEnvironment (org.wso2.carbon.apimgt.impl.ExternalEnvironment)2 APIRuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.APIRuntimeArtifactDto)2 RuntimeArtifactDto (org.wso2.carbon.apimgt.impl.dto.RuntimeArtifactDto)2 EnvironmentDto (org.wso2.carbon.apimgt.impl.gatewayartifactsynchronizer.dto.EnvironmentDto)2 APIImportExportException (org.wso2.carbon.apimgt.impl.importexport.APIImportExportException)2 EnvironmentDTO (org.wso2.carbon.apimgt.rest.api.admin.v1.dto.EnvironmentDTO)2 EnvironmentDTO (org.wso2.carbon.apimgt.rest.api.publisher.v1.dto.EnvironmentDTO)2 InputStream (java.io.InputStream)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Map (java.util.Map)1