mirror of
https://github.com/Theodor-Springmann-Stiftung/hamann-ausgabe-core.git
synced 2025-10-29 09:15:33 +00:00
Added a workaround for a bug in the parser
This commit is contained in:
@@ -21,6 +21,7 @@ namespace HaDocument
|
|||||||
private static ILibrary _library;
|
private static ILibrary _library;
|
||||||
|
|
||||||
public static ILibrary Create(IHaDocumentOptions Settings) {
|
public static ILibrary Create(IHaDocumentOptions Settings) {
|
||||||
|
_lib = new IntermediateLibrary();
|
||||||
SettingsValidator.Validate(Settings);
|
SettingsValidator.Validate(Settings);
|
||||||
_settings = Settings;
|
_settings = Settings;
|
||||||
_createReader();
|
_createReader();
|
||||||
|
|||||||
@@ -166,11 +166,18 @@ public class APIController : Controller {
|
|||||||
if (!ModelState.IsValid || element == null)
|
if (!ModelState.IsValid || element == null)
|
||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
var savedfile = await _xmlProvider.SaveHamannFile(element, _targetFilePath, ModelState);
|
var savedfile = await _xmlProvider.SaveHamannFile(element, _targetFilePath, ModelState);
|
||||||
if (!ModelState.IsValid || savedfile == null)
|
if (!ModelState.IsValid || savedfile == null) {
|
||||||
|
if (savedfile != null)
|
||||||
|
_xmlProvider.DeleteHamannFile(savedfile.Name);
|
||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
|
}
|
||||||
_ = _lib.SetLibrary(savedfile.PhysicalPath, ModelState);
|
_ = _lib.SetLibrary(savedfile.PhysicalPath, ModelState);
|
||||||
if (!ModelState.IsValid)
|
if (!ModelState.IsValid) {
|
||||||
|
_xmlProvider.DeleteHamannFile(savedfile.Name);
|
||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
|
}
|
||||||
|
_xmlProvider.SetInProduction(savedfile);
|
||||||
|
_xmlService.SetInProduction();
|
||||||
return Created("/", _xmlProvider.GetHamannFiles());
|
return Created("/", _xmlProvider.GetHamannFiles());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -329,13 +336,8 @@ public class APIController : Controller {
|
|||||||
return BadRequest(ModelState);
|
return BadRequest(ModelState);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
_ = _lib.SetLibrary(newFile.First().PhysicalPath, ModelState);
|
||||||
_ = _lib.SetLibrary(newFile.First().PhysicalPath, ModelState);
|
if (!ModelState.IsValid) return BadRequest(ModelState);
|
||||||
}
|
|
||||||
catch (Exception ex) {
|
|
||||||
ModelState.AddModelError("Error", "Error parsing the file: " + ex.Message);
|
|
||||||
return BadRequest(ModelState);
|
|
||||||
}
|
|
||||||
|
|
||||||
_xmlProvider.SetInProduction(newFile.First());
|
_xmlProvider.SetInProduction(newFile.First());
|
||||||
_xmlService.UnUseProduction();
|
_xmlService.UnUseProduction();
|
||||||
|
|||||||
@@ -35,8 +35,7 @@ public class HaDocumentWrapper : IHaDocumentWrappper {
|
|||||||
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { HamannXMLFilePath = filepath, AvailableYearRange = (_startYear, _endYear) });
|
Library = HaDocument.Document.Create(new HaWeb.Settings.HaDocumentOptions() { HamannXMLFilePath = filepath, AvailableYearRange = (_startYear, _endYear) });
|
||||||
}
|
}
|
||||||
catch (Exception ex) {
|
catch (Exception ex) {
|
||||||
if (ModelState != null) ModelState.AddModelError("Error:", "Das Dokument konnte nicht geparst werden: " + ex.Message);
|
if (ModelState != null) ModelState.AddModelError("Error", "Das Dokument konnte nicht geparst werden: " + ex.Message);
|
||||||
Console.WriteLine(ex.Message);
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
return Library;
|
return Library;
|
||||||
|
|||||||
@@ -12,4 +12,5 @@ public interface IXMLProvider {
|
|||||||
public List<IFileInfo>? GetHamannFiles();
|
public List<IFileInfo>? GetHamannFiles();
|
||||||
public IFileInfo? GetInProduction();
|
public IFileInfo? GetInProduction();
|
||||||
public void SetInProduction(IFileInfo info);
|
public void SetInProduction(IFileInfo info);
|
||||||
|
public void DeleteHamannFile(string filename);
|
||||||
}
|
}
|
||||||
@@ -10,7 +10,7 @@ public class XMLProvider : IXMLProvider {
|
|||||||
private Dictionary<string, FileList?>? _Files;
|
private Dictionary<string, FileList?>? _Files;
|
||||||
private Dictionary<string, IXMLRoot>? _Roots;
|
private Dictionary<string, IXMLRoot>? _Roots;
|
||||||
private List<IFileInfo>? _HamannFiles;
|
private List<IFileInfo>? _HamannFiles;
|
||||||
private IFileInfo? _InProduction;
|
private Stack<IFileInfo>? _InProduction;
|
||||||
|
|
||||||
public XMLProvider(IFileProvider provider, IXMLService xmlservice) {
|
public XMLProvider(IFileProvider provider, IXMLService xmlservice) {
|
||||||
_fileProvider = provider;
|
_fileProvider = provider;
|
||||||
@@ -26,9 +26,24 @@ public class XMLProvider : IXMLProvider {
|
|||||||
|
|
||||||
public List<IFileInfo>? GetHamannFiles() => this._HamannFiles;
|
public List<IFileInfo>? GetHamannFiles() => this._HamannFiles;
|
||||||
|
|
||||||
public IFileInfo? GetInProduction() => this._InProduction;
|
public IFileInfo? GetInProduction() {
|
||||||
|
if (_InProduction == null || !_InProduction.Any()) return null;
|
||||||
|
return this._InProduction.Peek();
|
||||||
|
}
|
||||||
|
|
||||||
public void SetInProduction(IFileInfo info) => _InProduction = info;
|
public void DeleteHamannFile(string filename) {
|
||||||
|
if (_HamannFiles == null) return;
|
||||||
|
var files = _HamannFiles.Where(x => x.Name == filename);
|
||||||
|
foreach (var file in files) {
|
||||||
|
File.Delete(file.PhysicalPath);
|
||||||
|
}
|
||||||
|
_HamannFiles.RemoveAll(x => x.Name == filename);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetInProduction(IFileInfo info) {
|
||||||
|
if (_InProduction == null) _InProduction = new Stack<IFileInfo>();
|
||||||
|
_InProduction.Push(info);
|
||||||
|
}
|
||||||
|
|
||||||
public FileList? GetFiles(string prefix)
|
public FileList? GetFiles(string prefix)
|
||||||
=> _Files != null && _Files.ContainsKey(prefix) ? _Files[prefix] : null;
|
=> _Files != null && _Files.ContainsKey(prefix) ? _Files[prefix] : null;
|
||||||
@@ -89,7 +104,6 @@ public class XMLProvider : IXMLProvider {
|
|||||||
if (_HamannFiles == null) _HamannFiles = new List<IFileInfo>();
|
if (_HamannFiles == null) _HamannFiles = new List<IFileInfo>();
|
||||||
_HamannFiles.RemoveAll(x => x.Name == info.Name);
|
_HamannFiles.RemoveAll(x => x.Name == info.Name);
|
||||||
_HamannFiles.Add(info);
|
_HamannFiles.Add(info);
|
||||||
_InProduction = info;
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -61,7 +61,7 @@
|
|||||||
document.getElementById("ha-filelistoutput").textContent = json.Error;
|
document.getElementById("ha-filelistoutput").textContent = json.Error;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
location.reload();
|
location.reload();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch ((e) => {
|
.catch ((e) => {
|
||||||
|
|||||||
@@ -57,7 +57,7 @@
|
|||||||
document.getElementById("ha-lds-ellipsis-publish").style.display = "none";
|
document.getElementById("ha-lds-ellipsis-publish").style.display = "none";
|
||||||
document.getElementById("ha-publishmessage").style.opacity = "1";
|
document.getElementById("ha-publishmessage").style.opacity = "1";
|
||||||
document.getElementById("publish-result").value = "Erfolg!";
|
document.getElementById("publish-result").value = "Erfolg!";
|
||||||
window.location.replace("/Admin/Upload/");
|
@* location.reload(); *@
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch ((e) => {
|
.catch ((e) => {
|
||||||
|
|||||||
@@ -16,4 +16,5 @@ public interface IXMLService {
|
|||||||
public Dictionary<string, FileList?>? GetInProduction();
|
public Dictionary<string, FileList?>? GetInProduction();
|
||||||
public void UnUse(string prefix);
|
public void UnUse(string prefix);
|
||||||
public void UnUseProduction();
|
public void UnUseProduction();
|
||||||
|
public void SetInProduction();
|
||||||
}
|
}
|
||||||
@@ -7,7 +7,7 @@ public class XMLService : IXMLService {
|
|||||||
private Dictionary<string, FileList?>? _Used;
|
private Dictionary<string, FileList?>? _Used;
|
||||||
private Dictionary<string, IXMLRoot>? _Roots;
|
private Dictionary<string, IXMLRoot>? _Roots;
|
||||||
|
|
||||||
private Dictionary<string, FileList?>? _InProduction;
|
private Stack<Dictionary<string, FileList?>>? _InProduction;
|
||||||
|
|
||||||
public XMLService() {
|
public XMLService() {
|
||||||
// Getting all classes which implement IXMLRoot for possible document endpoints
|
// Getting all classes which implement IXMLRoot for possible document endpoints
|
||||||
@@ -32,7 +32,23 @@ public class XMLService : IXMLService {
|
|||||||
|
|
||||||
public Dictionary<string, IXMLRoot>? GetRootsDictionary() => this._Roots == null ? null : this._Roots;
|
public Dictionary<string, IXMLRoot>? GetRootsDictionary() => this._Roots == null ? null : this._Roots;
|
||||||
|
|
||||||
public Dictionary<string, FileList?>? GetInProduction() => this._InProduction;
|
public Dictionary<string, FileList?>? GetInProduction() {
|
||||||
|
if (_InProduction == null) return null;
|
||||||
|
return this._InProduction.Peek();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetInProduction() {
|
||||||
|
if (_Used == null) return;
|
||||||
|
var inProduction = new Dictionary<string, FileList?>();
|
||||||
|
foreach (var category in _Used) {
|
||||||
|
if (category.Value == null || category.Value.GetFileList() == null || !category.Value.GetFileList()!.Any())
|
||||||
|
return;
|
||||||
|
inProduction.Add(category.Key, category.Value);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(_InProduction == null) _InProduction = new Stack<Dictionary<string, FileList?>>();
|
||||||
|
_InProduction.Push(inProduction);
|
||||||
|
}
|
||||||
|
|
||||||
public void UnUseProduction() => this._InProduction = null;
|
public void UnUseProduction() => this._InProduction = null;
|
||||||
|
|
||||||
@@ -104,20 +120,19 @@ public class XMLService : IXMLService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var opus = new XElement("opus");
|
var opus = new XElement("opus");
|
||||||
var inProduction = new Dictionary<string, FileList?>();
|
// TODO: Workaround for bug in HaDocument: roots have to be added in a specific order
|
||||||
foreach (var category in _Used) {
|
var used = _Used.OrderByDescending(x => x.Key);
|
||||||
|
foreach (var category in used) {
|
||||||
if (category.Value == null || category.Value.GetFileList() == null || !category.Value.GetFileList()!.Any()) {
|
if (category.Value == null || category.Value.GetFileList() == null || !category.Value.GetFileList()!.Any()) {
|
||||||
ModelState.AddModelError("Error", _Roots![category.Key].Type + " nicht vorhanden.");
|
ModelState.AddModelError("Error", _Roots![category.Key].Type + " nicht vorhanden.");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
inProduction.Add(category.Key, category.Value);
|
|
||||||
var documents = category.Value.GetFileList();
|
var documents = category.Value.GetFileList();
|
||||||
foreach (var document in documents!) {
|
foreach (var document in documents!) {
|
||||||
document.XMLRoot.MergeIntoFile(opus, document);
|
document.XMLRoot.MergeIntoFile(opus, document);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_InProduction = inProduction;
|
|
||||||
return opus;
|
return opus;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user