Skip to content

Commit

Permalink
Add methods for linking to an acl (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
bbpennel authored and Andrew Woods committed Nov 28, 2018
1 parent 1374484 commit 9709e6d
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/org/fcrepo/client/BodyRequestBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import static org.fcrepo.client.FedoraHeaderConstants.IF_MATCH;
import static org.fcrepo.client.FedoraHeaderConstants.IF_UNMODIFIED_SINCE;
import static org.fcrepo.client.FedoraHeaderConstants.LINK;
import static org.fcrepo.client.LinkHeaderConstants.ACL_REL;
import static org.fcrepo.client.LinkHeaderConstants.TYPE_REL;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_HANDLING;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_REL;
Expand Down Expand Up @@ -227,4 +228,20 @@ protected BodyRequestBuilder ifMatch(final String etag) {
}
return this;
}

/**
* Provide the URI to an ACL for this request
*
* @param aclUri URI to the ACL
* @return this builder
*/
protected BodyRequestBuilder linkAcl(final String aclUri) {
if (aclUri != null) {
final FcrepoLink link = FcrepoLink.fromUri(aclUri)
.rel(ACL_REL)
.build();
request.addHeader(LINK, link.toString());
}
return this;
}
}
3 changes: 3 additions & 0 deletions src/main/java/org/fcrepo/client/LinkHeaderConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ public class LinkHeaderConstants {
// rel identifying the RDF resource describing this resource
public static final String DESCRIBEDBY_REL = "describedby";

// rel identifying the ACL for the resource
public static final String ACL_REL = "acl";

private LinkHeaderConstants() {
}
}
5 changes: 5 additions & 0 deletions src/main/java/org/fcrepo/client/PostBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,11 @@ public PostBuilder addInteractionModel(final String interactionModelUri) {
return (PostBuilder) super.addInteractionModel(interactionModelUri);
}

@Override
protected PostBuilder linkAcl(final String aclUri) {
return (PostBuilder) super.linkAcl(aclUri);
}

/**
* Provide a content disposition header which will be used as the filename
*
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/org/fcrepo/client/PutBuilder.java
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public PutBuilder addInteractionModel(final String interactionModelUri) {
return (PutBuilder) super.addInteractionModel(interactionModelUri);
}

@Override
protected PutBuilder linkAcl(final String aclUri) {
return (PutBuilder) super.linkAcl(aclUri);
}

/**
* Provide a content disposition header which will be used as the filename
*
Expand Down
15 changes: 15 additions & 0 deletions src/test/java/org/fcrepo/client/PostBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.fcrepo.client.FedoraHeaderConstants.DIGEST;
import static org.fcrepo.client.FedoraHeaderConstants.SLUG;
import static org.fcrepo.client.FedoraTypes.LDP_DIRECT_CONTAINER;
import static org.fcrepo.client.LinkHeaderConstants.ACL_REL;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_HANDLING;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_REL;
import static org.fcrepo.client.LinkHeaderConstants.TYPE_REL;
Expand Down Expand Up @@ -211,4 +212,18 @@ public void testAddInteractionModel() throws Exception {
assertEquals(TYPE_REL, interLink.getRel());
assertEquals(LDP_DIRECT_CONTAINER, interLink.getUri().toString());
}

@Test
public void testLinkAcl() throws Exception {
testBuilder.linkAcl("http://localhost/acl")
.perform();

verify(client).executeRequest(eq(uri), requestCaptor.capture());

final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();

final FcrepoLink aclLink = new FcrepoLink(request.getFirstHeader(LINK).getValue());
assertEquals(ACL_REL, aclLink.getRel());
assertEquals("http://localhost/acl", aclLink.getUri().toString());
}
}
15 changes: 15 additions & 0 deletions src/test/java/org/fcrepo/client/PutBuilderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import static org.fcrepo.client.FedoraTypes.LDP_DIRECT_CONTAINER;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_HANDLING;
import static org.fcrepo.client.LinkHeaderConstants.EXTERNAL_CONTENT_REL;
import static org.fcrepo.client.LinkHeaderConstants.ACL_REL;
import static org.fcrepo.client.LinkHeaderConstants.TYPE_REL;
import static org.fcrepo.client.TestUtils.baseUrl;
import static org.junit.Assert.assertEquals;
Expand Down Expand Up @@ -194,4 +195,18 @@ public void testAddInteractionModel() throws Exception {
assertEquals(TYPE_REL, interLink.getRel());
assertEquals(LDP_DIRECT_CONTAINER, interLink.getUri().toString());
}

@Test
public void testLinkAcl() throws Exception {
testBuilder.linkAcl("http://localhost/acl")
.perform();

verify(client).executeRequest(eq(uri), requestCaptor.capture());

final HttpEntityEnclosingRequestBase request = (HttpEntityEnclosingRequestBase) requestCaptor.getValue();

final FcrepoLink aclLink = new FcrepoLink(request.getFirstHeader(LINK).getValue());
assertEquals(ACL_REL, aclLink.getRel());
assertEquals("http://localhost/acl", aclLink.getUri().toString());
}
}

0 comments on commit 9709e6d

Please sign in to comment.