Skip to content

Commit

Permalink
Compiles
Browse files Browse the repository at this point in the history
  • Loading branch information
janvanmansum committed Dec 11, 2024
1 parent dbb35a6 commit fe952b4
Show file tree
Hide file tree
Showing 15 changed files with 347 additions and 150 deletions.
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,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
Expand All @@ -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);
Expand Down
40 changes: 40 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,40 @@
/*
* 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.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);
}
}
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);
}
}
35 changes: 35 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,35 @@
/*
* 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;

@Override
public Runnable createInboxTask(Path path) {
var dataVerseIngestDeposit = dataverseIngestDepositFactory.createDataverseIngestDeposit(path);
return depositTaskFactory.createDepositTask(dataVerseIngestDeposit, path, false);
}
}
26 changes: 4 additions & 22 deletions src/main/java/nl/knaw/dans/dvingest/core/AutoIngestArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* 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;

import java.nio.file.Path;

public interface DataverseIngestDepositFactory {

DataverseIngestDeposit createDataverseIngestDeposit(Path location);
}
Loading

0 comments on commit fe952b4

Please sign in to comment.