use of javax.jcr.Property in project jackrabbit-oak by apache.
the class NodeImpl method internalSetProperty.
private Property internalSetProperty(final String jcrName, final Value[] values, final int type, final boolean exactTypeMatch) throws RepositoryException {
final String oakName = getOakPathOrThrow(checkNotNull(jcrName));
final PropertyState state = createMultiState(oakName, compact(values), Type.fromTag(type, true));
if (values.length > MV_PROPERTY_WARN_THRESHOLD) {
LOG.warn("Large multi valued property [{}/{}] detected ({} values).", dlg.getPath(), jcrName, values.length);
}
return perform(new ItemWriteOperation<Property>("internalSetProperty") {
@Override
public void checkPreconditions() throws RepositoryException {
super.checkPreconditions();
if (!isCheckedOut() && getOPV(dlg.getTree(), state) != OnParentVersionAction.IGNORE) {
throw new VersionException(format("Cannot set property. Node [%s] is checked in.", getNodePath()));
}
}
@Nonnull
@Override
public Property perform() throws RepositoryException {
return new PropertyImpl(dlg.setProperty(state, exactTypeMatch, false), sessionContext);
}
@Override
public String toString() {
return format("Setting property [%s/%s]", dlg.getPath(), jcrName);
}
});
}
use of javax.jcr.Property in project jackrabbit-oak by apache.
the class ObservationTest method testAggregate3.
@Test
public void testAggregate3() throws Exception {
assumeTrue(observationManager instanceof ObservationManagerImpl);
ObservationManagerImpl oManager = (ObservationManagerImpl) observationManager;
ExpectationListener listener = new ExpectationListener();
JackrabbitEventFilter filter = new JackrabbitEventFilter();
filter.setAbsPath("/parent");
filter.setIsDeep(true);
filter.setEventTypes(ALL_EVENTS);
filter = FilterFactory.wrap(filter).withNodeTypeAggregate(new String[] { "oak:Unstructured" }, new String[] { "**" });
oManager.addEventListener(listener, filter);
Node parent = getAdminSession().getRootNode().addNode("parent", "nt:unstructured");
// OAK-5096: in OR mode the following event also gets sent:
listener.expect(parent.getPath() + "/jcr:primaryType", PROPERTY_ADDED);
Node child = parent.addNode("child", "nt:unstructured");
// OAK-5096: in OR mode the following event also gets sent:
listener.expectAdd(child);
Node file = child.addNode("file", "oak:Unstructured");
listener.expect(file.getPath(), "/parent/child/file", NODE_ADDED);
listener.expect(file.getPath() + "/jcr:primaryType", "/parent/child/file", PROPERTY_ADDED);
Node jcrContent = file.addNode("jcr:content", "nt:unstructured");
listener.expect(jcrContent.getPath(), "/parent/child/file", NODE_ADDED);
listener.expect(jcrContent.getPath() + "/jcr:primaryType", "/parent/child/file", PROPERTY_ADDED);
Property jcrDataProperty = jcrContent.setProperty("jcr:data", "foo");
listener.expect(jcrDataProperty.getPath(), "/parent/child/file", PROPERTY_ADDED);
parent.getSession().save();
Thread.sleep(1000);
List<Expectation> missing = listener.getMissing(TIME_OUT, TimeUnit.SECONDS);
List<Event> unexpected = listener.getUnexpected();
assertTrue("Unexpected events: " + unexpected, unexpected.isEmpty());
assertTrue("Missing events: " + missing, missing.isEmpty());
}
use of javax.jcr.Property in project jackrabbit-oak by apache.
the class ReadDeepTreeTest method createDeepTree.
protected void createDeepTree() throws Exception {
Node rn = adminSession.getRootNode();
allPaths.clear();
String testNodeName = getTestNodeName();
long start = System.currentTimeMillis();
if (!rn.hasNode(testNodeName)) {
testRoot = adminSession.getRootNode().addNode(testNodeName, "nt:unstructured");
InputStream in = getClass().getClassLoader().getResourceAsStream(getImportFileName());
adminSession.importXML(testRoot.getPath(), in, ImportUUIDBehavior.IMPORT_UUID_CREATE_NEW);
adminSession.save();
} else {
testRoot = rn.getNode(testNodeName);
}
System.out.println("Import deep tree: " + (System.currentTimeMillis() - start));
ItemVisitor v = new TraversingItemVisitor.Default() {
@Override
protected void entering(Node node, int i) throws RepositoryException {
visitingNode(node, i);
super.entering(node, i);
}
@Override
protected void entering(Property prop, int i) throws RepositoryException {
visitingProperty(prop, i);
super.entering(prop, i);
}
};
v.visit(testRoot);
System.out.println("All paths: " + allPaths.size());
}
use of javax.jcr.Property in project jackrabbit-oak by apache.
the class ConcurrentEveryoneACLTest method beforeSuite.
@Override
public void beforeSuite() throws Exception {
Session session = loginWriter();
AccessControlManager acMgr = session.getAccessControlManager();
Privilege[] privileges = new Privilege[] { acMgr.privilegeFromName(Privilege.JCR_READ), acMgr.privilegeFromName(Privilege.JCR_READ_ACCESS_CONTROL) };
final Node root = session.getRootNode().addNode(ROOT_NODE_NAME, "nt:unstructured");
for (int i = 0; i < NODE_COUNT; i++) {
Node node = root.addNode("node" + i, "nt:unstructured");
for (int j = 0; j < NODE_COUNT; j++) {
Node newNode = node.addNode("node" + j, "nt:unstructured");
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, newNode.getPath());
acl.addEntry(EveryonePrincipal.getInstance(), privileges, true);
acMgr.setPolicy(newNode.getPath(), acl);
}
session.save();
}
// deny everyone on root node
JackrabbitAccessControlList acl = AccessControlUtils.getAccessControlList(session, root.getPath());
acl.addEntry(EveryonePrincipal.getInstance(), privileges, false);
acMgr.setPolicy(root.getPath(), acl);
session.save();
final int[] numACEs = new int[1];
ItemVisitor v = new TraversingItemVisitor.Default() {
@Override
protected void entering(Node node, int i) throws RepositoryException {
if (node.isNodeType(AccessControlConstants.NT_REP_ACE)) {
numACEs[0]++;
}
super.entering(node, i);
}
@Override
protected void entering(Property prop, int i) throws RepositoryException {
super.entering(prop, i);
}
};
v.visit(root);
System.out.println("Num ACEs: " + numACEs[0]);
session.logout();
}
use of javax.jcr.Property in project jackrabbit-oak by apache.
the class RepositoryTest method addMultiValuedLong.
@Test
public void addMultiValuedLong() throws RepositoryException {
Node parentNode = getNode(TEST_PATH);
Value[] values = new Value[2];
values[0] = getAdminSession().getValueFactory().createValue(42L);
values[1] = getAdminSession().getValueFactory().createValue(84L);
parentNode.setProperty("multi long", values);
parentNode.getSession().save();
Session session2 = createAnonymousSession();
try {
Property property = session2.getProperty(TEST_PATH + "/multi long");
assertTrue(property.isMultiple());
assertEquals(PropertyType.LONG, property.getType());
Value[] values2 = property.getValues();
assertEquals(values.length, values2.length);
assertEquals(values[0], values2[0]);
assertEquals(values[1], values2[1]);
} finally {
session2.logout();
}
}
Aggregations