Skip to content

Commit

Permalink
Give TransportSession.send access to PASS model of deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
markpatton committed Dec 4, 2024
1 parent ee7134d commit 44cb16d
Show file tree
Hide file tree
Showing 15 changed files with 59 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@
*/
@Component
public class DSpaceMetadataMapper {
// Section of workspace item form to add metadata
private static final String SECTION = "traditionalpageone";

@Value("${dspace.field.embargo.lift}")
private String dspaceFieldEmbargoLift;

Expand All @@ -59,45 +62,44 @@ public String patchWorkspaceItem(DepositSubmission submission) {
String title = manuscriptMd.getTitle();

// Required by DSpace
metadata.add(add_array("traditionalpageone", "dc.title", title));
metadata.add(add_array(SECTION, "dc.title", title));

if (journalMd != null && journalMd.getPublisherName() != null) {
metadata.add(add_array("traditionalpageone", "dc.publisher", journalMd.getPublisherName()));
metadata.add(add_array(SECTION, "dc.publisher", journalMd.getPublisherName()));
}

if (articleMd.getDoi() != null) {
metadata.add(add_array("traditionalpageone", "dc.identifier.doi", articleMd.getDoi().toString()));
metadata.add(add_array(SECTION, "dc.identifier.doi", articleMd.getDoi().toString()));
}

if (manuscriptMd.getMsAbstract() != null) {
metadata.add(add_array("traditionalpageone", "dc.description.abstract", manuscriptMd.getMsAbstract()));
metadata.add(add_array(SECTION, "dc.description.abstract", manuscriptMd.getMsAbstract()));
}

String citation = createCitation(submission);

if (!citation.isEmpty()) {
metadata.add(add_array("traditionalpageone", "dc.identifier.citation", citation));
metadata.add(add_array(SECTION, "dc.identifier.citation", citation));
}

// Required by DSpace as ISO 8601 local date
metadata.add(add_array("traditionalpageone", "dc.date.issued", journalMd.getPublicationDate().
metadata.add(add_array(SECTION, "dc.date.issued", journalMd.getPublicationDate().
format(DateTimeFormatter.ISO_LOCAL_DATE)));

// Add non-submitters as authors
// TODO This is different from before
String[] authors = depositMd.getPersons().stream().filter(
p -> p.getType() != DepositMetadata.PERSON_TYPE.submitter).
map(Person::getName).toArray(String[]::new);

metadata.add(add_array("traditionalpageone", "dc.contributor.author", authors));
metadata.add(add_array(SECTION, "dc.contributor.author", authors));

ZonedDateTime embargoLiftDate = articleMd.getEmbargoLiftDate();

if (embargoLiftDate != null) {
String liftDate = embargoLiftDate.format(DateTimeFormatter.ISO_LOCAL_DATE);

metadata.add(add_array("traditionalpageone", dspaceFieldEmbargoLift, liftDate));
metadata.add(add_array("traditionalpageone", dspaceFieldEmbargoTerms, liftDate));
metadata.add(add_array(SECTION, dspaceFieldEmbargoLift, liftDate));
metadata.add(add_array(SECTION, dspaceFieldEmbargoTerms, liftDate));
}

// Required by DSpace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,7 @@ static Function<Deposit, TransportResponse> performDeposit(DepositWorkerContext

Transport transport = getTransport(packager, dc);
try (TransportSession transportSession = transport.open(packagerConfig)) {
TransportResponse tr = transportSession.send(packageStream, packagerConfig);
TransportResponse tr = transportSession.send(packageStream, packagerConfig, dc);
deposit.setDepositStatus(DepositStatus.SUBMITTED);
deposit.setDepositStatusRef(packageStream.metadata().packageDepositStatusRef());
return tr;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* Abstracts the transport protocol used to deposit a package with a target submission system. Callers are able to
* {@link #open(Map) open} a {@link TransportSession} by supplying configuration hints, which allows the implementation
* to perform necessary connection initialization, prior to a package being transported using
* {@link TransportSession#send(PackageStream, Map)}.
* {@link TransportSession#send(PackageStream, Map, DepositWorkerContext)}.
*/
public interface Transport {

Expand Down Expand Up @@ -68,36 +68,36 @@ public interface Transport {

/**
* Property key identifying the base64 encoded checksum of the {@code InputStream} being deposited by {@link
* TransportSession#send(PackageStream, Map)}. <em>N.B.</em>: The preferred form of obtaining the checksum of the
* {@code InputStream} would be {@link PackageStream.Metadata#checksums()}.
* TransportSession#send(PackageStream, Map, DepositWorkerContext)}. <em>N.B.</em>: The preferred form of obtaining
* the checksum of the {@code InputStream} would be {@link PackageStream.Metadata#checksums()}.
*/
String TRANSPORT_CHECKSUM_SHA256 = "deposit.transport.checksum.sha256";

/**
* Property key identifying the base64 encoded checksum of the {@code InputStream} being deposited by {@link
* TransportSession#send(PackageStream, Map)}. <em>N.B.</em>: The preferred form of obtaining the checksum of the
* {@code InputStream} would be {@link PackageStream.Metadata#checksums()}.
* TransportSession#send(PackageStream, Map, DepositWorkerContext)}. <em>N.B.</em>: The preferred form of obtaining
* the checksum of the {@code InputStream} would be {@link PackageStream.Metadata#checksums()}.
*/
String TRANSPORT_CHECKSUM_SHA512 = "deposit.transport.checksum.sha512";

/**
* Property key identifying the base64 encoded checksum of the {@code InputStream} being deposited by {@link
* TransportSession#send(PackageStream, Map)}. <em>N.B.</em>: The preferred form of obtaining the checksum of the
* {@code InputStream} would be {@link PackageStream.Metadata#checksums()}.
* TransportSession#send(PackageStream, Map, DepositWorkerContext)}. <em>N.B.</em>: The preferred form of obtaining
* the checksum of the {@code InputStream} would be {@link PackageStream.Metadata#checksums()}.
*/
String TRANSPORT_CHECKSUM_MD5 = "deposit.transport.checksum.md5";

/**
* Property key identifying the mime type of the {@code InputStream} being deposited by
* {@link TransportSession#send(PackageStream, Map)}. <em>N.B.</em>: The preferred form of obtaining the name of
* {@link TransportSession#send(PackageStream, Map, DepositWorkerContext)}. <em>N.B.</em>: The preferred form of obtaining the name of
* the {@code InputStream} would be {@link PackageStream.Metadata#name()}.
*/
String TRANSPORT_MIME_TYPE = "deposit.transport.mime-type";

/**
* Property key identifying the packaging spec of the {@code InputStream} being deposited by {@link
* TransportSession#send(PackageStream, Map)}. <em>N.B.</em>: The preferred form of obtaining the packaging
* specification of the {@code InputStream} would be {@link PackageStream.Metadata#spec()}.
* TransportSession#send(PackageStream, Map, DepositWorkerContext)}. <em>N.B.</em>: The preferred form
* of obtaining the packaging specification of the {@code InputStream} would be {@link PackageStream.Metadata#spec()}.
*/
String TRANSPORT_PACKAGE_SPEC = "deposit.transport.package-spec";

Expand Down Expand Up @@ -144,7 +144,7 @@ enum PROTOCOL {
/**
* Open a {@link TransportSession} with the underlying transport. The returned {@code TransportSession} should be
* ready to use by the caller, without the caller having to perform any further setup (the implementation of this
* method should perform all necessary actions to allow {@link TransportSession#send(PackageStream, Map)} to
* method should perform all necessary actions to allow {@link TransportSession#send(PackageStream, Map, DepositWorkerContext)} to
* succeed). The supplied {@code hints} may be used by the implementation to configure and open the session. Well
* known properties include those documented in {@link Transport}, and individual implementations may document
* properties as well.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.Map;

import org.eclipse.pass.deposit.assembler.PackageStream;
import org.eclipse.pass.deposit.service.DepositUtil.DepositWorkerContext;

/**
* Represents an open connection, or the promise of a successful connection, with a service or system that will accept
Expand All @@ -33,7 +34,6 @@
* </p>
*/
public interface TransportSession extends AutoCloseable {

/**
* Transfer the bytes of the supplied package to the remote system. Metadata can be optionally supplied which may
* help the underlying transport correctly configure itself for the transfer.
Expand All @@ -45,12 +45,14 @@ public interface TransportSession extends AutoCloseable {
*
* @param packageStream the package and package metadata
* @param metadata transport-related metadata, or any "extra" package metadata
* @param dc information about PASS objects
* @return a response indicating success or failure of the transfer
*/
TransportResponse send(PackageStream packageStream, Map<String, String> metadata);
TransportResponse send(PackageStream packageStream, Map<String, String> metadata, DepositWorkerContext dc);

boolean closed();

@Override
void close() throws IOException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.eclipse.pass.deposit.cri.CriticalRepositoryInteraction;
import org.eclipse.pass.deposit.cri.CriticalRepositoryInteraction.CriticalResult;
import org.eclipse.pass.deposit.service.DepositUtil;
import org.eclipse.pass.deposit.service.DepositUtil.DepositWorkerContext;
import org.eclipse.pass.deposit.transport.Transport;
import org.eclipse.pass.deposit.transport.TransportResponse;
import org.eclipse.pass.deposit.transport.TransportSession;
Expand Down Expand Up @@ -66,7 +67,8 @@ public TransportSession open(Map<String, String> hints) {
class DevNullTransportSession implements TransportSession {

@Override
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata) {
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata,
DepositWorkerContext dc) {
// no-op, just return successful response
return new TransportResponse() {
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@
import org.eclipse.pass.deposit.assembler.PackageStream;
import org.eclipse.pass.deposit.model.DepositSubmission;
import org.eclipse.pass.deposit.provider.dspace.DSpaceMetadataMapper;
import org.eclipse.pass.deposit.service.DepositUtil.DepositWorkerContext;
import org.eclipse.pass.deposit.support.dspace.DspaceDepositService;
import org.eclipse.pass.deposit.support.dspace.DspaceDepositService.AuthContext;
import org.eclipse.pass.deposit.transport.TransportResponse;
import org.eclipse.pass.deposit.transport.TransportSession;
import org.eclipse.pass.support.client.PassClient;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand All @@ -38,14 +40,17 @@ class DSpaceSession implements TransportSession {

private final DspaceDepositService dspaceDepositService;
private final DSpaceMetadataMapper dspaceMetadataMapper;
private final PassClient passClient;

public DSpaceSession(DspaceDepositService dspaceDepositService, DSpaceMetadataMapper dspaceMetadataMapper) {
public DSpaceSession(DspaceDepositService dspaceDepositService, DSpaceMetadataMapper dspaceMetadataMapper,
PassClient passClient) {
this.dspaceDepositService = dspaceDepositService;
this.dspaceMetadataMapper = dspaceMetadataMapper;
this.passClient = passClient;
}

@Override
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata) {
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata, DepositWorkerContext dc) {
try {
DepositSubmission depositSubmission = packageStream.getDepositSubmission();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.eclipse.pass.deposit.support.dspace.DspaceDepositService;
import org.eclipse.pass.deposit.transport.Transport;
import org.eclipse.pass.deposit.transport.TransportSession;
import org.eclipse.pass.support.client.PassClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

Expand All @@ -32,13 +33,16 @@ public class DSpaceTransport implements Transport {
@Autowired
private DSpaceMetadataMapper dspaceMetadataMapper;

@Autowired
private PassClient passClient;

@Override
public PROTOCOL protocol() {
return PROTOCOL.DSpace;
}

@Override
public TransportSession open(Map<String, String> hints) {
return new DSpaceSession(dspaceDepositService, dspaceMetadataMapper);
return new DSpaceSession(dspaceDepositService, dspaceMetadataMapper, passClient);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.eclipse.pass.deposit.cri.CriticalRepositoryInteraction;
import org.eclipse.pass.deposit.cri.CriticalRepositoryInteraction.CriticalResult;
import org.eclipse.pass.deposit.service.DepositUtil;
import org.eclipse.pass.deposit.service.DepositUtil.DepositWorkerContext;
import org.eclipse.pass.deposit.transport.Transport;
import org.eclipse.pass.deposit.transport.TransportResponse;
import org.eclipse.pass.deposit.transport.TransportSession;
Expand Down Expand Up @@ -109,7 +110,8 @@ public TransportSession open(Map<String, String> hints) {
class FilesystemTransportSession implements TransportSession {

@Override
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata) {
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata,
DepositWorkerContext dc) {
String filename = packageStream.metadata().name();
AtomicReference<Exception> transportException = new AtomicReference<>();

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

import org.apache.commons.net.ftp.FTPClient;
import org.eclipse.pass.deposit.assembler.PackageStream;
import org.eclipse.pass.deposit.service.DepositUtil.DepositWorkerContext;
import org.eclipse.pass.deposit.transport.TransportResponse;
import org.eclipse.pass.deposit.transport.TransportSession;
import org.slf4j.Logger;
Expand Down Expand Up @@ -85,7 +86,7 @@ private FtpTransportSession(FTPClient ftpClient, ExecutorService executorService
}

@Override
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata) {
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata, DepositWorkerContext dc) {

PackageStream.Metadata streamMetadata = packageStream.metadata();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.eclipse.pass.deposit.assembler.PackageStream;
import org.eclipse.pass.deposit.model.DepositSubmission;
import org.eclipse.pass.deposit.provider.inveniordm.InvenioRdmMetadataMapper;
import org.eclipse.pass.deposit.service.DepositUtil.DepositWorkerContext;
import org.eclipse.pass.deposit.transport.TransportResponse;
import org.eclipse.pass.deposit.transport.TransportSession;
import org.slf4j.Logger;
Expand Down Expand Up @@ -81,7 +82,7 @@ class InvenioRdmSession implements TransportSession {
}

@Override
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata) {
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata, DepositWorkerContext dc) {
try {
DepositSubmission depositSubmission = packageStream.getDepositSubmission();
LOG.warn("Processing InvenioRDM Deposit for Submission: {}", depositSubmission.getId());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import org.apache.sshd.sftp.common.SftpException;
import org.eclipse.pass.deposit.DepositServiceRuntimeException;
import org.eclipse.pass.deposit.assembler.PackageStream;
import org.eclipse.pass.deposit.service.DepositUtil.DepositWorkerContext;
import org.eclipse.pass.deposit.transport.TransportResponse;
import org.eclipse.pass.deposit.transport.TransportSession;

Expand All @@ -57,7 +58,7 @@ class SftpTransportSession implements TransportSession {
}

@Override
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata) {
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata, DepositWorkerContext dc) {
PackageStream.Metadata streamMetadata = packageStream.metadata();
String fileName = streamMetadata.name();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
* <dd>A URL to the SWORD version 2 service document</dd>
* <dt>{@link Sword2TransportHints#SWORD_COLLECTION_URL}</dt>
* <dd>A URL to the SWORD version 2 collection that packages will be deposited to upon
* {@link Sword2TransportSession#send(PackageStream, Map) send}</dd>
* {@link Sword2TransportSession#send(PackageStream, Map, DepositWorkerContext) send}</dd>
* <dt><em>Optional:</em> {@link Sword2TransportHints#SWORD_ON_BEHALF_OF_USER}</dt>
* <dd>The username this session is being opened for</dd>
* <dt><em>Optional:</em> {@link Sword2TransportHints#SWORD_CLIENT_USER_AGENT}</dt>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.google.gson.JsonElement;
import org.eclipse.pass.deposit.assembler.PackageOptions.Checksum;
import org.eclipse.pass.deposit.assembler.PackageStream;
import org.eclipse.pass.deposit.service.DepositUtil.DepositWorkerContext;
import org.eclipse.pass.deposit.transport.TransportResponse;
import org.eclipse.pass.deposit.transport.TransportSession;
import org.slf4j.Logger;
Expand Down Expand Up @@ -104,14 +105,15 @@ public Sword2TransportSession(SWORDClient client, ServiceDocument serviceDocumen
*
* @param packageStream {@inheritDoc}
* @param metadata {@inheritDoc}
* @param dc {@inheritDoc}
* @return {@inheritDoc}
* @throws IllegalStateException if this session has been {@link #close() closed}
* @see
* <a href="http://swordapp.github.io/SWORDv2-Profile/SWORDProfile.html#protocoloperations_creatingresource_binary">
* SWORD v2 Profile</a>
*/
@Override
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata) {
public TransportResponse send(PackageStream packageStream, Map<String, String> metadata, DepositWorkerContext dc) {
if (closed) {
throw new IllegalStateException("SWORDv2 transport session has been closed.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private static Deposit depositContext(DepositUtil.DepositWorkerContext depositCo
when(stream.metadata()).thenReturn(metadata);
when(packager.getTransport()).thenReturn(transport);
when(transport.open(anyMap())).thenReturn(session);
when(session.send(eq(stream), any())).thenReturn(tr);
when(session.send(eq(stream), any(), any())).thenReturn(tr);

when(depositContext.packager()).thenReturn(packager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public void testCreateFile() {
TransportSession transportSession = sftpTransport.open(hints);

// WHEN
TransportResponse transportResponse = transportSession.send(stream, new HashMap<>());
TransportResponse transportResponse = transportSession.send(stream, new HashMap<>(), null);

// THEN
assertTrue(transportResponse.success());
Expand Down Expand Up @@ -131,7 +131,7 @@ public void testCreateFile_Fail_MissingBaseDir() {

// WHEN
DepositServiceRuntimeException ex = assertThrows(DepositServiceRuntimeException.class, () -> {
transportSession.send(stream, new HashMap<>());
transportSession.send(stream, new HashMap<>(), null);
});

// THEN
Expand Down

0 comments on commit 44cb16d

Please sign in to comment.