diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/OcrProfile.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/OcrProfile.java new file mode 100644 index 00000000000..c732e24bee2 --- /dev/null +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/OcrProfile.java @@ -0,0 +1,91 @@ +/* + * (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.data.database.beans; + +import java.util.Objects; + +import javax.persistence.Column; +import javax.persistence.Entity; +import javax.persistence.ForeignKey; +import javax.persistence.JoinColumn; +import javax.persistence.ManyToOne; +import javax.persistence.Table; + +@Entity +@Table(name = "ocrprofile") +public class OcrProfile extends BaseBean { + + @Column(name = "title") + private String title; + + @Column(name = "file") + private String file; + + @ManyToOne + @JoinColumn(name = "client_id", foreignKey = @ForeignKey(name = "FK_ocrprofile_client_id")) + private Client client; + + public String getTitle() { + return this.title; + } + + public void setTitle(String title) { + this.title = title; + } + + public String getFile() { + return this.file; + } + + public void setFile(String file) { + this.file = file; + } + + + /** + * Get client. + * + * @return Client object + */ + public Client getClient() { + return this.client; + } + + /** + * Set client. + * + * @param client + * as Client object + */ + public void setClient(Client client) { + this.client = client; + } + + @Override + public boolean equals(Object object) { + if (this == object) { + return true; + } + + if (object instanceof OcrProfile) { + OcrProfile ocrProfile = (OcrProfile) object; + return Objects.equals(this.getId(), ocrProfile.getId()); + } + + return false; + } + + @Override + public int hashCode() { + return Objects.hash(title, file); + } +} 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..350e305f968 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 @@ -62,6 +62,10 @@ public class Process extends BaseTemplateBean { @JoinColumn(name = "docket_id", foreignKey = @ForeignKey(name = "FK_process_docket_id")) private Docket docket; + @ManyToOne + @JoinColumn(name = "ocr_profile_id", foreignKey = @ForeignKey(name = "FK_process_ocr_profile_id")) + private OcrProfile ocrProfile; + @ManyToOne @JoinColumn(name = "project_id", foreignKey = @ForeignKey(name = "FK_process_project_id")) private Project project; @@ -289,6 +293,25 @@ public void setDocket(Docket docket) { this.docket = docket; } + /** + * Get OCR profile. + * + * @return value of OCR profile + */ + public OcrProfile getOcrProfile() { + return ocrProfile; + } + + /** + * Set OCR profile. + * + * @param ocrProfile + * as profile object + */ + public void setOcrProfile(OcrProfile ocrProfile) { + this.ocrProfile = ocrProfile; + } + /** * Get template. * 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..78facadc0e0 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 @@ -52,6 +52,10 @@ public class Template extends BaseTemplateBean { @JoinColumn(name = "workflow_id", foreignKey = @ForeignKey(name = "FK_template_workflow_id")) private Workflow workflow; + @ManyToOne + @JoinColumn(name = "ocr_profile_id", foreignKey = @ForeignKey(name = "FK_template_ocr_profile_id")) + private OcrProfile ocrProfile; + @OneToMany(mappedBy = "template", cascade = CascadeType.ALL, orphanRemoval = true) private List processes; @@ -168,6 +172,25 @@ public void setWorkflow(Workflow workflow) { this.workflow = workflow; } + /** + * Get OCR profile. + * + * @return value of OCR profile + */ + public OcrProfile getOcrProfile() { + return ocrProfile; + } + + /** + * Set OCR profile. + * + * @param ocrProfile + * as profile object + */ + public void setOcrProfile(OcrProfile ocrProfile) { + this.ocrProfile = ocrProfile; + } + /** * Get projects list. * diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/persistence/OcrProfileDAO.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/persistence/OcrProfileDAO.java new file mode 100644 index 00000000000..69dd64bba6c --- /dev/null +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/persistence/OcrProfileDAO.java @@ -0,0 +1,64 @@ +/* + * (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.data.database.persistence; + +import java.util.Collections; +import java.util.List; +import java.util.Objects; + +import org.kitodo.data.database.beans.OcrProfile; +import org.kitodo.data.database.exceptions.DAOException; + +public class OcrProfileDAO extends BaseDAO { + + @Override + public OcrProfile getById(Integer id) throws DAOException { + OcrProfile ocrProfile = retrieveObject(OcrProfile.class, id); + if (Objects.isNull(ocrProfile)) { + throw new DAOException("Object cannot be found in database"); + } + return ocrProfile; + } + + @Override + public List getAll() throws DAOException { + return retrieveAllObjects(OcrProfile.class); + } + + @Override + public List getAll(int offset, int size) throws DAOException { + return retrieveObjects("FROM OcrProfile ORDER BY id ASC", offset, size); + } + + @Override + public List getAllNotIndexed(int offset, int size) throws DAOException { + throw new UnsupportedOperationException(); + } + + @Override + public void remove(Integer ocrProfileId) throws DAOException { + removeObject(OcrProfile.class, ocrProfileId); + } + + /** + * Get available OCR profile - available means that OCR profile is assigned to client with given id. + * + * @param clientId + * id of client to which searched OCR profiles should be assigned + * @return list of available OCR profiles objects + */ + public List getAvailableOcrProfiles(int clientId) { + return getByQuery("SELECT w FROM OcrProfile AS w INNER JOIN w.client AS c WITH c.id = :clientId", + Collections.singletonMap("clientId", clientId)); + } + +} diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_124__Add_authorities_to_manage_ocr_profiles.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_124__Add_authorities_to_manage_ocr_profiles.sql new file mode 100644 index 00000000000..bffc154f3a0 --- /dev/null +++ b/Kitodo-DataManagement/src/main/resources/db/migration/V2_124__Add_authorities_to_manage_ocr_profiles.sql @@ -0,0 +1,40 @@ +-- +-- (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 authorities to manage OCR profile +INSERT IGNORE INTO authority (title) VALUES ('addOcrProfile_clientAssignable'); +INSERT IGNORE INTO authority (title) VALUES ('editOcrProfile_clientAssignable'); +INSERT IGNORE INTO authority (title) VALUES ('deleteOcrProfile_clientAssignable'); +INSERT IGNORE INTO authority (title) VALUES ('viewOcrProfile_clientAssignable'); + +-- Add table "ocrprofile" +CREATE TABLE IF NOT EXISTS ocrprofile ( + id INT(10) NOT NULL AUTO_INCREMENT, + title varchar(255) NOT NULL, + file varchar(255) NOT NULL, + client_id INT(10) NOT NULL, + PRIMARY KEY(id) +) DEFAULT CHARACTER SET = utf8mb4 + COLLATE utf8mb4_unicode_ci; + +-- Add column related to OCR profile to process table +ALTER TABLE process ADD ocr_profile_id INT(11) DEFAULT NULL; + +-- Add foreign key +ALTER TABLE process add constraint `FK_process_ocr_profile_id` + foreign key (ocr_profile_id) REFERENCES ocrprofile(id); + +-- Add column related to OCR profile to template table +ALTER TABLE template ADD ocr_profile_id INT(11) DEFAULT NULL; + +-- Add foreign key +ALTER TABLE template add constraint `FK_template_ocr_profile_id` + foreign key (ocr_profile_id) REFERENCES ocrprofile(id); diff --git a/Kitodo-DataManagement/src/test/resources/hibernate.cfg.xml b/Kitodo-DataManagement/src/test/resources/hibernate.cfg.xml index b972d7b1769..93fc262c385 100644 --- a/Kitodo-DataManagement/src/test/resources/hibernate.cfg.xml +++ b/Kitodo-DataManagement/src/test/resources/hibernate.cfg.xml @@ -67,6 +67,7 @@ + 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 b300555428b..c556b2eaf60 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 ("/"). + */ + DIR_OCR_PROFILES(new Parameter("directory.ocr.profiles")), + /** * 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 a93fd26fed4..dff88c1c344 100644 --- a/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java +++ b/Kitodo/src/main/java/org/kitodo/production/controller/SecurityAccessController.java @@ -1081,4 +1081,40 @@ public boolean hasAuthorityToViewDatabaseStatistics() { public boolean hasAuthorityToRunKitodoScripts() { return securityAccessService.hasAuthorityToRunKitodoScripts(); } + + /** + * 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 hasAuthorityToAddOcrProfile() { + return securityAccessService.hasAuthorityToAddOcrProfile(); + } + + /** + * Check if the current user has the authority to edit OCR profile. + * + * @return true if the current user has the authority to edit OCR profile. + */ + public boolean hasAuthorityToEditOcrProfile() { + return securityAccessService.hasAuthorityToEditOcrProfile(); + } + + /** + * Check if the current user has the authority to delete OCR profile. + * + * @return true if the current user has the authority to delete OCR profile. + */ + public boolean hasAuthorityToDeleteOcrProfile() { + return securityAccessService.hasAuthorityToDeleteOcrProfile(); + } + + /** + * Check if the current user has the authority to view OCR profile. + * + * @return true if the current user has the authority to view OCR profile. + */ + public boolean hasAuthorityToViewOcrProfile() { + return securityAccessService.hasAuthorityToViewOcrProfile(); + } } diff --git a/Kitodo/src/main/java/org/kitodo/production/converter/OcrProfileConverter.java b/Kitodo/src/main/java/org/kitodo/production/converter/OcrProfileConverter.java new file mode 100644 index 00000000000..e032858ebf0 --- /dev/null +++ b/Kitodo/src/main/java/org/kitodo/production/converter/OcrProfileConverter.java @@ -0,0 +1,34 @@ +/* + * (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 javax.faces.component.UIComponent; +import javax.faces.context.FacesContext; +import javax.faces.convert.Converter; +import javax.inject.Named; + +import org.kitodo.production.services.ServiceManager; + +@Named("OcrProfileConverter") +public class OcrProfileConverter extends BeanConverter implements Converter { + + @Override + public Object getAsObject(FacesContext context, UIComponent component, String value) { + return getAsObject(ServiceManager.getOcrProfileService(), value); + } + + @Override + public String getAsString(FacesContext context, UIComponent component, Object value) { + return getAsString(value, "ocrProfile"); + } + +} diff --git a/Kitodo/src/main/java/org/kitodo/production/dto/OcrProfileDTO.java b/Kitodo/src/main/java/org/kitodo/production/dto/OcrProfileDTO.java new file mode 100644 index 00000000000..c3741e2f7c5 --- /dev/null +++ b/Kitodo/src/main/java/org/kitodo/production/dto/OcrProfileDTO.java @@ -0,0 +1,79 @@ +/* + * (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.dto; + +/** + * OCR profile DTO object. + */ +public class OcrProfileDTO extends BaseDTO { + + private String file; + private String title; + private ClientDTO client; + + /** + * Get file. + * + * @return file as String + */ + public String getFile() { + return file; + } + + /** + * Set file. + * + * @param file + * as String + */ + public void setFile(String file) { + this.file = file; + } + + /** + * Get title. + * + * @return title as String + */ + public String getTitle() { + return title; + } + + /** + * Set title. + * + * @param title + * as String + */ + public void setTitle(String title) { + this.title = title; + } + + /** + * Get client object. + * + * @return value of clientDTO + */ + public ClientDTO getClient() { + return client; + } + + /** + * Set client object. + * + * @param client + * as org.kitodo.production.dto.ClientDTO + */ + public void setClientDTO(ClientDTO client) { + this.client = client; + } +} diff --git a/Kitodo/src/main/java/org/kitodo/production/enums/ObjectType.java b/Kitodo/src/main/java/org/kitodo/production/enums/ObjectType.java index 95b03001ba9..b623296798e 100644 --- a/Kitodo/src/main/java/org/kitodo/production/enums/ObjectType.java +++ b/Kitodo/src/main/java/org/kitodo/production/enums/ObjectType.java @@ -29,6 +29,7 @@ public enum ObjectType { PROJECT("project", "projects", true), PROPERTY("property", "properties", false), RULESET("ruleset", "rulesets", true), + OCR_PROFILE("ocrprofile", "ocrprofiles", false), TASK("task", "tasks", true), TEMPLATE("template", "template", true), USER("user", "users", false), diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/OcrProfileEditView.java b/Kitodo/src/main/java/org/kitodo/production/forms/OcrProfileEditView.java new file mode 100644 index 00000000000..79f1f65fadb --- /dev/null +++ b/Kitodo/src/main/java/org/kitodo/production/forms/OcrProfileEditView.java @@ -0,0 +1,120 @@ +/* + * (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.forms; + +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.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; +import java.util.stream.Collectors; +import java.util.stream.Stream; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Named; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.kitodo.config.ConfigCore; +import org.kitodo.config.enums.ParameterCore; +import org.kitodo.data.database.beans.OcrProfile; +import org.kitodo.data.database.exceptions.DAOException; +import org.kitodo.production.enums.ObjectType; +import org.kitodo.production.helper.Helper; +import org.kitodo.production.services.ServiceManager; + +@Named("OcrProfileEditView") +@SessionScoped +public class OcrProfileEditView extends BaseForm { + + private static final Logger logger = LogManager.getLogger(OcrProfileEditView.class); + private OcrProfile ocrProfile = new OcrProfile(); + + /** + * Load OCR profile by ID. + * + * @param id + * ID of OCR profile to load + */ + public void load(int id) { + try { + if (id > 0) { + ocrProfile = ServiceManager.getOcrProfileService().getById(id); + } else { + ocrProfile = new OcrProfile(); + } + setSaveDisabled(true); + } catch (DAOException e) { + Helper.setErrorMessage(ERROR_LOADING_ONE, + new Object[] {ObjectType.OCR_PROFILE.getTranslationSingular(), id}, logger, e); + } + } + + /** + * Save OCR profile. + * + * @return page or empty String + */ + public String save() { + try { + ocrProfile.setClient(ServiceManager.getUserService().getSessionClientOfAuthenticatedUser()); + ServiceManager.getOcrProfileService().saveToDatabase(ocrProfile); + return projectsPage; + } catch (DAOException e) { + Helper.setErrorMessage(ERROR_SAVING, new Object[] {ObjectType.OCR_PROFILE.getTranslationSingular()}, logger, + e); + return this.stayOnCurrentPage; + } + } + + /** + * Get list of OCR profile files. + *

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

+ * @return list of OCR profile filenames + */ + public List getFiles() { + String ocrProfilesDirectory = ConfigCore.getParameter(ParameterCore.DIR_OCR_PROFILES); + try (Stream ocrProfilePaths = Files.walk(Paths.get(ocrProfilesDirectory), FileVisitOption.FOLLOW_LINKS)) { + return ocrProfilePaths.filter(Files::isRegularFile).map(Path::toAbsolutePath) + .map(path -> path.toString().replace(ocrProfilesDirectory, File.separator)).sorted() + .collect(Collectors.toList()); + } catch (IOException e) { + Helper.setErrorMessage(ERROR_LOADING_MANY, new Object[] {ObjectType.OCR_PROFILE.getTranslationPlural()}, + logger, e); + return new ArrayList<>(); + } + } + + /** + * Get OCR profile. + * + * @return value of OCR profile + */ + public OcrProfile getOcrProfile() { + return ocrProfile; + } + + /** + * Set OCR profile. + * + * @param ocrProfile as org.kitodo.data.database.beans.OcrProfile + */ + public void setOcrProfile(OcrProfile ocrProfile) { + this.ocrProfile = ocrProfile; + } + +} diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/OcrProfileListView.java b/Kitodo/src/main/java/org/kitodo/production/forms/OcrProfileListView.java new file mode 100644 index 00000000000..87485258c43 --- /dev/null +++ b/Kitodo/src/main/java/org/kitodo/production/forms/OcrProfileListView.java @@ -0,0 +1,70 @@ +/* + * (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.forms; + +import java.text.MessageFormat; +import java.util.ArrayList; +import java.util.List; + +import javax.enterprise.context.SessionScoped; +import javax.inject.Named; + +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; +import org.kitodo.data.database.beans.OcrProfile; +import org.kitodo.data.database.exceptions.DAOException; +import org.kitodo.production.enums.ObjectType; +import org.kitodo.production.helper.Helper; +import org.kitodo.production.services.ServiceManager; + +@Named("OcrProfileListView") +@SessionScoped +public class OcrProfileListView extends BaseForm { + + private static final Logger logger = LogManager.getLogger(OcrProfileListView.class); + private final String ocrProfileCreatePath = MessageFormat.format(REDIRECT_PATH, "ocrProfileEdit"); + + + /** + * Get OCR profile. + * + * @return list of OCR profiles. + */ + public List getOcrProfile() { + try { + return ServiceManager.getOcrProfileService().getAll(); + } catch (DAOException e) { + Helper.setErrorMessage(ERROR_LOADING_MANY, + new Object[] { ObjectType.OCR_PROFILE.getTranslationPlural() }, logger, e); + return new ArrayList<>(); + } + } + + + public String newOcrProfile() { + return ocrProfileCreatePath; + } + + /** + * Delete OCR profile identified by ID. + * + * @param id ID of OCR profile to delete + */ + public void deleteById(int id) { + try { + ServiceManager.getOcrProfileService().removeFromDatabase(id); + } catch (DAOException e) { + Helper.setErrorMessage(ERROR_DELETING, new Object[] {ObjectType.OCR_PROFILE.getTranslationSingular() }, logger, e); + } + } + +} 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..51a71c642ad 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/ProcessForm.java @@ -35,6 +35,7 @@ import org.kitodo.config.ConfigCore; import org.kitodo.config.enums.ParameterCore; import org.kitodo.data.database.beans.Docket; +import org.kitodo.data.database.beans.OcrProfile; import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.beans.Project; import org.kitodo.data.database.beans.Property; @@ -874,6 +875,15 @@ public List getProjects() { return ServiceManager.getProjectService().getAllForSelectedClient(); } + /** + * Get list of OCR profiles for select list. + * + * @return list of OCR profiles + */ + public List getOcrProfiles() { + return ServiceManager.getOcrProfileService().getAvailableOcrProfiles(); + } + /** * 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 2af30725d4d..9986a958a64 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/TemplateForm.java @@ -27,6 +27,7 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.kitodo.data.database.beans.Docket; +import org.kitodo.data.database.beans.OcrProfile; import org.kitodo.data.database.beans.Project; import org.kitodo.data.database.beans.Ruleset; import org.kitodo.data.database.beans.Task; @@ -274,6 +275,15 @@ public List getWorkflows() { return ServiceManager.getWorkflowService().getAvailableWorkflows(); } + /** + * Get list of OCR profiles for select list. + * + * @return list of OCR profiles + */ + public List getOcrProfiles() { + return ServiceManager.getOcrProfileService().getAvailableOcrProfiles(); + } + /** * Check if user is not assigned to the project. Used for disabling projects. * 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..edd0e22e6df 100644 --- a/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java +++ b/Kitodo/src/main/java/org/kitodo/production/helper/VariableReplacer.java @@ -70,7 +70,8 @@ private enum MetadataLevel { * be replaced. */ private static final Pattern VARIABLE_FINDER_REGEX = Pattern.compile( - "(\\$?)\\((?:(prefs|processid|processtitle|projectid|stepid|stepname|generatorsource|generatorsourcepath)|" + "(\\$?)\\((?:(prefs|processid|processtitle|projectid|projectdmsexportpath|" + + "stepid|stepname|generatorsource|generatorsourcepath|ocrprofilefile)|" + "(?:(meta|process|product|template)\\.(?:(firstchild|topstruct)\\.)?([^)]+)|" + "(?:(filename|basename|relativepath))))\\)"); @@ -237,6 +238,8 @@ private String determineReplacementForInternalValue(Matcher variableFinder) { return determineReplacementForProcesstitle(variableFinder); case "projectid": return determineReplacementForProjectid(variableFinder); + case "projectdmsexportpath": + return determineReplacementForProjectDmsExportPath(variableFinder); case "stepid": return determineReplacementForStepid(variableFinder); case "stepname": @@ -244,6 +247,8 @@ private String determineReplacementForInternalValue(Matcher variableFinder) { case "generatorsource" : case "generatorsourcepath": return determineReplacementForGeneratorSource(variableFinder, variableFinder.group(2)); + case "ocrprofilefile": + return determineReplacementForOcrProfileFile(variableFinder); default: logger.warn("Cannot replace \"{}\": no such case defined in switch", variableFinder.group()); return variableFinder.group(); @@ -281,6 +286,28 @@ private String determineReplacementForProcessid(Matcher variableFinder) { return variableFinder.group(1) + process.getId().toString(); } + private String determineReplacementForOcrProfileFile(Matcher variableFinder) { + if (Objects.isNull(process)) { + logger.warn("Cannot replace \"(ocrprofilefile)\": no process given"); + return variableFinder.group(1); + } + + if (Objects.nonNull(process.getOcrProfile())) { + return variableFinder.group(1) + process.getOcrProfile().getFile(); + } + + if (Objects.isNull(process.getTemplate())) { + logger.warn("Cannot replace \"(ocrprofilefile)\": process has no template assigned"); + return variableFinder.group(1); + } + + if (Objects.isNull(process.getTemplate().getOcrProfile())) { + logger.warn("Cannot replace \"(ocrprofilefile)\": template has no OCR profile assigned"); + return variableFinder.group(1); + } + return variableFinder.group(1) + process.getTemplate().getOcrProfile().getFile(); + } + private String determineReplacementForProcesstitle(Matcher variableFinder) { if (Objects.isNull(process)) { logger.warn("Cannot replace \"(processtitle)\": no process given"); @@ -301,6 +328,18 @@ private String determineReplacementForProjectid(Matcher variableFinder) { return variableFinder.group(1) + String.valueOf(process.getProject().getId()); } + private String determineReplacementForProjectDmsExportPath(Matcher variableFinder) { + if (Objects.isNull(process)) { + logger.warn("Cannot replace \"(projectdmsexportpath)\": no process given"); + return variableFinder.group(1); + } + if (Objects.isNull(process.getProject())) { + logger.warn("Cannot replace \"(projectdmsexportpath)\": process has no project assigned"); + return variableFinder.group(1); + } + return variableFinder.group(1) + process.getProject().getDmsImportRootPath(); + } + private String determineReplacementForStepid(Matcher variableFinder) { if (Objects.isNull(task)) { logger.warn("Cannot replace \"(stepid)\": no task given"); 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..079ce2be633 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.OcrProfileService; import org.kitodo.production.services.schema.SchemaService; import org.kitodo.production.services.security.SecurityAccessService; import org.kitodo.production.services.security.SessionService; @@ -89,6 +90,7 @@ public class ServiceManager { private static RoleService roleService; private static RulesetService rulesetService; private static RulesetManagementService rulesetManagementService; + private static OcrProfileService ocrProfileService; private static SchemaService schemaService; private static SearchFieldService searchFieldService; private static SecurityAccessService securityAccessService; @@ -213,6 +215,12 @@ private static void initializeRulesetService() { } } + private static void initializeOcrProfileService() { + if (Objects.isNull(ocrProfileService)) { + ocrProfileService = OcrProfileService.getInstance(); + } + } + private static void initializeSessionService() { if (Objects.isNull(sessionService)) { sessionService = SessionService.getInstance(); @@ -529,6 +537,18 @@ public static RulesetService getRulesetService() { return rulesetService; } + /** + * Initialize OcrProfileService if it is not yet initialized and next return + * it. + * + * @return OcrProfileService object + */ + public static OcrProfileService getOcrProfileService() { + initializeOcrProfileService(); + return ocrProfileService; + } + + /** * Initialize SessionService if it is not yet initialized and next return * it. diff --git a/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrProfileService.java b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrProfileService.java new file mode 100644 index 00000000000..89b17b01bb3 --- /dev/null +++ b/Kitodo/src/main/java/org/kitodo/production/services/ocr/OcrProfileService.java @@ -0,0 +1,81 @@ +/* + * (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 java.util.List; +import java.util.Map; +import java.util.Objects; + +import org.kitodo.data.database.beans.OcrProfile; +import org.kitodo.data.database.exceptions.DAOException; +import org.kitodo.data.database.persistence.OcrProfileDAO; +import org.kitodo.data.exceptions.DataException; +import org.kitodo.production.services.ServiceManager; +import org.kitodo.production.services.data.base.SearchDatabaseService; +import org.primefaces.model.SortOrder; + +public class OcrProfileService extends SearchDatabaseService { + + private static volatile OcrProfileService instance = null; + + /** + * Constructor necessary to use searcher in child classes. + */ + private OcrProfileService() { + super(new OcrProfileDAO()); + } + + /** + * Return singleton variable of type OcrProfileService. + * + * @return unique instance of OcrProfileService + */ + public static OcrProfileService getInstance() { + OcrProfileService localReference = instance; + if (Objects.isNull(localReference)) { + synchronized (OcrProfileService.class) { + localReference = instance; + if (Objects.isNull(localReference)) { + localReference = new OcrProfileService(); + instance = localReference; + } + } + } + return localReference; + } + + + @Override + public List loadData(int first, int pageSize, String sortField, SortOrder sortOrder, Map filters) throws DataException { + return null; + } + + @Override + public Long countDatabaseRows() throws DAOException { + return null; + } + + @Override + public Long countResults(Map filters) throws DAOException, DataException { + return null; + } + + /** + * Get available OCR profiles - available means that OCR profile is assigned to selected session client. + * + * @return list of available OcrProfile objects + */ + public List getAvailableOcrProfiles() { + return dao.getAvailableOcrProfiles(ServiceManager.getUserService().getSessionClientId()); + } + +} 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 09af57e37ce..776c7a0f968 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 @@ -1068,4 +1068,40 @@ public boolean hasAuthorityToDeleteMedia() { public boolean hasAuthorityToRunKitodoScripts() { return hasAnyAuthorityForClient("runKitodoScript"); } + + /** + * Checks if the current user has the authority to add the OCR profile. + * + * @return true if the current user has the authority to add the OCR profile + */ + public boolean hasAuthorityToAddOcrProfile() { + return hasAuthorityForClient("addOcrProfile"); + } + + /** + * Checks if the current user has the authority to edit the OCR profile. + * + * @return true if the current user has the authority to edit the OCR profile + */ + public boolean hasAuthorityToEditOcrProfile() { + return hasAuthorityForClient("editOcrProfile"); + } + + /** + * Checks if the current user has the authority to delete the OCR profile. + * + * @return true if the current user has the authority to delete the OCR profile + */ + public boolean hasAuthorityToDeleteOcrProfile() { + return hasAuthorityForClient("deleteOcrProfile"); + } + + /** + * Checks if the current user has the authority to view the OCR profile. + * + * @return true if the current user has the authority to view the OCR profile + */ + public boolean hasAuthorityToViewOcrProfile() { + return hasAuthorityForClient("viewOcrProfile"); + } } diff --git a/Kitodo/src/main/resources/hibernate.cfg.xml b/Kitodo/src/main/resources/hibernate.cfg.xml index 5b52c5ce814..9955ba20a74 100644 --- a/Kitodo/src/main/resources/hibernate.cfg.xml +++ b/Kitodo/src/main/resources/hibernate.cfg.xml @@ -78,6 +78,7 @@ + diff --git a/Kitodo/src/main/resources/kitodo_config.properties b/Kitodo/src/main/resources/kitodo_config.properties index 5afc19d397f..32b3a8fedff 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 profile files will be +# read from. It must be terminated by a directory separator ("/"). +directory.ocr.profiles=/usr/local/kitodo/ocr/profiles/ # ----------------------------------- # Directory management diff --git a/Kitodo/src/main/resources/messages/messages_de.properties b/Kitodo/src/main/resources/messages/messages_de.properties index 6279e82f39d..81bf1d06cda 100644 --- a/Kitodo/src/main/resources/messages/messages_de.properties +++ b/Kitodo/src/main/resources/messages/messages_de.properties @@ -252,6 +252,7 @@ createNewspaperProcessesTask=Anlegen von Zeitungsvorg\u00E4ngen createNewBatchFromSelectedProcesses=Neuen Batch aus den gew\u00E4hlten Vorg\u00E4ngen erzeugen createNewDocket=Neuen Laufzettel anlegen createNewLdapGroup=Neue LDAP-Gruppe anlegen +createNewOcrProfile=Neues OCR Profil anlegen createNewProcess=Einen neuen Vorgang anlegen createNewProcessFromTemplate=Einen neuen Vorgang auf Basis der Produktionsvorlage anlegen createNewRuleset=Neuen Regelsatz anlegen @@ -289,7 +290,6 @@ dataEditor.comment.markCorrectionCommentAsSolvedToCloseTask=Bitte kennzeichnen S dataEditor.comment.parallelTaskInWorkText=Sie k\u00F6nnen f\u00FCr diesen Vorgang derzeit keinen Korrekturkommentar verfassen, da sich mindestens eine Aufgabe ({0}) im Moment durch einen anderen Benutzer ({1}) in Bearbeitung befindet. dataEditor.comment.role.archivist=Archivar/in dataEditor.comment.role.creator=Sch\u00F6pfer/in -dataEditor.comment.role.custodian=Verwalter/in dataEditor.comment.role.disseminator=Verbreiter/in dataEditor.comment.role.editor=Bearbeiter/in dataEditor.comment.role.ipowner=Intellektuelleneigenschaftsbesitzer/in @@ -816,6 +816,7 @@ newProcess.titleGeneration.creationRuleNotFound=Es konnte keine Regel zur Titelg newProject=Neues Projekt newRole=Neue Rolle newRuleSet=Neuer Regelsatz +newOcrProfile=Neues OCR Profile newspaperMigrationTask=Migriere Zeitung newTemplate=Neue Produktionsvorlage newUser=Neuer Benutzer @@ -841,6 +842,7 @@ numberOfMetadata=Anzahl Metadaten nurDieMarkiertenSeiten=Nur die markierten Seiten objectType=Objekttyp ocr=OCR +ocrProfile=OCR Profil oderSperrungAufheben=Oder heben Sie die Sperrung hier auf. ok=Ok oldPassword=Altes Passwort @@ -892,6 +894,7 @@ position=Position ppn=PPN priority=Priorit\u00E4t process=Vorgang +processConfig.useProcessTemplateOcrProfile=Produktionsvorlage spezifisch processData=Vorgangsdaten processDetails=Vorgangsdetails processList=Vorgangsliste @@ -1202,6 +1205,7 @@ addImportConfiguration=Importkonfiguration hinzufügen addLdapGroup=LDAP-Gruppe hinzuf\u00FCgen addLdapServer=LDAP-Server hinzuf\u00FCgen addMappingFile=Abbildungsdatei hinzufügen +addOcrProfile=OCR Profil hinzuf\u00FCgen addProcess=Vorgang hinzuf\u00FCgen addProject=Projekt hinzuf\u00FCgen addProjects=Projekte hinzuf\u00FCgen @@ -1228,6 +1232,7 @@ deleteImportConfiguration=Importkonfiguration löschen deleteLdapGroup=LDAP-Gruppe l\u00F6schen deleteLdapServer=LDAP-Server l\u00F6schen deleteMappingFile=Abbildungsdatei löschen +deleteOcrProfile=OCR Profil l\u00F6schen deleteProcess=Vorgang l\u00F6schen deleteProject=Projekt l\u00F6schen deleteProperty=Eigenschaft l\u00F6schen @@ -1251,6 +1256,7 @@ editImportConfiguration=Importkonfiguration bearbeiten editLdapGroup=LDAP-Gruppe bearbeiten editLdapServer=LDAP-Server bearbeiten editMappingFile=Abbildungsdatei bearbeiten +editOcrProfile=OCR Profil bearbeiten editProcess=Vorgang bearbeiten editProcessMetaData=Metadaten des Vorgangs bearbeiten editProcessStructureData=Strukturdaten des Vorgangs bearbeiten @@ -1299,6 +1305,7 @@ viewLdapGroup=LDAP-Gruppe anzeigen viewLdapServer=LDAP-Server anzeigen viewMappingFile=Abbildungsdatei anzeigen viewMigration=Migrationsseite anzeigen +viewOcrProfile=OCR Profil anzeigen viewProcess=Vorgang anzeigen viewProcessMetaData=Metadaten des Vorgangs anzeigen viewProcessStructureData=Strukturdaten des Vorgangs anzeigen diff --git a/Kitodo/src/main/resources/messages/messages_en.properties b/Kitodo/src/main/resources/messages/messages_en.properties index 40ca9181f3e..040d0d36c68 100644 --- a/Kitodo/src/main/resources/messages/messages_en.properties +++ b/Kitodo/src/main/resources/messages/messages_en.properties @@ -23,6 +23,9 @@ ACTIVE=Active activeUsers=Current users addElement=Add element addLogicalDivision=Add logical structure element +addLdapGroup=Add LDAP group +addLdapServer=Add LDAP server +addOcrProfile=Add OCR profile addPhysicalDivision=Add physical structure element addMessage=Add message addMessageForAll=Add message for all processes @@ -213,6 +216,7 @@ confirmDeleteMappingFile=Delete mapping file "{0}"? confirmDeleteProcess=Delete process "{0}"? confirmDeleteProject=Delete project "{0}"? confirmDeleteRuleset=Delete ruleset "{0}"? +confirmDeleteOcrProfile=Delete OCR profile "{0}"? confirmDeleteTemplate=Delete template "{0}"? confirmDeleteUser=Delete user "{0}"? confirmDeleteUserWithTasks=If you delete this user "{0}", all tasks assigned to him will be reset to 'Open'. Do you want to continue?" @@ -252,6 +256,7 @@ createNewspaperProcessesTask=Creation of processes for a newspaper createNewBatchFromSelectedProcesses=create new batch of the selected processes createNewDocket=Create new docket createNewLdapGroup=Create new LDAP group +createNewOcrProfile=Create OCR profile createNewProcess=Create new process createNewProcessFromTemplate=Create process from template createNewRuleset=Create new rule set @@ -816,6 +821,7 @@ newProcess.titleGeneration.creationRuleNotFound=No title creation rules found fo newProject=New project newRole=New role newRuleSet=New rule set +newOcrProfile=New OCR profile newspaperMigrationTask=Migrating newspaper newTemplate=New process template newWorkflow=New workflow @@ -841,6 +847,7 @@ numberOfMetadata=Number of metadata nurDieMarkiertenSeiten=Only the selected pages objectType=Object type ocr=OCR +ocrProfile=OCR profile oderSperrungAufheben=Or unlock here. ok=Ok oldPassword=Old password @@ -892,6 +899,7 @@ position=Position ppn=PPN priority=Priority process=Process +processConfig.useProcessTemplateOcrProfile=Process template specific processData=Process data processDetails=Process details processList=Process list @@ -1228,6 +1236,7 @@ deleteImportConfiguration=Delete import configuration deleteLdapGroup=Delete LDAP group deleteLdapServer=Delete LDAP server deleteMappingFile=Delete mapping file +deleteOcrProfile=Delete OCR profile deleteProcess=Delete process deleteProject=Delete project deleteProperty=Delete property @@ -1251,6 +1260,7 @@ editImportConfiguration=Edit import configuration editLdapGroup=Edit LDAP group editLdapServer=Edit LDAP-server editMappingFile=Edit mapping file +editOcrProfile=Edit OCR profile editProcess=Edit process editProcessMetaData=Edit metadata of the process editProcessStructureData=Edit structure data of the process @@ -1299,6 +1309,7 @@ viewLdapGroup=View LDAP group viewLdapServer=View LDAP server viewMappingFile=View mapping file viewMigration=View migration page +viewOcrProfile=View OCR profile viewProcess=View process viewProcessMetaData=View metadata of the process viewProcessStructureData=View structure data of the process 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..c99d4c1fcd5 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 @@ -14,6 +14,7 @@ @@ -46,6 +47,12 @@ + +
+ + +
@@ -80,6 +87,21 @@ + +
+ + + + + + +
diff --git a/Kitodo/src/main/webapp/WEB-INF/templates/includes/projects/ocrProfileList.xhtml b/Kitodo/src/main/webapp/WEB-INF/templates/includes/projects/ocrProfileList.xhtml new file mode 100644 index 00000000000..cbca9d04d98 --- /dev/null +++ b/Kitodo/src/main/webapp/WEB-INF/templates/includes/projects/ocrProfileList.xhtml @@ -0,0 +1,84 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 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..08e24442b56 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,20 @@ +
+ + + + + +
+
diff --git a/Kitodo/src/main/webapp/pages/ocrProfileEdit.xhtml b/Kitodo/src/main/webapp/pages/ocrProfileEdit.xhtml new file mode 100644 index 00000000000..9c0a01330da --- /dev/null +++ b/Kitodo/src/main/webapp/pages/ocrProfileEdit.xhtml @@ -0,0 +1,95 @@ + + + + + + + + + + + + + + + + + +

+ + + +

+ +
+ + + + + + +
+ + +
+
+ + + + + + +
+
+
+
+
+
+ +
diff --git a/Kitodo/src/main/webapp/pages/projects.xhtml b/Kitodo/src/main/webapp/pages/projects.xhtml index 9583164cd8c..73107873d1d 100644 --- a/Kitodo/src/main/webapp/pages/projects.xhtml +++ b/Kitodo/src/main/webapp/pages/projects.xhtml @@ -79,6 +79,9 @@ + @@ -117,6 +120,10 @@ rendered="#{SecurityAccessController.hasAuthorityToViewMappingFileList()}"> + + + diff --git a/Kitodo/src/test/resources/hibernate.cfg.xml b/Kitodo/src/test/resources/hibernate.cfg.xml index b972d7b1769..93fc262c385 100644 --- a/Kitodo/src/test/resources/hibernate.cfg.xml +++ b/Kitodo/src/test/resources/hibernate.cfg.xml @@ -67,6 +67,7 @@ + diff --git a/Kitodo/src/test/resources/selenium/resources/hibernate.cfg.xml b/Kitodo/src/test/resources/selenium/resources/hibernate.cfg.xml index 5e2af87d38a..fbae52f652b 100644 --- a/Kitodo/src/test/resources/selenium/resources/hibernate.cfg.xml +++ b/Kitodo/src/test/resources/selenium/resources/hibernate.cfg.xml @@ -70,6 +70,7 @@ +