use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class BatchedItemOperations method move.
/**
* Moves the tree at <code>srcPath</code> to the new location at
* <code>destPath</code>. Returns the id of the moved node.
* <p>
* <b>Precondition:</b> the state manager needs to be in edit mode.
*
* @param srcPath
* @param destPath
* @return the id of the moved node
* @throws ConstraintViolationException
* @throws VersionException
* @throws AccessDeniedException
* @throws PathNotFoundException
* @throws ItemExistsException
* @throws LockException
* @throws RepositoryException
* @throws IllegalStateException if the state manager is not in edit mode
*/
public NodeId move(Path srcPath, Path destPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException, IllegalStateException {
// check precondition
if (!stateMgr.inEditMode()) {
throw new IllegalStateException("cannot move path " + safeGetJCRPath(srcPath) + " because manager is not in edit mode");
}
try {
if (srcPath.isAncestorOf(destPath)) {
String msg = safeGetJCRPath(destPath) + ": invalid destination path" + " (cannot be descendant of source path)";
log.debug(msg);
throw new RepositoryException(msg);
}
} catch (MalformedPathException mpe) {
String msg = "invalid path for move: " + safeGetJCRPath(destPath);
log.debug(msg);
throw new RepositoryException(msg, mpe);
}
Path srcParentPath = srcPath.getAncestor(1);
NodeState target = getNodeState(srcPath);
NodeState srcParent = getNodeState(srcParentPath);
Path destParentPath = destPath.getAncestor(1);
NodeState destParent = getNodeState(destParentPath);
int ind = destPath.getIndex();
if (ind > 0) {
// subscript in name element
String msg = safeGetJCRPath(destPath) + ": invalid destination path" + " (subscript in name element is not allowed)";
log.debug(msg);
throw new RepositoryException(msg);
}
HierarchyManagerImpl hierMgr = (HierarchyManagerImpl) this.hierMgr;
if (hierMgr.isShareAncestor(target.getNodeId(), destParent.getNodeId())) {
String msg = safeGetJCRPath(destPath) + ": invalid destination path" + " (share cycle detected)";
log.debug(msg);
throw new RepositoryException(msg);
}
// 2. check if target state can be removed from old/added to new parent
checkRemoveNode(target, srcParent.getNodeId(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_CONSTRAINTS | CHECK_HOLD | CHECK_RETENTION);
checkAddNode(destParent, destPath.getName(), target.getNodeTypeName(), CHECK_ACCESS | CHECK_LOCK | CHECK_CHECKED_OUT | CHECK_CONSTRAINTS | CHECK_HOLD | CHECK_RETENTION);
// 3. do move operation (modify and store affected states)
boolean renameOnly = srcParent.getNodeId().equals(destParent.getNodeId());
int srcNameIndex = srcPath.getIndex();
if (srcNameIndex == 0) {
srcNameIndex = 1;
}
stateMgr.store(target);
if (renameOnly) {
stateMgr.store(srcParent);
// change child node entry
destParent.renameChildNodeEntry(srcPath.getName(), srcNameIndex, destPath.getName());
} else {
// check shareable case
if (target.isShareable()) {
String msg = "Moving a shareable node (" + safeGetJCRPath(srcPath) + ") is not supported.";
log.debug(msg);
throw new UnsupportedRepositoryOperationException(msg);
}
stateMgr.store(srcParent);
stateMgr.store(destParent);
// 1. remove child node entry from old parent
if (srcParent.removeChildNodeEntry(target.getNodeId())) {
// 2. re-parent target node
target.setParentId(destParent.getNodeId());
// 3. add child node entry to new parent
destParent.addChildNodeEntry(destPath.getName(), target.getNodeId());
}
}
return target.getNodeId();
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class LuceneQueryFactory method getPropertyValueQuery.
protected Query getPropertyValueQuery(String field, String operator, Value value, int type, int transform) throws RepositoryException {
String string = getValueString(value, type);
if (JCR_OPERATOR_LIKE.equals(operator)) {
return new WildcardQuery(PROPERTIES, field, string, transform, cache);
}
Term term = getTerm(field, string);
if (JCR_OPERATOR_EQUAL_TO.equals(operator)) {
switch(transform) {
case TRANSFORM_UPPER_CASE:
return new CaseTermQuery.Upper(term);
case TRANSFORM_LOWER_CASE:
return new CaseTermQuery.Lower(term);
default:
return new JackrabbitTermQuery(term);
}
} else if (JCR_OPERATOR_GREATER_THAN.equals(operator)) {
return new RangeQuery(term, getTerm(field, ""), false, transform, cache);
} else if (JCR_OPERATOR_GREATER_THAN_OR_EQUAL_TO.equals(operator)) {
return new RangeQuery(term, getTerm(field, ""), true, transform, cache);
} else if (JCR_OPERATOR_LESS_THAN.equals(operator)) {
return new RangeQuery(getTerm(field, ""), term, false, transform, cache);
} else if (JCR_OPERATOR_LESS_THAN_OR_EQUAL_TO.equals(operator)) {
return new RangeQuery(getTerm(field, ""), term, true, transform, cache);
} else if (JCR_OPERATOR_NOT_EQUAL_TO.equals(operator)) {
BooleanQuery query = new BooleanQuery();
query.add(Util.createMatchAllQuery(field, index.getIndexFormatVersion(), cache), SHOULD);
if (transform == TRANSFORM_UPPER_CASE) {
query.add(new CaseTermQuery.Upper(term), MUST_NOT);
} else if (transform == TRANSFORM_LOWER_CASE) {
query.add(new CaseTermQuery.Lower(term), MUST_NOT);
} else {
query.add(new JackrabbitTermQuery(term), MUST_NOT);
}
// and exclude all nodes where 'field' is multi valued
query.add(new JackrabbitTermQuery(new Term(MVP, field)), MUST_NOT);
return query;
} else {
// FIXME
throw new UnsupportedRepositoryOperationException();
}
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class LuceneQueryFactory method getComparisonQuery.
protected Query getComparisonQuery(DynamicOperand left, int transform, String operator, StaticOperand rigth, Map<String, NodeType> selectorMap) throws RepositoryException {
if (left instanceof PropertyValue) {
PropertyValue pv = (PropertyValue) left;
String field = npResolver.getJCRName(session.getQName(pv.getPropertyName()));
int type = PropertyType.UNDEFINED;
NodeType nt = selectorMap.get(pv.getSelectorName());
if (nt != null) {
for (PropertyDefinition pd : nt.getPropertyDefinitions()) {
if (pd.getName().equals(pv.getPropertyName())) {
type = pd.getRequiredType();
break;
}
}
}
return getPropertyValueQuery(field, operator, evaluator.getValue(rigth), type, transform);
} else if (left instanceof NodeName) {
return getNodeNameQuery(transform, operator, rigth);
} else if (left instanceof NodeLocalName) {
return getNodeLocalNameQuery(transform, operator, rigth);
} else {
throw new UnsupportedRepositoryOperationException(// FIXME
"Unknown operand type: " + left);
}
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class LuceneQueryFactory method getNodeNameQuery.
protected Query getNodeNameQuery(int transform, String operator, StaticOperand right) throws RepositoryException {
if (transform != TRANSFORM_NONE || !JCR_OPERATOR_EQUAL_TO.equals(operator)) {
throw new UnsupportedRepositoryOperationException();
}
Value value = evaluator.getValue(right);
int type = value.getType();
String string = value.getString();
if (type == PropertyType.URI && string.startsWith("./")) {
string = string.substring("./".length());
} else if (type == PropertyType.DOUBLE || type == PropertyType.DECIMAL || type == PropertyType.LONG || type == PropertyType.BOOLEAN || type == PropertyType.REFERENCE || type == PropertyType.WEAKREFERENCE) {
throw new InvalidQueryException("Invalid name value: " + string);
}
try {
Name name = session.getQName(string);
Term uri = new Term(NAMESPACE_URI, name.getNamespaceURI());
Term local = new Term(LOCAL_NAME, name.getLocalName());
BooleanQuery query = new BooleanQuery();
query.add(new JackrabbitTermQuery(uri), MUST);
query.add(new JackrabbitTermQuery(local), MUST);
return query;
} catch (IllegalNameException e) {
throw new InvalidQueryException("Illegal name: " + string, e);
}
}
use of javax.jcr.UnsupportedRepositoryOperationException in project jackrabbit by apache.
the class AbstractRepositoryOperationTest method testGetEffectivePoliciesByPrincipal.
public void testGetEffectivePoliciesByPrincipal() throws Exception {
if (!(acMgr instanceof JackrabbitAccessControlManager)) {
throw new NotExecutableException();
}
JackrabbitAccessControlManager jAcMgr = (JackrabbitAccessControlManager) acMgr;
Set<Principal> principalSet = Collections.singleton(testUser.getPrincipal());
try {
// initial state: no repo level policy
AccessControlPolicy[] policies = acMgr.getPolicies(null);
assertNotNull(policies);
assertEquals(0, policies.length);
AccessControlPolicy[] effective = jAcMgr.getEffectivePolicies(principalSet);
assertNotNull(effective);
assertEquals(0, effective.length);
AccessControlPolicyIterator it = acMgr.getApplicablePolicies(null);
assertTrue(it.hasNext());
// modify the repo level policy
modifyPrivileges(null, NameConstants.JCR_NODE_TYPE_DEFINITION_MANAGEMENT.toString(), false);
modifyPrivileges(null, NameConstants.JCR_NAMESPACE_MANAGEMENT.toString(), true);
// verify that the effective policies for the given principal set
// is properly calculated.
AccessControlPolicy[] eff = jAcMgr.getEffectivePolicies(principalSet);
assertNotNull(eff);
assertEquals(1, eff.length);
assertTrue(eff[0] instanceof AccessControlList);
AccessControlList acl = (AccessControlList) eff[0];
AccessControlEntry[] aces = acl.getAccessControlEntries();
assertNotNull(aces);
assertEquals(2, aces.length);
for (AccessControlEntry ace : aces) {
assertEquals(testUser.getPrincipal(), ace.getPrincipal());
}
} catch (UnsupportedRepositoryOperationException e) {
throw new NotExecutableException();
} finally {
// remove it again
for (AccessControlPolicy plc : acMgr.getPolicies(null)) {
acMgr.removePolicy(null, plc);
}
superuser.save();
// back to initial state: no repo level policy
AccessControlPolicy[] policies = acMgr.getPolicies(null);
assertNotNull(policies);
assertEquals(0, policies.length);
}
}
Aggregations