use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class NodeStateMergerTest method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
Reader cnd = new InputStreamReader(getClass().getClassLoader().getResourceAsStream(TEST_NODETYPES));
CndImporter.registerNodeTypes(cnd, superuser);
cnd.close();
NodeTypeIterator it = superuser.getWorkspace().getNodeTypeManager().getMixinNodeTypes();
while (it.hasNext()) {
NodeType nt = it.nextNodeType();
if (nt.getName().startsWith("test:")) {
testMixins.add(nt.getName());
}
}
testNode = testRootNode.addNode(nodeName1, "nt:unstructured");
superuser.save();
sessionB = getHelper().getSuperuserSession();
testNodeB = sessionB.getNode(testNode.getPath());
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class NodeStateMergerTest method testMixinRemovedInSessionA.
// ---------------- Tests removing jcr:mixinType property in the SessionA ---
/**
* Remove the jcr:mixinType property by removing all mixin types. Merge
* to changes made in the overlayed state should fail.
* @throws Exception
*/
public void testMixinRemovedInSessionA() throws Exception {
for (int i = 1; i <= 5; i++) {
testNode.addMixin("test:mixinProp_" + i);
}
superuser.save();
testNodeB.refresh(false);
// remove all mixin types
for (NodeType mixin : testNode.getMixinNodeTypes()) {
testNode.removeMixin(mixin.getName());
}
assertFalse(testNode.hasProperty("jcr:mixinTypes"));
testNodeB.addNode(nodeName1, "nt:unstructured");
testNodeB.setProperty(propertyName1, "anyValue");
sessionB.save();
try {
superuser.save();
fail();
} catch (InvalidItemStateException e) {
// expected
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class NodeSetPrimaryTypeTest method testSetAbstractAsPrimaryType.
/**
* Tests if <code>Node.setPrimaryType(String)</code> throws a
* <code>ConstraintViolationException</code> if the
* name of a mixin type is passed
*/
public void testSetAbstractAsPrimaryType() throws RepositoryException {
Session session = testRootNode.getSession();
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator nts = manager.getPrimaryNodeTypes();
while (nts.hasNext()) {
NodeType nt = nts.nextNodeType();
if (nt.isAbstract()) {
try {
Node node = testRootNode.addNode(nodeName1, testNodeType);
node.setPrimaryType(nt.getName());
fail("Node.setPrimaryType(String) must throw ConstraintViolationException if the specified node type name refers to an abstract node type.");
} catch (ConstraintViolationException e) {
// success
} finally {
// reset the changes.
session.refresh(false);
}
}
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class NodeSetPrimaryTypeTest method testSetPrimaryType.
// TODO: test if node definition is properly reset
// TODO: test if child items are properly reset upon changing definition
// TODO: test if conflicts are properly detected
/**
* Tests a successful call to <code>Node.setPrimaryType(String)</code>
*/
public void testSetPrimaryType() throws RepositoryException {
Session session = testRootNode.getSession();
Session otherSession = null;
String nonExistingMixinName = NodeMixinUtil.getNonExistingMixinName(session);
Node node = testRootNode.addNode(nodeName1, testNodeType);
superuser.save();
// TODO improve. retrieve settable node type name from config.
NodeTypeManager manager = session.getWorkspace().getNodeTypeManager();
NodeTypeIterator nts = manager.getPrimaryNodeTypes();
while (nts.hasNext()) {
NodeType nt = nts.nextNodeType();
String ntName = nt.getName();
if (!nt.isAbstract() && !ntFrozenNode.equals(ntName) && !ntActivity.equals(ntName)) {
try {
node.setPrimaryType(ntName);
// property value must be adjusted immediately
assertEquals("The value of the jcr:primaryType property must change upon setPrimaryType.", ntName, node.getProperty(jcrPrimaryType).getString());
// save changes -> reflected upon Node.getPrimaryNodeType and Property.getValue
superuser.save();
assertEquals("Node.getPrimaryNodeType must reflect the changes made.", ntName, node.getPrimaryNodeType().getName());
assertEquals("The value of the jcr:primaryType property must change upon setPrimaryType.", ntName, node.getProperty(jcrPrimaryType).getString());
otherSession = getHelper().getReadOnlySession();
assertEquals("Node.getPrimaryNodeType must reflect the changes made.", ntName, otherSession.getNode(node.getPath()).getPrimaryNodeType().getName());
assertEquals("The value of the jcr:primaryType property must change upon setPrimaryType.", ntName, otherSession.getNode(node.getPath()).getProperty(jcrPrimaryType).getString());
// was successful
return;
} catch (ConstraintViolationException e) {
// may happen as long as arbitrary primary types are used for testing -> ignore
} finally {
if (otherSession != null) {
otherSession.logout();
}
// revert any unsaved changes.
session.refresh(false);
}
}
}
}
use of javax.jcr.nodetype.NodeType in project jackrabbit by apache.
the class LuceneQueryFactory method execute.
/**
* @param columns
* @param selector
* @param constraint
* @param externalSort
* if <code>true</code> it means that the lqf should just let the
* QueryEngine take care of sorting and applying applying offset
* and limit constraints
* @param offsetIn
* used in pagination
* @param limitIn
* used in pagination
* @return a list of rows
* @throws RepositoryException
* @throws IOException
*/
public List<Row> execute(Map<String, PropertyValue> columns, Selector selector, Constraint constraint, Sort sort, boolean externalSort, long offsetIn, long limitIn) throws RepositoryException, IOException {
final IndexReader reader = index.getIndexReader(true);
final int offset = offsetIn < 0 ? 0 : (int) offsetIn;
final int limit = limitIn < 0 ? Integer.MAX_VALUE : (int) limitIn;
QueryHits hits = null;
try {
JackrabbitIndexSearcher searcher = new JackrabbitIndexSearcher(session, reader, index.getContext().getItemStateManager());
searcher.setSimilarity(index.getSimilarity());
Predicate filter = Predicate.TRUE;
BooleanQuery query = new BooleanQuery();
QueryPair qp = new QueryPair(query);
query.add(create(selector), MUST);
if (constraint != null) {
String name = selector.getSelectorName();
NodeType type = ntManager.getNodeType(selector.getNodeTypeName());
filter = mapConstraintToQueryAndFilter(qp, constraint, Collections.singletonMap(name, type), searcher, reader);
}
List<Row> rows = new ArrayList<Row>();
// TODO depending on the filters, we could push the offset info
// into the searcher
hits = searcher.evaluate(qp.mainQuery, sort, offset + limit);
int currentNode = 0;
int addedNodes = 0;
ScoreNode node = hits.nextScoreNode();
while (node != null) {
Row row = null;
try {
row = new SelectorRow(columns, evaluator, selector.getSelectorName(), session.getNodeById(node.getNodeId()), node.getScore());
} catch (ItemNotFoundException e) {
// skip the node
}
if (row != null && filter.evaluate(row)) {
if (externalSort) {
// return everything and not worry about sort
rows.add(row);
} else {
// apply limit and offset rules locally
if (currentNode >= offset && currentNode - offset < limit) {
rows.add(row);
addedNodes++;
}
currentNode++;
// end the loop when going over the limit
if (addedNodes == limit) {
break;
}
}
}
node = hits.nextScoreNode();
}
return rows;
} finally {
if (hits != null) {
hits.close();
}
Util.closeOrRelease(reader);
}
}
Aggregations