Skip to content

Commit

Permalink
Initial commit of OCR-D workflow implementaiton
Browse files Browse the repository at this point in the history
  • Loading branch information
markusweigelt committed Oct 9, 2023
1 parent e107408 commit c7e3aac
Show file tree
Hide file tree
Showing 7 changed files with 210 additions and 0 deletions.
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
* as profile object
*/
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,16 @@
--
-- (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 column of OCR-D workflow identifier
ALTER TABLE template ADD ocrd_workflow_id varchar(255) DEFAULT NULL;
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* (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 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;
}

}
29 changes: 29 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,34 @@ 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) {
template.setOcrdWorkflowId(ocrdWorkflow.getKey().toString());
}

/**
* 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 @@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* (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.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<Pair> 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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,19 @@
</p:selectOneMenu>
</div>

<div>
<p:outputLabel for="ocrdWorkflow" value="#{msgs.ocrdWorkflow}"/>
<p:selectOneMenu id="ocrdWorkflow" value="#{TemplateForm.ocrdWorkflow}"
title="#{TemplateForm.ocrdWorkflow}" disabled="#{isViewMode}"
converter="#{ocrdWorkflowConverter}"
required="#{not empty param['editForm:save']}">
<f:selectItems value="#{TemplateForm.ocrdWorkflows}"
var="ocrdWorkflow"
itemValue="#{ocrdWorkflow}"
itemLabel="#{ocrdWorkflow.value}"/>
<p:ajax event="change" oncomplete="toggleSave()"/>
</p:selectOneMenu>
</div>
</p:row>
</p:panelGrid>
</ui:composition>

0 comments on commit c7e3aac

Please sign in to comment.