Skip to content

Commit

Permalink
Add optional parameter to limit number of processes for media renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
solth committed Nov 14, 2023
1 parent 98d19c2 commit 7b0b6b2
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* (c) Kitodo. Key to digital objects e. V. <[email protected]>
*
* This file is part of the Kitodo project.
*
* It is licensed under GNU General Public License version 3 or later.
*
* For the full copyright and license information, please read the
* GPL3-License.txt file that was distributed with this source code.
*/

package org.kitodo.exceptions;

/**
* This exception is thrown when too many processes are selected for a specific list action.
*/
public class TooManyProcessesSelectedException extends RuntimeException {

/**
* Constructor with message.
*
* @param message String containing exception message
*/
public TooManyProcessesSelectedException(String message) {
super(message);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -639,8 +639,12 @@ public enum ParameterCore implements ParameterInterface {
* Secret is used to encrypt or decrypt LDAP manager passwords which are stored in the database in encrypted form.
* Once the secret value is set, it should not be changed since encrypted data can no longer be decrypted.
*/
SECURITY_SECRET_LDAPMANAGERPASSWORD(new Parameter<>("security.secret.ldapManagerPassword", ""));
SECURITY_SECRET_LDAPMANAGERPASSWORD(new Parameter<>("security.secret.ldapManagerPassword", "")),

/* Optional parameter can be used to limit the number of processes for which media renaming can be conducted as a
* list function. Values different from positive integers are interpreted as "unlimited".
*/
MAX_NUMBER_OF_PROCESSES_FOR_MEDIA_RENAMING(new Parameter<>("maxNumberOfProcessesForMediaRenaming", -1));

private final Parameter<?> parameter;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.kitodo.data.exceptions.DataException;
import org.kitodo.exceptions.InvalidImagesException;
import org.kitodo.exceptions.MediaNotFoundException;
import org.kitodo.exceptions.TooManyProcessesSelectedException;
import org.kitodo.production.controller.SecurityAccessController;
import org.kitodo.production.dto.ProcessDTO;
import org.kitodo.production.dto.TaskDTO;
Expand Down Expand Up @@ -1187,6 +1188,13 @@ public FilterMenu getFilterMenu() {
* Rename media files of all selected processes.
*/
public void renameMedia() {
ServiceManager.getFileService().renameMedia(getSelectedProcesses());
try {
ServiceManager.getFileService().renameMedia(getSelectedProcesses());
PrimeFaces.current().executeScript("PF('notifications').renderMessage({'summary':'"
+ Helper.getTranslation("renamingMediaFilesOfSelectedProcessesStarted")
+ "','severity':'info'})");
} catch (TooManyProcessesSelectedException e) {
Helper.setErrorMessage(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
import org.kitodo.exceptions.CommandException;
import org.kitodo.exceptions.InvalidImagesException;
import org.kitodo.exceptions.MediaNotFoundException;
import org.kitodo.exceptions.TooManyProcessesSelectedException;
import org.kitodo.production.dto.ProcessDTO;
import org.kitodo.production.file.BackupFileRotation;
import org.kitodo.production.helper.Helper;
Expand Down Expand Up @@ -1526,7 +1527,12 @@ public int renameMediaFiles(Process process, Workpiece workpiece, DualHashBidiMa
*/
public void renameMedia(List<Process> processes) {
processes = lockAndSortProcessesForRenaming(processes);
TaskManager.addTask(new RenameMediaThread(processes));
int limit = ConfigCore.getIntParameterOrDefaultValue(ParameterCore.MAX_NUMBER_OF_PROCESSES_FOR_MEDIA_RENAMING);
if (0 < limit && limit < processes.size()) {
throw new TooManyProcessesSelectedException(Helper.getTranslation("tooManyProcessesSelectedForMediaRenaming", String.valueOf(limit), String.valueOf(processes.size())));
} else {
TaskManager.addTask(new RenameMediaThread(processes));
}
}

private List<Process> lockAndSortProcessesForRenaming(List<Process> processes) {
Expand Down
4 changes: 4 additions & 0 deletions Kitodo/src/main/resources/kitodo_config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -764,3 +764,7 @@ security.secret.ldapManagerPassword=
# largest data tables of tasks by processingBegin and process by creation date are considered.
# The dates can be defined & separated in the format YYYY, YYYY-MM or YYYY-MM-DD e.g. 2017-05-10,2018-06,2022
# database.subset.dates=

# This optional parameter can be used to limit the number of processes for which media renaming can be conducted as a
# list function. Values different from positive integers are interpreted as "unlimited".
#maxNumberOfProcessesForMediaRenaming=10000
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/errors_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ templateAssignedError=Der Workflow kann nicht gel\u00F6scht werden, da diesem Pr
templateTitleAlreadyInUse=Der Produktionsvorlagentitel wird bereits verwendet.
templateTitleEmpty=Kein Produktionsvorlagentitel angegeben.
tooManyBatchesSelected=Es sind mehrere Batches ausgew\u00E4hlt. W\u00E4hlen Sie genau einen Batch aus, um diese Funktion zu nutzen.
tooManyProcessesSelectedForMediaRenaming=Die maximal erlaubte Anzahl an Vorg\u00E4ngen ({0}) f\u00FCr die Medienumbenennung wurde \u00FCberschritten ({1}).

# U
errorUploading=Fehler beim Hochladen von ''{0}''.
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/errors_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ templateAssignedError=The workflow could not be deleted because there are alread
templateTitleAlreadyInUse=The template title is already in use.
templateTitleEmpty=No template title stated.
tooManyBatchesSelected=Multiple batches are selected. To use this function, please select one batch only.
tooManyProcessesSelectedForMediaRenaming=Maximum number of allowed processes for media renaming ({0}) exceeded ({1}).

# U
errorUploading=Error uploading ''{0}''.
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_de.properties
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ removeRole=Rolle entfernen
removeUserFromGroup=Benutzer aus der Benutzergruppe l\u00F6schen
renameBatch=Batch umbenennen
renameMediaFiles=Medien umbenennen
renamingMediaFilesOfSelectedProcessesStarted=Das Umbenennen der Medien f\u00FCr die ausgew\u00E4hlten Vorg\u00E4nge wurde erfolgreich gestartet.
requiredField=Mit * gekennzeichnete Felder sind Pflichtfelder
reset=Zur\u00FCcksetzen
resultPDF=Ergebnis-PDF
Expand Down
1 change: 1 addition & 0 deletions Kitodo/src/main/resources/messages/messages_en.properties
Original file line number Diff line number Diff line change
Expand Up @@ -962,6 +962,7 @@ removeRole=Remove role
removeUserFromGroup=Delete user from group
renameBatch=Rename batch
renameMediaFiles=Rename media
renamingMediaFilesOfSelectedProcessesStarted=Renaming media files of selected processes started successfully.
requiredField=Fields marked with * are required
reset=Reset
resultPDF=Result PDF
Expand Down

0 comments on commit 7b0b6b2

Please sign in to comment.