Skip to content

Commit

Permalink
Extend BodyRequestBuilder to allow for removal of addTransaction
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejritter committed Aug 24, 2022
1 parent 373e8a7 commit 916e1ff
Showing 1 changed file with 102 additions and 4 deletions.
106 changes: 102 additions & 4 deletions src/main/java/org/fcrepo/client/HistoricMementoBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,27 @@
*/
package org.fcrepo.client;

import static org.fcrepo.client.FedoraHeaderConstants.CONTENT_DISPOSITION;
import static org.fcrepo.client.FedoraHeaderConstants.SLUG;
import static org.fcrepo.client.HeaderHelpers.UTC_RFC_1123_FORMATTER;
import static org.fcrepo.client.FedoraHeaderConstants.MEMENTO_DATETIME;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.time.Instant;

import org.fcrepo.client.FcrepoResponse.TransactionURI;
import org.apache.http.client.methods.HttpRequestBase;
import org.springframework.http.ContentDisposition;

/**
* Builds a POST request for creating a memento (LDPRm) with the state given in the request body
* and the datetime given in the Memento-Datetime request header.
*
* @author bbpennel
*/
public class HistoricMementoBuilder extends PostBuilder {
public class HistoricMementoBuilder extends BodyRequestBuilder {

/**
* Instantiate builder
Expand Down Expand Up @@ -49,7 +55,99 @@ public HistoricMementoBuilder(final URI uri, final FcrepoClient client, final St
}

@Override
public HistoricMementoBuilder addTransaction(final TransactionURI transaction) {
throw new UnsupportedOperationException("Mementos are not allowed in transactions");
protected HttpRequestBase createRequest() {
return HttpMethods.POST.createRequest(targetUri);
}

@Override
public HistoricMementoBuilder body(final InputStream stream, final String contentType) {
return (HistoricMementoBuilder) super.body(stream, contentType);
}

@Override
public HistoricMementoBuilder body(final File file, final String contentType) throws IOException {
return (HistoricMementoBuilder) super.body(file, contentType);
}

@Override
public HistoricMementoBuilder body(final InputStream stream) {
return (HistoricMementoBuilder) super.body(stream);
}

@Override
public HistoricMementoBuilder externalContent(final URI contentURI,
final String contentType,
final String handling) {
return (HistoricMementoBuilder) super.externalContent(contentURI, contentType, handling);
}

@Override
public HistoricMementoBuilder digest(final String digest, final String alg) {
return (HistoricMementoBuilder) super.digest(digest, alg);
}

@Override
public HistoricMementoBuilder digestMd5(final String digest) {
return (HistoricMementoBuilder) super.digestMd5(digest);
}

@Override
public HistoricMementoBuilder digestSha1(final String digest) {
return (HistoricMementoBuilder) super.digestSha1(digest);
}

@Override
public HistoricMementoBuilder digestSha256(final String digest) {
return (HistoricMementoBuilder) super.digestSha256(digest);
}

@Override
public HistoricMementoBuilder addInteractionModel(final String interactionModelUri) {
return (HistoricMementoBuilder) super.addInteractionModel(interactionModelUri);
}

@Override
public HistoricMementoBuilder linkAcl(final String aclUri) {
return (HistoricMementoBuilder) super.linkAcl(aclUri);
}

@Override
public HistoricMementoBuilder addHeader(final String name, final String value) {
return (HistoricMementoBuilder) super.addHeader(name, value);
}

@Override
public HistoricMementoBuilder addLinkHeader(final FcrepoLink linkHeader) {
return (HistoricMementoBuilder) super.addLinkHeader(linkHeader);
}

/**
* Provide a content disposition header which will be used as the filename
*
* @param filename the name of the file being provided in the body of the request
* @return this builder
* @throws FcrepoOperationFailedException if unable to encode filename
*/
public HistoricMementoBuilder filename(final String filename) throws FcrepoOperationFailedException {
final ContentDisposition.Builder builder = ContentDisposition.builder("attachment");
if (filename != null) {
builder.filename(filename);
}
request.addHeader(CONTENT_DISPOSITION, builder.build().toString());
return this;
}

/**
* Provide a suggested name for the new child resource, which the repository may ignore.
*
* @param slug value to supply as the slug header
* @return this builder
*/
public HistoricMementoBuilder slug(final String slug) {
if (slug != null) {
request.addHeader(SLUG, slug);
}
return this;
}

}

0 comments on commit 916e1ff

Please sign in to comment.