Skip to content

Commit

Permalink
Merge pull request kitodo#6411 from solth/massimport-metadata-key-tra…
Browse files Browse the repository at this point in the history
…nslation

Fix translation of metadata keys in mass import form
  • Loading branch information
solth authored Feb 27, 2025
2 parents 511ad4f + 165bd1e commit 66f0d5d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import org.apache.logging.log4j.Logger;
import org.kitodo.api.dataeditor.rulesetmanagement.RulesetManagementInterface;
import org.kitodo.data.database.beans.ImportConfiguration;
import org.kitodo.data.database.beans.Ruleset;
import org.kitodo.data.database.beans.Template;
import org.kitodo.data.database.exceptions.DAOException;
import org.kitodo.exceptions.ConfigException;
Expand All @@ -53,6 +54,7 @@ public class MassImportForm extends BaseForm {
private int projectId;
private int templateId;
private String templateTitle;
private Ruleset ruleset;
private ImportConfiguration importConfiguration;
private UploadedFile file;
private String csvSeparator = ";";
Expand Down Expand Up @@ -80,9 +82,10 @@ public void prepareMassImport(int templateId, int projectId) {
try {
Template template = ServiceManager.getTemplateService().getById(templateId);
templateTitle = template.getTitle();
RulesetManagementInterface ruleset = ServiceManager.getRulesetService().openRuleset(template.getRuleset());
addMetadataDialog.setRulesetManagement(ruleset);
checkRecordIdentifierConfigured(ruleset);
ruleset = template.getRuleset();
RulesetManagementInterface rulesetInterface = ServiceManager.getRulesetService().openRuleset(template.getRuleset());
addMetadataDialog.setRulesetManagement(rulesetInterface);
checkRecordIdentifierConfigured(rulesetInterface);
} catch (DAOException | IOException e) {
Helper.setErrorMessage(e);
}
Expand Down Expand Up @@ -220,7 +223,13 @@ private void importRecords(Map<String, Map<String, List<String>>> processMetadat
*/
public String getColumnHeader(Integer columnIndex) {
if (columnIndex < metadataKeys.size()) {
return Helper.getTranslation(metadataKeys.get(columnIndex));
String metadataKey = metadataKeys.get(columnIndex);
try {
return ServiceManager.getImportService().getMetadataTranslation(ruleset, metadataKey);
} catch (IOException e) {
Helper.setErrorMessage(e);
return metadataKey;
}
}
return "";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1737,6 +1737,23 @@ public LinkedList<TempProcess> processUploadedFile(CreateProcessForm createProce
return processes;
}

/**
* Retrieve and return label of metadata with given key 'metadataKey'.
*
* @param ruleset Ruleset from which metadata label is retrieved
* @param metadataKey key of metadata for which label ir retrieved
* @return label of metadata
* @throws IOException if ruleset file could not be read
*/
public String getMetadataTranslation(Ruleset ruleset, String metadataKey) throws IOException {
RulesetManagementInterface managementInterface = ServiceManager.getRulesetService().openRuleset(ruleset);
User user = ServiceManager.getUserService().getCurrentUser();
String metadataLanguage = user.getMetadataLanguage();
List<Locale.LanguageRange> languages = Locale.LanguageRange.parse(metadataLanguage.isEmpty()
? Locale.ENGLISH.getCountry() : metadataLanguage);
return managementInterface.getTranslationForKey(metadataKey, languages).orElse(metadataKey);
}

private TempProcess extractParentRecordFromFile(Document internalDocument, CreateProcessForm createProcessForm)
throws XPathExpressionException, UnsupportedFormatException, URISyntaxException, IOException,
ParserConfigurationException, SAXException, ProcessGenerationException, TransformerException {
Expand Down

0 comments on commit 66f0d5d

Please sign in to comment.