Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiles #7

Merged
merged 5 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
@@ -0,0 +1,27 @@
/*
* 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 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* 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 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -77,42 +80,47 @@ 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);
var bagProcessorFactory = new BagProcessorFactoryImpl(dataverseService, utilityServices);

/*
* 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(bagProcessorFactory, dansDepositSupportFactoryImport);
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(bagProcessorFactory, dansDepositSupportFactoryMigration);
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, autoIngestConfig.getOutbox());
var inbox = Inbox.builder().inbox(autoIngestConfig.getInbox()).taskFactory(inboxTaskFactory).build();
var autoIngestArea = new AutoIngestArea(inbox, autoIngestConfig.getOutbox());

/*
* Register components with Dropwizard
Expand All @@ -124,10 +132,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);
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/nl/knaw/dans/dvingest/DepositTaskFactoryImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 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.bagprocessor.BagProcessorFactory;
import nl.knaw.dans.dvingest.core.dansbag.DansDepositSupportFactory;

import java.nio.file.Path;

@AllArgsConstructor
public class DepositTaskFactoryImpl implements DepositTaskFactory {
private final BagProcessorFactory bagProcessorFactory;
private final DansDepositSupportFactory dansDepositSupportFactory;

@Override
public Runnable createDepositTask(DataverseIngestDeposit deposit, Path outputDir, boolean onlyConvertDansDeposit) {
return new DepositTask(deposit, outputDir, onlyConvertDansDeposit, bagProcessorFactory, dansDepositSupportFactory);
}
}
39 changes: 39 additions & 0 deletions src/main/java/nl/knaw/dans/dvingest/ImportJobFactoryImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* 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 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);
}
}
36 changes: 36 additions & 0 deletions src/main/java/nl/knaw/dans/dvingest/InboxTaskFactoryImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 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;
private final Path outputDir;

@Override
public Runnable createInboxTask(Path path) {
var dataVerseIngestDeposit = dataverseIngestDepositFactory.createDataverseIngestDeposit(path);
return depositTaskFactory.createDepositTask(dataVerseIngestDeposit, outputDir, false);
}
}
Loading
Loading