Search in sources :

Example 1 with Value

use of javax.jcr.Value in project jackrabbit-oak by apache.

the class AceCreationTest method createAce.

private void createAce(Session session, int count) throws RepositoryException {
    AccessControlManager acManager = session.getAccessControlManager();
    JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(acManager, nodePath);
    for (int i = 0; i < count; i++) {
        ImmutableMap<String, Value> restrictions = ImmutableMap.of(AccessControlConstants.REP_GLOB, session.getValueFactory().createValue(i + ""));
        acl.addEntry(EveryonePrincipal.getInstance(), AccessControlUtils.privilegesFromNames(acManager, Privilege.JCR_ADD_CHILD_NODES), true, restrictions);
    }
    acManager.setPolicy(nodePath, acl);
}
Also used : AccessControlManager(javax.jcr.security.AccessControlManager) Value(javax.jcr.Value) JackrabbitAccessControlList(org.apache.jackrabbit.api.security.JackrabbitAccessControlList)

Example 2 with Value

use of javax.jcr.Value in project jackrabbit-oak by apache.

the class AggregatingDescriptorsTest method assertMatches.

private void assertMatches(AggregatingDescriptors aggregator, int expectedEntryCount, GenericDescriptors... descriptors) {
    // prepare the expectedEntries map
    final Map<String, DescriptorEntry> expectedEntries = new HashMap<String, AggregatingDescriptorsTest.DescriptorEntry>();
    for (int i = 0; i < descriptors.length; i++) {
        final String[] keys = descriptors[i].getKeys();
        for (int j = 0; j < keys.length; j++) {
            final DescriptorEntry entry = DescriptorEntry.fromKey(keys[j], descriptors[i]);
            // implements overwriting: eg descriptors[1] values overwrite descriptors[0] values
            // (in terms of the AggregatingDescriptors it is the opposite: the service
            // that is enlisted first always wins - with the idea that later added
            // services should not overwrite earlier ones - lowest startorder wins)
            expectedEntries.put(keys[j], entry);
        }
    }
    assertEquals(expectedEntryCount, expectedEntries.size());
    // now go through the resulting expectedEntries and match them
    // with the aggregator one
    final Collection<DescriptorEntry> entries = expectedEntries.values();
    for (Iterator<DescriptorEntry> it = entries.iterator(); it.hasNext(); ) {
        DescriptorEntry entry = it.next();
        assertEquals(entry.standard, aggregator.isStandardDescriptor(entry.key));
        if (entry.singleValued) {
            assertTrue(aggregator.isSingleValueDescriptor(entry.key));
            Value expectedValue = entry.value;
            Value actualValue = aggregator.getValue(entry.key);
            assertTrue(expectedValue.equals(actualValue));
        } else {
            assertFalse(aggregator.isSingleValueDescriptor(entry.key));
            Value[] expectedValues = entry.values;
            Value[] actualValues = aggregator.getValues(entry.key);
            assertEquals(expectedValues.length, actualValues.length);
            for (int i = 0; i < expectedValues.length; i++) {
                assertEquals(expectedValues[i], actualValues[i]);
            }
        }
    }
    assertEquals(expectedEntryCount, aggregator.getKeys().length);
}
Also used : HashMap(java.util.HashMap) Value(javax.jcr.Value)

Example 3 with Value

use of javax.jcr.Value in project jackrabbit-oak by apache.

the class AggregatingDescriptors method getValue.

@CheckForNull
@Override
public Value getValue(@Nonnull String key) {
    for (Iterator<Descriptors> it = getDescriptors().iterator(); it.hasNext(); ) {
        Descriptors descriptors = it.next();
        Value value = descriptors.getValue(key);
        if (value != null) {
            return value;
        }
    }
    return null;
}
Also used : Value(javax.jcr.Value) Descriptors(org.apache.jackrabbit.oak.api.Descriptors) CheckForNull(javax.annotation.CheckForNull)

Example 4 with Value

use of javax.jcr.Value in project jackrabbit-oak by apache.

the class DefaultSyncContextTest method testCreateValueDecimal.

@Test
public void testCreateValueDecimal() throws Exception {
    BigDecimal dec = new BigDecimal(123);
    Value v = syncCtx.createValue(dec);
    assertNotNull(v);
    assertEquals(PropertyType.DECIMAL, v.getType());
    assertEquals(dec, v.getDecimal());
}
Also used : Value(javax.jcr.Value) BigDecimal(java.math.BigDecimal) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Example 5 with Value

use of javax.jcr.Value in project jackrabbit-oak by apache.

the class DefaultSyncContextTest method testCreateValueString.

@Test
public void testCreateValueString() throws Exception {
    Value v = syncCtx.createValue("s");
    assertNotNull(v);
    assertEquals(PropertyType.STRING, v.getType());
    assertEquals("s", v.getString());
    v = syncCtx.createValue(new char[] { 's' });
    assertNotNull(v);
    assertEquals(PropertyType.STRING, v.getType());
    assertEquals("s", v.getString());
    Object o = new TestIdentityProvider.ForeignExternalUser();
    v = syncCtx.createValue(o);
    assertNotNull(v);
    assertEquals(PropertyType.STRING, v.getType());
    assertEquals(o.toString(), v.getString());
}
Also used : Value(javax.jcr.Value) AbstractExternalAuthTest(org.apache.jackrabbit.oak.spi.security.authentication.external.AbstractExternalAuthTest) Test(org.junit.Test)

Aggregations

Value (javax.jcr.Value)643 Node (javax.jcr.Node)177 Test (org.junit.Test)124 Property (javax.jcr.Property)113 RepositoryException (javax.jcr.RepositoryException)105 NotExecutableException (org.apache.jackrabbit.test.NotExecutableException)82 PropertyDefinition (javax.jcr.nodetype.PropertyDefinition)72 Session (javax.jcr.Session)71 NodeType (javax.jcr.nodetype.NodeType)61 ValueFactory (javax.jcr.ValueFactory)57 ValueFormatException (javax.jcr.ValueFormatException)53 HashMap (java.util.HashMap)51 QValue (org.apache.jackrabbit.spi.QValue)51 ArrayList (java.util.ArrayList)40 InputStream (java.io.InputStream)34 ConstraintViolationException (javax.jcr.nodetype.ConstraintViolationException)31 Privilege (javax.jcr.security.Privilege)31 PropertyIterator (javax.jcr.PropertyIterator)30 Authorizable (org.apache.jackrabbit.api.security.user.Authorizable)30 JackrabbitNode (org.apache.jackrabbit.api.JackrabbitNode)29