Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 830652de

Přidáno uživatelem Vojtěch Bartička před asi 2 roky(ů)

Export in BE

  1. Conflicts:
  2. Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
  3. Backend/Core/Services/AnnotationService/IAnnotationService.cs

Zobrazit rozdíly:

Backend/Core/Services/AnnotationService/AnnotationServiceEF.cs
16 16
using System.Text.RegularExpressions;
17 17
using Newtonsoft.Json;
18 18
using Core.GraphUtils;
19
using Models.Documents;
19 20

  
20 21
namespace Core.Services.AnnotationService
21 22
{
......
775 776

  
776 777
            return true;
777 778
        }
778

  
779
        
779 780
        public void SetTagIsFinal(Guid annotationId, Guid occurenceId, bool isFinal)
780 781
        {
781 782
            Annotation annotation;
......
802 803

  
803 804
            context.SaveChanges();
804 805
        }
806

  
807
        public MemoryStream Export(ExportRequest request)
808
        {
809
            if (request.ExportAllDone && request.DocumentIds == null)
810
            {
811
                throw new InvalidOperationException("No documents specified");
812
            }
813

  
814
            // Get documents
815
            IEnumerable<Document> documentsToExport = null;
816
            if (request.ExportAllDone)
817
            {
818
                documentsToExport = context.Documents
819
                    .Include(d => d.Content);
820
            }
821
            else
822
            {
823
                documentsToExport = context.Documents
824
                    .Include(d => d.Content)
825
                    .Where(d => request.DocumentIds.Contains(d.Id));
826
            }
827

  
828
            // Get annotations
829
            Dictionary<Document, List<Annotation>> annotationsToExport = new();
830
            foreach (var document in documentsToExport)
831
            {
832
                annotationsToExport[document] = context.Annotations
833
                    .Where(a => a.Document == document && a.State == EState.DONE)
834
                    .Include(a => a.Document)
835
                    .Include(a => a.User)
836
                    .ToList();
837
            }
838

  
839
            // Get final annotations
840
            Dictionary<Document, FinalAnnotation> finalAnnotationsToExport = new();
841
            foreach (var document in documentsToExport)
842
            {
843
                if (!context.FinalAnnotations.Any(fa => fa.Document == document))
844
                {
845
                    finalAnnotationsToExport[document] = null;
846
                }
847
                else
848
                {
849
                    finalAnnotationsToExport[document] = context.FinalAnnotations
850
                        .Single(fa => fa.Document == document);
851
                }
852
            }
853

  
854
            // Get tags for each annotation
855
            Dictionary<Annotation, List<AnnotationTag>> tagsToExport = new();
856
            foreach (var document in annotationsToExport.Keys)
857
            {
858
                foreach (var annotation in annotationsToExport[document])
859
                {
860
                    tagsToExport[annotation] = context.AnnotationTags
861
                        .Include(at => at.Annotation)
862
                        .Include(at => at.Tag).ThenInclude(t => t.Category)
863
                        .Include(at => at.SubTag)
864
                        .Where(at => at.Annotation == annotation)
865
                        .ToList();
866
                }
867
            }
868

  
869
            // Get tags for each final annotation
870
            Dictionary<FinalAnnotation, List<FinalAnnotationTag>> finalTagsToExport = new();
871
            foreach (var document in finalAnnotationsToExport.Keys)
872
            {
873
                var finalAnnotation = finalAnnotationsToExport[document];
874
                finalTagsToExport[finalAnnotation] = context.FinalAnnotationTags
875
                    .Include(at => at.Annotation)
876
                    .Include(at => at.Tag).ThenInclude(t => t.Category)
877
                    .Include(at => at.SubTag)
878
                    .Where(at => at.Annotation == finalAnnotation)
879
                    .ToList();
880
            }
881

  
882
            MemoryStream output = ZipUtils.Export.FullExport(documentsToExport.ToList(), annotationsToExport, finalAnnotationsToExport, tagsToExport, finalTagsToExport);
883
            return output;
884
        }
805 885
    }
806 886
}

Také k dispozici: Unified diff