Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.8] Fix translation of metadata keys in mass import form #6412

Open
wants to merge 1 commit into
base: 3.8.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,6 +82,7 @@ public void prepareMassImport(int templateId, int projectId) {
try {
Template template = ServiceManager.getTemplateService().getById(templateId);
templateTitle = template.getTitle();
ruleset = template.getRuleset();
RulesetManagementInterface ruleset = ServiceManager.getRulesetService().openRuleset(template.getRuleset());
addMetadataDialog.setRulesetManagement(ruleset);
checkRecordIdentifierConfigured(ruleset);
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 @@ -1736,6 +1736,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
Loading