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

OCR-D Workflow integration (without entity implementation) #5809

Merged
merged 13 commits into from
Nov 28, 2023
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public class Template extends BaseTemplateBean {
@JoinColumn(name = "project_id", foreignKey = @ForeignKey(name = "FK_project_x_template_project_id")) })
private List<Project> projects;

@Column(name = "ocrd_workflow_id")
private String ocrdWorkflowId;

/**
* Constructor.
*/
Expand Down Expand Up @@ -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
* The identifier of the OCR-D workflow
*/
public void setOcrdWorkflowId(String ocrdWorkflowId) {
this.ocrdWorkflowId = ocrdWorkflowId;
}

/**
* Get projects list.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
--
-- (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.
--

-- Add authority to assign OCR-D workflow in template or process details
INSERT IGNORE INTO authority (title) VALUES ('assignOcrdWorkflow_clientAssignable');

-- 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;
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ public enum ParameterCore implements ParameterInterface {
*/
DIR_RULESETS(new Parameter<UndefinedParameter>("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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ public boolean hasAuthorityToAddOnProjectPage() {
return securityAccessService.hasAuthorityToAddOnProjectPage();
}

/**
* 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-D workflow.
*/
public boolean hasAuthorityToAssignOcrdWorkflow() {
return securityAccessService.hasAuthorityToAssignOcrdWorkflow();
}

/**
* Check if the current user has the authority to delete the batch.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
/*
* (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.production.converter;

import java.util.Objects;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.inject.Named;

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<Object> {

@Override
public Object getAsObject(FacesContext context, UIComponent component, String value) {
if (StringUtils.isNotEmpty(value)) {
return ServiceManager.getOcrdWorkflowService().getOcrdWorkflow(value);
}
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;
}

}
42 changes: 42 additions & 0 deletions Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,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.config.ConfigCore;
Expand Down Expand Up @@ -877,6 +878,47 @@ public List<Project> getProjects() {
return ServiceManager.getProjectService().getAllForSelectedClient();
}

/**
* Get list of OCR-D workflows for select list.
*
* @return list of OCR-D workflows
*/
public List<Pair<?, ?>> getOcrdWorkflows() {
return ServiceManager.getOcrdWorkflowService().getOcrdWorkflows();
}

/**
* Get the OCR-D workflow.
*
* @return Immutable key value pair
*/
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) {
String ocrdWorkflowId = StringUtils.EMPTY;
if (Objects.nonNull(ocrdWorkflow)) {
ocrdWorkflowId = ocrdWorkflow.getKey().toString();
}
process.setOcrdWorkflowId(ocrdWorkflowId);
}

/**
* Get rulesets for select list.
*
Expand Down
33 changes: 33 additions & 0 deletions Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -274,6 +275,38 @@ public List<Workflow> getWorkflows() {
return ServiceManager.getWorkflowService().getAvailableWorkflows();
}

/**
* Get list of OCR-D workflows for select list.
*
* @return list of OCR-D workflows
*/
public List<Pair<?, ?>> 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) {
String ocrdWorkflowId = StringUtils.EMPTY;
if (Objects.nonNull(ocrdWorkflow)) {
ocrdWorkflowId = ocrdWorkflow.getKey().toString();
}
template.setOcrdWorkflowId(ocrdWorkflowId);
}

/**
* Check if user is not assigned to the project. Used for disabling projects.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -70,10 +71,9 @@ 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
* backwards compatibility with version 2.
Expand Down Expand Up @@ -244,6 +244,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();
Expand Down Expand Up @@ -281,6 +283,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.isEmpty(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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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.
Expand Down
Loading