private void addNodeToCreatedList(Node node) throws RepositoryException { if (this.createdNodes != null) { this.createdNodes.add(node.getSession().getWorkspace().getName() + ":" + node.getPath()); } }
private String getNodeWorkspaceName(final Node node) { try { return node.getSession().getWorkspace().getName(); } catch (RepositoryException e) { log.error("An error occurred while trying to access session for jcr node {}", node, e); return null; } } }
/** * The destAbsPath provided must not have an index on its final element. If * it does, then a RepositoryException is thrown. Strictly speaking, the * destAbsPath parameter is actually an absolute path to the parent node of * the new location, appended with the new name desired for the copied node. * It does not specify a position within the child node ordering. */ public void testCloneNodesAbsolutePath() { try { // copy referenceable node to an absolute path containing index String dstAbsPath = node2W2.getPath() + "/" + node1.getName() + "[2]"; workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true); fail("Cloning a node to an absolute path containing index should not be possible."); } catch (RepositoryException e) { // successful } }
@Override public Node addNode(String relPath, String primaryNodeTypeName) throws ItemExistsException, PathNotFoundException, NoSuchNodeTypeException, LockException, VersionException, ConstraintViolationException, RepositoryException { Node node = super.addNode(relPath, primaryNodeTypeName); if (RepositoryConstants.WEBSITE.equals(this.getSession().getWorkspace().getName()) && NodeTypes.Page.NAME.equals(primaryNodeTypeName)) { // no LUD update on adding subpages } else { this.updateLastModified(); } setCreatedProperty(node.getPath()); return node; }
/** * Node.merge(): If this node does not have a corresponding node in the * indicated workspace <br> then the merge method returns quietly and no * changes are made.<br> */ @SuppressWarnings("deprecation") public void testMergeNodeNonCorrespondingNode() throws RepositoryException { // create new node - this node has no corresponding node in default workspace Node subNode = nodeToMerge.addNode(nodeName3, versionableNodeType); subNode.setProperty(propertyName1, CHANGED_STRING); superuserW2.save(); subNode.checkin(); subNode.merge(workspace.getName(), true); assertTrue(subNode.getProperty(propertyName1).getString().equals(CHANGED_STRING)); }
@Override public void save() throws AccessDeniedException, ItemExistsException, ReferentialIntegrityException, ConstraintViolationException, InvalidItemStateException, VersionException, LockException, NoSuchNodeTypeException, RepositoryException { String workspaceName = wrapped.getWorkspace().getName(); try { log.debug("saving session: {}::{}::sys:{}::{}", wrapped.toString(), workspaceName, MgnlContext.isSystemInstance(), Thread.currentThread().getName()); super.save(); } catch (InvalidItemStateException e) { log.error("Failed to update LUD for session: {}::{}", wrapped.toString(), workspaceName, e); throw e; } if (!dirtyOps.isEmpty()) { Session sysSession = MgnlContext.getSystemContext().getJCRSession(workspaceName); if (sysSession instanceof DelegateSessionWrapper) { sysSession = ((DelegateSessionWrapper) sysSession).deepUnwrap(MgnlPropertySettingSessionWrapper.class); } applyPendingChanges(sysSession); sysSession.save(); } }
@Override public boolean isSame(Item otherItem) throws RepositoryException { if (this == otherItem) { return true; } if (otherItem instanceof Node) { return this.getIdentifier().equals(((Node) otherItem).getIdentifier()) && getSession().getWorkspace().getName().equals( otherItem.getSession().getWorkspace().getName()); } return false; }
@Test @FixFor( "MODE-1975" ) public void shouldNotAllowCloneWithinTheSameWs() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); try { jcrSession().getWorkspace().clone(jcrSession().getWorkspace().getName(), "/testRoot", "/testRoot1", false); fail("Should not be able to clone in the same ws if external nodes are involved"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
/** * Operation is performed entirely within the persistent workspace, it does * not involve transient storage and therefore does not require a save */ public void testCopyNodes() throws RepositoryException { // copy referenceable node below non-referenceable node String dstAbsPath = node2W2.getPath() + "/" + node1.getName(); workspaceW2.copy(workspace.getName(), node1.getPath(), dstAbsPath); // there should not be any pending changes after copy assertFalse(superuserW2.hasPendingChanges()); }
@Override public void copy(String srcAbsPath, String destAbsPath) throws ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { super.copy(srcAbsPath, destAbsPath); final String workspaceName = super.getWrappedWorkspace().getName(); setCreatedDate(workspaceName, destAbsPath, true); final String user = getCurrentUserName(); NodeUtil.visit(getSession().getNode(destAbsPath), node -> updateActivationStatus(node, user)); getSession().save(); }
/** * {@link info.magnolia.module.site.theme.Theme}-aware cache path for imaging. * * @see info.magnolia.templating.imaging.parameters.ThemeAwareParameterCachingStrategy */ public String getCachePath() { try { return "/" + themeName + "/" + variationName + "/" + node.getSession().getWorkspace().getName() + node.getPath(); } catch (RepositoryException e) { // TODO log error and return null? return ""; } }
private String getNodeWorkspaceName(final Node node) { try { return node.getSession().getWorkspace().getName(); } catch (RepositoryException e) { log.error("An error occurred while trying to access session for jcr node {}.", node, e); } return null; }
/** * Find principal nodes of type {@link NodeTypes.User#NAME}, {@link NodeTypes.Group#NAME} or {@link NodeTypes.Role#NAME}. * * As we don't save sessions during installation phase the principals that are searched might not be visible to JRC queries so we use traversal then. */ protected Node findPrincipalNode(String principalName, Session session, String primaryNodeType, Node startNode) throws RepositoryException { final boolean isInstallationPhase = InstallStatus.inProgress.equals(Components.getComponent(InstallContextImpl.class).getStatus()); final long start = System.currentTimeMillis(); final Node principalNode = isInstallationPhase ? findPrincipalNodeByTraversal(principalName, session, primaryNodeType, startNode) : findPrincipalNodeByQuery(principalName, session, primaryNodeType, startNode); log.debug("Retrieving node took {}ms (isInstallationPhase: {}): path = {}", System.currentTimeMillis() - start, isInstallationPhase, principalNode == null ? "<null>" : principalNode.getPath()); if (principalNode == null) { log.debug("Could not find principal node '{}' of primary type '{}' under startnode '{}' in workspace '{}'.", principalName, primaryNodeType, startNode == null ? "/" : startNode.getPath(), session.getWorkspace().getName()); } return principalNode; }
/** * If successful, the changes are persisted immediately, there is no need to * call save. */ public void testCloneNodes() throws RepositoryException { // clone referenceable node below non-referenceable node String dstAbsPath = node2W2.getPath() + "/" + node1.getName(); workspaceW2.clone(workspace.getName(), node1.getPath(), dstAbsPath, true); // there should not be any pending changes after clone assertFalse(superuserW2.hasPendingChanges()); }
private void updateLastModifiedProperty(String name) throws PathNotFoundException, RepositoryException { if (this.isNew()) { // node itself is not saved, nothing to do return; } getContentDecorator().updateLastModifiedProperty(this.getSession().getWorkspace().getName(), name, this.getPath()); }
@Test @FixFor( "MODE-1975" ) public void shouldNotAllowMoveWithinTheSameWsViaClone() throws Exception { federationManager.createProjection("/testRoot", SOURCE_NAME, MockConnector.DOC1_LOCATION, "fed1"); try { // clone with removeExisting = true in the same ws is a move jcrSession().getWorkspace().clone(jcrSession().getWorkspace().getName(), "/testRoot", "/testRoot1", true); fail("Should not be able to clone in the same ws if external nodes are involved"); } catch (RepositoryException e) { // expected if (print) { e.printStackTrace(); } } }
@Override public void copy(String srcWorkspace, String srcAbsPath, String destAbsPath) throws NoSuchWorkspaceException, ConstraintViolationException, VersionException, AccessDeniedException, PathNotFoundException, ItemExistsException, LockException, RepositoryException { super.copy(srcWorkspace, srcAbsPath, destAbsPath); final String workspaceName = super.getWrappedWorkspace().getName(); setCreatedDate(workspaceName, destAbsPath, true); final String user = getCurrentUserName(); NodeUtil.visit(getSession().getNode(destAbsPath), node -> updateActivationStatus(node, user)); getSession().save(); }
protected String getNodePath(Node node) throws RenderException { try { return node.getSession().getWorkspace().getName() + ":" + node.getPath(); } catch (RepositoryException e) { throw new RenderException("Can't construct node path for node " + node); } }
public LazyNodeWrapper(Node node) throws RepositoryException { this.workspace = node.getSession().getWorkspace().getName(); this.nodeIdentifier = node.getIdentifier(); this.node = node; }
@Override public void remove() throws VersionException, LockException, ConstraintViolationException, AccessDeniedException, RepositoryException { Node parent = this.getParent(); super.remove(); String workspaceName = this.getSession().getWorkspace().getName(); // as insane as it might look we might need to update lud on parent in case this is the component in a page, but not otherwise! (except maybe for data) if (RepositoryConstants.WEBSITE.equals(workspaceName)) { getContentDecorator().updateLastModified(workspaceName, parent.getPath()); } }