diff --git a/src/main/java/nl/knaw/dans/dvingest/DansDepositSupportDisabledFactory.java b/src/main/java/nl/knaw/dans/dvingest/DansDepositSupportDisabledFactory.java new file mode 100644 index 0000000..990bc24 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/DansDepositSupportDisabledFactory.java @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvingest; + +import nl.knaw.dans.dvingest.core.DataverseIngestDeposit; +import nl.knaw.dans.dvingest.core.Deposit; +import nl.knaw.dans.dvingest.core.dansbag.DansDepositSupportFactory; + +public class DansDepositSupportDisabledFactory implements DansDepositSupportFactory { + @Override + public Deposit addDansDepositSupportIfEnabled(DataverseIngestDeposit deposit) { + return deposit; + } +} diff --git a/src/main/java/nl/knaw/dans/dvingest/core/DepositInboxTaskFactory.java b/src/main/java/nl/knaw/dans/dvingest/DansDepositSupportFactoryImpl.java similarity index 64% rename from src/main/java/nl/knaw/dans/dvingest/core/DepositInboxTaskFactory.java rename to src/main/java/nl/knaw/dans/dvingest/DansDepositSupportFactoryImpl.java index ce2f7d1..176c176 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/DepositInboxTaskFactory.java +++ b/src/main/java/nl/knaw/dans/dvingest/DansDepositSupportFactoryImpl.java @@ -13,31 +13,29 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package nl.knaw.dans.dvingest.core; +package nl.knaw.dans.dvingest; import lombok.AllArgsConstructor; +import lombok.extern.slf4j.Slf4j; import nl.knaw.dans.dvingest.client.ValidateDansBagService; +import nl.knaw.dans.dvingest.core.DataverseIngestDeposit; +import nl.knaw.dans.dvingest.core.Deposit; import nl.knaw.dans.dvingest.core.dansbag.DansBagMappingService; +import nl.knaw.dans.dvingest.core.dansbag.DansDepositSupport; +import nl.knaw.dans.dvingest.core.dansbag.DansDepositSupportFactory; import nl.knaw.dans.dvingest.core.service.DataverseService; -import nl.knaw.dans.dvingest.core.service.UtilityServices; import nl.knaw.dans.dvingest.core.service.YamlService; -import nl.knaw.dans.lib.util.inbox.InboxTaskFactory; - -import java.nio.file.Path; +@Slf4j @AllArgsConstructor -public class DepositInboxTaskFactory implements InboxTaskFactory { - private final Path outputDir; - private final boolean onlyConvertDansDeposit; - private final DataverseService dataverseService; - private final UtilityServices utilityServices; +public class DansDepositSupportFactoryImpl implements DansDepositSupportFactory { private final ValidateDansBagService validateDansBagService; private final DansBagMappingService dansBagMappingService; + private final DataverseService dataverseService; private final YamlService yamlService; @Override - public Runnable createInboxTask(Path path) { - var deposit = new DataverseIngestDeposit(path, yamlService); - return new DepositTask(deposit, outputDir, onlyConvertDansDeposit, validateDansBagService, dataverseService, utilityServices, dansBagMappingService, yamlService); + public Deposit addDansDepositSupportIfEnabled(DataverseIngestDeposit deposit) { + return new DansDepositSupport(deposit, validateDansBagService, dansBagMappingService, dataverseService, yamlService); } } diff --git a/src/main/java/nl/knaw/dans/dvingest/DataverseIngestDepositFactoryImpl.java b/src/main/java/nl/knaw/dans/dvingest/DataverseIngestDepositFactoryImpl.java new file mode 100644 index 0000000..5ed45a8 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/DataverseIngestDepositFactoryImpl.java @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvingest; + +import lombok.AllArgsConstructor; +import nl.knaw.dans.dvingest.core.DataverseIngestDeposit; +import nl.knaw.dans.dvingest.core.DataverseIngestDepositFactory; +import nl.knaw.dans.dvingest.core.service.YamlService; + +import java.nio.file.Path; + +@AllArgsConstructor +public class DataverseIngestDepositFactoryImpl implements DataverseIngestDepositFactory { + private final YamlService yamlService; + + @Override + public DataverseIngestDeposit createDataverseIngestDeposit(Path location) { + return new DataverseIngestDeposit(location, yamlService); + } +} diff --git a/src/main/java/nl/knaw/dans/dvingest/DdDataverseIngestApplication.java b/src/main/java/nl/knaw/dans/dvingest/DdDataverseIngestApplication.java index f2716d6..3cd50a0 100644 --- a/src/main/java/nl/knaw/dans/dvingest/DdDataverseIngestApplication.java +++ b/src/main/java/nl/knaw/dans/dvingest/DdDataverseIngestApplication.java @@ -23,10 +23,12 @@ import nl.knaw.dans.dvingest.client.ValidateDansBagServiceImpl; import nl.knaw.dans.dvingest.config.DansDepositConversionConfig; import nl.knaw.dans.dvingest.config.DdDataverseIngestConfiguration; +import nl.knaw.dans.dvingest.config.IngestAreaConfig; import nl.knaw.dans.dvingest.core.AutoIngestArea; import nl.knaw.dans.dvingest.core.IngestArea; import nl.knaw.dans.dvingest.core.dansbag.DansBagMappingService; import nl.knaw.dans.dvingest.core.dansbag.DansBagMappingServiceImpl; +import nl.knaw.dans.dvingest.core.dansbag.DansDepositSupportFactory; import nl.knaw.dans.dvingest.core.dansbag.SupportedLicenses; import nl.knaw.dans.dvingest.core.dansbag.mapper.DepositToDvDatasetMetadataMapper; import nl.knaw.dans.dvingest.core.service.DataverseService; @@ -38,6 +40,7 @@ import nl.knaw.dans.dvingest.resources.IngestApiResource; import nl.knaw.dans.lib.dataverse.DataverseException; import nl.knaw.dans.lib.util.MappingLoader; +import nl.knaw.dans.lib.util.inbox.Inbox; import org.apache.commons.io.FileUtils; import java.io.IOException; @@ -77,42 +80,46 @@ public void run(final DdDataverseIngestConfiguration configuration, final Enviro .maxNumberOfFilesPerUpload(configuration.getIngest().getMaxNumberOfFilesPerUploadBatch()) .maxUploadSize(configuration.getIngest().getMaxByteSizePerUploadBatch().toBytes()) .build(); - var dansBagMappingForImport = createDansBagMappingService(false, configuration.getDansDepositConversion(), dataverseService); - var dansBagMappingForMigration = createDansBagMappingService(true, configuration.getDansDepositConversion(), dataverseService); var yamlService = new YamlServiceImpl(); - var importAreaConfig = configuration.getIngest().getImportConfig(); - var validateDansBagMigration = new ValidateDansBagServiceImpl(configuration.getDansDepositConversion().getValidateDansBag(), true); - var validateDansBagImport = new ValidateDansBagServiceImpl(configuration.getDansDepositConversion().getValidateDansBag(), false); - var importArea = IngestArea.builder() - .executorService(environment.lifecycle().executorService("import").minThreads(1).maxThreads(1).build()) - .dataverseService(dataverseService) - .utilityServices(utilityServices) - .yamlService(yamlService) - .inbox(importAreaConfig.getInbox()) - .outbox(importAreaConfig.getOutbox()) - .validateDansBagService(validateDansBagImport) - .dansBagMappingService(dansBagMappingForImport).build(); - var migrationAreaConfig = configuration.getIngest().getMigration(); - var migrationArea = IngestArea.builder() - .executorService(environment.lifecycle().executorService("migration").minThreads(1).maxThreads(1).build()) - .dataverseService(dataverseService) - .utilityServices(utilityServices) - .yamlService(yamlService) - .inbox(migrationAreaConfig.getInbox()) - .outbox(migrationAreaConfig.getOutbox()) - .validateDansBagService(validateDansBagMigration) - .dansBagMappingService(dansBagMappingForMigration).build(); + var dataverseIngestDepositFactory = new DataverseIngestDepositFactoryImpl(yamlService); + + /* + * Import area + */ + DansDepositConversionConfig dansDepositConversionConfig = configuration.getDansDepositConversion(); + DansDepositSupportFactory dansDepositSupportFactoryImport = new DansDepositSupportDisabledFactory(); + if (dansDepositConversionConfig != null) { + var dansBagMappingServiceImport = createDansBagMappingService(false, dansDepositConversionConfig, dataverseService); + var validateDansBagImportImport = new ValidateDansBagServiceImpl(dansDepositConversionConfig.getValidateDansBag(), false); + dansDepositSupportFactoryImport = new DansDepositSupportFactoryImpl(validateDansBagImportImport, dansBagMappingServiceImport, dataverseService, yamlService); + } + var depositTaskFactoryImport = new DepositTaskFactoryImpl(dataverseService, utilityServices, dansDepositSupportFactoryImport, yamlService); + var importJobFactory = new ImportJobFactoryImpl(dataverseIngestDepositFactory, depositTaskFactoryImport); + IngestAreaConfig importConfig = configuration.getIngest().getImportConfig(); + var importArea = new IngestArea(importJobFactory, importConfig.getInbox(), importConfig.getOutbox(), + environment.lifecycle().executorService("import").minThreads(1).maxThreads(1).build()); + + /* + * Migration area + */ + DansDepositSupportFactory dansDepositSupportFactoryMigration = new DansDepositSupportDisabledFactory(); + if (dansDepositConversionConfig != null) { + var dansBagMappingService = createDansBagMappingService(true, dansDepositConversionConfig, dataverseService); + var validateDansBagImport = new ValidateDansBagServiceImpl(dansDepositConversionConfig.getValidateDansBag(), true); + dansDepositSupportFactoryMigration = new DansDepositSupportFactoryImpl(validateDansBagImport, dansBagMappingService, dataverseService, yamlService); + } + var depositTaskFactoryMigration = new DepositTaskFactoryImpl(dataverseService, utilityServices, dansDepositSupportFactoryMigration, yamlService); + var migrationJobFactory = new ImportJobFactoryImpl(dataverseIngestDepositFactory, depositTaskFactoryMigration); + IngestAreaConfig migrationConfig = configuration.getIngest().getMigration(); + var migrationArea = new IngestArea(migrationJobFactory, migrationConfig.getInbox(), migrationConfig.getOutbox(), + environment.lifecycle().executorService("migration").minThreads(1).maxThreads(1).build()); + /* + * Auto ingest area + */ var autoIngestConfig = configuration.getIngest().getAutoIngest(); - var autoIngestArea = AutoIngestArea.autoIngestAreaBuilder() - .inbox(autoIngestConfig.getInbox()) - .outbox(autoIngestConfig.getOutbox()) - .dansBagMappingService(dansBagMappingForImport) - .dataverseService(dataverseService) - .utilityServices(utilityServices) - .validateDansBagService(validateDansBagImport) - .yamlService(yamlService) - .executorService(environment.lifecycle().executorService("auto-ingest").minThreads(1).maxThreads(1).build()) - .build(); + var inboxTaskFactory = new InboxTaskFactoryImpl(dataverseIngestDepositFactory, depositTaskFactoryImport); + var inbox = Inbox.builder().inbox(autoIngestConfig.getInbox()).taskFactory(inboxTaskFactory).build(); + var autoIngestArea = new AutoIngestArea(inbox, autoIngestConfig.getOutbox()); /* * Register components with Dropwizard @@ -124,10 +131,6 @@ public void run(final DdDataverseIngestConfiguration configuration, final Enviro } private DansBagMappingService createDansBagMappingService(boolean isMigration, DansDepositConversionConfig dansDepositConversionConfig, DataverseService dataverseService) { - if (dansDepositConversionConfig == null) { - log.info("DANS Deposit conversion is disabled"); - return null; - } log.info("Configuring DANS Deposit conversion"); try { var mapper = createMapper(isMigration, dansDepositConversionConfig, dataverseService); diff --git a/src/main/java/nl/knaw/dans/dvingest/DepositTaskFactoryImpl.java b/src/main/java/nl/knaw/dans/dvingest/DepositTaskFactoryImpl.java new file mode 100644 index 0000000..3130140 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/DepositTaskFactoryImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvingest; + +import lombok.AllArgsConstructor; +import nl.knaw.dans.dvingest.core.DataverseIngestDeposit; +import nl.knaw.dans.dvingest.core.DepositTask; +import nl.knaw.dans.dvingest.core.DepositTaskFactory; +import nl.knaw.dans.dvingest.core.dansbag.DansDepositSupportFactory; +import nl.knaw.dans.dvingest.core.service.DataverseService; +import nl.knaw.dans.dvingest.core.service.UtilityServices; +import nl.knaw.dans.dvingest.core.service.YamlService; + +import java.nio.file.Path; + +@AllArgsConstructor +public class DepositTaskFactoryImpl implements DepositTaskFactory { + private final DataverseService dataverseService; + private final UtilityServices utilityServices; + private final DansDepositSupportFactory dansDepositSupportFactory; + private final YamlService yamlService; + + @Override + public Runnable createDepositTask(DataverseIngestDeposit deposit, Path outputDir, boolean onlyConvertDansDeposit) { + return new DepositTask(deposit, outputDir, onlyConvertDansDeposit, dansDepositSupportFactory, dataverseService, utilityServices, yamlService); + } +} diff --git a/src/main/java/nl/knaw/dans/dvingest/ImportJobFactoryImpl.java b/src/main/java/nl/knaw/dans/dvingest/ImportJobFactoryImpl.java new file mode 100644 index 0000000..0d94fb8 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/ImportJobFactoryImpl.java @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvingest; + +import lombok.AllArgsConstructor; +import lombok.NonNull; +import nl.knaw.dans.dvingest.api.ImportCommandDto; +import nl.knaw.dans.dvingest.core.DataverseIngestDepositFactory; +import nl.knaw.dans.dvingest.core.DepositTaskFactory; +import nl.knaw.dans.dvingest.core.ImportJob; +import nl.knaw.dans.dvingest.core.ImportJobFactory; + +import java.nio.file.Path; + +@AllArgsConstructor +public class ImportJobFactoryImpl implements ImportJobFactory { + @NonNull + private final DataverseIngestDepositFactory dataverseIngestDepositFactory; + @NonNull + private final DepositTaskFactory depositTaskFactory; + + @Override + public ImportJob createImportJob(ImportCommandDto importCommand, Path outputDir, boolean onlyConvertDansDeposit) { + return new ImportJob(importCommand, outputDir, onlyConvertDansDeposit, dataverseIngestDepositFactory, depositTaskFactory); + } +} diff --git a/src/main/java/nl/knaw/dans/dvingest/InboxTaskFactoryImpl.java b/src/main/java/nl/knaw/dans/dvingest/InboxTaskFactoryImpl.java new file mode 100644 index 0000000..924740c --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/InboxTaskFactoryImpl.java @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvingest; + +import lombok.AllArgsConstructor; +import nl.knaw.dans.dvingest.core.DataverseIngestDepositFactory; +import nl.knaw.dans.dvingest.core.DepositTaskFactory; +import nl.knaw.dans.lib.util.inbox.InboxTaskFactory; + +import java.nio.file.Path; + +@AllArgsConstructor +public class InboxTaskFactoryImpl implements InboxTaskFactory { + private final DataverseIngestDepositFactory dataverseIngestDepositFactory; + private final DepositTaskFactory depositTaskFactory; + + @Override + public Runnable createInboxTask(Path path) { + var dataVerseIngestDeposit = dataverseIngestDepositFactory.createDataverseIngestDeposit(path); + return depositTaskFactory.createDepositTask(dataVerseIngestDeposit, path, false); + } +} diff --git a/src/main/java/nl/knaw/dans/dvingest/core/AutoIngestArea.java b/src/main/java/nl/knaw/dans/dvingest/core/AutoIngestArea.java index c2c7727..ebc0d11 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/AutoIngestArea.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/AutoIngestArea.java @@ -16,35 +16,17 @@ package nl.knaw.dans.dvingest.core; import io.dropwizard.lifecycle.Managed; -import lombok.Builder; -import lombok.NonNull; +import lombok.AllArgsConstructor; import lombok.extern.slf4j.Slf4j; -import nl.knaw.dans.dvingest.client.ValidateDansBagService; -import nl.knaw.dans.dvingest.core.dansbag.DansBagMappingService; -import nl.knaw.dans.dvingest.core.service.DataverseService; -import nl.knaw.dans.dvingest.core.service.UtilityServices; -import nl.knaw.dans.dvingest.core.service.YamlService; import nl.knaw.dans.lib.util.inbox.Inbox; import java.nio.file.Path; -import java.util.concurrent.ExecutorService; @Slf4j -public class AutoIngestArea extends IngestArea implements Managed { +@AllArgsConstructor +public class AutoIngestArea implements Managed { private final Inbox autoIngestInbox; - - @Builder(builderMethodName = "autoIngestAreaBuilder") - public AutoIngestArea(@NonNull ExecutorService executorService, @NonNull ValidateDansBagService validateDansBagService, @NonNull DataverseService dataverseService, - @NonNull UtilityServices utilityServices, - DansBagMappingService dansBagMappingService /* may be null if disabled !*/, @NonNull YamlService yamlService, - Path inbox, Path outbox) { - super(executorService, validateDansBagService, dataverseService, utilityServices, dansBagMappingService, yamlService, inbox, outbox); - var inboxTaskFactory = new DepositInboxTaskFactory(outbox, false, dataverseService, utilityServices, validateDansBagService, dansBagMappingService, yamlService); - autoIngestInbox = Inbox.builder() - .inbox(inbox) - .taskFactory(inboxTaskFactory) - .build(); - } + private final Path outbox; private void initOutputDir() { log.debug("Initializing output directory: {}", outbox); diff --git a/src/main/java/nl/knaw/dans/dvingest/core/DataverseIngestDepositFactory.java b/src/main/java/nl/knaw/dans/dvingest/core/DataverseIngestDepositFactory.java new file mode 100644 index 0000000..741d4d6 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/core/DataverseIngestDepositFactory.java @@ -0,0 +1,23 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvingest.core; + +import java.nio.file.Path; + +public interface DataverseIngestDepositFactory { + + DataverseIngestDeposit createDataverseIngestDeposit(Path location); +} diff --git a/src/main/java/nl/knaw/dans/dvingest/core/DepositTask.java b/src/main/java/nl/knaw/dans/dvingest/core/DepositTask.java index 924bf3b..d134918 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/DepositTask.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/DepositTask.java @@ -21,6 +21,7 @@ import nl.knaw.dans.dvingest.core.bagprocessor.BagProcessor; import nl.knaw.dans.dvingest.core.dansbag.DansBagMappingService; import nl.knaw.dans.dvingest.core.dansbag.DansDepositSupport; +import nl.knaw.dans.dvingest.core.dansbag.DansDepositSupportFactory; import nl.knaw.dans.dvingest.core.dansbag.exception.RejectedDepositException; import nl.knaw.dans.dvingest.core.service.DataverseService; import nl.knaw.dans.dvingest.core.service.UtilityServices; @@ -47,10 +48,8 @@ public enum Status { @Getter private Status status = Status.TODO; - public DepositTask(DataverseIngestDeposit dataverseIngestDeposit, Path outputDir, boolean onlyConvertDansDeposit, ValidateDansBagService validateDansBagService, DataverseService dataverseService, UtilityServices utilityServices, - DansBagMappingService dansBagMappingService, - YamlService yamlService) { - this.deposit = dansBagMappingService == null ? dataverseIngestDeposit : new DansDepositSupport(dataverseIngestDeposit, validateDansBagService, dansBagMappingService, dataverseService, yamlService); + public DepositTask(DataverseIngestDeposit dataverseIngestDeposit, Path outputDir, boolean onlyConvertDansDeposit, DansDepositSupportFactory dansDepositSupportFactory, DataverseService dataverseService, UtilityServices utilityServices, YamlService yamlService) { + this.deposit = dansDepositSupportFactory.addDansDepositSupportIfEnabled(dataverseIngestDeposit); this.dataverseService = dataverseService; this.onlyConvertDansDeposit = onlyConvertDansDeposit; this.utilityServices = utilityServices; diff --git a/src/main/java/nl/knaw/dans/dvingest/core/DepositTaskFactory.java b/src/main/java/nl/knaw/dans/dvingest/core/DepositTaskFactory.java new file mode 100644 index 0000000..648883a --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/core/DepositTaskFactory.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvingest.core; + +import nl.knaw.dans.lib.util.inbox.InboxTaskFactory; + +import java.nio.file.Path; + +public interface DepositTaskFactory { + + Runnable createDepositTask(DataverseIngestDeposit deposit, Path outputDir, boolean onlyConvertDansDeposit); +} diff --git a/src/main/java/nl/knaw/dans/dvingest/core/ImportJob.java b/src/main/java/nl/knaw/dans/dvingest/core/ImportJob.java index b19e41d..815e636 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/ImportJob.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/ImportJob.java @@ -15,18 +15,13 @@ */ package nl.knaw.dans.dvingest.core; -import lombok.Builder; +import lombok.AllArgsConstructor; import lombok.Getter; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import nl.knaw.dans.dvingest.api.ImportCommandDto; import nl.knaw.dans.dvingest.api.ImportJobStatusDto; import nl.knaw.dans.dvingest.api.ImportJobStatusDto.StatusEnum; -import nl.knaw.dans.dvingest.client.ValidateDansBagService; -import nl.knaw.dans.dvingest.core.dansbag.DansBagMappingService; -import nl.knaw.dans.dvingest.core.service.DataverseService; -import nl.knaw.dans.dvingest.core.service.UtilityServices; -import nl.knaw.dans.dvingest.core.service.YamlService; import java.io.IOException; import java.nio.file.Files; @@ -34,7 +29,7 @@ import java.util.TreeSet; @Slf4j -@Builder +@AllArgsConstructor public class ImportJob implements Runnable { @NonNull @Getter @@ -42,37 +37,12 @@ public class ImportJob implements Runnable { @NonNull private final Path outputDir; private boolean onlyConvertDansDeposit; - @NonNull - private final DataverseService dataverseService; - @NonNull - private final UtilityServices utilityServices; - @NonNull - private final YamlService yamlService; - @NonNull - private final DansBagMappingService dansBagMappingService; - @NonNull - private final ValidateDansBagService validateDansBagService; + private final DataverseIngestDepositFactory depositFactory; + private final DepositTaskFactory depositTaskFactory; @Getter private final ImportJobStatusDto status = new ImportJobStatusDto(); - private ImportJob(@NonNull ImportCommandDto importCommand, - @NonNull Path outputDir, - boolean onlyConvertDansDeposit, - @NonNull DataverseService dataverseService, - @NonNull UtilityServices utilityServices, - @NonNull YamlService yamlService, - @NonNull DansBagMappingService dansBagMappingService, @NonNull ValidateDansBagService validateDansBagService) { - this.importCommand = importCommand; - this.outputDir = outputDir; - this.onlyConvertDansDeposit = onlyConvertDansDeposit; - this.dataverseService = dataverseService; - this.utilityServices = utilityServices; - this.yamlService = yamlService; - this.dansBagMappingService = dansBagMappingService; - this.validateDansBagService = validateDansBagService; - } - @Override public void run() { try { @@ -83,11 +53,14 @@ public void run() { var deposits = new TreeSet(); if (importCommand.getSingleObject()) { - deposits.add(new DataverseIngestDeposit(Path.of(importCommand.getPath()), yamlService)); + deposits.add(depositFactory.createDataverseIngestDeposit(Path.of(importCommand.getPath()))); } else { try (var depositPaths = Files.list(Path.of(importCommand.getPath()))) { - depositPaths.filter(Files::isDirectory).sorted().forEach(p -> deposits.add(new DataverseIngestDeposit(p, yamlService))); + depositPaths.filter(Files::isDirectory) + .sorted() + .map(depositFactory::createDataverseIngestDeposit) + .forEach(deposits::add); } } @@ -95,7 +68,7 @@ public void run() { for (DataverseIngestDeposit dataverseIngestDeposit : deposits) { log.info("START Processing deposit: {}", dataverseIngestDeposit.getId()); - var task = new DepositTask(dataverseIngestDeposit, outputDir, onlyConvertDansDeposit, validateDansBagService, dataverseService, utilityServices, dansBagMappingService, yamlService); + var task = depositTaskFactory.createDepositTask(dataverseIngestDeposit, outputDir, onlyConvertDansDeposit); task.run(); log.info("END Processing deposit: {}", dataverseIngestDeposit.getId()); // TODO: record number of processed/rejected/failed deposits in ImportJob status diff --git a/src/main/java/nl/knaw/dans/dvingest/core/ImportJobFactory.java b/src/main/java/nl/knaw/dans/dvingest/core/ImportJobFactory.java new file mode 100644 index 0000000..d3383ce --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/core/ImportJobFactory.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvingest.core; + +import nl.knaw.dans.dvingest.api.ImportCommandDto; + +import java.nio.file.Path; + +public interface ImportJobFactory { + + ImportJob createImportJob(ImportCommandDto importCommand, Path outputDir, boolean onlyConvertDansDeposit); +} diff --git a/src/main/java/nl/knaw/dans/dvingest/core/IngestArea.java b/src/main/java/nl/knaw/dans/dvingest/core/IngestArea.java index b10a4cf..659749d 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/IngestArea.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/IngestArea.java @@ -15,17 +15,11 @@ */ package nl.knaw.dans.dvingest.core; -import lombok.Builder; import lombok.NonNull; import lombok.extern.slf4j.Slf4j; import nl.knaw.dans.dvingest.api.ImportCommandDto; import nl.knaw.dans.dvingest.api.ImportJobStatusDto; import nl.knaw.dans.dvingest.api.ImportJobStatusDto.StatusEnum; -import nl.knaw.dans.dvingest.client.ValidateDansBagService; -import nl.knaw.dans.dvingest.core.dansbag.DansBagMappingService; -import nl.knaw.dans.dvingest.core.service.DataverseService; -import nl.knaw.dans.dvingest.core.service.UtilityServices; -import nl.knaw.dans.dvingest.core.service.YamlService; import java.nio.file.Path; import java.util.List; @@ -34,17 +28,11 @@ import java.util.concurrent.ExecutorService; @Slf4j -public class IngestArea { +public class IngestArea { @NonNull private final ExecutorService executorService; @NonNull - private final DataverseService dataverseService; - @NonNull - private final UtilityServices utilityServices; - @NonNull - private final DansBagMappingService dansBagMappingService; - @NonNull - private final ValidateDansBagService validateDansBagService; + private final ImportJobFactory importJobFactory; @NonNull private final Path inbox; @NonNull @@ -52,27 +40,18 @@ public class IngestArea { private final Map importJobs = new ConcurrentHashMap<>(); - @NonNull - private final YamlService yamlService; - - @Builder - protected IngestArea(ExecutorService executorService, ValidateDansBagService validateDansBagService, DataverseService dataverseService, UtilityServices utilityServices, DansBagMappingService dansBagMappingService, YamlService yamlService, Path inbox, Path outbox) { + public IngestArea(ImportJobFactory importJobFactory, Path inbox, Path outbox, ExecutorService executorService) { try { - this.executorService = executorService; - this.validateDansBagService = validateDansBagService; - this.dataverseService = dataverseService; - this.utilityServices = utilityServices; - this.dansBagMappingService = dansBagMappingService; - this.yamlService = yamlService; + this.importJobFactory = importJobFactory; this.inbox = inbox.toAbsolutePath().toRealPath(); this.outbox = outbox.toAbsolutePath().toRealPath(); + this.executorService = executorService; } catch (Exception e) { throw new IllegalStateException("Failed to create ingest area", e); } } - public void submit(ImportCommandDto importCommand) { log.debug("Received import command: {}", importCommand); var existingJob = importJobs.get(importCommand.getPath()); @@ -108,16 +87,7 @@ private ImportJob createImportJob(ImportCommandDto importCommand) { else { relativePath = inbox.relativize(Path.of(importCommand.getPath())); } - return ImportJob.builder() - .importCommand(importCommand) - .outputDir(outbox.resolve(relativePath)) - .onlyConvertDansDeposit(importCommand.getOnlyConvertDansBag()) - .dataverseService(dataverseService) - .utilityServices(utilityServices) - .yamlService(yamlService) - .dansBagMappingService(dansBagMappingService) - .validateDansBagService(validateDansBagService) - .build(); + return importJobFactory.createImportJob(importCommand, outbox.resolve(relativePath), importCommand.getOnlyConvertDansBag()); } private void validatePath(String path) { diff --git a/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositSupportFactory.java b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositSupportFactory.java new file mode 100644 index 0000000..7c81b72 --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/core/dansbag/DansDepositSupportFactory.java @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2024 DANS - Data Archiving and Networked Services (info@dans.knaw.nl) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package nl.knaw.dans.dvingest.core.dansbag; + +import nl.knaw.dans.dvingest.core.DataverseIngestDeposit; +import nl.knaw.dans.dvingest.core.Deposit; + +public interface DansDepositSupportFactory { + + Deposit addDansDepositSupportIfEnabled(DataverseIngestDeposit deposit); + +}