Skip to content

Commit

Permalink
Add function to start a tx and create a client
Browse files Browse the repository at this point in the history
  • Loading branch information
mikejritter committed Sep 12, 2022
1 parent 6002a51 commit 837afe5
Showing 1 changed file with 20 additions and 0 deletions.
20 changes: 20 additions & 0 deletions src/main/java/org/fcrepo/client/TransactionBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
package org.fcrepo.client;

import java.io.IOException;
import java.net.URI;
import java.util.regex.Pattern;

Expand Down Expand Up @@ -36,6 +37,25 @@ public TransactionBuilder(final FcrepoClient client) {
this.client = client;
}

/**
* Execute {@link TransactionBuilder#start} and return a new {@link TransactionalFcrepoClient} using the Atomic-Id
* from the response
*
* @param uri the uri to start the transaction with
* @return a Transactional client
* @throws FcrepoOperationFailedException If the underlying HTTP request results in an error
* @throws IOException If there is an error closing the underlying HTTP response stream
*/
public TransactionalFcrepoClient startTransactionalClient(final URI uri)
throws FcrepoOperationFailedException, IOException {
try (final FcrepoResponse response = start(uri).perform()) {
return response.getTransactionUri()
.map(client::transactionalClient)
.orElseThrow(() -> new FcrepoOperationFailedException(uri, response.getStatusCode(),
"No Atomic-Id found"));
}
}

/**
* Create a RequestBuilder to start a transaction
*
Expand Down

0 comments on commit 837afe5

Please sign in to comment.