Add project files.
This commit is contained in:
65
paperless-ngx-export/Models/DocumentParsed.cs
Normal file
65
paperless-ngx-export/Models/DocumentParsed.cs
Normal file
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
|
||||
namespace paperless_ngx_export.Models
|
||||
{
|
||||
public class DocumentParsed
|
||||
{
|
||||
#region static arrays
|
||||
public static Tag[] _tags { get; set; } = new Tag[0];
|
||||
public static Correspondent[] _correspondents { get; set; } = new Correspondent[0];
|
||||
public static CustomField[] _customFields { get; set; } = new CustomField[0];
|
||||
public static DocumentType[] _documentTypes { get; set; } = new DocumentType[0];
|
||||
#endregion
|
||||
|
||||
public string Correspondent { get; protected set; }
|
||||
public string DocumentType { get; protected set; } = "Unsorted";
|
||||
public string Title { get; protected set; }
|
||||
public string Content { get; protected set; }
|
||||
public List<Tag> Tags { get; protected set; } = new List<Tag>();
|
||||
public DateTime Created { get; protected set; }
|
||||
public DateTimeOffset Modified { get; protected set; }
|
||||
public DateTimeOffset Added { get; protected set; }
|
||||
public DateTimeOffset? DeletedAt { get; protected set; }
|
||||
public List<string> Notes{ get; protected set; }=new List<string>();
|
||||
public string MIMEType { get; protected set; }
|
||||
public int? PageCount { get; protected set; }
|
||||
public List<CustomFieldParsed> CustomFields { get; protected set; } = new List<CustomFieldParsed>();
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Correspondent} {DocumentType}";
|
||||
}
|
||||
|
||||
public static DocumentParsed FromDocument(Document doc)
|
||||
{
|
||||
DocumentParsed d = new DocumentParsed();
|
||||
|
||||
d.Correspondent = _correspondents.First(c => c.Id == doc.correspondent).name;
|
||||
d.DocumentType = _documentTypes.FirstOrDefault(dt => dt.Id == doc.document_type)?.name ?? "Unsorted";
|
||||
d.Title=doc.title.Trim();
|
||||
d.Content = doc.content.Trim();
|
||||
_tags.Where(_t=>doc.tags.Any(dt=>_t.Id == dt)).ToList().ForEach(t => d.Tags.Add(t));
|
||||
d.Created=doc.created;
|
||||
d.Modified=doc.modified;
|
||||
d.Added=doc.added;
|
||||
d.DeletedAt = doc.deleted_at;
|
||||
d.Notes = doc.notes.ToList(); ;
|
||||
d.MIMEType = doc.mime_type;
|
||||
d.PageCount = doc.page_count;
|
||||
_customFields.Where(_cf => doc.custom_fields.Any(dcf => _cf.Id == dcf.field)).ToList()
|
||||
.ForEach(cf =>
|
||||
{
|
||||
var cfp = CustomFieldParsed.FromCustomFieldKeyValuePair(
|
||||
doc.custom_fields.First(dcf => dcf.field == cf.Id),
|
||||
_customFields);
|
||||
if (!(cfp is null))
|
||||
{
|
||||
d.CustomFields.Add(cfp);
|
||||
}
|
||||
});
|
||||
return d;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user