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

WIP #1

Merged
merged 6 commits into from
Nov 12, 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
File renamed without changes.
Empty file added docs/description.md
Empty file.
Empty file added docs/dev.md
Empty file.
Empty file added docs/install.md
Empty file.
10 changes: 8 additions & 2 deletions mkdocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ repo_name: DANS-KNAW/dd-dataverse-ingest-cli
repo_url: https://github.com/DANS-KNAW/dd-dataverse-ingest-cli

nav:
- Manual: index.md

- Manual:
- Introduction: index.md
- Description: description.md
# - Examples: examples.md
- Installation: install.md
- Development:
- Overview: dev.md
- Context: arch.md
plugins:
- markdownextradata
- search
Expand Down
57 changes: 50 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
limitations under the License.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
Expand All @@ -27,9 +26,9 @@
</parent>

<artifactId>dd-dataverse-ingest-cli</artifactId>
<version>0.1.0-SNAPSHOT</version>
<version>0.1.1-SNAPSHOT</version>

<name>Dd Dataverse Ingest Cli</name>
<name>DD Dataverse Ingest CLI</name>
<url>https://github.com/DANS-KNAW/dd-dataverse-ingest-cli</url>
<description>CLI for dd-dataverse-ingest</description>
<inceptionYear>2024</inceptionYear>
Expand All @@ -38,6 +37,7 @@
<main-class>nl.knaw.dans.dvingestcli.DdDataverseIngestCli</main-class>
<picocli.version>4.7.5</picocli.version> <!-- TODO: move to parent -->
<command-name>ingest</command-name>
<dd-dataverse-ingest-api.version>0.1.0-SNAPSHOT</dd-dataverse-ingest-api.version>
</properties>

<scm>
Expand Down Expand Up @@ -79,8 +79,6 @@
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
</dependency>
<!-- Only required if this CLI connects to a OpenAPI generated service -->
<!--
<dependency>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
Expand All @@ -106,7 +104,6 @@
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
-->
</dependencies>

<repositories>
Expand Down Expand Up @@ -185,6 +182,52 @@
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>nl.knaw.dans</groupId>
<artifactId>dd-dataverse-ingest-api</artifactId>
<version>${dd-dataverse-ingest-api.version}</version>
<outputDirectory>${project.build.directory}/openapi</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-dd-dataverse-ingest-client</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.build.directory}/openapi/dd-dataverse-ingest-api.yml</inputSpec>
<generatorName>java</generatorName>
<configOptions>
<apiPackage>nl.knaw.dans.dvingest.client</apiPackage>
<modelPackage>nl.knaw.dans.dvingest.api</modelPackage>
<invokerPackage>nl.knaw.dans.dvingest.client</invokerPackage>
<annotationLibrary>none</annotationLibrary>
<library>jersey2</library>
<openApiNullable>false</openApiNullable>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

Expand Down
7 changes: 7 additions & 0 deletions src/main/assembly/dist/cfg/example-config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
dataverseIngest:
url: "http://localhost:20360"
httpClient:
connectTimeout: 15s
readTimeout: 60s


#
# See https://www.dropwizard.io/en/latest/manual/configuration.html#logging
#
Expand Down
20 changes: 16 additions & 4 deletions src/main/java/nl/knaw/dans/dvingestcli/DdDataverseIngestCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@

package nl.knaw.dans.dvingestcli;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.extern.slf4j.Slf4j;
import nl.knaw.dans.dvingest.client.ApiClient;
import nl.knaw.dans.dvingest.client.DefaultApi;
import nl.knaw.dans.dvingestcli.command.GetImportStatus;
import nl.knaw.dans.dvingestcli.command.StartImport;
import nl.knaw.dans.dvingestcli.config.DdDataverseIngestCliConfig;
import nl.knaw.dans.lib.util.AbstractCommandLineApp;
import nl.knaw.dans.lib.util.ClientProxyBuilder;
import nl.knaw.dans.lib.util.PicocliVersionProvider;
import nl.knaw.dans.dvingestcli.config.DdDataverseIngestCliConfig;
import picocli.AutoComplete.GenerateCompletion;
import picocli.CommandLine;
import picocli.CommandLine.Command;

Expand All @@ -40,8 +45,15 @@ public String getName() {

@Override
public void configureCommandLine(CommandLine commandLine, DdDataverseIngestCliConfig config) {
// TODO: set up the API client, if applicable
var objectMapper = new ObjectMapper();
DefaultApi api = new ClientProxyBuilder<ApiClient, DefaultApi>()
.apiClient(new ApiClient())
.defaultApiCtor(DefaultApi::new)
.httpClient(config.getDataverseIngest().getHttpClient())
.basePath(config.getDataverseIngest().getUrl()).build();

log.debug("Configuring command line");
// TODO: add options and subcommands
commandLine.addSubcommand(new StartImport(api, objectMapper));
commandLine.addSubcommand(new GetImportStatus(api, objectMapper));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
/*
* 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.dvingestcli.command;

import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import nl.knaw.dans.dvingest.client.DefaultApi;
import picocli.CommandLine.Command;
import picocli.CommandLine.Parameters;

import java.util.concurrent.Callable;

@RequiredArgsConstructor
@Command(name = "get-import-status")
public class GetImportStatus implements Callable<Integer> {
@NonNull
private final DefaultApi api;

@NonNull
private final ObjectMapper objectMapper;

@Parameters(index = "0", paramLabel = "location", description = "The path to the import batch", arity = "0..1")
private String location;

@Override
public Integer call() {
try {
var status = api.ingestGet(location);
System.out.println(objectMapper.writeValueAsString(status));
System.err.println("Import status retrieved: " + location);
}
catch (Exception e) {
System.err.println("Error getting import status: " + e.getMessage());
e.printStackTrace();
return 1;
}
return 0;
}

}
72 changes: 72 additions & 0 deletions src/main/java/nl/knaw/dans/dvingestcli/command/StartImport.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* 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.dvingestcli.command;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import nl.knaw.dans.dvingest.api.ImportCommandDto;
import nl.knaw.dans.dvingest.client.ApiException;
import nl.knaw.dans.dvingest.client.DefaultApi;
import picocli.CommandLine.Command;
import picocli.CommandLine.Option;
import picocli.CommandLine.Parameters;

import java.io.IOException;
import java.nio.file.Path;
import java.util.concurrent.Callable;

@Command(name = "start-import",
mixinStandardHelpOptions = true,
description = "Start an import job")
@RequiredArgsConstructor
public class StartImport implements Callable<Integer> {
@NonNull
private final DefaultApi api;

@NonNull
private final ObjectMapper objectMapper;

@Parameters(index = "0", paramLabel = "path", description = "The path to the file to import")
private Path path;

@Option(names = { "-s", "--single-object" }, description = "Import as single object")
private boolean singleObject;

@Override
public Integer call() {
try {
var canonicalPath = path.toRealPath().toString();
var status = api.ingestPost(
new ImportCommandDto()
.path(canonicalPath)
.singleObject(singleObject));
System.out.println(objectMapper.writeValueAsString(status));
System.err.println("Import started: " + canonicalPath);
}
catch (JsonProcessingException e) {
System.err.println("Status report could not be parsed: " + e.getMessage());
return 1;
}
catch (ApiException | IOException e) {
System.err.println("Error starting import: " + e.getMessage());
e.printStackTrace();
return 1;
}
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* 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.dvingestcli.config;

import io.dropwizard.client.JerseyClientConfiguration;
import lombok.Data;

import javax.validation.constraints.NotNull;
import java.net.URI;

@Data
public class DataverseIngestConfig {
@NotNull
private URI url;

@NotNull
private JerseyClientConfiguration httpClient;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
package nl.knaw.dans.dvingestcli.config;

import io.dropwizard.core.Configuration;
import lombok.Data;
import lombok.EqualsAndHashCode;

@Data
@EqualsAndHashCode(callSuper = true)
public class DdDataverseIngestCliConfig extends Configuration {
// TODO: add configuration fields
private DataverseIngestConfig dataverseIngest;
}
Loading