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/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; + } +}