private void AddRepositoryFoldersToTreeList(List <RepositoryFolder> repositoryFolders, FolderInfo parent)
        {
            foreach (var repositoryFolder in repositoryFolders)
            {
                Log.Verbose("Add folder with logical name {LogicalName}", repositoryFolder.LogicalName);
                var cmisFolder  = repositoryAccess.GetCmisFolder(repositoryFolder.Id);
                var addedFolder = AddFolderToTreeList(cmisFolder, false, false);
                addedFolder.Parent = parent;

                Log.Verbose("Adding children if any.");
                AddRepositoryFoldersToTreeList(repositoryFolder.Folders, addedFolder);
            }
        }
        /// <summary>
        ///     Adds the folder data to the DIP package.
        /// </summary>
        /// <param name="folder">The folder to add.</param>
        /// <param name="parent">The parent under which the new folder should be added.</param>
        /// <param name="dip">The existing dip object where the data is added.</param>
        /// <param name="indexRecords">
        ///     A list with the metadata information from the elastic index containing the ordered archive record and all its
        ///     children.
        ///     The first record in the collection is the ordered archive record
        /// </param>
        /// <param name="packageId">The packageId of the ordered item</param>
        /// <param name="filesToIgnore">A list of files that should not be included in the output</param>
        /// <exception cref="InvalidOperationException"></exception>
        /// <exception cref="ArgumentOutOfRangeException"></exception>
        private void AddFolderData(FolderInfo folder, FolderInfo parent, PaketDIP dip, List <ElasticArchiveRecord> indexRecords, string packageId,
                                   List <RepositoryFile> filesToIgnore)
        {
            var extensions = folder.CmisFolder.GetExtensions(ExtensionLevel.Object);

            Log.Verbose("Adding folder data to DIP Package for {FolderType}: {data} with parent {parent}", folder.FolderType,
                        JsonConvert.SerializeObject(extensions), parent);
            switch (folder.FolderType)
            {
            case PackageFolderType.Ablieferung:
                var orderedRecord = indexRecords.FirstOrDefault(i => i.PrimaryDataLink == packageId);
                AddAblieferungData(dip.Ablieferung, extensions, orderedRecord);
                break;

            case PackageFolderType.OrdnungssystemPosition:
                OrdnungssystempositionDIP position;
                switch (parent.FolderType)
                {
                case PackageFolderType.Ablieferung:
                    position = AddOrdnungssystemPositionData(dip.Ablieferung.Ordnungssystem.Ordnungssystemposition, extensions);
                    break;

                case PackageFolderType.OrdnungssystemPosition:
                    var parentPosition = FindOrdnungssystemPositionInPackage(parent, dip);
                    position = AddOrdnungssystemPositionData(parentPosition.Ordnungssystemposition, extensions);
                    break;

                default:
                    throw new InvalidOperationException(
                              "A <Ordnungssystemposition> can only be added to a <Ordnungssystem> or another <Ordnungssystemposition>.");
                }

                folder.Id = position.Id;
                break;

            case PackageFolderType.Dossier:
                DossierDIP dossier;
                var        dossierRecord = GetArchiveRecordFromDossier(folder, indexRecords);
                switch (parent.FolderType)
                {
                case PackageFolderType.OrdnungssystemPosition:
                    var parentPosition = FindOrdnungssystemPositionInPackage(parent, dip);
                    dossier = AddDossierData(parentPosition.Dossier, extensions, dossierRecord,
                                             folder.IsOrderedItem || folder.IsChildOfOrderedItem, filesToIgnore);
                    break;

                case PackageFolderType.Dossier:
                    var parentDossier = FindDossierInPackage(parent, dip);
                    dossier = AddDossierData(parentDossier.Dossier, extensions, dossierRecord,
                                             folder.IsOrderedItem || folder.IsChildOfOrderedItem, filesToIgnore);
                    break;

                default:
                    throw new InvalidOperationException("A <Dossier> can only be added to a <Ordnungssystemposition> or another <Dossier>.");
                }

                folder.Id = dossier.Id;
                break;

            case PackageFolderType.Dokument:
                DokumentDIP dokument;
                var         documentRecord = GetArchiveRecordFromDocument(folder, indexRecords);
                switch (parent.FolderType)
                {
                case PackageFolderType.Dossier:
                    var parentDossier = FindDossierInPackage(parent, dip);
                    dokument = AddDokumentData(parentDossier, extensions, documentRecord, filesToIgnore);
                    break;

                default:
                    throw new InvalidOperationException("A <Dokument> can only be added to a <Dossier>.");
                }

                folder.Id = dokument.Id;
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            foreach (var child in FoldersTreeList.GetChildren(folder))
            {
                AddFolderData(child, folder, dip, indexRecords, packageId, filesToIgnore);
            }
        }