mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 17:25:32 +00:00
Added Upload functionality; still a bit janky in selecting the files to use...
This commit is contained in:
@@ -17,7 +17,7 @@ public interface IXMLRoot {
|
||||
public abstract Predicate<XElement> IsCollectedObject { get; }
|
||||
|
||||
// Gets the Key of a collected object
|
||||
public abstract Func<XElement, string?> GetKey { get; }
|
||||
// public abstract Func<XElement, string?> GetKey { get; }
|
||||
|
||||
// Can the Root be found within that document?
|
||||
public List<XElement>? IsTypeOf(XElement root) {
|
||||
@@ -45,18 +45,20 @@ public interface IXMLRoot {
|
||||
// Further deciding which of two documents replaces which
|
||||
public abstract bool Replaces(XMLRootDocument doc1, XMLRootDocument doc2);
|
||||
|
||||
public Dictionary<string, XElement>? GetCollectedObjects(XMLRootDocument document) {
|
||||
Dictionary<string, XElement>? ret = null;
|
||||
var root = document.Root;
|
||||
root.Elements().Where(x => this.IsCollectedObject(x)).ToList().ForEach(x => {
|
||||
var id = this.GetKey(x);
|
||||
if (id != null) {
|
||||
if (ret == null) ret = new Dictionary<string, XElement>();
|
||||
ret.Add(id, x);
|
||||
}
|
||||
});
|
||||
return ret;
|
||||
}
|
||||
// public Dictionary<string, XElement>? GetCollectedObjects(XMLRootDocument document) {
|
||||
// Dictionary<string, XElement>? ret = null;
|
||||
// var root = document.Root;
|
||||
// root.Elements().Where(x => this.IsCollectedObject(x)).ToList().ForEach(x => {
|
||||
// var id = this.GetKey(x);
|
||||
// if (id != null) {
|
||||
// if (ret == null) ret = new Dictionary<string, XElement>();
|
||||
// ret.Add(id, x);
|
||||
// }
|
||||
// });
|
||||
// return ret;
|
||||
// }
|
||||
|
||||
public abstract XElement CreateHamannDocument(XElement element);
|
||||
|
||||
public abstract void MergeIntoFile(XElement file, XMLRootDocument document);
|
||||
}
|
||||
@@ -7,8 +7,9 @@ public interface IXMLService {
|
||||
public IXMLRoot? GetRoot(string name);
|
||||
public List<IXMLRoot>? GetRootsList();
|
||||
public Dictionary<string, IXMLRoot>? GetRootsDictionary();
|
||||
public Task<List<XMLRootDocument>?> ProbeHamannFile(XDocument document, ModelStateDictionary ModelState);
|
||||
public List<XMLRootDocument>? ProbeHamannFile(XDocument document, ModelStateDictionary ModelState);
|
||||
public Dictionary<string, FileList?>? GetUsedDictionary();
|
||||
public XElement? MergeUsedDocuments(ModelStateDictionary ModelState);
|
||||
public void Use(XMLRootDocument doc);
|
||||
public void AutoUse(string prefix);
|
||||
public void AutoUse(FileList filelist);
|
||||
|
||||
@@ -30,7 +30,7 @@ public class XMLService : IXMLService {
|
||||
|
||||
public Dictionary<string, IXMLRoot>? GetRootsDictionary() => this._Roots == null ? null : this._Roots;
|
||||
|
||||
public async Task<List<XMLRootDocument>?> ProbeHamannFile(XDocument document, ModelStateDictionary ModelState) {
|
||||
public List<XMLRootDocument>? ProbeHamannFile(XDocument document, ModelStateDictionary ModelState) {
|
||||
if (document.Root!.Name != "opus") {
|
||||
ModelState.AddModelError("Error", "A valid Hamann-Docuemnt must begin with <opus>");
|
||||
return null;
|
||||
@@ -86,6 +86,27 @@ public class XMLService : IXMLService {
|
||||
}
|
||||
}
|
||||
|
||||
public XElement? MergeUsedDocuments(ModelStateDictionary ModelState) {
|
||||
if (_Used == null || _Roots == null) {
|
||||
ModelState.AddModelError("Error", "Keine Dokumente ausgewählt");
|
||||
return null;
|
||||
}
|
||||
|
||||
var opus = new XElement("opus");
|
||||
foreach (var category in _Used) {
|
||||
if (category.Value == null || category.Value.GetFileList() == null || !category.Value.GetFileList()!.Any()) {
|
||||
ModelState.AddModelError("Error", _Roots![category.Key].Type + " nicht vorhanden.");
|
||||
return null;
|
||||
}
|
||||
|
||||
var documents = category.Value.GetFileList();
|
||||
foreach (var document in documents!) {
|
||||
document.XMLRoot.MergeIntoFile(opus, document);
|
||||
}
|
||||
}
|
||||
return opus;
|
||||
}
|
||||
|
||||
private XMLRootDocument _createXMLRootDocument(IXMLRoot Root, XElement element) {
|
||||
var doc = new XMLRootDocument(Root, Root.Prefix, Root.GenerateIdentificationString(element), element);
|
||||
doc.Fields = Root.GenerateFields(doc);
|
||||
|
||||
Reference in New Issue
Block a user