From 30d44d2a0d0ec2cffda7b2e43243e4f3afda3b2a Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Tue, 13 Dec 2022 15:32:42 +0100 Subject: [PATCH 1/3] Fix 'skiplist' method for FTP interfaces --- .../createprocess/CatalogImportDialog.java | 7 +------ .../services/data/ImportService.java | 19 +++++++++++++++++++ .../test/java/org/kitodo/MockDatabase.java | 12 ++++++++++++ .../catalogimport/CatalogImportIT.java | 11 +++++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CatalogImportDialog.java b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CatalogImportDialog.java index 30401786d0c..7db17e6ece6 100644 --- a/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CatalogImportDialog.java +++ b/Kitodo/src/main/java/org/kitodo/production/forms/createprocess/CatalogImportDialog.java @@ -129,12 +129,7 @@ public void search() { } private boolean skipHitList(ImportConfiguration importConfiguration, String searchField) { - if (SearchInterfaceType.OAI.name().equals(importConfiguration.getInterfaceType()) - || searchField.equals(importConfiguration.getIdSearchField().getLabel())) { - return true; - } - return (Objects.isNull(importConfiguration.getMetadataRecordIdXPath()) - || Objects.isNull(importConfiguration.getMetadataRecordTitleXPath())); + return ImportService.skipHitlist(importConfiguration, searchField); } /** diff --git a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java index 011d1501cc4..4850b892073 100644 --- a/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java +++ b/Kitodo/src/main/java/org/kitodo/production/services/data/ImportService.java @@ -246,6 +246,25 @@ public static String getDefaultSearchField(ImportConfiguration importConfigurati return ""; } + /** + * Check and return whether to skip hit list for given ImportConfiguration and search field or not. + * Hit list is skipped either if SearchInterfaceType of given ImportConfiguration does not support + * hit lists (e.g. OAI and FTP interfaces) or if the provides search field equals the ID search field + * of the given ImportConfiguration. + * @param configuration ImportConfiguration to check + * @param field value of SearchField to check + * @return whether to skip hit list or not + */ + public static boolean skipHitlist(ImportConfiguration configuration, String field) { + if (SearchInterfaceType.OAI.name().equals(configuration.getInterfaceType()) + || SearchInterfaceType.FTP.name().equals(configuration.getInterfaceType()) + || field.equals(configuration.getIdSearchField().getLabel())) { + return true; + } + return (Objects.isNull(configuration.getMetadataRecordIdXPath()) + || Objects.isNull(configuration.getMetadataRecordTitleXPath())); + } + /** * Get default import depth for given import configuration. * diff --git a/Kitodo/src/test/java/org/kitodo/MockDatabase.java b/Kitodo/src/test/java/org/kitodo/MockDatabase.java index de529f87732..47dff64b8e3 100644 --- a/Kitodo/src/test/java/org/kitodo/MockDatabase.java +++ b/Kitodo/src/test/java/org/kitodo/MockDatabase.java @@ -1533,6 +1533,18 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti } } + /** + * Create an ImportConfiguration with configuration type `OPAC_SEARCH` and search interface type 'FTP'. + * @throws DAOException when saving ImportConfiguration to database fails + */ + public static void insertFtpImportConfiguration() throws DAOException { + ImportConfiguration genericFtpConfiguration = new ImportConfiguration(); + genericFtpConfiguration.setTitle("FTP example configuration"); + genericFtpConfiguration.setConfigurationType(ImportConfigurationType.OPAC_SEARCH.name()); + genericFtpConfiguration.setInterfaceType(SearchInterfaceType.FTP.name()); + ServiceManager.getImportConfigurationService().saveToDatabase(genericFtpConfiguration); + } + /** * Create an ImportConfiguration with configuration type `OPAC_SEARCH` and search interface type `CUSTOM` and * add custom URL parameters. diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java index ece806917dd..334b7e89789 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java @@ -35,8 +35,11 @@ import org.junit.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; +import org.kitodo.data.database.beans.ImportConfiguration; +import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.production.helper.TempProcess; import org.kitodo.production.services.ServiceManager; +import org.kitodo.production.services.data.ImportService; public class CatalogImportIT { @@ -77,6 +80,14 @@ public void shouldImportProcessHierarchy() throws Exception { Assert.assertEquals(IMPORT_DEPTH, processes.size()); } + @Test + public void shouldSkipHitlistForFtpImportConfiguration() throws DAOException { + MockDatabase.insertFtpImportConfiguration(); + ImportConfiguration ftpConfiguration = ServiceManager.getImportConfigurationService().getById(4); + Assert.assertTrue("'Skip hitlist' should return 'true' for FTP configurations", + ImportService.skipHitlist(ftpConfiguration, null)); + } + private static void setupServer() throws IOException { server = new StubServer(PORT).run(); addRestEndPointForImport("ead.id=" + CHILD_RECORD_ID, CHILD_RECORD_PATH, 1); From 35c974b3d1569299cfb87d9a4dfb1632ada00806 Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Wed, 14 Dec 2022 09:39:21 +0100 Subject: [PATCH 2/3] Replace integration test with unit test --- .../test/java/org/kitodo/MockDatabase.java | 12 ------ .../catalogimport/CatalogImportIT.java | 8 ---- .../catalogimport/ImportServiceTest.java | 43 +++++++++++++++++++ 3 files changed, 43 insertions(+), 20 deletions(-) create mode 100644 Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java diff --git a/Kitodo/src/test/java/org/kitodo/MockDatabase.java b/Kitodo/src/test/java/org/kitodo/MockDatabase.java index 47dff64b8e3..de529f87732 100644 --- a/Kitodo/src/test/java/org/kitodo/MockDatabase.java +++ b/Kitodo/src/test/java/org/kitodo/MockDatabase.java @@ -1533,18 +1533,6 @@ public static void insertImportConfigurations() throws DAOException, DataExcepti } } - /** - * Create an ImportConfiguration with configuration type `OPAC_SEARCH` and search interface type 'FTP'. - * @throws DAOException when saving ImportConfiguration to database fails - */ - public static void insertFtpImportConfiguration() throws DAOException { - ImportConfiguration genericFtpConfiguration = new ImportConfiguration(); - genericFtpConfiguration.setTitle("FTP example configuration"); - genericFtpConfiguration.setConfigurationType(ImportConfigurationType.OPAC_SEARCH.name()); - genericFtpConfiguration.setInterfaceType(SearchInterfaceType.FTP.name()); - ServiceManager.getImportConfigurationService().saveToDatabase(genericFtpConfiguration); - } - /** * Create an ImportConfiguration with configuration type `OPAC_SEARCH` and search interface type `CUSTOM` and * add custom URL parameters. diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java index 334b7e89789..cde67e5eb6f 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java @@ -80,14 +80,6 @@ public void shouldImportProcessHierarchy() throws Exception { Assert.assertEquals(IMPORT_DEPTH, processes.size()); } - @Test - public void shouldSkipHitlistForFtpImportConfiguration() throws DAOException { - MockDatabase.insertFtpImportConfiguration(); - ImportConfiguration ftpConfiguration = ServiceManager.getImportConfigurationService().getById(4); - Assert.assertTrue("'Skip hitlist' should return 'true' for FTP configurations", - ImportService.skipHitlist(ftpConfiguration, null)); - } - private static void setupServer() throws IOException { server = new StubServer(PORT).run(); addRestEndPointForImport("ead.id=" + CHILD_RECORD_ID, CHILD_RECORD_PATH, 1); diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java new file mode 100644 index 00000000000..98fdbe23121 --- /dev/null +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/ImportServiceTest.java @@ -0,0 +1,43 @@ +/* + * (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.catalogimport; + +import org.junit.Assert; +import org.junit.Test; +import org.kitodo.api.externaldatamanagement.ImportConfigurationType; +import org.kitodo.api.externaldatamanagement.SearchInterfaceType; +import org.kitodo.data.database.beans.ImportConfiguration; +import org.kitodo.production.services.data.ImportService; + +public class ImportServiceTest { + + /** + * Test whether hit list is properly skipped for FTP type import configurations. + */ + @Test + public void shouldSkipHitListForFtpImportConfiguration() { + ImportConfiguration ftpConfiguration = createFtpImportConfiguration(); + Assert.assertTrue("'Skip hit list' should return 'true' for FTP configurations", + ImportService.skipHitlist(ftpConfiguration, null)); + } + + /** + * Create and return an ImportConfiguration with configuration type `OPAC_SEARCH` and search interface type 'FTP'. + */ + private ImportConfiguration createFtpImportConfiguration() { + ImportConfiguration genericFtpConfiguration = new ImportConfiguration(); + genericFtpConfiguration.setTitle("FTP example configuration"); + genericFtpConfiguration.setConfigurationType(ImportConfigurationType.OPAC_SEARCH.name()); + genericFtpConfiguration.setInterfaceType(SearchInterfaceType.FTP.name()); + return genericFtpConfiguration; + } +} From beeafb4071d44dcf462b0f4404d7753e109c02ea Mon Sep 17 00:00:00 2001 From: Arved Solth Date: Wed, 14 Dec 2022 09:40:05 +0100 Subject: [PATCH 3/3] Remove unused imports --- .../production/services/catalogimport/CatalogImportIT.java | 3 --- 1 file changed, 3 deletions(-) diff --git a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java index cde67e5eb6f..ece806917dd 100644 --- a/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java +++ b/Kitodo/src/test/java/org/kitodo/production/services/catalogimport/CatalogImportIT.java @@ -35,11 +35,8 @@ import org.junit.Test; import org.kitodo.MockDatabase; import org.kitodo.SecurityTestUtils; -import org.kitodo.data.database.beans.ImportConfiguration; -import org.kitodo.data.database.exceptions.DAOException; import org.kitodo.production.helper.TempProcess; import org.kitodo.production.services.ServiceManager; -import org.kitodo.production.services.data.ImportService; public class CatalogImportIT {