FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

JCL-360: Add acl property to Metadata class in solid module by acoburn · Pull Request #471 · inrupt/solid-client-java · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (4) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/
public class Metadata {

private final URI acl;
private final URI storage;
private final Set<URI> type = new HashSet<>();
private final Map<String, Set<String>> wacAllow = new HashMap<>();
Expand Down Expand Up @@ -71,6 +72,15 @@ public Map<String, Set<String>> getWacAllow() {
return wacAllow;
}

/**
* The access control resource location.
*
* @return the access control resource location, if present
*/
public Optional<URI> getAcl() {
return Optional.ofNullable(acl);
}

/**
* The supported HTTP methods for the associated resource.
*
Expand Down Expand Up @@ -133,9 +143,23 @@ public String getContentType() {
*
* @param storage the Solid storage in which this resource is managed
* @param contentType the content type of the respective Solid resource
* @deprecated as of Beta3, please use the 3-parameter constructor
*/
@Deprecated
protected Metadata(final URI storage, final String contentType) {
this(storage, null, contentType);
}

/**
* Create a new Metadata object.
*
* @param storage the Solid storage in which this resource is managed
* @param acl the ACL location for this resource
* @param contentType the content type of the respective Solid resource
*/
protected Metadata(final URI storage, final URI acl, final String contentType) {
this.storage = storage;
this.acl = acl;
this.contentType = contentType;
}

Expand All @@ -153,6 +177,7 @@ public static Builder newBuilder() {
*/
public static final class Builder {

private URI builderAcl;
private URI builderStorage;
private Set<URI> builderType = new HashSet<>();
private Map<String, Set<String>> builderWacAllow = new HashMap<>();
Expand Down Expand Up @@ -195,6 +220,17 @@ public Builder wacAllow(final Map.Entry<String, Set<String>> accessParam) {
return this;
}

/**
* Add an acl property.
*
* @param acl the acl location
* @return this builder
*/
public Builder acl(final URI acl) {
builderAcl = acl;
return this;
}

/**
* Add an allowedMethod property.
*
Expand Down Expand Up @@ -256,7 +292,7 @@ public Builder contentType(final String type) {
* @return the resource Metadata object
*/
public Metadata build() {
final Metadata metadata = new Metadata(builderStorage, builderContentType);
final Metadata metadata = new Metadata(builderStorage, builderAcl, builderContentType);
metadata.wacAllow.putAll(builderWacAllow);
metadata.type.addAll(builderType);
metadata.allowedMethods.addAll(builderAllowedMethods);
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ static Metadata buildMetadata(final URI uri, final Headers headers) {
metadata.storage(uri);
}
metadata.type(link.getUri());
} else if (link.getParameter("rel").contains("acl")) {
metadata.acl(link.getUri());
} else if (link.getParameter("rel").contains(PIM.storage.toString())) {
metadata.storage(link.getUri());
}
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ private void setupMocks() {
.withStatus(200)
.withHeader("Content-Type", "text/turtle")
.withHeader("Link", Link.of(LDP.BasicContainer, "type").toString())
.withHeader("Link", Link.of(URI.create("http://acl.example/"), "acl").toString())
.withHeader("Link", Link.of(
URI.create(PIM.getNamespace() + "Storage"),
"type").toString())
Expand All @@ -66,6 +67,7 @@ private void setupMocks() {
.withStatus(200)
.withHeader("Content-Type", "text/turtle")
.withHeader("Link", Link.of(LDP.BasicContainer, "type").toString())
.withHeader("Link", Link.of(URI.create("http://acl.example/solid/"), "acl").toString())
.withHeader("Link", Link.of(URI.create("http://storage.example/"),
PIM.storage).toString())
.withHeader("Link", Link.of(URI.create("https://history.test/"), "timegate").toString())
Expand All @@ -84,6 +86,7 @@ private void setupMocks() {
.withStatus(200)
.withHeader("Content-Type", "text/turtle")
.withHeader("Link", Link.of(LDP.RDFSource, "type").toString())
.withHeader("Link", Link.of(URI.create("http://acl.example/recipe"), "acl").toString())
.withHeader("Link", Link.of(URI.create("http://storage.example/"),
PIM.storage).toString())
.withHeader("Link", Link.of(URI.create("https://history.test/"), "timegate").toString())
Expand All @@ -103,6 +106,7 @@ private void setupMocks() {
.withHeader("Content-Type", "text/turtle")
.withHeader("Link", Link.of(LDP.RDFSource, "type").toString())
.withHeader("Link", Link.of(URI.create("http://storage.example/"), PIM.storage).toString())
.withHeader("Link", Link.of(URI.create("http://acl.example/custom-agent"), "acl").toString())
.withHeader("Link", Link.of(URI.create("https://history.test/"), "timegate").toString())
.withHeader("WAC-Allow", "user=\"read write\",public=\"read\"")
.withHeader("Allow", "POST, PUT, PATCH")
Expand Down Expand Up @@ -136,6 +140,7 @@ private void setupMocks() {
.withHeader("Link", Link.of(URI.create("http://storage.example/"),
PIM.storage).toString())
.withHeader("Link", Link.of(URI.create("https://history.test/"), "timegate").toString())
.withHeader("Link", Link.of(URI.create("http://acl.example/playlist"), "acl").toString())
.withHeader("WAC-Allow", "user=\"read write\",public=\"read\"")
.withHeader("Allow", "POST, PUT, PATCH")
.withHeader("Accept-Post", "application/ld+json, text/turtle")
Expand Down Expand Up @@ -171,6 +176,7 @@ private void setupMocks() {
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/plain")
.withHeader("Link", Link.of(URI.create("http://acl.example/binary"), "acl").toString())
.withBody("This is a plain text document.")));

wireMockServer.stubFor(put(urlEqualTo("/binary"))
Expand All @@ -191,6 +197,7 @@ private void setupMocks() {
.willReturn(aResponse()
.withStatus(200)
.withHeader("Content-Type", "text/turtle")
.withHeader("Link", Link.of(URI.create("http://acl.example/nonRDF"), "acl").toString())
.withBody("This isn't valid turtle.")));

wireMockServer.stubFor(get(urlEqualTo("/missing"))
Expand Down
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ void testGetOfSolidRDFSource() throws IOException, InterruptedException {
try (final SolidRDFSource resource = response.body()) {
assertEquals(uri, resource.getIdentifier());
assertTrue(resource.getMetadata().getType().contains(LDP.BasicContainer));
assertEquals(Optional.of(URI.create("http://acl.example/solid/")),
resource.getMetadata().getAcl());
assertEquals(Optional.of(URI.create("http://storage.example/")),
resource.getMetadata().getStorage());
assertTrue(resource.getMetadata().getWacAllow().get("user")
Expand Down Expand Up @@ -114,6 +116,8 @@ void testCheckRootOfSolidRDFSource() throws IOException, InterruptedException {
try (final SolidRDFSource resource = response.body()) {
assertEquals(uri, resource.getIdentifier());
assertTrue(resource.getMetadata().getType().contains(LDP.BasicContainer));
assertEquals(Optional.of(URI.create("http://acl.example/")),
resource.getMetadata().getAcl());
assertEquals(Optional.of(uri), resource.getMetadata().getStorage());
}
}
Expand Down Expand Up @@ -157,6 +161,7 @@ void testEmptyResourceBuilder() {
final URI id = URI.create("https://resource.example/");
try (final SolidRDFSource res = new SolidRDFSource(id, null, null)) {
assertFalse(res.getMetadata().getStorage().isPresent());
assertFalse(res.getMetadata().getAcl().isPresent());
assertTrue(res.getMetadata().getAllowedPatchSyntaxes().isEmpty());
assertEquals(0, res.size());
assertEquals(id, res.getIdentifier());
Expand All @@ -168,6 +173,7 @@ void testEmptyContainerBuilder() {
final URI id = URI.create("https://resource.example/");
try (final SolidContainer res = new SolidContainer(id, null, null)) {
assertFalse(res.getMetadata().getStorage().isPresent());
assertFalse(res.getMetadata().getAcl().isPresent());
assertTrue(res.getMetadata().getAllowedPatchSyntaxes().isEmpty());
assertEquals(0, res.size());
assertEquals(id, res.getIdentifier());
Expand Down

Back | FazBrowse Home | New Git URL