Skip to content

Commit

Permalink
Factory for BagProcessor.
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Dec 11, 2024
1 parent e8f572c commit 47e0469
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 26 deletions.
43 changes: 43 additions & 0 deletions src/main/java/nl/knaw/dans/dvingest/BagProcessorFactoryImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected])
*
* 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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand All @@ -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(),
Expand Down
10 changes: 3 additions & 7 deletions src/main/java/nl/knaw/dans/dvingest/DepositTaskFactoryImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
24 changes: 7 additions & 17 deletions src/main/java/nl/knaw/dans/dvingest/core/DepositTask.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Copyright (C) 2024 DANS - Data Archiving and Networked Services ([email protected])
*
* 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;

}

0 comments on commit 47e0469

Please sign in to comment.