Source:
public Network convertToLegacyNetwork(EnvironmentNetworkResponse source, String availabilityZone) { Network result = new Network(); result.setName(missingResourceNameGenerator.generateName(APIResourceType.NETWORK)); result.setSubnetCIDR(null); result.setOutboundInternetTraffic(source.getOutboundInternetTraffic()); result.setNetworkCidrs(source.getNetworkCidrs()); Map<String, Object> attributes = new HashMap<>(); Optional<CloudSubnet> cloudSubnet = chooseSubnet(source.getPreferedSubnetId(), source.getSubnetMetas(), availabilityZone, true); if (cloudSubnet.isEmpty()) { throw new BadRequestException("No subnet for the given availability zone: " + availabilityZone); } LOGGER.debug("Chosen subnet: {}", cloudSubnet.get()); if (source.getPublicEndpointAccessGateway() == PublicEndpointAccessGateway.ENABLED) { String selectedAZ = cloudSubnet.get().getAvailabilityZone(); Map<String, CloudSubnet> subnetsToParse; if (source.getGatewayEndpointSubnetMetas() == null || source.getGatewayEndpointSubnetMetas().isEmpty()) { subnetsToParse = source.getSubnetMetas(); } else { subnetsToParse = source.getGatewayEndpointSubnetMetas(); } Map<String, CloudSubnet> publicSubnetMetas = subnetsToParse.entrySet().stream() .filter(entry -> !entry.getValue().isPrivateSubnet()) .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); Optional<CloudSubnet> endpointGatewayCloudSubnet = chooseSubnet(null, publicSubnetMetas, selectedAZ, false); if (endpointGatewayCloudSubnet.isEmpty()) { throw new BadRequestException("Could not find public subnet in availability zone: " + availabilityZone); } LOGGER.debug("Chosen endpoint gateway subnet: {}", endpointGatewayCloudSubnet.get()); attributes.put("endpointGatewaySubnetId", endpointGatewayCloudSubnet.get().getId()); } attributes.put("subnetId", cloudSubnet.get().getId()); attributes.put("cloudPlatform", getCloudPlatform().name()); attributes.putAll(getAttributesForLegacyNetwork(source)); try { result.setAttributes(new Json(attributes)); } catch (IllegalArgumentException e) { LOGGER.debug("Environment's network could not be converted to network.", e); } return result; }

Target:
public Network convertToLegacyNetwork(EnvironmentNetworkResponse source, String availabilityZone) { Network result = new Network(); result.setName(missingResourceNameGenerator.generateName(APIResourceType.NETWORK)); result.setSubnetCIDR(null); result.setOutboundInternetTraffic(source.getOutboundInternetTraffic()); result.setNetworkCidrs(source.getNetworkCidrs()); Map<String, Object> attributes = new HashMap<>(); Optional<CloudSubnet> cloudSubnet = chooseSubnet(source.getPreferedSubnetId(), source.getSubnetMetas(), availabilityZone, true); if (cloudSubnet.isEmpty()) { throw new BadRequestException("No subnet for the given availability zone: " + availabilityZone); } LOGGER.debug("Chosen subnet: {}", cloudSubnet.get()); attributes.put("subnetId", cloudSubnet.get().getId()); attributes.put("cloudPlatform", getCloudPlatform().name()); attributes.putAll(getAttributesForLegacyNetwork(source)); chooseSubnetForEndpointGateway(source, cloudSubnet.get(), attributes); try { result.setAttributes(new Json(attributes)); } catch (IllegalArgumentException e) { LOGGER.debug("Environment's network could not be converted to network.", e); } return result; }