001/* 002 * The contents of this file are subject to the license and copyright 003 * detailed in the LICENSE and NOTICE files at the root of the source 004 * tree. 005 */ 006package org.fcrepo.client; 007 008import java.net.URI; 009 010/** 011 * A Transaction aware client which adds the Atomic_ID header to requests and provides functionality for interacting 012 * with the Fedora Transaction API 013 * 014 * @author mikejritter 015 */ 016public class TransactionalFcrepoClient extends FcrepoClient { 017 018 private final URI transactionURI; 019 020 /** 021 * @param transactionURI the transaction to append to all requests 022 * @param httpClientBuilder the httpclient 023 * @param throwExceptionOnFailure whether to throw an exception on any non-2xx or 3xx HTTP responses 024 */ 025 public TransactionalFcrepoClient(final URI transactionURI, 026 final FcrepoHttpClientBuilder httpClientBuilder, 027 final Boolean throwExceptionOnFailure) { 028 super(httpClientBuilder, throwExceptionOnFailure); 029 030 if (transactionURI == null) { 031 throw new IllegalArgumentException("TransactionURI cannot be null"); 032 } 033 this.transactionURI = transactionURI; 034 } 035 036 public URI getTransactionURI() { 037 return transactionURI; 038 } 039 040 /** 041 * Commit a transaction by performing a PUT 042 * 043 * @return the commit RequestBuilder 044 */ 045 public PutBuilder commit() { 046 return put(transactionURI); 047 } 048 049 /** 050 * Retrieve the status of a transaction by performing a GET 051 * 052 * @return the status RequestBuilder 053 */ 054 public GetBuilder status() { 055 return get(transactionURI); 056 } 057 058 /** 059 * Keep a transaction alive by performing a POST 060 * 061 * @return the keep alive RequestBuilder 062 */ 063 public PostBuilder keepAlive() { 064 return post(transactionURI); 065 } 066 067 /** 068 * Rollback a transaction by performing a DELETE 069 * 070 * @return the rollback RequestBuilder 071 */ 072 public DeleteBuilder rollback() { 073 return delete(transactionURI); 074 } 075 076 @Override 077 public GetBuilder get(final URI url) { 078 final var builder = super.get(url); 079 builder.addTransaction(transactionURI); 080 return builder; 081 } 082 083 @Override 084 public HeadBuilder head(final URI url) { 085 final var builder = super.head(url); 086 builder.addTransaction(transactionURI); 087 return builder; 088 } 089 090 @Override 091 public DeleteBuilder delete(final URI url) { 092 final var builder = super.delete(url); 093 builder.addTransaction(transactionURI); 094 return builder; 095 } 096 097 @Override 098 public OptionsBuilder options(final URI url) { 099 final var builder = super.options(url); 100 builder.addTransaction(transactionURI); 101 return builder; 102 } 103 104 @Override 105 public PatchBuilder patch(final URI url) { 106 final var builder = super.patch(url); 107 builder.addTransaction(transactionURI); 108 return builder; 109 } 110 111 @Override 112 public PostBuilder post(final URI url) { 113 final var builder = super.post(url); 114 builder.addTransaction(transactionURI); 115 return builder; 116 } 117 118 @Override 119 public PutBuilder put(final URI url) { 120 final var builder = super.put(url); 121 builder.addTransaction(transactionURI); 122 return builder; 123 } 124 125}