Search in sources :

Example 21 with PropertyInfo

use of org.apache.jackrabbit.spi.PropertyInfo in project jackrabbit by apache.

the class BatchTest method testSetReferenceValue.

public void testSetReferenceValue() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    NodeInfo nInfo = rs.getNodeInfo(si, nid);
    if (!Arrays.asList(nInfo.getMixins()).contains(NameConstants.MIX_REFERENCEABLE)) {
        Batch b = rs.createBatch(si, nid);
        b.setMixins(nid, new Name[] { NameConstants.MIX_REFERENCEABLE });
        rs.submit(b);
    }
    String ref = rs.getNodeInfo(si, nid).getId().getUniqueID();
    Name propName = resolver.getQName("refProp");
    QValue v = rs.getQValueFactory().create(ref, PropertyType.REFERENCE);
    Batch b = rs.createBatch(si, nid);
    b.addProperty(nid, propName, v);
    rs.submit(b);
    PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName));
    assertFalse(pi.isMultiValued());
    assertEquals(v, pi.getValues()[0]);
    assertEquals(PropertyType.REFERENCE, pi.getType());
    pi = getPropertyInfo(nid, propName);
    assertEquals(v, pi.getValues()[0]);
    assertEquals(PropertyType.REFERENCE, pi.getType());
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Batch(org.apache.jackrabbit.spi.Batch) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name)

Example 22 with PropertyInfo

use of org.apache.jackrabbit.spi.PropertyInfo in project jackrabbit by apache.

the class BatchTest method testSetPropertyTwice.

public void testSetPropertyTwice() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Name propName = resolver.getQName("nameProp");
    PropertyId pid = getPropertyId(nid, propName);
    QValue v = rs.getQValueFactory().create(NameConstants.JCR_AUTOCREATED);
    QValue v2 = rs.getQValueFactory().create(NameConstants.JCR_BASEVERSION);
    QValue v3 = rs.getQValueFactory().create(NameConstants.JCR_CONTENT);
    Batch b = rs.createBatch(si, nid);
    b.addProperty(nid, propName, v);
    b.setValue(pid, v2);
    b.setValue(pid, v3);
    rs.submit(b);
    PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName));
    assertFalse(pi.isMultiValued());
    assertEquals(1, pi.getValues().length);
    assertEquals(v3, pi.getValues()[0]);
    assertEquals(PropertyType.NAME, pi.getType());
    pi = getPropertyInfo(nid, propName);
    assertFalse(pi.isMultiValued());
    assertEquals(1, pi.getValues().length);
    assertEquals(v3, pi.getValues()[0]);
    assertEquals(PropertyType.NAME, pi.getType());
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name) PropertyId(org.apache.jackrabbit.spi.PropertyId)

Example 23 with PropertyInfo

use of org.apache.jackrabbit.spi.PropertyInfo in project jackrabbit by apache.

the class BatchTest method testSetEmptyBinaryValue.

public void testSetEmptyBinaryValue() throws RepositoryException, IOException {
    NodeId nid = getNodeId(testPath);
    Name propName = resolver.getQName("binProp");
    Batch b = rs.createBatch(si, nid);
    b.addProperty(nid, propName, rs.getQValueFactory().create(new byte[0]));
    rs.submit(b);
    PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName));
    assertFalse(pi.isMultiValued());
    InputStream in = pi.getValues()[0].getStream();
    assertTrue(in.read() == -1);
    assertEquals("", pi.getValues()[0].getString());
    assertEquals(PropertyType.BINARY, pi.getType());
    pi = getPropertyInfo(nid, propName);
    assertFalse(pi.isMultiValued());
    in = pi.getValues()[0].getStream();
    assertTrue(in.read() == -1);
    assertEquals("", pi.getValues()[0].getString());
    assertEquals(PropertyType.BINARY, pi.getType());
}
Also used : Batch(org.apache.jackrabbit.spi.Batch) InputStream(java.io.InputStream) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name)

Example 24 with PropertyInfo

use of org.apache.jackrabbit.spi.PropertyInfo in project jackrabbit by apache.

the class BatchTest method testMultiValuedProperty.

public void testMultiValuedProperty() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    Name propName = resolver.getQName("mvProperty2");
    QValue[] vs = new QValue[] { rs.getQValueFactory().create(111), rs.getQValueFactory().create(222), rs.getQValueFactory().create(333) };
    Batch b = rs.createBatch(si, nid);
    b.addProperty(nid, propName, vs);
    rs.submit(b);
    PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName));
    assertTrue(pi.isMultiValued());
    assertEquals(Arrays.asList(vs), Arrays.asList(pi.getValues()));
    assertEquals(PropertyType.LONG, pi.getType());
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Batch(org.apache.jackrabbit.spi.Batch) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name)

Example 25 with PropertyInfo

use of org.apache.jackrabbit.spi.PropertyInfo in project jackrabbit by apache.

the class BatchTest method testSetWeakReferenceValue.

public void testSetWeakReferenceValue() throws RepositoryException {
    NodeId nid = getNodeId(testPath);
    NodeInfo nInfo = rs.getNodeInfo(si, nid);
    if (!Arrays.asList(nInfo.getMixins()).contains(NameConstants.MIX_REFERENCEABLE)) {
        Batch b = rs.createBatch(si, nid);
        b.setMixins(nid, new Name[] { NameConstants.MIX_REFERENCEABLE });
        rs.submit(b);
    }
    String ref = rs.getNodeInfo(si, nid).getId().getUniqueID();
    Name propName = resolver.getQName("weakRefProp");
    QValue v = rs.getQValueFactory().create(ref, PropertyType.WEAKREFERENCE);
    Batch b = rs.createBatch(si, nid);
    b.addProperty(nid, propName, v);
    rs.submit(b);
    PropertyInfo pi = rs.getPropertyInfo(si, getPropertyId(nid, propName));
    assertFalse(pi.isMultiValued());
    assertEquals(v, pi.getValues()[0]);
    assertEquals(PropertyType.WEAKREFERENCE, pi.getType());
    pi = getPropertyInfo(nid, propName);
    assertEquals(v, pi.getValues()[0]);
    assertEquals(PropertyType.WEAKREFERENCE, pi.getType());
}
Also used : QValue(org.apache.jackrabbit.spi.QValue) Batch(org.apache.jackrabbit.spi.Batch) NodeInfo(org.apache.jackrabbit.spi.NodeInfo) NodeId(org.apache.jackrabbit.spi.NodeId) PropertyInfo(org.apache.jackrabbit.spi.PropertyInfo) Name(org.apache.jackrabbit.spi.Name)

Aggregations

PropertyInfo (org.apache.jackrabbit.spi.PropertyInfo)27 NodeId (org.apache.jackrabbit.spi.NodeId)23 Name (org.apache.jackrabbit.spi.Name)22 Batch (org.apache.jackrabbit.spi.Batch)19 QValue (org.apache.jackrabbit.spi.QValue)18 ItemInfo (org.apache.jackrabbit.spi.ItemInfo)5 NodeInfo (org.apache.jackrabbit.spi.NodeInfo)5 PropertyId (org.apache.jackrabbit.spi.PropertyId)5 ArrayList (java.util.ArrayList)4 ItemNotFoundException (javax.jcr.ItemNotFoundException)3 InputStream (java.io.InputStream)2 PathNotFoundException (javax.jcr.PathNotFoundException)2 RepositoryException (javax.jcr.RepositoryException)2 Path (org.apache.jackrabbit.spi.Path)2 IOException (java.io.IOException)1 ItemVisitor (javax.jcr.ItemVisitor)1 Node (javax.jcr.Node)1 Property (javax.jcr.Property)1 TraversingItemVisitor (javax.jcr.util.TraversingItemVisitor)1 HttpEntity (org.apache.http.HttpEntity)1