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

Fix compile warnings in deposit-services #138

Merged
merged 2 commits into from
Nov 20, 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
Expand Up @@ -24,6 +24,7 @@
* @author Elliot Metsger ([email protected])
*/
public class RemedialDepositException extends DepositServiceRuntimeException {
private static final long serialVersionUID = 1L;

public RemedialDepositException(PassEntity resource) {
super(resource);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.OutputStream;
import java.util.Map;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;

/**
Expand All @@ -37,6 +38,7 @@ public interface ArchiveOutputStreamFactory {
* @param toWrap the output stream to be wrapped by the returned {@code ArchiveOutputStream}
* @return the configured {@code ArchiveOutputStream} ready for writing
*/
ArchiveOutputStream newInstance(Map<String, Object> packageOptions, OutputStream toWrap);
<O extends ArchiveOutputStream<? extends ArchiveEntry>> O newInstance(Map<String, Object> packageOptions,
OutputStream toWrap);

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.eclipse.pass.deposit.assembler.PackageOptions.Archive;
import org.eclipse.pass.deposit.model.DepositSubmission;
Expand Down Expand Up @@ -130,7 +131,7 @@ public InputStream open() {

// Wrap the output stream in an ArchiveOutputStream
// we support zip, tar and tar.gz so far
ArchiveOutputStream archiveOut = archiveOutputStreamFactory.newInstance(packageOptions, pipedOut);
ArchiveOutputStream<ArchiveEntry> archiveOut = archiveOutputStreamFactory.newInstance(packageOptions, pipedOut);

// Set on the writer, and used to report any exceptions caught by the writer to the reader. That way a full
// stack trace of the exception will be reported when it is encountered by the reader
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.concurrent.Callable;
import java.util.concurrent.atomic.AtomicBoolean;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.eclipse.pass.deposit.model.DepositSubmission;
import org.springframework.core.io.Resource;
Expand All @@ -36,7 +37,7 @@ public class CallableStreamWriter<V> implements Callable<V>, StreamWriter {

private StreamWriter delegate;

private ArchiveOutputStream archiveOut;
private ArchiveOutputStream<ArchiveEntry> archiveOut;

private List<DepositFileResource> custodialFiles;

Expand All @@ -55,7 +56,7 @@ public class CallableStreamWriter<V> implements Callable<V>, StreamWriter {
* @param custodialFiles
*/
CallableStreamWriter(StreamWriter delegate,
ArchiveOutputStream archiveOut,
ArchiveOutputStream<ArchiveEntry> archiveOut,
List<DepositFileResource> custodialFiles) {
this.delegate = delegate;
this.archiveOut = archiveOut;
Expand All @@ -73,7 +74,8 @@ public V call() throws Exception {
}

@Override
public void start(List<DepositFileResource> custodialFiles, ArchiveOutputStream archiveOut) throws IOException {
public void start(List<DepositFileResource> custodialFiles, ArchiveOutputStream<ArchiveEntry> archiveOut)
throws IOException {
if (alreadyStarted.getAndSet(true) == Boolean.FALSE) {
delegate.start(custodialFiles, archiveOut);
} else {
Expand All @@ -98,7 +100,7 @@ public void finish(DepositSubmission submission, List<PackageStream.Resource> cu
}

@Override
public void close() throws Exception {
public void close() throws IOException {
if (alreadyClosed.getAndSet(true) == Boolean.FALSE) {
delegate.close();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@
/**
* @author Elliot Metsger ([email protected])
*/
public class DebuggingArchiveOutputStream extends ArchiveOutputStream {
public class DebuggingArchiveOutputStream extends ArchiveOutputStream<ArchiveEntry> {

private ArchiveOutputStream delegate;
private ArchiveOutputStream<ArchiveEntry> delegate;

public DebuggingArchiveOutputStream(ArchiveOutputStream delegate) {
public DebuggingArchiveOutputStream(ArchiveOutputStream<ArchiveEntry> delegate) {
this.delegate = delegate;
}

Expand Down Expand Up @@ -78,21 +78,6 @@ public void write(int b) throws IOException {
delegate.write(b);
}

// @Override
// protected void count(int written) {
// delegate.count(written);
// }
//
// @Override
// protected void count(long written) {
// delegate.count(written);
// }

@Override
public int getCount() {
return delegate.getCount();
}

@Override
public long getBytesWritten() {
return delegate.getBytesWritten();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.OutputStream;
import java.util.Map;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;

/**
Expand All @@ -29,8 +30,10 @@ public DebuggingArchiveOutputStreamFactory(Map<String, Object> packageOptions) {
super(packageOptions);
}

@SuppressWarnings("unchecked")
@Override
public ArchiveOutputStream newInstance(Map<String, Object> packageOptions, OutputStream toWrap) {
return new DebuggingArchiveOutputStream(super.newInstance(packageOptions, toWrap));
public <O extends ArchiveOutputStream<? extends ArchiveEntry>> O newInstance(Map<String, Object> packageOptions,
OutputStream toWrap) {
return (O) new DebuggingArchiveOutputStream(super.newInstance(packageOptions, toWrap));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.OutputStream;
import java.util.Map;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
Expand All @@ -40,38 +41,38 @@ public DefaultArchiveOutputStreamFactory(Map<String, Object> packageOptions) {
this.packageOptions = packageOptions;
}

@SuppressWarnings("unchecked")
@Override
public ArchiveOutputStream newInstance(Map<String, Object> packageOptions, OutputStream toWrap) {
// Wrap the output stream in an ArchiveOutputStream
// we support zip, tar and tar.gz so far
ArchiveOutputStream archiveOut;
public <O extends ArchiveOutputStream<? extends ArchiveEntry>> O newInstance(Map<String, Object> packageOptions,
OutputStream toWrap) {

if (packageOptions.getOrDefault(PackageOptions.Archive.KEY, PackageOptions.Archive.OPTS.NONE) ==
PackageOptions.Archive.OPTS.TAR) {
try {
TarArchiveOutputStream tarArchiveOutputStream;
if (packageOptions.getOrDefault(PackageOptions.Compression.KEY, PackageOptions.Compression.OPTS.NONE)
== PackageOptions.Compression.OPTS.GZIP) {
archiveOut = new TarArchiveOutputStream(new GzipCompressorOutputStream(toWrap));
tarArchiveOutputStream = new TarArchiveOutputStream(new GzipCompressorOutputStream(toWrap));
} else {
archiveOut = new TarArchiveOutputStream(toWrap);
tarArchiveOutputStream = new TarArchiveOutputStream(toWrap);
}
return (O) tarArchiveOutputStream;
} catch (Exception e) {
throw new RuntimeException(String.format(ERR_CREATING_ARCHIVE_STREAM, PackageOptions.Archive.OPTS.TAR,
e.getMessage()), e);
}
} else if (packageOptions.getOrDefault(PackageOptions.Archive.KEY, PackageOptions.Archive.OPTS.NONE) ==
PackageOptions.Archive.OPTS.ZIP) {
try {
archiveOut = new ZipArchiveOutputStream(toWrap);
ZipArchiveOutputStream zipArchiveOutputStream = new ZipArchiveOutputStream(toWrap);
return (O) zipArchiveOutputStream;
} catch (Exception e) {
throw new RuntimeException(String.format(ERR_CREATING_ARCHIVE_STREAM, PackageOptions.Archive.OPTS.ZIP,
e.getMessage()), e);
}
} else {
throw new RuntimeException(ERR_NO_ARCHIVE_FORMAT);
}

return archiveOut;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public class DefaultStreamWriterImpl implements StreamWriter {
private final List<DepositFileResource> packageFiles;
private final ResourceBuilderFactory rbf;
private final DepositSubmission submission;
protected ArchiveOutputStream archiveOut;
protected ArchiveOutputStream<ArchiveEntry> archiveOut;
protected Map<String, Object> packageOptions;
protected PackageProvider packageProvider;

Expand All @@ -75,7 +75,8 @@ public DefaultStreamWriterImpl(DepositSubmission submission,
}

@Override
public void start(List<DepositFileResource> custodialFiles, ArchiveOutputStream archiveOut) throws IOException {
public void start(List<DepositFileResource> custodialFiles, ArchiveOutputStream<ArchiveEntry> archiveOut)
throws IOException {
this.archiveOut = archiveOut;
List<PackageStream.Resource> assembledResources = new ArrayList<>();

Expand Down Expand Up @@ -118,7 +119,7 @@ public void start(List<DepositFileResource> custodialFiles, ArchiveOutputStream
}

@Override
public void close() throws Exception {
public void close() throws IOException {
archiveOut.close();
}

Expand Down Expand Up @@ -215,7 +216,8 @@ protected ArchiveEntry createEntry(String name, long length) {
* @param archiveEntryIn the bytes to be written
* @throws IOException if there is an error encountered writing the bytes
*/
private void writeResource(ArchiveOutputStream archiveOut, ArchiveEntry archiveEntry, InputStream archiveEntryIn)
private void writeResource(ArchiveOutputStream<ArchiveEntry> archiveOut, ArchiveEntry archiveEntry,
InputStream archiveEntryIn)
throws IOException {
archiveOut.putArchiveEntry(archiveEntry);
int bytesWritten = IOUtils.copy(archiveEntryIn, archiveOut);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.io.IOException;
import java.util.List;

import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.eclipse.pass.deposit.model.DepositSubmission;
import org.springframework.core.io.Resource;
Expand Down Expand Up @@ -45,7 +46,8 @@ interface StreamWriter extends AutoCloseable {
* @param archiveOut the {@code OutputStream} to be written to
* @throws IOException if there are any errors encountered initializing state
*/
void start(List<DepositFileResource> custodialFiles, ArchiveOutputStream archiveOut) throws IOException;
void start(List<DepositFileResource> custodialFiles, ArchiveOutputStream<ArchiveEntry> archiveOut)
throws IOException;

/**
* Writes the {@code Resource} and returns metadata describing the {@code custodialFile}.
Expand All @@ -70,4 +72,5 @@ interface StreamWriter extends AutoCloseable {
*/
void finish(DepositSubmission submission, List<PackageStream.Resource> custodialResources) throws IOException;

void close() throws IOException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public DepositSubmission createDepositSubmission(Submission submissionEntity, Li
// Prepare for Metadata
DepositMetadata metadata = new DepositMetadata();
submission.setMetadata(metadata);
submission.setSubmissionMeta(new JsonParser().parse(submissionEntity.getMetadata()).getAsJsonObject());
submission.setSubmissionMeta(JsonParser.parseString(submissionEntity.getMetadata()).getAsJsonObject());
DepositMetadata.Manuscript manuscript = new DepositMetadata.Manuscript();
metadata.setManuscriptMetadata(manuscript);
DepositMetadata.Article article = new DepositMetadata.Article();
Expand Down Expand Up @@ -328,7 +328,7 @@ private void processPmcMetadata(DepositMetadata metadata, JsonObject submissionD
* @param metadataStr
*/
void processMetadata(DepositMetadata depositMetadata, String metadataStr) {
JsonObject json = new JsonParser().parse(metadataStr).getAsJsonObject();
JsonObject json = JsonParser.parseString(metadataStr).getAsJsonObject();
processCommonMetadata(depositMetadata, json);
processPmcMetadata(depositMetadata, json);
processCrossrefMetadata(depositMetadata, json);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.springframework.core.env.Environment;

public class SpringEnvironmentDeserializer extends StringDeserializer {
private static final long serialVersionUID = 1L;

private Environment env;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package org.eclipse.pass.deposit.transport;

import java.io.IOException;
import java.util.Map;

import org.eclipse.pass.deposit.assembler.PackageStream;
Expand Down Expand Up @@ -50,4 +51,6 @@ public interface TransportSession extends AutoCloseable {

boolean closed();

void close() throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.eclipse.pass.deposit.transport.devnull;

import java.io.IOException;
import java.net.URI;
import java.util.Map;

Expand Down Expand Up @@ -120,7 +121,7 @@ public boolean closed() {
}

@Override
public void close() throws Exception {
public void close() throws IOException {
// no-op
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ public boolean closed() {
}

@Override
public void close() throws Exception {
public void close() throws IOException {
// no-op
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public boolean closed() {
}

@Override
public void close() throws Exception {
public void close() throws IOException {
LOG.debug("Closing {}@{}...",
this.getClass().getSimpleName(), toHexString(identityHashCode(this)));
if (transfer != null && !transfer.isDone()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private FtpUtil () {
* @param clientCommand the command to perform
* @throws RuntimeException if the command throw a checked exception
*/
static void performSilently(ExceptionThrowingVoidCommand clientCommand) {
static <T> void performSilently(ExceptionThrowingVoidCommand<T> clientCommand) {
try {
clientCommand.perform();
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.eclipse.pass.deposit.transport.inveniordm;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -104,7 +105,7 @@ public boolean closed() {
}

@Override
public void close() throws Exception {
public void close() throws IOException {
// no-op resources are closed with try-with-resources
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public boolean closed() {
}

@Override
public void close() throws Exception {
public void close() throws IOException {
// no-op resources are closed with try-with-resources
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* For example, when the Collection URL is no present in the SWORD service document.
*/
class InvalidCollectionUrl extends RuntimeException {
private static final long serialVersionUID = 1L;

InvalidCollectionUrl(String message) {
super(message);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ public boolean closed() {
}

@Override
public void close() throws Exception {
public void close() throws IOException {
if (this.closed()) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Wraps a {@link SWORDError} for the purpose of providing a non-null response to {@link Throwable#getMessage()}.
*/
class SwordErrorMessageWrapper extends Exception {
private static final long serialVersionUID = 1L;

private SWORDError wrapped;

Expand Down
Loading
Loading