@NotNull @Override public Set<RestrictionDefinition> getSupportedRestrictions(@Nullable String oakPath) { Set<RestrictionDefinition> defs = Sets.newHashSet(); for (RestrictionProvider rp : providers) { defs.addAll(rp.getSupportedRestrictions(oakPath)); } return defs; }
@NotNull @Override public Set<RestrictionDefinition> getSupportedRestrictions(@Nullable String oakPath) { return getProvider().getSupportedRestrictions(oakPath); }
@NotNull @Override public Set<RestrictionDefinition> getSupportedRestrictions(@Nullable String oakPath) { Set<RestrictionDefinition> definitions = new HashSet<>(base.getSupportedRestrictions(oakPath)); definitions.add(new RestrictionDefinitionImpl(REP_NODE_PATH, Type.PATH, true)); return definitions; }
@Nonnull @Override public Set<RestrictionDefinition> getSupportedRestrictions(@Nullable String oakPath) { return getProvider().getSupportedRestrictions(oakPath); }
@Nonnull @Override public Set<RestrictionDefinition> getSupportedRestrictions(@Nullable String oakPath) { Set<RestrictionDefinition> definitions = new HashSet<RestrictionDefinition>(base.getSupportedRestrictions(oakPath)); definitions.add(new RestrictionDefinitionImpl(REP_NODE_PATH, Type.PATH, true)); return definitions; }
@NotNull @Override public Set<RestrictionDefinition> getSupportedRestrictions(@Nullable String oakPath) { return getProvider().getSupportedRestrictions(oakPath); }
private Map<String, RestrictionDefinition> getSupported(@Nullable String oakPath) { Map<String, RestrictionDefinition> supported = new HashMap<>(); for (RestrictionProvider rp : providers) { for (RestrictionDefinition rd : rp.getSupportedRestrictions(oakPath)) { supported.put(rd.getName(), rd); } } return supported; }
@NotNull @Override public String[] getRestrictionNames() { Collection<RestrictionDefinition> supported = getRestrictionProvider().getSupportedRestrictions(getOakPath()); return Collections2.transform(supported, new Function<RestrictionDefinition, String>() { @Override public String apply(RestrictionDefinition definition) { return namePathMapper.getJcrName(definition.getName()); } }).toArray(new String[supported.size()]); }
private RestrictionProvider getProvider(@Nullable String oakPath, @Nonnull String oakName) throws AccessControlException { for (RestrictionProvider rp : providers) { for (RestrictionDefinition def : rp.getSupportedRestrictions(oakPath)) { if (def.getName().equals(oakName)) { return rp; } } } throw new AccessControlException("Unsupported restriction (path = " + oakPath + "; name = " + oakName + ')'); }
private RestrictionProvider getProvider(@Nullable String oakPath, @NotNull String oakName) throws AccessControlException { for (RestrictionProvider rp : providers) { for (RestrictionDefinition def : rp.getSupportedRestrictions(oakPath)) { if (def.getName().equals(oakName)) { return rp; } } } throw new AccessControlException("Unsupported restriction (path = " + oakPath + "; name = " + oakName + ')'); }
@Test public void testGetSupportedRestrictions() { String[] paths = new String[] {null, "/testPath"}; for (String path : paths) { Set<RestrictionDefinition> defs = provider.getSupportedRestrictions(path); int expectedSize = rp1.getSupportedRestrictions(path).size() + rp2.getSupportedRestrictions(path).size(); assertEquals(expectedSize, defs.size()); assertTrue(defs.containsAll(rp1.getSupportedRestrictions(path))); assertTrue(defs.containsAll(rp2.getSupportedRestrictions(path))); } }
@Test public void testGetSupportedRestrictions() { assertTrue(RestrictionProvider.EMPTY.getSupportedRestrictions(null).isEmpty()); assertTrue(RestrictionProvider.EMPTY.getSupportedRestrictions("/any/path").isEmpty()); }
@Override public int getRestrictionType(String restrictionName) { for (RestrictionDefinition definition : getRestrictionProvider().getSupportedRestrictions(getOakPath())) { String jcrName = namePathMapper.getJcrName(definition.getName()); if (jcrName.equals(restrictionName)) { return definition.getRequiredType().tag(); } } // for backwards compatibility with JR2 return undefined type for an // unknown restriction name. return PropertyType.UNDEFINED; }
@Override public boolean isMultiValueRestriction(String restrictionName) { for (RestrictionDefinition definition : getRestrictionProvider().getSupportedRestrictions(getOakPath())) { String jcrName = namePathMapper.getJcrName(definition.getName()); if (jcrName.equals(restrictionName)) { return definition.getRequiredType().isArray(); } } // not a supported restriction => return false. return false; }
@Test public void testNewInstance() { RestrictionProvider crp = CompositeRestrictionProvider.newInstance(ImmutableSet.of(rp1, rp2)); RestrictionProvider crp2 = CompositeRestrictionProvider.newInstance(rp1, rp2); assertEquals(crp.getSupportedRestrictions("/testPath"), crp2.getSupportedRestrictions("/testPath")); }
@Test public void testGetRestrictionNames() throws RepositoryException { AbstractAccessControlList acl = createEmptyACL(); String[] restrNames = acl.getRestrictionNames(); assertNotNull(restrNames); List<String> names = Lists.newArrayList(restrNames); for (RestrictionDefinition def : getRestrictionProvider().getSupportedRestrictions(TEST_PATH)) { assertTrue(names.remove(getNamePathMapper().getJcrName(def.getName()))); } assertTrue(names.isEmpty()); }
@Test public void testGetRestrictionNames() { AbstractAccessControlList acl = createEmptyACL(); String[] restrNames = acl.getRestrictionNames(); assertNotNull(restrNames); List<String> names = Lists.newArrayList(restrNames); for (RestrictionDefinition def : getRestrictionProvider().getSupportedRestrictions(getTestPath())) { assertTrue(names.remove(getNamePathMapper().getJcrName(def.getName()))); } assertTrue(names.isEmpty()); }
@Test public void testIsMultiValueRestriction() { AbstractAccessControlList acl = createEmptyACL(); for (RestrictionDefinition def : getRestrictionProvider().getSupportedRestrictions(getTestPath())) { boolean isMv = acl.isMultiValueRestriction(getNamePathMapper().getJcrName(def.getName())); assertEquals(def.getRequiredType().isArray(), isMv); } }
@Test public void testGetRestrictionType() throws RepositoryException { AbstractAccessControlList acl = createEmptyACL(); for (RestrictionDefinition def : getRestrictionProvider().getSupportedRestrictions(TEST_PATH)) { int reqType = acl.getRestrictionType(getNamePathMapper().getJcrName(def.getName())); assertTrue(reqType > PropertyType.UNDEFINED); assertEquals(def.getRequiredType().tag(), reqType); } }
@Test public void testGetRestrictionType() { AbstractAccessControlList acl = createEmptyACL(); for (RestrictionDefinition def : getRestrictionProvider().getSupportedRestrictions(getTestPath())) { int reqType = acl.getRestrictionType(getNamePathMapper().getJcrName(def.getName())); assertTrue(reqType > PropertyType.UNDEFINED); assertEquals(def.getRequiredType().tag(), reqType); } }