@Deprecated @Override public AbstractJcrNode getNodeByUUID( String uuid ) throws ItemNotFoundException, RepositoryException { return getNodeByIdentifier(uuid); }
@Deprecated @Override public AbstractJcrNode getNodeByUUID( String uuid ) throws ItemNotFoundException, RepositoryException { return getNodeByIdentifier(uuid); }
protected Node findBaseVersion( Node node ) throws RepositoryException { String baseVersionUuid = node.getProperty(JCR_BASEVERSION).getString(); return session.getNodeByIdentifier(baseVersionUuid); }
@Override public boolean matches( Value value, JcrSession session ) { assert value instanceof JcrValue; if (session == null) { return false; } JcrValue jcrValue = (JcrValue)value; Node node = null; try { node = session.getNodeByIdentifier(jcrValue.getString()); } catch (RepositoryException re) { return false; } NamespaceRegistry namespaces = session.namespaces(); for (int i = 0; i < constraints.length; i++) { try { if (node.isNodeType(constraints[i].getString(namespaces))) { return true; } } catch (RepositoryException re) { throw new IllegalStateException(re); } } return false; }
@Override public boolean matches( Value value, JcrSession session ) { assert value instanceof JcrValue; if (session == null) { return false; } JcrValue jcrValue = (JcrValue)value; Node node = null; try { node = session.getNodeByIdentifier(jcrValue.getString()); } catch (RepositoryException re) { return false; } NamespaceRegistry namespaces = session.namespaces(); for (int i = 0; i < constraints.length; i++) { try { if (node.isNodeType(constraints[i].getString(namespaces))) { return true; } } catch (RepositoryException re) { throw new IllegalStateException(re); } } return false; }
final AbstractJcrNode node( Path absolutePath ) throws PathNotFoundException, AccessDeniedException, RepositoryException { assert absolutePath.isAbsolute(); if (absolutePath.isRoot()) return getRootNode(); if (absolutePath.isIdentifier()) { // Look up the node by identifier ... String identifierString = stringFactory().create(absolutePath).replaceAll("\\[", "").replaceAll("\\]", ""); return getNodeByIdentifier(identifierString); } CachedNode node = getRootNode().node(); return node(node, absolutePath); }
final AbstractJcrNode node( Path absolutePath ) throws PathNotFoundException, AccessDeniedException, RepositoryException { assert absolutePath.isAbsolute(); if (absolutePath.isRoot()) return getRootNode(); if (absolutePath.isIdentifier()) { // Look up the node by identifier ... String identifierString = stringFactory().create(absolutePath).replaceAll("\\[", "").replaceAll("\\]", ""); return getNodeByIdentifier(identifierString); } CachedNode node = getRootNode().node(); return node(node, absolutePath); }
private void assertReferencePropertyHasPaths(String refAbsPropertyPath, String...paths ) throws Exception { Property property = (Property)session.getProperty(refAbsPropertyPath); Value[] values = property.getValues(); assertEquals("Incorrect number of references", paths.length, values.length); for (int i = 0; i < values.length; i++) { Value value = values[i]; String nodeId = value.getString(); Node referredNode = session.getNodeByIdentifier(nodeId); assertEquals("Incorrect referred node", paths[i], referredNode.getPath()); } } }
@Override public void validate( int rowNumber, Row row ) throws RepositoryException { String id = row.getValue("mode:id").getString(); Node nodeFromQuery = row.getNode(); Node resolvedNode = session().getNodeByIdentifier(id); assertSame(nodeFromQuery, resolvedNode); nodesById.put(id, nodeFromQuery); } }).validate(query, result);
@Override public String call() throws Exception { JcrSession session = repository.login(); final Node item = session.getNodeByIdentifier(sourceId); String destAbsPath = destinationPath + "/" + item.getName(); String sourceAbsPath = item.getPath(); try { if (print) { System.out.println(Thread.currentThread().getName() + String.format(" Moving node from '%s' to '%s'", sourceAbsPath, destAbsPath)); } session.move(item.getPath(), destAbsPath); session.save(); session.save(); return item.getIdentifier(); } catch (Exception e) { if (print) { System.out.println(Thread.currentThread().getName() + String.format(" Exception moving node from '%s' to '%s'", sourceAbsPath, destAbsPath)); } throw e; } finally { session.logout(); } } }
/** * Create a tree of nodes that have different name siblings at the leaves. * * @param parentsCount the number of nodes created under the root node * @param snsCount the number of nodes created under each parent * @throws Exception */ private void createTreeWithSNS( int parentsCount, int snsCount ) throws Exception { session = repository.login(); List<String> nodeIds = new ArrayList<String>(); Node testRoot = session.getRootNode().addNode("testRoot"); for (int i = 0; i < parentsCount; i++) { nodeIds.add(testRoot.addNode("parent" + i).getIdentifier()); } for (String parentId : nodeIds) { Node parent = session.getNodeByIdentifier(parentId); for (int c = 0; c < snsCount; c++) { parent.addNode("child"); } } session.save(); }
protected void assertValueIsReference( Row row, String refColumnName, boolean mayBeNull ) throws RepositoryException { Value value = row.getValue(refColumnName); if (!mayBeNull) { assertThat(value, is(notNullValue())); String ref = value.getString(); Node referenced = session.getNodeByIdentifier(ref); assertThat(referenced, is(notNullValue())); assertEquals(ref, referenced.getIdentifier()); } }
@SuppressWarnings( "deprecation" ) @Test @FixFor( "MODE-1775" ) public void shouldFindVersionNodeByIdentifierAndByUuid() throws Exception { registerNodeTypes(session, "cnd/versioning.cnd"); // Set up parent node and check it in ... Node parent = session.getRootNode().addNode("versionableNode", "ver:versionable"); parent.setProperty("versionProp", "v"); parent.setProperty("copyProp", "c"); parent.setProperty("ignoreProp", "i"); session.save(); Version version = versionManager.checkin(parent.getPath()); // Now look for the version node by identifier, using the different ways to get an identifier ... assertThat(session.getNodeByIdentifier(version.getIdentifier()), is((Node)version)); assertThat(session.getNodeByIdentifier(version.getProperty("jcr:uuid").getString()), is((Node)version)); assertThat(session.getNodeByUUID(version.getProperty("jcr:uuid").getString()), is((Node)version)); }
private void moveSNSWhileCachingPaths( String srcId, String destId, String destNodeName ) throws Exception { Node targetNode = session.getNodeByIdentifier(destId); String targetNodePath = targetNode.getPath(); targetNode = session.getNode(targetNodePath); Node sourceNode = session.getNodeByIdentifier(srcId); String sourceNodePath = sourceNode.getPath(); sourceNode = session.getNode(sourceNodePath); Node sourceParent = sourceNode.getParent(); // the next calls will load all the children (sns) and store them in the ws cache loadChildrenByPaths(session, sourceParent); loadChildrenByPaths(session, targetNode); session.move(sourceNodePath, targetNodePath + "/" + destNodeName); session.save(); // this will expose the problem of the cached paths loadChildrenByPaths(session, sourceParent); loadChildrenByPaths(session, targetNode); }
@FixFor( "MODE-1720" ) @Test public void shouldPropertyDereferenceReferencePropertiesCreatedFromStringValues() throws Exception { prop = cars.getProperty("referenceProperty2"); Value[] vals = prop.getValues(); for (Value value : vals) { String str = value.getString(); Node node = cars.getSession().getNodeByIdentifier(str); assertThat(node, IsIn.isOneOf((Node)altima, (Node)aston)); } } }
@Test @FixFor( "MODE-2055" ) public void shouldNotReturnTheVersionHistoryNode() throws Exception { Node node = session.getRootNode().addNode("outerFolder"); node.setProperty("jcr:mimeType", "text/plain"); node.addMixin("mix:versionable"); session.save(); versionManager.checkpoint("/outerFolder"); node.remove(); session.save(); try { session.getNodeByIdentifier(node.getIdentifier()); fail("Removed versionable node should not be retrieved "); } catch (ItemNotFoundException e) { //expected } }
AbstractJcrNode node = session.getNodeByIdentifier(id); assertThat(node.isShared(), is(true)); node.remove(); AbstractJcrNode node2 = session.getNodeByIdentifier(id); assertThat(node2.isShared(), is(false)); node2 = session.getNodeByIdentifier(id); assertThat(node2.isShared(), is(false));
@FixFor( "MODE-1720" ) @Test public void shouldPropertyDereferenceReferenceProperties() throws Exception { prop = cars.getProperty("referenceProperty"); Value[] vals = prop.getValues(); for (Value value : vals) { String str = value.getString(); Node node = cars.getSession().getNodeByIdentifier(str); assertThat(node, IsIn.isOneOf((Node)altima, (Node)aston)); } Node[] nodes = prop.getAs(Node[].class); for (Node node : nodes) { assertThat(node, IsIn.isOneOf((Node)altima, (Node)aston)); } NodeIterator nodeIterator = prop.getAs(NodeIterator.class); while (nodeIterator.hasNext()) { assertThat(nodeIterator.nextNode(), IsIn.isOneOf((Node)altima, (Node)aston)); } assertThat(prop.getAs(Node.class, 0), IsIn.isOneOf((Node)altima, (Node)aston)); assertThat(prop.getAs(Node.class, 1), IsIn.isOneOf((Node)altima, (Node)aston)); }
@Override public void setValue( Node value ) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { if (value == null) { this.remove(); return; } checkSession(); checkForLock(); checkForCheckedOut(); checkModifyPermission(); if (!value.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(this.context().getNamespaceRegistry()))) { throw new ValueFormatException(JcrI18n.nodeNotReferenceable.text()); } AbstractJcrNode jcrNode = session.getNodeByIdentifier(value.getIdentifier()); if (!jcrNode.isInTheSameProcessAs(session.context().getProcessId())) { throw new RepositoryException(JcrI18n.nodeNotInTheSameSession.text(jcrNode.path())); } JcrValue referenceValue = session().valueFactory().createValue(jcrNode); internalSetValue(referenceValue.asType(this.getType())); }
@Override public void setValue( Node value ) throws ValueFormatException, VersionException, LockException, ConstraintViolationException, RepositoryException { if (value == null) { this.remove(); return; } checkSession(); checkForLock(); checkForCheckedOut(); checkModifyPermission(); if (!value.isNodeType(JcrMixLexicon.REFERENCEABLE.getString(this.context().getNamespaceRegistry()))) { throw new ValueFormatException(JcrI18n.nodeNotReferenceable.text()); } AbstractJcrNode jcrNode = session.getNodeByIdentifier(value.getIdentifier()); if (!jcrNode.isInTheSameProcessAs(session.context().getProcessId())) { throw new RepositoryException(JcrI18n.nodeNotInTheSameSession.text(jcrNode.path())); } JcrValue referenceValue = session().valueFactory().createValue(jcrNode); internalSetValue(referenceValue.asType(this.getType())); }