From c7e3aacc2186a5b6013de620b9cf8ebb0814473b Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Mon, 9 Oct 2023 18:17:46 +0200 Subject: [PATCH 01/14] Initial commit of OCR-D workflow implementaiton --- .../kitodo/data/database/beans/Template.java | 23 +++++++ ...uthority_and_fields_for_ocrd_workflows.sql | 16 +++++ .../converter/OcrdWorkflowConverter.java | 44 +++++++++++++ .../kitodo/production/forms/TemplateForm.java | 29 ++++++++ .../production/services/ServiceManager.java | 19 ++++++ .../services/ocr/OcrdWorkflowService.java | 66 +++++++++++++++++++ .../includes/templateEdit/details.xhtml | 13 ++++ 7 files changed, 210 insertions(+) create mode 100644 Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql create mode 100644 Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java create mode 100644 Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java index 93e997ab8ce..9615c4848ab 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java @@ -65,6 +65,9 @@ public class Template extends BaseTemplateBean { @JoinColumn(name = "project_id", foreignKey = @ForeignKey(name = "FK_project_x_template_project_id")) }) private List projects; + @Column(name = "ocrd_workflow_id") + private String ocrdWorkflowId; + /** * Constructor. */ @@ -168,6 +171,26 @@ public void setWorkflow(Workflow workflow) { this.workflow = workflow; } + + /** + * Get OCR-D workflow identifier. + * + * @return value of OCR-D workflow identifier + */ + public String getOcrdWorkflowId() { + return ocrdWorkflowId; + } + + /** + * Set the OCR-D workflow identifier. + * + * @param ocrdWorkflowId + * as profile object + */ + public void setOcrdWorkflowId(String ocrdWorkflowId) { + this.ocrdWorkflowId = ocrdWorkflowId; + } + /** * Get projects list. * diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql new file mode 100644 index 00000000000..7abc8cdcb46 --- /dev/null +++ b/Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql @@ -0,0 +1,16 @@ +-- +-- (c) Kitodo. Key to digital objects e. V. +-- +-- 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. +-- + +-- Add authority to assign OCR-D workflow in template or process details +INSERT IGNORE INTO authority (title) VALUES ('assignOcrdWorkflow_clientAssignable'); + +-- Add column of OCR-D workflow identifier +ALTER TABLE template ADD ocrd_workflow_id varchar(255) DEFAULT NULL; diff --git a/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java b/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java new file mode 100644 index 00000000000..9526aaea98e --- /dev/null +++ b/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java @@ -0,0 +1,44 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * 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.production.converter; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.kitodo.production.services.ServiceManager; + +import javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Named; +import java.util.Objects; + +@Named +public class OcrdWorkflowConverter extends BeanConverter implements Converter { + + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + if (StringUtils.isNotEmpty(value)) { + return ServiceManager.getOcrdWorkflowService().getOcrdWorkflows().stream().filter(pair -> pair.getKey().equals(value)) + .findFirst().get(); + } + return null; + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + if(Objects.nonNull(value) && value instanceof Pair) { + return (String) ((Pair) value).getKey(); + } + return null; + } + +} diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java index 2af30725d4d..383db08497e 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java @@ -24,6 +24,7 @@ import javax.inject.Named; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.kitodo.data.database.beans.Docket; @@ -274,6 +275,34 @@ public List getWorkflows() { return ServiceManager.getWorkflowService().getAvailableWorkflows(); } + /** + * Get list of OCR-D workflows for select list. + * + * @return list of OCR-D workflows + */ + public List getOcrdWorkflows() { + return ServiceManager.getOcrdWorkflowService().getOcrdWorkflows(); + } + + /** + * Get the OCR-D workflow. + * + * @return Immutable key value pair + */ + public Pair getOcrdWorkflow() { + return ServiceManager.getOcrdWorkflowService().getOcrdWorkflow(template.getOcrdWorkflowId()); + } + + /** + * Set the OCR-D workflow. + * + * @param ocrdWorkflow + * The immutable key value pair + */ + public void setOcrdWorkflow(Pair ocrdWorkflow) { + template.setOcrdWorkflowId(ocrdWorkflow.getKey().toString()); + } + /** * Check if user is not assigned to the project. Used for disabling projects. * diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ServiceManager.java b/Kitodo/src/main/java/org/kitodo/production/services/ServiceManager.java index 10bbe24abe1..30c82187d79 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/ServiceManager.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/ServiceManager.java @@ -48,6 +48,7 @@ import org.kitodo.production.services.image.ImageService; import org.kitodo.production.services.index.IndexingService; import org.kitodo.production.services.migration.MigrationService; +import org.kitodo.production.services.ocr.OcrdWorkflowService; import org.kitodo.production.services.schema.SchemaService; import org.kitodo.production.services.security.SecurityAccessService; import org.kitodo.production.services.security.SessionService; @@ -83,6 +84,7 @@ public class ServiceManager { private static MetsService metsService; private static MigrationService migrationService; private static ImportConfigurationService importConfigurationService; + private static OcrdWorkflowService ocrdWorkflowService; private static PropertyService propertyService; private static ProcessService processService; private static ProjectService projectService; @@ -201,6 +203,12 @@ private static void initializeFolderService() { } } + private static void initializeOcrdWorkflowService() { + if (Objects.isNull(ocrdWorkflowService)) { + ocrdWorkflowService = OcrdWorkflowService.getInstance(); + } + } + private static void initializeProjectService() { if (Objects.isNull(projectService)) { projectService = ProjectService.getInstance(); @@ -507,6 +515,17 @@ public static FolderService getFolderService() { return folderService; } + /** + * Initialize OcrdWorkflowService if it is not yet initialized and next return + * it. + * + * @return OcrdWorkflowService object + */ + public static OcrdWorkflowService getOcrdWorkflowService() { + initializeOcrdWorkflowService(); + return ocrdWorkflowService; + } + /** * Initialize ProjectService if it is not yet initialized and next return * it. diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java new file mode 100644 index 00000000000..ec4cc125577 --- /dev/null +++ b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java @@ -0,0 +1,66 @@ +/* + * (c) Kitodo. Key to digital objects e. V. + * + * 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.production.services.ocr; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.kitodo.production.services.ServiceManager; + +import java.util.ArrayList; +import java.util.List; +import java.util.Objects; + +public class OcrdWorkflowService { + + private static volatile OcrdWorkflowService instance = null; + + /** + * Return singleton variable of type OcrdWorkflowService. + * + * @return unique instance of OcrdWorkflowService + */ + public static OcrdWorkflowService getInstance() { + OcrdWorkflowService localReference = instance; + if (Objects.isNull(localReference)) { + synchronized (OcrdWorkflowService.class) { + localReference = instance; + if (Objects.isNull(localReference)) { + localReference = new OcrdWorkflowService(); + instance = localReference; + } + } + } + return localReference; + } + + /** + * Get OCR-D workflows - available means that ... + * + * @return list of OCR-D workflows objects + */ + public List getOcrdWorkflows() { + List workflows = new ArrayList(); + workflows.add(new ImmutablePair<>("1", "One")); + workflows.add(new ImmutablePair<>("2", "Two")); + workflows.add(new ImmutablePair<>("3", "Tree")); + return workflows; + } + + public Pair getOcrdWorkflow(String ocrdWorkflowId) { + if (StringUtils.isNotEmpty(ocrdWorkflowId)) { + return getOcrdWorkflows().stream().filter(pair -> pair.getKey().equals(ocrdWorkflowId)).findFirst().get(); + } + return null; + } + +} diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/templateEdit/details.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/templateEdit/details.xhtml index 73cd95a1402..9a7b1ad1662 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/templateEdit/details.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/templateEdit/details.xhtml @@ -95,6 +95,19 @@ +
+ + + + + +
From e56b7223a29f43fb586f71e7b3f563bcfffd85fd Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Tue, 10 Oct 2023 19:01:21 +0200 Subject: [PATCH 02/14] Implementation of OCR-D workflow selection in template and process, Improve variable replace to replace OCR-D workflow identifier --- .../kitodo/data/database/beans/Process.java | 22 +++++++++ .../kitodo/data/database/beans/Template.java | 2 +- ...uthority_and_fields_for_ocrd_workflows.sql | 3 +- .../kitodo/config/enums/ParameterCore.java | 6 +++ .../controller/SecurityAccessController.java | 9 ++++ .../kitodo/production/forms/ProcessForm.java | 34 +++++++++++++ .../kitodo/production/forms/TemplateForm.java | 6 ++- .../production/helper/VariableReplacer.java | 29 +++++++++-- .../services/ocr/OcrdWorkflowService.java | 49 +++++++++++++++---- .../security/SecurityAccessService.java | 9 ++++ .../main/resources/kitodo_config.properties | 3 ++ .../resources/messages/messages_de.properties | 3 ++ .../resources/messages/messages_en.properties | 3 ++ .../includes/processEdit/details.xhtml | 23 +++++++++ .../includes/templateEdit/details.xhtml | 11 +++-- 15 files changed, 193 insertions(+), 19 deletions(-) diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Process.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Process.java index aa706aa4152..5884c88075a 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Process.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Process.java @@ -116,6 +116,9 @@ public class Process extends BaseTemplateBean { @Column(name = "inChoiceListShown") Boolean inChoiceListShown; + @Column(name = "ocrd_workflow_id") + private String ocrdWorkflowId; + @Transient private User blockedUser; @@ -651,4 +654,23 @@ public void setNumberOfImages(int numberOfImages) { public void setNumberOfStructures(int numberOfStructures) { this.numberOfStructures = numberOfStructures; } + + /** + * Get OCR-D workflow identifier. + * + * @return The OCR-D workflow identifier + */ + public String getOcrdWorkflowId() { + return ocrdWorkflowId; + } + + /** + * Set the OCR-D workflow identifier. + * + * @param ocrdWorkflowId + * The identifier of the OCR-D workflow + */ + public void setOcrdWorkflowId(String ocrdWorkflowId) { + this.ocrdWorkflowId = ocrdWorkflowId; + } } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java index 9615c4848ab..e26c256a697 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/Template.java @@ -185,7 +185,7 @@ public String getOcrdWorkflowId() { * Set the OCR-D workflow identifier. * * @param ocrdWorkflowId - * as profile object + * The identifier of the OCR-D workflow */ public void setOcrdWorkflowId(String ocrdWorkflowId) { this.ocrdWorkflowId = ocrdWorkflowId; diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql index 7abc8cdcb46..336275943f2 100644 --- a/Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql +++ b/Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql @@ -12,5 +12,6 @@ -- Add authority to assign OCR-D workflow in template or process details INSERT IGNORE INTO authority (title) VALUES ('assignOcrdWorkflow_clientAssignable'); --- Add column of OCR-D workflow identifier +-- Add columns of OCR-D workflow identifier +ALTER TABLE process ADD ocrd_workflow_id varchar(255) DEFAULT NULL; ALTER TABLE template ADD ocrd_workflow_id varchar(255) DEFAULT NULL; diff --git a/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java b/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java index 755ac4b7bf7..c1a903d916f 100644 --- a/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java +++ b/Kitodo/src/main/java/org/kitodo/config/enums/ParameterCore.java @@ -46,6 +46,12 @@ public enum ParameterCore implements ParameterInterface { */ DIR_RULESETS(new Parameter("directory.rulesets")), + /** + * Absolute path to the directory that the OCR-D workflow files will be + * read from. It must be terminated by a directory separator ("/"). + */ + OCRD_WORKFLOWS_DIR(new Parameter<>("ocrd.workflows.directory", "")), + /** * Absolute path to the directory that XSLT files are stored in which are used * to transform the "XML log" (as visible from the XML button in the processes diff --git a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java index 032f46ef4ba..1b92034cbd8 100644 --- a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java +++ b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java @@ -222,6 +222,15 @@ public boolean hasAuthorityToAddOnProjectPage() { return securityAccessService.hasAuthorityToAddOnProjectPage(); } + /** + * Check if the current user has the authority to add OCR profile. + * + * @return true if the current user has the authority to add OCR profile. + */ + public boolean hasAuthorityToAssignOcrdWorkflow() { + return securityAccessService.hasAuthorityToAssignOcrdWorkflow(); + } + /** * Check if the current user has the authority to delete the batch. * 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 18cb425973e..65b6053d187 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java @@ -30,6 +30,8 @@ import javax.inject.Inject; import javax.inject.Named; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.kitodo.config.ConfigCore; @@ -874,6 +876,38 @@ public List getProjects() { return ServiceManager.getProjectService().getAllForSelectedClient(); } + /** + * Get list of OCR-D workflows for select list. + * + * @return list of OCR-D workflows + */ + public List getOcrdWorkflows() { + return ServiceManager.getOcrdWorkflowService().getOcrdWorkflows(); + } + + /** + * Get the OCR-D workflow. + * + * @return Immutable key value pair + */ + public Pair getOcrdWorkflow() { + return ServiceManager.getOcrdWorkflowService().getOcrdWorkflow(process.getOcrdWorkflowId()); + } + + /** + * Set the OCR-D workflow. + * + * @param ocrdWorkflow + * The immutable key value pair + */ + public void setOcrdWorkflow(Pair ocrdWorkflow) { + String ocrdWorkflowId = StringUtils.EMPTY; + if(Objects.nonNull(ocrdWorkflow)) { + ocrdWorkflowId = ocrdWorkflow.getKey().toString(); + } + process.setOcrdWorkflowId(ocrdWorkflowId); + } + /** * Get rulesets for select list. * diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java index 383db08497e..8cd8f67addb 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java @@ -300,7 +300,11 @@ public Pair getOcrdWorkflow() { * The immutable key value pair */ public void setOcrdWorkflow(Pair ocrdWorkflow) { - template.setOcrdWorkflowId(ocrdWorkflow.getKey().toString()); + String ocrdWorkflowId = StringUtils.EMPTY; + if(Objects.nonNull(ocrdWorkflow)) { + ocrdWorkflowId = ocrdWorkflow.getKey().toString(); + } + template.setOcrdWorkflowId(ocrdWorkflowId); } /** diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java b/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java index 43571f8e4f8..b04ee9a3577 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java @@ -21,6 +21,7 @@ import java.util.regex.Pattern; import org.apache.commons.io.FilenameUtils; +import org.apache.commons.lang3.StringUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.kitodo.api.dataformat.LogicalDivision; @@ -70,9 +71,7 @@ private enum MetadataLevel { * be replaced. */ private static final Pattern VARIABLE_FINDER_REGEX = Pattern.compile( - "(\\$?)\\((?:(prefs|processid|processtitle|projectid|stepid|stepname|generatorsource|generatorsourcepath)|" - + "(?:(meta|process|product|template)\\.(?:(firstchild|topstruct)\\.)?([^)]+)|" - + "(?:(filename|basename|relativepath))))\\)"); + "(\\$?)\\((?:(prefs|processid|processtitle|projectid|" + "stepid|stepname|generatorsource|generatorsourcepath|ocrdworkflowid)|" + "(?:(meta|process|product|template)\\.(?:(firstchild|topstruct)\\.)?([^)]+)|" + "(?:(filename|basename|relativepath))))\\)"); /** * The map is filled with replacement instructions that are required for @@ -244,6 +243,8 @@ private String determineReplacementForInternalValue(Matcher variableFinder) { case "generatorsource" : case "generatorsourcepath": return determineReplacementForGeneratorSource(variableFinder, variableFinder.group(2)); + case "ocrdworkflowid": + return determineReplacementForOcrdWorkflowId(variableFinder); default: logger.warn("Cannot replace \"{}\": no such case defined in switch", variableFinder.group()); return variableFinder.group(); @@ -281,6 +282,28 @@ private String determineReplacementForProcessid(Matcher variableFinder) { return variableFinder.group(1) + process.getId().toString(); } + private String determineReplacementForOcrdWorkflowId(Matcher variableFinder) { + if (Objects.isNull(process)) { + logger.warn("Cannot replace \"(ocrdworkflowid)\": no process given"); + return variableFinder.group(1); + } + + if (StringUtils.isNotEmpty(process.getOcrdWorkflowId())) { + return variableFinder.group(1) + process.getOcrdWorkflowId(); + } + + if (Objects.isNull(process.getTemplate())) { + logger.warn("Cannot replace \"(ocrdworkflowid)\": process has no template assigned"); + return variableFinder.group(1); + } + + if (StringUtils.isNotEmpty(process.getTemplate().getOcrdWorkflowId())) { + logger.warn("Cannot replace \"(ocrdworkflowid)\": template has no OCR-D workflow assigned"); + return variableFinder.group(1); + } + return variableFinder.group(1) + process.getTemplate().getOcrdWorkflowId(); + } + private String determineReplacementForProcesstitle(Matcher variableFinder) { if (Objects.isNull(process)) { logger.warn("Cannot replace \"(processtitle)\": no process given"); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java index ec4cc125577..93c4a86c37e 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java @@ -14,14 +14,25 @@ import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.tuple.ImmutablePair; import org.apache.commons.lang3.tuple.Pair; -import org.kitodo.production.services.ServiceManager; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.kitodo.config.ConfigCore; +import org.kitodo.config.enums.ParameterCore; +import java.io.File; +import java.io.IOException; +import java.nio.file.FileVisitOption; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.ArrayList; import java.util.List; import java.util.Objects; +import java.util.stream.Collectors; +import java.util.stream.Stream; public class OcrdWorkflowService { + private static final Logger logger = LogManager.getLogger(OcrdWorkflowService.class); private static volatile OcrdWorkflowService instance = null; /** @@ -44,21 +55,41 @@ public static OcrdWorkflowService getInstance() { } /** - * Get OCR-D workflows - available means that ... + * Get list of OCR-D workflows from directory. + *

+ * The files are relative paths to the ocr profiles directory. + *

* - * @return list of OCR-D workflows objects + * @return list of OCR-D workflows */ public List getOcrdWorkflows() { - List workflows = new ArrayList(); - workflows.add(new ImmutablePair<>("1", "One")); - workflows.add(new ImmutablePair<>("2", "Two")); - workflows.add(new ImmutablePair<>("3", "Tree")); - return workflows; + String ocrdWorkflowsDirectoryConfig = ConfigCore.getParameterOrDefaultValue(ParameterCore.OCRD_WORKFLOWS_DIR); + if (StringUtils.isNotEmpty(ocrdWorkflowsDirectoryConfig)) { + Path ocrdWorkflowsDirectory = Path.of(ocrdWorkflowsDirectoryConfig); + if (Files.isDirectory(ocrdWorkflowsDirectory)) { + try (Stream ocrProfilePaths = Files.walk(ocrdWorkflowsDirectory, FileVisitOption.FOLLOW_LINKS)) { + return ocrProfilePaths.filter(Files::isRegularFile).map(Path::toAbsolutePath) + .map(path -> path.toString().replace(ocrdWorkflowsDirectoryConfig, File.separator)).sorted() + .map(path -> ImmutablePair.of(path, Path.of(path).getFileName())) + .collect(Collectors.toList()); + } catch (IOException e) { + logger.error(e.getMessage(), e); + } + } + } + return new ArrayList<>(); } + /** + * Get an OCR-D workflow by identifier. + * + * @param ocrdWorkflowId + * @return + */ public Pair getOcrdWorkflow(String ocrdWorkflowId) { if (StringUtils.isNotEmpty(ocrdWorkflowId)) { - return getOcrdWorkflows().stream().filter(pair -> pair.getKey().equals(ocrdWorkflowId)).findFirst().get(); + return getOcrdWorkflows().stream().filter(pair -> pair.getKey().equals(ocrdWorkflowId)).findFirst() + .orElse(null); } return null; } diff --git a/Kitodo/src/main/java/org/kitodo/production/services/security/SecurityAccessService.java b/Kitodo/src/main/java/org/kitodo/production/services/security/SecurityAccessService.java index 963344c9b9d..97a1967786a 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/security/SecurityAccessService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/security/SecurityAccessService.java @@ -233,6 +233,15 @@ public boolean hasAuthorityToAddOnProjectPage() { return hasAnyAuthorityForClient("addProject, addTemplate, addWorkflow, addDocket, addRuleset"); } + /** + * Check if the current user has the authority to assign an OCR-D workflow to template or process. + * + * @return true if the current user has the authority to assign an OCR-D workflow + */ + public boolean hasAuthorityToAssignOcrdWorkflow() { + return hasAnyAuthorityForClient("assignOcrdWorkflow"); + } + /** * Check if the current user has the authority to delete the batch. * diff --git a/Kitodo/src/main/resources/kitodo_config.properties b/Kitodo/src/main/resources/kitodo_config.properties index 4f00df84098..3e891f6e793 100644 --- a/Kitodo/src/main/resources/kitodo_config.properties +++ b/Kitodo/src/main/resources/kitodo_config.properties @@ -71,6 +71,9 @@ directory.modules=/usr/local/kitodo/modules/ # Falls Dateien zum Debuggen / Tracen geschrieben werden sollen, hier ein Verzeichnis angeben directory.debug=/usr/local/kitodo/debug/ +# Absolute path to the directory that the OCR-D workflow files will be +# read from. It must be terminated by a directory separator ("/"). +ocrd.workflows.directory=/usr/local/kitodo/ocrd/workflows/ # ----------------------------------- # Directory management diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index 93a139d10b9..8028950a411 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -52,6 +52,7 @@ ARCHIVED=Archiviert assigned=Zugewiesen assignedTo=In Bearbeitung durch assignMedia=und ausgew\u00E4hlte Medien zuweisen +assignOcrdWorkflow=OCR-D Workflow zuweisen assignToNextElement=Mit n\u00E4chstem Element verkn\u00FCpfen ats=ATS actions=Aktionen @@ -837,6 +838,7 @@ numberVolumes=Anzahl der B\u00E4nde numberOfMetadata=Anzahl Metadaten objectType=Objekttyp ocr=OCR +ocrdWorkflow=OCR-D Workflow ok=Ok oldPassword=Altes Passwort onlySelectedPages=Nur die markierten Seiten @@ -888,6 +890,7 @@ position=Position ppn=PPN priority=Priorit\u00E4t process=Vorgang +processConfig.useProcessTemplateOcrdWorkflow=aus Produktionsvorlage processData=Vorgangsdaten processDetails=Vorgangsdetails processList=Vorgangsliste diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index 6b9172fa659..056604de8ec 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -52,6 +52,7 @@ ARCHIVED=Archived assigned=Assigned assignedTo=In edition by assignMedia=and assign selected media +assignOcrdWorkflow=Assign OCR-D workflow assignToNextElement=Assign to next element ats=ATS actions=Actions @@ -838,6 +839,7 @@ numberVolumes=Number of volumes numberOfMetadata=Number of metadata objectType=Object type ocr=OCR +ocrdWorkflow=OCR-D workflow ok=Ok oldPassword=Old password onlySelectedPages=Only the selected pages @@ -889,6 +891,7 @@ position=Position ppn=PPN priority=Priority process=Process +processConfig.useProcessTemplateOcrdWorkflow=From process template processData=Process data processDetails=Process details processList=Process list diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml index c928b1bbf85..45cd9aad05c 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml @@ -13,6 +13,7 @@ @@ -46,6 +47,12 @@ + +
+ + +
@@ -80,6 +87,22 @@ + +
+ + + + + + +
diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/templateEdit/details.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/templateEdit/details.xhtml index 9a7b1ad1662..88005b27ae3 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/templateEdit/details.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/templateEdit/details.xhtml @@ -13,6 +13,7 @@ @@ -95,12 +96,14 @@ -
+
+ disabled="#{isViewMode}" + converter="#{ocrdWorkflowConverter}"> + Date: Wed, 11 Oct 2023 10:38:42 +0200 Subject: [PATCH 03/14] Solve checkstyle errors --- .../converter/OcrdWorkflowConverter.java | 15 +++++++------- .../kitodo/production/forms/ProcessForm.java | 2 +- .../kitodo/production/forms/TemplateForm.java | 2 +- .../production/helper/VariableReplacer.java | 5 +++-- .../services/ocr/OcrdWorkflowService.java | 20 +++++++++---------- 5 files changed, 23 insertions(+), 21 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java b/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java index 9526aaea98e..149ecff8de8 100644 --- a/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java +++ b/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java @@ -11,15 +11,17 @@ package org.kitodo.production.converter; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.Pair; -import org.kitodo.production.services.ServiceManager; +import java.util.Objects; import javax.faces.component.UIComponent; import javax.faces.context.FacesContext; import javax.faces.convert.Converter; import javax.inject.Named; -import java.util.Objects; + +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; +import org.kitodo.production.services.ServiceManager; + @Named public class OcrdWorkflowConverter extends BeanConverter implements Converter { @@ -27,15 +29,14 @@ public class OcrdWorkflowConverter extends BeanConverter implements Converter { @Override public Object getAsObject(FacesContext context, UIComponent component, String value) { if (StringUtils.isNotEmpty(value)) { - return ServiceManager.getOcrdWorkflowService().getOcrdWorkflows().stream().filter(pair -> pair.getKey().equals(value)) - .findFirst().get(); + return ServiceManager.getOcrdWorkflowService().getOcrdWorkflow(value); } return null; } @Override public String getAsString(FacesContext context, UIComponent component, Object value) { - if(Objects.nonNull(value) && value instanceof Pair) { + if (Objects.nonNull(value) && value instanceof Pair) { return (String) ((Pair) value).getKey(); } return null; 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 65b6053d187..5c7fe18fdf2 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java @@ -902,7 +902,7 @@ public Pair getOcrdWorkflow() { */ public void setOcrdWorkflow(Pair ocrdWorkflow) { String ocrdWorkflowId = StringUtils.EMPTY; - if(Objects.nonNull(ocrdWorkflow)) { + if (Objects.nonNull(ocrdWorkflow)) { ocrdWorkflowId = ocrdWorkflow.getKey().toString(); } process.setOcrdWorkflowId(ocrdWorkflowId); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java index 8cd8f67addb..3e8745b958c 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java @@ -301,7 +301,7 @@ public Pair getOcrdWorkflow() { */ public void setOcrdWorkflow(Pair ocrdWorkflow) { String ocrdWorkflowId = StringUtils.EMPTY; - if(Objects.nonNull(ocrdWorkflow)) { + if (Objects.nonNull(ocrdWorkflow)) { ocrdWorkflowId = ocrdWorkflow.getKey().toString(); } template.setOcrdWorkflowId(ocrdWorkflowId); diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java b/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java index b04ee9a3577..30bdc154259 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java @@ -71,8 +71,9 @@ private enum MetadataLevel { * be replaced. */ private static final Pattern VARIABLE_FINDER_REGEX = Pattern.compile( - "(\\$?)\\((?:(prefs|processid|processtitle|projectid|" + "stepid|stepname|generatorsource|generatorsourcepath|ocrdworkflowid)|" + "(?:(meta|process|product|template)\\.(?:(firstchild|topstruct)\\.)?([^)]+)|" + "(?:(filename|basename|relativepath))))\\)"); - + "(\\$?)\\((?:(prefs|processid|processtitle|projectid|stepid|stepname|generatorsource|generatorsourcepath|ocrdworkflowid)|" + + "(?:(meta|process|product|template)\\.(?:(firstchild|topstruct)\\.)?([^)]+)|" + + "(?:(filename|basename|relativepath))))\\)"); /** * The map is filled with replacement instructions that are required for * backwards compatibility with version 2. diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java index 93c4a86c37e..a90d84b9cad 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java @@ -11,14 +11,6 @@ package org.kitodo.production.services.ocr; -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.tuple.ImmutablePair; -import org.apache.commons.lang3.tuple.Pair; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.Logger; -import org.kitodo.config.ConfigCore; -import org.kitodo.config.enums.ParameterCore; - import java.io.File; import java.io.IOException; import java.nio.file.FileVisitOption; @@ -30,6 +22,14 @@ import java.util.stream.Collectors; import java.util.stream.Stream; +import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; +import org.apache.commons.lang3.tuple.Pair; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.kitodo.config.ConfigCore; +import org.kitodo.config.enums.ParameterCore; + public class OcrdWorkflowService { private static final Logger logger = LogManager.getLogger(OcrdWorkflowService.class); @@ -83,8 +83,8 @@ public List getOcrdWorkflows() { /** * Get an OCR-D workflow by identifier. * - * @param ocrdWorkflowId - * @return + * @param ocrdWorkflowId The OCR-D workflow identifier + * @return The OCR-D workflow */ public Pair getOcrdWorkflow(String ocrdWorkflowId) { if (StringUtils.isNotEmpty(ocrdWorkflowId)) { From 89b126dcdebb497e26af561a2843ee81e6c42180 Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Wed, 11 Oct 2023 11:15:11 +0200 Subject: [PATCH 04/14] Add variable replacer test for replacement of ocrdworkflowid placeholder --- .../production/helper/VariableReplacer.java | 2 +- .../helper/VariableReplacerTest.java | 26 ++++++++++++++++--- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java b/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java index 30bdc154259..2ff1e071157 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java @@ -298,7 +298,7 @@ private String determineReplacementForOcrdWorkflowId(Matcher variableFinder) { return variableFinder.group(1); } - if (StringUtils.isNotEmpty(process.getTemplate().getOcrdWorkflowId())) { + if (StringUtils.isEmpty(process.getTemplate().getOcrdWorkflowId())) { logger.warn("Cannot replace \"(ocrdworkflowid)\": template has no OCR-D workflow assigned"); return variableFinder.group(1); } diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java index de8cee8174e..cdb30854447 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java @@ -19,10 +19,8 @@ import org.junit.Test; import org.kitodo.config.KitodoConfig; -import org.kitodo.data.database.beans.Folder; +import org.kitodo.data.database.beans.*; import org.kitodo.data.database.beans.Process; -import org.kitodo.data.database.beans.Project; -import org.kitodo.data.database.beans.Ruleset; public class VariableReplacerTest { @@ -159,6 +157,26 @@ public void shouldReplaceGeneratorSourcePath() { replaced); } + @Test + public void shouldReplaceOcrdWorkflowId() { + Process process = prepareProcess(); + Template template = new Template(); + template.setOcrdWorkflowId("/template-ocrd-workflow.sh"); + process.setTemplate(template); + + VariableReplacer variableReplacerTemplate = new VariableReplacer(null, process, null); + String replaced = variableReplacerTemplate.replace("-title (ocrdworkflowid) -hardcoded test"); + String expected = "-title " + template.getOcrdWorkflowId() + " -hardcoded test"; + assertEquals("String was replaced incorrectly!", expected, replaced); + + process.setOcrdWorkflowId("/process-ocrd-workflow.sh"); + VariableReplacer variableReplacerProcess = new VariableReplacer(null, process, null); + replaced = variableReplacerProcess.replace("-title (ocrdworkflowid) -hardcoded test"); + expected = "-title " + process.getOcrdWorkflowId() + " -hardcoded test"; + assertEquals("String was replaced incorrectly!", expected, replaced); + } + + private Process prepareProcess() { Process process = new Process(); process.setId(2); @@ -175,8 +193,8 @@ private Process prepareProcess() { project.setId(projectId); process.setProject(project); scansFolder.setProject(project); - project.getFolders().add(scansFolder); project.setGeneratorSource(scansFolder); + project.getFolders().add(scansFolder); return process; } From 41a20b8db8b0d3d8a4b9415e1ae487ca44150966 Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Wed, 11 Oct 2023 11:19:05 +0200 Subject: [PATCH 05/14] Fix variable replace test --- .../kitodo/production/helper/VariableReplacerTest.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java index cdb30854447..fa6f45820f3 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java @@ -19,8 +19,12 @@ import org.junit.Test; import org.kitodo.config.KitodoConfig; -import org.kitodo.data.database.beans.*; +import org.kitodo.data.database.beans.Folder; import org.kitodo.data.database.beans.Process; +import org.kitodo.data.database.beans.Project; +import org.kitodo.data.database.beans.Ruleset; +import org.kitodo.data.database.beans.Template; + public class VariableReplacerTest { @@ -193,8 +197,8 @@ private Process prepareProcess() { project.setId(projectId); process.setProject(project); scansFolder.setProject(project); - project.setGeneratorSource(scansFolder); project.getFolders().add(scansFolder); + project.setGeneratorSource(scansFolder); return process; } From 8af9c07a68bb3e28f16320576ffc31e51955e71d Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Wed, 11 Oct 2023 11:21:33 +0200 Subject: [PATCH 06/14] Remove line --- .../java/org/kitodo/production/helper/VariableReplacerTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java b/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java index fa6f45820f3..403fbaf4b24 100644 --- a/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java +++ b/Kitodo/src/test/java/org/kitodo/production/helper/VariableReplacerTest.java @@ -25,7 +25,6 @@ import org.kitodo.data.database.beans.Ruleset; import org.kitodo.data.database.beans.Template; - public class VariableReplacerTest { int projectId = 12; From aa157b022c8741b47ece8b7eda51a2280d4882f9 Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Wed, 11 Oct 2023 14:16:02 +0200 Subject: [PATCH 07/14] Improve OCR-D workflow list --- .../production/services/ocr/OcrdWorkflowService.java | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java index a90d84b9cad..9f471628002 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java @@ -68,9 +68,8 @@ public List getOcrdWorkflows() { Path ocrdWorkflowsDirectory = Path.of(ocrdWorkflowsDirectoryConfig); if (Files.isDirectory(ocrdWorkflowsDirectory)) { try (Stream ocrProfilePaths = Files.walk(ocrdWorkflowsDirectory, FileVisitOption.FOLLOW_LINKS)) { - return ocrProfilePaths.filter(Files::isRegularFile).map(Path::toAbsolutePath) - .map(path -> path.toString().replace(ocrdWorkflowsDirectoryConfig, File.separator)).sorted() - .map(path -> ImmutablePair.of(path, Path.of(path).getFileName())) + return ocrProfilePaths.filter(Files::isRegularFile).map(Path::toAbsolutePath).sorted() + .map(path -> getImmutablePairFromPath(path, ocrdWorkflowsDirectory)) .collect(Collectors.toList()); } catch (IOException e) { logger.error(e.getMessage(), e); @@ -80,6 +79,13 @@ public List getOcrdWorkflows() { return new ArrayList<>(); } + private static Pair getImmutablePairFromPath(Path filePath, Path ocrdWorkflowsDirectory) { + String path = filePath.toString(); + path = path.replace(ocrdWorkflowsDirectory.toString(), StringUtils.EMPTY); + path = StringUtils.removeStart(path, "/"); + return ImmutablePair.of(path, path); + } + /** * Get an OCR-D workflow by identifier. * From 5662a3d8ced2bae9c094eeab5209e64dcef1c563 Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Wed, 11 Oct 2023 14:20:39 +0200 Subject: [PATCH 08/14] Rename profiles to OCR-D workflow --- .../production/controller/SecurityAccessController.java | 4 ++-- .../kitodo/production/services/ocr/OcrdWorkflowService.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java index 1b92034cbd8..72eb057e8e4 100644 --- a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java +++ b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java @@ -223,9 +223,9 @@ public boolean hasAuthorityToAddOnProjectPage() { } /** - * Check if the current user has the authority to add OCR profile. + * Check if the current user has the authority to add OCR-D workflow. * - * @return true if the current user has the authority to add OCR profile. + * @return true if the current user has the authority to add OCR-D workflow. */ public boolean hasAuthorityToAssignOcrdWorkflow() { return securityAccessService.hasAuthorityToAssignOcrdWorkflow(); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java index 9f471628002..6a04c6ac116 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java @@ -57,7 +57,7 @@ public static OcrdWorkflowService getInstance() { /** * Get list of OCR-D workflows from directory. *

- * The files are relative paths to the ocr profiles directory. + * The files are relative paths to the OCR-D workflow directory. *

* * @return list of OCR-D workflows From 0aec943d1a70f45ab9951d07907b3a417194c3fb Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Wed, 1 Nov 2023 17:18:32 +0100 Subject: [PATCH 09/14] Rename message key and remove unused import --- .../org/kitodo/production/services/ocr/OcrdWorkflowService.java | 1 - Kitodo/src/main/resources/messages/messages_de.properties | 2 +- Kitodo/src/main/resources/messages/messages_en.properties | 2 +- .../webapp/WEB-INF/templates/includes/processEdit/details.xhtml | 2 +- 4 files changed, 3 insertions(+), 4 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java index 6a04c6ac116..419a1a82109 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java @@ -11,7 +11,6 @@ package org.kitodo.production.services.ocr; -import java.io.File; import java.io.IOException; import java.nio.file.FileVisitOption; import java.nio.file.Files; diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index e040df3ba5b..d8b8434909e 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -891,7 +891,7 @@ position=Position ppn=PPN priority=Priorit\u00E4t process=Vorgang -processConfig.useProcessTemplateOcrdWorkflow=aus Produktionsvorlage +processConfig.fromTemplate=aus Produktionsvorlage processData=Vorgangsdaten processDetails=Vorgangsdetails processList=Vorgangsliste diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index 3473c534de0..5491bf80a93 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -892,7 +892,7 @@ position=Position ppn=PPN priority=Priority process=Process -processConfig.useProcessTemplateOcrdWorkflow=From process template +processConfig.fromTemplate=From process template processData=Process data processDetails=Process details processList=Process list diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml index 45cd9aad05c..dbb7f39633b 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml @@ -94,7 +94,7 @@ disabled="#{isViewMode}" converter="#{ocrdWorkflowConverter}"> Date: Mon, 27 Nov 2023 14:17:55 +0100 Subject: [PATCH 10/14] Complete DFG Viewer ruleset's XSLT file --- Kitodo/src/main/resources/xslt/dfg-viewer.xsl | 133 +++++++++++++++++- 1 file changed, 128 insertions(+), 5 deletions(-) diff --git a/Kitodo/src/main/resources/xslt/dfg-viewer.xsl b/Kitodo/src/main/resources/xslt/dfg-viewer.xsl index fe27b34bdb1..520324f3cd0 100644 --- a/Kitodo/src/main/resources/xslt/dfg-viewer.xsl +++ b/Kitodo/src/main/resources/xslt/dfg-viewer.xsl @@ -11,13 +11,136 @@ * GPL3-License.txt file that was distributed with this source code. * --> - + + - - - + + + - + + + + + + + + + + + + + + + + + + + + + + + + + + physSequence + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 3058faed920573e84d13358b6e19d738909267da Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Tue, 28 Nov 2023 10:57:39 +0100 Subject: [PATCH 11/14] Make use of full page width on role edit details page --- .../templates/includes/roleEdit/details.xhtml | 91 ++++++++++--------- 1 file changed, 46 insertions(+), 45 deletions(-) diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/roleEdit/details.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/roleEdit/details.xhtml index 34752a6435e..503a33fe4f9 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/roleEdit/details.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/roleEdit/details.xhtml @@ -42,52 +42,53 @@ -
- - - - -

- -

- - #{msgs.available} - #{msgs.assigned} - -
+ + + + +

+ +

+ + #{msgs.available} + #{msgs.assigned} + +
+
- - -

- -

- - #{msgs.available} - #{msgs.assigned} - -
-
-
+ + + +

+ +

+ + #{msgs.available} + #{msgs.assigned} + +
+
+ From 07507f5e4ee1871756c31654f3c2f27dfab018d8 Mon Sep 17 00:00:00 2001 From: Markus Weigelt Date: Tue, 28 Nov 2023 15:45:21 +0100 Subject: [PATCH 12/14] Improvments from review --- ...d_authority_and_fields_for_ocrd_workflows.sql} | 0 .../org/kitodo/production/forms/ProcessForm.java | 15 ++++++++++++--- .../org/kitodo/production/forms/TemplateForm.java | 6 +++--- .../services/ocr/OcrdWorkflowService.java | 6 +++--- .../src/main/resources/kitodo_config.properties | 2 +- .../templates/includes/processEdit/details.xhtml | 7 +------ 6 files changed, 20 insertions(+), 16 deletions(-) rename Kitodo-DataManagement/src/main/resources/db/migration/{V2_125__Add_authority_and_fields_for_ocrd_workflows.sql => V2_126__Add_authority_and_fields_for_ocrd_workflows.sql} (100%) diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_126__Add_authority_and_fields_for_ocrd_workflows.sql similarity index 100% rename from Kitodo-DataManagement/src/main/resources/db/migration/V2_125__Add_authority_and_fields_for_ocrd_workflows.sql rename to Kitodo-DataManagement/src/main/resources/db/migration/V2_126__Add_authority_and_fields_for_ocrd_workflows.sql 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 43181d932f9..0bd56c0dcbf 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java @@ -883,7 +883,7 @@ public List getProjects() { * * @return list of OCR-D workflows */ - public List getOcrdWorkflows() { + public List> getOcrdWorkflows() { return ServiceManager.getOcrdWorkflowService().getOcrdWorkflows(); } @@ -892,17 +892,26 @@ public List getOcrdWorkflows() { * * @return Immutable key value pair */ - public Pair getOcrdWorkflow() { + public Pair getOcrdWorkflow() { return ServiceManager.getOcrdWorkflowService().getOcrdWorkflow(process.getOcrdWorkflowId()); } + /** + * Get the OCR-D workflow of process template. + * + * @return Immutable key value pair + */ + public Pair getOcrdWorkflowOfTemplate() { + return ServiceManager.getOcrdWorkflowService().getOcrdWorkflow(process.getTemplate().getOcrdWorkflowId()); + } + /** * Set the OCR-D workflow. * * @param ocrdWorkflow * The immutable key value pair */ - public void setOcrdWorkflow(Pair ocrdWorkflow) { + public void setOcrdWorkflow(Pair ocrdWorkflow) { String ocrdWorkflowId = StringUtils.EMPTY; if (Objects.nonNull(ocrdWorkflow)) { ocrdWorkflowId = ocrdWorkflow.getKey().toString(); diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java b/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java index 3e8745b958c..e852d31f89b 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java @@ -280,7 +280,7 @@ public List getWorkflows() { * * @return list of OCR-D workflows */ - public List getOcrdWorkflows() { + public List> getOcrdWorkflows() { return ServiceManager.getOcrdWorkflowService().getOcrdWorkflows(); } @@ -289,7 +289,7 @@ public List getOcrdWorkflows() { * * @return Immutable key value pair */ - public Pair getOcrdWorkflow() { + public Pair getOcrdWorkflow() { return ServiceManager.getOcrdWorkflowService().getOcrdWorkflow(template.getOcrdWorkflowId()); } @@ -299,7 +299,7 @@ public Pair getOcrdWorkflow() { * @param ocrdWorkflow * The immutable key value pair */ - public void setOcrdWorkflow(Pair ocrdWorkflow) { + public void setOcrdWorkflow(Pair ocrdWorkflow) { String ocrdWorkflowId = StringUtils.EMPTY; if (Objects.nonNull(ocrdWorkflow)) { ocrdWorkflowId = ocrdWorkflow.getKey().toString(); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java index 419a1a82109..ab8d4f41e18 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrdWorkflowService.java @@ -61,7 +61,7 @@ public static OcrdWorkflowService getInstance() { * * @return list of OCR-D workflows */ - public List getOcrdWorkflows() { + public List> getOcrdWorkflows() { String ocrdWorkflowsDirectoryConfig = ConfigCore.getParameterOrDefaultValue(ParameterCore.OCRD_WORKFLOWS_DIR); if (StringUtils.isNotEmpty(ocrdWorkflowsDirectoryConfig)) { Path ocrdWorkflowsDirectory = Path.of(ocrdWorkflowsDirectoryConfig); @@ -78,7 +78,7 @@ public List getOcrdWorkflows() { return new ArrayList<>(); } - private static Pair getImmutablePairFromPath(Path filePath, Path ocrdWorkflowsDirectory) { + private static Pair getImmutablePairFromPath(Path filePath, Path ocrdWorkflowsDirectory) { String path = filePath.toString(); path = path.replace(ocrdWorkflowsDirectory.toString(), StringUtils.EMPTY); path = StringUtils.removeStart(path, "/"); @@ -91,7 +91,7 @@ private static Pair getImmutablePairFromPath(Path filePath, Path ocrdWorkflowsDi * @param ocrdWorkflowId The OCR-D workflow identifier * @return The OCR-D workflow */ - public Pair getOcrdWorkflow(String ocrdWorkflowId) { + public Pair getOcrdWorkflow(String ocrdWorkflowId) { if (StringUtils.isNotEmpty(ocrdWorkflowId)) { return getOcrdWorkflows().stream().filter(pair -> pair.getKey().equals(ocrdWorkflowId)).findFirst() .orElse(null); diff --git a/Kitodo/src/main/resources/kitodo_config.properties b/Kitodo/src/main/resources/kitodo_config.properties index cbf17c65c4f..e1fb72ff1c8 100644 --- a/Kitodo/src/main/resources/kitodo_config.properties +++ b/Kitodo/src/main/resources/kitodo_config.properties @@ -73,7 +73,7 @@ directory.debug=/usr/local/kitodo/debug/ # Absolute path to the directory that the OCR-D workflow files will be # read from. It must be terminated by a directory separator ("/"). -ocrd.workflows.directory=/usr/local/kitodo/ocrd/workflows/ +ocrd.workflows.directory=/usr/local/kitodo/ocrd_workflows/ # ----------------------------------- # Directory management diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml index dbb7f39633b..45474d56a97 100644 --- a/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/processEdit/details.xhtml @@ -48,11 +48,6 @@
-
- - -
@@ -94,7 +89,7 @@ disabled="#{isViewMode}" converter="#{ocrdWorkflowConverter}"> Date: Tue, 28 Nov 2023 16:15:18 +0100 Subject: [PATCH 13/14] Improve types --- .../kitodo/production/converter/OcrdWorkflowConverter.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java b/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java index 149ecff8de8..4070df06cf5 100644 --- a/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java +++ b/Kitodo/src/main/java/org/kitodo/production/converter/OcrdWorkflowConverter.java @@ -24,7 +24,7 @@ @Named -public class OcrdWorkflowConverter extends BeanConverter implements Converter { +public class OcrdWorkflowConverter extends BeanConverter implements Converter { @Override public Object getAsObject(FacesContext context, UIComponent component, String value) { @@ -36,8 +36,8 @@ public Object getAsObject(FacesContext context, UIComponent component, String va @Override public String getAsString(FacesContext context, UIComponent component, Object value) { - if (Objects.nonNull(value) && value instanceof Pair) { - return (String) ((Pair) value).getKey(); + if (Objects.nonNull(value) && value instanceof Pair) { + return (String) ((Pair) value).getKey(); } return null; } From d8bdb149ddea1cd0dc3ea4355b783bca38898db2 Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Wed, 29 Nov 2023 13:23:56 +0100 Subject: [PATCH 14/14] Update Kitodo/src/main/resources/xslt/dfg-viewer.xsl Co-authored-by: Arved Solth --- Kitodo/src/main/resources/xslt/dfg-viewer.xsl | 1 - 1 file changed, 1 deletion(-) diff --git a/Kitodo/src/main/resources/xslt/dfg-viewer.xsl b/Kitodo/src/main/resources/xslt/dfg-viewer.xsl index 520324f3cd0..a38b30f33cc 100644 --- a/Kitodo/src/main/resources/xslt/dfg-viewer.xsl +++ b/Kitodo/src/main/resources/xslt/dfg-viewer.xsl @@ -14,7 +14,6 @@