Constructing the process title from additional csv metadata fails
Describe the bug Importing a process using the mass import allows for adding additional metadata in the csv file. (see: https://github.com/kitodo/kitodo-production/pull/5039) If those additional fields are used to create a process title by specifying one of the additionally added fields as source of the processtitle (attribute processtitle="...") the creation of the process fails.
To Reproduce Steps to reproduce the behavior:
- Prepare a csv file with a catalogue ID and an additional metadata element.
- Specify in the ruleset that the additional metadata entry should be used to create the process title
- Try to import the csv using the mass import
Expected behavior It should be possible to use preset metadata to automaticaly create the process title. This probably means to add the preset metadata earlier, so that the process title can be constructed from that data:
https://github.com/kitodo/kitodo-production/blob/29138f39373d9b03f475cfacdb4a2bffc4016ffd/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java#L1135
Right now it probably fails because the process title is constructed before the additional metadata is added:
https://github.com/kitodo/kitodo-production/blob/29138f39373d9b03f475cfacdb4a2bffc4016ffd/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java#L1091
Release Snapshot 3.4.4
I am unable to reproduce this problem with the current master. Maybe it was fixed by #5329 @BartChris could you check if the error still occurs for you?
@solth I checked again with the current master and i cannot make it work unfortunately.
I construct the process title from another metadata element. This works for manually imported records where i set this field by hand. In case of the mass import with this field as additional metadata i get the exception
org.kitodo.exceptions.ProcessGenerationException: Unable to create process
For a short moment
"Unvollständige Daten. Kein Vorganstitel angegeben"
is shown as a flash message.
I will check again if i am making a mistake.
I can confirm that those two lines need to be exchanged:
https://github.com/kitodo/kitodo-production/blob/c0e9ce9494b447b0d7b2677106785b72b2b0e1f1/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java#L1153-L1156
The problem does not appear if the metadata is added first.
tempProcess.getWorkpiece().getLogicalStructure().getMetadata().addAll(createMetadata(presetMetadata));
processTempProcess(tempProcess, ServiceManager.getRulesetService().openRuleset(template.getRuleset()),
"create", Locale.LanguageRange.parse(metadataLanguage.isEmpty() ? "en" : metadataLanguage),
parentTempProcess);
Otherwise the titlegenerator does not have access to the metadata provided by the csv file.
@BartChris can you make a pull request with your solution so we can check if it creates any other problems?