private MeshNetwork prepareNetwork(@NonNull final MeshNetwork network,
                                       @NonNull final NetworkKeysConfig networkKeysConfig,
                                       @NonNull final ApplicationKeysConfig applicationKeysConfig,
                                       @NonNull final NodesConfig nodesConfig,
                                       @NonNull final ProvisionersConfig provisionersConfig,
                                       @NonNull final GroupsConfig groupsConfig,
                                       @NonNull final ScenesConfig scenesConfig) {

        // Initial list of nodes to export
        if (nodesConfig.getConfig() instanceof NodesConfig.ExportWithoutDeviceKey) {
            for (ProvisionedMeshNode node : network.nodes)
                node.setDeviceKey(null);
        } else if (nodesConfig.getConfig() instanceof NodesConfig.ExportSome) {
            network.nodes.clear();
            final List<ProvisionedMeshNode> withDeviceKey = ((NodesConfig.ExportSome) nodesConfig.getConfig()).getWithDeviceKey();
            final List<ProvisionedMeshNode> withoutDeviceKey = ((NodesConfig.ExportSome) nodesConfig.getConfig()).getWithoutDeviceKey();
            for (ProvisionedMeshNode node : withoutDeviceKey)
                node.setDeviceKey(null);
            network.nodes.addAll(withDeviceKey);
            network.nodes.addAll(withoutDeviceKey);

            // Add any missing provisioner nodes if they were not selected when selecting nodes.
            for (Provisioner provisioner : network.provisioners) {
                if (!isProvisionerExistsInNodes(provisioner, network.nodes)) {
                    network.nodes.add(new ProvisionedMeshNode(provisioner, network.netKeys, network.appKeys));
                }
            }
        }

        // Include the selected provisioners
        // List of provisioners to export
        if (provisionersConfig.getConfig() instanceof ProvisionersConfig.ExportSome) {
            // First Let's exclude provisioners that are not nodes
            final ListIterator<Provisioner> provisionerListIterator = network.provisioners.listIterator();
            while (provisionerListIterator.hasNext()) {
                final Provisioner provisioner = provisionerListIterator.next();
                if (!isProvisionerExistsInNodes(provisioner, network.nodes)) {
                    provisionerListIterator.remove();
                }
            }

            // Now let's add the selected ones
            // We must go through all items to ensure there are no duplicates
            final List<Provisioner> selectedProvisioners = ((ProvisionersConfig.ExportSome) provisionersConfig.getConfig()).getProvisioners();
            for (Provisioner provisioner : selectedProvisioners) {
                if (!network.isProvisionerUuidInUse(provisioner.getProvisionerUuid())) {
                    network.provisioners.add(provisioner);
                }
            }
        }

        // List of Network Keys to export
        if (networkKeysConfig.getConfig() instanceof NetworkKeysConfig.ExportSome) {
            network.setNetKeys(((NetworkKeysConfig.ExportSome) networkKeysConfig.getConfig()).getKeys());
        }

        // List of Application Keys to export
        if (applicationKeysConfig.getConfig() instanceof ApplicationKeysConfig.ExportSome) {
            network.appKeys.clear();
            // List of application keys set in the configuration, but we must only export the keys that are bound to that network key.
            final List<ApplicationKey> keys = ((ApplicationKeysConfig.ExportSome) applicationKeysConfig.getConfig()).getKeys();
            for (ApplicationKey key : keys) {
                if (isApplicationKeyBound(network.getNetKeys(), key)) {
                    network.appKeys.add(key);
                }
            }
        }

        // Exclude nodes unknown to network keys
        // TODO what will happen to the provisioner if the node is to excluded due to an unknown network key?
        final ListIterator<ProvisionedMeshNode> nodeListIterator = network.nodes.listIterator();
        while (nodeListIterator.hasNext()) {
            final ProvisionedMeshNode node = nodeListIterator.next();
            if (!isNetworkKeyAdded(node, network.getNetKeys())) {
                nodeListIterator.remove();
                continue;
            }
            excludeAppKeys(node, network.appKeys);
        }

        if (groupsConfig.getConfig() instanceof GroupsConfig.ExportRelated) {
            excludeNonRelatedGroups(network);
        } else if (groupsConfig.getConfig() instanceof GroupsConfig.ExportSome) {
            network.groups = ((GroupsConfig.ExportSome) groupsConfig.getConfig()).getGroups();
            // If subscriptions/publications uses any excluded group addresses, let's remove them.
            for (ProvisionedMeshNode node : network.getNodes()) {
                for (Element element : node.getElements().values()) {
                    for (MeshModel model : element.getMeshModels().values()) {
                        for (Group group : network.groups) {
                            if (model.getPublicationSettings() != null &&
                                    isValidGroupAddress(model.getPublicationSettings().getPublishAddress()) &&
                                    model.getPublicationSettings().getPublishAddress() != group.getAddress()) {
                                model.setPublicationSettings(null);
                            }
                            model.getSubscribedAddresses().remove((Integer) group.getAddress());
                        }
                    }
                }
            }
        }

        if (scenesConfig.getConfig() instanceof ScenesConfig.ExportSome) {
            network.scenes = ((ScenesConfig.ExportSome) scenesConfig.getConfig()).getScenes();
        }
        removeExcludedNodesFromScenes(network.nodes, network.scenes);
        return network;
    }
Configures and returns a network with the export configuration provided.

@param network               MeshNetwork.
@param networkKeysConfig     Network Keys configuration.
@param applicationKeysConfig Application Keys configuration.
@param nodesConfig           Nodes configuration.
@param provisionersConfig    Provisioners configuration.
@param groupsConfig          Groups configuration.
@param scenesConfig          Scenes configuration.
mesh/src/main/java/no/nordicsemi/android/mesh/ImportExportUtils.java