diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java index cac8a412b5c..5cafe410199 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java @@ -45,6 +45,7 @@ import org.kitodo.data.database.enums.TaskStatus; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.data.exceptions.DataException; +import org.kitodo.exceptions.InvalidImagesException; import org.kitodo.production.controller.SecurityAccessController; import org.kitodo.production.dto.ProcessDTO; import org.kitodo.production.dto.TaskDTO; @@ -666,7 +667,7 @@ private void executeKitodoScriptForProcesses(List processes, String kit KitodoScriptService service = new KitodoScriptService(); try { service.execute(processes, kitodoScript); - } catch (DataException e) { + } catch (DataException | IOException | InvalidImagesException e) { Helper.setErrorMessage(e.getLocalizedMessage(), logger, e); } } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/command/KitodoScriptService.java b/Kitodo/src/main/java/org/kitodo/production/services/command/KitodoScriptService.java index 31cca87bf81..a938d9e731c 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/command/KitodoScriptService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/command/KitodoScriptService.java @@ -24,10 +24,10 @@ import java.util.Objects; import java.util.stream.Collectors; -import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.lang.text.StrTokenizer; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.kitodo.api.dataformat.Workpiece; import org.kitodo.data.database.beans.Folder; import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.beans.Role; @@ -36,15 +36,16 @@ import org.kitodo.data.database.enums.TaskStatus; import org.kitodo.data.exceptions.DataException; import org.kitodo.exceptions.CommandException; +import org.kitodo.exceptions.InvalidImagesException; import org.kitodo.export.ExportDms; import org.kitodo.production.enums.GenerationMode; import org.kitodo.production.helper.Helper; import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyMetsModsDigitalDocumentHelper; import org.kitodo.production.helper.tasks.TaskManager; -import org.kitodo.production.metadata.copier.CopierData; -import org.kitodo.production.metadata.copier.DataCopier; import org.kitodo.production.model.Subfolder; import org.kitodo.production.services.ServiceManager; +import org.kitodo.production.services.data.ProcessService; +import org.kitodo.production.services.dataformat.MetsService; import org.kitodo.production.services.file.FileService; import org.kitodo.production.services.image.ImageGenerator; import org.kitodo.production.thread.TaskImageGeneratorThread; @@ -68,7 +69,8 @@ public class KitodoScriptService { * @param script * from frontend passed as String */ - public void execute(List processes, String script) throws DataException { + public void execute(List processes, String script) + throws DataException, IOException, InvalidImagesException { this.parameters = new HashMap<>(); // decompose and capture all script parameters StrTokenizer tokenizer = new StrTokenizer(script, ' ', '\"'); @@ -95,7 +97,8 @@ public void execute(List processes, String script) throws DataException } } - private boolean executeScript(List processes, String script) throws DataException { + private boolean executeScript(List processes, String script) + throws DataException, IOException, InvalidImagesException { // call the correct method via the parameter switch (this.parameters.get("action")) { case "importFromFileSystem": @@ -133,6 +136,16 @@ private boolean executeScript(List processes, String script) throws Dat case "doit2": exportDms(processes, String.valueOf(Boolean.FALSE)); break; + default: + return executeOtherScript(processes, script); + } + return true; + } + + private boolean executeOtherScript(List processes, String script) + throws DataException, IOException, InvalidImagesException { + // call the correct method via the parameter + switch (this.parameters.get("action")) { case "runscript": String taskName = this.parameters.get("stepname"); String scriptName = this.parameters.get(SCRIPT); @@ -163,6 +176,16 @@ private boolean executeScript(List processes, String script) throws Dat case "copyDataToChildren": copyDataToChildren(processes, script); break; + default: + return executeRemainingScript(processes, script); + } + return true; + } + + private boolean executeRemainingScript(List processes, String script) + throws DataException, IOException, InvalidImagesException { + // call the correct method via the parameter + switch (this.parameters.get("action")) { case "generateImages": String folders = parameters.get("folders"); List foldersList = Arrays.asList("all"); @@ -176,6 +199,9 @@ private boolean executeScript(List processes, String script) throws Dat } generateImages(processes, mode, foldersList); break; + case "searchForMedia": + searchForMedia(processes); + break; default: Helper.setErrorMessage("Unknown action", " - use: 'action:addRole, action:setTaskProperty, action:setStepStatus, " @@ -379,6 +405,19 @@ private void generateImages(List processes, GenerationMode generationMo } } + private void searchForMedia(List processes) throws IOException, InvalidImagesException { + FileService fileService = ServiceManager.getFileService(); + MetsService metsService = ServiceManager.getMetsService(); + ProcessService processService = ServiceManager.getProcessService(); + + for (Process process : processes) { + URI metadataFileUri = processService.getMetadataFileUri(process); + Workpiece workpiece = metsService.loadWorkpiece(metadataFileUri); + fileService.searchForMedia(process, workpiece); + metsService.saveWorkpiece(workpiece, metadataFileUri); + } + } + private void runScript(List processes, String taskName, String scriptName) throws DataException { for (Process process : processes) { for (Task task : process.getTasks()) { diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/processes/executeScriptSelectedPopup.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/processes/executeScriptSelectedPopup.xhtml index da34b7d704d..29766789e67 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/processes/executeScriptSelectedPopup.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/processes/executeScriptSelectedPopup.xhtml @@ -68,6 +68,9 @@ +