Skip to content

Commit 6f1e2a0

Browse files
committed
Simplification
1 parent 74d2250 commit 6f1e2a0

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

acp/src/main/java/com/inrupt/client/acp/AccessControlResource.java

Lines changed: 20 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.inrupt.rdf.wrapping.commons.WrapperIRI;
3030

3131
import java.net.URI;
32+
import java.util.List;
33+
import java.util.Map;
3234
import java.util.Set;
3335
import java.util.UUID;
3436
import java.util.function.Consumer;
@@ -54,6 +56,17 @@ public class AccessControlResource extends RDFSource {
5456

5557
public static final URI SOLID_ACCESS_GRANT = URI.create("http://www.w3.org/ns/solid/vc#SolidAccessGrant");
5658

59+
private static final Map<URI, IRI> EXPANSION_MAPPINGS = Map.of(
60+
ACP.accessControl, asIRI(ACP.AccessControl),
61+
ACP.memberAccessControl, asIRI(ACP.AccessControl),
62+
ACP.apply, asIRI(ACP.Policy),
63+
ACP.allOf, asIRI(ACP.Matcher),
64+
ACP.anyOf, asIRI(ACP.Matcher),
65+
ACP.noneOf, asIRI(ACP.Matcher));
66+
67+
private static final List<URI> EXPANSION_PROPERTIES = List.of(ACP.accessControl, ACP.memberAccessControl,
68+
ACP.apply, ACP.allOf, ACP.anyOf, ACP.noneOf);
69+
5770
/**
5871
* Definitions for different matcher types, for use with {@link #find}.
5972
*/
@@ -127,23 +140,13 @@ public Set<AccessControl> memberAccessControl() {
127140
public AccessControlResource expand(final SolidSyncClient client) {
128141
// Copy the data from the existing ACR into a new dataset
129142
final var dataset = rdf.createDataset();
130-
final var matcherType = asIRI(ACP.Matcher);
131-
final var accessControlType = asIRI(ACP.AccessControl);
132143
stream().forEach(dataset::add);
133144

134145
try (final var cache = rdf.createDataset()) {
135-
expandType(dataset, cache, asIRI(ACP.accessControl), accessControlType,
136-
uri -> populateCache(client, uri, cache));
137-
expandType(dataset, cache, asIRI(ACP.memberAccessControl), accessControlType,
138-
uri -> populateCache(client, uri, cache));
139-
expandType(dataset, cache, asIRI(ACP.apply), asIRI(ACP.Policy),
140-
uri -> populateCache(client, uri, cache));
141-
expandType(dataset, cache, asIRI(ACP.allOf), matcherType,
142-
uri -> populateCache(client, uri, cache));
143-
expandType(dataset, cache, asIRI(ACP.anyOf), matcherType,
144-
uri -> populateCache(client, uri, cache));
145-
expandType(dataset, cache, asIRI(ACP.noneOf), matcherType,
146+
for (final var property : EXPANSION_PROPERTIES) {
147+
expandType(dataset, cache, asIRI(property), EXPANSION_MAPPINGS.get(property),
146148
uri -> populateCache(client, uri, cache));
149+
}
147150
} catch (final Exception ex) {
148151
LOGGER.atDebug().setMessage("Unable to close dataset: {}").addArgument(ex::getMessage).log();
149152
}
@@ -162,21 +165,11 @@ public AccessControlResource expand(final SolidClient client) {
162165
final var dataset = rdf.createDataset();
163166
stream().forEach(dataset::add);
164167

165-
final var matcherType = asIRI(ACP.Matcher);
166-
final var accessControlType = asIRI(ACP.AccessControl);
167168
try (final var cache = rdf.createDataset()) {
168-
expandType(dataset, cache, asIRI(ACP.accessControl), accessControlType,
169-
uri -> populateCacheAsync(client, uri, cache));
170-
expandType(dataset, cache, asIRI(ACP.memberAccessControl), accessControlType,
171-
uri -> populateCacheAsync(client, uri, cache));
172-
expandType(dataset, cache, asIRI(ACP.apply), asIRI(ACP.Policy),
173-
uri -> populateCacheAsync(client, uri, cache));
174-
expandType(dataset, cache, asIRI(ACP.allOf), matcherType,
175-
uri -> populateCacheAsync(client, uri, cache));
176-
expandType(dataset, cache, asIRI(ACP.anyOf), matcherType,
177-
uri -> populateCacheAsync(client, uri, cache));
178-
expandType(dataset, cache, asIRI(ACP.noneOf), matcherType,
179-
uri -> populateCacheAsync(client, uri, cache));
169+
for (final var property : EXPANSION_PROPERTIES) {
170+
expandType(dataset, cache, asIRI(property), EXPANSION_MAPPINGS.get(property),
171+
uri -> populateCacheAsync(client, uri, cache));
172+
}
180173
} catch (final Exception ex) {
181174
LOGGER.atDebug().setMessage("Unable to close dataset: {}").addArgument(ex::getMessage).log();
182175
}

0 commit comments

Comments
 (0)