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

Transaction Support #67

Merged
merged 38 commits into from Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
a9d558a
Add startTransaction for creating transactions
mikejritter Mar 11, 2022
e0bf3ce
Add transaction header constants
mikejritter Mar 11, 2022
bc9e596
Add method to retrieve transaction uri
mikejritter Mar 11, 2022
a3d2c0e
Add method to add Atomic-Id header for transactions
mikejritter Mar 11, 2022
fb686ac
Use transaction endpoint constant
mikejritter Jun 7, 2022
6a615d8
Override addTransaction for all builders
mikejritter Jun 7, 2022
7b5d998
Initial TransactionBuilder idea
mikejritter Jun 8, 2022
2ba7721
Checkstyle updates
mikejritter Jun 9, 2022
bf4ef02
Create RequestBuilders per transaction endpoint
mikejritter Jun 9, 2022
4ab4583
Move start and TRANSACTION_ENDPOINT to TransactionBuilder
mikejritter Jun 9, 2022
26e68a3
Add uri validation methods
mikejritter Jun 13, 2022
e708c1e
Add simple tests for tx uri validation
mikejritter Jun 13, 2022
cb41eca
Split start valid into separate tests
mikejritter Jul 1, 2022
d5225d0
Use regex from fcrepo for validation help on tx ids
mikejritter Jul 12, 2022
3ab69aa
Create TransactionURI for more strict api definitions
mikejritter Jul 13, 2022
d757231
Update ATOMIC_ID constant
mikejritter Jul 28, 2022
798b055
Try to retrieve the Atomic-ID from a response when getting the transa…
mikejritter Jul 28, 2022
4f1c652
Add TransactionalFcrepoClient for automatically adding Atomic-IDs to …
mikejritter Jul 28, 2022
d1fe986
Add builder option for a TransactionFcrepoClient
mikejritter Jul 28, 2022
441ef5c
Create a container to test the transactional client
mikejritter Jul 28, 2022
bb007a2
Use DateTimeFormatter when checking all Atomic-Expires headers
mikejritter Aug 2, 2022
373e8a7
Add a method for creating transaction clients from a fcrepo client
mikejritter Aug 23, 2022
916e1ff
Extend BodyRequestBuilder to allow for removal of addTransaction
mikejritter Aug 24, 2022
6002a51
Make addTransaction protected to hide it in unused builders
mikejritter Sep 7, 2022
837afe5
Add function to start a tx and create a client
mikejritter Sep 12, 2022
87d40ec
Test for startTransactionalClient
mikejritter Sep 12, 2022
9f49e6e
Drop Optional from getTransactionUri
mikejritter Sep 27, 2022
913a529
Add transaction helpers to client
mikejritter Oct 5, 2022
e8daf3f
Move startTransactionClient to FcrepoClient
mikejritter Oct 28, 2022
e06e813
Update tests to be only through TransactionalFcrepoClient
mikejritter Oct 28, 2022
c68bbd6
Create RequestBuilders for tx endpoints in TransactionalFcrepoClient
mikejritter Oct 28, 2022
b97e05d
Update import for TRANSACTION_ENDPOINT
mikejritter Oct 28, 2022
42ad827
Remove unused classes
mikejritter Oct 28, 2022
6e0230b
Shorten transaction methods
mikejritter Nov 1, 2022
44b64b4
Keep functionality for base or transaction endpoints
mikejritter Nov 1, 2022
a786b92
Add test creating a client using the full transaction endpoint
mikejritter Nov 1, 2022
975192d
Drop need for TransactionURI
mikejritter Nov 1, 2022
1eb0043
Use Get/Post/etc builders for the transaction api
mikejritter Nov 2, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/main/java/org/fcrepo/client/FcrepoClient.java
Expand Up @@ -51,6 +51,8 @@ public class FcrepoClient implements Closeable {

private Boolean throwExceptionOnFailure = true;

private static final String TRANSACTION_ENDPOINT = "fcr:tx";

private static final Logger LOGGER = getLogger(FcrepoClient.class);

/**
Expand Down Expand Up @@ -152,6 +154,17 @@ public HistoricMementoBuilder createMemento(final URI url, final String mementoD
return new HistoricMementoBuilder(url, this, mementoDatetime);
}

/**
* Make a POST request to create a new Transaction
*
* @param url the base url of the Fedora repository
* @return ???
*/
public PostBuilder startTransaction(final URI url) {
bbpennel marked this conversation as resolved.
Show resolved Hide resolved
final var txUrl = url.resolve(TRANSACTION_ENDPOINT);
return post(txUrl);
}

/**
* Make a DELETE request to delete a resource
*
Expand Down
16 changes: 16 additions & 0 deletions src/main/java/org/fcrepo/client/FcrepoResponse.java
Expand Up @@ -56,6 +56,8 @@ public class FcrepoResponse implements Closeable {

private InputStream body;

private String transactionUri;

private String contentType;

private boolean closed = false;
Expand Down Expand Up @@ -313,4 +315,18 @@ public Map<String, String> getContentDisposition() {
}
return contentDisposition;
}

/**
* Get the transaction location. If the location is not for a transaction, return null.
*
* @return the transaction location or null
*/
public String getTransactionUri() {
if (transactionUri == null && headers.containsKey(LOCATION)) {
final var location = getHeaderValue(LOCATION);
transactionUri = location.contains("fcr:tx") ? location : null;
bbpennel marked this conversation as resolved.
Show resolved Hide resolved
}

return transactionUri;
}
}
4 changes: 4 additions & 0 deletions src/main/java/org/fcrepo/client/FedoraHeaderConstants.java
Expand Up @@ -67,6 +67,10 @@ public class FedoraHeaderConstants {

public static final String ACCEPT_DATETIME = "Accept-Datetime";

public static final String ATOMIC_ID = "Atomic-Id";

public static final String ATOMIC_EXPIRES = "Atomic-Expires";

private FedoraHeaderConstants() {
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/fcrepo/client/HistoricMementoBuilder.java
Expand Up @@ -45,4 +45,9 @@ public HistoricMementoBuilder(final URI uri, final FcrepoClient client, final St
UTC_RFC_1123_FORMATTER.parse(mementoDatetime);
request.setHeader(MEMENTO_DATETIME, mementoDatetime);
}

@Override
public RequestBuilder addTransaction(final String transaction) {
bbpennel marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalStateException("Mementos are not allowed in transactions");
bbpennel marked this conversation as resolved.
Show resolved Hide resolved
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/fcrepo/client/OriginalMementoBuilder.java
Expand Up @@ -40,4 +40,9 @@ public OriginalMementoBuilder addHeader(final String name, final String value) {
public OriginalMementoBuilder addLinkHeader(final FcrepoLink linkHeader) {
return (OriginalMementoBuilder) super.addLinkHeader(linkHeader);
}

@Override
public RequestBuilder addTransaction(final String transaction) {
bbpennel marked this conversation as resolved.
Show resolved Hide resolved
throw new IllegalStateException("Mementos are not allowed in transactions");
}
}
12 changes: 12 additions & 0 deletions src/main/java/org/fcrepo/client/RequestBuilder.java
Expand Up @@ -5,6 +5,7 @@
*/
package org.fcrepo.client;

import static org.fcrepo.client.FedoraHeaderConstants.ATOMIC_ID;
import static org.slf4j.LoggerFactory.getLogger;
import static org.fcrepo.client.FedoraHeaderConstants.LINK;

Expand Down Expand Up @@ -89,4 +90,15 @@ protected RequestBuilder addLinkHeader(final FcrepoLink linkHeader) {
request.addHeader(LINK, linkHeader.toString());
return this;
}

/**
* Add a transaction atomic id header to the request
*
* @param transaction transaction atomic id
* @return this builder
*/
public RequestBuilder addTransaction(final String transaction) {
bbpennel marked this conversation as resolved.
Show resolved Hide resolved
request.addHeader(ATOMIC_ID, transaction);
return this;
}
}