From d2130d261beffb8c1c82a26fbc6cadaf8ee52e3c Mon Sep 17 00:00:00 2001 From: Matthias Ronge Date: Wed, 28 Aug 2024 16:15:37 +0200 Subject: [PATCH] Remove database column 'indexAction' --- .../data/database/beans/BaseIndexedBean.java | 29 --- .../data/database/enums/IndexAction.java | 22 -- .../data/database/persistence/BaseDAO.java | 2 - .../V2_130__Delete_columns_indexAction.sql | 23 +++ .../database/persistence/DocketDaoIT.java | 3 - .../database/persistence/FilterDaoIT.java | 3 - .../database/persistence/PropertyDaoIT.java | 3 - .../database/persistence/RulesetDaoIT.java | 3 - .../services/data/ProcessService.java | 189 ------------------ .../services/data/base/SearchService.java | 5 - .../production/forms/IndexingFormIT.java | 6 - 11 files changed, 23 insertions(+), 265 deletions(-) delete mode 100644 Kitodo-DataManagement/src/main/java/org/kitodo/data/database/enums/IndexAction.java create mode 100644 Kitodo-DataManagement/src/main/resources/db/migration/V2_130__Delete_columns_indexAction.sql diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/BaseIndexedBean.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/BaseIndexedBean.java index 5cc533852c7..617a1305e82 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/BaseIndexedBean.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/beans/BaseIndexedBean.java @@ -11,40 +11,11 @@ package org.kitodo.data.database.beans; -import javax.persistence.Column; -import javax.persistence.EnumType; -import javax.persistence.Enumerated; import javax.persistence.MappedSuperclass; -import org.kitodo.data.database.enums.IndexAction; - /** * Base bean class. */ @MappedSuperclass public abstract class BaseIndexedBean extends BaseBean { - - @Column(name = "indexAction") - @Enumerated(EnumType.STRING) - private IndexAction indexAction; - - /** - * Get action which should be performed on ElasticSearch index. - * - * @return action which needs to be performed on index - */ - public IndexAction getIndexAction() { - return indexAction; - } - - /** - * Set DONE if record is already indexed in ElasticSearch, set INDEX if it - * needs to be indexed and DELETE if it needs to be deleted. - * - * @param indexAction - * index, delete or done - */ - public void setIndexAction(IndexAction indexAction) { - this.indexAction = indexAction; - } } diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/enums/IndexAction.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/enums/IndexAction.java deleted file mode 100644 index 83200323260..00000000000 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/enums/IndexAction.java +++ /dev/null @@ -1,22 +0,0 @@ -/* - * (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.enums; - -/** - * Enum for determining current state of ElasticSearch index. According to it - * necessary operation must be performed on ElasticSearch index. - */ -public enum IndexAction { - INDEX, - DELETE, - DONE -} diff --git a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/persistence/BaseDAO.java b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/persistence/BaseDAO.java index 92ca8403e4d..7256deb7692 100644 --- a/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/persistence/BaseDAO.java +++ b/Kitodo-DataManagement/src/main/java/org/kitodo/data/database/persistence/BaseDAO.java @@ -33,7 +33,6 @@ import org.kitodo.config.ConfigMain; import org.kitodo.data.database.beans.BaseBean; import org.kitodo.data.database.beans.BaseIndexedBean; -import org.kitodo.data.database.enums.IndexAction; import org.kitodo.data.database.exceptions.DAOException; /** @@ -390,7 +389,6 @@ void storeObject(T object) throws DAOException { void storeAsIndexed(List baseBeans) throws DAOException { for (BaseBean baseBean : baseBeans) { BaseIndexedBean entity = (BaseIndexedBean) getById(baseBean.getId()); - entity.setIndexAction(IndexAction.DONE); storeObject((T) entity); } } diff --git a/Kitodo-DataManagement/src/main/resources/db/migration/V2_130__Delete_columns_indexAction.sql b/Kitodo-DataManagement/src/main/resources/db/migration/V2_130__Delete_columns_indexAction.sql new file mode 100644 index 00000000000..8dfaae5ca96 --- /dev/null +++ b/Kitodo-DataManagement/src/main/resources/db/migration/V2_130__Delete_columns_indexAction.sql @@ -0,0 +1,23 @@ +-- +-- (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. +-- + +-- +-- Delete columns for index action + +ALTER TABLE batch DROP COLUMN indexAction; +ALTER TABLE docket DROP COLUMN indexAction; +ALTER TABLE filter DROP COLUMN indexAction; +ALTER TABLE process DROP COLUMN indexAction; +ALTER TABLE project DROP COLUMN indexAction; +ALTER TABLE ruleset DROP COLUMN indexAction; +ALTER TABLE task DROP COLUMN indexAction; +ALTER TABLE template DROP COLUMN indexAction; +ALTER TABLE workflow DROP COLUMN indexAction; diff --git a/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/DocketDaoIT.java b/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/DocketDaoIT.java index 1230a9cfae4..3117864ef01 100644 --- a/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/DocketDaoIT.java +++ b/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/DocketDaoIT.java @@ -20,7 +20,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.kitodo.data.database.beans.Docket; -import org.kitodo.data.database.enums.IndexAction; import org.kitodo.data.database.exceptions.DAOException; public class DocketDaoIT { @@ -53,11 +52,9 @@ public void runPersistenceSuitTest() throws DAOException { private List getAuthorities() { Docket firstDocket = new Docket(); firstDocket.setTitle("first_docket"); - firstDocket.setIndexAction(IndexAction.DONE); Docket secondDocket = new Docket(); secondDocket.setTitle("second_docket"); - secondDocket.setIndexAction(IndexAction.INDEX); Docket thirdDocket = new Docket(); thirdDocket.setTitle("third_docket"); diff --git a/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/FilterDaoIT.java b/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/FilterDaoIT.java index dc1c81a4b40..5f1e7ce0a75 100644 --- a/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/FilterDaoIT.java +++ b/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/FilterDaoIT.java @@ -20,7 +20,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.kitodo.data.database.beans.Filter; -import org.kitodo.data.database.enums.IndexAction; import org.kitodo.data.database.exceptions.DAOException; public class FilterDaoIT { @@ -53,11 +52,9 @@ public void runPersistenceSuitTest() throws DAOException { private List getAuthorities() { Filter firstFilter = new Filter(); firstFilter.setValue("first_filter"); - firstFilter.setIndexAction(IndexAction.DONE); Filter secondFilter = new Filter(); secondFilter.setValue("second_filter"); - secondFilter.setIndexAction(IndexAction.INDEX); Filter thirdFilter = new Filter(); thirdFilter.setValue("third_filter"); diff --git a/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/PropertyDaoIT.java b/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/PropertyDaoIT.java index 13c2a687b8e..f13a34b1f2f 100644 --- a/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/PropertyDaoIT.java +++ b/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/PropertyDaoIT.java @@ -20,7 +20,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.kitodo.data.database.beans.Property; -import org.kitodo.data.database.enums.IndexAction; import org.kitodo.data.database.enums.PropertyType; import org.kitodo.data.database.exceptions.DAOException; @@ -58,11 +57,9 @@ private List getProperties() { Property firstProperty = new Property(); firstProperty.setTitle("first_property"); firstProperty.setDataType(null); - firstProperty.setIndexAction(IndexAction.DONE); Property secondProperty = new Property(); secondProperty.setTitle("second_property"); - secondProperty.setIndexAction(IndexAction.INDEX); Property thirdProperty = new Property(); thirdProperty.setTitle("third_property"); diff --git a/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/RulesetDaoIT.java b/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/RulesetDaoIT.java index 4c47e1ab106..23d47a1a277 100644 --- a/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/RulesetDaoIT.java +++ b/Kitodo-DataManagement/src/test/java/org/kitodo/data/database/persistence/RulesetDaoIT.java @@ -20,7 +20,6 @@ import org.junit.Test; import org.junit.rules.ExpectedException; import org.kitodo.data.database.beans.Ruleset; -import org.kitodo.data.database.enums.IndexAction; import org.kitodo.data.database.exceptions.DAOException; public class RulesetDaoIT { @@ -53,11 +52,9 @@ public void runPersistenceSuitTest() throws DAOException { private List getAuthorities() { Ruleset firstRuleset = new Ruleset(); firstRuleset.setTitle("first_ruleset"); - firstRuleset.setIndexAction(IndexAction.DONE); Ruleset secondRuleset = new Ruleset(); secondRuleset.setTitle("second_ruleset"); - secondRuleset.setIndexAction(IndexAction.INDEX); Ruleset thirdRuleset = new Ruleset(); thirdRuleset.setTitle("third_ruleset"); diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java index c170fb3af44..112994144a5 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ProcessService.java @@ -108,7 +108,6 @@ import org.kitodo.data.database.beans.User; import org.kitodo.data.database.enums.CommentType; import org.kitodo.data.database.enums.CorrectionComments; -import org.kitodo.data.database.enums.IndexAction; import org.kitodo.data.database.enums.TaskStatus; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.data.database.persistence.BaseDAO; @@ -121,14 +120,12 @@ import org.kitodo.data.interfaces.TaskInterface; import org.kitodo.exceptions.InvalidImagesException; import org.kitodo.export.ExportMets; -import org.kitodo.production.dto.DTOFactory; import org.kitodo.production.helper.Helper; import org.kitodo.production.helper.SearchResultGeneration; import org.kitodo.production.helper.WebDav; import org.kitodo.production.helper.metadata.ImageHelper; import org.kitodo.production.helper.metadata.MetadataHelper; import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyDocStructHelperInterface; -import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyMetadataHelper; import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyMetadataTypeHelper; import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyMetsModsDigitalDocumentHelper; import org.kitodo.production.helper.metadata.legacytypeimplementations.LegacyPrefsHelper; @@ -408,73 +405,6 @@ public List loadData(int first, int pageSize, String sortField, SortOrd return getByQuery(query.formQueryForAll(), query.getQueryParameters(), first, pageSize); } - /** - * Check if IndexAction flag is delete. If true remove process from list of - * processes and re-save batch, if false only re-save batch object. - * - * @param process - * object - */ - private void manageBatchesDependenciesForIndex(Process process) - throws CustomResponseException, DataException, IOException { - if (process.getIndexAction() == IndexAction.DELETE) { - for (Batch batch : process.getBatches()) { - batch.getProcesses().remove(process); - ServiceManager.getBatchService().saveToIndex(batch, false); - } - } else { - for (Batch batch : process.getBatches()) { - ServiceManager.getBatchService().saveToIndex(batch, false); - } - } - } - - /** - * Add process to project, if project is assigned to process. - * - * @param process - * object - */ - private void manageProjectDependenciesForIndex(Process process) - throws CustomResponseException, DataException, IOException { - if (Objects.nonNull(process.getProject())) { - ServiceManager.getProjectService().saveToIndex(process.getProject(), false); - } - } - - /** - * Check IndexAction flag in for process object. If DELETE remove all tasks - * from index, if other call saveOrRemoveTaskInIndex() method. - * - * @param process - * object - */ - private void manageTaskDependenciesForIndex(Process process) - throws CustomResponseException, DAOException, IOException, DataException { - if (process.getIndexAction() == IndexAction.DELETE) { - for (Task task : process.getTasks()) { - ServiceManager.getTaskService().removeFromIndex(task, false); - } - } - } - - - - /** - * Compare two list and return difference between them. - * - * @param firstList - * list from which records can be remove - * @param secondList - * records stored here will be removed from firstList - * @return difference between two lists - */ - private List findMissingValues(List firstList, List secondList) { - List newList = new ArrayList<>(firstList); - newList.removeAll(secondList); - return newList; - } - @Override public void saveList(List list) throws DAOException { dao.saveList(list); @@ -1228,32 +1158,6 @@ public String getBaseType(int processId) throws DataException { } } - /** - * Filter for correction / solution messages. - * - * @param lpe - * List of process properties - * @return List of filtered correction / solution messages - */ - private List filterForCorrectionSolutionMessages(List lpe) { - List filteredList = new ArrayList<>(); - - if (lpe.isEmpty()) { - return filteredList; - } - - List translationList = Arrays.asList("Correction required", "Correction performed", - "Korrektur notwendig", "Korrektur durchgef\u00FChrt"); - - // filtering for correction and solution messages - for (PropertyInterface property : lpe) { - if (translationList.contains(property.getTitle())) { - filteredList.add(property); - } - } - return filteredList; - } - /** * Sanitizes a possibly dirty reference URI and extracts from it the * operation ID of the referenced process. In case of error, a speaking @@ -1318,70 +1222,6 @@ public boolean handleExceptionsForConfiguration(LegacyMetsModsDigitalDocumentHel return false; } - /** - * Run through all metadata and children of given docStruct to trim the strings - * calls itself recursively. - * - * @param docStruct - * metadata to be trimmed - */ - private void trimAllMetadata(LegacyDocStructHelperInterface docStruct) { - // trim all metadata values - for (LegacyMetadataHelper md : docStruct.getAllMetadata()) { - if (Objects.nonNull(md.getValue())) { - md.setStringValue(md.getValue().trim()); - } - } - - // run through all children of docStruct - for (LegacyDocStructHelperInterface child : docStruct.getAllChildren()) { - trimAllMetadata(child); - } - } - - /** - * Download full text. - * - * @param userHome - * safe file - * @param atsPpnBand - * String - */ - private void downloadFullText(Process process, URI userHome, String atsPpnBand) throws IOException { - downloadSources(process, userHome, atsPpnBand); - downloadOCR(process, userHome, atsPpnBand); - } - - private void downloadSources(Process process, URI userHome, String atsPpnBand) throws IOException { - URI source = fileService.getSourceDirectory(process); - if (fileService.fileExist(source) && !fileService.getSubUris(source).isEmpty()) { - URI destination = userHome.resolve(File.separator + atsPpnBand + "_src"); - if (!fileService.fileExist(destination)) { - fileService.createDirectory(userHome, atsPpnBand + "_src"); - } - copyProcessFiles(source, destination, null); - } - } - - private void downloadOCR(Process process, URI userHome, String atsPpnBand) throws IOException { - URI ocr = fileService.getOcrDirectory(process); - if (fileService.fileExist(ocr)) { - List directories = fileService.getSubUris(ocr); - for (URI directory : directories) { - if (fileService.isDirectory(directory) && !fileService.getSubUris(directory).isEmpty() - && fileService.getFileName(directory).contains("_")) { - String suffix = fileService.getFileNameWithExtension(directory) - .substring(fileService.getFileNameWithExtension(directory).lastIndexOf('_')); - URI destination = userHome.resolve(File.separator + atsPpnBand + suffix); - if (!fileService.fileExist(destination)) { - fileService.createDirectory(userHome, atsPpnBand + suffix); - } - copyProcessFiles(directory, destination, null); - } - } - } - } - /** * Download images. * @@ -1492,31 +1332,6 @@ public List getDataFiles(Process process) throws InvalidImagesException { return dataList; } - /** - * Starts copying all directories configured in kitodo_config.properties - * parameter "processDirs" to export folder. - * - * @param myProcess - * the process object - * @param targetDirectory - * the destination directory - */ - private void directoryDownload(Process myProcess, URI targetDirectory) throws IOException { - String[] processDirs = ConfigCore.getStringArrayParameter(ParameterCore.PROCESS_DIRS); - String normalizedTitle = Helper.getNormalizedTitle(myProcess.getTitle()); - - for (String processDir : processDirs) { - URI sourceDirectory = URI.create(getProcessDataDirectory(myProcess).toString() + "/" - + processDir.replace(PROCESS_TITLE, normalizedTitle)); - URI destinationDirectory = URI - .create(targetDirectory.toString() + "/" + processDir.replace(PROCESS_TITLE, normalizedTitle)); - - if (fileService.isDirectory(sourceDirectory)) { - fileService.copyFile(sourceDirectory, destinationDirectory); - } - } - } - /** * Creates a List of Docket data for the given processes. * @@ -1591,10 +1406,6 @@ private static List getDocketDataForComments(List comments) { return commentsForDocket; } - private List> getMetadataForIndex(Process process) { - return getMetadataForIndex(process, false); - } - @SuppressWarnings("unchecked") private List> getMetadataForIndex(Process process, boolean forIndexingAll) { try { diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/base/SearchService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/base/SearchService.java index 72f68c70383..9a3b686b407 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/base/SearchService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/base/SearchService.java @@ -20,7 +20,6 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.kitodo.data.database.beans.BaseIndexedBean; -import org.kitodo.data.database.enums.IndexAction; import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.data.database.persistence.BaseDAO; import org.kitodo.data.elasticsearch.exceptions.CustomResponseException; @@ -140,7 +139,6 @@ public void save(T object) throws DataException { @Override public void save(T baseIndexedBean, boolean updateRelatedObjectsInIndex) throws DataException { try { - baseIndexedBean.setIndexAction(IndexAction.INDEX); saveToDatabase(baseIndexedBean); // TODO: find out why properties lists are save double T savedBean = getById(baseIndexedBean.getId()); @@ -148,7 +146,6 @@ public void save(T baseIndexedBean, boolean updateRelatedObjectsInIndex) throws if (updateRelatedObjectsInIndex) { manageDependenciesForIndex(savedBean); } - savedBean.setIndexAction(IndexAction.DONE); saveToDatabase(savedBean); } catch (DAOException e) { logger.debug(e); @@ -160,7 +157,6 @@ public void save(T baseIndexedBean, boolean updateRelatedObjectsInIndex) throws try { saveToIndex(baseIndexedBean, true); manageDependenciesForIndex(baseIndexedBean); - baseIndexedBean.setIndexAction(IndexAction.DONE); saveToDatabase(baseIndexedBean); break; } catch (CustomResponseException | IOException ee) { @@ -202,7 +198,6 @@ public void remove(Integer id) throws DataException { @Override public void remove(T baseIndexedBean) throws DataException { try { - baseIndexedBean.setIndexAction(IndexAction.DELETE); saveToDatabase(baseIndexedBean); T savedBean = getById(baseIndexedBean.getId()); removeFromIndex(savedBean, true); diff --git a/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java b/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java index 5dc0dc95cdb..b07af3ac131 100644 --- a/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/forms/IndexingFormIT.java @@ -27,7 +27,6 @@ import org.kitodo.data.database.beans.Process; import org.kitodo.data.database.beans.Project; import org.kitodo.data.database.beans.User; -import org.kitodo.data.database.enums.IndexAction; import org.kitodo.data.interfaces.ProcessInterface; import org.kitodo.production.services.ServiceManager; @@ -73,21 +72,16 @@ public void indexingAll() throws Exception { Process process = new Process(); process.setTitle("testIndex"); process.setProject(project); - process.setIndexAction(IndexAction.INDEX); ServiceManager.getProcessService().saveToDatabase(process); indexingForm.countDatabaseObjects(); ProcessInterface processOne = ServiceManager.getProcessService().findById(1); Assert.assertNull("process should not be found in index", processOne.getTitle()); - IndexAction indexAction = ServiceManager.getProcessService().getById(1).getIndexAction(); - Assert.assertEquals("Index Action should be Index", IndexAction.INDEX, indexAction); indexingForm.startAllIndexing(); given().ignoreExceptions().await() .until(() -> Objects.nonNull(ServiceManager.getProcessService().findById(1).getTitle())); processOne = ServiceManager.getProcessService().findById(1); Assert.assertEquals("process should be found", "testIndex",processOne.getTitle()); - indexAction = ServiceManager.getProcessService().getById(1).getIndexAction(); - Assert.assertEquals("Index Action should be Index", IndexAction.INDEX, indexAction); } }