From 47e04692ead0af3a08ec00afa8a41c2fcde3f5f4 Mon Sep 17 00:00:00 2001 From: Jan van Mansum Date: Wed, 11 Dec 2024 13:12:45 +0100 Subject: [PATCH] Factory for BagProcessor. --- .../dvingest/BagProcessorFactoryImpl.java | 43 +++++++++++++++++++ .../DdDataverseIngestApplication.java | 5 ++- .../dans/dvingest/DepositTaskFactoryImpl.java | 10 ++--- .../knaw/dans/dvingest/core/DepositTask.java | 24 +++-------- .../bagprocessor/BagProcessorFactory.java | 28 ++++++++++++ 5 files changed, 84 insertions(+), 26 deletions(-) create mode 100644 src/main/java/nl/knaw/dans/dvingest/BagProcessorFactoryImpl.java create mode 100644 src/main/java/nl/knaw/dans/dvingest/core/bagprocessor/BagProcessorFactory.java diff --git a/src/main/java/nl/knaw/dans/dvingest/BagProcessorFactoryImpl.java b/src/main/java/nl/knaw/dans/dvingest/BagProcessorFactoryImpl.java new file mode 100644 index 0000000..510566f --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/BagProcessorFactoryImpl.java @@ -0,0 +1,43 @@ +/* + * 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 io.dropwizard.configuration.ConfigurationException; +import lombok.AllArgsConstructor; +import nl.knaw.dans.dvingest.core.DataverseIngestBag; +import nl.knaw.dans.dvingest.core.bagprocessor.BagProcessor; +import nl.knaw.dans.dvingest.core.bagprocessor.BagProcessorFactory; +import nl.knaw.dans.dvingest.core.service.DataverseService; +import nl.knaw.dans.dvingest.core.service.UtilityServices; + +import java.io.IOException; +import java.util.UUID; + +@AllArgsConstructor +public class BagProcessorFactoryImpl implements BagProcessorFactory { + private final DataverseService dataverseService; + private final UtilityServices utilityServices; + + @Override + public BagProcessor createBagProcessor(UUID depositId, DataverseIngestBag bag) throws ConfigurationException, IOException { + return BagProcessor.builder() + .depositId(depositId) + .bag(bag) + .dataverseService(dataverseService) + .utilityServices(utilityServices) + .build(); + } +} diff --git a/src/main/java/nl/knaw/dans/dvingest/DdDataverseIngestApplication.java b/src/main/java/nl/knaw/dans/dvingest/DdDataverseIngestApplication.java index 3cd50a0..928702a 100644 --- a/src/main/java/nl/knaw/dans/dvingest/DdDataverseIngestApplication.java +++ b/src/main/java/nl/knaw/dans/dvingest/DdDataverseIngestApplication.java @@ -82,6 +82,7 @@ public void run(final DdDataverseIngestConfiguration configuration, final Enviro .build(); var yamlService = new YamlServiceImpl(); var dataverseIngestDepositFactory = new DataverseIngestDepositFactoryImpl(yamlService); + var bagProcessorFactory = new BagProcessorFactoryImpl(dataverseService, utilityServices); /* * Import area @@ -93,7 +94,7 @@ public void run(final DdDataverseIngestConfiguration configuration, final Enviro var validateDansBagImportImport = new ValidateDansBagServiceImpl(dansDepositConversionConfig.getValidateDansBag(), false); dansDepositSupportFactoryImport = new DansDepositSupportFactoryImpl(validateDansBagImportImport, dansBagMappingServiceImport, dataverseService, yamlService); } - var depositTaskFactoryImport = new DepositTaskFactoryImpl(dataverseService, utilityServices, dansDepositSupportFactoryImport, yamlService); + var depositTaskFactoryImport = new DepositTaskFactoryImpl(bagProcessorFactory, dansDepositSupportFactoryImport); var importJobFactory = new ImportJobFactoryImpl(dataverseIngestDepositFactory, depositTaskFactoryImport); IngestAreaConfig importConfig = configuration.getIngest().getImportConfig(); var importArea = new IngestArea(importJobFactory, importConfig.getInbox(), importConfig.getOutbox(), @@ -108,7 +109,7 @@ public void run(final DdDataverseIngestConfiguration configuration, final Enviro var validateDansBagImport = new ValidateDansBagServiceImpl(dansDepositConversionConfig.getValidateDansBag(), true); dansDepositSupportFactoryMigration = new DansDepositSupportFactoryImpl(validateDansBagImport, dansBagMappingService, dataverseService, yamlService); } - var depositTaskFactoryMigration = new DepositTaskFactoryImpl(dataverseService, utilityServices, dansDepositSupportFactoryMigration, yamlService); + var depositTaskFactoryMigration = new DepositTaskFactoryImpl(bagProcessorFactory, dansDepositSupportFactoryMigration); var migrationJobFactory = new ImportJobFactoryImpl(dataverseIngestDepositFactory, depositTaskFactoryMigration); IngestAreaConfig migrationConfig = configuration.getIngest().getMigration(); var migrationArea = new IngestArea(migrationJobFactory, migrationConfig.getInbox(), migrationConfig.getOutbox(), diff --git a/src/main/java/nl/knaw/dans/dvingest/DepositTaskFactoryImpl.java b/src/main/java/nl/knaw/dans/dvingest/DepositTaskFactoryImpl.java index 3130140..8ce341e 100644 --- a/src/main/java/nl/knaw/dans/dvingest/DepositTaskFactoryImpl.java +++ b/src/main/java/nl/knaw/dans/dvingest/DepositTaskFactoryImpl.java @@ -19,22 +19,18 @@ 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.bagprocessor.BagProcessorFactory; 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 BagProcessorFactory bagProcessorFactory; 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); + return new DepositTask(deposit, outputDir, onlyConvertDansDeposit, bagProcessorFactory, dansDepositSupportFactory); } } 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 aacc7c3..2585d6f 100644 --- a/src/main/java/nl/knaw/dans/dvingest/core/DepositTask.java +++ b/src/main/java/nl/knaw/dans/dvingest/core/DepositTask.java @@ -17,12 +17,9 @@ import lombok.Getter; import lombok.extern.slf4j.Slf4j; -import nl.knaw.dans.dvingest.core.bagprocessor.BagProcessor; +import nl.knaw.dans.dvingest.core.bagprocessor.BagProcessorFactory; 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; -import nl.knaw.dans.dvingest.core.service.YamlService; import java.io.IOException; import java.nio.file.Path; @@ -39,18 +36,17 @@ public enum Status { private final Deposit deposit; private final Path outputDir; private final boolean onlyConvertDansDeposit; - private final DataverseService dataverseService; - private final UtilityServices utilityServices; + private final BagProcessorFactory bagProcessorFactory; @Getter private Status status = Status.TODO; - public DepositTask(DataverseIngestDeposit dataverseIngestDeposit, Path outputDir, boolean onlyConvertDansDeposit, DansDepositSupportFactory dansDepositSupportFactory, DataverseService dataverseService, UtilityServices utilityServices, YamlService yamlService) { + public DepositTask(DataverseIngestDeposit dataverseIngestDeposit, Path outputDir, boolean onlyConvertDansDeposit, BagProcessorFactory bagProcessorFactory, + DansDepositSupportFactory dansDepositSupportFactory) { this.deposit = dansDepositSupportFactory.addDansDepositSupportIfEnabled(dataverseIngestDeposit); - this.dataverseService = dataverseService; - this.onlyConvertDansDeposit = onlyConvertDansDeposit; - this.utilityServices = utilityServices; this.outputDir = outputDir; + this.onlyConvertDansDeposit = onlyConvertDansDeposit; + this.bagProcessorFactory = bagProcessorFactory; } @Override @@ -66,13 +62,7 @@ public void run() { for (DataverseIngestBag bag : deposit.getBags()) { log.info("START processing deposit / bag: {} / {}", deposit.getId(), bag); - pid = BagProcessor.builder() - .depositId(deposit.getId()) - .bag(bag) - .dataverseService(dataverseService) - .utilityServices(utilityServices) - .build() - .run(pid); + pid = bagProcessorFactory.createBagProcessor(deposit.getId(), bag).run(pid); log.info("END processing deposit / bag: {} / {}", deposit.getId(), bag); } deposit.onSuccess(pid, "Deposit processed successfully"); diff --git a/src/main/java/nl/knaw/dans/dvingest/core/bagprocessor/BagProcessorFactory.java b/src/main/java/nl/knaw/dans/dvingest/core/bagprocessor/BagProcessorFactory.java new file mode 100644 index 0000000..8c1b76e --- /dev/null +++ b/src/main/java/nl/knaw/dans/dvingest/core/bagprocessor/BagProcessorFactory.java @@ -0,0 +1,28 @@ +/* + * 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.bagprocessor; + +import io.dropwizard.configuration.ConfigurationException; +import nl.knaw.dans.dvingest.core.DataverseIngestBag; + +import java.io.IOException; +import java.util.UUID; + +public interface BagProcessorFactory { + + BagProcessor createBagProcessor(UUID depositId, DataverseIngestBag bag) throws ConfigurationException, IOException; + +}